CUDA10.1 + python3.7 + pytorch1.7 安装DCNv2

最近想运行一个网络,用到了centernet,需要安装DCNv2,折腾了两天,记录一下填坑的过程。

  1. 下载
    (1)github上最新版的DCNv2源码在"https://github.com/CharlesShang/DCNv2",但是该版本源码不支持PyTorch1.7,如果使其支持PyTorch1.7需要做以下修改:
    DCNv2/src/cuda/dcn_v2_cuda.cu中所有的THCState_getCurrentStream(state)替换成c10::cuda::getCurrentCUDAStream()

(2)github上有支持PyTorch1.7的源码,“https://github.com/lbin/DCNv2/tree/pytorch_1.7”,可以直接使用。

  1. 修改torch/utils/cpp_extension.py文件
    该文件一般在你的python安装目录site-packages文件夹下,比如我的在conda虚拟环境路径/lib/python3.7/site-packages/torch/utils/cpp_extension.py
    (1)将源码command = [‘ninja’, ‘-v’]修改成command = [‘ninja’, ‘–version’],注意version前面是两条短横线。
    (2)将源码compiler_info.decode().strip()修改成compiler_info.decode(‘gbk’).strip()

  2. 编译
    DCNv2目录下执行./make.sh即可。

  3. 错误
    在使用conda安装torchtorchvision的环境中,一直出现如下错误,实在找不到解决方法。

g++: error: xxx/DCNv2/src/vision.o: No such file or directory
g++: error: xxx/DCNv2/src/cpu/dcn_v2_psroi_pooling_cpu.o: No such file or directory
g++: error: xxx/DCNv2/src/cpu/dcn_v2_im2col_cpu.o: No such file or directory
g++: error: xxx/DCNv2/src/cpu/dcn_v2_cpu.o: No such file or directory
g++: error: xxx/DCNv2/src/cuda/dcn_v2_im2col_cuda.o: No such file or directory
g++: error: xxx/DCNv2/src/cuda/dcn_v2_psroi_pooling_cuda.o: No such file or directory
g++: error: xxx/src/cuda/dcn_v2_cuda.o: No such file or directory

后来在使用pip安装torchtorchvison的环境中,就可以正常编译了。

running develop
running egg_info
creating DCNv2.egg-info
writing DCNv2.egg-info/PKG-INFO
writing dependency_links to DCNv2.egg-info/dependency_links.txt
writing top-level names to DCNv2.egg-info/top_level.txt
writing manifest file 'DCNv2.egg-info/SOURCES.txt'
reading manifest file 'DCNv2.egg-info/SOURCES.txt'
writing manifest file 'DCNv2.egg-info/SOURCES.txt'
running build_ext
copying build/lib.linux-x86_64-3.7/_ext.cpython-37m-x86_64-linux-gnu.so -> 
Creating /home/gaeiauto5/.conda/envs/Python3.7_qyx/lib/python3.7/site-packages/DCNv2.egg-link (link to .)
DCNv2 0.1 is already the active version in easy-install.pth

Installed /home/gaeiauto5/qiyuxiao/python_ws/CenterFusion_mrnabati/CenterFusion/src/lib/model/networks/DCNv2
Processing dependencies for DCNv2==0.1
Finished processing dependencies for DCNv2==0.1

猜测可能是condapip安装的环境差异造成的,有大佬解决了上述问题欢迎交流。

参考:
日常填坑-DCNv2+pytorch1.7+vs2017编译
Ubuntu + pytorch1.7 + rtx3090/3080 安装DCNv2 踩坑记录
Ubuntu18.04+RTX3090+pytorch1.7 安装Yolact无法编译DCNv2解决方法

你可能感兴趣的:(#,软件安装配置,#,Python,深度学习,python,linux)