TensorFlow2.0 编写的 tensor 转 example 的函数出现类型问题

相关代码:

# 将 tensor 的 xy 数据转化成 example 中的数据,并进行序列化

def serialize_example(x, y):

    """Converts x, y to tf.train.Example and serialize"""

    input_features = tf.train.FloatList(value = x)

    label = tf.train.FloatList(value = y)

    features = tf.train.Features(

        feature = {

            "input_features": tf.train.Feature(

                float_list = input_features),

            "label": tf.train.Feature(float_list = label)

        }

    )

    example = tf.train.Example(features = features)

    return example.SerializeToString()
TypeError: <tf.Tensor: id=249, shape=(), dtype=float32, numpy=0.63034356> has type <class 'tensorflow.python.framework.ops.EagerTensor'>, but expected one of: numbers.Real
数据类型<DatasetV1Adapter shapes: ((None, 8), (None, 1)), types: (tf.float32, tf.float32)>
不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^