代码:
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])
回溯 (最近一次调用最后): File “D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”, line 1278, in _do_call return fn(*args) File “D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”, line 1263, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File “D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”, line 1350, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: NewRandomAccessFile无法创建/打开: Tensor(“arg0:0″, shape=(), dtype=string) : 文件名、目录名或卷标语法不正确。 ; 未知错误 [[Node: ReadFile = ReadFile]] [[Node: IteratorGetNext = IteratorGetNextoutput_shapes=[[?,224,224,3], [?,1000]], output_types=[DT_FLOAT, DT_FLOAT], _device=”/job:localhost/replica:0/task:0/device:CPU:0″]] [[Node: 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″]]
在处理上述异常时,发生了另一个异常:
回溯 (最近一次调用最后): File “vgg16_train_batch_processing.py”, line 231, in sess.run(optimizer) File “D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”, line 877, in run run_metadata_ptr) File “D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”, line 1100, in _run feed_dict_tensor, options, run_metadata) File “D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”, line 1272, in _do_run run_metadata) File “D:\Python\Anaconda\envs\tf\lib\site-packages\tensorflow\python\client\session.py”, line 1291, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: NewRandomAccessFile无法创建/打开: Tensor(“arg0:0″, shape=(), dtype=string) : 文件名、目录名或卷标语法不正确。 ; 未知错误 [[Node: ReadFile = ReadFile]] [[Node: IteratorGetNext = IteratorGetNextoutput_shapes=[[?,224,224,3], [?,1000]], output_types=[DT_FLOAT, DT_FLOAT], _device=”/job:localhost/replica:0/task:0/device:CPU:0″]] [[Node: 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″]]
回答:
没关系,我自己解决了这个问题。
问题出在数据集映射的解析函数中。
我错误地使用了tf.read_file(str(filename))
代替了tf.read_file(filename)
,因为这里的filename
是一个张量,所以导致了错误。