PyTorch_YOLOv4
PyTorch_YOLOv4 copied to clipboard
Pytorch 1.8: Tensor to cumpy
Hi, I am using pytorch 1.8 with cuda 11.2. While training on coco or custom dataset I get this error message. I used pretained weight yolov4.conv.137.pth to train the custom dataset. Does anybody has the same problem and fixed it?
Traceback (most recent call last):
File "train.py", line 438, in <module>
train(hyp, opt, device, tb_writer)
File "train.py", line 301, in train
results, maps, times = test.test(opt.data,
File "/home/kamal/Documents/PyTorch_YOLOv4/test.py", line 206, in test
plot_images(img, output_to_target(output, width, height), paths, str(f), names) # predictions
File "/home/kamal/Documents/PyTorch_YOLOv4/utils/general.py", line 907, in output_to_target
return np.array(targets)
File "/home/kamal/.virtualenvs/pytorch-yolov4/lib/python3.8/site-packages/torch/tensor.py", line 621, in __array__
return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
Yes,I have the same problem in pytorch1.7.1 with cuda 10.2.I also want the solutions.
@WongKinYiu can you please have a look at this?
Yes,I have the same problem in pytorch1.7.1 with cuda 10.2.I also want the solutions.
@Arthur-zfc were you able to fix it?
@shuuny-matrix No, I haven't solved it yet
我是用的是单机8卡,在general.py的output_to_target方法中 将这两句注释if isinstance(output, torch.Tensor): output = output.cpu().numpy() 并加上 output = [temp.cpu().numpy() for temp in output]
我是用的是单机8卡,在general.py的output_to_target方法中 将这两句注释if isinstance(output, torch.Tensor): output = output.cpu().numpy() 并加上 output = [temp.cpu().numpy() for temp in output]
Thank you, worked like a charm. But need to output.cpu() >> output in test.py in output_to_target()
我是用的是单机8卡,在general.py的output_to_target方法中 将这两句注释if isinstance(output, torch.Tensor): output = output.cpu().numpy() 并加上 output = [temp.cpu().numpy() for temp in output]
Thank you!
谢谢,现在需要修改的地方放在了utils/plots.py!