def main_vgg(argv): # dataset = keras.datasets.cifar10 scale = 1 if len(argv) >= 3: scale = float(argv[2]) (x_train, y_train), (x_test, y_test) = dataprocessing.preprocess( scale=scale) # dataset.load_data() mean, std = meanStd(x_train.astype('float32'), x_test.astype('float32')) x_train = normalize(x_train.astype('float32'), mean, std) x_test = normalize(x_test.astype('float32'), mean, std) # y_train = keras.utils.to_categorical(y_train, num_classes=10) # y_test = keras.utils.to_categorical(y_test, num_classes=10) datagen = ImageDataGenerator(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=15, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False) datagen.fit(x_train) model = VGG(argv[1]) lr = 0.01 lr_decay = 1e-6 lr_drop = 20 def lr_scheduler(epoch): return lr * (0.5**(epoch // lr_drop)) reduce_lr = keras.callbacks.LearningRateScheduler(lr_scheduler) sgd = SGD(lr=lr, decay=lr_decay, momentum=0.9, nesterov=True) model_cp = keras.callbacks.ModelCheckpoint("Model/{0}.model".format( argv[1])) model.compile(optimizer=sgd, loss='binary_crossentropy', metrics=['accuracy']) print(model.summary()) batch_size = 128 model.fit_generator(datagen.flow(x_train, y_train, batch_size=batch_size), steps_per_epoch=x_train.shape[0] // batch_size, epochs=int(argv[2]), validation_data=(x_test, y_test), callbacks=[reduce_lr, model_cp]) print(model.evaluate(x_test, y_test)) model.save("Model/{0}.model".format(argv[1])) model.save_weights("Model/{0}.weights".format(argv[1]))
from vgg import VGG import os model = VGG() print(model.summary()) weights = './model/emotion_best_weights.h5' if os.path.exists(weights): print("Loading weight") model.load_weights(weights) print("Saving model") model.save("./model/emotion_recognition.h5")
from vgg import VGG import os model = VGG() print(model.summary()) weights = './Xml_File/emotion_best_weights.h5' if os.path.exists(weights): print("Loading weight") model.load_weights(weights) print("Saving model") model.save("./Xml_File/emotion_recognition.h5")