This article was written to remember to build an environment for ** pytorch ** with ** ubuntu **. If you want to know about pytorch, please see the article here.
- ubuntu18.04
- GeForce GTX TITAN X
- CUDA 10.0
- anaconda 4.8.3
- python 3.7
- pycharm
If you want to know GPU related information (CUDA etc.), please refer to the article here.
Now let's build the environment.
This time the IDE uses pycharm.
The installation destination is the following URL. https://www.jetbrains.com/pycharm/download/#section=linux
You can download the following Communities. (Students can also use Professional if they have the email address specified by the school.) For the setup, I referred to the here site.
You can download it from the ubuntu launcher or from the ubuntu software in Application Search. Please refer to the above Site for setup.
The installation destination is the following URL. https://www.anaconda.com/products/individual The latest version will be installed when you download from the above URL. If you want an older version, you can choose from here.
First, move to the folder where you downloaded anaconda on your device. Therefore,
$ bash Anaconda3-2020.02-Linux-x86_64.sh
The file name is the file name you dropped.
Please, press ENTER to continue
When the command appears, press enter. Then scroll down the description
Do you accept the license terms?[yes|no]
When the command appears, type yes and press enter. Next, you will be asked about the pass, but if you do not change it, you can enter as it is. You will be asked if you want to enter VS Code, but this time I will set it to no.
It is OK if you do not throw an error by typing the following command at the end.
$ conda -V
Open the anaconda config file in the vim editor
$ vi ~/.bashrc
Add the following path as it can be anywhere.
Insert command: i
Save command: ZZ
$ export PATH=~/anaconda3/bin:$PATH
Execute the following command after adding
$ source ~/.bashrc
If you execute the following command again, the version of anaconda will come out.
$ conda -V
If you have any concerns about the path, please refer to here.
This time I want to install pytorch on the virtual environment of anaconda, so first create the virtual environment of anaconda. Here, specify what you want to use for python.
$ conda create -n test_torch python=3.7 anaconda
Check if the virtual environment is created.
$ conda info -e
# conda environments:
#
test_torch /home/user/anaconda3/envs/test_torch
Make the virtual environment Active.
$ conda activate test_torch
When you check the state of the virtual environment
$ conda info -e
# conda environments:
#
test_torch * /home/user/anaconda3/envs/test_torch
You can see that the virtual environment has been successfully started. By the way, if you want to make the virtual environment inactive, use the following command.
$ conda deactivate
Install pytorch on the virtual environment. Since pytorch will be used on GPU this time, install the GPU version with the command below cuda. It is safe to put a cuda toolkit that is compatible with cuda in your computer. Check the supported cuda and commands from here.
$ conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
Next, create an environment for pytorch with pycharm. Please refer to the here site for the detailed procedure. I will briefly introduce it here. In pycharm's new project, click "..." in the Visiting interpreter. After that, specify the python of the virtual environment created earlier from the "..." of the interpreter of Conda Environment. Finally, press Create to create the environment.
As a test, after creating a python file from new, execute the following code
import torch
num = torch.randn(3,3)
num.cuda()
print(num)
If you get such a result, you are successful. Thank you for your hard work.
tensor([[-1.3524, -0.1332, -1.7219],
[ 1.1739, 0.3055, 1.4518],
[-2.2588, -1.2884, -1.4783]])
I'm in the process of switching from Keras to Pytorch, but I feel that Pytorch will become the mainstream from now on, so I want to learn it as soon as possible.
Someone please teach me the code to center the image on qiita ...
Recommended Posts