Commit 3b270041 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME

Merge branch 'theo-gen-load' into 'theo'

Generic loading input file

See merge request !50
parents f3657022 f3ea47fb
Pipeline #17786 passed with stage
in 20 minutes and 58 seconds
This diff is collapsed.
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Mon 23 May 2011 16:23:05 CEST
"""A set of utilities to load score files with different formats.
"""
import logging
import numpy
LOGGER = logging.getLogger('bob.measure')
def split(filename):
"""split(filename) -> negatives, positives
Loads the scores from the given file and splits them into positive
and negative arrays. The file must be a two columns file where the first
column contains -1 or 1 (for negative or positive respectively) and the
second the corresponding scores.
Parameters
----------
filename: :py:class:`str`:
The name of the file containing the scores.
Returns
-------
negatives: 1D :py:class:`numpy.ndarray` of type float
This array contains the list of negative scores
positives: 1D :py:class:`numpy.ndarray` of type float
This array contains the list of positive scores
"""
try:
columns = numpy.loadtxt(filename)
neg_pos = columns[:, 0]
scores = columns[:, 1]
except:
LOGGER.error('''Cannot read {}. This file must be a two columns file with
the first column containing -1 or 1 (i.e. negative or
positive) and the second the scores
(float).'''.format(filename))
return None, None
return (scores[numpy.where(neg_pos == -1)],
scores[numpy.where(neg_pos == 1)])
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <andre.anjos@idiap.ch>
# Wed 11 Dec 15:14:08 2013 CET
#
# Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland
"""Tests the IO functionality of bob.measure."""
from nose.tools import assert_equal
import bob.measure.load
import bob.io.base.test_utils
import bob.io.base
import numpy
def test_split():
# This function test loading for generic bob.measure input files
# Read test file
test_file = bob.io.base.test_utils.datafile(
'data.txt', 'bob.measure')
neg, pos = bob.measure.load.split(test_file)
assert neg is not None
assert_equal(len(neg), 521)
assert_equal(len(pos), 479)
test_ref_file_path = bob.io.base.test_utils.datafile(
'two-cols.hdf5', 'bob.measure')
test_ref = bob.io.base.HDF5File(test_ref_file_path)
neg_ref = test_ref.read('negatives')
pos_ref = test_ref.read('positives')
del test_ref
assert numpy.array_equal(numpy.nan_to_num(neg_ref), numpy.nan_to_num(neg))
assert numpy.array_equal(numpy.nan_to_num(pos_ref), numpy.nan_to_num(pos))
......@@ -83,6 +83,12 @@ Plotting
bob.measure.plot.cmc
bob.measure.plot.detection_identification_curve
Loading
-------
.. autosummary::
bob.measure.load.split
Details
-------
......@@ -90,3 +96,4 @@ Details
.. automodule:: bob.measure
.. automodule:: bob.measure.calibration
.. automodule:: bob.measure.plot
.. automodule:: bob.measure.load
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