使用内置的初始脚本将图像目录转换为tfrecords

时间:2019-02-18 21:11:01

标签: python python-3.x tensorflow

我正在尝试将我的数据(图像)转换为tfrecords。 我是通过Stackoverflow进入此内置脚本的,但似乎无法正常工作。

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

我已更改默认标志值以反映我的值,例如:

tf.app.flags.DEFINE_string('train_directory', r'D:\project\Moondra\BAD_IMAGES\BAD IMAGES TRAINING DATA\TEST 2\training',
                           'Training data directory')
tf.app.flags.DEFINE_string('validation_directory', r''D:\project\Moondra\BAD_IMAGES\BAD IMAGES TRAINING DATA\TEST 2\validation',
                           'Validation data directory')
tf.app.flags.DEFINE_string('output_directory', r''D:\project\Moondra\BAD_IMAGES\BAD IMAGES TRAINING DATA\TEST 2\tfrecords',
                           'Output data directory')

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

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

tf.app.flags.DEFINE_string('labels_file','', r'D:\project\Moondra\BAD_IMAGES\BAD IMAGES TRAINING DATA\TEST 2\labels.txt')

training目录格式是5个子目录,每个子目录代表一个标签。

我尝试运行脚本,但是遇到以下错误:

Saving results to D:\project\Moondra\BAD_IMAGES\BAD IMAGES TRAINING DATA\TEST 2\tfrecords
Determining list of input files and labels from D:\project\Moondra\BAD_IMAGES\BAD IMAGES TRAINING DATA\TEST 2\validation.

raceback (most recent call last):
  File "C:\Users\Moondra\Desktop\cloud_test\train\convert_to_TFRECORDS.py", line 397, in <module>
    tf.app.run()
  File "C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run
    _sys.exit(main(argv))
  File "C:\Users\Moondra\Desktop\cloud_test\train\convert_to_TFRECORDS.py", line 391, in main
    FLAGS.validation_shards, FLAGS.labels_file)
  File "C:\Users\Moondra\Desktop\cloud_test\train\convert_to_TFRECORDS.py", line 377, in _process_dataset
    filenames, texts, labels = _find_image_files(directory, labels_file)
  File "C:\Users\Moondra\Desktop\cloud_test\train\convert_to_TFRECORDS.py", line 330, in _find_image_files
    labels_file, 'r').readlines()]
  File "C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 183, in readlines
    self._preread_check()
  File "C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 80, in _preread_check
    compat.as_bytes(self.__name), 1024 * 512, status)
  File "C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 519, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: NewRandomAccessFile failed to Create/Open:  : The system cannot find the path specified.

; No such process

谢谢。

1 个答案:

答案 0 :(得分:0)

您是否验证了训练目录和验证目录都正确标记了数据?
标签也应与标签文件匹配。
最好从路径中删除空格。有时还会产生错误。 ;)