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
e85eb10b
There was a problem fetching the pipeline summary.
Commit
e85eb10b
authored
7 years ago
by
Guillaume HEUSCH
Browse files
Options
Downloads
Patches
Plain Diff
[algorithm] added my simple implementation of One Class SVM
parent
c9b2ecc3
Branches
Branches containing commit
No related tags found
1 merge request
!33
WIP: added LDA and MLP
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/pad/base/algorithm/OCSVM.py
+73
-0
73 additions, 0 deletions
bob/pad/base/algorithm/OCSVM.py
bob/pad/base/algorithm/__init__.py
+1
-0
1 addition, 0 deletions
bob/pad/base/algorithm/__init__.py
with
74 additions
and
0 deletions
bob/pad/base/algorithm/OCSVM.py
0 → 100644
+
73
−
0
View file @
e85eb10b
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import
numpy
from
bob.pad.base.algorithm
import
Algorithm
import
bob.learn.libsvm
import
bob.io.base
class
OCSVM
(
Algorithm
):
"""
This class interfaces a One Class SVM classifier used for PAD
"""
def
__init__
(
self
,
rescale
=
True
,
nu
=
0.01
,
gamma
=
0.1
,
**
kwargs
):
Algorithm
.
__init__
(
self
,
performs_projection
=
True
,
requires_projector_training
=
True
,
**
kwargs
)
self
.
rescale
=
rescale
self
.
nu
=
nu
self
.
gamma
=
gamma
self
.
machine
=
None
self
.
trainer
=
bob
.
learn
.
libsvm
.
Trainer
(
machine_type
=
'
ONE_CLASS
'
,
kernel_type
=
'
RBF
'
,
probability
=
True
)
def
train_projector
(
self
,
training_features
,
projector_file
):
"""
Trains the One Class SVM
**Parameters**
training_features:
"""
# training_features[0] - training features for the REAL class.
# training_features[1] - training features for the ATTACK class.
# The data - "positive class only"
pos
=
numpy
.
array
(
training_features
[
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
]
=
((
2
*
(
pos
[
i
]
-
min_value
))
/
(
max_value
-
min_value
))
-
1
pos
=
[
pos
]
# train
self
.
machine
=
self
.
trainer
.
train
(
pos
)
print
(
self
.
machine
.
shape
)
f
=
bob
.
io
.
base
.
HDF5File
(
projector_file
,
'
w
'
)
self
.
machine
.
save
(
f
)
def
project
(
self
,
feature
):
"""
Project the given feature
"""
if
self
.
rescale
:
min_value
=
numpy
.
min
(
feature
)
max_value
=
numpy
.
max
(
feature
)
feature
=
((
2
*
(
feature
-
min_value
))
/
(
max_value
-
min_value
))
-
1
return
self
.
machine
(
feature
)
def
score
(
self
,
toscore
):
return
[
toscore
[
0
]]
This diff is collapsed.
Click to expand it.
bob/pad/base/algorithm/__init__.py
+
1
−
0
View file @
e85eb10b
...
...
@@ -5,6 +5,7 @@ from .LogRegr import LogRegr
from
.SVMCascadePCA
import
SVMCascadePCA
from
.MLP
import
MLP
from
.PadLDA
import
PadLDA
from
.OCSVM
import
OCSVM
def
__appropriate__
(
*
args
):
"""
Says object was actually declared here, and not in the import module.
...
...
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