2017-08-26 93 views
0

我想创建一个TFRecord文件为我的数据和我使用TFRecordWriter但不能写入该目录,并引发以下错误:Tensorflow 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(管理员),但得到相同的错误。

回答

0

路径必须包括文件名以及

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