Skip to main content

TensorFlow : Install Docker Image (CPU)

 Install TensorFlow which is the Machine Learning Library.

On this example, Install TensorFlow official Docker Image without GPU support and run it on Containers.

[1].  Install Podman, refer to here.

[2]. Install TensorFlow Docker (CPU only).

# pull TensorFlow 2.0 with Python3 image

[cent@dlp ~]$ podman pull tensorflow/tensorflow:2.0.0-py3

[cent@dlp ~]$ podman images

REPOSITORY                        TAG         IMAGE ID       CREATED        SIZE

docker.io/tensorflow/tensorflow   2.0.0-py3   90f5cb97b18f   9 months ago   1.09 GB


# run container

[cent@dlp ~]$ podman run --rm tensorflow/tensorflow:2.0.0-py3 \

python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

2020-07-22 05:21:27.138093: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2801480000 Hz

2020-07-22 05:21:27.138647: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x34ccfe0 executing computations on platform Host. Devices:

2020-07-22 05:21:27.138671: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version

tf.Tensor(1074.4442, shape=(), dtype=float32)


# create Hello World test script and run it on container

[cent@dlp ~]$ vi hello_tensorflow.py

import tensorflow as tf

hello = tf.constant('Hello, TensorFlow World!')

tf.print(hello)


[cent@dlp ~]$ podman run --rm -v $PWD:/tmp -w /tmp tensorflow/tensorflow:2.0.0-py3 python ./hello_tensorflow.py

2020-07-22 05:23:36.928319: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2801480000 Hz

2020-07-22 05:23:36.928717: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4add050 executing computations on platform Host. Devices:

2020-07-22 05:23:36.928738: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version

Hello, TensorFlow World!

[3]. If SELinux is enabled, change pilicy.

[root@dlp ~]# vi my-python.te

# create new

module my-python 1.0;


require {

        type user_home_t;

        type container_t;

        type user_home_dir_t;

        class file { create ioctl open read unlink write };

        class dir { add_name remove_name write };

}


#============= container_t ==============

allow container_t user_home_dir_t:dir { add_name remove_name write };

allow container_t user_home_dir_t:file { create ioctl open read unlink write };

allow container_t user_home_t:file { ioctl open read };


[root@dlp ~]# checkmodule -m -M -o my-python.mod my-python.te

[root@dlp ~]# semodule_package --outfile my-python.pp --module my-python.mod

[root@dlp ~]# semodule -i my-python.pp

[4] Install TensorFlow Docker Image with Jupyter Notebook.

# pull TensorFlow 2.0 with Python3/Jupyter image

[cent@dlp ~]$ podman pull tensorflow/tensorflow:2.0.0-py3-jupyter

[cent@dlp ~]$ podman images

REPOSITORY                        TAG                 IMAGE ID       CREATED        SIZE

docker.io/tensorflow/tensorflow   2.0.0-py3-jupyter   c652a4fc8a4f   9 months ago   1.24 GB

docker.io/tensorflow/tensorflow   2.0.0-py3           90f5cb97b18f   9 months ago   1.09 GB


# run container as daemon

[cent@dlp ~]$ podman run -dt -p 8888:8888 tensorflow/tensorflow:2.0.0-py3-jupyter

1d54bcba3f14eef778a45332b825b6dedd9efb7c8926fde76a5c81cbaed09947


[cent@dlp ~]$ podman ps

CONTAINER ID  IMAGE                                              COMMAND               CREATED        STATUS            PORTS                   NAMES

1d54bcba3f14  docker.io/tensorflow/tensorflow:2.0.0-py3-jupyter  bash -c source /e...  6 seconds ago  Up 6 seconds ago  0.0.0.0:8888->8888/tcp  vigorous_blackburn


# confirm URL

[cent@dlp ~]$ podman exec 1d54bcba3f14 bash -c "jupyter notebook list"

Currently running servers:

http://0.0.0.0:8888/?token=2b1641a43d5bca23758e6cc1d1979cf3fd4003ba52f8ee4b :: /tf

Comments

Popular posts from this blog

Lambda Function with Amazon SNS

  Amazon SNS is a service used for push notification. In this chapter, we will explain working of AWS Lambda and Amazon SNS with the help of an example where will perform the following actions − Create Topic in SNS Service and use AWS Lambda Add Topics to CloudWatch Send SNS text message on phone number given. Requisites To create Topic in SNS Service and use AWS Lambda Add Topics to CloudWatch, we need not follow the steps given below − Create Topic in SNS Create Role for permission in IAM Create AWS Lambda Function Publish to topic to activate trigger Check the message details in CloudWatch service. To send SNS text message on phone number given, we need to do the following − Add code in AWS Lambda to send message to your phone. Example In this example, we will create a topic in SNS. When details are entered in the topic to publish, AWS Lambda is triggered. The topic details are logged in CloudWatch and a message is sent on phone by AWS Lambda. Here is a basic block diagram which exp

Unix / Linux - Shell Input/Output Redirections

W e will discuss in detail about the Shell input/output redirections. Most Unix system commands take input from your terminal and send the resulting output back to your terminal. A command normally reads its input from the standard input, which happens to be your terminal by default. Similarly, a command normally writes its output to standard output, which is again your terminal by default. Output Redirection The output from a command normally intended for standard output can be easily diverted to a file instead. This capability is known as output redirection. If the notation > file is appended to any command that normally writes its output to standard output, the output of that command will be written to file instead of your terminal. Check the following  who  command which redirects the complete output of the command in the users file. $ who > users Notice that no output appears at the terminal. This is because the output has been redirected from the default standard output dev

Unix / Linux - Shell Functions

W e will discuss in detail about the shell functions. Functions enable you to break down the overall functionality of a script into smaller, logical subsections, which can then be called upon to perform their individual tasks when needed. Using functions to perform repetitive tasks is an excellent way to create  code reuse . This is an important part of modern object-oriented programming principles. Shell functions are similar to subroutines, procedures, and functions in other programming languages. Creating Functions To declare a function, simply use the following syntax − function_name () { list of commands } The name of your function is  function_name , and that's what you will use to call it from elsewhere in your scripts. The function name must be followed by parentheses, followed by a list of commands enclosed within braces. Example Following example shows the use of function − #!/bin/sh # Define your function here Hello () { echo "Hello World" } # Invoke yo