运行yolo代码中,遇到的错误,以及解决办法

一,问题描述:

Traceback (most recent call last):
  File "/mnt/YOLOv5-7.0-DSConv-biformer/train.py", line 704, in <module>
    main(opt)
  File "/mnt/YOLOv5-7.0-DSConv-biformer/train.py", line 596, in main
    train(opt.hyp, opt, device, callbacks)
  File "/mnt/YOLOv5-7.0-DSConv-biformer/train.py", line 358, in train
    scaler.scale(loss).backward()
  File "/root/miniconda3/envs/myconda/lib/python3.9/site-packages/torch/_tensor.py", line 396, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
  File "/root/miniconda3/envs/myconda/lib/python3.9/site-packages/torch/autograd/__init__.py", line 173, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: scatter_add_cuda_kernel does not have a deterministic implementation, but you set 'torch.use_deterministic_algorithms(True)'. You can turn off determinism just for this operation, or you can use the 'warn_only=True' option, if that's acceptable for your application. You can also file an issue at https://github.com/pytorch/pytorch/issues to help us prioritize adding deterministic support for this operation.

1.解决方案

提示:在train.py文件中的scaler.scale(loss).backward()前添加torch.use_deterministic_algorithms(False)

#  Backward
torch.use_deterministic_algorithms(False)     #添加这句代码
scaler.scale(loss).backward()

pycharm中可以使用Ctr+F 可以查找代码

2.解决方案

打开utils–>general.py文件
找到torch.use_deterministic_algorithms(True)
True改成False

def init_seeds(seed=0, deterministic=False):
    # Initialize random number generator (RNG) seeds https://pytorch.org/docs/stable/notes/randomness.html
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)  # for Multi-GPU, exception safe
    # torch.backends.cudnn.benchmark = True  # AutoBatch problem https://github.com/ultralytics/yolov5/issues/9287
    if deterministic and check_version(torch.__version__, '1.12.0'):  # https://github.com/ultralytics/yolov5/pull/8213
        torch.use_deterministic_algorithms(False)
        torch.backends.cudnn.deterministic = True
        os.environ['CUBLAS_WORKSPACE_CONFIG'] = ':4096:8'
        os.environ['PYTHONHASHSEED'] = str(seed)

二,问题描述

ModuleNotFoundError: No module named 'yaml'

1,解决办法:

pip install pyaml

注意安装时是pyaml

三,问题描述

Traceback (most recent call last):
  File "/mnt/yolov7-DSConv-att/train.py", line 617, in <module>
    train(hyp, opt, device, tb_writer)
  File "/mnt/yolov7-DSConv-att/train.py", line 89, in train
    model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device)  # create
  File "/mnt/yolov7-DSConv-att/models/yolo.py", line 528, in __init__
    self.model, self.save = parse_model(deepcopy(self.yaml), ch=[ch])  # model, savelist
  File "/mnt/yolov7-DSConv-att/models/yolo.py", line 763, in parse_model
    c1, c2 = ch[f], args[0]
TypeError: list indices must be integers or slices, not list

1,解决办法


报错时的源代码
在这里插入图片描述

二,问题描述

Traceback (most recent call last):
  File "/mnt/yolov7-GhostNet/train.py", line 617, in <module>
    train(hyp, opt, device, tb_writer)
  File "/mnt/yolov7-GhostNet/train.py", line 89, in train
    model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device)  # create
  File "/mnt/yolov7-GhostNet/models/yolo.py", line 544, in __init__
    m.stride = torch.tensor([s / x.shape[-2] for x in self.forward(torch.zeros(1, ch, s, s))])  # forward
  File "/mnt/yolov7-GhostNet/models/yolo.py", line 599, in forward
    return self.forward_once(x, profile)  # single-scale inference, train
  File "/mnt/yolov7-GhostNet/models/yolo.py", line 625, in forward_once
    x = m(x)  # run
  File "/root/miniconda3/envs/myconda/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/mnt/yolov7-GhostNet/models/common.py", line 2058, in forward
    X = torch.einsum('bkhw,bckhw->bchw', [W, X])    # b * c * h_ * w_
  File "/root/miniconda3/envs/myconda/lib/python3.9/site-packages/torch/functional.py", line 358, in einsum
    return einsum(equation, *_operands)
  File "/root/miniconda3/envs/myconda/lib/python3.9/site-packages/torch/functional.py", line 360, in einsum
    return _VF.einsum(equation, operands)  # type: ignore[attr-defined]
RuntimeError: einsum(): operands do not broadcast with remapped shapes [original->remapped]: [1, 9, 18, 18]->[1, 1, 18, 18, 9] [1, 256, 9, 16, 16]->[1, 256, 16, 16, 9]

1,解决方案

这个错误目前没有解决

三,问题描述

Traceback (most recent call last):
  File "/mnt/yolov7/train.py", line 617, in <module>
    train(hyp, opt, device, tb_writer)
  File "/mnt/yolov7/train.py", line 246, in train
    dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt,
  File "/mnt/yolov7/utils/datasets.py", line 69, in create_dataloader
    dataset = LoadImagesAndLabels(path, imgsz, batch_size,
  File "/mnt/yolov7/utils/datasets.py", line 392, in __init__
    cache, exists = torch.load(cache_path), True  # load
  File "/root/miniconda3/envs/myconda/lib/python3.9/site-packages/torch/serialization.py", line 713, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/root/miniconda3/envs/myconda/lib/python3.9/site-packages/torch/serialization.py", line 920, in _legacy_load
    magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: STACK_GLOBAL requires str

1,解决办法

产生原因:在过去对当前数据集进行过训练,导致在数据集文件夹中生成了.cache的缓存文件
解决办法:找到数据集文件夹中的全部.cache文件,并将他们全部删除
注意:.cache文件也有可能在数据集的images和labels文件夹中,要注意仔细查找

四,问题描述

Traceback (most recent call last):
  File "/mnt/yolov7-p2+p6/train.py", line 26, in <module>
    from models.yolo import Model
  File "/mnt/yolov7-p2+p6/models/yolo.py", line 10, in <module>
    from models.EfficientFormerV2 import *
  File "/mnt/yolov7-p2+p6/models/EfficientFormerV2.py", line 14, in <module>
    from timm.models.layers.helpers import to_2tuple
ModuleNotFoundError: No module named 'timm.models.layers.helpers'

1,解决办法

解决办法:卸载timm包,安装旧版本,亲测0.6.13版本可运行

pip uninstall timm
pip install timm==0.6.13

五,问题描述

Traceback (most recent call last):
  File "/mnt/yolov7-p2+p6/train.py", line 616, in <module>
    train(hyp, opt, device, tb_writer)
  File "/mnt/yolov7-p2+p6/train.py", line 251, in train
    assert mlc < nc, 'Label class %g exceeds nc=%g in %s. Possible class labels are 0-%g' % (mlc, nc, opt.data, nc - 1)
AssertionError: Label class 1 exceeds nc=1 in ./data/coco.yaml. Possible class labels are 0-0

1,解决办法

这个错误说的是标签对不上,仔细检查标注的txt文件,发现标签是1,只分了一个类,标签是1,明显错误
解决办法:要不增加0类的数据,要不将1改成0

六 问题描述

Traceback (most recent call last):
  File "/mnt/yolov7-EVC_block/train.py", line 26, in <module>
    from models.yolo import Model
  File "/mnt/yolov7-EVC_block/models/yolo.py", line 948
    elif m is EVCBlock:
TabError: inconsistent use of tabs and spaces in indentation

解决办法

这个错误说的是 出现错误的缩进,找到问题行 修改缩进空格即可

  • 15
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值