facebookresearch / detectron2

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
https://detectron2.readthedocs.io/en/latest/
Apache License 2.0
30.55k stars 7.49k forks source link

Installing Detectron2 on CPU #23

Closed kHarshit closed 5 years ago

kHarshit commented 5 years ago

❓ Questions and Help

Can I install detectron2 on CPU? Currently, I'm getting the following error while building detectron2 on manjaro.

Env:

---------------------  --------------------------------------------------
Python                 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0]
DETECTRON2_ENV_MODULE  <not set>
PyTorch                1.3.0
PyTorch Debug Build    False
CUDA available         False
Pillow                 6.2.0
---------------------  --------------------------------------------------
PyTorch built with:
  - GCC 7.3
  - Intel(R) Math Kernel Library Version 2019.0.4 Product Build 20190411 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v0.20.5 (Git Hash 0125f28c61c1f822fd48570b4c1066f96fcb9b2e)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - NNPACK is enabled
  - Build settings: BLAS=MKL, BUILD_NAMEDTENSOR=OFF, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -fopenmp -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Wno-stringop-overflow, DISABLE_NUMA=1, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=True, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_STATIC_DISPATCH=OFF

Error:

...
g++ -pthread -shared -B /home/harshit/anaconda3/envs/py13/compiler_compat -L/home/harshit/anaconda3/envs/py13/lib -Wl,-rpath=/home/harshit/anaconda3/envs/py13/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/vision.o build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_cpu.o build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cpu.o build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/ROIAlign/ROIAlign_cpu.o build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/nms_rotated/nms_rotated_cpu.o -o build/lib.linux-x86_64-3.7/detectron2/_C.cpython-37m-x86_64-linux-gnu.so
/home/harshit/anaconda3/envs/py13/compiler_compat/ld: build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/vision.o: unable to initialize decompress status for section .debug_info
/home/harshit/anaconda3/envs/py13/compiler_compat/ld: build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/vision.o: unable to initialize decompress status for section .debug_info
/home/harshit/anaconda3/envs/py13/compiler_compat/ld: build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/vision.o: unable to initialize decompress status for section .debug_info
/home/harshit/anaconda3/envs/py13/compiler_compat/ld: build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/vision.o: unable to initialize decompress status for section .debug_info
build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/vision.o: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status
error: command 'g++' failed with exit status 1
ppwwyyxx commented 5 years ago

You can install detectron2 on CPU and run inference.

If you google the error message, all occurrences of the message suggest a bug in binutils / elfutils . You may need to upgrade / downgrade your system or compiler toolchain.

kHarshit commented 5 years ago

Thanks, it worked after downgrading binutils.

leopiney commented 5 years ago

It happened to me when running some tools from the DensePose project that it always tried to compile the model using CUDA, which I don't have installed because I'm running some experiments on MacOS.

If you want to use CPU for inference you can add the option MODEL.DEVICE cpu to the command you are running, or add that same setting in the configuration file you are using:

MODEL:
  DEVICE: "cpu"
kHarshit commented 5 years ago

Thanks @leopiney, I was able to run it on CPU using the MODEL.DEVICE option.

FlyEgle commented 5 years ago

I also have the same error on my MacOS, please how i can use the command MODEL.DEVICE cpu or where should i write to the config file , thank you!

kHarshit commented 5 years ago

I also have the same error on my MacOS, please how i can use the command MODEL.DEVICE cpu or where should i write to the config file , thank you!

Check https://detectron2.readthedocs.io/tutorials/getting_started.html#inference-with-pre-trained-models i.e. in order to run inference on cpu

python demo/demo.py --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
  --input input1.jpg input2.jpg \
  --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl \
  MODEL.DEVICE cpu

If you're talking about the error build/temp.linux-x86_64-3.7/home/harshit/PycharmProjects/detectron2/detectron2/layers/csrc/vision.o: file not recognized: file format not recognized, then I solved it by downgrading binutils to 2.30-5.