Python and Tensorflow on GPU-001

Preperation for Tensorflow and Python

Add the following to.bash_profile

export PATH=/opt/rh/rh-python36/root/usr/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/rh/rh-python36/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/rh/rh-python36/root/usr/share/man:$MANPATH
export PKG_CONFIG_PATH=/opt/rh/rh-python36/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
export XDG_DATA_DIRS="/opt/rh/rh-python36/root/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}

Now load the new configurations

$ source ~/.bash_profile

Start a virtual evironment

$ virtualenv ~/.virtualenvs/first-python/



Now you are able to install Tensorflow in this environment

$ pip3 install -U --user six numpy wheel setuptools mock
$ pip3 install -U --user /opt/local_wheels/tensorflow-1.13.1-cp36-cp36m-linux_ppc64le.whl

Here you might be advised to upgrade to pip3, which can be done with this command:

$ pip3 install -U --user --upgrade pip

It is now possible to run a simple training

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(input_shape=(28, 28)),
      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)