Commit e5879661 authored by Guillaume HEUSCH's avatar Guillaume HEUSCH
Browse files

[svm] added some debug information

parent 6542568e
...@@ -230,6 +230,8 @@ class SVM(Algorithm): ...@@ -230,6 +230,8 @@ class SVM(Algorithm):
A trained SVM machine. A trained SVM machine.
""" """
kernel_type = 'LINEAR'
one_class_flag = ( one_class_flag = (
machine_type == 'ONE_CLASS') # True if one-class SVM is used machine_type == 'ONE_CLASS') # True if one-class SVM is used
...@@ -237,11 +239,21 @@ class SVM(Algorithm): ...@@ -237,11 +239,21 @@ class SVM(Algorithm):
real_train, real_cv, attack_train, attack_cv = \ real_train, real_cv, attack_train, attack_cv = \
prepare_data_for_hyper_param_grid_search(training_features, n_samples) 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: if mean_std_norm_flag:
# normalize the data: # normalize the data:
real_train, real_cv, attack_train, attack_cv = norm_train_cv_data( real_train, real_cv, attack_train, attack_cv = norm_train_cv_data(
real_train, real_cv, attack_train, attack_cv, one_class_flag) 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 = [ precisions_cv = [
] # for saving the precision on the cross-validation set ] # for saving the precision on the cross-validation set
...@@ -253,6 +265,7 @@ class SVM(Algorithm): ...@@ -253,6 +265,7 @@ class SVM(Algorithm):
for trainer_grid_search_param in trainer_grid_search_params_list: for trainer_grid_search_param in trainer_grid_search_params_list:
# initialize the SVM trainer: # initialize the SVM trainer:
trainer = bob.learn.libsvm.Trainer( trainer = bob.learn.libsvm.Trainer(
machine_type=machine_type, machine_type=machine_type,
...@@ -275,7 +288,32 @@ class SVM(Algorithm): ...@@ -275,7 +288,32 @@ class SVM(Algorithm):
data = [np.copy(real_train) data = [np.copy(real_train)
] # only real class is used for training ] # 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 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( precision_cv = self.comp_prediction_precision(
machine, np.copy(real_cv), np.copy(attack_cv)) machine, np.copy(real_cv), np.copy(attack_cv))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment