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

Getting CUDA error when using GPU #1

Closed
jliendo opened this issue May 12, 2020 · 1 comment
Closed

Getting CUDA error when using GPU #1

jliendo opened this issue May 12, 2020 · 1 comment

Comments

@jliendo
Copy link
Collaborator

jliendo commented May 12, 2020

When running with CPU there is no issue...when I enable GPU then i get:

`(deep) deep/MtcnnMaskDetection git:(master) [D]% python main.py ../automl/efficientdet/video_calle.mp4
Downloading: "https://github.com/khrlimam/mtcnn-pytorch/releases/download/0.0.1/pnet-6b6ef92b.pth" to /home/javier/.cache/torch/checkpoints/pnet-6b6ef92b.pth
100%|##########################################################################################################| 28.1k/28.1k [00:00<00:00, 253kB/s]
Downloading: "https://github.com/khrlimam/mtcnn-pytorch/releases/download/0.0.1/rnet-b13c48bc.pth" to /home/javier/.cache/torch/checkpoints/rnet-b13c48bc.pth
100%|############################################################################################################| 394k/394k [00:00<00:00, 616kB/s]
Downloading: "https://github.com/khrlimam/mtcnn-pytorch/releases/download/0.0.1/onet-60cc8dd5.pth" to /home/javier/.cache/torch/checkpoints/onet-60cc8dd5.pth
100%|##########################################################################################################| 1.49M/1.49M [00:02<00:00, 559kB/s]

Traceback (most recent call last):
File "main.py", line 60, in
main(**parse_args())
File "main.py", line 49, in main
track_video(vcap)
File "main.py", line 33, in track_video
bboxes, scores = detections.fetch_faces(frame, return_landmarks=False)
File "/home/javier/repos/deep/MtcnnMaskDetection/utils/detections.py", line 24, in fetch_faces
bboxes, landmarks = detect_faces(image)
File "/home/javier/repos/deep/lib/python3.6/site-packages/torch_mtcnn/detector.py", line 58, in detect_faces
boxes = run_first_stage(image, pnet, scale=s, threshold=thresholds[0])
File "/home/javier/repos/deep/lib/python3.6/site-packages/torch_mtcnn/first_stage.py", line 34, in run_first_stage
probs = output[1].data.numpy()[0, 1, :, :]

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.`

@tempdata73
Copy link
Owner

The problem is due to torch_mtcnn pip package, which does not currently support GPU. To fix this, you can go to the source file (in your case it is /home/javier/repos/deep/lib/python3.6/site-packages/torch_mtcnn/detector.py) and
add after line 26

pnet.cuda()
rnet.cuda()
onet.cuda()

replace lines 82-83 with

offsets = output[0].cpu().data.numpy()
probs = output[1].cpu().data.numpy()

Link to solution from original repo.

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

2 participants