深度学习python之制作VOC数据集中的xml文件(Annotations文件夹内)
2017-12-20 11:59
525 查看
深度学习python之制作VOC数据集中的xml文件(Annotations文件夹内)
调用格式
其中
image_name 没有扩展名,比如 ‘000001’
xmin_tuple = []
xmin_tuple.append(xmin) # xmin 为坐标值,有多少物体,len(xmin_tuple)就是多少
某一打印结果为:
from lxml.etree import Element, SubElement, tostring from xml.dom.minidom import parseString def make_xml(xmin_tuple, ymin_tuple, xmax_tuple, ymax_tuple, image_name): node_root = Element('annotation') node_folder = SubElement(node_root, 'folder') node_folder.text = 'VOC' node_filename = SubElement(node_root, 'filename') node_filename.text = image_name + '.jpg' node_object_num = SubElement(node_root, 'object_num') node_object_num.text = str(len(xmin_tuple)) node_size = SubElement(node_root, 'size') node_width = SubElement(node_size, 'width') node_width.text = '512' node_height = SubElement(node_size, 'height') node_height.text = '384' node_depth = SubElement(node_size, 'depth') node_depth.text = '3' for i in xrange(len(xmin_tuple)): node_object = SubElement(node_root, 'object') node_name = SubElement(node_object, 'name') node_name.text = 'ship' node_difficult = SubElement(node_object, 'difficult') node_difficult.text = '0' node_bndbox = SubElement(node_object, 'bndbox') node_xmin = SubElement(node_bndbox, 'xmin') node_xmin.text = str(xmin_tuple[i]) node_ymin = SubElement(node_bndbox, 'ymin') node_ymin.text = str(ymin_tuple[i]) node_xmax = SubElement(node_bndbox, 'xmax') node_xmax.text = str(xmax_tuple[i]) node_ymax = SubElement(node_bndbox, 'ymax') node_ymax.text = str(ymax_tuple[i]) xml = tostring(node_root, pretty_print = True) dom = parseString(xml) #print xml 打印查看结果 return dom
调用格式
dom = make_xml(xmin_tuple, ymin_tuple, xmax_tuple, ymax_tuple, image_name) xml_name = os.path.join(save_xml_path, image_name + '.xml') with open(xml_name, 'w') as f: f.write(dom.toprettyxml(indent='\t', encoding='utf-8'))
其中
image_name 没有扩展名,比如 ‘000001’
xmin_tuple = []
xmin_tuple.append(xmin) # xmin 为坐标值,有多少物体,len(xmin_tuple)就是多少
某一打印结果为:
<annotation> <folder>VOC</folder> <filename>000077.jpg</filename> <object_num>3</object_num> <size> <width>512</width> <height>384</height> <depth>3</depth> </size> <object> <name>ship</name> <difficult>0</difficult> <bndbox> <xmin>20</xmin> <ymin>1</ymin> <xmax>50</xmax> <ymax>67</ymax> </bndbox> </object> <object> <name>ship</name> <difficult>0</difficult> <bndbox> <xmin>1</xmin> <ymin>119</ymin> <xmax>27</xmax> <ymax>201</ymax> </bndbox> </object> <object> <name>ship</name> <difficult>0</difficult> <bndbox> <xmin>290</xmin> <ymin>1</ymin> <xmax>409</xmax> <ymax>365</ymax> </bndbox> </object> </annotation>
相关文章推荐
- Comprehensive learning path – Data Science in Python深度学习路径-用python进行数据学习
- 限时领取 | 10G+AI人工智能/复杂系统/数据挖掘/深度学习/Python资料
- 深度学习-CAFFE利用CIFAR10网络模型训练自己的图像数据获得模型-1.制作自己的数据集
- 大数据、机器学习、深度学习Python库必备速查表,快来收藏!
- 免费领取 | 10G+AI人工智能/复杂系统/数据挖掘/深度学习/Python资料
- 深度学习,制作类似cifar10图像数据集
- 深度学习数据整理——Python读写xml文件
- 免费领取 | 140G+AI人工智能/复杂系统/数据挖掘/深度学习/Python资料
- Comprehensive learning path – Data Science in Python深度学习路径-用python进行数据学习
- Python数据挖掘,AI人工智能,机器学习,深度学习,高级项目实战
- Python 深度学习模型训练数据预处理 批文件重命名 os.listdir方法 os.rename方法 file.spilt方法
- python-框架-网页爬虫-文本处理-科学计算-可视化-机器学习-数据挖掘-深度学习
- 深度学习数据整理——Python常用的遍历操作
- 【深度学习】笔记14 windows下caffe的python接口的配置(数据的可视化环境)
- 大数据、机器学习、深度学习Python库必备速查表,快来收藏!
- Python---利用scipy.misc等库对jpg以及png等图像数据预处理(用于深度学习喂数据)
- python 处理pascal voc数据 读取xml文件
- (Python实现)数据PCA降维白化和L2归一化-深度学习实践常用数据预处理
- Python源码学习笔记(1 基本数据类型)
- python学习(一) 如何解析xml文件