target_dimensions = (128, 128) target_dimensions2 = (490, 640) #directory_path = r'C:\Users\localadmin\Desktop\final_proj\cohn-kanade-images2' directory_path = r'D:\Degree\Final project\cohn-kanade-formated2' data_loader = DirectoryDataLoader(datapath=directory_path, validation_split=validation_split, target_dimension=target_dimensions2, out_channels=3) dataset = data_loader.load_data() if verbose: dataset.print_data_details() print('Creating training/testing data...') train_images, train_labels = dataset.get_training_data() train_gen = DataGenerator().fit(train_images, train_labels) test_images, test_labels = dataset.get_test_data() test_gen = DataGenerator().fit(test_images, test_labels) print('Initializing neural network with InceptionV3 base model...') model = TransferLearningNN(model_name=model_name, emotion_map=dataset.get_emotion_index_map()) print('Training model...') model.fit_generator(train_gen.generate(target_dimensions, 10), test_gen.generate(target_dimensions, 10), epochs=10)
model = ConvolutionalNNDropout(target_dimensions, channels, emotion_map, verbose=True) pretrained_model = load_model('./output/ferplus_subset_conv_dropout_30_64.h5') # neuralnets.fit_generator not keras.models.fit_generator # history = model.fit_generator(train_gen.generate(target_dimensions, batch_size=batch_size), # test_gen.generate( # target_dimensions, batch_size=batch_size), # epochs=epochs) history = model.continue_training_model( pretrained_model, train_gen.generate(target_dimensions, batch_size=batch_size), test_gen.generate(target_dimensions, batch_size=batch_size), epochs=epochs) hist_df = pd.DataFrame(history.history) # save to json file hist_json_file = "output/" + model_file_name + ".json" with open(hist_json_file, mode='w') as f: hist_df.to_json(f) # Save model configuration (src.nueralnets.save_model) model.save_model("output/" + model_file_name + ".h5", "output/" + model_file_name + "_emotion_map.json", emotion_map)
print('--------------- Convolutional Model -------------------') print('Loading data...') # directory_path = resource_filename('EmoPy.examples','image_data/sample_image_directory') directory_path = r'D:\Degree\Final project\cohn-kanade-formated2' data_loader = DirectoryDataLoader(datapath=directory_path, validation_split=validation_split, target_dimension=target_dimensions2) dataset = data_loader.load_data() if verbose: dataset.print_data_details() print('Preparing training/testing data...') train_images, train_labels = dataset.get_training_data() train_gen = DataGenerator().fit(train_images, train_labels) test_images, test_labels = dataset.get_test_data() test_gen = DataGenerator().fit(test_images, test_labels) print('Training net...') model = ConvolutionalNN(target_dimensions, channels, dataset.get_emotion_index_map(), verbose=True) model.fit_generator(train_gen.generate(target_dimensions, batch_size=5), test_gen.generate(target_dimensions, batch_size=5), epochs=5) # Save model configuration # model.export_model('output/conv2d_model.json','output/conv2d_weights.h5',"output/conv2d_emotion_map.json", emotion_map)
dataset.print_data_details() print('Preparing training/testing data...') train_images, train_labels = dataset.get_training_data() train_gen = DataGenerator().fit(train_images, train_labels) test_images, test_labels = dataset.get_test_data() test_gen = DataGenerator().fit(test_images, test_labels) emotion_map = dataset.get_emotion_index_map() print('Training net...') model = DeepConvolutionalNNDropout( target_dimensions, channels, emotion_map, verbose=True) # neuralnets.fit_generator not keras.models.fit_generator history = model.fit_generator(train_gen.generate(target_dimensions, batch_size=batch_size), test_gen.generate(target_dimensions, batch_size=batch_size), epochs=epochs) hist_df = pd.DataFrame(history.history) # save to json file hist_json_file = "output/" + model_file_name + ".json" with open(hist_json_file, mode='w') as f: hist_df.to_json(f) # Save model configuration (src.nueralnets.save_model) model.save_model("output/" + model_file_name + ".h5", "output/" + model_file_name + "_emotion_map.json", emotion_map)