我使用tflite_model_maker包来训练object_detector tflite模型。当我尝试从pascal voc导入数据时,我得到KeyError: 'pose'错误。我做错了什么?
Traceback (most recent call last):
File "2main.py", line 7, in <module>
dataloader = object_detector.DataLoader.from_pascal_voc('data/images', 'data/annotations', label_map=label_map)
File "/home/luke/moneyDetector/venv/lib/python3.8/site-packages/tensorflow_examples/lite/model_maker/core/data_util/object_detector_dataloader.py", line 217, in from_pascal_voc
cache_writer.write_files(
File "/home/luke/moneyDetector/venv/lib/python3.8/site-packages/tensorflow_examples/lite/model_maker/core/data_util/object_detector_dataloader_util.py", line 252, in write_files
tf_example = create_pascal_tfrecord.dict_to_tf_example(
File "/home/luke/moneyDetector/venv/lib/python3.8/site-packages/tensorflow_examples/lite/model_maker/third_party/efficientdet/dataset/create_pascal_tfrecord.py", line 176, in dict_to_tf_example
poses.append(obj['pose'].encode('utf8'))
KeyError: 'pose'
编辑:对于进一步的上下文,我认为注释是通过从cvat
导出创建的。这是因为你的注释文件没有属性'pose'。当我使用CVAT作为注释工具并意识到"姿势"one_answers"截断"缺失时,我也遇到了同样的问题。因此,我将我的注释数据导入到另一个注释工具(LabelImg),然后再次导出到pascal voc。我不认为这是最好的方法,但它有效。
当我从CVAT工具导出数据时,我也遇到了同样的问题,我已经设法用这个脚本修复了它:
import xmltodict
from dict2xml import dict2xml
import glob
def postprocessor(path, key, value):
if key == 'object':
if 'pose' not in value:
value['pose'] = 'Unspecified'
value['bndbox']['xmax'] = int(float(value['bndbox']['xmax']))
value['bndbox']['xmin'] = int(float(value['bndbox']['xmin']))
value['bndbox']['ymax'] = int(float(value['bndbox']['ymax']))
value['bndbox']['ymin'] = int(float(value['bndbox']['ymin']))
if not value:
return key, []
return key, value
xml_files = glob.glob(
f"{annotations_in}/*.xml",
recursive=True)
for xml_file in xml_files:
# Open the file and read the contents
with open(xml_file, 'r', encoding='utf-8') as file:
src_xml = file.read()
my_dict = xmltodict.parse(src_xml, postprocessor=postprocessor)
dist_xml = dict2xml(my_dict)
with open(xml_file, 'w', encoding='utf-8') as file:
file.write(dist_xml)