1
我正在使用Tensorflow圖像分類示例(https://www.tensorflow.org/versions/r0.9/tutorials/image_recognition/index.html)。 我怎樣才能一次分類多個圖像?tensorflow分類多個圖像
編輯:理想情況下,我也只是通過在一個圖像和一個數字(nb
)作爲參數,然後使輸入要被分類的NB該圖像的迭代
該文件是classify_image.py
,而重要的部分是:
def run_inference_on_image(image):
"""Runs inference on an image.
Args:
image: Image file name.
Returns:
Nothing
"""
if not tf.gfile.Exists(image):
tf.logging.fatal('File does not exist %s', image)
image_data = tf.gfile.FastGFile(image, 'rb').read()
# Creates graph from saved GraphDef.
create_graph()
with tf.Session() as sess:
# Some useful tensors:
# 'softmax:0': A tensor containing the normalized prediction across
# 1000 labels.
# 'pool_3:0': A tensor containing the next-to-last layer containing 2048
# float description of the image.
# 'DecodeJpeg/contents:0': A tensor containing a string providing JPEG
# encoding of the image.
# Runs the softmax tensor by feeding the image_data as input to the graph.
softmax_tensor = sess.graph.get_tensor_by_name('softmax:0')
predictions = sess.run(softmax_tensor,
{'DecodeJpeg/contents:0': image_data})
predictions = np.squeeze(predictions)
# Creates node ID --> English string lookup.
node_lookup = NodeLookup()
top_k = predictions.argsort()[-FLAGS.num_top_predictions:][::-1]
for node_id in top_k:
human_string = node_lookup.id_to_string(node_id)
score = predictions[node_id]
print('%s (score = %.5f)' % (human_string, score))
def main(_):
maybe_download_and_extract()
image = (FLAGS.image_file if FLAGS.image_file else
os.path.join(FLAGS.model_dir, 'cropped_panda.jpg'))
run_inference_on_image(image)
到目前爲止你的代碼是什麼?請將其添加到您的問題。 –
你需要的東西應該很容易實現,但是我們需要你閱讀你的圖片的部分,並打電話給你展示的東西。 – mathetes
不是在main中調用,而是在前幾行完成圖像讀取(image_data = tf.gfile.FastGFile(image,'rb')。read())? – Claire