我恢复了训练有素的张量流模型,然后我想要检测输入图像结果。 这里恢复代码:
import tensorflow as tf
import cv2
sess=tf.Session()
image_size=128
saver = tf.train.import_meta_graph('my_test_model-1000.meta')
saver.restore(sess,tf.train.latest_checkpoint('./'))
sess.run(tf.global_variables_initializer())
然后如何使用此模型预测128 * 128 * 3 rgb输入图像?
答案 0 :(得分:0)
import tensorflow as tf
import cv2
def model(inputs):
# You define your model over here
...
...
return logtis
image = cv2.imread("image_path.jpg")
ip_tensor = tf.placeholder(tf.float32, (None, 128, 128, 3))
logits = model(ip_tensor)
with tf.Session() as sess:
saver.restore(sess, tf.train.latest_checkpoint('./')) # restore your model
feed={ip_tensor: inputs} # prepare your feed to the saved model
predictions = sess.run(tf.argmax(logits, 1), feed_dict=feed) # make prediction