我想用这些预训练tensorflow的车型之一:https://github.com/tensorflow/models/tree/master/slimTensorflow:使用预训练以来模型
加载inceptionv4模型后,我有问题,一些测试的预测。 还有一个类似的问题:Using pre-trained inception_resnet_v2 with Tensorflow
在这个问题中,解决方案是修复图像预处理。 我尝试使用范围为颜色通道从0到1和从-1到1
这是我的代码(我已经导入一切从inceptionv4源文件):
checkpoint_file = '..\checkpoints\inception_resnet_v2_2016_08_30.ckpt'
sample_images = ['horse.jpg', 'hound.jpg']
sess = tf.Session()
im_size = 299
inception_v4.default_image_size = im_size
arg_scope = inception_utils.inception_arg_scope()
inputs = tf.placeholder(tf.float32, (None, im_size, im_size, 3))
with slim.arg_scope(arg_scope):
net, logits, end_points = inception_v4(inputs)
saver = tf.train.Saver()
saver.restore(sess,'..\checkpoints\inception_v4.ckpt')
for image in sample_images:
im = Image.open(image)
im = im.resize((299, 299))
im = np.array(im)
im = im.reshape(-1, 299, 299, 3)
im = 2. * (im/255.) - 1.
logit_values = sess.run(logits, feed_dict={inputs: im})
print(np.max(logit_values))
print(np.argmax(logit_values))
随着目前的预处理,颜色通道从-1到1,网络认为这匹马是一顶泳帽。 对于从0到1的比例缩放,它变成了一只海豚,显然是一只小鸟。 我用这个表来找出预测的分类:https://gist.github.com/aaronpolhamus/964a4411c0906315deb9f4a3723aac57
我也检查了多个图像。网络一直关闭。
什么问题?