【发布时间】:2017-05-23 22:12:08
【问题描述】:
我正在尝试测试一个 tensorflow 模型,其中包含 10 张图像作为批量大小,并作为输出获得特定区域的分割。这是我用来加载模型的代码
def run(model_path, image_path,graph_path ,output_path):
with tf.Session() as sess:
model_saver = tf.train.import_meta_graph(graph_path, clear_devices=True)
model_saver.restore(sess,tf.train.latest_checkpoint(LOGDIR))
sess.run(tf.global_variables_initializer())
graph = tf.get_default_graph()
x=tf.placeholder(tf.float32,shape=[10, 400, 600, 3])
output = graph.get_tensor_by_name("prediction:0")
print("Model restored.")
print('Initialized')
temp=[]
import glob
from scipy import misc
for file in os.listdir(image_path):
if file.endswith(".jpg"):
img = misc.imread(image_path + file)
img = img.astype('Float32')
img = np.resize(img,(400,600,3))
temp.append(img)
prediction = sess.run(output, feed_dict={x:temp})
cv2.imwrite(output_path, prediction * 255)
但我收到以下错误:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'x' with dtype float and shape [10,400,600,3]
[[Node: x = Placeholder[dtype=DT_FLOAT, shape=[10,400,600,3], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
[[Node: prediction/_265 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_28_prediction", tensor_type=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
有谁知道这个错误是什么,或者是否有另一种测试模型的方法。
【问题讨论】:
-
我认为你在这里重新定义了 x。而是按名称提供它,因此删除 x=placeholder() 行并使用 {'x:0': temp} 之类的东西作为提要字典,让我知道会发生什么。
-
@AlWld 感谢您解决了所有问题!
-
很高兴听到,如果您可以将其标记为已解决,请将其添加为答案,谢谢
标签: python tensorflow computer-vision