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! #50

Open
zjhleaning opened this issue Apr 8, 2024 · 2 comments
Labels
question Further information is requested

Comments

@zjhleaning
Copy link

I encountered the following error while reproducing your code:RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

The specific details are as follows:
Plotting labels...
Image sizes 640 train, 640 val
Using 8 dataloader workers
Logging results to runs/train/exp
Starting training for 300 epochs...

 Epoch   gpu_mem       box       obj       cls    labels  img_size

0%| | 0/183 [00:02<?, ?it/s]
Traceback (most recent call last):
File "/data/master21/zhujh/software/pythonProject/quantized-yolov5-quantized_yolo/train.py", line 653, in
main(opt)
File "/data/master21/zhujh/software/pythonProject/quantized-yolov5-quantized_yolo/train.py", line 545, in main
train(opt.hyp, opt, device, callbacks)
File "/data/master21/zhujh/software/pythonProject/quantized-yolov5-quantized_yolo/train.py", line 333, in train
pred = model(imgs) # forward
File "/home/zhujh/anaconda3/envs/yolov5/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/data/master21/zhujh/software/pythonProject/quantized-yolov5-quantized_yolo/models/yolo.py", line 156, in forward
return self._forward_once(x, profile, visualize) # single-scale inference, train
File "/data/master21/zhujh/software/pythonProject/quantized-yolov5-quantized_yolo/models/yolo.py", line 179, in _forward_once
x = m(x) # run
File "/home/zhujh/anaconda3/envs/yolov5/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/data/master21/zhujh/software/pythonProject/quantized-yolov5-quantized_yolo/models/common.py", line 150, in forward
x = self.conv(x)
File "/home/zhujh/anaconda3/envs/yolov5/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/home/zhujh/anaconda3/envs/yolov5/lib/python3.7/site-packages/brevitas/nn/quant_conv.py", line 191, in forward
return self.forward_impl(input)
File "/home/zhujh/anaconda3/envs/yolov5/lib/python3.7/site-packages/brevitas/nn/quant_layer.py", line 311, in forward_impl
output_scale = output_scale * quant_input.scale.view(output_scale_shape)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

Process finished with exit code 1

May I ask if there is a good and effective solution,thanks.

@zjhleaning zjhleaning added the question Further information is requested label Apr 8, 2024
Copy link

github-actions bot commented Apr 8, 2024

👋 Hello @zjhleaning, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@Jidkboh
Copy link

Jidkboh commented Apr 17, 2024

how about check your device?it's seems that you have a gpu and a cup ,maybe your device get wrong

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

No branches or pull requests

2 participants