【问题标题】:Getting InvalidArgumentError: NewRandomAccessFile failed to Create/Open while working with tf.data on the custom image dataset获取 InvalidArgumentError:NewRandomAccessFile 在自定义图像数据集上使用 tf.data 时无法创建/打开
【发布时间】:2019-04-04 03:46:56
【问题描述】:

代码:

dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
dataset = dataset.map(_parseJpeg, num_parallel_calls = nthread)

dataset = dataset.batch(batch_size)     
dataset = dataset.prefetch(batch_size)

iterator = dataset.make_one_shot_iterator()
images, labels = iterator.get_next()

 with tf.Session() as sess:
    sess.run([images, labels])

Traceback(最近一次调用最后一次): _do_call 中的文件“D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”,第 1278 行 返回 fn(*args) _run_fn 中的文件“D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”,第 1263 行 选项,feed_dict,fetch_list,target_list,run_metadata) _call_tf_sessionrun 中的文件“D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”,第 1350 行 运行元数据) tensorflow.python.framework.errors_impl.InvalidArgumentError: NewRandomAccessFile failed to Create/Open: Tensor("arg0:0", shape=(), dtype=string) : 文件名、目录名或卷标语法不正确。 ;未知错误 [[节点:ReadFile = ReadFile]] [[节点:IteratorGetNext = IteratorGetNextoutput_shapes=[[?,224,224,3], [?,1000]], output_types=[DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device: CPU:0"]] [[节点:IteratorGetNext/_1 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0 /device:CPU:0", send_device_incarnation=1, tensor_name="edge_37_IteratorGetNext", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

在处理上述异常的过程中,又发生了一个异常:

Traceback(最近一次调用最后一次): 文件“vgg16_train_batch_processing.py”,第 231 行,在 sess.run(优化器) 文件“D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”,第 877 行,运行中 run_metadata_ptr) 文件“D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”,第 1100 行,在 _run feed_dict_tensor、选项、run_metadata) 文件“D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”,第 1272 行,在 _do_run 运行元数据) _do_call 中的文件“D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”,第 1291 行 raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: NewRandomAccessFile failed to Create/Open: Tensor("arg0:0", shape=(), dtype=string) : 文件名、目录名或卷标语法不正确。 ;未知错误 [[节点:ReadFile = ReadFile]] [[节点:IteratorGetNext = IteratorGetNextoutput_shapes=[[?,224,224,3], [?,1000]], output_types=[DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device: CPU:0"]] [[节点:IteratorGetNext/_1 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0 /device:CPU:0", send_device_incarnation=1, tensor_name="edge_37_IteratorGetNext", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

【问题讨论】:

    标签: python tensorflow machine-learning deep-learning


    【解决方案1】:

    没关系,我自己解决了这个问题。

    它在数据集映射的解析器函数中。

    我错误地输入了tf.read_file(str(filename)),而不是tf.read_file(filename), 这是导致错误的原因,因为filename 这里是一个张量。

    【讨论】:

      猜你喜欢
      • 2019-05-12
      • 1970-01-01
      • 2019-09-03
      • 1970-01-01
      • 2022-11-05
      • 1970-01-01
      • 2021-12-19
      • 2020-12-21
      • 1970-01-01
      相关资源
      最近更新 更多