Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Error handling 跳过Tensorflow中不存在或损坏的文件_Error Handling_Tensorflow - Fatal编程技术网

Error handling 跳过Tensorflow中不存在或损坏的文件

Error handling 跳过Tensorflow中不存在或损坏的文件,error-handling,tensorflow,Error Handling,Tensorflow,我有一些包含图像文件路径和功能的文件,其中一些图像可能丢失或损坏。我想知道如何通过跳过这些图像并将其从队列中删除来稳健地处理错误 我注意到,仅仅捕获错误并继续将导致队列输出相同的图像,因此它将在相同的图像上重复出错。是否有一种方法可以在出现错误时将图像出列 另外,我有一个“tf.Print()”语句来记录文件名,但日志中的“Result:”行显示有效图像在处理时没有相应的打印输出。为什么“tf.Print()”只打印不存在的文件名,而不是正确处理的文件名 下面是一个小示例,其错误处理代码与我的大

我有一些包含图像文件路径和功能的文件,其中一些图像可能丢失或损坏。我想知道如何通过跳过这些图像并将其从队列中删除来稳健地处理错误

我注意到,仅仅捕获错误并继续将导致队列输出相同的图像,因此它将在相同的图像上重复出错。是否有一种方法可以在出现错误时将图像出列

另外,我有一个“tf.Print()”语句来记录文件名,但日志中的“Result:”行显示有效图像在处理时没有相应的打印输出。为什么“tf.Print()”只打印不存在的文件名,而不是正确处理的文件名

下面是一个小示例,其错误处理代码与我的大程序相同:

代码:

程序输出:

I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
Running graph
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning N
UMA node zero
I tensorflow/core/common_runtime/gpu/gpu_device.cc:951] Found device 0 with properties: 
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.8475
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 6.83GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:972] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
I tensorflow/core/kernels/logging_ops.cc:79] [nonexistent.jpg]
Result: [ 0.33875707  0.39879724  0.28882763]
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
W tensorflow/core/framework/op_kernel.cc:968] Not found: nonexistent.jpg
         [[Node: ReaderRead_1 = ReaderRead[_class=["loc:@WholeFileReader", "loc:@input_producer_1"], _device="/job:localhost/replica:0/task:0/cpu:0"](WholeFileReader, input_produ
cer_1)]]
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Skipping file due to image not existing
Done training -- epoch limit reached after 0 iterations

您可以手动定义出列操作:

filename_deq = image_filenames_queue.dequeue()
稍后,如果在读取文件时发现问题,请将该文件从文件名队列中退出:

except tf.errors.NotFoundError as e:
    print("Skipping file due to image not existing")
    sess.run(filename_deq)
filename_deq = image_filenames_queue.dequeue()
except tf.errors.NotFoundError as e:
    print("Skipping file due to image not existing")
    sess.run(filename_deq)