How to easily install Detectron2 on Windows 10 ?

DGMaxime
2 min readAug 16, 2020

--

Installing Detectron2 on Windows is no easy task because the official version of Detectron2 is officially not supported on this platform, and the Windows Subsystem for Linux does not have access to the machine’s GPU. By following the next steps, you can quickly install and use the latest version of Detectron2, which works perfectly.

Step 1 : Create a conda environment

This step is not necessary. You can create a empty environment to test detectron2 using the two command lines described below: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands

conda create -n myenv python=3.7
conda activate myenv

Replace myenv by the name of your env.

Step 2 : Install Cuda

Go to the official site of Nvidia and download the cuda Tookit executable. I recommend Cuda 10.1 which can used with torch versions 1.6, 1.5 and 1.4.
https://developer.nvidia.com/cuda-10.1-download-archive-base

Then, install the Cuda Toolkit like any program.

Step 3 : Install Torch

Go to https://pytorch.org/get-started/locally/ and select PyTorch 1.6. PyTorch 1.7 and later doesn’t work. If you have installed cuda 10.1 or later, the command should be:

conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch

N.B.: PyTorch 1.6 doesn’t support cudatoolkit=11. But if you have installed CUDA 11.x, cudatoolkit=10.1 still works fine.

Step 4 : Install Cython and Pycocotools

Before installing Pycocotools, you need Cython.

pip install cython

Then use the following repository, which works well with Windows to install Pycocotools.

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

Step 5 : Install Detectron2

Now, you are ready to install Detectron2. Clone the following repository of Detectron2.

git clone https://github.com/DGMaxime/detectron2-windows.git

This repository has been prepared to work with Windows. Some files has been modified. You can find these files here:

setup.py
detectron2/engine/defaults.py
detectron2/layers/csrc/cocoeval/cocoeval.cpp

Once the cloning is complete, install it.

cd detectron2-windows
pip install -e .

If the installation was successful, you should see the message “Successfully installed detectron2”.

Step 6: Test the installation of Detectron2

In the same repository, there is a test file in the tests folder. Run the file named test_windows_install.py. You must first install opencv to perform the test.

pip install opencv-python
python tests/test_windows_install.py

The result:

Image Flickr : Michael J. Belgie, Sr

Hope this story helps you !

--

--

Responses (16)