DEV Community

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

Posted on

76 1

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!🤗🤗

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (5)

Collapse
 
rodolfo_guzman_2b79dea104 profile image
Rodolfo Guzman

Thank you! Just what I was looking for!

Collapse
 
sam_tux profile image
Sam Tux • Edited

When I run python.exe -m pip install -e detectron2

I get ModuleNotFoundError: No module named 'torch'.

However, torch imports normally:

C:\Python310>python.exe
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import torch
torch.__version__
'2.3.0+cu121'

Collapse
 
thiwanka_pathirana_41b658 profile image
Thiwanka Pathirana

try this,

pip install -U pip setuptools wheel

Collapse
 
jucelino_fon_f5764e190ab8 profile image
Jucelino Fon

Do I need to clone and install detectron2? Why is this necessary?

Collapse
 
reckon762 profile image
Karan Bhardwaj

Installation will set up your system, while cloning will help you utilize all the models present in the detectron2 model zoo. I hope this helps!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay