Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.pad.base
Commits
e5879661
Commit
e5879661
authored
Jun 22, 2018
by
Guillaume HEUSCH
Browse files
[svm] added some debug information
parent
6542568e
Changes
1
Hide whitespace changes
Inline
Side-by-side
bob/pad/base/algorithm/SVM.py
View file @
e5879661
...
...
@@ -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
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment