在张量流模型上测试图像
Testing images on a tensorflow model
我正在尝试使用 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} 作为喂食字典。
我正在尝试使用 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} 作为喂食字典。