isv.py 1.23 KB
Newer Older
1
2
3
4
5
6
7
import logging
logger = logging.getLogger("bob.bio.gmm")

import bob.io.base
import os

from bob.bio.base.tools.FileSelector import FileSelector
8
from bob.bio.base import utils, tools 
9

10
11

def train_isv(algorithm, force=False, allow_missing_files=False):
12
13
14
15
  """Finally, the UBM is used to train the ISV projector/enroller."""
  fs = FileSelector.instance()

  if utils.check_file(fs.projector_file, force, 800):
16
    logger.info("ISV training: Skipping ISV training since '%s' already exists", fs.projector_file)
17
18
19
20
21
  else:
    # read UBM into the ISV class
    algorithm.load_ubm(fs.ubm_file)

    # read training data
22
    training_list = fs.training_list('projected_gmm', 'train_projector', arrange_by_client = True)
23
    training_list = utils.filter_missing_files(training_list, split_by_client=True, allow_missing_files=allow_missing_files)
24
25
26
27
28
29
30
31
    train_gmm_stats = [[algorithm.read_gmm_stats(filename) for filename in client_files] for client_files in training_list]

    # perform ISV training
    logger.info("ISV training: training ISV with %d clients", len(train_gmm_stats))
    algorithm.train_isv(train_gmm_stats)
    # save result
    bob.io.base.create_directories_safe(os.path.dirname(fs.projector_file))
    algorithm.save_projector(fs.projector_file)