Deep learning environment configuration 5 - torch-cpu=1.2.0 environment configuration under windows

Precautions

1. 2021/10/8 update

Many fans reported that TypeError: array () takes 1 positional argument but 2 were given errors, which can be solved by modifying the pillow version.

pip install pillow==8.2.0
  • 1

study foreword

Many people don't have a graphics card and want to configure a deep learning environment. The torch -gpu blog is useless. Get a cpu, so that it can be configured!

The environment configuration blog for the pytorch- gpu version is http://www.ifindbug.com/doc/id-48523/name-deep-learning-environment-configuration-2-torch-1-2-0-environment-configuration-under-windows.html .
insert image description here

Configuration tutorial for each version of pytorch

The configuration tutorials for each version of pytorch are as follows:
deep learning environment configuration 10 - torch==1.7.1 environment configuration under Ubuntu Deep learning environment configuration 8 - (30 series graphics card) torch==1.7.1 environment configuration depth
under windows
Learning environment configuration 5 - torch-cpu=1.2.0 environment configuration
under windows Deep learning environment configuration 2 - torch=1.2.0 environment configuration under windows

environmental content

torch: 1.2.0
torchvision: 0.4.0

Environment configuration

1. Anaconda installation

The installation of Anaconda is mainly for the convenience of environment management. You can install multiple environments on one computer at the same time. Different environments place different frameworks: pytorch, tensorflow, and keras can be installed in different environments. You only need to use conda create –n to create a new environment. That's it.

1. Download Anaconda

Students can choose to install the new version of Anaconda and the old version of Anaconda, there is no difference in the installation steps.

Download of the old version of anaconda:
The new version of Anaconda does not have VSCODE. If you can install the old version of Anaconda directly for the convenience of installing VSCODE, the Baidu network disk is connected as follows. You can also install the new version and then install VSCODE separately.
Link: https://pan.baidu.com/s/12tW0Oad_Tqn7jNs8RNkvFA Extraction code: i83n

Download of the new version of anaconda:
If you want to install the latest Anaconda, first log in to Anaconda's official website: https://www.anaconda.com/distribution/ . You can directly download the corresponding installation package.
insert image description here
insert image description here
Usually download 64-bit, open after the download is complete.

2. Installation of Anaconda

insert image description here
Select the installation location, you can not install it in the C drive.
insert image description here
I chose Add Anaconda to my PATH environment variable, which will automatically install anaconda into the system's environment variables, and the configuration will be more convenient.
insert image description here
After waiting for the installation, the installation of Anaconda is over.

Second, configure the pytorch environment

1. Creation and activation of pytorch environment

Win+R to start cmd, enter the following command in the command prompt:

conda create –n pytorch python=3.6
  • 1
activate pytorch 
  • 1

There are two instructions in total:
the previous one is used to create an environment called pytorch, the python version of which is 3.6.
The last instruction is used to activate an environment called pytorch.

2. Installation of pytorch library

Since all our operations must be performed in the corresponding environment, we need to activate the environment before installing the library.

activate pytorch 
  • 1

At this point, the cmd window looks like:
insert image description here
Then we enter the following command:

# CPU only
pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
  • 1
  • 2

This is the official instruction provided by pytorch for installing the cpu version of torch and torchvision.

3. Installation of other dependent libraries

But if you want to run deep learning models, there are some other dependent libraries that need to be installed. details as follows:

scipy == 1.2 .1 
numpy == 1.17 .0 
matplotlib == 3.1 .2 
opencv_python == 4.1 .2 .30 
torch == 1.2 .0 
torchvision == 0.4 .0 
tqdm == 4.60 .0 
Pillow == 8.2 .0 
h5py == 2.10.0 _
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

If you want a more convenient installation, you can create a requirements.txt file on the desktop or elsewhere, and copy the above content into the txt file.
insert image description here
Use the following command to install it. In the following instructions, the path in front of requirements.txt is the path where I put the file on the desktop, and you can modify it according to your computer.

pip install -r C : \ Users\ 33232 \ Desktop\ requirements.txt
  • 1

4. The installation is slow, please pay attention to changing the source

It should be noted that if the download and installation in pip is slow, you can change the source. You can go to the user folder, create a pip folder, and then create a txt file in the pip folder.
insert image description here
Modify the content of the txt file and change the suffix to ini

[ global ] 
index - url = http : //pypi.mirrors.ustc.edu.cn/simple [ install ] 
use - mirrors = true _ _ _ _ _ _ _ _ _
 _ _
mirrors = http : //pypi.mirrors.ustc.edu.cn/simple/trusted-host=pypi.mirrors.ustc.edu.cn _ _ _ _ _ _ _ _ _ _ _ _ 
_ _ _ _ _ _ _ _ _ _ _ _ _
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

insert image description here
insert image description here
After all installation is complete, restart the computer.

3. Install VSCODE

I personally like VSCODE, so I installed it. Other editing software can also be, personal preference.

1. Download the installation package and install (recommended)

The latest version of Anaconda does not have VSCODE, so it can be installed directly with Baidu VSCODE.

a. Download of VSCODE

Directly load the official website of VSCODE https://code.visualstudio.com/ , click Download for Windows to download.
insert image description here

b. Installation of VSCODE

First agree to the agreement, click Next.
insert image description here
Several ticks in the other should be checked, because this way, you can right-click the folder to open it with VSCODE, which is very convenient. Next step.
insert image description here
Proceed to the next step to install.
insert image description here

After the installation is complete, you can change your environment in the lower left corner.
insert image description here

2. Install on anaconda

Open anaconda and switch environments.
insert image description here
Install VSCODE, you can launch it after installation, and then you can pin VSCODE to the taskbar for easy opening.
insert image description here

Tags: Deep learning environment configuration 5 - torch-cpu=1.2.0 environment configuration under windows

Deep Learning Environment Configuration Neural network learning small record windows vscode pytorch Environment configuration

Related: Deep learning environment configuration 5 - torch-cpu=1.2.0 environment configuration under windows