如何在Tensorflow decode_jpeg中确定哪个JPEG图片已损坏

问题描述 投票:0回答:1

当我解码JPEG格式图片时,它会给出消息“损坏的jpeg数据过早结束数据段”。我怎样才能确定哪张图片已损坏。这是我的代码:

import os
import tensorflow as tf

directory = 'D:\\tfrecord\\read'
directories = []
class_names = []

photo_filenames = []

for filename in os.listdir(directory):
    path = os.path.join(directory, filename)
    photo_filenames.append(path)

with tf.Session() as sess:
    print("session")
    init = tf.global_variables_initializer()
    sess.run(init)
    for filename in photo_filenames:
        filecontents = tf.read_file(filename)
        image = tf.image.decode_jpeg(filecontents, channels = 3)
        try:
            sess.run(image)
        except Exception as e:
            print(filename)
            print (e)
tensorflow
1个回答
0
投票

插入

image = tf.Print(image,[filename]) 

image = tf.image.decode_jpeg(filecontents, channels = 3)

文件名将在“损坏的jpeg数据......”之后显示

© www.soinside.com 2019 - 2024. All rights reserved.