这篇文章为分割提供了新思路,很有参考意义。
注:原代码的运行环境为Ubuntu,本文在Windows10系统下完成配置。
1、论文下载:
Deep Snake for Real-Time Instance Segmentation [paper][code]
2、代码下载:
https://github.com/zju3dv/snake/
3、安装依赖库
进入工程目录运行如下代码
pip install Cython==0.28.2
pip install -r requirements.txt
4、安装apex
下载apex:
git clone https://github.com/NVIDIA/apex.git
进入apex目录安装
cd apex
python setup.py install
作者给的教程,安装apex的代码为:
python setup.py install --cuda_ext --cpp_ext
我的windows10系统下运行会出现如下错误:
e:\codes\pycharm\snake\apex\csrc\multi_tensor_apply.cuh(109): here
instantiation of "void multi_tensor_apply<depth,T,ArgTypes...>(int, int, const at::Tensor &, const std::vector<std::vector<at::Tensor, std::allocator<at::Tensor>>, std::allocator<std::vector<at::Tensor, std::allocator<at::T
ensor>>>> &, T, ArgTypes...) [with depth=2, T=ScaleFunctor<float, float>, ArgTypes=<float>]"
csrc/multi_tensor_scale_kernel.cu(124): here
1 error detected in the compilation of "C:/Users/XXX/AppData/Local/Temp/tmpxft_0000212c_00000000-10_multi_tensor_scale_kernel.cpp1.ii".
error: command 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.1\\bin\\nvcc.exe' failed with exit status 1
所以我用python setup.py install直接安装的,可以安装成功
5、使用Cuda编译库lib/csrc
1)进入lib/csrc/dcn_v2路径运行
python setup.py build_ext --inplace
遇到如下错误:
正在创建库 build\temp.win-amd64-3.7\Release\Codes\PyCharm\snake\lib\csrc\dcn_v2\src\_ext.cp37-win_amd64.lib 和对象 build\temp.win-amd64-3.7\Release\Codes\PyCharm\snake\lib\csrc\dcn_v2\src\_ext.cp37-win_amd64.exp
dcn_v2_cuda.obj : error LNK2001: 无法解析的外部符号 "struct THCState * state" (?state@@3PEAUTHCState@@EA)
build\lib.win-amd64-3.7\_ext.cp37-win_amd64.pyd : fatal error LNK1120: 1 个无法解析的外部命令
error: command 'D:\\Softwares\\VisualStudio\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\link.exe' failed with exit status 1120
解决方法:
进入目录:lib/csrc/dcn_v2/src/cuda
打开dcn_v2_cuda.cu,把extern THCState *state;
改成THCState *state = at::globalContext().lazyInitCUDA();
更改后,再次编译即可。
方法来源:
windows下安装DCNv2出现错误:error LNK2001: 无法解析的外部符号 "struct THCState * state"_libbo2000
2)进入lib/csrc/extreme_utils路径运行
python setup.py build_ext --inplace
遇到如下错误:
正在创建库 build\temp.win-amd64-3.7\Release\Codes\PyCharm\snake\lib\csrc\extreme_utils\_ext.cp37-win_amd64.lib 和对象 build\temp.win-amd64-3.7\Release\Codes\PyCharm\snake\lib\csrc\extreme_utils\_ext.cp37-win_amd64.exp
utils.obj : error LNK2001: 无法解析的外部符号 "public: long * __cdecl at::Tensor::data_ptr<long>(void)const " (??$data_ptr@J@Tensor@at@@QEBAPEAJXZ)
build\lib.win-amd64-3.7\_ext.cp37-win_amd64.pyd : fatal error LNK1120: 1 个无法解析的外部命令
error: command 'D:\\Softwares\\VisualStudio\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\link.exe' failed with exit status 1120
解决方法:
原因可能是x64平台编译对data_ptr<long>的格式不支持,需要将long
改成 int64_t。
打开lib/csrc/extreme_utils/src/utils.cu文件,将里面的long全部替换成int64_t,再次运行编译即可。
3)进入lib/csrc/roi_align_layer路径运行
python setup.py build_ext --inplace
6、在用Sbd的预训练模型做可视化测试
1)下载预训练模型 here 然后放到这个路径/data/model/snake/sbd/149.pth
2)回到工程路径运行
python run.py --type demo --cfg_file configs/sbd_snake.yaml demo_path demo_images/2009_000871.jpg ct_score 0.3
运行结果: