我已经使用tensorflow-for-poets参考文献重新训练了模型,它已经成功构建,但是一次只能预测一张图像。我需要在label_image.py中进行什么更改才能使其在整个文件夹中运行? (成为张量流中的新秀)
for i, image in enumerate(image_list):
image_time = image.split('.')[0].replace('_', ':')
image_path = "%s/%s" % (image_dir, image)
t = read_tensor_from_image_file(image_path,
input_height=input_height,
input_width=input_width,
input_mean=input_mean,
input_std=input_std)
with tf.Session(graph=graph) as sess:
results = sess.run(output_operation.outputs[0],
{input_operation.outputs[0]: t})
results = np.squeeze(results)
top_k = results.argsort()[-1:][::-1]
#for i in top_k:
if labels[i]=='exempt vehicle':
data=(labels[i], results[i],0)
elif labels[i]=='2 wheeler':
data=(labels[i], results[i],20)
elif labels[i]=='4 wheeler':
data=(labels[i], results[i],40)
else:
data=(labels[i],results[i],80)
print(data)
wr.writerow(data)
myfile.flush()