You need to enable JavaScript to run this app. 使用tflite_model_maker导入Pascal VOC训练时出现KeyError: 'pose'报错
优惠活动
大模型
产品
解决方案
定价
更多

使用tflite_model_maker导入Pascal VOC训练时出现KeyError: 'pose'报错

报错原因

tflite_model_maker内置的Pascal VOC格式解析逻辑,默认要求每个标注目标必须包含pose字段用于记录目标姿态信息,但从CVAT导出的Pascal VOC格式标注文件默认不会生成<pose>标签,解析时读取不到对应字段就会触发KeyError。

解决方案
  • 方法一:批量补全所有XML标注文件的pose字段
    不需要修改源码,兼容性最好,运行以下Python脚本遍历所有标注文件,给每个目标节点补全默认值为Unspecified的pose标签即可:
import os
import xml.etree.ElementTree as ET

# 替换为你自己的annotations文件夹路径
anno_dir = "data/annotations"
for xml_file in os.listdir(anno_dir):
    if not xml_file.endswith(".xml"):
        continue
    xml_path = os.path.join(anno_dir, xml_file)
    tree = ET.parse(xml_path)
    root = tree.getroot()
    for obj in root.findall("object"):
        # 不存在pose标签就新增
        if obj.find("pose") is None:
            pose_ele = ET.SubElement(obj, "pose")
            pose_ele.text = "Unspecified"
    tree.write(xml_path)
  • 方法二:修改tflite_model_maker源码兼容缺失字段
    找到报错堆栈里的create_pascal_tfrecord.py文件,定位到第176行代码:
    原代码:poses.append(obj['pose'].encode('utf8'))
    修改为:poses.append(obj.get('pose', 'Unspecified').encode('utf8'))
    修改后解析时如果找不到pose字段会自动用默认值填充,不需要修改标注文件。

内容的提问来源于stack exchange,提问作者lukew3

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 11:00:04