Skip to content
Snippets Groups Projects
Commit cd37699c authored by Abdul Rafae Noor's avatar Abdul Rafae Noor
Browse files

Updating Keras frontend examples to use model_params data

parent b84aa41a
No related branches found
No related tags found
No related merge requests found
......@@ -69,18 +69,25 @@ class AlexNet_CIFAR10(Benchmark):
mean = np.mean(X_train)
std = np.std(X_train)
X_train = (X_train - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_test = X_val[0:5000]
y_test = y_val[0:5000]
X_tuner = X_val[5000:]
y_tuner = y_val[5000:]
X_test = np.fromfile(MODEL_PARAMS_DIR + '/alexnet_cifar10/test_input.bin', dtype=np.float32)
y_test = np.fromfile(MODEL_PARAMS_DIR + '/alexnet_cifar10/test_labels.bin', dtype=np.uint32)
X_test = X_test.reshape((-1,3,32,32))
X_tuner = np.fromfile(MODEL_PARAMS_DIR + '/alexnet_cifar10/tune_input.bin', dtype=np.float32)
y_tuner = np.fromfile(MODEL_PARAMS_DIR + '/alexnet_cifar10/tune_labels.bin', dtype=np.uint32)
X_tuner = X_tuner.reshape((-1,3,32,32))
return X_train, y_train, X_test, y_test, X_tuner, y_tuner
def trainModel(self, model, X_train, y_train, X_test, y_test):
y_train = to_categorical(y_train, self.num_classes)
y_test = to_categorical(y_test, self.num_classes)
......
......@@ -68,21 +68,27 @@ class AlexNet2_CIFAR10(Benchmark):
mean = np.mean(X_train)
std = np.std(X_train)
X_train = (X_train - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_test = X_val[0:5000]
y_test = y_val[0:5000]
X_tuner = X_val[5000:]
y_tuner = y_val[5000:]
X_test = np.fromfile(MODEL_PARAMS_DIR + '/alexnet2_cifar10/test_input.bin', dtype=np.float32)
y_test = np.fromfile(MODEL_PARAMS_DIR + '/alexnet2_cifar10/test_labels.bin', dtype=np.uint32)
X_test = X_test.reshape((-1,3,32,32))
X_tuner = np.fromfile(MODEL_PARAMS_DIR + '/alexnet2_cifar10/tune_input.bin', dtype=np.float32)
y_tuner = np.fromfile(MODEL_PARAMS_DIR + '/alexnet2_cifar10/tune_labels.bin', dtype=np.uint32)
X_tuner = X_tuner.reshape((-1,3,32,32))
return X_train, y_train, X_test, y_test, X_tuner, y_tuner
def trainModel(self, model, X_train, y_train, X_test, y_test):
y_train = to_categorical(y_train, self.num_classes)
y_test = to_categorical(y_test, self.num_classes)
model.compile(
loss='categorical_crossentropy',
optimizer=Adam(lr=0.0001),
......
......@@ -110,21 +110,27 @@ class MobileNet_CIFAR10(Benchmark):
mean = np.mean(X_train)
std = np.std(X_train)
X_train = (X_train - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_test = np.fromfile(MODEL_PARAMS_DIR + '/mobilenet_cifar10/test_input.bin', dtype=np.float32)
y_test= np.fromfile(MODEL_PARAMS_DIR + '/mobilenet_cifar10/test_labels.bin', dtype=np.uint32)
X_test = X_test.reshape((-1,3,32,32))
X_tuner = np.fromfile(MODEL_PARAMS_DIR + '/mobilenet_cifar10/tune_input.bin', dtype=np.float32)
y_tuner = np.fromfile(MODEL_PARAMS_DIR + '/mobilenet_cifar10/tune_labels.bin', dtype=np.uint32)
X_tuner = X_tune.reshape((-1,3,32,32))
X_test = X_val[0:5000]
y_test = y_val[0:5000]
X_tuner = X_val[5000:]
y_tuner = y_val[5000:]
return X_train, y_train, X_test, y_test, X_tuner, y_tuner
def trainModel(self, model, X_train, y_train, X_test, y_test):
y_train = to_categorical(y_train, self.num_classes)
y_test = to_categorical(y_test, self.num_classes)
# data augmentation, horizontal flips only
datagen = ImageDataGenerator(
featurewise_center=False,
......
......@@ -448,24 +448,16 @@ class ResNet18_CIFAR10(Benchmark):
X_val = (X_val - mean)
X_test_val = np.fromfile(MODEL_PARAMS_DIR + '/resnet18_cifar10/test_input.bin', dtype=np.float32)
Y_test_val = np.fromfile(MODEL_PARAMS_DIR + '/resnet18_cifar10/test_labels.bin', dtype=np.uint32)
X_test = np.fromfile(MODEL_PARAMS_DIR + '/resnet18_cifar10/test_input.bin', dtype=np.float32)
y_test = np.fromfile(MODEL_PARAMS_DIR + '/resnet18_cifar10/test_labels.bin', dtype=np.uint32)
X_test_val = X_test_val.reshape((-1,3,32,32))
X_test = X_test.reshape((-1,3,32,32))
X_tune_val = np.fromfile(MODEL_PARAMS_DIR + '/resnet18_cifar10/tune_input.bin', dtype=np.float32)
Y_tune_val = np.fromfile(MODEL_PARAMS_DIR + '/resnet18_cifar10/tune_labels.bin', dtype=np.uint32)
X_tune_val = X_tune_val.reshape((-1,3,32,32))
X_test = X_test_val[:5000]
y_test= Y_test_val[:5000]
X_tuner = X_tune_val[:5000]
y_tuner = Y_tune_val[:5000]
X_tuner = np.fromfile(MODEL_PARAMS_DIR + '/resnet18_cifar10/tune_input.bin', dtype=np.float32)
y_tuner = np.fromfile(MODEL_PARAMS_DIR + '/resnet18_cifar10/tune_labels.bin', dtype=np.uint32)
X_tuner = X_tuner.reshape((-1,3,32,32))
return X_train, y_train, X_test, y_test, X_tuner, y_tuner
......
......@@ -108,29 +108,35 @@ class VGG16_CIFAR10(Benchmark):
mean = np.mean(X_train)
std = np.std(X_train)
X_train = (X_train - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_test= np.fromfile(MODEL_PARAMS_DIR + '/vgg16_cifar10/test_input.bin', dtype=np.float32)
y_test = np.fromfile(MODEL_PARAMS_DIR + '/vgg16_cifar10/test_labels.bin', dtype=np.uint32)
X_test = X_test.reshape((-1,3,32,32))
X_tuner= np.fromfile(MODEL_PARAMS_DIR + '/vgg16_cifar10/tune_input.bin', dtype=np.float32)
y_tuner = np.fromfile(MODEL_PARAMS_DIR + '/vgg16_cifar10/tune_labels.bin', dtype=np.uint32)
X_tuner = X_tuner.reshape((-1,3,32,32))
X_test = X_val[0:5000]
y_test = y_val[0:5000]
X_tuner = X_val[5000:]
y_tuner = y_val[5000:]
return X_train, y_train, X_test, y_test, X_tuner, y_tuner
def trainModel(self, model, X_train, y_train, X_test, y_test):
y_train = to_categorical(y_train, self.num_classes)
y_test = to_categorical(y_test, self.num_classes)
batch_size = 128
learning_rate = 0.01
lr_drop = 20
def lr_scheduler(epoch):
return learning_rate * (0.5 ** (epoch // lr_drop))
reduce_lr = keras.callbacks.LearningRateScheduler(lr_scheduler)
#data augmentation
......
......@@ -124,29 +124,34 @@ class VGG16_CIFAR100(Benchmark):
mean = np.mean(X_train)
std = np.std(X_train)
X_train = (X_train - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_val = (X_val - mean) / (std + 1e-7)
X_test = X_val[0:5000]
y_test = y_val[0:5000]
X_tuner = X_val[5000:]
y_tuner = y_val[5000:]
X_test = np.fromfile(MODEL_PARAMS_DIR + '/vgg16_cifar100/test_input.bin', dtype=np.float32)
y_test = np.fromfile(MODEL_PARAMS_DIR + '/vgg16_cifar100/test_labels.bin', dtype=np.uint32)
X_test = X_test.reshape((-1,3,32,32))
X_tuner = np.fromfile(MODEL_PARAMS_DIR + '/vgg16_cifar100/tuner_input.bin', dtype=np.float32)
y_tuner = np.fromfile(MODEL_PARAMS_DIR + '/vgg16_cifar100/tuner_labels.bin', dtype=np.uint32)
X_tuner = X_tuner.reshape((-1,3,32,32))
return X_train, y_train, X_test, y_test, X_tuner, y_tuner
def trainModel(self,model, X_train, y_train, X_test, y_test):
y_train = to_categorical(y_train, self.num_classes)
y_test = to_categorical(y_test, self.num_classes)
batch_size = 128
learning_rate = 0.1
lr_drop = 30
def lr_scheduler(epoch):
return learning_rate * (0.5 ** (epoch // lr_drop))
reduce_lr = keras.callbacks.LearningRateScheduler(lr_scheduler)
#data augmentation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment