工程上构建detectron2=0.6
conda create -n catseg python=3.8
conda activate catseg
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia
pip install -r requirements.txt
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2
scipy==1.7.0
ftfy==6.0.1
opencv-python==4.5.1.48
setuptools==59.5.0
pillow==8.2.0
imageio==2.4.1
timm==0.8.3.dev0
regex
einops
2.1 修改e:\detectron2\detectron2\layers\csrc\ROIAlignRotated\ROIAlignRotated_cuda.cu
将其中的ceil全部替换为ceilf
2.2 修改e:\detectron2\detectron2\layers\csrc\deformable\deform_conv_cuda_kernel.cu
将其中的floor全部替换为floorf
2.3 e:\detectron2\detectron2\layers\csrc\cocoeval\cocoeval.cpp
#修改第487行 // localtime_r(&rawtime, &local_time); localtime_s(&local_time, *rawtime);
3.1
接下来需要修改一些文件里的内容。
3.2在Anaconda的安装路径里,D:\Anaconda3\envs\pt2.0\Lib\site-packages\torch\utils\cpp_extension.py,修改在文件中的SUBPROCESS_DECODE_ARGS参数为gbk,上边是注释掉的,可以使用查找来找这个变量。注意路径中的虚拟环境名与自己实际情况对应。
# SUBPROCESS_DECODE_ARGS = ('',) if IS_WINDOWS else ()
SUBPROCESS_DECODE_ARGS = ('gbk',) if IS_WINDOWS else ()
如果不能找到这个变量,那可能是pytorch版本不一样导致的,此时还可以有另一种解决办法,修改如下
# 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())
不同的pytorch版本可能存在一些小差异,但基本这条语句类似。
3.3继续修改当前环境里的,D:\Anaconda3\envs\pt2.0\Lib\site-packages\torch\include\torch\csrc\jit\runtime\argument_spec.h,修改如下
// static constexpr size_t ARG_SPEC_DEPTH_LIMIT = 128;
static const size_t ARG_SPEC_DEPTH_LIMIT = 128;
4.1
error: command 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6\\bin\\nvcc.exe' failed with exit code 1
解决办法:
找到如下文件:
detectron2\layers\csrc\nms_rotated\nms_rotated_cuda.cudetectron2\layers\csrc\nms_rotated\nms_rotated_cuda.cu
原文内容为:
// 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
修改为:
// 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"
linux:
raise RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_version, torch.version.cuda))
RuntimeError:
The detected CUDA version (11.3) mismatches the version that was used to compile
PyTorch (12.1). Please make sure to use the same CUDA versions.
解决方案
看到这既然是cuda和pytorch对比导致的错误,但是众所周知其实问题没那么大,然后往上看看到了
File "/root/miniconda3/envs/llava/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 525, in build_extensions
_check_cuda_version(compiler_name, compiler_version)
那解决不了问题就解决提出问题的代码,修改该部分代码为
if cuda_ext and not IS_HIP_EXTENSION:
pass # _check_cuda_version(compiler_name, compiler_version)
python setup.py build develop