pre.load_data(filename='test_public_norm.csv', name='validate') X_train_df = pre.get(name='train').drop(columns=['emotion']) y_train_df = pre.get(name='train')['emotion'] X_val_df = pre.get(name='validate').drop(columns=['emotion']) y_val_df = pre.get(name='validate')['emotion'] dtype = torch.float model_name = f'cnn_triple_layer_D_bs_{learning_rate}_{batch_size}_{n_epochs}_{n_classes}' model = CnnTripleLayer(model_name, d_out=n_classes) model.train() train_classifier = TrainClassifier2(model, X_train_df, y_train_df, X_val_df, y_val_df, root_dir=current_working_dir) t = time.time() trained_model, optimizer, criterion, \ train_loss_hist, train_acc_hist, train_f1_hist, train_b_hist,\ val_loss_hist, val_acc_hist, val_f1_hist, val_b_hist = train_classifier.run_train(n_epochs=n_epochs, lr=learning_rate, batch_size=batch_size) print(f'trained in {time.time() - t} sec') if args.s_model: m_exporter = ModelExporter('fer2013_datasetD', root_dir=current_working_dir) m_exporter.save_nn_model(trained_model, optimizer, trained_model.get_args())
y_val_df = pre.get(name='val')['emotion'] n_classes = 7 n_epochs = 10 learning_rate = 0.001 batch_size = 64 dtype = torch.float model_conv = torchvision.models.vgg16_bn(pretrained=True) # _bn batch normalization model_name = f'cnn_VGG16_pretrained_A_bs_{learning_rate}_{batch_size}_{n_epochs}_{n_classes}' model = CnnVGG16Pretrained(model_name, features = model_conv.features) model.load_state_dict(state_dict=model_conv.state_dict()) model.prepare_model() model.train() train_classifier = TrainClassifier2(model, train_pixel_224_np, y_train_df, val_pixel_224_np, y_val_df, to_rgb=True, root_dir=current_working_dir) t = time.time() trained_model, optimizer, criterion, \ train_loss_hist, train_acc_hist, train_f1_hist, train_b_hist,\ val_loss_hist, val_acc_hist, val_f1_hist, val_b_hist = train_classifier.run_train(n_epochs=n_epochs, lr=learning_rate, batch_size=batch_size) print(f'trained in {time.time() - t} sec') if args.s_model: m_exporter = ModelExporter('fer2013_datasetA', root_dir=current_working_dir) m_exporter.save_nn_model(trained_model, optimizer,trained_model.get_args()) m_exporter.save_results(f'{model_name}', train_loss_hist, train_acc_hist, train_f1_hist, train_b_hist, val_loss_hist, val_acc_hist, val_f1_hist, val_b_hist)
batch_size = 32 pre = Preprocessing('fer2013') pre.load_data(filename='DatasetD.csv', name='train') X_df = pre.get(name='train').drop(columns=['emotion']) y_df = pre.get(name='train')['emotion'] dtype = torch.float device = torch.device("cpu") model_name = f'cnn_double_layer_D_bs_{learning_rate}_{batch_size}_{n_epochs}_{n_classes}' model = CnnDoubleLayer(model_name, d_out=n_classes) model.train() train_classifier = TrainClassifier2(model, X_df, y_df) t = time.time() trained_model, optimizer, criterion, loss_hist, loss_val_hist, f1_val_hist = train_classifier.run_train( n_epochs=n_epochs, lr=learning_rate, batch_size=batch_size) print(f'trained in {time.time() - t} sec') pre.save_results(loss_hist, loss_val_hist, f1_val_hist, f'{model_name}') if args.s_model: m_exporter = ModelExporter('fer2013_DatasetD') m_exporter.save_nn_model(trained_model, optimizer, trained_model.get_args()) if args.s_patterns: detected_patterns1 = trained_model.get_detected_patterns1() for idx in range(10): plt.figure(1, figsize=(20, 10))
X_train_df = pre.get(name='train').drop(columns=['emotion']) y_train_df = pre.get(name='train')['emotion'] X_val_df = pre.get(name='validate').drop(columns=['emotion']) y_val_df = pre.get(name='validate')['emotion'] n_classes = 7 n_epochs = 100 learning_rate = 0.001 batch_size = 64 model_name = f'cnn_simple_reduced_bs_{learning_rate}_{batch_size}_{n_epochs}_{n_classes}' model = CnnSimple(model_name, d_out=n_classes) train_classifier = TrainClassifier2(model, X_train_df, y_train_df, X_val_df, y_val_df, root_dir=script_root_dir) t = time.time() trained_model, optimizer, criterion, \ train_loss_hist, train_acc_hist, train_f1_hist, train_b_hist,\ val_loss_hist, val_acc_hist, val_f1_hist, val_b_hist = train_classifier.run_train(n_epochs=n_epochs, lr=learning_rate, batch_size=batch_size) print(f'trained in {time.time() - t} sec') if args.s_model: m_exporter = ModelExporter('fer2013_reduced', root_dir=script_root_dir) m_exporter.save_nn_model(trained_model, optimizer, trained_model.get_args())