We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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')
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')
The text was updated successfully, but these errors were encountered:
No branches or pull requests
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')
The text was updated successfully, but these errors were encountered: