Tensorflow 2:序列化并解码时形状不匹配

2024-07-02 04:53:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个a形张量(300256256)。 我想序列化以另存为tfrecord格式。 但我不能把它转换成相同形状的张量

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])

如果我运行上面的代码,我会得到一个形状错误:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 19660806 values, but the requested shape has 19660800 [Op:Reshape]

当我序列化或解码时,似乎添加了6个浮点数。(非常奇怪)


Tags: toionumpyconvert序列化tf格式type