0

TensorflowのCNNで使用するためにjpgイメージのセットをTFRecordに変換しようとしています。ここからbuild_image_data.pyスクリプトを使用しています:tensforflowのbuild_image_data.pyスクリプトがうまくいかない理由

https://github.com/tensorflow/models/blob/master/inception/inception/data/build_image_data.py

私は、検証ディレクトリおよびトレーニングディレクトリだけでなく、適切なラベルを持つlabels.txtファイルを作成しました。私はjupyterノートを使ってスクリプトを実行します(私もコマンドラインで試しました)、tf.app.flags.DEFINE_string引数を適切なディレクトリ/ファイル名に変更しました。私はそれを実行すると、次のエラーが表示されます:

Saving results to /tmp/ 
Determining list of input files and labels from /tmp/. 
--------------------------------------------------------------------------- 
NotFoundError        Traceback (most recent call last) 
<ipython-input-2-6349ff3421a2> in <module>() 
    356 
    357 if __name__ == '__main__': 
--> 358 tf.app.run() 

C:\Users\Lenovo\Anaconda3\envs\tensorflow3_5\lib\site-packages\tensorflow\python\platform\app.py in run(main, argv) 
    42 # Call the main function, passing through any arguments 
    43 # to the final program. 
---> 44 _sys.exit(main(_sys.argv[:1] + flags_passthrough)) 
    45 
    46 

<ipython-input-2-6349ff3421a2> in main(unused_argv) 
    350 # Run it! 
    351 _process_dataset('validation', FLAGS.validation_directory, 
--> 352     FLAGS.validation_shards, FLAGS.labels_file) 
    353 _process_dataset('train', FLAGS.train_directory, 
    354     FLAGS.train_shards, FLAGS.labels_file) 

<ipython-input-2-6349ff3421a2> in _process_dataset(name, directory, num_shards, labels_file) 
    336  labels_file: string, path to the labels file. 
    337 """ 
--> 338 filenames, texts, labels = _find_image_files(directory, labels_file) 
    339 _process_image_files(name, filenames, texts, labels, num_shards) 
    340 

<ipython-input-2-6349ff3421a2> in _find_image_files(data_dir, labels_file) 
    288 print('Determining list of input files and labels from %s.' % data_dir) 
    289 unique_labels = [l.strip() for l in tf.gfile.FastGFile(
--> 290  labels_file, 'r').readlines()] 
    291 
    292 labels = [] 

C:\Users\Lenovo\Anaconda3\envs\tensorflow3_5\lib\site-packages\tensorflow\python\lib\io\file_io.py in readlines(self) 
    126 def readlines(self): 
    127  """Returns all lines from the file in a list.""" 
--> 128  self._preread_check() 
    129  lines = [] 
    130  while True: 

C:\Users\Lenovo\Anaconda3\envs\tensorflow3_5\lib\site-packages\tensorflow\python\lib\io\file_io.py in _preread_check(self) 
    71  with errors.raise_exception_on_not_ok_status() as status: 
    72   self._read_buf = pywrap_tensorflow.CreateBufferedInputStream(
---> 73    compat.as_bytes(self.__name), 1024 * 512, status) 
    74 
    75 def _prewrite_check(self): 

C:\Users\Lenovo\Anaconda3\envs\tensorflow3_5\lib\contextlib.py in __exit__(self, type, value, traceback) 
    64   if type is None: 
    65    try: 
---> 66     next(self.gen) 
    67    except StopIteration: 
    68     return 

C:\Users\Lenovo\Anaconda3\envs\tensorflow3_5\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status() 
    464   None, None, 
    465   compat.as_text(pywrap_tensorflow.TF_Message(status)), 
--> 466   pywrap_tensorflow.TF_GetCode(status)) 
    467 finally: 
    468  pywrap_tensorflow.TF_DeleteStatus(status) 

NotFoundError: NewRandomAccessFile failed to Create/Open: : The system cannot find the path specified. 

手がかりはありますか?私は私のバリデーションとトレーニングフォルダを含む同じディレクトリからスクリプトを実行しています。ありがとう。

EDIT:フルパスで試してみましたが、同じエラーが表示されます。ここでコードの関連するセクションですが、私はそれが私の一部ではいくつかの単純なエラーだと確信しています。

tf.app.flags.DEFINE_string('train_directory', '/tmp/', 
          'C:/Users/Lenovo/dir2/tensorflow_code/cell_tf/cell_images/main_cell_images/TRAIN_DIR') 
tf.app.flags.DEFINE_string('validation_directory', '/tmp/', 
          'C:/Users/Lenovo/dir2/tensorflow_code/cell_tf/cell_images/main_cell_images/VALIDATION_DIR') 
tf.app.flags.DEFINE_string('output_directory', '/tmp/', 
          'C:/Users/Lenovo/dir2/tensorflow_code/cell_tf/cell_images/main_cell_images/OUTPUT_DIR') 

tf.app.flags.DEFINE_integer('train_shards', 1, 
          'Number of shards in training TFRecord files.') 
tf.app.flags.DEFINE_integer('validation_shards', 1, 
          'Number of shards in validation TFRecord files.') 

tf.app.flags.DEFINE_integer('num_threads', 1, 
          'Number of threads to preprocess the images.') 

tf.app.flags.DEFINE_string('labels_file', '','C:/Users/Lenovo/dir2/tensorflow_code/cell_tf/cell_images/main_cell_images/MYLABELS.TXT') 
+0

/の/ TEMP場所に住所を置く必要がありますか? –

+0

ちょうどそれを試してみました。私の編集を参照してください。 – Jaafa

+0

ああ。 DEFINE_stringの2番目の引数はデフォルト値を設定します。 3番目はフラグの説明です。 –

答えて

0

あなたは絶対パスが動作します

tf.app.flags.DEFINE_string('train_directory', 'D:/full/path', 
         'Training data directory') 
関連する問題