def main_loop(): print("fitting the whole model ") model = minc_model1() model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1, validation_data=(X_test, Y_test)) model.summary() score = model.evaluate(X_test, Y_test, verbose=0) print('Test score:', score[0]) print('Test accuracy:', score[1]) # Save the model to another location. output_name = 'model_saved/minc_cnn_sndstat.weights' out_dir = get_absolute_dir_project(output_name) print('saving model to location -> {} '.format(out_dir)) model.save_weights(out_dir) model2 = model_without_dense() model2.load_weights(out_dir, by_name=True) model2.summary() model2.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1, validation_data=(X_test, Y_test)) score = model2.evaluate(X_test, Y_test, verbose=0) print('Test score:', score[0]) print('Test accuracy:', score[1])
def evaluate_model(): model = mnist_model1() output_name = 'model_saved/mnist_cnn_sndstat.weights' out_dir = get_absolute_dir_project(output_name) model.load_weights(out_dir) score = model.evaluate(X_test, Y_test, verbose=0) print('Test score:', score[0]) print('Test accuracy:', score[1])
from keras.utils import np_utils from keras.utils.data_utils import get_absolute_dir_project from kyu.utils.logger import Logger import sys batch_size = 32 nb_classes = 20 nb_epoch = 1000 data_augmentation = True # input image dimensions img_rows, img_cols = 32, 32 # the CIFAR10 images are RGB img_channels = 3 BASELINE_PATH = get_absolute_dir_project( 'model_saved/cifar10_baseline.weights') SND_PATH = get_absolute_dir_project('model_saved/cifar10_cnn_sndstat.weights') LOG_PATH = get_absolute_dir_project('model_saved/log') # the data, shuffled and split between train and test sets # label_mode = 'fine' label_mode = 'coarse' (X_train, y_train), (X_test, y_test) = cifar100.load_data(label_mode=label_mode) if label_mode is 'fine': nb_classes = 100 elif label_mode is 'coarse': nb_classes = 20 print('X_train shape:', X_train.shape) print(X_train.shape[0], 'train samples')
from keras.utils.data_utils import get_absolute_dir_project from kyu.datasets.minc import Minc2500 from kyu.utils.example_engine import ExampleEngine LOG_PATH = get_absolute_dir_project('model_saved/log/minc2500') # global constants NB_CLASS = 23 # number of classes LEARNING_RATE = 0.01 MOMENTUM = 0.9 BATCH_SIZE = 128 ALPHA = 0.0001 BETA = 0.75 GAMMA = 0.1 DROPOUT = 0.5 WEIGHT_DECAY = 0.0005 NB_EPOCH = 20 LRN2D_norm = True # whether to use batch normalization # Theano - 'th' (channels, width, height) # Tensorflow - 'tf' (width, height, channels) DIM_ORDERING = 'th' TARGET_SIZE = (224, 224) ### FOR model 1 if K.backend() == 'tensorflow': INPUT_SHAPE = TARGET_SIZE + (3, ) K.set_image_dim_ordering('tf') else: INPUT_SHAPE = (3, ) + TARGET_SIZE K.set_image_dim_ordering('th')
def test_loader(): # Save the model to another location. output_name = 'model_saved/mnist_cnn_sndstat.weights' out_dir = get_absolute_dir_project(output_name) print('saving model to location -> {} '.format(out_dir))