Create ubuntu20.04 (or windows10) + anaconda + pytorch or tensorflow environment

at first

This is Qiita's first post. I would be grateful if you could let me know if there are any points that cannot be reached.

What to do in this article

Build an environment for pytorch, tensorflow, and keras on a PC equipped with NVIDIA Geforce GTX 1060. Please note that it often does not work with different versions.

What to introduce

--nvidia driver (version is arbitrary (?))

Operating environment

Install nvidia driver (for ubuntu)

Reference

  1. Check the installed GPU and driver

GPU confirmation


ubuntu-drivers devices  

2 . Driver installation

install_driver


sudo ubuntu-drivers install [Driver version(Is it safe to use recommended ones such as 435??)]
#autoinstall seems not recommended
#For more information ubuntu-drivers --Run help

3 . Restart your PC 4 . It is OK if you can get information such as driver by executing nvidia-smi.

When nvidia-smi doesn't work

Reference NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running. It may become like. At this time, disable Nouveau

procedure

  1. Create a file with sudo vim /etc/modprobe.d/blacklist-nouveau.conf

blacklist-nouveau.conf


blacklist nouveau
options nouveau modeset=0

Fill in 2. sudo update-initramfs -u 3 . PC restart See the reference above for details.

Install nvidia driver (for windows)

-Select the environment you are using from nvidia_driver_download and download the driver. [](--You can check your environment in the nvidia control panel by right-clicking on the desktop ??) --Launch the installer (all defaults are OK) --Open a command prompt and execute nvidia-smi to get information such as drivers.

Installation of anaconda

-Installing guide of anaconda by python japan -anaconda Official Install according to

Creating a virtual environment

--Launch anaconda prompt (for windows). In ubuntu, it is OK if (base) is attached to the command line. Reference conda create -n environment name python = version Create a virtual environment with. Here, the environment name is arbitrary and the version is 3.6. --Environment activation conda activate environment name It's okay if you see (environment name) on the command line.

Install pytorch

If you select your environment in pytorch official, the necessary commands will appear. In my environment conda install pytorch torchvision cudatoolkit=10.2 -c pytorch was.

Check if gpu is recognized (pytorch)

Reference (pytorch official) Start python

Confirmation


import torch
torch.cuda.is_available()

To execute. If True, you can recognize

tensorflow-install gpu

** Note: cuda-toolkit requires version 9.1 for tensorflow-gpu == 1.12.0, so you need something different from pytorch. Therefore, it is necessary to separate pytorch and virtual environment ** conda install tensorflow-gpu==1.12.0

Check if gpu is recognized (tensorflow)

Reference Start python

Confirmation


from tensorflow.python.client import device_lib
device_lib.list_local_devices()

And. If the GPU is displayed, the GPU is recognized

install keras

conda install keras==2.2.4

Future outlook (not opened)

-Use keras-yolov3 -Learning fine tuning of nvidia-jetson classification with pc and putting it on jetson nano -Learning fine tuning of nvidia-jetson detection on pc and putting it on jetson nano

At the end

I would appreciate it if you could let me know if there is a problem with the page. Thank you to everyone on the page for reference.

Reference list

-Install CUDA on Ubuntu 18.04 -Installing guide of anaconda by python japan -anaconda Official -[For beginners] Create a virtual environment with Anaconda -pytorch official -Check if GPU can be recognized from TensorFlow with 2-line code

Recommended Posts

Create ubuntu20.04 (or windows10) + anaconda + pytorch or tensorflow environment
[Windows] WSL2 + Ubuntu + Node.js environment construction
Let's create Ubuntu environment with vmware
Create RUNTEQ's environment with Windows DockerDesktop
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090
Create Spring Boot environment with Windows + VS Code
How to build a Pytorch environment on Ubuntu
Create an environment where CircleCI can be executed locally with Windows10 + WSL2 (Ubuntu) + Docker
I built an Ubuntu environment on Windows 10 using WSL2.
Cross-compile Qt – GUI Windows Application in Ubuntu 18.04 MinGW environment
Beginners use ubuntu in windows to prepare rails environment
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker