Bobo-y / flexible-yolov5

More readable and flexible yolov5 with more backbone(gcn, resnet, shufflenet, moblienet, efficientnet, hrnet, swin-transformer, etc) and (cbam,dcn and so on), and tensorrt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

我用HRNet32作Backbone时,训练完出现了RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!这个问题

ChenShuai-CA opened this issue · comments

Traceback (most recent call last):
File "/media/shunde/Data/chenshuai/HRNet-yolov5/scripts/train.py", line 666, in
main(opt)
File "/media/shunde/Data/chenshuai/HRNet-yolov5/scripts/train.py", line 562, in main
train(opt.hyp, opt, device, callbacks)
File "/media/shunde/Data/chenshuai/HRNet-yolov5/scripts/train.py", line 451, in train
results, _, _ = eval.run(
File "/home/shunde/anaconda3/envs/helmet_detect/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/media/shunde/Data/chenshuai/HRNet-yolov5/scripts/eval.py", line 187, in run
out, train_out = model(im) if training else model(im) # inference, loss outputs
File "/home/shunde/anaconda3/envs/helmet_detect/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/media/shunde/Data/chenshuai/HRNet-yolov5/od/models/model.py", line 71, in forward
y = self.detection(list(out))
File "/home/shunde/anaconda3/envs/helmet_detect/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/media/shunde/Data/chenshuai/HRNet-yolov5/od/models/head/yolo.py", line 44, in forward
y[..., 0:2] = (y[..., 0:2] * 2 + self.grid[i]) * self.stride[i] # xy
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
这个问题我看是eval.py里面的问题,请问这个您有办法解决吗?

commented

@ChenShuai-CA 训练完后,单独加载权重只执行 eval.py 是可以的. 连在一起报错,我还得查查