I have a tensor A of shape (300,256,256). I want to serialize A to save as tfrecord format. But I cannot convert it back to tensor with same shape.
A = tf.convert_to_tensor( *a numpy array with float32 type* )
B = tf.io.serialize_tensor(A)
C = tf.reshape(tf.io.decode_raw(B, out_type=tf.float32),[300,256,256])
If I run the code above, I got a shape error:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 19660806 values, but the requested shape has 19660800 [Op:Reshape]
It seems that when I serialize or when I decode, 6 floats are added. (very weird)
Try using: tf.io.parse_tensor()
, instead of tf.io.decode_raw()
.
https://www.tensorflow.org/api_docs/python/tf/io/parse_tensor
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.