0

我想用 tf slim 的网络预测图像。但是我得到了 inceptionv3 的随机结果。对于 resnet50,一切正常。

资源网50:

import tensorflow as tf
import cv2
import numpy as np
import tensorflow.contrib.slim.nets as nets
slim = tf.contrib.slim

with tf.device('/gpu:1'):
    inputs = tf.placeholder(tf.float32, shape=[None,299,299,3])
    with slim.arg_scope(nets.resnet_v1.resnet_arg_scope()):
        features,net = nets.resnet_v1.resnet_v1_50(inputs=inputs, num_classes=1000)

    saver = tf.train.Saver()

    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    config.allow_soft_placement=True
    with tf.Session(config=config) as sess:
        saver.restore(sess, 'weights/resnet_v1_50.ckpt')
        img = cv2.imread('images/dog_ball.jpg')
        img = cv2.resize(img,(299,299))
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        img = img/255.0
        curr_features, curr_net = sess.run([features, net], feed_dict={inputs: [img,img, img]})
        for curr_feature in curr_features:
            f_ind = np.argsort(curr_feature[0][0])[-4:] # resnet50v1
            for i in f_ind:
                print i
            print ' '

但是如果我尝试 inception_v3,它就不起作用。即使图像相同,结果也不相同。首先我想,权重没有正确加载,但一切看起来都很好。

初始v3:

import tensorflow as tf
import cv2
import numpy as np
import tensorflow.contrib.slim.nets as nets
slim = tf.contrib.slim

with tf.device('/gpu:1'):
    inputs = tf.placeholder(tf.float32, shape=[None,299,299,3])

    with slim.arg_scope(nets.inception.inception_v3_arg_scope()):
        features,net = nets.inception.inception_v3(inputs=inputs, num_classes=1001)


    saver = tf.train.Saver()

    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    config.allow_soft_placement=True
    with tf.Session(config=config) as sess:
        saver.restore(sess, 'weights/inception_v3.ckpt')
        img = cv2.imread('images/dog_ball.jpg')
        img = cv2.resize(img,(299,299))
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        img = img/255.0
        curr_features, curr_net = sess.run([features, net], feed_dict={inputs: [img,img, img]})
        for curr_feature in curr_features:
            f_ind = np.argsort(curr_feature)[-4:] # inceptionv3
            for i in f_ind:
                print i
            print ' '

你知道,我的错误在哪里吗?

4

1 回答 1

-1

找到了答案

如果您有同样的问题,请写:

features,net = nets.inception.inception_v3(inputs=inputs, num_classes=1001, is_training=False)
于 2018-02-05T02:47:47.550 回答