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

runtime error mobillenet-ssd-v2 #183

Open
DaiGuard opened this issue Sep 27, 2022 · 5 comments
Open

runtime error mobillenet-ssd-v2 #183

DaiGuard opened this issue Sep 27, 2022 · 5 comments

Comments

@DaiGuard
Copy link

Hello

I'm trying to use this repo to run live demo to use mobielnet-ssd-v2.
I tried to run python run_ssd_live_demo.py mb2-ssd-lite models/mb2-ssd-lite-mp-0_686.pth models/voc-model-labels.txt .

I got this error as output

$ python run_ssd_live_demo.py mb2-ssd-lite models/mb2-ssd-lite-mp-0_686.pth models/voc-model-labels.txt 
Traceback (most recent call last):
  File "run_ssd_live_demo.py", line 70, in <module>
    boxes, labels, probs = predictor.predict(image, 10, 0.4)
  File "/home/dai_guard/Workspaces/apps/pytorch-ssd/vision/ssd/predictor.py", line 37, in predict
    scores, boxes = self.net.forward(images)
  File "/home/dai_guard/Workspaces/apps/pytorch-ssd/vision/ssd/ssd.py", line 93, in forward
    locations, self.priors, self.config.center_variance, self.config.size_variance
  File "/home/dai_guard/Workspaces/apps/pytorch-ssd/vision/utils/box_utils.py", line 108, in convert_locations_to_boxes
    locations[..., :2] * center_variance * priors[..., 2:] + priors[..., :2],
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
  • Environments
    OS: Ubuntu 18.04
    GPU: NVIDIA GeForce RTX 2070 SUPER
    DRIVER: 515.65.01
    CUDA: 11.6

  • Dependecies
    torch==1.10.2
    torchaudio==0.10.1
    torchvision==0.11.2
    opencv-python==4.6.0.66

@DaiGuard
Copy link
Author

From wath I can tell, of the two valiables (locations, priors), priors seems to be in cuda mode.

# add this code in box_utils.py line: 104
print(locations.is_cuda)
print(priors.is_cuda)
---
False
True

Therefore, the following code could be added for use

    # priors can have one dimension less.
    if priors.dim() + 1 == locations.dim():
        priors = priors.unsqueeze(0)

+    if priors.is_cuda:
+       priors = priors.to('cpu')
    
    return torch.cat([
        locations[..., :2] * center_variance * priors[..., 2:] + priors[..., :2],
        torch.exp(locations[..., 2:] * size_variance) * priors[..., 2:]
    ], dim=locations.dim() - 1)

@bryanbocao
Copy link

bryanbocao commented Feb 20, 2023

https://github.com/qfgaohao/pytorch-ssd/blob/master/vision/ssd/ssd.py#L38

priors is saved in cuda device if you run with GPUs.

Another walkaway solution would be simply to run by

CUDA_VISIBLE_DEVICES='' python3 run_ssd_live_demo2.py mb2-ssd-lite models/mb2-ssd-lite-mp-0_686.pth models/voc-model-labels.txt <TEST_IMG>.jpg

@bryanbocao
Copy link

I simply commented it out

self.priors = config.priors #.to(self.device)

#189
f9de973

@hidetoshi-kinoshita
Copy link

Hello.
With the modification below, I was able to get it to work as expected on both CPU and GPU environments.
MobileNetV1 has the same implementation and runs without problems in the GPU environment. I think it was probably a simple mistake.

imgC1

@DaiGuard
Copy link
Author

I simply commented it out

self.priors = config.priors #.to(self.device)

#189 f9de973

Thank you very much. It worked fine.

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