Running score.py

51 views
Skip to first unread message

s...@oben.com

unread,
Aug 30, 2016, 2:54:10 PM8/30/16
to bob-devel
Hello all, 

I am recently using SPEAR for speaker verification
and what I need to to is enrolling the speaker and testing an unknown speaker in separated steps.

The solution I found was using "enroll.py" and "score.py" in the "bin" folder
instead of using "verify.py".

It worked quite well when I used "ivector-plda" algorithm,
but when I tried "gmm" algorithm
"score.py" made an error as following.

File "/home/soo/work/bin/score.py", line 34, in <module>

    sys.exit(bob.bio.base.script.score.main())

  File "/home/soo/work/eggs/bob.bio.base-2.0.9-py2.7.egg/bob/bio/base/script/score.py", line 55, in main

    for p in args.probe_files: probes[p] = algorithm.read_probe(p)

  File "/home/soo/work/eggs/bob.bio.gmm-2.0.7-py2.7.egg/bob/bio/gmm/algorithm/GMM.py", line 195, in read_feature

    return self.read_gmm_stats(feature_file)

  File "/home/soo/work/eggs/bob.bio.gmm-2.0.7-py2.7.egg/bob/bio/gmm/algorithm/GMM.py", line 191, in read_gmm_stats

    return bob.learn.em.GMMStats(bob.io.base.HDF5File(gmm_stats_file))

RuntimeError: bob.learn.em.GMMStats - cannot create GMMStats: C++ exception caught: 'Cannot find dataset `log_liklihood' at `/home/soo/Downloads/temp/extracted/test/mfcc-60-6kBand/01.hdf5:''


I put the path to the hdf5 file in the "extracted" folder as an input argument for "--probe-files" option,

but the error message seems to say that the probe file should be something different...


Could anyone give me an insight which form of "--probe-files" I should give as an input?



Thank you!

Soo  

Manuel Günther

unread,
Aug 30, 2016, 3:01:57 PM8/30/16
to bob-devel
I think the gmm algorithm needs projection, so you need to specify the --projector-file (which contains the UBM).

s...@oben.com

unread,
Aug 30, 2016, 6:49:01 PM8/30/16
to bob-devel
Thanks Manuel,

Even though I specified the projector file, it did not solve the problem... :(

Manuel Günther

unread,
Aug 30, 2016, 8:59:37 PM8/30/16
to bob-devel
Hmm... I see... this is definitely a bug in the score.py function. Although you can specify the projector and enroller files, it will not handle feature projection correctly. In fact, this script needs a major rewrite to support algorithms that require projection. Let me give it a try.

As we are currently in the process of moving our code, I cannot provide you with a proper update for the script. Anyways, can you try to replace your file "/home/soo/work/eggs/bob.bio.base-2.0.9-py2.7.egg/bob/bio/base/script/score.py" with the following content? Let me know if that solved your problem.

"""This script can be used to compute scores between a list of enrolled models and a list of probe files.
"""

from __future__ import print_function

import argparse
import bob.core
logger = bob.core.log.setup("bob.bio.base")

import bob.bio.base


def command_line_arguments(command_line_parameters):
  """Parse the program options"""

  # set up command line parser
  parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)

  parser.add_argument('-a', '--algorithm', metavar = 'x', nargs = '+', required = True, help = 'Biometric recognition; registered algorithms are: %s' % bob.bio.base.resource_keys('algorithm'))
  parser.add_argument('-P', '--projector-file', metavar = 'FILE', help = 'The pre-trained projector file, if the algorithm performs projection')
  parser.add_argument('-E', '--enroller-file' , metavar = 'FILE', help = 'The pre-trained enroller file, if the extractor requires enroller training')
  parser.add_argument('-e', '--extractor', metavar = 'x', nargs = '+', help = 'Feature extraction -- required when algorithm performs projection; registered feature extractors are: %s' % bob.bio.base.resource_keys('extractor'))
  parser.add_argument('-m', '--model-files', metavar = 'MODEL', nargs='+', required = True, help = "A list of enrolled model files")
  parser.add_argument('-p', '--probe-files', metavar = 'PROBE', nargs='+', required = True, help = "A list of extracted feature files used as probes")

  # add verbose option
  bob.core.log.add_command_line_option(parser)
  # parse arguments
  args = parser.parse_args(command_line_parameters)
  # set verbosity level
  bob.core.log.set_verbosity_level(logger, args.verbose)

  return args


def main(command_line_parameters=None):
  """Preprocesses the given image with the given preprocessor."""
  args = command_line_arguments(command_line_parameters)

  logger.debug("Loading algorithm")
  algorithm = bob.bio.base.load_resource(' '.join(args.algorithm), "algorithm")
  if algorithm.requires_projector_training:
    if args.projector_file is None:
      raise ValueError("The desired algorithm requires a pre-trained projector file, but it was not specified")
    algorithm.load_projector(args.projector_file)

  if algorithm.requires_enroller_training:
    if args.enroller_file is None:
      raise ValueError("The desired algorithm requires a pre-trained enroller file, but it was not specified")
    algorithm.load_enroller(args.enroller_file)

  models, probes = {}, {}
  logger.debug("Loading %d models", len(args.model_files))
  for m in args.model_files: models[m] = algorithm.read_model(m)
  if algorithm.performs_projection:
    if args.extractor is None:
      raise ValueError("The --extractor is required when the algorithm requires projection")
    logger.debug("Loading extractor")
    extractor = bob.bio.base.load_resource(' '.join(args.extractor), "extractor")
    logger.debug("Loading %d probes", len(args.probe_files))
    for p in args.probe_files: probes[p] = extractor.read_feature(p)
    logger.debug("Projecting %d probes", len(args.probe_files))
    for p in probes: probes[p] = algorithm.project(probes[p])
  else:
    logger.debug("Loading %d probes", len(args.probe_files))
    for p in args.probe_files: probes[p] = algorithm.read_probe(p)

  logger.info("Computing scores")
  for p in args.probe_files:
    for m in args.model_files:
      print("Score between model '%s' and probe '%s' is %3.8f" % (m, p, algorithm.score(models[m], probes[p])))


s...@oben.com

unread,
Aug 30, 2016, 11:55:17 PM8/30/16
to bob-devel
Thank you so much!
It seems working :)
Reply all
Reply to author
Forward
0 new messages