这篇博客或许不能帮助你解决问题,只是希望能根据记录帮助理解。
spconv介绍
SPConv一种精度更高、速度更快的“即插即用”卷积。由重庆大学闫岩提出,GitHub地址如下地址。(@Janet_xueting感谢提出的问题,以后我会调研更加完备。)
编译
我的编译源码来自源码,这里的版本是1.0。务必确认自己版本的问题。接下来如下操作:
sudo apt-get install libboost-all-dev
python setup.py bdist_wheel
cd ./dist
pip install *.whl
一般来说正常步骤之后就可以happy的使用这个功能块,但是实际情况与之相违。
踩坑
- 保证自己的cmake>=3.13.2,并且已经添加到环境目录;
- gcc版本不能高于7之后,我最开始用的gcc9.2编译失败,切换会7.4之后成功,gcc升降可以参考,以及参考,实践还是建立软连接好使。
- 如果pytorch版本>=1.4.0并且遇到"nvcc fatal: unknown -Wall", 需要去torch所在目录,找到Caffe2Targets.cmake文件,注释掉“INTERFACE_COMPILE_OPTIONS”就行。操作如下:终端输入
locate Caffe2Targets.cmake
找到自己编译的torch环境目录下的Caffe2Targets.cmake文件,注释掉 “-Wall;-Wextra;-Wno-unused-parameter;-Wno-missing-field-initializers;-Wno-write-strings;-Wno-unknown-pragmas;-Wno-missing-braces;-fopenmp”,听说有两段,但是我只找到一段。 - 如果是"recipe for target ‘src/spconv/CMakeFiles/spconv.dir/reordering.cc.o’ failed",这个错误可能解决如下:
After almost an entire day of debugging I finally managed to build spconv.
In order to successfully build spconv I had to modify setup.py in the following way
Before:
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
After
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
build_make_file = 'build/temp.linux-x86_64-3.7/src/spconv/CMakeFiles/spconv.dir/build.make'
link_file = 'build/temp.linux-x86_64-3.7/src/spconv/CMakeFiles/spconv.dir/link.txt'
for file in [build_make_file, link_file]:
with open(file) as f:
newText = f.read().replace('/usr/local/cuda', env['CUDA_ROOT'])
with open(file, "w") as f:
f.write(newText)
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
- 20201105 pytorch1.4下编译成功
之前1.4一直遇到“spconv/src/spconv/all.cc:20:91: error: no matching function for call to ‘torch::jit::RegisterOperators::RegisterOperators(const char [28], )’
torch::jit::RegisterOperators(“spconv::get_indice_pairs_2d”, &spconv::getIndicePair<2>)
”
这个错误在我把anaconda3/envs/py1_4/lib/python3.6/site-packages/torch/share/cmake/Caffe2下的Caffe2Targets.cmake文件,注释掉“INTERFACE_COMPILE_OPTIONS”之后仍然遇到此错误,解决方法如下:
在 src/spconv/all.cc中, pytorch1.4包括及以后版本早就把torch::jit::RegisterOperators::RegisterOperators 替换为 torch::RegisterOperators::RegisterOperators , 所以移除 “jit“” namespace再次编译既可以成功。
成功界面:
我叫谢琛,深度学习探索者一枚!(有意咨询xiec177)
tensorflow/pytorch交流群请加QQ:548368797
更多咨询咨询请关注!