【发布时间】:2019-01-30 19:14:03
【问题描述】:
我的训练 TFRecord 中写入了以下功能:
feature = {'label': _int64_feature(gt),
'image': _bytes_feature(tf.compat.as_bytes(im.tostring())),
'height': _int64_feature(h),
'width': _int64_feature(w)}
我正在阅读它:
train_dataset = tf.data.TFRecordDataset(train_file)
train_dataset = train_dataset.map(parse_func)
train_dataset = train_dataset.shuffle(buffer_size=1)
train_dataset = train_dataset.batch(batch_size)
train_dataset = train_dataset.prefetch(batch_size)
而我的 parse_func 看起来像这样:
def parse_func(ex):
feature = {'image': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenSequenceFeature([], tf.int64, allow_missing=True),
'height': tf.FixedLenFeature([], tf.int64),
'width': tf.FixedLenFeature([], tf.int64)}
features = tf.parse_single_example(ex, features=feature)
image = tf.decode_raw(features['image'], tf.uint8)
height = tf.cast(features['height'], tf.int32)
width = tf.cast(features['width'], tf.int32)
im_shape = tf.stack([width, height])
image = tf.reshape(image, im_shape)
label = tf.cast(features['label'], tf.int32)
return image, label
现在,我想获得 image 和 label 的形状,例如:
image.get_shape().as_list()
打印
[无,无,无]
而不是
[None, 224, 224] (图片大小(batch, width, height))
有没有什么函数可以给我这些张量的大小?
【问题讨论】:
标签: tensorflow tensor tensorflow-datasets tfrecord