spconv简介、环境配置与安装以及遇到的各种报错处理

spconv简介、环境配置与安装以及遇到的各种报错处理

此篇博客将介绍spconv、如何安装spconv 1.x和spconv2.x,以及遇到的各种报错处理,更多详细内容可以参考官方的GitHub链接https://github.com/traveller59/spconv

spconv介绍

spconv为空间稀疏卷积库,一个提供高度优化的稀疏卷积实现和张量核心支持的项目。spconv的设计旨在有效地处理包含大量零元素的稀疏数据,主要用于3D点云的卷积操作。

spconv安装

博主自己的硬件配置如下:

  • Linux(Ubuntu 20.04)
  • NVIDIA GeForce RTX 3090
  • NVIDIA显卡驱动版本:12.0
  • CUDA version:11.3

首先安装pytorch、cuda等相关软件包:

conda create --name env_name python=3.7 cmake=3.22.1
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge
conda install cudnn -c conda-forge
conda install boost

打开bashrc文件:vim ~/.bashrc,设置环境变量:

export PATH=/usr/local/cuda/bin:$PATH
export CUDA_HOME=/usr/local/cuda/bin:$CUDA_HOME
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/[$YourUserName]/anaconda3/envs/[$YourEnvName]/include
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/[$YourUserName]/anaconda3/envs/[$YourEnvName]/include
export LIBRARY_PATH=$LIBRARY_PATH:/[$YourUserName]/anaconda3/envs/[$YourEnvName]/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/[$YourUserName]/anaconda3/envs/[$YourEnvName]/lib

源码安装spconv 1.x

spconv 1.x官方已经舍弃掉不维护了,推荐使用spconv 2.x。而且spconv 2.x相较于spconv 1.x做了优化,速度、效率等有所提升。若由于版本需要,不得不需要安装spconv 1.x,则需要源码编译安装。
下面是官方给出的安装spconv 1.2.1的步骤:

# STEP 1: get source code
git clone https://github.com/traveller59/spconv.git 
cd spconv
git checkout v1.2.1
git submodule update --init --recursive 

# STEP 2: compile
python setup.py bdist_wheel

# STEP 3: install
cd ./dist
pip install spconv-1.2.1-cp37-cp37m-linux_x86_64.whl

# check if is successfully installed
python 
import spconv

pip安装spconv 2.x

spconv 2.x目前已经支持通过pip install的方式进行安装了,可以根据自己的环境进行选择运行以下命令:

# 预先安装cumm和timm
pip install cumm timm
# cpu
pip install spconv
# cuda 10.2
pip install spconv-cu102
# cuda 11.3
pip install spconv-cu113
# cuda 11.4
pip install spconv-cu114
# cuda 11.6
pip install spconv-cu116
# cuda 11.7
pip install spconv-cu117
# cuda 11.8
pip install spconv-cu118
# cuda 12.0
pip install spconv-cu120

报错处理

在此主要列举了在安装spconv 1.x的报错和解决方法。

报错一

error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

输入gcc --version获取gcc版本是4.8.5,解决办法是安装5.4.0版本的gcc。在此,我使用的是在conda虚拟环境中安装:

conda install https://anaconda.org/brown-data-science/gcc/5.4.0/download/linux-64/gcc-5.4.0-0.tar.bz2

这个package有一个坑在于,在miniconda3/envs/env_name/lib文件下的libstdc++.solibstdc++.so.6软链接指向的是libstdc++.so.6.0.21动态链接库,并且这个软链接会覆盖环境内原有的软链接,也就是说,之后使用的都会是这个package所提供的动态链接库。

这就会导致如果你的pytorch版本较高时,由于libstdc++.so.6.0.21版本较旧,所以会报错:

ImportError: /xxx/miniconda3/envs/env_name/lib/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /xxx/miniconda3/envs/env_name/lib/python3.7/site-packages/open3d/open3d.cpython-37m-x86_64-linux-gnu.so)

解决方法是,进入miniconda3/envs/env_name/lib,然后将软链接libstdc++.solibstdc++.so.6指向高版本的动态链接库,例如同目录下的libstdc++.so.6.0.32,命令如下:

# 先删除原来的软连接
rm libstdc++.so
rm libstdc++.so.6
# 建立新的软连接
ln -s libstdc++.so.6.0.32 libstdc++.so
ln -s libstdc++.so.6.0.32 libstdc++.so.6

参考链接:https://blog.csdn.net/j___t/article/details/107308883

报错二

/xxx/spconv/include/tensorview/tensorview.h:741:23: error: template declaration of ‘constexpr const char* const tv::type_s’
 constexpr const char *type_s = detail::TypeToString<T>::value;
                       ^
/xxx/spconv/include/tensorview/tensorview.h: In member function ‘std::string tv::TensorView<T, Rank, PtrTraits, Tindex>::repr(Os&) const’:
/xxx/spconv/include/tensorview/tensorview.h:1124:26: error: ‘type_s’ was not declared in this scope
       ss << "Tensor[" << type_s<T> << "]" << std::endl;
                          ^
