From e3fd702f0a8b8d1dcbb7f25ec4a6ac1e6ff4f25a Mon Sep 17 00:00:00 2001 From: Rauf Date: Thu, 29 Aug 2019 17:48:32 +0000 Subject: [PATCH] reorginize the code --- configs/road_signs.yml | 9 +++++---- siamese_net/__init__.py | 0 augmentations.py => siamese_net/augmentations.py | 0 backbones.py => siamese_net/backbones.py | 0 data_loader.py => siamese_net/data_loader.py | 0 .../losses_and_accuracies.py | 0 model.py => siamese_net/model.py | 5 +++-- utils.py => siamese_net/utils.py | 5 ++++- train.py | 4 ++-- 9 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 siamese_net/__init__.py rename augmentations.py => siamese_net/augmentations.py (100%) rename backbones.py => siamese_net/backbones.py (100%) rename data_loader.py => siamese_net/data_loader.py (100%) rename losses_and_accuracies.py => siamese_net/losses_and_accuracies.py (100%) rename model.py => siamese_net/model.py (99%) rename utils.py => siamese_net/utils.py (96%) diff --git a/configs/road_signs.yml b/configs/road_signs.yml index 8b451f0..c23b84a 100644 --- a/configs/road_signs.yml +++ b/configs/road_signs.yml @@ -1,17 +1,18 @@ input_shape : [48, 48, 3] -encodings_len: 4096 +encodings_len: 1024 mode : 'triplet' distance_type : 'l1' backbone : 'simple2' backbone_weights : 'imagenet' -optimizer : 'adam' +optimizer : 'radam' learning_rate : 0.0001 project_name : 'road_signs/' freeze_backbone : True #paths -dataset_path : '/home/rauf/dataset/road_signs/road_signs_separated/' +dataset_path : '/home/rauf/datasets/road_signs/road_signs_separated/' tensorboard_log_path : 'tf_log/' weights_save_path : 'weights/' plots_path : 'plots/' -encodings_path : 'encodings/' \ No newline at end of file +encodings_path : 'encodings/' +model_save_name : 'best_model.h5' \ No newline at end of file diff --git a/siamese_net/__init__.py b/siamese_net/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/augmentations.py b/siamese_net/augmentations.py similarity index 100% rename from augmentations.py rename to siamese_net/augmentations.py diff --git a/backbones.py b/siamese_net/backbones.py similarity index 100% rename from backbones.py rename to siamese_net/backbones.py diff --git a/data_loader.py b/siamese_net/data_loader.py similarity index 100% rename from data_loader.py rename to siamese_net/data_loader.py diff --git a/losses_and_accuracies.py b/siamese_net/losses_and_accuracies.py similarity index 100% rename from losses_and_accuracies.py rename to siamese_net/losses_and_accuracies.py diff --git a/model.py b/siamese_net/model.py similarity index 99% rename from model.py rename to siamese_net/model.py index 6dcfae0..8ca8907 100644 --- a/model.py +++ b/siamese_net/model.py @@ -11,9 +11,9 @@ from keras.layers import Conv2D, MaxPool2D, BatchNormalization, concatenate from classification_models import Classifiers import pickle -from . import losses_and_accuracies as lac from .utils import parse_net_params, load_encodings from .backbones import get_backbone +from . import losses_and_accuracies as lac import matplotlib.pyplot as plt @@ -49,7 +49,8 @@ def __init__(self, cfg_file): self.plots_path = params['plots_path'] self.tensorboard_log_path = params['tensorboard_log_path'] self.weights_save_path = params['weights_save_path'] - + self.model_save_name = params['model_save_name'] + os.makedirs(self.encodings_path, exist_ok=True) os.makedirs(self.plots_path, exist_ok=True) os.makedirs(self.tensorboard_log_path, exist_ok=True) diff --git a/utils.py b/siamese_net/utils.py similarity index 96% rename from utils.py rename to siamese_net/utils.py index 3f1b761..f252170 100644 --- a/utils.py +++ b/siamese_net/utils.py @@ -87,6 +87,9 @@ def parse_net_params(filename='configs/road_signs.yml'): optimizer = optimizers.Adam(lr=learning_rate) elif cfg['optimizer'] == 'rms_prop': optimizer = optimizers.RMSprop(lr=learning_rate) + elif cfg['optimizer'] == 'radam': + from keras_radam import RAdam + optimizer = RAdam() else: optimizer = optimizers.SGD(lr=learning_rate) @@ -105,7 +108,7 @@ def parse_net_params(filename='configs/road_signs.yml'): cfg['project_name']) params['weights_save_path'] = os.path.join(cfg['weights_save_path'], cfg['project_name']) - + params['model_save_name'] = cfg['model_save_name'] if 'dataset_path' in cfg: params['loader'] = SiameseImageLoader(cfg['dataset_path'], input_shape=cfg['input_shape'], diff --git a/train.py b/train.py index 97f190a..1aaecb1 100644 --- a/train.py +++ b/train.py @@ -1,6 +1,6 @@ import os import numpy as np -from model import SiameseNet +from siamese_net.model import SiameseNet from keras.callbacks import TensorBoard, LearningRateScheduler from keras.callbacks import EarlyStopping, ReduceLROnPlateau, ModelCheckpoint @@ -21,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_4.h5'), + ModelCheckpoint(filepath=os.path.join(model.weights_save_path, model.model_save_name), verbose=1, monitor='val_loss', save_best_only=True) ]