Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.pad.base
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bob
bob.pad.base
Commits
cff21817
Commit
cff21817
authored
Jun 22, 2018
by
Guillaume HEUSCH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[algorithms] added my own version of one-class GMM
parent
9ddf3309
Pipeline
#21279
failed with stage
in 48 minutes and 20 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
0 deletions
+139
-0
bob/pad/base/algorithm/OCGMM.py
bob/pad/base/algorithm/OCGMM.py
+64
-0
bob/pad/base/algorithm/SKLGMM.py
bob/pad/base/algorithm/SKLGMM.py
+75
-0
No files found.
bob/pad/base/algorithm/OCGMM.py
0 → 100644
View file @
cff21817
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import
numpy
from
bob.pad.base.algorithm
import
Algorithm
import
bob.learn.em
import
bob.io.base
class
OCGMM
(
Algorithm
):
"""
This class interfaces a GMM-based "classifier" to perform PAD experiments
A GMM is used to model the bonafide features
"""
def
__init__
(
self
,
n_gaussians
=
2
,
max_iter
=
1000
,
conv_threshold
=
1e-5
,
**
kwargs
):
Algorithm
.
__init__
(
self
,
performs_projection
=
True
,
requires_projector_training
=
True
,
**
kwargs
)
self
.
n_gaussians
=
n_gaussians
self
.
max_iter
=
max_iter
self
.
conv_threshold
=
conv_threshold
self
.
machine
=
None
self
.
trainer
=
bob
.
learn
.
em
.
ML_GMMTrainer
(
update_means
=
True
,
update_variances
=
True
,
update_weights
=
True
)
def
train_projector
(
self
,
training_features
,
projector_file
):
"""
Trains the GMM using Expectation-Maximimazation with Maximum Likelihood criterion
**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
])
features_dim
=
pos
.
shape
[
1
]
# The machine
self
.
machine
=
bob
.
learn
.
em
.
GMMMachine
(
self
.
n_gaussians
,
features_dim
)
# train
bob
.
learn
.
em
.
train
(
self
.
trainer
,
self
.
machine
,
pos
,
max_iterations
=
self
.
max_iter
,
convergence_threshold
=
self
.
conv_threshold
)
f
=
bob
.
io
.
base
.
HDF5File
(
projector_file
,
'w'
)
self
.
machine
.
save
(
f
)
def
project
(
self
,
feature
):
"""
Compute the log-likelihood of the feature
"""
return
self
.
machine
(
feature
)
def
score
(
self
,
toscore
):
return
[
toscore
[
0
]]
bob/pad/base/algorithm/SKLGMM.py
0 → 100644
View file @
cff21817
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import
numpy
from
bob.pad.base.algorithm
import
Algorithm
import
bob.io.base
from
sklearn
import
mixture
class
SKLGMM
(
Algorithm
):
"""
This class interfaces a GMM-based "classifier" to perform PAD experiments
A GMM is used to model the bonafide features
"""
def
__init__
(
self
,
n_gaussians
=
2
,
max_iter
=
1000
,
conv_threshold
=
1e-5
,
**
kwargs
):
Algorithm
.
__init__
(
self
,
performs_projection
=
True
,
requires_projector_training
=
True
,
**
kwargs
)
self
.
n_gaussians
=
n_gaussians
self
.
max_iter
=
max_iter
self
.
conv_threshold
=
conv_threshold
self
.
machine
=
mixture
.
GaussianMixture
(
n_components
=
n_gaussians
,
tol
=
conv_threshold
,
max_iter
=
max_iter
)
self
.
parameters_keys
=
[
"covariance_type"
,
"covariances_"
,
"lower_bound_"
,
"means_"
,
"n_components"
,
"weights_"
,
"converged_"
,
"precisions_"
,
"precisions_cholesky_"
]
def
train_projector
(
self
,
training_features
,
projector_file
):
"""
Trains the GMM using Expectation-Maximimazation with Maximum Likelihood criterion
**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
])
features_dim
=
pos
.
shape
[
1
]
# train
self
.
machine
.
fit
(
pos
)
# save
f
=
bob
.
io
.
base
.
HDF5File
(
projector_file
,
'w'
)
for
key
in
self
.
parameters_keys
:
data
=
getattr
(
self
.
machine
,
key
)
f
.
set
(
key
,
data
)
def
load_projector
(
self
,
projector_file
):
f
=
bob
.
io
.
base
.
HDF5File
(
projector_file
,
'r'
)
# file to read the machine from
self
.
machine
=
mixture
.
GaussianMixture
()
for
key
in
self
.
parameters_keys
:
data
=
f
.
read
(
key
)
setattr
(
self
.
machine
,
key
,
data
)
def
project
(
self
,
feature
):
"""
Compute the log-likelihood of the feature
"""
# load
return
self
.
machine
.
score_samples
(
feature
)
def
score
(
self
,
toscore
):
return
[
toscore
[
0
]]
Write
Preview
Markdown
is supported
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