2016-06-15 7 views
1

Tensorflow画像分類の例(https://www.tensorflow.org/versions/r0.9/tutorials/image_recognition/index.html)を使用しています。 一度に複数の画像を分類するにはどうすればよいですか?テンソルフローで複数の画像を分類する

EDIT:理想的には、私はちょうど

を引数として一つの画像と番号(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) 
+0

これまでのコードは何ですか?あなたの質問にそれを加えてください。 –

+0

あなたが必要とするものは、実装が非常に簡単であるべきですが、私たちはあなたのイメージを読んで、あなたが示したものを呼び出す部分が必要です。 – mathetes

+0

は、メインで行われた呼び出しではなく、最初の数行で行われたイメージの読み取り(image_data = tf.gfile.FastGFile(image、 'rb')。read())? – Claire

答えて

1

あなたに関連するコードは、このセクションのようになります。

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) 
これは、そのフォルダ

にすべての画像の予測をプリントアウトする必要があり

def main(_): 
    maybe_download_and_extract() 

    # search for files in 'images' dir 
    files_dir = os.getcwd() + '/images' 
    files = os.listdir(files_dir) 

    # loop over files, print prediction if it is an image 
    for f in files: 
    if f.lower().endswith(('.png', '.jpg', '.jpeg')): 
     image_path = files_dir + '/' + f 
     print run_inference_on_image(image_path) 

:「画像」フォルダ内のすべてのPNG、JPEGまたはJPGファイルのための予測を持っているために、210

は、あなたがこれを行うことができます

関連する問題