Python 将tfrecords中的原始字节解码为tf.feature\u column.numeric\u column功能

Python 将tfrecords中的原始字节解码为tf.feature\u column.numeric\u column功能,python,tensorflow,tfrecord,Python,Tensorflow,Tfrecord,我有一个tfrecords文件,将图像存储为ByTestRing。我想将此功能列定义为tf.feature\u column.numeric\u column(“image”,shape=[64,64],dtype=tf.float32),但由于它没有存储为tfrecords文件中的float\u列表,所以这不起作用 然后我尝试使用我定义为的numeric_列的normalizer_fn参数 def decode(image_bytestring): img = tf.reshape(t

我有一个tfrecords文件,将图像存储为ByTestRing。我想将此功能列定义为
tf.feature\u column.numeric\u column(“image”,shape=[64,64],dtype=tf.float32)
,但由于它没有存储为tfrecords文件中的float\u列表,所以这不起作用

然后我尝试使用我定义为的numeric_列的normalizer_fn参数

def decode(image_bytestring):
    img = tf.reshape(tf.decode_raw(image_bytestring, tf.uint8), [28, 28])
    img = tf.cast(img, tf.float32)
    return img

...

examples = tf.parse_example(
            serialized_batch,
            tf.feature_column.make_parse_example_spec(feature_columns))
然而,第一个问题是,由这个feature\u列生成的parse spec
FixedLenFeature(shape=(28,28),dtype=tf.float32,default\u value=None)
表示在float32实际存储为字符串时解析它,这会导致错误。因此,不使用解码功能

在使用tf.feature_列时,除了将图像存储为tfrecord中的float_列表之外,还有其他解决方法吗


似乎有一个静态类型系统可以很好地保证映射功能的功能类型正确。

也许您可以将图像存储为字符串字节,然后按照常见的方式读取图像

feature_map = { 'image': tf.FixedLenFeature([], dtype=tf.string,default_value='') }
features = tf.parse_single_example(example_serialized, feature_map)
image_buffer = features['image']
image = tf.image.decode_image(image_buffer, ...)