Skip to content
Snippets Groups Projects

Keras Frontend

Installing Dependencies

Updating pip:

The pip version required in this subproject must be >= 19.3.

To upgrade pip:

pip install --upgrade pip

To check installed pip version:

pip -V

Importing Conda Environment:

conda env create -f keras_environment.yml --name ${KERAS_ENV_NAME}

Note: pip version MUST be > 19.3

Activating Conda Environment:

conda activate ${KERAS_ENV_NAME}

Building and Installing Frontend:

python setup.py build

python setup.py install

Running Benchmaks

Benchmarks under ./src/

NOTE: Activate conda environment (above) before running benchmarks

List of benchmarks and the expected accuracies:

Benchmark Accuracy
AlexNet-CIFAR10 79.28
AlexNet2-CIFAR10 84.98
AlexNet-ImageNet 56.30
LeNet-MNIST 98.70
MobileNet-CIFAR10 84.42
ResNet18-CIFAR10 89.56
ResNet50-ImageNet 75.10
VGG16-CIFAR10 89.96
VGG16-CIFAR100 66.50
VGG16-ImageNet 69.46

Synopsis

python src/${BENCH_NAME}.py  [hpvm_reload|keras_reload]  [frontend] 

Parameters:

hpvm_reload : Reloads HPVM weights ('.bin' binary format used in model_params found here: https://gitlab.engr.illinois.edu/llvm/hpvm/-/tree/approx_hpvm_reorg_keras/hpvm/test/dnn_benchmarks/model_params) from directory path specified in the Benchmark class constructor.

keras_reload: Reloads weights in Keras .h5 file format with path to file specified in Benchmark class constructor

frontend: Invokes the HPVM frontend and dumps weights (in HPVM .bin format) in the output directory specified. The constructor requires two paths:

  • data_dir: Directory to dump weights specified specified in constructor

  • src_dir: Directory to dump ApproxHPVM sources in HPVM-C (C with HPVM compiler intrinsics) specified in constructor

Building New Benchmarks

All benchmarks inherit from the commom parent Benchmark class. Each benchmark overrides virtual functions for building the model, training, and data preprocessing.

def buildModel(self): Constructs and returns a keras model

def data_preprocess(self): returns X_train, y_train, X_test, y_test, X_tuner, and y_tuner data (in that order): These are described here:

  • X_train: Training data (fp32) in NCHW format

  • y_train: Training labels (int32)

  • X_test: Testing/Evaluation data in NCHW format

  • y_test: Testing/Evaluation labels

  • X_tuner: Data to be used for autotuning

  • y_tuner: Labels corresponding to tuning data

def trainModel(self, model, X_train, y_train, X_test, y_test): Trains the Keras model constructed in buildModel and is expected to return the trained keras model - training parameters should be tuned here.

Limitations

  • We mosty support convolutional neural networks - RNNs/LSTMS are not supported
  • We currently only support models in NCHW format (NHWC is not supported)
  • Softmax operator should be the last operation in the CNN pipeline
  • Softmax operation must be a separate operator (not specified as activation to another type of Keras operator)