Exemplo n.º 1
0
from src.fcnet import FullyConnectedNet
from src.utils.solver import Solver
from src.utils.data_utils import get_FER2013_data
import pickle

model = FullyConnectedNet([512, 512, 512],
                          input_dim=48 * 48 * 1,
                          num_classes=7,
                          dropout=0,
                          dtype=np.float32,
                          reg=0.1)
#f = open('model.pickle', 'rb')
#model = pickle.load(f)
#f.close()

data = get_FER2013_data(num_test=3589)
solver = Solver(model,
                data,
                update_rule='sgd_momentum',
                optim_config={
                    'learning_rate': 5e-3,
                },
                lr_decay=0.95,
                num_epochs=35,
                batch_size=100,
                print_every=200)
solver.train()

save = input("Save model?  ")
if (save is 'y'):
    f = open('model.pickle', 'wb')
Exemplo n.º 2
0
    with open(path + filename, 'w') as file:
        for line, layer in enumerate(layers):
            stat = "{}. layer: [{:4}, {:4}] - accuracy: {:.4f}".format(
                line + 1, layer[0], layer[1], accs[line])
            file.write(stat + "\n")

        best_layer_idx = np.argmax(np.asarray(accs), axis=0)
        best_layer = layers[best_layer_idx]
        best_layer_acc = accs[best_layer_idx]

        file.write(
            "Best accur layer - {}: [{:4}, {:4}] with accuracy {:.4f}\n".
            format(best_layer_idx + 1, best_layer[0], best_layer[1],
                   best_layer_acc))


data = get_FER2013_data(TRAIN_NUM, VALID_NUM, TEST_NUM)
# data = get_FER2013_data_from_binary(VALID_NUM)

INPUT_DIMS = np.prod(data["X_train"].shape[1:])
HIDDEN_DIMS = np.asarray([1155, 1155])

fcnn = FullyConnectedNet(HIDDEN_DIMS,
                         INPUT_DIMS,
                         CLASS_NUM,
                         DROPOUT,
                         REGULAR,
                         weight_scale=5e-3)
stage_optim_layers(fcnn, data)
# stage_optim_drop(fcnn, data)
Exemplo n.º 3
0
"""
Created on Tue Feb 27 19:53:32 2018

@author: wuyuxiang
"""
from __future__ import print_function
import matplotlib.pyplot as plt
from src.utils.data_utils import get_FER2013_data
from plot import plot_acc_loss
import keras
from keras.layers import Convolution2D, MaxPooling2D, Dense, Dropout, Activation, Flatten, Conv2D
from keras.models import Sequential
from keras.callbacks import ModelCheckpoint
from keras.preprocessing.image import ImageDataGenerator
#load data from file
data = get_FER2013_data()
x_train, y_train, x_test, y_test, x_val, y_val = data['X_train'], data[
    'y_train'], data['X_test'], data['y_test'], data['X_val'], data['y_val']

x_train = x_train.reshape(x_train.shape[0], 48, 48, 1)

y_train = y_train.reshape(y_train.shape[0], 1)

x_test = x_test.reshape(x_test.shape[0], 48, 48, 1)

y_test = y_test.reshape(y_test.shape[0], 1)

x_val = x_val.reshape(x_val.shape[0], 48, 48, 1)

y_val = y_val.reshape(y_val.shape[0], 1)
Exemplo n.º 4
0
'momentum': 0.95,
'learning_rate': 4e-4,
'update_rule': 'sgd_momentum',
'lr_decay': 0.9,
'num_epochs': 20,
'batch_size': 64,
'num_training': 22000,
'num_validation': 2000,
'num_test': 2000,
'dropout': 0.3
}



data = get_FER2013_data(num_training=default_para['num_training'], 
	num_validation=default_para['num_validation'], 
	num_test=default_para['num_test'], subtract_mean=True)
model = FullyConnectedNet(default_para['hidden_layer'], 
							input_dim=48*48, num_classes=7, 
							reg = default_para['regularization'],
							dropout = default_para['dropout'])
solver = Solver(model, data,
				update_rule=default_para['update_rule'],
				optim_config={
				  'learning_rate': default_para['learning_rate'],
				  'momentum': default_para['momentum']
				},
				lr_decay=default_para['lr_decay'],
				num_epochs=default_para['num_epochs'], 
				batch_size=default_para['batch_size'] ,
				print_every=200,
reg = 0.0
seed = 42
weight_scale = 1e-2

# model
model = FullyConnectedNet(hidden_dims,
                          input_dim,
                          num_classes,
                          dropout,
                          reg,
                          weight_scale,
                          dtype=np.float32,
                          seed=None)

# dataset
data = get_FER2013_data(
    '/vol/bitbucket/jsh114/emotion-recognition-networks/datasets/FER2013')

# training
best = (0, 0)
initial_starting = 1e-2
minimal_learning = 1e-4
learning_rate = initial_starting
print("entering the loop")
while (learning_rate >= minimal_learning):
    print("Starting with " + str(learning_rate))
    solver = Solver(model,
                    data,
                    update_rule='sgd_momentum',
                    optim_config={
                        'learning_rate': learning_rate,
                        'momentum': 0.0