Build TensorFlow operation check environment with Docker

Thing you want to do

Download TensorFlow Docker image https://www.tensorflow.org/install/docker?hl=ja Then, I want to start the container and check the operation of tensorflow.

Premise

How to install Docker https://qiita.com/kenichiro-yamato/items/7e3cb21613784a27409d

Prior confirmation

version

[root@docker ~]# docker -v
Docker version 19.03.7, build 7141c199a2

Container in operation

[root@docker ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Get image with docker pull

docker pull tensorflow/tensorflow

result

[root@docker ~]# docker pull tensorflow/tensorflow
Using default tag: latest
latest: Pulling from tensorflow/tensorflow
171857c49d0f: Pull complete
419640447d26: Pull complete
61e52f862619: Pull complete
40085aa86d3c: Pull complete
b827fdfa00c7: Pull complete
134f84527676: Pull complete
e1f30e7788ed: Pull complete
a13925316d82: Pull complete
5decca4d86ff: Pull complete
70c56a3cd1fa: Pull complete
Digest: sha256:c57fb9628d80872ece8640a22bd0153b2cc8d62d21d79f4d99c3b237a728b62e
Status: Downloaded newer image for tensorflow/tensorflow:latest
docker.io/tensorflow/tensorflow:latest

Confirm that the image was acquired

[root@docker ~]# docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
tensorflow/tensorflow                  latest              623195db36df        7 weeks ago         1.46GB

Start the container with docker run

Change the option specifications such as memory specification, port specification, host specification, and shared directory specification as desired.

docker run -m 4096m -p 80:80 -d --privileged -h yamato.host -i -t -v /root/share:/share:rw --name tensorflow_container1 tensorflow/tensorflow

Confirm the start of the container and connect

[root@docker ~]# docker ps
CONTAINER ID        IMAGE                   COMMAND             CREATED             STATUS              PORTS                NAMES
62f578fc0279        tensorflow/tensorflow   "/bin/bash"         11 seconds ago      Up 10 seconds       0.0.0.0:80->80/tcp   tensorflow_container1

docker exec -it tensorflow_container1 /bin/bash

Connect to tensorflow_container1 with.

[root@docker ~]# docker exec -it tensorflow_container1 /bin/bash

________                               _______________
___  __/__________________________________  ____/__  /________      __
__  /  _  _ \_  __ \_  ___/  __ \_  ___/_  /_   __  /_  __ \_ | /| / /
_  /   /  __/  / / /(__  )/ /_/ /  /   _  __/   _  / / /_/ /_ |/ |/ /
/_/    \___//_/ /_//____/ \____//_/    /_/      /_/  \____/____/|__/

Successful connection.

Confirmation of initial state

You can already use python3 and pip.

root@yamato:~# python -V
Python 3.6.9
root@yamato:~# pip

Usage:
  pip <command> [options]

Since vim is not included, install it.

apt-get update

after

apt-get install vim

Then you can use vim.

Create a py file and try it

vim test.py


print ("Hello World! I am Kenichiro Yamato")

Run.

python test.py

so

Hello World! I am Kenichiro Yamato

Is displayed, OK.

Try tensorflow sample code

vi sample.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.

python sample.py

There are some warnings and information, but it seems to be working.

2020-11-18 10:00:09.352555: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-11-18 10:00:09.352579: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-11-18 10:00:10.743602: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2020-11-18 10:00:10.743630: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2020-11-18 10:00:10.743654: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (yamato.host): /proc/driver/nvidia/version does not exist
2020-11-18 10:00:10.743940: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-11-18 10:00:10.752038: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 3599995000 Hz
2020-11-18 10:00:10.752747: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4e64770 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-11-18 10:00:10.752763: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Epoch 1/5
1875/1875 [==============================] - 3s 2ms/step - loss: 0.2193 - accuracy: 0.9347
Epoch 2/5
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0972 - accuracy: 0.9705
Epoch 3/5
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0676 - accuracy: 0.9789
Epoch 4/5
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0525 - accuracy: 0.9831
Epoch 5/5
1875/1875 [==============================] - 3s 2ms/step - loss: 0.0423 - accuracy: 0.9862
313/313 [==============================] - 0s 1ms/step - loss: 0.0640 - accuracy: 0.9801

Recommended Posts

Build TensorFlow operation check environment with Docker
Build docker environment with WSL
Build Couchbase local environment with Docker
Build a Node.js environment with Docker
Build PlantUML environment with VSCode + Docker
Build environment with vue.js + rails + docker
Build Rails environment with Docker Compose
Build docker + laravel environment with laradock
Build a Wordpress development environment with Docker
[Docker] Build Jupyter Lab execution environment with Docker
Build an environment with Docker on AWS
How to build Rails 6 environment with Docker
Build a WordPress development environment quickly with Docker
[Rails] How to build an environment with Docker
[First team development ②] Build an environment with Docker
[Rails API x Docker] Easy environment construction with shell & operation check with Flutter
Pytorch execution environment with Docker
How to build docker environment with Gradle for intelliJ
Build an environment of Ruby2.7.x + Rails6.0.x + MySQL8.0.x with Docker
Easily build a Vue.js environment with Docker + Vue CLI
[Docker] Rails 5.2 environment construction with docker
Build Rails (API) x MySQL x Nuxt.js environment with Docker
Build WordPress environment with Docker (Local) and AWS (Production)
Exciting environment check with mkmf
React environment construction with Docker
Build DynamoDB local with Docker
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ Express ~
How to build Rails, Postgres, ElasticSearch development environment with Docker
Build a Node-RED environment with Docker to move and understand
Rails + MySQL environment construction with Docker
Create a Vue3 environment with Docker!
Node.js environment construction with Docker Compose
Build a Tomcat 8.5 environment with Pleiades 4.8
Environment construction with Docker for beginners
Create SolrCloud verification environment with Docker
Build jooby development environment with Eclipse
[Environment construction with Docker] Rails 6 & MySQL 8
Build Unity development environment on docker
Build WebRTC Janus with Docker container
Check MySQL logs in Docker environment
Spring Boot gradle build with Docker
Build Go development environment with WSL2 + Docker Desktop + VSCode (Remote --Containers)
Build apache7.4 + mysql8 environment with Docker (with initial data) (your own memo)
I tried to build the environment of PlantUML Server with Docker
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ MySQL edition ~
How to build Rails + Vue + MySQL environment with Docker [2020/09 latest version]
Build a development environment for Django + MySQL + nginx with Docker Compose
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ Sequelize ~
Alert slack with alert manager in Docker environment
Check the operation using jetty with Maven.
GPU environment construction with Docker [October 2020 version]
Rails environment construction with Docker (personal apocalypse)
Building Rails 6 and PostgreSQL environment with Docker
Build and manage RStudio environment with Docker-compose
Create Rails 6 + MySQL environment with Docker compose
Edit Mysql with commands in Docker environment
Create a MySQL environment with Docker from 0-> 1
Build a WAS execution environment from Docker
Create Spring Boot-gradle-mysql development environment with Docker
[Docker] Create Node.js + express + webpack environment with Docker
Laravel + MySQL + phpMyadmin environment construction with Docker