From 7da3f9c1fd4ac1714d2ca1bc7d8b353dcb69feed Mon Sep 17 00:00:00 2001 From: Rauf Date: Thu, 22 Aug 2019 11:12:02 +0000 Subject: [PATCH] add testing script --- test.py | 18 ++++++++++++++++++ train.py | 13 +++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/test.py b/test.py index e69de29..a00a91f 100644 --- a/test.py +++ b/test.py @@ -0,0 +1,18 @@ +import keras.backend as K +from model import SiameseNet +from data_loader import SiameseImageLoader +import matplotlib.pyplot as plt +from keras import optimizers +from keras.models import Model, load_model +import albumentations as A +import cv2 +import time + + +model = SiameseNet('configs/road_signs.yml') +model.load_model('{}best_model_4.h5'.format(model.weights_save_path)) +model.load_encodings('{}encodings.pkl'.format(model.encodings_path)) + + +model_accuracy = model.calculate_prediction_accuracy() +print('Model accuracy on validation set: {}'.format(model_accuracy)) diff --git a/train.py b/train.py index e5e9ae4..97f190a 100644 --- a/train.py +++ b/train.py @@ -5,14 +5,12 @@ from keras.callbacks import EarlyStopping, ReduceLROnPlateau, ModelCheckpoint -n_epochs = 5 -n_steps_per_epoch = 6 -batch_size = 1 +n_epochs = 1000 +n_steps_per_epoch = 600 +batch_size = 8 val_steps = 100 -# model = SiameseNet('configs/road_signs.yml') -model = SiameseNet('configs/plates.yml') - +model = SiameseNet('configs/road_signs.yml') initial_lr = 1e-4 decay_factor = 0.99 @@ -23,7 +21,7 @@ decay_factor ** np.floor(x/step_size)), EarlyStopping(patience=50, verbose=1), TensorBoard(log_dir=model.tensorboard_log_path), - ModelCheckpoint(filepath=os.path.join(model.weights_save_path, 'best_model.h5'), + ModelCheckpoint(filepath=os.path.join(model.weights_save_path, 'best_model_4.h5'), verbose=1, monitor='val_loss', save_best_only=True) ] @@ -32,7 +30,6 @@ model.generate_encodings() -# model.load_encodings('encodings/encodings.pkl') model_accuracy = model.calculate_prediction_accuracy() print('Model accuracy on validation set: {}'.format(model_accuracy))