Friday, June 5, 2020

Install Tensorflow and Keras on Centos 7 Linux

Tensorflow (available in github) provides a version that utilise the GPU of a server to perform much more heavier computations. Tensorflow version 1.6 onwards are optimimsed to use AVX instructions that is not available in older CPUs. These versions are installed via pip, uses the AVX instruction set at compile time and require CPU that support the AVX instruction set. This instruction set is supported from the second generation of Intel Core CPUs (codenamed SandyBridge).

Pre-requisite: 
Centos 7 Linux updated
Installed Python (see previous posting)
Created a project directory called tensorflow

Default steps are to install Tensorflow 2.x (see tensorflow), but server environments that does not support AVX, they need to install Tensorflow 1.5 (see article and blog). To determine if AVX support is available, run the following command and look for AVX or AVX2.

more /proc/cpuinfo | grep flags

My output shows no AVX.
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni monitor ssse3 lahf_lm

Optional:
Configure the project directory for python:

python3 -m venv my_env

Step 1: Install Tensorflow (Or tensorflow-gpu)

cd tensorflow
source my_env/bin/activate

Install Tensorflow application, then print its version

pip install --upgrade tensorflow

Or for server that doesn't have AVX support,

pip install tensorflow==1.15

pip show tensorflow

Step 2: Test Tensorflow install

Create a script file hello.py with following contents;

import tensorflow as tf
hello = tf.constant('Hello, World')
session = tf.Session()
print( session.run(hello) )

Run the script

python hello.py

Step 3: Install Keras

pip install --upgrade scikit-learn pillow
pip install --upgrade keras keras-utils

Or for server that doesn't have AVX support,

pip install --upgrade scikit-learn pillow
pip install keras==2.1.6

pip show keras

Configuration file will be at ~/.keras/keras.conf
{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "tensorflow",
    "image_data_format": "channels_last"
}

Test install by editing hello.py

import tensorflow as tf
from tensorflow import keras
hello = tf.constant('Hello, World')
session = tf.Session()
print( session.run(hello) )


The above instructions are meant to provide the platform prior to my learning chatbot at site and colab.

No comments:

Blog Archive