:punch: Prepare VOC format datasets for ultralytics/yolov3 & yolov5
GNU General Public License v3.0
196
stars
57
forks
source link
File "D:\Program Files\Python\Python37\lib\xml\etree\ElementTree.py", line 598, in parse self._root = parser._parse_whole(source) UnicodeDecodeError: 'gbk' codec can't decode byte 0x87 in position 37: illegal multibyte sequence #2
Open
wemindful opened 4 years ago
File "D:\Program Files\Python\Python37\lib\xml\etree\ElementTree.py", line 598, in parse self._root = parser._parse_whole(source) UnicodeDecodeError: 'gbk' codec can't decode byte 0x87 in position 37: illegal multibyte sequence
解决办法:
def convert_annotation(year, image_id, classes): in_file = open('Annotations/%s.xml' % (image_id),encoding="UTF-8") #将数据集放于当前目录下 out_file = open('voc_labels/%s.txt' % (image_id), 'w') tree = ET.parse(in_file) root = tree.getroot() size = root.find('size') w = int(size.find('width').text) h = int(size.find('height').text) for obj in root.iter('object'): difficult = obj.find('difficult').text cls = obj.find('name').text if cls not in classes or int(difficult) == 1: continue cls_id = classes.index(cls) xmlbox = obj.find('bndbox') b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text)) bb = convert((w, h), b) out_file.write( str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')