UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x99 in position 661: illegal multibyte sequence
1.使用Yolov5 跑模型,输入命令python train.py出错
Traceback (most recent call last):
File "train.py", line 543, in <module>
train(hyp, opt, device, tb_writer)
File "train.py", line 64, in train
data_dict = yaml.load(f, Loader=yaml.SafeLoader) # data dict
File "J:\WorkSoft\envs\Yolov550\lib\site-packages\yaml\__init__.py", line 112, in load
loader = Loader(stream)
File "J:\WorkSoft\envs\Yolov550\lib\site-packages\yaml\loader.py", line 34, in __init__
Reader.__init__(self, stream)
File "J:\WorkSoft\envs\Yolov550\lib\site-packages\yaml\reader.py", line 85, in __init__
self.determine_encoding()
File "J:\WorkSoft\envs\Yolov550\lib\site-packages\yaml\reader.py", line 124, in determine_encoding
self.update_raw()
File "J:\WorkSoft\envs\Yolov550\lib\site-packages\yaml\reader.py", line 178, in update_raw
data = self.stream.read(size)
UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 661: illegal multibyte sequence
2.跟踪代码到train.py的64行,代码如下

3.修改第64行with open(opt.data) as f : 为with open(opt.data, encoding=‘utf-8’) as f :
with open(opt.data,encoding='utf-8') as f:
4.正常运行。
本文讲述了在使用Yolov5训练模型时遇到的UnicodeDecodeError,通过修改文件编码从'gbk'改为'utf-8'解决了问题。关键步骤是在yaml文件读取时指定正确的编码,确保数据文件正确解析。
19万+