/xxx/spconv/include/tensorview/tensorview.h:1124:34: error: expected primary-expression before ‘>’ token
       ss << "Tensor[" << type_s<T> << "]" << std::endl;
                                  ^
/xxx/spconv/include/tensorview/tensorview.h:1124:36: error: expected primary-expression before ‘<<’ token
       ss << "Tensor[" << type_s<T> << "]" << std::endl;
                                    ^
/xxx/spconv/include/tensorview/tensorview.h:1135:24: error: ‘type_s’ was not declared in this scope
     ss << "Tensor[" << type_s<T> << "]: shape=" << shape()
                        ^
/xxx/spconv/include/tensorview/tensorview.h:1135:32: error: expected primary-expression before ‘>’ token
     ss << "Tensor[" << type_s<T> << "]: shape=" << shape()
                                ^
/xxx/spconv/include/tensorview/tensorview.h:1135:34: error: expected primary-expression before ‘<<’ token
     ss << "Tensor[" << type_s<T> << "]: shape=" << shape()
                                  ^
/xxx/spconv/include/tensorview/tensorview.h: At global scope:
/xxx/spconv/include/tensorview/tensorview.h:1270:23: error: template declaration of ‘constexpr const char* const tv::detail::type_printf_format_v’
 constexpr const char *type_printf_format_v = TypePrintfFormat<T>::value;
                       ^
/xxx/spconv/include/tensorview/tensorview.h: In function ‘void tv::printTensorView(tv::TensorView<T, Rank, PtrTraits, Tindex>)’:
/xxx/spconv/include/tensorview/tensorview.h:1343:34: error: ‘type_printf_format_v’ is not a member of ‘tv::detail’
   return printTensorView(tensor, detail::type_printf_format_v<Traw>);
                                  ^
/xxx/spconv/include/tensorview/tensorview.h:1343:67: error: expected primary-expression before ‘>’ token
   return printTensorView(tensor, detail::type_printf_format_v<Traw>);
                                                                   ^
/xxx/spconv/include/tensorview/tensorview.h:1343:68: error: expected primary-expression before ‘)’ token
   return printTensorView(tensor, detail::type_printf_format_v<Traw>);
                                                                    ^
/xxx/spconv/include/tensorview/tensorview.h: In function ‘void tv::printTensorView(const T*, tv::Shape)’:
/xxx/spconv/include/tensorview/tensorview.h:1349:26: error: ‘type_printf_format_v’ is not a member of ‘tv::detail’
                          detail::type_printf_format_v<Traw>);
                          ^
/xxx/spconv/include/tensorview/tensorview.h:1349:59: error: expected primary-expression before ‘>’ token
                          detail::type_printf_format_v<Traw>);
                                                           ^
/xxx/spconv/include/tensorview/tensorview.h:1349:60: error: expected primary-expression before ‘)’ token
                          detail::type_printf_format_v<Traw>);

解决方法是直接将build文件夹删掉,重新运行python setup.py bdist_wheel就解决了,如果没有解决,可以尝试一下将boost/. 复制到spconv/include/,但此方法我没有尝试,不确定是否可以解决。

报错三

以下两个报错均是由CUDA环境变量未找到或不正确导致:

CMake Error at /disk1/zhuhe/miniconda3/envs/env_name/lib/python3.7/site-packages/cmake/data/share/cmake-3.28/Modules/CMakeDetermineCUDACompiler.cmake:270 (message):
  Failed to detect a default CUDA architecture.



  Compiler output:

Call Stack (most recent call first):
  CMakeLists.txt:9 (project)
CMake Error at /xxx/miniconda3/envs/env_name/lib/python3.7/site-packages/torch/share/cmake/Caffe2/public/cuda.cmake:87 (message):
  FindCUDA says CUDA version is (usually determined by nvcc), but the CUDA
  headers say the version is ERROR: ld.so: object

  10.2.  This often occurs when you set both CUDA_HOME and
  CUDA_NVCC_EXECUTABLE to non-standard locations, without also setting PATH
  to point to the correct nvcc.  Perhaps, try re-running this command again
  with PATH=/usr/local/cuda-10.2/bin:$PATH.  See above log messages for more
  diagnostics, and see https://github.com/pytorch/pytorch/issues/8092 for
  more details.
Call Stack (most recent call first):
  /xxx/miniconda3/envs/env_name/lib/python3.7/site-packages/torch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  /xxx/miniconda3/envs/env_name/lib/python3.7/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:22 (find_package)

打开bashrc文件:vim ~/.bashrc,设置好CUDA的相关环境变量。

