The whole process of Pytorch3D installation - install it yourself

a brief introdction

Pytorch3D is a library for accelerating the calculation rate of deep learning when processing 3D related information. Deep learning sometimes needs to process a large amount of 3D data, such as in face modeling. At this time, using these libraries will greatly help us save computing costs.

Encounter problems

According to the official installation method, you will encounter many problems: https://github.com/facebookresearch/pytorch3d/blob/main/INSTALL.md. When I installed it personally, I couldn’t install it successfully by inputting relevant commands, and it took almost a morning plus a noon to solve it. I would like to share it here, hoping to help more people.

Preparation

1. The virtual environment created by conda

First of all, you need a virtual environment created with conda. There are many online tutorials on how to create it, so I won’t go into details here. Note that you must have the cudatoolkit package in your cuda. ​​This package is used to use cuda. ​​Simply put, it calls your computer GPU.

Remember the python/pytorch version and cudatoolkit version of your virtual environment. It is recommended to manually set the installation version for the pytorch version, otherwise it will be automatically installed to the latest version. The latest version is often incompatible with many other packages.

2.cub installation and configuration

The cub version must correspond to the cudatoolkit version. The link to the version corresponding description is here: https://gitcode.net/mirrors/nvidia/cub?utm_source=csdn_github_accelerator

After knowing what your version is, start downloading, download link: https://github.com/NVIDIA/cub/releases

Please add a picture description

After entering the webpage, scroll down and find the corresponding version of Assets. There are two compressed packages here. Generally, if it is a windows computer, choose zip, and if it is linux, choose tar.gz (and then use the command to decompress)

Then unzip the corresponding installation package.

After the decompression is complete, add the directory where the file is located to the environment variable

Environment variable setting method: Right-click My Computer (This Computer) - Properties - Advanced System Settings - Environment Variables - Path Variables - Add New Environment Variables

3. MinGW installation

There are blogs on the Internet saying that it needs to be installed, because I need to use vscode in my computer before, so I have installed it, and it is in the computer, so I am not sure whether it must be installed.

official installation

1. First download the pytorch3D installation package

Download link: https://github.com/facebookresearch/pytorch3d/releases

Be sure to pay attention to the version correspondence! !

Please add a picture description

For example, the picture above shows that pytorch3D version 0.7.1 only supports pytorch from 1.9.0 to 1.12.1

After downloading, unzip it. It is recommended to install it in the site-packages folder, because this folder is a place for storing various packages of pytorch, such as mine:.\anaconda3\Lib\site-packages

2. Change related files

The decompressed files cannot be used directly, and the code needs to be changed first.

Open the pytorch3D folder (my file name is pytorch3d-0.7.2), there is a setup.py folder inside, and modify the code in the following part:

Please add a picture description

The line 52 I commented out is the original code, and the line 53 with a red dot is the modified one. I guess the modification here is to not specify the compiler of C++. Because the underlying code of python is still C++, this package cannot be used directly after downloading, it needs to be installed and compiled before it can be used.

Some tutorials on the Internet changed the code in many places, but I only modified this one place and it can be used. If only one change is unsuccessful, refer to this blog ( click the link )

3. Install VS2019

You need to install vs2019, just find a tutorial on the Internet here, there are many tutorials. The reason for downloading vs2019 is to compile the downloaded installation package.

After downloading and installing, find this thing x64 Native Tools Command Prompt for VS 2019 (if it is win10win11, you can search directly in the search bar). This is the terminal that comes with vs2019.

4. Install! ! !

It's finally here.

First enter the following commands in the terminal window in turn:

set DISTUTILS_USE_SDK=1
set PYTORCH3D_NO_NINJA=1

Then enter this to compile and install pytorch3d:

python setup.py install

I remember that many lines of code were run in the terminal at that time, and it should be compiled line by line. After about fifteen minutes, it succeeded.

Guess you like

Origin blog.csdn.net/m0_61787307/article/details/129941897