配置DexGraspNet所需环境时遇到的问题与解决方法

问题描述

配置DexGraspNet所需环境时遇到的问题
1:pytorch3d
2:TorchSDF

目前环境配置:ubuntu 20.04,cuda 11.3


问题1流程复盘:

conda创建并激活环境,由于pytorch3d限制了Python 3.8, 3.9 or 3.10,所以不能按照ReadMe中所建议的创建python 3.7环境。

conda create -n dexgraspnet python=3.8
conda activate dexgraspnet

安装与cuda对应的pytorch(可查询https://pytorch.org/get-started/previous-versions/

conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch

此时,python查看pytorch版本,并判断cuda是可用的。

>>> import torch                                                                          
>>> print(torch.__version__)                                                              
1.12.0                                                                                    
>>> print(torch.cuda.is_available())                                                      
True

继续安装

conda install pytorch3d

conda install transforms3d
conda install trimesh
conda install plotly

pip install urdf_parser_py
pip install scipy

pip install networkx  # soft dependency for trimesh
conda install rtree  # soft dependency for trimesh

再通过python查看pytorch版本时,发现与之前版本不一致,并判断cuda是不可用的。

>>> import torch
>>> print(torch.__version__)
1.12.0.post2
>>> torch.version.cuda
>>> print(torch.cuda.is_available())
False

创建新环境,逐步执行上述流程,判断哪一步安装导致cuda不可用
发现是直接使用conda install pytorch3d安装pytorch3d时,产生了依赖冲突

问题1解决——pytorch3d安装:

重新创建并激活环境,安装与cuda 11.3相对应的pytorch

conda create -n dexgraspnet python=3.8
conda activate dexgraspnet
conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch

在安装pytorch3d时,参考https://github.com/facebookresearch/pytorch3d/blob/main/INSTALL.md

首先安装依赖

conda install -c fvcore -c iopath -c conda-forge fvcore iopath

因为CUDA 11.3 < 11.7,所以需要cub构建依赖项

conda install -c bottler nvidiacub

按照如下命令安装pytorch3d

conda install pytorch3d -c pytorch3d

此时,检测pytorch、cuda、以及pytorch3d,都是正常的

>>> import torch
>>> print(torch.__version__)
1.12.0
>>> print(torch.cuda.is_available())
True
>>> import pytorch3d
>>> from pytorch3d import _C

问题2流程复盘及解决:

按照DexGraspNet所列出的步骤安装TorchSDF,具体步骤如下

cd DexGraspNet/thirdparty
git clone https://github.com/wrc042/TorchSDF.git
cd TorchSDF
git checkout 0.1.0
bash install.sh

在运行指令git checkout 0.1.0时,报错。该条指令是在Git 中切换到了标签 0.1.0,执行后提示目前工作区处于"detached HEAD" 状态,不属于任何分支。

(dexgraspnet) tianyu@tianyu:/mnt/91b4721e-2245-4799-a473-2ff794a00e67/DexGraspNet/thirdparty/TorchSDF$ git checkout 0.1.0
Note: switching to '0.1.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at f2e8226 [UPDATE] add README

查看TorchSDF官方指导,发现直接安装即可

bash install.sh

报错。第一个错误提示NameError: name 'IGNORE_TORCH_VER' is not defined意味着 setup.py 中使用到了未定义的变量 IGNORE_TORCH_VER。第二个错误提示ImportError: cannot import name '_C' from 'torchsdf'则意味着无法从 torchsdf 模块中导入 _C

(dexgraspnet) tianyu@tianyu:/mnt/91b4721e-2245-4799-a473-2ff794a00e67/DexGraspNet/thirdparty/TorchSDF$ bash install.sh
Traceback (most recent call last):
  File "setup.py", line 32, in <module>
    if IGNORE_TORCH_VER:
NameError: name 'IGNORE_TORCH_VER' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/mnt/91b4721e-2245-4799-a473-2ff794a00e67/DexGraspNet/thirdparty/TorchSDF/torchsdf/__init__.py", line 1, in <module>
    from torchsdf.sdf import *
  File "/mnt/91b4721e-2245-4799-a473-2ff794a00e67/DexGraspNet/thirdparty/TorchSDF/torchsdf/sdf.py", line 2, in <module>
    from torchsdf import _C
ImportError: cannot import name '_C' from 'torchsdf' (/mnt/91b4721e-2245-4799-a473-2ff794a00e67/DexGraspNet/thirdparty/TorchSDF/torchsdf/__init__.py)

参考https://github.com/wrc042/TorchSDF/issues/1所提供的建议,重新配置环境,只安装了与cuda 11.3所匹配的 pytorch, 在安装TorchSDF时没有再报错。安装结束后再执行git checkout 0.1.0时,会提示

(dexgraspnet) tianyu@tianyu:/mnt/91b4721e-2245-4799-a473-2ff794a00e67/DexGraspNet/thirdparty/TorchSDF$ git checkout 0.1.0
warning: refname '0.1.0' is ambiguous.
Already on '0.1.0'

但后续又重装了环境,再通过bash install.sh指令安装TorchSDF时,由于已经安装过,所以会报错,需要卸载后重装。

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值