FaceRecLib Utilities

facereclib.utils.load(file)[source]

Loads data from file. The given file might be an HDF5 file open for reading or a string.

facereclib.utils.save(data, file, compression=0)[source]

Saves the data to file using HDF5. The given file might be an HDF5 file open for writing, or a string. If the given data contains a save method, this method is called with the given HDF5 file. Otherwise the data is written to the HDF5 file using the given compression.

facereclib.utils.open_compressed(filename, open_flag='r', compression_type='bz2')[source]

Opens a compressed HDF5File with the given opening flags. For the ‘r’ flag, the given compressed file will be extracted to a local space. For ‘w’, an empty HDF5File is created. In any case, the opened HDF5File is returned, which needs to be closed using the close_compressed() function.

facereclib.utils.close_compressed(filename, hdf5_file, compression_type='bz2', create_link=False)[source]

Closes the compressed hdf5_file that was opened with open_compressed. When the file was opened for writing (using the ‘w’ flag in open_compressed), the created HDF5 file is compressed into the given file name. To be able to read the data using the real tools, a link with the correct extension might is created, when create_link is set to True.

facereclib.utils.load_compressed(filename, compression_type='bz2')[source]

Extracts the data to a temporary HDF5 file using HDF5 and reads its contents. Note that, though the file name is .hdf5, it contains compressed data! Accepted compression types are ‘gz’, ‘bz2’, ‘’

facereclib.utils.save_compressed(data, filename, compression_type='bz2', create_link=False)[source]

Saves the data to a temporary file using HDF5. Afterwards, the file is compressed using the given compression method and saved using the given file name. Note that, though the file name will be .hdf5, it will contain compressed data! Accepted compression types are ‘gz’, ‘bz2’, ‘’

facereclib.utils.ensure_dir(dirname)[source]

Creates the directory dirname if it does not already exist, taking into account concurrent ‘creation’ on the grid. An exception is thrown if a file (rather than a directory) already exists.

facereclib.utils.score_fusion_strategy(strategy_name='avarage')[source]

Returns a function to compute a fusion strategy between different scores.

Different strategies are employed:

  • 'average' : The averaged score is computed using the numpy.average() function.
  • 'min' : The minimum score is computed using the min() function.
  • 'max' : The maximum score is computed using the max() function.
  • 'median' : The median score is computed using the numpy.median() function.
  • None is also accepted, in which case None is returned.
facereclib.utils.gray_channel(image, channel='gray')[source]

Returns the desired channel of the given image. Currently, gray, red, green and blue channels are supported.

facereclib.utils.quasi_random_indices(number_of_total_items, number_of_desired_items=None)[source]

Returns a quasi-random list of indices that will contain exactly the number of desired indices (or the number of total items in the list, if this is smaller).

facereclib.utils.command_line(cmdline)[source]

Converts the given options to a string that can be executed on command line.

class facereclib.utils.GridParameters(grid='sge', number_of_preprocessing_jobs=32, number_of_extraction_jobs=32, number_of_projection_jobs=32, number_of_enrollment_jobs=32, number_of_scoring_jobs=32, training_queue='8G', preprocessing_queue='default', extraction_queue='default', projection_queue='default', enrollment_queue='default', scoring_queue='default', number_of_parallel_processes=1, scheduler_sleep_time=1.0)[source]

This class is defining the options that are required to submit parallel jobs to the SGE grid.

is_local()[source]

Returns whether this grid setup should use the local submission or the SGE grid.

queue(params)[source]

Helper function to translate the given queue parameters to grid options.

facereclib.utils.add_bob_handlers(logger_name, set_format=True, set_log_level=True)[source]

Sets the logging handler of ‘bob’ to the logger with the given name

facereclib.utils.add_logger_command_line_option(parser)[source]

Adds the verbosity command line option to the given parser.

facereclib.utils.debug(text)[source]

Writes the given text to the debug stream.

facereclib.utils.error(text)[source]

Writes the given text to the error stream.

facereclib.utils.info(text)[source]

Writes the given text to the info stream.

facereclib.utils.set_verbosity_level(level)[source]

Sets the log level to 0: Error; 1: Warn; 2: Info; 3: Debug.

facereclib.utils.warn(text)[source]

Writes the given text to the warning stream.