Coverage for src/bob/bio/spear/config/pipeline/mfcc60_gmm_mobio.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-06 22:04 +0100

1#!/usr/bin/env python 

2# @author: Yannick Dayer <yannick.dayer@idiap.ch> 

3# @date: Fri 02 Jul 2021 15:41:48 UTC+02 

4 

5"""Creates a biometric PipelineSimple for the `bob bio pipeline simple` command. 

6 

7These parameters were chosen to work best with the mobio database. 

8 

9This pipeline is composed of the following steps: 

10 - annotator: Mod_4Hz 

11 - extractor: Cepstral (MFCC, 60 features) 

12 - algorithm: GMM (trained in the pipeline as a Transformer, and used as 

13 BioAlgorithm for enrollment and scoring) 

14""" 

15 

16from sklearn.pipeline import Pipeline 

17 

18from bob.bio.base.algorithm import GMM 

19from bob.bio.base.pipelines import PipelineSimple 

20from bob.bio.spear.annotator import Mod_4Hz 

21from bob.bio.spear.extractor import Cepstral 

22from bob.learn.em import KMeansMachine 

23from bob.pipelines import wrap 

24 

25# Number of Gaussians for the UBM (used by kmeans and GMM) 

26n_gaussians = 512 

27 

28# Kmeans machine used for GMM initialization 

29kmeans_trainer = KMeansMachine( 

30 n_clusters=n_gaussians, 

31 max_iter=25, 

32 convergence_threshold=0.0, 

33 init_max_iter=5, 

34 oversampling_factor=128, 

35) 

36 

37# Algorithm used for enrollment and scoring, trained first as a Transformer. 

38bioalgorithm = GMM( 

39 n_gaussians=n_gaussians, 

40 max_fitting_steps=25, 

41 enroll_iterations=1, 

42 convergence_threshold=0.0, # Maximum number of iterations as stopping criterion 

43 k_means_trainer=kmeans_trainer, 

44 random_state=2, 

45) 

46 

47# Transformer part of PipelineSimple 

48transformer = Pipeline( 

49 [ 

50 ("annotator", wrap(["sample"], Mod_4Hz())), 

51 ("extractor", wrap(["sample"], Cepstral())), 

52 ("algorithm_trainer", wrap(["sample"], bioalgorithm)), 

53 ] 

54) 

55 

56 

57# PipelineSimple instance used by `execute_pipeline_simple` or the `pipeline simple` command 

58pipeline = PipelineSimple(transformer, bioalgorithm)