windows下安装最新detectron2

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

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
查看环境各个包的版本

您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

### 回答1: 要在Windows 10上安装Detectron2,您需要按照以下步骤操作: 1. 安装Anaconda或Miniconda 2. 创建一个新的conda环境 3. 安装PyTorch 4. 安装COCO API 5. 安装Detectron2 具体步骤可以参考Detectron2官方文档。 ### 回答2: 在Windows 10下安装Detectron2需要进行以下步骤: 1. 确保系统已经安装了C++构建工具。可以通过运行`Visual Studio Installer`来安装所需的C++工具集。 2. 确保Python环境已经正确安装并配置。建议使用Anaconda进行Python环境管理。 3. 创建一个新的Python虚拟环境(可选),可以使用以下命令来创建: ``` conda create -n detectron2 python=3.7 ``` 4. 激活新创建的虚拟环境,使用以下命令: ``` conda activate detectron2 ``` 5. 确保虚拟环境已激活后,使用以下命令来安装Detectron2及其依赖: ``` pip install torch torchvision ``` ``` pip install cython ``` ``` pip install opencv-python ``` ``` pip install git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI ``` ``` pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/index.html ``` 6. 安装完成后,使用以下命令来验证Detectron2安装是否成功: ``` python -c "import detectron2; print(detectron2.__version__)" ``` 如果以上步骤都按照正确操作,你应该能够在Windows 10系统上成功安装Detectron2,并且可以在你的Python环境中使用它进行计算机视觉任务的开发和实验。 ### 回答3: 要在Windows 10下安装Detectron2,你可以按照以下步骤进行操作: 1. 首先,在你的Windows 10系统上安装Python。你可以从Python官方网站 (https://www.python.org/downloads/) 下载并安装Python 3.6或以上版本。 2. 安装Microsoft Visual C++ Build Tools。你可以从 https://visualstudio.microsoft.com/visual-cpp-build-tools/ 下载并安装适用于Windows的Build Tools。 3. 安装PyTorch和TorchVision。你可以从PyTorch官方网站 (https://pytorch.org/) 下载适用于Windows的预编译的PyTorch和TorchVision版本,并按照官方指南进行安装。 4. 安装Detectron2的依赖项。打开命令行界面,并使用pip install命令安装以下依赖项: ``` pip install cython pip install pycocotools-windows pip install opencv-python ``` 5. 克隆Detectron2的GitHub代码库。在命令行界面中使用git命令克隆Detectron2的代码库: ``` git clone https://github.com/facebookresearch/detectron2.git ``` 6. 在命令行界面中导航到Detectron2的代码库,并使用以下命令安装Detectron2: ``` cd detectron2 python -m pip install -e . ``` 7. 安装完毕后,你可以在Python中导入Detectron2并开始使用它。例如,你可以使用以下命令导入Detectron2: ```python import detectron2 ``` 这些是在Windows 10下安装Detectron2的基本步骤。请注意,上述步骤可能会因为Detectron2的版本和相关依赖项的更新而略有不同,建议在安装时参考Detectron2的官方文档和GitHub页面上的详细指南。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值