安装pytorch3d最简单方法

安装pytorch3d的最简单方法

前言

安装pytorch3d踩了很多坑,现将最简单的方法公布如下:

一、pytorch3d是什么?

PyTorch3D的目标是帮助加速深度学习和3D交叉点的研究。3D数据比2D图像更复杂,在从事Mesh R-CNN和C3DPO等项目时,我们遇到了一些挑战,包括3D数据表示、批处理和速度。我们开发了许多有用的算子和抽象,用于3D深度学习,并希望与社区分享,以推动这一领域的新研究。
在PyTorch3D中,我们包含了高效的3D操作符、异构批处理功能和模块化可微渲染API,为该领域的研究人员提供了急需的工具包,以实现复杂3D输入的前沿研究。

来自:https://pytorch3d.org/docs/why_pytorch3d

二、安装步骤

1.添加anaconda源(最最最最最关键!!)

以清华源 ubuntu18.04为例,其他平台安装方法可以借鉴:


conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch3d/

conda config --set show_channel_urls yes

添加完成后可以使用conda info命令查看是否添加成功
!!!添加pytorch源和pytorch3d源是最关键的步骤!!!

2.创建环境

python3.8为例,这个看实际需求。

conda create -n pytorch3d python=3.8
conda activate pytorch3d

3.安装pytorch和pytorch3d

截止本文的编写时间,当前最版本pytorch3d为0.6.2,最高支持pytorch1.11.0,所以最好不要安装pytorch 1.12.0 以上版本;以pytorch 1.10.1版本为例,对了我的nvcc -v cuda版本是11.3,安装pytorch需要适配:


conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3

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

conda install pytorch3d

那么就是激动人心的时刻了: 安装pytorch3d最简单方法 4.更新一下编译安装吧

安装完自己的所需的其他环境后,PyTorch、fvcore、iopath是必须的。

编译安装实际上是最不容易出错的:
参考官网安装教程 https://github.com/facebookresearch/pytorch3d/blob/main/INSTALL.md

  1. Install from GitHub 如果可以科学上网,执行这条
pip install "git+https://github.com/facebookresearch/pytorch3d.git"

如果要使用发布版本的代码进行安装,而不是从主分支中获取,请使用以下方法。

pip install "git+https://github.com/facebookresearch/pytorch3d.git@stable"

对于版本早于CUDA 11的CUDA构建,如上所述,在构建之前按照官方文档设置CUB_HOME。

在macOS上从Github安装:应该提供一些环境变量,比如这样。

MACOSX_DEPLOYMENT_TARGET=10.14 CC=clang CXX=clang++ pip install "git+https://github.com/facebookresearch/pytorch3d.git"
  1. Install from a local clone 本地安装适用于大部分情况,可以下载zip之后解压
git clone https://github.com/facebookresearch/pytorch3d.git
cd pytorch3d && pip install -e .

要在从本地克隆运行安装后重建,请 rm-rf build/**/*.然后 pip install -e。在重新安装PyTorch之后,您通常需要重建pytorch3d。对于版本早于CUDA 11的CUDA构建,如上所述,在构建之前设置CUB_HOME。

从macOS上的本地克隆安装:

MACOSX_DEPLOYMENT_TARGET=10.14 CC=clang CXX=clang++ pip install -e .

从Windows上的本地克隆安装:根据PyTorch的版本,在编译之前可能需要更改某些PyTorch标头。这些问题经常在此存储库中的问题中进行讨论。在进行任何必要的修补后,您可以转到”x64 Native Tools命令提示符for VS 2019″进行编译和安装

cd pytorch3d
python3 setup.py install

安装后,您可以运行单元测试

python3 -m unittest discover -v -s tests -t .

总结

完结撒花,希望后续在使用pytorch3d的过程中能够出一些好的教程,期待自己可以~

有问题请留言, 成功的童鞋麻烦留言告知啦。

Original: https://blog.csdn.net/weixin_43357695/article/details/126063091
Author: LuH1124
Title: 安装pytorch3d最简单方法

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/727835/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球