从源码安装Pytorch3D详细记录及学习资料

从源码安装Pytorch3D详细记录及学习资料
https://zhuanlan.zhihu.com/p/512347464
下载合适的基础镜像
第一步:选择pytorch基础镜像库。由于我们需要用到cuda工具箱,但是我又懒得自己配置CUDA和驱动,于是我直接选择了pytorch 1.9 的devel版本,devel版本的镜像中包含必须的CUDA组件和驱动。由于pytorch3d对于pytorch和cuda的版本都有要求,需要选择合适的版本。

这里,我选择的是python 3.7 + pytorch 1.9 + cuda10.2(注意,这里假设你已经在宿主机配置好显卡驱动和nvidia-docker,宿主机的显卡信息能通过nvidia-docker映射进容器内)

docker pull pytorch/pytorch:1.9.0-cuda10.2-cudnn7-devel
我们还需要进入镜像配置下基本工具

nvidia-docker run -it pytorch/pytorch:1.9.0-cuda10.2-cudnn7-devel /bin/bash
检查nvcc编译器

root@xxx:/workspace# nvcc -V
nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89
检查CUDA工具箱

root@xxx:/workspace# cd /usr/local/ && ls
bin cuda cuda-10.2 etc games include lib man sbin share src
查看驱动是否正常运行

nvidia-smi # 能看到显卡信息说明基本没有问题
安装git、vim、sudo、curl等基本工具

apt-get update
apt-get install sudo
sudo apt-get install vim
sudo apt-get install git
sudo apt-get install curl
配置CUB工具
第二步:配置CUB工具。按照Pytorch3D的安装文档说明,如果需要从源码编译支持CUDA的pytorch3d,需要在编译前先配置好CUB,并设置好CUB_HOME。

cd /mnt/
curl -LO https://github.com/NVIDIA/cub/archive/1.10.0.tar.gz
tar xzf 1.10.0.tar.gz
配置CUB_HOME环境变量

vim ~/.bashrc

在最后添加

export CUB_HOME=/mnt/cub-1.10.0

更新一下

source ~/.bashrc
因为我们选择的pytorch镜像包含了cuda工具箱,在编译pytorch3d的时候,cuda会被自动include到编译过程中,当然为保险起见,我们也可以指定 FORCE_CUDA 环境变量为 1 .

export FORCE_CUDA=1

同时可考虑手动添加CUDA到链接路径中

export PATH=“/usr/local/cuda-10.2/bin: P A T H " e x p o r t L D L I B R A R Y P A T H = " / u s r / l o c a l / c u d a − 10.2 / l i b 64 : PATH" export LD_LIBRARY_PATH="/usr/local/cuda-10.2/lib64: PATH"exportLDLIBRARYPATH="/usr/local/cuda10.2/lib64:LD_LIBRARY_PATH”

从源码编译Pytorch3D
第三步:从源码编译Pytorch3D。我最终并没有采用conda的方式,因为在尝试的过程中遇到了一些conda检查的依赖冲突的问题,导致无法安装pytorch3d,于是我决定采用了从源码进行编译的方式。如果前两步,你都确认没有问题了,那么最后这步大概率是顺利的。

pip install “git+https://github.com/facebookresearch/pytorch3d.git”
安装log

root@xxx:/mnt# pip install “git+https://github.com/facebookresearch/pytorch3d.git”
Collecting git+https://github.com/facebookresearch/pytorch3d.git
Cloning https://github.com/facebookresearch/pytorch3d.git to /tmp/pip-req-build-2ab2c97d
Running command git clone -q https://github.com/facebookresearch/pytorch3d.git /tmp/pip-req-build-2ab2c97d
Collecting fvcore
Downloading fvcore-0.1.5.post20220506.tar.gz (50 kB)
|████████████████████████████████| 50 kB 281 kB/s
Collecting iopath

Building wheels for collected packages: pytorch3d, fvcore, termcolor
Building wheel for pytorch3d (setup.py) … done
Created wheel for pytorch3d: filename=pytorch3d-0.6.2-cp37-cp37m-linux_x86_64.whl size=30640003 sha256=0bbe1f267973a683926895ea91581d1c1b11c34c4ce3ec4a4a477af5536e33e2

Installing collected packages: portalocker, yacs, termcolor, tabulate, iopath, fvcore, pytorch3d
Successfully installed fvcore-0.1.5.post20220506 iopath-0.1.9 portalocker-2.4.0 pytorch3d-0.6.2 tabulate-0.8.9 termcolor-1.1.0 yacs-0.1.8
检查pytorch3d的版本信息

import torch
torch.cuda.is_available()
True
import pytorch3d
pytorch3d.version
‘0.6.2’
Pytorch3D测试用例
我们从ARkit中导出一些BS系数,用Pytorch3D随便渲个白模试试,看看能否利用到GPU

root@xxx:/workspace# python ./pytorch3d_demo.py
building Pytorch3D Demo, Device: cuda …
/opt/conda/lib/python3.8/site-packages/pytorch3d/io/obj_io.py:532: UserWarning: No mtl file provided
warnings.warn(“No mtl file provided”) # 没有用到纹理,只是渲个白模
building Pytorch3D Demo ! Device: cuda
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 67/67 [00:14<00:00, 4.57it/s]

我们可以看到,显卡已经充分被用起来了,说明一些正常,终于可以愉快地玩耍了。

Tue May 10 12:37:26 2022
±----------------------------------------------------------------------------+
| NVIDIA-SMI 460.106.00 Driver Version: 460.106.00 CUDA Version: 11.2 |
|-------------------------------±---------------------±---------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=++==============|
| 0 Tesla P40 Off | 00000000:88:00.0 Off | 0 |
| N/A 37C P0 102W / 250W | 1543MiB / 22919MiB | 100% Default |
| | | N/A |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 4322 C python 1541MiB |
±----------------------------------------------------------------------------+
渲染后的结果如下:

动图
Pytorch3D一些简单的用法可以参考以下我收集的一些资料:

[1] [pytorch3d官方使用文档](Welcome to PyTorch3D’s documentation!)
[2] pytorch3d官方安装教程
[3] [pytorch3d 配置](pytorch3d 配置)
[4] Pytorch3d学习记录
[5] [pytorch3d-视频教程](通过 PyTorch3D进行 3D深度学习_哔哩哔哩_bilibili)
[6] [PyTorch3D 立体隐式形状渲染:教你构建场景 3D 结构](PyTorch3D 立体隐式形状渲染:教你构建场景 3D 结构)
[7] 论文:Accelerating 3D Deep Learning with PyTorch3D
[8] [渲染管线(Renderer Pipeline)介绍:以Pytorch3D为例](渲染管线(Renderer Pipeline)介绍:以Pytorch3D为例)
[9] batching meshes
[10] [PyTorch3D · A library for deep learning with 3D data](PyTorch3D · A library for deep learning with 3D data)
[11] pytorch3d应用手册-官方
[12] why_pytorch3d-doc
[13] render_textured_meshes
[13] Pytorch3D应用简介
[14] PyTorch3D:论文解读

  • 21
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值