Home 9 Resources 9 Software 9 Keras

KERAS

 

Keras is a minimalist, highly modular neural networks library written in Python and capable of running on top of either TensorFlow or Theano.

Sample scripts for Keras use are available in directory /opt/packages/examples/keras on Bridges.

Documentation

 

Usage

To use Keras, you must load the appropriate Keras module, then activate the virtual environment and launch python. Once python is launched, you can import keras or other specific software.

 

Find and load the appropriate Keras module

To see what versions of Keras are available type

module avail keras

Note that the names of the keras modules reflect the software it has been built with.  For example, the module keras/2.2.0_tf1.7_py2_gpu  establishes an environment

  • using Keras 2.2.0, TensorFlow 1.7, and Python2
  • for use on GPUs

To see what other modules are needed, what commands are available and how to get additional help type

module help keras

Use a command like this in your batch script or interactive session to load the keras module.  This command loads the default keras module.  Be sure to load the specific module you need by using its full name.

module load keras

Loading the keras module will also load other necessary modules for you. You can list those with the module list command. Check to see if there are others you need to load manually by typing the module help keras command.

 

Activate the virtual environment, launch python, import needed software

Use the source activate command to load the virtual environment

source activate

Start python.

python

Add any necessary software with the import command.

import keras

 

Example

Here is an example of using Keras on Bridges. In this example, an interactive session has been started in one of Bridges’ GPU partitions.  To read more about Bridges’ partitions and how to use interactive sessions, see the Running Jobs section of the Bridges User Guide.

[joeuser@gpu045 keras]$ module available keras ---------- /opt/modulefiles ------------ keras/1.1.2                keras/2.0.4                keras/2.0.6_anaconda       keras/2.0.6_anaconda_nogpu keras/2.2.0_tf1.7_py2_gpu  keras/2.2.0_tf1.7_py3_gpu  [joeuser@gpu045 keras]$ module load keras/2.2.0_tf1.7_py3_gpu   [joeuser@gpu045 keras]$ module list Currently Loaded Modulefiles:   1) psc_path/1.1                 4) cuda/9.0                     7) python/3.6.4_gcc5_np1.14.5   2) slurm/default                5) mpi/gcc_openmpi              8) tensorflow/1.7_py3_gpu   3) gcc/5.3.0                    6) phdf5/1.10.2_gnu_openmpi     9) keras/2.2.0_tf1.7_py3_gpu  [joeuser@gpu045 keras]$ source activate  (tf1.7_py3_gpu) [joeuser@gpu045 keras]$ python Python 3.6.4 (default, Jun 28 2018, 13:20:07)  [GCC 5.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import keras Using TensorFlow backend. >>> print(keras.__version__) 2.2.0 >>> import pandas >>> print(pandas.__version__) 0.23.1 >>>   (tf1.7_py3_gpu) [joeuser@gpu045 keras]$ deactivate