DEV Community

Cover image for How to Install Detectron2 on Windows
Karan Bhardwaj
Karan Bhardwaj

Posted on

How to Install Detectron2 on Windows

Detectron2 is a powerful open-source object detection and segmentation framework built by Facebook AI Research. It's widely used for research and development in computer vision applications. However, installing Detectron2 on Windows 11 can be a bit tricky due to various dependencies. In this guide, I will take you through the step-by-step process to set up Detectron2 on your Windows 11 system.

Step 1: Set up a Conda Environment

First, let's create a new conda environment to isolate the installation:

conda create --name detectron2_env python=3.11.7
conda activate detectron2_env
Enter fullscreen mode Exit fullscreen mode

Step 2: Install CUDA

If you have an NVIDIA GPU, you'll need to install the CUDA toolkit. Ensure you have the correct version compatible with your GPU:

conda install cuda=12.1 -c nvidia
Enter fullscreen mode Exit fullscreen mode

Step 3: Install PyTorch

Install PyTorch with the required CUDA version:

conda install pytorch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1 cudatoolkit=12.1 -c pytorch -c nvidia
Enter fullscreen mode Exit fullscreen mode

For other versions of CUDA, and the required PyTorch version, you can refer to https://pytorch.org/get-started/locally/.

In case you are on CPU, use

conda install pytorch torchvision torchaudio cpuonly -c pytorch
Enter fullscreen mode Exit fullscreen mode

Step 4: Update Visual C++ Redistributable

Ensure your system has the latest Visual C++ Redistributable installed. You can download and install it from the official Microsoft website.

Step 5: Install Cython and COCO Tools

Cython is a prerequisite for building Detectron2, while COCO tools required for evaluation:

pip install cython
conda install conda-forge::pycocotools
Enter fullscreen mode Exit fullscreen mode

Step 6: Clone Detectron2 Repository

Clone the Detectron2 repository from GitHub:

git clone https://github.com/facebookresearch/detectron2.git
Enter fullscreen mode Exit fullscreen mode

Step 7: Install Detectron2

python -m pip install -e detectron2

Enter fullscreen mode Exit fullscreen mode

That's it! You've successfully installed Detectron2 on your Windows 11 system. You can now start using it for various computer vision tasks like object detection, instance segmentation, and more.

Remember to activate your conda environment whenever you want to work with Detectron2.

Happy coding!πŸ€—πŸ€—

Top comments (0)