detectron2 windows 安装

detectron2 windows 安装

https://github.com/facebookresearch/detectron2官方目前暂时没有提供官方的windows安装教程,这里记录使用中碰到的坑

1. 主要参考

https://github.com/conansherry/detectron2

2. 安装依赖

  1. 安装已有的包

    conda create -n detectron2 python=3.8
    
    conda activate detectron2
    
    conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
    
    pip install cython pycocotools-windows fvcore pydot future tensorboard tqdm mock matplotlib cloudpickle tabulate yacs Pillow termcolor opencv-python
    
  2. 安装vs2019或者2017,然后执行如下
    2019版本执行
    set DISTUTILS_USE_SDK=1 set MAX_JOBS=5 "H:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
    2017版本执行
    set DISTUTILS_USE_SDK=1 set MAX_JOBS=5 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"

  3. 修改几处代码

    file1: 
       E:\ProgramData\Miniconda3\envs\detectron2\lib\site-packages\torch\include\torch\csrc\jit\argument_spec.h
      example:
      {C:\Miniconda3\envs\py36}\Lib\site-packages\torch\include\torch\csrc\jit\argument_spec.h(190)
        static constexpr size_t DEPTH_LIMIT = 128;
          change to -->
        static const size_t DEPTH_LIMIT = 128;
    
    file2: 
       E:\ProgramData\Miniconda3\envs\detectron2\lib\site-packages\torch\include\pybind11\cast.h
      example:
      {C:\Miniconda3\envs\py36}\Lib\site-packages\torch\include\pybind11\cast.h(1449)
        explicit operator type&() { return *(this->value); }
          change to -->
        explicit operator type&() { return *((type*)this->value); }
    
    file3:
     {detectron2 src path}\detectron2\layers\csrc\cocoeval\cocoeval.cpp
    注释掉下面几行 localtime_r只有linux有
    //localtime_r(&rawtime, &local_time);
    //strftime(
    //    buffer.data(), 200, "%Y-%m-%d %H:%num_max_detections:%S", &local_time);
    
    
  4. 下载源码

    git clone --depth=1 https://hub.fastgit.org/facebookresearch/detectron2.git
    cd detectron2
    python setup.py build develop
    
  5. [选择执行,如果后面运行没有win32错误]重新安装pywin32

    pip uninstall pywin32
    pip install pywin32==225
    
  6. 安装成功

你可能感兴趣的:(detectron2 windows 安装)