yolov5训练报错

yolov5训练报错

Transferred 342/349 items from weights\yolov5s.pt
Scaled weight_decay = 0.0005
optimizer: SGD with parameter groups 57 weight (no decay), 60 weight, 60 bias
train: Scanning ‘C:\Users\Administrator\Desktop\yolov5-6.1-distillation\VOCdevkit\labels\train.cache’ images and labels… 1104 found, 0 missing, 0 empty, 0 corrupt: 100%|██████████| 1104/1104 [00:00<?, ?it/s]
val: Scanning ‘C:\Users\Administrator\Desktop\yolov5-6.1-distillation\VOCdevkit\labels\val.cache’ images and labels… 312 found, 0 missing, 0 empty, 0 corrupt: 100%|██████████| 312/312 [00:00<?, ?it/s]
module ‘signal’ has no attribute ‘SIGALRM’
AutoAnchor: 5.28 anchors/target, 1.000 Best Possible Recall (BPR). Current anchors are a good fit to dataset
Image sizes 640 train, 640 val
Using 4 dataloader workers
Logging results to runs\train\yolov5s-baseline5
Starting training for 100 epochs…
Epoch gpu_mem box obj cls labels img_size
0%| | 0/69 [00:04<?, ?it/s]
Traceback (most recent call last):
File “C:\Users\Administrator\Desktop\yolov5-6.1-distillation\train.py”, line 643, in
main(opt)
File “C:\Users\Administrator\Desktop\yolov5-6.1-distillation\train.py”, line 539, in main
train(opt.hyp, opt, device, callbacks)
File “C:\Users\Administrator\Desktop\yolov5-6.1-distillation\train.py”, line 331, in train
loss, loss_items = compute_loss(pred, targets.to(device)) # loss scaled by batch_size
File “C:\Users\Administrator\Desktop\yolov5-6.1-distillation\utils\loss.py”, line 120, in call
tcls, tbox, indices, anchors = self.build_targets(p, targets) # targets
File “C:\Users\Administrator\Desktop\yolov5-6.1-distillation\utils\loss.py”, line 217, in build_targets
indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices
RuntimeError: result type Float can’t be cast to the desired output type __int64
Process finished with exit code 1

补充:readme中提到pytorch1.8.1,但实际pytorch是1.11.0

解决方法:

将loss.py中gain = torch.ones(7, device=targets.device)改为gain = torch.ones(7, device=targets.device).long()即可。原因是新版本的torch无法自动执行此转换,旧版本torch可以。

loss.py在utils文件夹下,ctrl+f搜索gain,找到
第一:gain = torch.ones(7, device=targets.device),将其修改为gain = torch.ones(7, device=targets.device).long()
第二:gain = torch.ones(7 + nc, device=targets.device),将其改为gain = torch.ones(7 + nc, device=targets.device).long()
也就是改两处,问题解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

唐丶晚笙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值