4

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

enter image description here

Here's the installation algorithm I'm trying to follow (taken from https://stackoverflow.com/a/70498119/1897063)

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

enter image description here

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

  1. Open Anaconda Promt with administrator privileges
  2. Create new Conda environment with Python 3.7:

conda create -n detectron_env python=3.7

  1. Activate newly created environment detectron_env:

conda activate detectron_env

  1. Install cudatoolkit for CUDA 11.3

conda install –c anaconda cudatoolkit=11.3

  1. Install cudnn

conda install -c anaconda cudnn

  1. Install pywin32

conda install -c anaconda pywin32

  1. Install pytorch, torchvision and torchaudio for CUDA 11.3 enter image description here

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

  1. Check whether GPU is enabled for Pytorch:

python -c "import torch; print(torch.cuda.is_available())"

enter image description here

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

  1. Go to the directory where I want to install detectron2

e:

cd e:/TRON

  1. Git clone detectron2 repository

git clone https://github.com/facebookresearch/detectron2.git detectron_repo

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

SagRU
  • 448
  • 4
  • 17
  • did you solve the issue? – FDI Jun 14 '22 at 21:26
  • Check https://stackoverflow.com/a/72784255/12635565 – Hiren Namera Jun 28 '22 at 09:49
  • I got as far as you did, and then it broke on install. This solved it for me: https://github.com/Ikomia-dev/detectron2/commit/cf546cfdae29b1f032f58a7d0340140443ee0603 – BaKeR Aug 19 '22 at 16:06
  • @FDI no, I had to use Ubuntu instead. – SagRU Sep 09 '22 at 11:47
  • For me it was that I had previously had CUDA computing toolkit on my system (11.2). Although I uninstalled it, the "Nvidia GPU Computing Toolkit" directory still existed under C:/Program Files. That made the build choose the system installation (11.2) instead of the correct 11.3 version installed with conda which caused the error. I deleted the "Nvidia GPU Computing Toolkit" directory and the error is gone – SaPropper Nov 11 '22 at 14:48

0 Answers0