Image 解码失败。预期图像(JPEG、PNG或GIF)的格式未知,以'\257\
我将一些图像编码为TFRecords作为示例,然后尝试对它们进行解码。然而,在解码过程中有一个bug,我真的无法修复它 InvalidArgumentError:预期图像(JPEG、PNG或GIF),格式未知,以“\257\222\244\257\222\244\260\223\245\260\223\245\262\225\247\263”开头 [{{node DecodeJpeg}}][Op:IteratorGetNextSync] 编码: 定义字节功能(值): “”“从字符串/字节返回字节列表。”“” 返回tf.train.Feature(bytes\u list=tf.train.BytesList(value=[value])) 解码: 导入IPython.display作为显示Image 解码失败。预期图像(JPEG、PNG或GIF)的格式未知,以'\257\,image,tensorflow,deep-learning,computer-vision,tfrecord,Image,Tensorflow,Deep Learning,Computer Vision,Tfrecord,我将一些图像编码为TFRecords作为示例,然后尝试对它们进行解码。然而,在解码过程中有一个bug,我真的无法修复它 InvalidArgumentError:预期图像(JPEG、PNG或GIF),格式未知,以“\257\222\244\257\222\244\260\223\245\260\223\245\262\225\247\263”开头 [{{node DecodeJpeg}}][Op:IteratorGetNextSync] 编码: 定义字节功能(值): “”“从字符串/字节返回字节
train_files = tf.data.Dataset.list_files(r"E:\data\datatrainPrecipitate.tfrecords")
train_files = train_files.interleave(tf.data.TFRecordDataset)
def decode_example(example_proto):
image_feature_description = {
'image/height': tf.io.FixedLenFeature([], tf.int64),
'image/width': tf.io.FixedLenFeature([], tf.int64),
'image/class/label': tf.io.FixedLenFeature([], tf.int64, default_value=3),
'image/encoded': tf.io.FixedLenFeature([], tf.string)
}
parsed_features = tf.io.parse_single_example(example_proto, image_feature_description)
height = tf.cast(parsed_features['image/height'], tf.int32)
width = tf.cast(parsed_features['image/width'], tf.int32)
label = tf.cast(parsed_features['image/class/label'], tf.int32)
image_buffer = parsed_features['image/encoded']
image = tf.io.decode_jpeg(image_buffer, channels=3)
image = tf.cast(image, tf.float32)
return image, label
def processed_dataset(dataset):
dataset = dataset.repeat()
dataset = dataset.batch(1)
dataset = dataset.prefetch(buffer_size=tf.data.experimental.AUTOTUNE)
# print(dataset)
return dataset
train_dataset = train_files.map(decode_example)
# train_dataset = processed_dataset(train_dataset)
print(train_dataset)
for (image, label) in train_dataset:
print(repr(image))
InvalidArgumentError:预期图像(JPEG、PNG或GIF),格式未知,以“\257\222\244\257\222\244\260\223\245\260\223\245\262\225\247\263”开头
[{{node DecodeJpeg}}][Op:IteratorGetNextSync]我可以使用tf.io.decode_raw()对tf记录进行解码,然后使用tf.reforme()获得原始图像。虽然仍然不知道何时使用tf.io.decode_raw()和何时使用tf.io.decode_jpeg()。我可以使用tf.io.decode_raw()对tf记录进行解码,然后使用tf.reforme()获得原始图像。但仍然不知道何时使用tf.io.decode_raw()和何时使用tf.io.decode_jpeg()
train_files = tf.data.Dataset.list_files(r"E:\data\datatrainPrecipitate.tfrecords")
train_files = train_files.interleave(tf.data.TFRecordDataset)
def decode_example(example_proto):
image_feature_description = {
'image/height': tf.io.FixedLenFeature([], tf.int64),
'image/width': tf.io.FixedLenFeature([], tf.int64),
'image/class/label': tf.io.FixedLenFeature([], tf.int64, default_value=3),
'image/encoded': tf.io.FixedLenFeature([], tf.string)
}
parsed_features = tf.io.parse_single_example(example_proto, image_feature_description)
height = tf.cast(parsed_features['image/height'], tf.int32)
width = tf.cast(parsed_features['image/width'], tf.int32)
label = tf.cast(parsed_features['image/class/label'], tf.int32)
image_buffer = parsed_features['image/encoded']
image = tf.io.decode_jpeg(image_buffer, channels=3)
image = tf.cast(image, tf.float32)
return image, label
def processed_dataset(dataset):
dataset = dataset.repeat()
dataset = dataset.batch(1)
dataset = dataset.prefetch(buffer_size=tf.data.experimental.AUTOTUNE)
# print(dataset)
return dataset
train_dataset = train_files.map(decode_example)
# train_dataset = processed_dataset(train_dataset)
print(train_dataset)
for (image, label) in train_dataset:
print(repr(image))