Commit 28bdfd74 authored by Anjith GEORGE's avatar Anjith GEORGE

Removed the old oneclassGMM

parent 4478742b
Pipeline #36737 failed with stage
in 4 minutes and 13 seconds
This diff is collapsed.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
@author: Anjith George
"""
#==============================================================================
from .ScikitClassifier import ScikitClassifier
from sklearn.mixture import GaussianMixture
from sklearn.preprocessing import StandardScaler
class OneClassGMM3(ScikitClassifier):
"""
This class is designed to train a OneClassGMM based PAD system. The OneClassGMM is trained
using data of one class (real class) only. The procedure is the following:
1. First, the training data is mean-std normalized using mean and std of the
real class only.
2. Second, the OneClassGMM with ``n_components`` Gaussians is trained using samples
of the real class.
3. The input features are next classified using pre-trained OneClassGMM machine.
**Parameters:**
``n_components`` : :py:class:`int`
Number of Gaussians in the OneClassGMM. Default: 1 .
``random_state`` : :py:class:`int`
A seed for the random number generator used in the initialization of
the OneClassGMM. Default: 3 .
``frame_level_scores_flag`` : :py:class:`bool`
Return scores for each frame individually if True. Otherwise, return a
single score per video. Default: False.
"""
def __init__(self,
n_components=1,
random_state=3,
frame_level_scores_flag=False,
covariance_type='full',
reg_covar=1e-06,
):
ScikitClassifier.__init__(self,
clf=GaussianMixture(n_components=n_components, random_state=random_state, covariance_type=covariance_type,reg_covar=reg_covar),
scaler=StandardScaler(),
frame_level_scores_flag=frame_level_scores_flag,
norm_on_bonafide=True,
one_class=True)
\ No newline at end of file
......@@ -2,7 +2,6 @@ from .Algorithm import Algorithm
from .SVM import SVM
from .OneClassGMM import OneClassGMM
from .OneClassGMM2 import OneClassGMM2
from .OneClassGMM3 import OneClassGMM3
from .LogRegr import LogRegr
from .SVMCascadePCA import SVMCascadePCA
......@@ -35,7 +34,6 @@ __appropriate__(
SVM,
OneClassGMM,
OneClassGMM2,
OneClassGMM3,
LogRegr,
SVMCascadePCA,
Predictions,
......
......@@ -123,67 +123,13 @@ def test_video_gmm_pad_algorithm():
real = convert_array_to_list_of_frame_cont(real_array)
N_COMPONENTS = 1
RANDOM_STATE = 3
FRAME_LEVEL_SCORES_FLAG = True
algorithm = OneClassGMM(
n_components=N_COMPONENTS,
random_state=RANDOM_STATE,
frame_level_scores_flag=FRAME_LEVEL_SCORES_FLAG)
# training_features[0] - training features for the REAL class.
real_array_converted = convert_list_of_frame_cont_to_array(real) # output is array
assert (real_array == real_array_converted).all()
# Train the OneClassGMM machine and get normalizers:
machine, features_mean, features_std = algorithm.train_gmm(
real=real_array_converted)
algorithm.machine = machine
algorithm.features_mean = features_mean
algorithm.features_std = features_std
scores_real = algorithm.project(real_array_converted)
scores_attack = algorithm.project(attack_array)
assert (np.min(scores_real) + 7.9423798970985917) < 0.000001
assert (np.max(scores_real) + 1.8380480068281055) < 0.000001
assert (np.min(scores_attack) + 38.831260843070098) < 0.000001
assert (np.max(scores_attack) + 5.3633030621521272) < 0.000001
def test_video_gmm_pad_algorithm_3():
random.seed(7)
N = 1000
mu = 1
sigma = 1
real_array = np.transpose(
np.vstack([[random.gauss(mu, sigma) for _ in range(N)],
[random.gauss(mu, sigma) for _ in range(N)]]))
mu = 5
sigma = 1
attack_array = np.transpose(
np.vstack([[random.gauss(mu, sigma) for _ in range(N)],
[random.gauss(mu, sigma) for _ in range(N)]]))
real = convert_array_to_list_of_frame_cont(real_array)
attack = convert_array_to_list_of_frame_cont(attack_array)
N_COMPONENTS = 1
RANDOM_STATE = 3
FRAME_LEVEL_SCORES_FLAG = True
algorithm = OneClassGMM3(
algorithm = OneClassGMM(
n_components=N_COMPONENTS,
random_state=RANDOM_STATE,
frame_level_scores_flag=FRAME_LEVEL_SCORES_FLAG)
......
Markdown is supported
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