Tensorflow TFRecordWriter:访问被拒绝

时间:2017-08-26 07:53:48

标签: tensorflow

我正在尝试为我的数据创建一个TFRecord文件,因为我正在使用TFRecordWriter,但它无法写入目录并引发以下错误:

堆栈跟踪:

FLAGS.output_path: E:\ml\output
Traceback (most recent call last):
 File "conversion_script_for_converting_dataset_to_TFRECORD_format.py", line 126, in <module>
tf.app.run()
File "C:\Python\Python35\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "conversion_script_for_converting_dataset_to_TFRECORD_format.py", line 107, in main
writer = tf.python_io.TFRecordWriter(FLAGS.output_path)
File "C:\Python\Python35\lib\site-packages\tensorflow\python\lib\io\tf_record.py", line 106, in __init__
compat.as_bytes(path), compat.as_bytes(compression_type), status)
File "C:\Python\Python35\lib\contextlib.py", line 66, in __exit__
next(self.gen)
File "C:\Python\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.UnknownError: Failed to create a NewWriteableFile: E:\ml\output : Access is denied.
; Input/output error

代码段:

import tensorflow as tf
import os
import io
from PIL import Image
from object_detection.utils import dataset_util

flags = tf.app.flags
flags.DEFINE_string('output_path', 'E:\\ml\\output', '')
FLAGS = flags.FLAGS

def main(_):
  print('test')
  print("FLAGS.output_path: {}".format(FLAGS.output_path))
  writer = tf.python_io.TFRecordWriter(FLAGS.output_path)

  # TODO(user): Write code to read in your dataset to examples variable
  PATH_TO_TEST_IMAGES_DIR = 'E:\ml\dataset_in_TFRECORD_format'
  image_files = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, 'img{}'.format(i)) for i in range(0, 2) ]

  for image_file in image_files:
    image_path = image_file + '.jpg'
    image_metadata_path = image_file + '_manmet.txt'
    print('Image path: {}'.format(image_path))
    print('Image metadata path: {}'.format(image_metadata_path))
    print('\n')
    tf_example = create_tf_example(image_path, image_metadata_path)
    writer.write(tf_example.SerializeToString())

    writer.close()


if __name__ == '__main__':
  tf.app.run()

我是从Git-bash,Windows PowerShell,Windows PowerShell(管理员)尝试过的,但是遇到了同样的错误。

2 个答案:

答案 0 :(得分:1)

您应该在路径中定义文件名,代码应如下所示:

flags.DEFINE_string('output_path', 'E:\\ml\\output', '')

答案 1 :(得分:0)

路径必须包含文件名

$url = "myfile.php?v=houses";
foreach ($playerHouses as $value)
{
    $url .= '&id[]='.$value['id'];
}