扇贝丫丫 2022-12-29 17:14 采纳率: 0%
浏览 263

yolov5训练模型报错

在谷歌colab上训练yolov5 2.0的模型,训练时遇到问题如下:

Analyzing anchors... Best Possible Recall (BPR) = 1.0000
Image sizes 640 train, 640 test
Using 2 dataloader workers
Starting training for 300 epochs...

     Epoch   gpu_mem      GIoU       obj       cls     total   targets  img_size
  0% 0/93 [00:14<?, ?it/s]
Traceback (most recent call last):
  File "train.py", line 469, in <module>
    train(hyp, tb_writer, opt, device)
  File "train.py", line 291, in train
    loss, loss_items = compute_loss(pred, targets.to(device), model)  # scaled by batch_size
  File "/content/yolov5-2.0/utils/utils.py", line 444, in compute_loss
    tcls, tbox, indices, anchors = build_targets(p, targets, model)  # targets
  File "/content/yolov5-2.0/utils/utils.py", line 533, in build_targets
    a, t = at[j], t.repeat(na, 1, 1)[j]  # filter
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

这个是什么原因造成的,需要怎样修改?求能指点迷津!

  • 写回答

2条回答 默认 最新

  • ShowMeAI 2022-12-29 17:56
    关注

    看错误应该是t和indices使用了不同的设备存储。


    解决办法是将indices移动到与t相同的设备上,或者将t移动到CPU上。你可以使用indices.to(device)或t.to("cpu")来实现。

    indices = indices.to(device)
    t = t.repeat(na, 1, 1)[indices]
    

    或者:

    t = t.to("cpu")
    t = t.repeat(na, 1, 1)[indices]
    
    评论

报告相同问题?

问题事件

  • 创建了问题 12月29日