解决报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xab in position 105: illegal multibyte sequence
目标检测YOLO系列转数据集格式的时候报错如下:
最后发现是编码器的问题,解决方法如下:
def convert_annotation(image_id):
in_file = open('data/Annotations/%s.xml' % (image_id), 'r', encoding="UTF-8")
out_file = open('data/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)
在in_file = open(‘data/Annotations/%s.xml’ % (image_id)后加上 ‘r’, encoding=“UTF-8”。
再次运行代码,报错已经解决。