Skip to main content

安装detectron2

Tiu MoAbout 2 min

环境要求

安装detectron2

'Check the vision of pytorch' -> https://pytorch.org/get-started/locally/

# install pytorch
$ conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch-lts -c nvidia

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch -c nvidia

# install cv2 
$  'if xcb error' $ pip3 install opencv-python-headless 

# git project
$ git clone https://github.com/facebookresearch/detectron2.git
# Install Pre-Built Detectron2 (Linux only)
$ python -m pip install detectron2 -f \
  https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.8/index.html

# Build Detectron2 from Source
$ python -m pip install -e detectron2

'To rebuild detectron2 that is built from a local clone, use' $rm -rf build/ **/*.so 'to clean the old build first. You often need to rebuild detectron2 after reinstalling PyTorch.'
opencv-python 的区别
  1. opencv-python:这个存储库只包含OpenCV库的主要模块。如果您是PyImageSearch阅读器,则不需要安装此软件包。
  2. opencv-contrib-python:包含主要模块contrib模块。 # 一般推荐安装,因为它包含了所有的OpenCV功能。
  3. opencv-python-headless:与opencv-python相同但没有GUI功能。适用于无界面系统。
  4. opencv-contrib-python-headless:与opencv-contrib-python相同,但没有GUI功能。适用于无界面系统。

运行demo

# 官方示例
$ python projects/CenterNet2/demo/demo.py --config-file projects/CenterNet2/configs/CenterNet2_R50_1x.yaml --input path/to/image/ --opts MODEL.WEIGHTS models/CenterNet2_R50_1x.pth

# 运行代码
$ python /home/leng/Documents/nemo/CenterNet2-master/projects/CenterNet2/demo.py --config-file /home/leng/Documents/nemo/CenterNet2-master/projects/CenterNet2/configs/CenterNet2_R2-101-DCN-BiFPN_4x+4x_1560_ST.yaml --input /home/leng/Documents/nemo/temp_img/ --output /home/leng/Documents/nemo/temp_output/ --opts MODEL.WEIGHTS /home/leng/Downloads/CenterNet2_R2-101-DCN-BiFPN_4x+4x_1560_ST.pth 
# 使用tensorborad查看loss等信息
$ tensorboard --logdir /home/leng/Documents/T42/detectron2/output/CenterNet2/Centernet2_3090

第一次使用时的报错,记录一下:

/home/leng/anaconda3/envs/detectron2/lib/python3.8/site-packages/torch/cuda/__init__.py:104: UserWarning: 
NVIDIA GeForce RTX 3090 with CUDA capability sm_86 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_61 sm_70 sm_75 compute_37.
If you want to use the NVIDIA GeForce RTX 3090 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

  warnings.warn(incompatible_device_warn.format(device_name, capability, " ".join(arch_list), device_name))

AttributeError: module ‘distutils‘ has no attribute ‘version‘ 解决方案

1 问题 PyTorch版本1.10,安装完tensorboard后运行代码时出现错误:AttributeError: module 'distutils' has no attribute 'version'。

2 原因 setuptools版本问题。

3 解决方案

pip uninstall setuptools
pip install setuptools==59.5.0