Pytorch installation tutorial: the latest nanny-level tutorial

Table of contents

overview

The important thing is said three times: no need to install cuda, no need to install cuda, no need to install cuda

         1. Check your NVIDIA version

2. Create a conda environment

3. Install pytorch


This article is intended to help students who are about to enter the field of in-depth study

Before that, you need to install anaconda first. If you don’t understand, you can read the following article

The latest Anaconda installation - nanny level tutorial

overview


PyTorch is an open source deep learning framework that provides various tensor operations and can automatically perform gradient calculations through automatic derivation, making it easy to build various dynamic neural networks. Supports accelerated computing using GPU/TPU. (Torch Chinese Encyclopedia)
In January 2017, PyTorch was launched by Facebook Artificial Intelligence Research Institute (FAIR) based on Torch. It is a Python-based sustainable computing package that provides two advanced features: 1. Tensor computing (such as NumPy) with powerful GPU acceleration. 2. Deep neural network including automatic derivation system. (Baidu Encyclopedia)

The important thing is said three times: no need to install cuda, no need to install cuda, no need to install cuda

1. Check your NVIDIA version

ctrl+r enter cmd to open the command window, enter nvidia-smi to view your version number

nvidia-smi

 For example, here is 11.6

 What is the function of this version, that is, the cuda version corresponding to your pytorch cannot exceed this

If you choose to go to the official website to download, it will easily exceed this version (if you are a new computer, you will not have this trouble)

Enter Pytorch official website: PyTorch , find the version suitable for your computer

insert image description here

 So it is not recommended that you download it like this, it is meaningless. The official website will only give the latest version, not the most suitable version

2. Create a conda environment

If you installed anaconda according to my tutorial, then he will come with a 3.9 python

Or you can also type python in the command window to check your python version.

conda create -n env_name python=3.9

 # env_name is the name of the created virtual environment (you can choose an easy-to-remember name); the python version can be changed

It may take some time to create for the first time. After the creation is successful, activate the environment

source activate env_name # 激活虚拟环境,进入虚拟环境即可安装自己要的包

3. Install pytorch

As long as your NVIDIA query version is greater than or equal to 11.3, run the following code directly here, saving two months of detours

This pytorch can run most of the mainstream YOLOv5, v7 and other deep learning frameworks.

pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple

The source of this code has been changed. If it can’t be downloaded in ten minutes, there must be a problem. You can leave a message in the comment area, or learn from other bloggers.

Of course, the following URL is a must, and you will use it. It is recommended to save it. When you start writing papers by hand, you need to be able to configure the environment of various ancient algorithms, and it is your life-saving straw.

The URL corresponds to each version of pytorch and torchvision
https://pytorch.org/get-started/previous-versions/

Finally test whether the installation is successful

python
import torch
torch.__version__
torch.cuda.is_available()

insert image description here

It is best not to change the environment source, because Xiaobai is prone to problems.

If you need to download the package, use the following code directly, the orange is the code for changing the source

pip --default-timeout=5000 install package name -i https://pypi.tuna.tsinghua.edu.cn/simple

That's all for the tutorial.

Guess you like

Origin blog.csdn.net/weixin_45303602/article/details/132271697