python解析XML的三种方式
https://www.cnblogs.com/xiaobingqianrui/p/8405813.html

主要用xml.etree.ElementTree模块(简称 ET)来解析xml文件,它提供了轻量级的Python式的API。读取VOC数据集大致流程如下:

import xml.etree.ElementTree as ET

tree = ET.parse(file_name)
root = tree.getroot()
# 从size节点中读取宽高
size=root.find('size')
width = float(size.find('width').text)
height = float(size.find('height').text)
print(width,height)
        
for obj in root.iter('object'):
    xml_box = obj.find('bndbox')
    xmin = (int(xml_box.find('xmin').text))
    ymin = (int(xml_box.find('ymin').text))
    xmax = (int(xml_box.find('xmax').text))
    ymax = (int(xml_box.find('ymax').text))
    
	captionList = obj.findall('class') # find只能查找一个,findall可以查找所有的,class名可以换为其他子节点名

Pascal voc 数据集xml格式解析
https://blog.csdn.net/weixin_41278720/article/details/84872064

python xml提取多重标签内容
https://blog.csdn.net/qq_36076233/article/details/78989300

Logo

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

更多推荐