2017-08-26 126 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', '')