我对TFRecord解码和编码的工作方式非常困惑,特别是使用tf.train.Feature(bytes_list=tf.train.BytesList(...))进行编码,然后再对其进行解码。
我想编写三种类型的数据--我的TFRecord:宽度/高度值(整数)、图像数据和字符串标签。我在网上查看了代码示例,我不确定何时需要使用decode_raw,何时不需要使用。
例如,假设这是我写它时的记录:
def _bytes_feature(value):
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
def _int64_feature(value):
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))
example = tf.train.Example(features=
tf.train.Features(feature={
'width': _int64_feature(256),
'height': _int64_feature(256),
'label': tf.train.Feature(bytes_list=tf.train.BytesList(
value=['LABEL{}'.format(np.random.choice(range(5))).encode('utf-8')]
)),
'image_raw': _bytes_feature(raw)
}))阅读后,我对image_raw特性进行了解码,因为它将字节字符串转换为数字,这正是我想要的。但是,我的label应该是原始字符串,width/height应该是原始数字:
features = {
'width': tf.FixedLenFeature([], tf.int64),
'height': tf.FixedLenFeature([], tf.int64),
'label': tf.FixedLenFeature([], tf.string),
'image_raw': tf.FixedLenFeature([], tf.string),
}
parsed_features = tf.parse_single_example(example_proto, features)
# Decode the raw bytes so it becomes a tensor with type.
image = tf.decode_raw(parsed_features['image_raw'], tf.uint16)
# Is parsed_features['label'] a valid string now?
# Are parsed_features['width'] and ['height'] good to use now?我猜只有当我把数字数据写成字节字符串时才使用decode_raw --这是对的吗?
发布于 2018-02-19 17:45:09
https://stackoverflow.com/questions/48865823
复制相似问题