How to classify an image?
yangxue0827 opened this issue · 3 comments
yangxue0827 commented
I want to classify an image, but the result is not correct. What is wrong with the operation?
input_image = tf.placeholder(tf.float32, shape=(None, 3, 224, 224), name='input_placeholder')
outputs = SE_ResNet(input_image, 1000, is_training=False, data_format='channels_first')
saver = tf.train.Saver()
with tf.Session() as sess:
init = tf.global_variables_initializer()
sess.run(init)
saver.restore(sess, "./seresnet50/se_resnet50.ckpt")
img = cv2.imread('./person.jpg')
img = cv2.resize(img, (224, 224))
img = np.array(img, np.float32)
img -= np.array([[[104., 117., 123.]]])
img = np.transpose(img, (2, 0, 1))
predict = sess.run(outputs, feed_dict={input_image: np.expand_dims(img, axis=0)})
print(predict)
print(np.argmax(predict))
HiKapok commented
@yangxue0827 what do you mean by uncorrect?
yangxue0827 commented
The input image is panda, but the network prediction is 168 ('redbone'). Is the above code handled incorrectly? @HiKapok
HiKapok commented
I don't know, I just checked the output of logits to match the Caffe models