在线云训练平台导出数据集在aicube显示数据不合法

Viewed 347

重现步骤

在嘉楠堪智在线开发平台制作完数据导出的数据集,导出后想用aicube本地训练模型但显示数据不合法image.png
image.png

期待结果和实际结果

在嘉楠堪智在线开发平台制作完数据导出的数据集,我该怎么调整后用aicube训练模型,请各位老师指点
image.png

错误日志

2025-07-10 00:12:43,290: INFO maincontroller.py 479: 数据集不合法,请清洗数据集!
2025-07-10 00:12:43,290: ERROR maincontroller.py 480: Traceback (most recent call last):
File "D:\AICube_for_Windows\AICube\canaan_controller\maincontroller.py", line 459, in get_det_pro
File "D:\AICube_for_Windows\AICube\canaan_controller\voc2coco.py", line 275, in voc_to_coco
File "D:\AICube_for_Windows\AICube\canaan_controller\voc2coco.py", line 118, in parseXmlFiles
AttributeError: 'NoneType' object has no attribute 'find'

补充材料

文件夹格式符合
image.png
图片与标注文件同名
image.pngimage.png
xml文件里面格式
image.png

2 Answers

你好,在线训练平台导出的xml文件中缺少size字段,你可以使用如下python代码,保存成python脚本convert.py,放到数据集JPEGImages和Annotations同一层目录下,然后使用python执行该脚本:

import os
import cv2
import xml.etree.ElementTree as ET

# 路径配置
image_dir = "JPEGImages"
xml_dir = "Annotations"

# 遍历所有XML文件
for xml_file in os.listdir(xml_dir):
    if not xml_file.endswith(".xml"):
        continue

    xml_path = os.path.join(xml_dir, xml_file)
    tree = ET.parse(xml_path)
    root = tree.getroot()

    # 检查是否已经有 <size> 节点
    if root.find("size") is not None:
        print(f"[跳过] {xml_file} 已有 <size>")
        continue

    # 获取对应的图片路径
    img_filename = root.find("filename").text
    img_path = os.path.join(image_dir, img_filename)

    if not os.path.exists(img_path):
        print(f"[警告] 找不到对应图片:{img_filename}")
        continue

    # 读取图像大小
    img = cv2.imread(img_path)
    if img is None:
        print(f"[错误] 无法读取图像:{img_filename}")
        continue

    height, width, depth = img.shape

    # 创建 <size> 节点并插入到 <annotation> 下
    size_elem = ET.Element("size")
    ET.SubElement(size_elem, "width").text = str(width)
    ET.SubElement(size_elem, "height").text = str(height)
    ET.SubElement(size_elem, "depth").text = str(depth)

    root.insert(1, size_elem)  # 插入在 <filename> 之后更符合VOC结构

    # 保存修改后的XML
    tree.write(xml_path, encoding="utf-8", xml_declaration=True)
    print(f"[更新] 已添加 <size> 至 {xml_file}")

它会帮你添加size字段。添加结束后该数据集就可以在aicube上可用了。

成功解决,感谢大佬

大佬你好,请问这段代码生成的文件在K230上怎末不能正常运行啊

这是修改数据集的,不是在230上跑的

哥们,你这个数字训练模型训练好了吗,交流一下呗

并没有还在努力驯化。