Building a Deep Learning environment (Ubuntu 20.04 LTS)

Building a Deep Learning environment Ubuntu 20.04 LTS

Since Ubuntu 20.04 can now perform stable deep learning, record the installation method

Operation check environment



Freeze problem during installation

Ubuntu 20.04 LTS, like Ubuntu 18.04, is incompatible with Nvidia's GPU The screen will look like the one below

image.png

The workaround is to disable the default driver nouveau during installation or on the GRUB screen to prevent it from freezing.

On this screen, hover over Install Ubuntu and press e image.png

Where it says quiet splash --- You can disable nouveau by rewritingquiet splash nomodeset ---.

After rewriting, start running with the options updated with Ctrl-x

Install according to the instructions. If you install additional drivers etc. instead of the minimum configuration, Recommended because nvidia-driver is included.

Freeze problem when logging in for the first time

Since the same problem occurs after installation, there are cases where nomodeset support is required (especially when a login loop occurs when automatic login is enabled).

Press ctrl + alt + F2 on the login screen to enter the CLI login screen. Enter username and password and execute the process corresponding to nomodeset

sudo vi /etc/default/grub


GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
Where it is
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
To

#Apply changes
sudo update-grab

# nvidia-Insert the driver
sudo apt install nvidia-driver-440;

#Reboot
sudo reboot

After reboot

At this point the driver is in.

$ nvidia-smi
Tue Sep 15 18:56:00 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.100      Driver Version: 440.100      CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce RTX 208...  Off  | 00000000:01:00.0 Off |                  N/A |
| 41%   31C    P8    13W / 250W |    311MiB / 10997MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0       973      G   /usr/lib/xorg/Xorg                           175MiB |
|    0      1339      G   /usr/bin/gnome-shell                         120MiB |
|    0      3263      G   /usr/lib/firefox/firefox                       6MiB |
|    0      3787      G   gnome-control-center                           6MiB |
+-----------------------------------------------------------------------------+

Install major libraries (only if needed)

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install -y vim csh flex gfortran git g++ cmake xorg-dev patch zlib1g-dev libbz2-dev libboost-all-dev openssh-server libcairo2 libcairo2-dev libeigen3-dev lsb-core lsb-base net-tools network-manager xclip gdebi-core libffi-dev make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl

Install pyenv (only for those who need it)

git clone https://github.com/yyuu/pyenv.git ~/.pyenv

Pass through

$ vim ~/.bashrc
#Add the following to the end
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

$ source ~/.bashrc

Install your favorite Python version

$ pyenv install 3.6.9
$ pyenv global 3.6.9
$ pyenv rehash
$ python -V
Python 3.6.9

test

$ mkdir -p ~/workspace/test
$ cd ~/workspace/test
$ python -m venv venv36tf
$ source venv36tf/bin/activate

$ pip install --upgrade pip
$ pip install tensorflow-gpu==2.2

mnist experiment Save the following as test_mnist.py

test_mnist.py


import tensorflow as tf
mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(),
  tf.keras.layers.Dense(512, activation=tf.nn.relu),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)

Run Success if the output is as follows

$ python test_mnist.py

Epoch 1/5
1875/1875 [==============================] - 1s 768us/step - loss: 0.2215 - accuracy: 0.9337
Epoch 2/5
1875/1875 [==============================] - 1s 733us/step - loss: 0.0980 - accuracy: 0.9700
Epoch 3/5
1875/1875 [==============================] - 1s 739us/step - loss: 0.0711 - accuracy: 0.9780
Epoch 4/5
1875/1875 [==============================] - 1s 738us/step - loss: 0.0562 - accuracy: 0.9821
Epoch 5/5
1875/1875 [==============================] - 1s 736us/step - loss: 0.0437 - accuracy: 0.9861
313/313 [==============================] - 0s 608us/step - loss: 0.0613 - accuracy: 0.9816

Recommended Posts

Building a Deep Learning environment (Ubuntu 20.04 LTS)
[Ruby] Building a Ruby development environment on Ubuntu
Building WebGIS on Ubuntu20.04 LTS
Ruby Learning # 11 Building a Calculator
Ruby Learning # 32 Building a Quiz
Laravel environment construction (Ubuntu 18.04 LTS)
Ruby Learning # 19 Building a Better Calculator
Ruby Learning # 22 Building a Guessing Game
Build a XAMPP environment on Ubuntu
A story I was addicted to before building a Ruby and Rails environment using Ubuntu (20.04.1 LTS)
Create a development environment for Ruby 3.0.0 and Rails 6.1.0 on Ubuntu 20.04.1 LTS
Creating a dual boot environment for Ubuntu Server 20.04.1 LTS and Windows 10
WSL2 + Ubuntu 20.04 Install Vivado in LTS environment
Building a Lambda development environment in Eclipse
Building a Kotlin development environment using SDKMAN
Ruby Learning # 12 Building a Mad Libs Game
A memo that installed Ubuntu 20.4 on HP Z2 Mini G4 and created a deep learning environment with Python Docker
Quick learning Java "Introduction?" Part 1 Building an environment
Building a Hadoop cluster (Cloudera Manager on Ubuntu 18.04)
Building a Ruby environment for classes on Mac
Rip a CD to MP3 with Ubuntu 18.04 LTS
How to build a Pytorch environment on Ubuntu
Build Ubuntu 20.04 LTS desktop environment on Raspberry Pi 4 (+ Japanese)
Old notebook + Ubuntu 18.04 LTS makes old iPad a sub monitor
[Flutter] Ubuntu 20.04 environment construction
Apache2 on Ubuntu20.04 LTS
Ubuntu 18.04.05 About LTS setup
Install Ubuntu MATE 20.04 LTS on older MacBook Early 2008 (MB402 * / A, MB403 * / A, MB404 * / A)
Docker × Java Building a development environment that is too simple
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Build mate desktop environment on ec2 with terraform (Ubuntu 20.04LTS)
Set up a MineCraft Paper server on Ubuntu 20.04.1 LTS ② Update
Ubuntu 18.04 LTS makes old iPad a sub monitor without WiFi