export PATH=/usr/local/cuda/bin:$PATH
export CUDA_HOME=/usr/local/cuda
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
<think>嗯,用户问的是如何在Windows 10上下载spconv-cu113 2.3.3。首先,我需要确定spconv是什么。spconv是一个用于稀疏卷积的库,通常在深度学习中使用,特别是处理点云数据,比如在3D目标检测任务中。用户提到的cu113应该是指CUDA 11.3版本,所以这个库是针对使用CUDA 11.3的环境编译的。 接下来,我需要考虑用户可能遇到的问题。在Windows上安装这类库通常比Linux复杂,因为它们可能依赖特定的编译工具和库。用户可能已经尝试过直接使用pip install,但可能遇到问题,比如找不到合适的版本或者编译错误。 首先,我应该检查spconv的官方仓库。GitHub上的open-mmlab/spconv可能有相关的发布版本或者文档。访问其GitHub页面后,发现确实有不同版本的发布,但需要确认是否支持Windows。通常,spconv的官方可能主要支持Linux,但可能有社区提供的Windows版本。 然后,考虑PyPI的情况。使用pip search spconv或者直接访问PyPI网站查看是否存在预编译的Windows版本。不过,spconv的PyPI包可能只提供Linux的wheel文件,或者需要从源代码编译,而Windows上编译可能需要Visual Studio和CUDA工具包。 用户可能没有安装正确的编译工具,或者CUDA环境配置不正确。这时候,可能需要指导用户安装CUDA 11.3,并确保他们的GPU驱动兼容。另外,需要安装对应版本的PyTorch,因为spconv可能依赖特定版本的PyTorch。 另外,可能存在第三方提供的预编译版本。例如,有人可能将Windows的wheel文件上传到某个存储库,用户可以通过pip指定URL来安装。需要提醒用户注意来源的可信度,避免安全风险。 如果从源代码编译,用户需要安装CMake、Ninja、CUDA工具包,并正确设置环境变量。这可能对不熟悉编译的用户来说比较复杂,所以需要分步骤指导,比如安装依赖项,克隆仓库,切换分支,配置CMake,然后构建安装。 还需要检查是否有已知的Windows编译问题,比如特定的补丁或修改代码的需要。例如,某些文件路径可能需要调整,或者编译器选项需要更改以兼容Windows。 最后,测试安装是否成功,可以通过Python导入spconv并运行简单示例来验证。如果遇到错误,可能需要检查CUDA路径、环境变量,或者重新安装依赖项。 总结可能的步骤:1. 检查官方文档;2. 安装依赖项;3. 尝试预编译的wheel;4. 从源码编译;5. 验证安装。需要详细说明每一步,并针对Windows环境给出具体建议,比如使用Visual Studio的版本,设置环境变量等。</think>在Windows 10上安装`spconv-cu113 2.3.3`需要分步骤操作,以下是详细指南: --- ### **步骤1:确认系统环境** 1. 确保已安装 **CUDA 11.3**(检查方法:命令行输入 `nvcc --version`) 2. 确认Python版本为 **3.6-3.8**(推荐3.7或3.8) 3. 安装对应版本的 **PyTorch**(需CUDA 11.3匹配,例如 `torch==1.10.0+cu113`) --- ### **步骤2:下载预编译包(推荐)** 由于官方未提供Windows预编译包,可通过第三方渠道尝试: 1. 访问 [spconv GitHub Issues](https://github.com/traveller59/spconv/issues) 搜索用户分享的Windows编译版本 2. 下载社区维护的预编译包(示例命令): ```bash pip install spconv-cu113==2.3.3 -f https://download.openmmlab.com/mmdetection3d/release_thirdparty/ ``` --- ### **步骤3:从源码编译(备用方案)** #### **准备工作** 1. 安装 **Visual Studio 2019**(勾选“C++桌面开发”) 2. 安装 **CMake** 并添加至系统路径 3. 安装 **CUDA 11.3 Toolkit**(需系统PATH匹配) #### **编译流程** ```bash # 克隆spconv仓库(注意分支版本) git clone https://github.com/traveller59/spconv.git cd spconv git checkout v2.3.3 # 配置编译环境 set DISTUTILS_USE_SDK=1 set CUDA_HOME=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3 # 编译安装 python setup.py bdist_wheel pip install dist/spconv-2.3.3*.whl ``` --- ### **步骤4:验证安装** ```python import spconv print(spconv.__version__) # 应输出 2.3.3 ``` --- ### **常见问题** 1. **CUDA版本不匹配**:必须严格对齐CUDA 11.3和PyTorch的CUDA版本 2. **MSVC编译错误**:确保安装Visual Studio 2019的C++编译组件 3. **依赖缺失**:需安装`ninja`和`pybind11`:`pip install ninja pybind11` --- ### **替代方案** 如果以上方法失败,可尝试: 1. 使用Docker容器运行Linux环境编译 2. 改用Linux子系统(WSL2)进行安装 建议优先尝试预编译包,若需进一步帮助可提供具体报错信息。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI Player

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值