From fd23f858597c32dc7141a2989ea96eab6ac7a5f4 Mon Sep 17 00:00:00 2001 From: Hashim Sharif <hsharif3@miranda.cs.illinois.edu> Date: Fri, 4 Dec 2020 16:24:21 -0600 Subject: [PATCH] renaming HPVM reload weights routine --- llvm/projects/keras/frontend/weight_utils.py | 2 +- llvm/projects/keras/src/Benchmark.py | 5 +++-- llvm/projects/keras/src/alexnet.py | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/llvm/projects/keras/frontend/weight_utils.py b/llvm/projects/keras/frontend/weight_utils.py index 69c1ee5469..e2a956fa9a 100644 --- a/llvm/projects/keras/frontend/weight_utils.py +++ b/llvm/projects/keras/frontend/weight_utils.py @@ -159,7 +159,7 @@ def dumpCalibrationData2(file_name, test_data, labels_fname, test_labels): # Loads Existing HPVM FP32 weights -def dumpHPVMToKerasModel(model, reload_dir, output_model, X_test, Y_test): +def reloadHPVMWeights(model, reload_dir, output_model, X_test, Y_test): print ("***** Reloading pre-trained HPVM weights ****") diff --git a/llvm/projects/keras/src/Benchmark.py b/llvm/projects/keras/src/Benchmark.py index fc3b483fbc..8053345548 100644 --- a/llvm/projects/keras/src/Benchmark.py +++ b/llvm/projects/keras/src/Benchmark.py @@ -7,7 +7,7 @@ from keras.utils.np_utils import to_categorical from keras.models import load_model from frontend.approxhpvm_translator import translate_to_approxhpvm from frontend.weight_utils import dumpCalibrationData -from frontend.weight_utils import dumpHPVMToKerasModel +from frontend.weight_utils import reloadHPVMWeights # Every CNN Benchmark must inherit from Benchmark class @@ -62,7 +62,8 @@ class Benchmark: X_train, Y_train, X_test, Y_test = self.data_preprocess() if argv[1] == "hpvm_reload": - model = dumpHPVMToKerasModel(model, self.reload_dir, self.keras_model_file, X_test, Y_test) + print ("loading weights .....\n\n") + model = reloadHPVMWeights(model, self.reload_dir, self.keras_model_file, X_test, Y_test) if argv[1] == "keras_reload": model = load_model(self.keras_model_file) diff --git a/llvm/projects/keras/src/alexnet.py b/llvm/projects/keras/src/alexnet.py index d7848a2b63..ae2c20493c 100644 --- a/llvm/projects/keras/src/alexnet.py +++ b/llvm/projects/keras/src/alexnet.py @@ -19,9 +19,7 @@ import keras import numpy as np import os from Benchmark import Benchmark -from frontend.approxhpvm_translator import translate_to_approxhpvm -from frontend.weight_utils import dumpCalibrationData -from frontend.weight_utils import dumpHPVMToKerasModel + @@ -46,6 +44,8 @@ class AlexNet(Benchmark): def buildModel(self): + print ("BuildModel ...") + activation_type = "tanh" weight_decay = 1e-4 @@ -138,16 +138,25 @@ class AlexNet(Benchmark): def data_preprocess(self): + print ("Data Preprocess... \n") + (X_train, Y_train), (X_test, Y_test) = cifar10.load_data() + print ("Data Loaded... \n") + X_train = X_train / 255.0 X_test = X_test / 255.0 + print(X_train, X_test) + mean = np.mean(X_train,axis=(0,1,2,3)) std = np.std(X_train,axis=(0,1,2,3)) X_train = (X_train-mean)/(std+1e-7) X_test = (X_test-mean)/(std+1e-7) + print(X_train, X_test) + + return X_train, Y_train, X_test, Y_test -- GitLab