I have following feature written to my training TFRecord:
feature = {'label': _int64_feature(gt),
'image': _bytes_feature(tf.compat.as_bytes(im.tostring())),
'height': _int64_feature(h),
'width': _int64_feature(w)}
and I am reading it like:
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)
whereas my parse_func looks like this:
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
Now, I want to get the shape of image and label like:
image.get_shape().as_list()
which prints
[None, None, None]
instead of
[None, 224, 224] (size of the image (batch, width, height))
Is there any function which can give me the size of these tensors?
As your map function "parse_func" is part of the graph as an operation and it doesn't know the fixed size of your input and labels a priori, using get_shape() wouldn't return the expected fixed shape.
If your image, label shape is fixed, as a hack, you can try reshaping your image, labels with the already known size(this would in effect wouldn't do anything at all, but will explicitly set the size of the output tensors).
ex. image = tf.reshape(image, [224,224])
With this you should be able to get the get_shape() result as expected.