0

我正在尝试将一组 jpg 图像转换为 TFRecord,以便在 Tensorflow 中与 CNN 一起使用。我正在使用来自此处的脚本 build_image_data.py:

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

我创建了一个验证目录和一个训练目录,以及一个带有适当标签的 labels.txt 文件。我使用 jupyter notebook 运行脚本(我也尝试过通过命令行),并将 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. 

有什么线索吗?我从包含我的验证和培训文件夹的同一目录运行脚本。谢谢。

编辑:尝试使用完整路径,但仍然出现相同的错误。这是代码的相关部分,我确定这是我的一些简单错误。

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

1 回答 1

0

您应该将地址放在 /temp/ 的位置

tf.app.flags.DEFINE_string('train_directory', 'D:/full/path',
                       'Training data directory')
于 2017-05-09T18:46:17.580 回答