Closed darkmatter18 closed 1 year ago
Model should be exported on cuda to be used on cuda. See the first example in https://github.com/facebookresearch/detectron2/tree/main/tools/deploy#use
./export_model.py --config-file ../../configs/DLA_mask_rcnn_X_101_32x8d_FPN_3x.yaml --output ./output --export-method tracing --format torchscript MODEL.WEIGHTS ../../../DLA_mask_rcnn_X_101_32x8d_FPN_3x.pth MODEL.DEVICE cuda
Even though I specify MODEL.DEVICE cuda
I still get the same error.
I am noticing (device=cpu)
on a couple places in the txt files in the output folder. I am not sure if this is an indicator that the model was not exported on cuda even though it was specified, and I noticed that there was a process occupying portion of the GPU memory while the script was running (nvidia-smi).
Is it possible that the sample_image
should also be transfered to GPU memory too?
If you do not know the root cause of the problem, please post according to this template:
Instructions To Reproduce the Issue:
Check https://stackoverflow.com/help/minimal-reproducible-example for how to ask good questions. Simplify the steps to reproduce the issue using suggestions from the above link, and provide them below:
Export Command
CFG
Main Code for inference
Traceback of TorchScript, original code (most recent call last): /home/arkadip_bhattacharya/agtech/codebases/detection-on-cloud/venv/lib/python3.8/site-packages/detectron2/structures/image_list.py(101): from_tensors /home/arkadip_bhattacharya/agtech/codebases/detection-on-cloud/venv/lib/python3.8/site-packages/detectron2/modeling/meta_arch/rcnn.py(229): preprocess_image /home/arkadip_bhattacharya/agtech/codebases/detection-on-cloud/venv/lib/python3.8/site-packages/detectron2/modeling/meta_arch/rcnn.py(203): inference export.py(123): inference /home/arkadip_bhattacharya/agtech/codebases/detection-on-cloud/venv/lib/python3.8/site-packages/detectron2/export/flatten.py(294): forward /home/arkadip_bhattacharya/agtech/codebases/detection-on-cloud/venv/lib/python3.8/site-packages/torch/nn/modules/module.py(1118): _slow_forward /home/arkadip_bhattacharya/agtech/codebases/detection-on-cloud/venv/lib/python3.8/site-packages/torch/nn/modules/module.py(1130): _call_impl /home/arkadip_bhattacharya/agtech/codebases/detection-on-cloud/venv/lib/python3.8/site-packages/torch/jit/_trace.py(967): trace_module /home/arkadip_bhattacharya/agtech/codebases/detection-on-cloud/venv/lib/python3.8/site-packages/torch/jit/_trace.py(750): trace export.py(132): export_tracing export.py(232):
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
sys.platform linux Python 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0] numpy 1.17.4 detectron2 0.6 @/home/arkadip_bhattacharya/.local/lib/python3.8/site-packages/detectron2 Compiler GCC 9.4 CUDA compiler CUDA 11.3 detectron2 arch flags 6.1 DETECTRON2_ENV_MODULE
PyTorch 1.12.0+cu113 @/home/arkadip_bhattacharya/.local/lib/python3.8/site-packages/torch
PyTorch debug build False
GPU available Yes
GPU 0 NVIDIA GeForce MX230 (arch=6.1)
Driver version 515.65.01
CUDA_HOME /usr/local/cuda
Pillow 9.2.0
torchvision 0.13.0+cu113 @/home/arkadip_bhattacharya/.local/lib/python3.8/site-packages/torchvision
torchvision arch flags 3.5, 5.0, 6.0, 7.0, 7.5, 8.0, 8.6
fvcore 0.1.5.post20220512
iopath 0.1.9
cv2 4.2.0
PyTorch built with: