Home > other >  Python batch processing XML file (modify the values in the XML and saved)
Python batch processing XML file (modify the values in the XML and saved)

Time:11-28

In the production of voc data sets, often because of the path contains Chinese, an error
'GBK' codec can 't decode byte 0 x86 position in 119: illegal multibyte sequence
Put forward a method of batch change path:
 # - * - coding: utf-8 - * - 

The from XML. Etree. ElementTree import ElementTree, Element
The import XML. Etree. ElementTree as ET
The import pickled
The import OS
The from OS import listdir, getcwd
The from OS. Path import join


Def convert_annotation (image_id) :
In_file='C:/Users/xiaoming/Documents/yolov3/coco/label/' +' nomask '+' 06 % d % int (image_id) + 'XML'
Out_file='C:/Users/xiaoming/Documents/yolov3/coco/label/' +' nomask '+' 06 % d % int (image_id) + 'XML'
The tree=ET. Parse (in_file)

Root=tree. Getroot ()

For elem in root. The iter (" path ") :

New_elem='C:/Users/xiaoming/Documents/yolov3/coco/label'

Elem. Text=new_elem


Tree. Write (out_file)


For image_id in range (1100, 00) :

Convert_annotation (image_id)

  • Related