UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x99 in position 661: illegal multibyte sequence

本文讲述了在使用Yolov5训练模型时遇到的UnicodeDecodeError,通过修改文件编码从'gbk'改为'utf-8'解决了问题。关键步骤是在yaml文件读取时指定正确的编码,确保数据文件正确解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.正常运行。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值