我想将一个张量保存为TFRecord格式。我尝试了以下代码:
import tensorflow as tf
x = tf.constant([[2.0, 3.0, 3.0],
[1.0, 5.0, 9.0]], dtype='float32')
x2 = tf.io.serialize_tensor(x)
# I understand that I can parse it using this:
# x3 = tf.io.parse_tensor(x2, 'float32')
record_file = 'temp.tfrecord'
with tf.io.TFRecordWriter(record_file) as writer:
writer.write(x2)
这给我报错:
TypeError: write(): incompatible function arguments. The following argument types are supported:
1. (self: tensorflow.python._pywrap_record_io.RecordWriter, record: str) -> None
我知道这可能是一个基础问题,但我在 TensorFlow 网站上阅读了一份指南,并在 StackOverflow 上搜索,但没有找到答案。