解决UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x84 in position 285: illegal multibyte sequence

解决报错UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x84 in position 285: illegal multibyte sequence

下载github上yolov5的链接:https://github.com/ultralytics/yolov5/tree/v5.0


问题描述

之前运行yolov5 train.py没出现错误,今天再次运行报错UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x84 in position 285: illegal multibyte sequence

D:\Anaconda\envs\pytorch\python.exe H:/PycharmProject/yolov5-5.0/train.py
github: skipping check (not a git repository)
YOLOv5  2022-3-29 torch 1.11.0 CUDA:0 (NVIDIA GeForce 940MX, 2047.875MB)

Namespace(weights='yolov5s.pt', cfg='', data='data/coco128.yaml', hyp='data/hyp.scratch.yaml', epochs=300, batch_size=8, img_size=[640, 640], rect=False, resume=False, nosave=False, notest=False, noautoanchor=False, evolve=False, bucket='', cache_images=False, image_weights=False, device='', multi_scale=False, single_cls=False, adam=False, sync_bn=False, local_rank=-1, workers=0, project='runs/train', entity=None, name='exp', exist_ok=False, quad=False, linear_lr=False, label_smoothing=0.0, upload_dataset=False, bbox_interval=-1, save_period=-1, artifact_alias='latest', world_size=1, global_rank=-1, save_dir='runs\\train\\exp9', total_batch_size=8)
tensorboard: Start with 'tensorboard --logdir runs/train', view at http://localhost:6006/
hyperparameters: lr0=0.01, lrf=0.2, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0
Traceback (most recent call last):
  File "H:\PycharmProject\yolov5-5.0\train.py", line 546, in <module>
    train(hyp, opt, device, tb_writer)
  File "H:\PycharmProject\yolov5-5.0\train.py", line 64, in train
    data_dict = yaml.load(f, Loader=yaml.SafeLoader)  # data dict
  File "D:\Anaconda\envs\pytorch\lib\site-packages\yaml\__init__.py", line 79, in load
    loader = Loader(stream)
  File "D:\Anaconda\envs\pytorch\lib\site-packages\yaml\loader.py", line 34, in __init__
    Reader.__init__(self, stream)
  File "D:\Anaconda\envs\pytorch\lib\site-packages\yaml\reader.py", line 85, in __init__
    self.determine_encoding()
  File "D:\Anaconda\envs\pytorch\lib\site-packages\yaml\reader.py", line 124, in determine_encoding
    self.update_raw()
  File "D:\Anaconda\envs\pytorch\lib\site-packages\yaml\reader.py", line 178, in update_raw
    data = self.stream.read(size)
UnicodeDecodeError: 'gbk' codec can't decode byte 0x84 in position 285: illegal multibyte sequence

Process finished with exit code 1

解决方案:

找到所有文件加上一句指令,encoding=‘utf-8’

具体如下:Ctrl + f 查找open

    with open(save_dir / 'hyp.yaml', 'w') as f:
    with open(save_dir / 'opt.yaml', 'w') as f:  
    with open(opt.data) as f:
    with open(results_file, 'a') as f:   
	with open(Path(ckpt).parent.parent /'opt.yaml') as f:
	with open(opt.hyp) as f:

添加代码:

,encoding='utf-8'
    with open(save_dir / 'hyp.yaml', 'w',encoding='utf-8') as f:
    with open(save_dir / 'opt.yaml', 'w',encoding='utf-8') as f:
    with open(opt.data,encoding='utf-8') as f:
	with open(results_file, 'a',encoding='utf-8') as f:
	with open(Path(ckpt).parent.parent /'opt.yaml',encoding='utf-8') as f:
	with open(opt.hyp,encoding='utf-8') as f:

一定要将每一个open后面都加上那句指令


参考链接:

https://blog.csdn.net/zhangpeterx/article/details/88663052
https://blog.csdn.net/weixin_46709219/article/details/112060945

  • 8
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值