Running TensorFlow
This chapter goes through some example runs with TensorFlow. Some output messages have been removed or simplified in the runs for readability.
The sample runs assume that the GPU drivers are in place (section 9.1 of the Installation Manual). The runs also assume that TensorFlow package and the TensorFlow extras package have both been installed from the NVIDIA Base Command Manager repository with a package manager.
TensorFlow can be installed, for example with
yum install cm-tensorflow2-py39-cuda11.2-gcc9 cm-tensorflow2-extra-py39-cuda11.2-gcc9
In addition to requiring the extras package, TensorFlow requires an OpenMPI implementation to work. Chapter 3 of the User Manual describes the different OpenMPI packages that the BCM repositories provide. The different OpenMPI packages allow the user to choose which one to use. For example, depending on which interconnect is being used, or depending on if CUDA support is required.
In this chapter, the cm-openmpi4-cuda11.2-ofed51-gcc9 package is used. It can be installed with, for example:
yum install cm-openmpi4-cuda11.2-ofed51-gcc9
More information on the examples can be found at https://github.com/tensorflow/examples.
2.1 Hello World
A “Hello World” interactive example, that just shows that the software is in place for TensorFlow, can be run as follows:
Example
2.2 Deep Convolutional Generative Adversarial Network
The following trains a deep convolutional generative adversarial network (DCGAN).
The example code is included in the TensorFlow extras package. Once its module has been loaded, the example directory is defined with the CM_TENSORFLOW2_EXTRA environment variable.
The example picks up training images and labels from the MNIST site, and places them in a directory tensorflow_datasets/ if it needs to. The images are then used to train the model. End users would be expected to train the neural network within their home directories.
Example
Datasets generated by the preceding run can be purged with:
Example
2.3 Image-to-Image Translation with Conditional Adversarial Nets
The following trains a conditional adversarial networks as a general-purpose solution to image-to-image translation problems. The trained model is capable of completing different tasks, such as colorizing black and white photos.
The example code is included in the TensorFlow extras package. Once its module has been loaded, the example directory is defined with the CM_TENSORFLOW2_EXTRA environment variable.
The example uses a preprocessed copy of the CMP Facade Database, helpfully provided by the Center for Machine Perception at the Czech Technical University in Prague. The original dataset includes 606 rectified images of facades from various sources, which have been manually annotated. The facades are from different cities around the world and diverse architectural styles.
The example conveniently downloads the dataset in a temporary directory and then trains the model. End users would be expected to train the neural network within their home directories.
Example
2.4 Neural Machine Translation With Attention
The following trains a sequence to sequence model for neural machine translation with attention using gated recurrent units (GRUs).
The example code is included in the TensorFlow extra package. Once its module has been loaded, the example directory is defined with the CM_TENSORFLOW2_EXTRA environment variable.
The example conveniently downloads a dataset for Spanish to English translation in a temporary directory and then trains the model. End users would be expected to train the neural network within their home directories.
Example