Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! #3

Open
NgheNhanTruong opened this issue Oct 14, 2023 · 2 comments

Comments

@NgheNhanTruong
Copy link

When i conducted the training process, i have a trouble with evaluation on cuda, can you help me to sovle them. Below is the bug:
(yolov5) D:\OneDrive - Sejong University\NgheNhan_Master\Research\Multicamera Fusion Method\Code\YOLOV5m>python train.py --data Mask_Dataset --box_format yolo --epochs 10 --bs 8

Training Logs will be saved in train_eval_metrics\model_1\loss.csv


Eval Logs will be saved in train_eval_metrics\model_1\eval.csv

Training epoch 1/11
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 75/75 [00:59<00:00, 1.27it/s, average_loss_batches=34.4]
==> training_loss: 37.94
.. Computing: class and obj accuracies ..
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [00:30<00:00, 1.38s/it]
Class accuracy: 0.00%
Obj accuracy: 100.00%
.. Getting Evaluation bboxes to compute MAP..
0%| | 0/22 [00:25<?, ?it/s]
Traceback (most recent call last):
File "D:\OneDrive - Sejong University\NgheNhan_Master\Research\Multicamera Fusion Method\Code\YOLOV5m\train.py", line 147, in
main(parser)
File "D:\OneDrive - Sejong University\NgheNhan_Master\Research\Multicamera Fusion Method\Code\YOLOV5m\train.py", line 130, in main
evaluate.map_pr_rec(model.to(config.DEVICE), val_loader, anchors=model.head.anchors, epoch=epoch)
File "D:\OneDrive - Sejong University\NgheNhan_Master\Research\Multicamera Fusion Method\Code\YOLOV5m\utils\validation_utils.py", line 103, in map_pr_rec
pred_boxes = cells_to_bboxes(predictions, anchors, strides=model.head.stride, is_pred=True, to_list=False)
File "D:\OneDrive - Sejong University\NgheNhan_Master\Research\Multicamera Fusion Method\Code\YOLOV5m\utils\plot_utils.py", line 25, in cells_to_bboxes
xy = (2 * (layer_prediction[..., 0:2]) + grid[i] - 0.5) * stride
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

@AlessandroMondin
Copy link
Owner

Hi! It's been a while since I last used this repo and I do not have a GPU to test the error. I suggest you to put a breakpoint on the error line and check which tensor is not sent to cuda

@xjyisok
Copy link

xjyisok commented Mar 20, 2024

May be you can set device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants