最近在安装pytorch3D的时候遇到了很多问题,查了很多博客,但发现讲的都不太全,所以特将自己的及收集到的安装过程经验总结如下。我是在Anaconda中虚拟环境下安装的。
官方安装教程如下:https://github.com/facebookresearch/pytorch3d/blob/main/INSTALL.md,完全按照这个教程安装可能会遇到很多问题,因此需要补充一些细节。安装这个的前提是已经安装了pytorch。
总共需要安装的包有:
这里面除了cub需要单独安装(后面会单独讲),其他都可以用conda直接安装。推荐用conda安装,因为我没用其他方法试过,所以不确定不用conda会出现哪些问题。具体安装过程如下:
conda create -n pytorch-gpu python=3.9
conda activate pytorch3d
conda install -c fvcore -c iopath -c conda-forge fvcore iopath
conda install jupyter
pip install scikit-image matplotlib imageio plotly opencv-python
pip install black usort flake8 flake8-bugbear flake8-comprehensions
cub与cuda toolkit对应关系如下(图片截自https://github.com/NVIDIA/cub):
根据自己的cuda tookit版本选择对应的cub realase版本下载,下载地址为https://github.com/NVIDIA/cub/releases
我是按照一些博客教程的步骤安装了这个,但我也不确定是不是一定需要安装,以防万一大家还是安装一下比较好。
下载地址:https://github.com/facebookresearch/pytorch3d/releases注意版本要与pytorch对应,每个版本的Pytorch3d下有注明其适用的pytorch版本。
打开pytorch3D文件夹,找到setup.py文件,打开,将extra_compile_args = {“cxx”: [“-std=c++14”]} 修改为: extra_compile_args = {“cxx”: []};
set DISTUTILS_USE_SDK=1
set PYTORCH3D_NO_NINJA=1
python setup.py install
如果一切顺利,那么等待执行完成,pytorch就安装成功了。
也有可能会遇到一些错误,下面是一些常见错误的总结和解决方法。
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/include\cub/device/dispatch/dispatch_segmented_sort.cuh(338): error: invalid combination of type specifiers
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/include\cub/device/dispatch/dispatch_segmented_sort.cuh(338): error: expected an identifier
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/include\cub/device/dispatch/dispatch_segmented_sort.cuh(379): error: expected a member name
3 errors detected in the compilation of "D:/research/code/pytorch3d/pytorch3d/csrc/pulsar/cuda/renderer.backward.gpu.cu".
renderer.backward.gpu.cu
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\include\thrust\system\cuda\config.h(78): fatal error C1189:
#error: The version of CUB in your include path is not compatible with this release of Thrust.
CUB is now included in the CUDA Toolkit, so you no longer need to use your own checkout of CUB.
Define THRUST_IGNORE_CUB_VERSION_CHECK to ignore this. ball_query.cu
#ifndef THRUST_IGNORE_CUB_VERSION_CHECK
然后在它前面加上一行 #define THRUST_IGNORE_CUB_VERSION_CHECK
代码.该解决方法参考了https://github.com/facebookresearch/pytorch3d/issues/1299subprocess.CalledProcessError: Command ‘[‘ninja‘, ‘-v‘]‘ returned non-zero exit status 1.
...
...
File "D:\Programs\python3.6.8\lib\site-packages\torch\utils\cpp_extension.py", line 1529, in _run_ninja_build
raise RuntimeError(message)
RuntimeError: Error compiling objects for extension