Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install Detectron2 on Windows 10

I try to install Facebook's Detectron2 followed this official repo. Following that repo, detectron2 can only install on linux. However, I'm working on a server run on Windows operator. Anybody know how to install it on Windows?

like image 906
Khiem Le Avatar asked Mar 11 '20 08:03

Khiem Le


People also ask

Can we Install Detectron2 on windows?

Any issue on windows. Although detectron2 can be installed on windows with some effort (similar to these), we do not provide official support for it. PRs that improves code compatibility on windows are welcome.

Does Detectron2 work on Windows 10?

How to Install Detectron2 on Windows 10 or 11 –2021(AUG) with the latest build(v0. 5). Installing Detectron2 on windows is not so easy but an achievement indeed!

What is Detectron2?

Detectron2 is a ground-up rewrite of Detectron that started with maskrcnn-benchmark. The platform is now implemented in PyTorch. With a new, more modular design, Detectron2 is flexible and extensible, and able to provide fast training on single or multiple GPU servers.


5 Answers

Answer found through this issue: https://github.com/facebookresearch/detectron2/issues/9

These steps worked for me on my RTX 3070.

  1. Install Anaconda https://docs.anaconda.com/anaconda/install/windows/
  2. Create a environment.yml file containing the following code.
name: detectron2
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python=3.8
  - numpy
  - pywin32
  - cudatoolkit=11.0
  - pytorch==1.7.1
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/[email protected]
  1. Launch the Anaconda terminal, navigate to the yml file and run conda env create -f environment.yml

  2. Activate the environment conda activate detectron2

And you're good to go.

Edit: This works without issue if you run your script within the anaconda terminal but I was also having this issue ImportError: DLL load failed: The specified module could not be found. with numpy and Pillow when running the script from VS Code so if you happen to have this issue, I fixed it by uninstalling and reinstalling the troubled modules from within the anaconda terminal.

pip uninstall numpy
pip install numpy
like image 90
Austin Ulfers Avatar answered Oct 19 '22 21:10

Austin Ulfers


Here is the installation instructions. To install the latest version of Detectron2, following command works.

  • Windows10
  • Python = 3.7.9
  • Pytorch = 1.7.1
  • Torchvision = 0.8.2
  • Cuda = 11.0
  • detectron2 = 0.5

In the terminal:

python -m pip install git+https://github.com/facebookresearch/detectron2.git
like image 20
Maryam Bahrami Avatar answered Oct 19 '22 22:10

Maryam Bahrami


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):

  1. 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

  2. Activate detectron_env:

    conda activate detectron_env

  3. 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

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

    conda install -c anaconda cudnn

  5. Install pywin32:

    conda install -c anaconda pywin32

  6. 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

  7. Check whether GPU is enabled for pytorch:

    Enable python, import torch and type 'torch.cuda.is_available()'

    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.

  8. 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

  9. Go to the directory where you want to install detectron2.

  10. 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

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

    pip install -q -e detectron_repo

  12. Go to detectron_repo directory:

    cd detectron_repo

  13. 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

  14. 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

like image 5
east Avatar answered Oct 19 '22 21:10

east


Here is how I managed to use detectron2 on Windows 10:

  1. Determine how to install pytorch using https://pytorch.org/get-started/locally/ (I am using CPU only, install pytorch using the suggested command

  2. Run python -m pip install git+github.com/facebookresearch/detectron2.git

  3. conda install pywin32

like image 1
Greg7000 Avatar answered Oct 19 '22 21:10

Greg7000


I Installed this in Windows 10 and 11 Successfully using this trick.

First of all, Install Visual Studio and Compiler, and build tools, and runtimes. Install .NET Runtime.

Then start with

conda create -n norfair python=3.9

conda install -c anaconda pywin32

conda install -c anaconda cython

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

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

DONE

like image 1
Hiren Namera Avatar answered Oct 19 '22 22:10

Hiren Namera