首页 > 解决方案 > 如何解析 tfds.features.Sequence 对象?它与 tf.io.FixedLenSequenceFeature 不兼容

问题描述

最近我试图在 Wider-Face 数据集上训练一个模型。我发现它已预建在 tfds 中(https://www.tensorflow.org/datasets/catalog/wider_face)。但是我很难解析它。它的特征图具有以下形式 -

FeaturesDict({
'faces': Sequence({
    'bbox': BBoxFeature(shape=(4,), dtype=tf.float32),
    'blur': tf.uint8,
    'expression': tf.bool,
    'illumination': tf.bool,
    'invalid': tf.bool,
    'occlusion': tf.uint8,
    'pose': tf.bool,
}),
'image': Image(shape=(None, None, 3), dtype=tf.uint8),
'image/filename': Text(shape=(), dtype=tf.string),})

所以我将以下嵌套字典传递给 tf.io.parse_single_example

feature_description = {'faces': {
    'bbox': tf.io.FixedLenFeature([], dtype=tf.float32),
    'blur': tf.io.FixedLenFeature([], dtype=tf.uint8),
    'expression': tf.io.FixedLenFeature([], dtype=tf.bool),
    'illumination': tf.io.FixedLenFeature([], dtype=tf.bool),
    'invalid': tf.io.FixedLenFeature([], dtype=tf.bool),
    'occlusion': tf.io.FixedLenFeature([], dtype=tf.uint8),
    'pose': tf.io.FixedLenFeature([], dtype=tf.bool),
},
'image': tf.io.FixedLenFeature([], dtype=tf.uint8),
'image/filename': tf.io.FixedLenFeature([], dtype=tf.string),} 

但它给了我一个 ValueError: Unsupported dict 的值错误。后来我还了解到,Sequence 不支持 tf.io.FixedLenSequenceFeature 类型的功能。

请让我知道如何解析这种类型的 TFRecords。我没有找到太多关于如何使用构建到 Tensorflow 中的对象检测数据集的文档,因此提供一些示例链接也会有所帮助。

谢谢

标签: tensorflowdeep-learningcomputer-visionobject-detectiontensorflow-datasets

解决方案


推荐阅读