Although there's no official support for Detectron2 on Windows, there're many instructions available. I tried following these instruction, but ended up with the same error.
Here's my setup:
OS: Windows 10 Pro 19043.1466
Microsoft Visual Studio: 2019
CUDA: 11.3
Here's the installation algorithm I'm trying to follow (taken from https://stackoverflow.com/a/70498119/1897063)
- Set up environment variables for Microsoft Visual Studio by running
vcvars64.bat
:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat
- Add new system path for
cl.exe
in my PATH variable:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64
- Open Anaconda Promt with administrator privileges
- Create new Conda environment with Python 3.7:
conda create -n detectron_env python=3.7
- Activate newly created environment detectron_env:
conda activate detectron_env
- Install cudatoolkit for CUDA 11.3
conda install –c anaconda cudatoolkit=11.3
- Install cudnn
conda install -c anaconda cudnn
- Install pywin32
conda install -c anaconda pywin32
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
- Check whether GPU is enabled for Pytorch:
python -c "import torch; print(torch.cuda.is_available())"
- Install additional packages
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 I want to install detectron2
e:
cd e:/TRON
- Git clone detectron2 repository
git clone https://github.com/facebookresearch/detectron2.git detectron_repo
- Install dependencies
pip install -q -e detectron_repo
And everything breaks here:
(detectron_env) e:\TRON>pip install -q -e detectron_repo
ERROR: Command errored out with exit status 1:
command: 'C:\Users\E-soft\Anaconda3\envs\detectron_env\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'E:\\TRON\\detectron_repo\\setup.py'"'"'; __file__='"'"'E:\\TRON\\detectron_repo\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
cwd: E:\TRON\detectron_repo\
Complete output (16 lines):
running develop
running egg_info
writing detectron2.egg-info\PKG-INFO
writing dependency_links to detectron2.egg-info\dependency_links.txt
writing requirements to detectron2.egg-info\requires.txt
writing top-level names to detectron2.egg-info\top_level.txt
reading manifest file 'detectron2.egg-info\SOURCES.txt'
adding license file 'LICENSE'
writing manifest file 'detectron2.egg-info\SOURCES.txt'
running build_ext
error: [WinError 2] The system cannot find the file specified
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Users\E-soft\Anaconda3\envs\detectron_env\lib\site-packages\colorama\ansitowin32.py", line 59, in closed
return stream.closed
ValueError: underlying buffer has been detached
----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\E-soft\Anaconda3\envs\detectron_env\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'E:\\TRON\\detectron_repo\\setup.py'"'"'; __file__='"'"'E:\\TRON\\detectron_repo\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.
I've tried to get past the problem by changing build_ext
to build_ext --inplace
in setup.py
(line 208):
cmdclass={"build_ext --inplace": torch.utils.cpp_extension.BuildExtension}
Here's the result of running step 14 with these changes applied:
(detectron_env) e:\TRON>pip install -q -e detectron_repo
ERROR: Command errored out with exit status 1:
command: 'C:\Users\E-soft\Anaconda3\envs\detectron_env\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'E:\\TRON\\detectron_repo\\setup.py'"'"'; __file__='"'"'E:\\TRON\\detectron_repo\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
cwd: E:\TRON\detectron_repo\
Complete output (17 lines):
running develop
running egg_info
writing detectron2.egg-info\PKG-INFO
writing dependency_links to detectron2.egg-info\dependency_links.txt
writing requirements to detectron2.egg-info\requires.txt
writing top-level names to detectron2.egg-info\top_level.txt
reading manifest file 'detectron2.egg-info\SOURCES.txt'
adding license file 'LICENSE'
writing manifest file 'detectron2.egg-info\SOURCES.txt'
running build_ext
building 'detectron2._C' extension
error: Don't know how to compile E:\TRON\detectron_repo\detectron2\layers\csrc\box_iou_rotated\box_iou_rotated_cuda.cu
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Users\E-soft\Anaconda3\envs\detectron_env\lib\site-packages\colorama\ansitowin32.py", line 59, in closed
return stream.closed
ValueError: underlying buffer has been detached
----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\E-soft\Anaconda3\envs\detectron_env\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'E:\\TRON\\detectron_repo\\setup.py'"'"'; __file__='"'"'E:\\TRON\\detectron_repo\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.
It says "Don't know how to compile E:\TRON\detectron_repo\detectron2\layers\csrc\box_iou_rotated\box_iou_rotated_cuda.cu". What's the origin of the problem? Is it coming from Microsoft Visual Studio?