Detectron2: Is it possible to use detectron2 without cuda?

Created on 11 Nov 2019  路  4Comments  路  Source: facebookresearch/detectron2

I'm trying to execute the following code snippet in Ubuntu 18.04.02 without cuda:

import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()
import numpy as np
import cv2
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog

im = cv2.imread("./input.jpg")
cfg = get_cfg()
cfg.merge_from_file("../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 

cfg.MODEL.WEIGHTS = "detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x
/137849600/model_final_f10217.pkl"
predictor = DefaultPredictor(cfg)
outputs = predictor(im)

But this is the output:

(base) marco@pc:~/detectron2/demo$ python3 detectron2Tutorial.py 
WARNING [11/11 14:51:29 d2.config.compat]: Config '../configs/COCO-InstanceSegmentation
/mask_rcnn_R_50_FPN_3x.yaml' has no VERSION. Assuming it to be compatible with latest v2.
Traceback (most recent call last):
  File "detectron2Tutorial.py", line 30, in <module>
    predictor = DefaultPredictor(cfg)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/detectron2/engine/defaults.py", line 145, 
in __init__
    self.model = build_model(self.cfg)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/detectron2/modeling/meta_arch/build.py",
line 18, in build_model
    return META_ARCH_REGISTRY.get(meta_arch)(cfg)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/detectron2/modeling/meta_arch/rcnn.py", 
line 37, in __init__
    pixel_mean = torch.Tensor(cfg.MODEL.PIXEL_MEAN).to(self.device).view(num_channels, 1, 1)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/cuda/__init__.py", line 192, in 
_lazy_init
    _check_driver()
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/cuda/__init__.py", line 95, in 
_check_driver
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

Most helpful comment

As https://github.com/facebookresearch/detectron2/blob/master/GETTING_STARTED.md#inference-with-pre-trained-models said you need to change cfg.MODEL.DEVICE to "cpu".

All 4 comments

As https://github.com/facebookresearch/detectron2/blob/master/GETTING_STARTED.md#inference-with-pre-trained-models said you need to change cfg.MODEL.DEVICE.

Thanks for your reply @ppwwyyxx .
Where should I specify the MODEL?

(base) marco@pc:~/detectron2/demo$ python3 detectron2Tutorial.py --opts MODEL.DEVICE cpu
WARNING [11/11 15:06:34 d2.config.compat]: Config '../configs/COCO-InstanceSegmentation
/mask_rcnn_R_50_FPN_3x.yaml' has no VERSION. Assuming it to be compatible with latest v2.
Traceback (most recent call last):
  File "detectron2Tutorial.py", line 30, in <module>
    predictor = DefaultPredictor(cfg)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/detectron2/engine/defaults.py", line 145, in 
__init__
    self.model = build_model(self.cfg)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/detectron2/modeling/meta_arch/build.py", 
line 18, in build_model
    return META_ARCH_REGISTRY.get(meta_arch)(cfg)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/detectron2/modeling/meta_arch/rcnn.py", 
line 37, in __init__
    pixel_mean = torch.Tensor(cfg.MODEL.PIXEL_MEAN).to(self.device).view(num_channels, 1, 1)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/cuda/__init__.py", line 192, in 
_lazy_init
    _check_driver()
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/cuda/__init__.py", line 95, in 
_check_driver
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

As https://github.com/facebookresearch/detectron2/blob/master/GETTING_STARTED.md#inference-with-pre-trained-models said you need to change cfg.MODEL.DEVICE to "cpu".

Thank you @ppwwyyxx !
Adding cfg.MODEL.DEVICE = "cpu" this problem disappears
I'm going to open another question/issue for another error

Was this page helpful?
0 / 5 - 0 ratings

Related issues

invisprints picture invisprints  路  4Comments

limsijie93 picture limsijie93  路  3Comments

kl720 picture kl720  路  3Comments

choasup picture choasup  路  3Comments

aminekechaou picture aminekechaou  路  3Comments