当我解码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)
插入
image = tf.Print(image,[filename])
后
image = tf.image.decode_jpeg(filecontents, channels = 3)
文件名将在“损坏的jpeg数据......”之后显示