windows10+detectron2 perfect installation tutorial

foreword

You need to download the github project of detectron2, install vs2019 (this version is strongly recommended, other versions need more operations to be successfully installed), and the default environment is no problem.

download detectron2

Link: https://github.com/facebookresearch/detectron2
can also be cloned locally

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

Change the current path of prompt to detectron2

cd detectron2

Install Visual Studio 2019

Official website: Download the community version of VS2019 and install it. You may need to log in with your Microsoft account to enter this interface for the first time. Double-click to run the downloaded executable file, select it during installation , and then install all by default. It takes a long time here, it takes more than ten minutes, and there is no need to start after the installation is complete. Next you need to configure an environment variable. Right-click on this computer and select Properties –> Advanced System Settings –> Environment Variables –> System Variables –> Path –> Edit –> New, enter

insert image description here
使用C++的桌面开发
insert image description here

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64

Note that this path should correspond to the actual situation on your computer, and the number 14.29 will be needed in the next step.
Next, click win+Rto open the command line window, enter cl, and check for output.
insert image description here
As shown in the figure above, there is no problem with the environment variable. At this time, the compiler needs to be set again.

SET MSSdk=1
SET DISTUTILS_USE_SDK=1
call “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat” amd64 -vcvars_ver=14.29

The result after running is shown in the figure.
insert image description here

modify the code

First install the fvcore package, which can be installed directly using pip

pip install fvcore -i https://pypi.mirrors.ustc.edu.cn/simple/

You can also download or git clone the github package of fvcore first, and then install it.

git clone https://github.com/facebookresearch/fvcore.git
cd fvcore
python setup.py build --force develop

Next, you need to modify the contents of some files.

  1. In the Anaconda installation path, D:\Anaconda3\envs\pt2.0\Lib\site-packages\torch\utils\cpp_extension.pymodify the SUBPROCESS_DECODE_ARGS parameter in the file to gbk, which is commented out above, and you can use the search to find this variable. Note that the virtual environment name in the path corresponds to your actual situation.
# SUBPROCESS_DECODE_ARGS = ('',) if IS_WINDOWS else ()
SUBPROCESS_DECODE_ARGS = ('gbk',) if IS_WINDOWS else ()

If you cannot find this variable, it may be caused by a different version of pytorch. At this time, there is another solution, which is modified as follows

# match = re.search(r'(\d+)\.(\d+)\.(\d+)', compiler_info.decode(*SUBPROCESS_DECODE_ARGS).strip())
match = re.search(r'(\d+)\.(\d+)\.(\d+)', compiler_info.decode(‘gbk’).strip())

There may be some small differences between different pytorch versions, but basically this statement is similar.

  1. Continue to modify the current environment, D:\Anaconda3\envs\pt2.0\Lib\site-packages\torch\include\torch\csrc\jit\runtime\argument_spec.h, modify as follows
// static constexpr size_t ARG_SPEC_DEPTH_LIMIT = 128;
static const size_t ARG_SPEC_DEPTH_LIMIT = 128;

Note that if you add comments here, you should pay attention to the difference between python and c++ in the comment format.

  1. Continue to modify the current environment, D:\Anaconda3\envs\pt2.0\Lib\site-packages\torch\include\torch\csrc\jit\ir\ir.h, comment out the following sentence, some versions of pytorch may not have this sentence directly.
// static constexpr Symbol Kind = ::c10::prim::profile_optional
  1. Modify, in detectron2, and replace I:\detectron2\detectron2\layers\csrc\ROIAlignRotated\ROIAlignRotated_cuda.cuall with , pay attention to case sensitivity here, do not replace Ceil with two capitals, and strictly limit case when using one-key replacement.ceilceilf
  2. Continue to modify the in detectron2, and change I:\detectron2\detectron2\layers\csrc\deformable\deform_conv_cuda_kernel.cuall to .floorfloorf
  3. Continue to modify in detectron2, I:\detectron2\detectron2\layers\csrc\cocoeval\cocoeval.cpp.
// localtime_r(&rawtime, &local_time); 
localtime_s(&local_time,&rawtime);
  1. Continue to modify in detectron2, I:\detectron2\detectron2\layers\csrc\nms_rotated\nms_rotated_cuda.cu, which comment out some in the definition of the header file, add some, as follows
// Copyright (c) Facebook, Inc. and its affiliates.
#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <c10/cuda/CUDAGuard.h>
#include <ATen/cuda/CUDAApplyUtils.cuh>
/*#ifdef WITH_CUDA
#include "../box_iou_rotated/box_iou_rotated_utils.h"
#endif
// TODO avoid this when pytorch supports "same directory" hipification
#ifdef WITH_HIP
#include "box_iou_rotated/box_iou_rotated_utils.h"
#endif*/
#include "box_iou_rotated/box_iou_rotated_utils.h"

At this point the prompt is in the detectron2 path, run

python setup.py build develop

The following indicates that the installation has been successful.
insert image description here

Guess you like

Origin blog.csdn.net/Wenyuanbo/article/details/130577744