Python 如何使用TensorFlow解码tfrecords中存储的字节列表?

Python 如何使用TensorFlow解码tfrecords中存储的字节列表?,python,tensorflow,image-processing,deep-learning,tfrecord,Python,Tensorflow,Image Processing,Deep Learning,Tfrecord,我已将不同数量的图像存储为字节列表: img.append(trajectory_step['img'].tostring()) feature['img'] = _bytes_feature(img) ... example = tf.train.Example(features=tf.train.Features(feature=feature)) writer.write(example.SerializeToString()) 我还确保保存图像的数量,以便以后解码(experiment

我已将不同数量的图像存储为字节列表:

img.append(trajectory_step['img'].tostring())
feature['img'] = _bytes_feature(img)
...
example = tf.train.Example(features=tf.train.Features(feature=feature))
writer.write(example.SerializeToString())
我还确保保存图像的数量,以便以后解码(
experiment\u length

现在我无法按以下方式解码图像:

features = {
'img': tf.VarLenFeature(tf.string),
...
}
parsed_features = tf.parse_single_example(example_proto, features)
img = tf.decode_raw(parsed_features['img'], out_type=tf.uint8)
img = tf.reshape(img, tf.stack([experiment_length, 120, 160, 3]))
这会产生以下错误:

TypeError:应将字符串传递给op的参数“bytes” “破译”,明白了吗 改为“SparseTensor”类型

如果我选择使用
tf.FixedLenFeature
我会得到以下错误:

tensorflow.python.framework.errors\u impl.InvalidArgumentError:名称: ,关键字:img,索引:0。字节数值!=预期。 值大小:5,但输出形状:[]

如何正确解码字节列表?和:在这种情况下,
tf.VarLenFeature
正确吗,还是应该使用
tf.FixedLenFeature

多谢各位