1、 pip list
, 检查自己是否已经存在一个不能用的pytorch3d, pip uninstall pytorch3d
2、https://github.com/facebookresearch/pytorch3d/blob/main/INSTALL.md
访问官方教程,跟着做,不要相信小道链接
3、python版本可以改变
1、创建conda python3.9的虚拟环境
conda create -n pytorch3d python=3.9
conda activate pytorch3d
conda install pytorch=1.13.0 torchvision pytorch-cuda=11.6 -c pytorch -c nvidia
conda install -c iopath iopath
curl -LO https://github.com/NVIDIA/cub/archive/1.10.0.tar.gz
tar xzf 1.10.0.tar.gz
export CUB_HOME=$PWD/cub-1.10.0
2、若基于cuda,需通过下面这个命令安装所需要的库
conda install -c conda-forge -c fvcore fvcore
conda install -c bottler nvidiacub
3、安装pytorch3d
conda install pytorch3d -c pytorch3d
4、写在最后
一直安装失败怎么办?–>去github下载pytorch3d,放到Anaconda3\envs\msx\Lib\site-packages\pytorch3d,其中msx是我的conda虚拟环境名字
下载地址:https://github.com/facebookresearch/pytorch3d/tree/main/pytorch3d
注意是有_init_.py文件的,如上图所示是可以引入成功的,该方法同时适用于Ubuntu服务器
官方示例:
from pytorch3d.utils import ico_sphere
from pytorch3d.io import load_obj
from pytorch3d.structures import Meshes
from pytorch3d.ops import sample_points_from_meshes
from pytorch3d.loss import chamfer_distance
# Use an ico_sphere mesh and load a mesh from an .obj e.g. model.obj
sphere_mesh = ico_sphere(level=3)
verts, faces, _ = load_obj("model.obj")
test_mesh = Meshes(verts=[verts], faces=[faces.verts_idx])
# Differentiably sample 5k points from the surface of each mesh and then compute the loss.
sample_sphere = sample_points_from_meshes(sphere_mesh, 5000)
sample_test = sample_points_from_meshes(test_mesh, 5000)
loss_chamfer, _ = chamfer_distance(sample_sphere, sample_test)