2016-12-04 6 views
1

GoogleのInceptionモデルを画像のリストのループで実行しようとすると、約100ほどの画像の後に問題が発生します。メモリが不足しているようです。私はCPU上で走っています。他の誰かがこの問題に遭遇しましたか?Google Inception tensorflow.python.framework.errors.ResourceExhaustedError

Traceback (most recent call last): 
    File "clean_dataset.py", line 33, in <module> 
    description, score = inception.run_inference_on_image(f.read()) 
    File "/Volumes/EXPANSION/research/dcgan-transfer/data/classify_image.py", line 178, in run_inference_on_image 
    node_lookup = NodeLookup() 
    File "/Volumes/EXPANSION/research/dcgan-transfer/data/classify_image.py", line 83, in __init__ 
    self.node_lookup = self.load(label_lookup_path, uid_lookup_path) 
    File "/Volumes/EXPANSION/research/dcgan-transfer/data/classify_image.py", line 112, in load 
    proto_as_ascii = tf.gfile.GFile(label_lookup_path).readlines() 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 110, in readlines 
    self._prereadline_check() 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 72, in _prereadline_check 
    compat.as_bytes(self.__name), 1024 * 512, status) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 24, in __exit__ 
    self.gen.next() 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/framework/errors.py", line 463, in raise_exception_on_not_ok_status 
    pywrap_tensorflow.TF_GetCode(status)) 
tensorflow.python.framework.errors.ResourceExhaustedError: /tmp/imagenet/imagenet_2012_challenge_label_map_proto.pbtxt 


real 6m32.403s 
user 7m8.210s 
sys  1m36.114s 

https://github.com/tensorflow/models/tree/master/inception

答えて

3

問題は、あなたが」画像の数千人を分類するために巨大なループにそれを置く場合は特に、自分のコードにあなたは、単にオリジナルの「classify_image.py」をインポートすることはできません(https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/imagenet/classify_image.py)でありますバッチモード '。ここでは、元のコードで

ルック:

    :あなた以上から

    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)) 
    

    は、それがファイルから以下のロードクラスのNodeLookup 'の新しいインスタンスを生成し、各分類タスクのためにそれを見ることができます

  • label_lookup = "imagenet_2012_challenge_label_map_proto.pbtxt"
  • uid_lookup_path = "imagenet_synset_to_human_label_map.txt"

インスタンスが本当に巨大になり、コードのループでこのクラスのインスタンスが何百も生成され、結果として 'tensorflow.python.framework.errors.ResourceExhaustedError'が生成されます。

私は、新しいスクリプトを作成し、それらのクラスと関数を 'classify_image.py'から変更して、各ループのNodeLookupクラスをインスタンス化せずに一度だけインスタンス化して使用することをお勧めしますそれはループの中にある。このようなもの:

with tf.Session() as sess: 
     softmax_tensor = sess.graph.get_tensor_by_name('softmax:0') 
     print 'Making classifications:' 

     # Creates node ID --> English string lookup. 
     node_lookup = NodeLookup(label_lookup_path=self.Model_Save_Path + self.label_lookup, 
           uid_lookup_path=self.Model_Save_Path + self.uid_lookup_path) 

     current_counter = 1 
     for (tensor_image, image) in self.tensor_files: 
      print 'On ' + str(current_counter) 

      predictions = sess.run(softmax_tensor, {'DecodeJpeg/contents:0': tensor_image}) 
      predictions = np.squeeze(predictions) 

      top_k = predictions.argsort()[-int(self.filter_level):][::-1] 

      for node_id in top_k: 
       human_string = node_lookup.id_to_string(node_id) 
       score = predictions[node_id] 
関連する問題