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?
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.
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!
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.
Answer found through this issue: https://github.com/facebookresearch/detectron2/issues/9
These steps worked for me on my RTX 3070.
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]
Launch the Anaconda terminal, navigate to the yml
file and run conda env create -f environment.yml
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
Here is the installation instructions. To install the latest version of Detectron2, following command works.
In the terminal:
python -m pip install git+https://github.com/facebookresearch/detectron2.git
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_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.
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
Here is how I managed to use detectron2 on Windows 10:
Determine how to install pytorch using https://pytorch.org/get-started/locally/ (I am using CPU only, install pytorch using the suggested command
Run python -m pip install git+github.com/facebookresearch/detectron2.git
conda install pywin32
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With