Skip to content

Commit

Permalink
reorginize the code
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketFlash committed Aug 29, 2019
1 parent 5cf1178 commit e3fd702
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 9 deletions.
9 changes: 5 additions & 4 deletions configs/road_signs.yml
Original file line number Diff line number Diff line change
@@ -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/'
encodings_path : 'encodings/'
model_save_name : 'best_model.h5'
Empty file added siamese_net/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions model.py → siamese_net/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion utils.py → siamese_net/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
]

Expand Down

0 comments on commit e3fd702

Please sign in to comment.