Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.pad.base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.pad.base
Commits
5675f218
Commit
5675f218
authored
6 years ago
by
Guillaume HEUSCH
Browse files
Options
Downloads
Patches
Plain Diff
[mysvm] added some debug stuff
parent
e5879661
No related branches found
No related tags found
1 merge request
!33
WIP: added LDA and MLP
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/pad/base/algorithm/mySVM.py
+32
-3
32 additions, 3 deletions
bob/pad/base/algorithm/mySVM.py
with
32 additions
and
3 deletions
bob/pad/base/algorithm/mySVM.py
+
32
−
3
View file @
5675f218
...
...
@@ -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
=
Tru
e
)
self
.
trainer
=
bob
.
learn
.
libsvm
.
Trainer
(
machine_type
=
'
C_SVC
'
,
kernel_type
=
'
RBF
'
,
probability
=
Fals
e
)
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment