Commit 5675f218 authored by Guillaume HEUSCH's avatar Guillaume HEUSCH
Browse files

[mysvm] added some debug stuff

parent e5879661
......@@ -13,7 +13,7 @@ class mySVM(Algorithm):
"""
def __init__(self, rescale=True, gamma=0.1, **kwargs):
def __init__(self, rescale=True, gamma=0.1, cost=1.0, **kwargs):
Algorithm.__init__(self,
performs_projection=True,
......@@ -22,9 +22,11 @@ class mySVM(Algorithm):
self.rescale = rescale
self.gamma = gamma
self.cost = cost
self.machine = None
self.trainer = bob.learn.libsvm.Trainer(machine_type='C_SVC', kernel_type='RBF', probability=True)
self.trainer = bob.learn.libsvm.Trainer(machine_type='C_SVC', kernel_type='RBF', probability=False)
setattr(self.trainer, 'gamma', self.gamma)
setattr(self.trainer, 'cost', self.cost)
def train_projector(self, training_features, projector_file):
......@@ -38,24 +40,51 @@ class mySVM(Algorithm):
# training_features[0] - training features for the REAL class.
# training_features[1] - training features for the ATTACK class.
# The data - "positive class only"
# The data
pos = numpy.array(training_features[0])
neg = numpy.array(training_features[1])
for i in range(pos.shape[0]):
print("real feature {}:".format(i))
print(pos[i])
print("positive examples shape {}".format(pos.shape))
print("negative examples shape {}".format(neg.shape))
# -----------------------------------------------------
# Olegs whole stuff
#n_real = pos.shape[0]
#n_attack = neg.shape[0]
#pos_train = pos[:numpy.int(n_real/2)]
#neg_train = neg[:numpy.int(n_real/2)]
#pos_cv = pos[numpy.int(n_real/2):2*numpy.int(n_real/2)+1]
#neg_cv = neg[numpy.int(n_real/2):2*numpy.int(n_real/2)+1]
# -----------------------------------------------------
print("Feature before rescaling")
print(pos[0])
if self.rescale:
for i in range(pos.shape[0]):
min_value = numpy.min(pos[i])
max_value = numpy.max(pos[i])
#pos[i] = (pos[i] - min_value)/ (max_value - min_value)
pos[i] = ((2 * (pos[i] - min_value))/ (max_value - min_value)) - 1
for i in range(neg.shape[0]):
min_value = numpy.min(neg[i])
max_value = numpy.max(neg[i])
#neg[i] = (neg[i] - min_value)/ (max_value - min_value)
neg[i] = ((2 * (neg[i] - min_value))/ (max_value - min_value)) - 1
print("Feature after rescaling")
print(pos[0])
data = [pos, neg]
# train
self.machine = self.trainer.train(data)
print(self.machine.shape)
f = bob.io.base.HDF5File(projector_file, 'w')
self.machine.save(f)
......
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