python - 解码的 TFRecord 大小错误
问题描述
我正在使用 TensorFlows DeepLab,想看看我的数据是否正确转换为 tfrecords。我使用预定义download_and_convert_ade20k.sh
和以下代码将其解码回来:
import tensorflow as tf
feature_desc = {
'image/encoded': tf.io.FixedLenFeature((), tf.string, default_value=''),
'image/filename': tf.io.FixedLenFeature((), tf.string, default_value=''),
'image/format': tf.io.FixedLenFeature((), tf.string, default_value='jpeg'),
'image/height': tf.io.FixedLenFeature((), tf.int64, default_value=0),
'image/width': tf.io.FixedLenFeature((), tf.int64, default_value=0),
'image/segmentation/class/encoded': tf.io.FixedLenFeature((), tf.string, default_value=''),
'image/segmentation/class/format': tf.io.FixedLenFeature((), tf.string, default_value='png'),
}
def _parse_image_function(example_proto):
return tf.io.parse_single_example(example_proto, feature_desc)
raw_image_dataset = tf.data.TFRecordDataset('ADE20K/tfrecord/train-00000-of-00004.tfrecord')
parsed_image_dataset = raw_image_dataset.map(_parse_image_function)
for image_features in parsed_image_dataset:
img = tf.io.decode_raw(image_features['image/encoded'], tf.uint8).numpy()
seg = tf.io.decode_raw(image_features['image/segmentation/class/encoded'], tf.uint8).numpy()
我有两个问题。首先,我在编码之前不知道图像的数据类型。我猜tf.uint8
是因为它是唯一一个也可以输出 0 到 255 之间的值的工作。另一方面,获得的图像是一维的(如预期的那样),但不足以将其重塑为原始形状。解码后的图像长度为 48836,而原始高度和宽度为 (512, 612),总共等于 313344 个像素。
解决方案
推荐阅读
- java - 收缩数组在 Java 中维护数字分布
- qt - 向 QML 布局添加边距
- .net-core - .Net Core 1.1 程序集中的重复类型名称
- java - 如何在spring数据mongo db中聚合一个嵌套对象并避免PropertyReferenceException?
- c# - 在本地运行单元测试时缺少文件
- r - 将当前数据框重塑为另一个数据框并创建新列(连接)
- node.js - 如何使用谷歌语音从长音频中获取文本到文本 node.js
- ruby - Ruby mediainfo(gem)错误“mon超出范围”?
- c++ - 如果同时运行,BIGSERIAL 事务是否安全?(PostgreSQL,libpqxx)
- excel - 如何将 application.vlookup 函数的结果显示为 TextBox.Value?