diff --git a/bob/pad/base/algorithm/SVM.py b/bob/pad/base/algorithm/SVM.py index 9eb71ec04632442cc1b06c7b6537a8661f8f1f9b..93ef4c6e97b9cc05d43bc446801bb0fdd9f4c1f6 100644 --- a/bob/pad/base/algorithm/SVM.py +++ b/bob/pad/base/algorithm/SVM.py @@ -230,6 +230,8 @@ class SVM(Algorithm): A trained SVM machine. """ + kernel_type = 'LINEAR' + one_class_flag = ( machine_type == 'ONE_CLASS') # True if one-class SVM is used @@ -237,11 +239,21 @@ class SVM(Algorithm): real_train, real_cv, attack_train, attack_cv = \ prepare_data_for_hyper_param_grid_search(training_features, n_samples) + # at this point the first half for every class is for training, the 2nd half for CV + + #for f in range(real_train.shape[0]): + # print("real feature {} = {}".format(f, real_train[f])) + if mean_std_norm_flag: # normalize the data: real_train, real_cv, attack_train, attack_cv = norm_train_cv_data( real_train, real_cv, attack_train, attack_cv, one_class_flag) + # at this point, features have been normalized using the mean and std across all + # training features (i.e. real and attack examples ...) + + + precisions_cv = [ ] # for saving the precision on the cross-validation set @@ -253,6 +265,7 @@ class SVM(Algorithm): for trainer_grid_search_param in trainer_grid_search_params_list: + # initialize the SVM trainer: trainer = bob.learn.libsvm.Trainer( machine_type=machine_type, @@ -275,7 +288,32 @@ class SVM(Algorithm): data = [np.copy(real_train) ] # only real class is used for training + + print(data[0].shape) + print(data[1].shape) + stacked_data = np.vstack((data[0], data[1])) + print(stacked_data.shape) + col_sum = np.sum(stacked_data, axis=0) + print(col_sum) + import sys + sys.exit() + + #print("=== TRAINING DATA ===") + #print("data for training (len) -> {}".format(len(data))) + #print("real data for training (shape) -> {}".format(data[0].shape)) + #print("attack data for training (shape) -> {}".format(data[1].shape)) + ##for i in range(data[0].shape[0]): + # print("real example {} -> shape = {}".format(i, data[0][i].shape)) + #for i in range(data[1].shape[0]): + # print("attack example {} -> shape = {}".format(i, data[1][i].shape)) + + #print("trained machine shape (before training) -> {}".format(machine.shape)) machine = trainer.train(data) # train the machine + #print("trained machine shape -> {}".format(machine.shape)) + + #print("=== CV DATA ===") + #print("real examples CV shape -> {}".format(np.copy(real_cv).shape)) + #print("attack examples CV -> {}".format(np.copy(attack_cv).shape)) precision_cv = self.comp_prediction_precision( machine, np.copy(real_cv), np.copy(attack_cv))