在线云训练平台导出数据集在AICUBE显示数据不合法
经过许多大佬指点之后发现是堪智在线平台导出的数据集中的xml文件缺少size字段,可以通过脚本给xml文件添加size片段,添加结束之后就可以在aicube上面训练数据了,下面是脚本代码。将这个脚本放在JPEGImages和Annotations同一目录下之后,使用Python执行该脚本,就可以添加size字段了下面是添加之后的xml文件。print(f"[跳过] {xml_file} 已有 <s
·
在嘉楠堪智在线开发平台制作完数据导出数据集,导出之后在aicube训练,但是显示数据不合法
这是voc数据集的格式
这两个是对应文件里面内容,xml文件和图片文件名一一对应
这个是xml文件内容
经过许多大佬指点之后发现是堪智在线平台导出的数据集中的xml文件缺少size字段,可以通过脚本给xml文件添加size片段,添加结束之后就可以在aicube上面训练数据了,下面是脚本代码
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}")
将这个脚本放在JPEGImages和Annotations同一目录下之后,使用Python执行该脚本,就可以添加size字段了下面是添加之后的xml文件
这样就可以在aicube上面合法训练了

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)