Since I bought a new PC, I used Docker to build a python environment and run CNN.
Since Docker is almost a beginner, I will take this opportunity to study.
As the flow this time
MacOS Catalina version 10.15.5
Docker version 19.03.8
anaconda is an open source platform that has all the essential packages for data science practitioners. I am grateful to use this because there is an image of anaconda3 from the official.
https://hub.docker.com/r/continuumio/anaconda3/
Now, start Docker and get the image of Anaconda3.
% docker pull continuumio/anaconda3
Using default tag: latest
latest: Pulling from continuumio/anaconda3
68ced04f60ab: Pull complete
57047f2400d7: Pull complete
8b26dd278326: Pull complete
Digest: sha256:6502693fd278ba962af34c756ed9a9f0c3b6236a62f1e1fecb41f60c3f536d3c
Status: Downloaded newer image for continuumio/anaconda3:latest
docker.io/continuumio/anaconda3:latest
pull
is a command to get a Docker image.
Next, we will create a container.
% docker run --name anaconda -it -p 8888:8888 -v /Users/xxxx/docker/anaconda:/home continuumio/anaconda3 /bin/bash
(base) root@xxxx:/# conda list
The meaning of each command and option is as follows.
run
: Create a container.
--name [name]
: Set the name of the container.
-it
: You can operate inside the container.
-p [Host side port number: Container port number]
: Bind the container port to the host side.
-v [Host-side directory: Container-side directory]
: Host-side directory in the container
Mount
Let's check the packages that are pre-installed on anaconda3.
base) root@xxxx:/# conda list
# packages in environment at /opt/conda:
#
# Name Version Build Channel
_ipyw_jlab_nb_ext_conf 0.1.0 py37_0
_libgcc_mutex 0.1 main
alabaster 0.7.12 py37_0
anaconda 2020.02 py37_0
anaconda-client 1.7.2 py37_0
anaconda-navigator 1.9.12 py37_0
anaconda-project 0.8.4 py_0
argh 0.26.2 py37_0
asn1crypto 1.3.0 py37_0
astroid 2.3.3 py37_0
astropy 4.0 py37h7b6447c_0
atomicwrites 1.3.0 py37_1
attrs 19.3.0 py_0
.
.
.
yaml 0.1.7 had09818_2
yapf 0.28.0 py_0
zeromq 4.3.1 he6710b0_3
zict 1.0.0 py_0
zipp 2.2.0 py_0
zlib 1.2.11 h7b6447c_3
zstd 1.3.7 h0b5b093_0
The docker
command cannot be used because it is in the anaconda3 container.
Look at the package in the conda list
available on the anaconda terminal.
Since anaconda3 does not have tensorflow installed from the beginning, use conda install
Install tensorflow and its peripheral packages.
base) root@xxxx:/# conda install tensorflow
You can open the Jupyter Notebook, which you used to love when you were in college, from your browser.
base) root@xxxx:/# jupyter notebook --port 8888 --ip=0.0.0.0 --allow-root
.
.
.
To access the notebook, open this file in a browser:
file:///root/.local/share/jupyter/runtime/nbserver-12-open.html
Or copy and paste one of these URLs:
http://81127b992594:8888/?token=22ab4d7b42e6629eb76dad08af9c8e6b1d5b59e0f0050f73
or http://127.0.0.1:8888/?token=22ab4d7b42e6629eb76dad08af9c8e6b1d5b59e0f0050f73
Before building CNN, Docker can only use up to 2G of memory by default, so if you try to train with CNN, it will overflow. So I will change the setting so that it can be used up to 7G.
Finally, we will build CNN. For the dataset, download the standard CIFAR10, and use the three convolution layers, the adam method for optimization, and the cross entropy error for the loss function.
I was able to import tensorflow without any problems, and the memory did not overflow, so this is the end of environment construction!
I tried touching Docker with a light feeling, but it was too deep and I was addicted to the swamp ... Introducing tensorflow to anaconda3 and opening Jupyter Notebook, which was probably quite difficult for experienced Docker users. There is no loss in doing Docker, so I would like to actively use it. For the time being, I was able to build an environment where tensorflow can be operated, so I will try various deep learning in this environment from now on.
Recommended Posts