windows下安装最新detectron2

本文档详细介绍了在Windows 10上,配备RTX2070 GPU的笔记本电脑上安装detectron2的过程。首先创建一个conda环境,然后安装cudatoolkit、cudnn、pywin32、pytorch、torchvision和torchaudio。接着确认GPU是否为pytorch启用,安装必要的包如ninja、cython等,克隆detectron2仓库并进行安装和测试。确保安装VS 2015-2019以避免兼容性问题。
摘要由CSDN通过智能技术生成

Installation of detectron2 in Windows is somehow tricky. I struggled a whole week to make it work. For this, I created a new anaconda environment (to match with the version requirement for pytorch and torchvision for detectron2) and started from installing cudatoolkit and cudnn in that environment. This could be the best way not to mess up with the existing anaconda environment.

Here is the step by step procedure (verified with my laptop with Windows 10 and RTX2070 GPU):

Create an anaconda environment (say ‘detectron_env’):
(note. python 3.8 didn’t work, 3.7 worked)

conda create -n detectron_env python=3.7

Activate detectron_env:

conda activate detectron_env

Install cudatoolkit:
(note. cuda version number should match with the one installed in your computer (in my case 11.3. You can check by typing “nvcc -V” in the anaconda prompt window. For further information, refer to https://pytorch.org/)

conda install –c anaconda cudatoolkit=11.3

Install cudnn:
(note. Don’t specify the version number. It will be automatically figured out)

conda install -c anaconda cudnn

Install pywin32:

conda install -c anaconda pywin32

Install pytorch, torchvision and torchaudio:
(note. Version number of cudatoolkit should match with the one in step 3. pytorch will be automatically installed with version number equal to or higher than 1.8 that is required by detectron2)

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

Check whether GPU is enabled for pytorch:

Enable python, import torch and type ‘torch.cuda.is_avaiable()’

You should get ‘True’. However, If you find that GPU is not enabled for pytorch, go to step 1) and try again with different version numbers for cuda and/or python.

Install some packages:
(note. You should install ninja. Otherwise, set-up and build procedure will not go smoothly)

conda install -c anaconda cython

pip install opencv-python

pip install git+https://github.com/facebookresearch/fvcore

pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

pip install av

conda install -c anaconda scipy

conda install -c anaconda ninja

Go to the directory where you want to install detectron2.

Git clone the following repository:
(note. The folder name for detectron2 should be different from ‘detectron2’. In my case, I used ‘detectron_repo’. Otherwise, path for pytorch will be confused)

git clone https://github.com/facebookresearch/detectron2.git detectron_repo

Install dependencies:
(note. Don’t enter the cloned detectron_repo directory)

pip install -q -e detectron_repo

Go to detectron_repo directory:

cd detectron_repo

Build detectron2:

python setup.py build develop

If the above is not successful, you may need to start again from the beginning or reinstall pytorch. If you reinstall pytocrh, you need to rebuild detectron2 again.

If the above is successful, then

Test:

Go to demo/ directory and run the following script by specyfing an input path to any of your image (say .jpg):

python demo.py --config-file …/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input <path_to_your_image_file.jpg> --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl

原文链接:
https://stackoverflow.com/questions/60631933/install-detectron2-on-windows-10

需要注意的是需要安装vs 2015-2019,安装2022提示无法兼容

使用python -m detectron2.utils.collect_env
查看环境各个包的版本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值