Commit edf4910f authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Fixes #8 Algorithm.read_toscore_object should not exist

parent 5d9460a9
Pipeline #26921 passed with stage
in 11 minutes and 11 seconds
......@@ -85,7 +85,9 @@ class Algorithm(object):
toscore : object
The object to compute the score for.
The object to compute the score for. This will be the output of
extractor if performs_projection is False, otherwise this will be the
output of project method of the algorithm.
......@@ -159,27 +161,6 @@ class Algorithm(object):
return utils.load(feature_file)
def read_toscore_object(self, toscore_object_file):
"""read_toscore_object(toscore_object_file) -> toscore_object
Reads the toscore_object feature from a file.
By default, the toscore_object feature is identical to the projected feature.
Hence, this base class implementation simply calls :py:meth:`read_feature`.
If your algorithm requires different behavior, please overwrite this function.
toscore_object_file : str or :py:class:``
The file open for reading, or the file name to read from.
toscore_object : object
The toscore_object that was read from file.
return self.read_feature(toscore_object_file)
def train_projector(self, training_features, projector_file):
"""This function can be overwritten to train the feature projector.
If you do this, please also register the function by calling this base class constructor
......@@ -202,6 +202,7 @@ def execute(args):
elif args.sub_task == 'compute-scores':
......@@ -23,7 +23,7 @@ from .FileSelector import FileSelector
from import utils
def _compute_scores(algorithm, toscore_objects, allow_missing_files):
def _compute_scores(algorithm, extractor, toscore_objects, allow_missing_files):
"""Compute scores for the given list of objects using provided algorithm.
# the scores to be computed
......@@ -37,7 +37,10 @@ def _compute_scores(algorithm, toscore_objects, allow_missing_files):
scores.insert(i, [numpy.nan])
# read toscore
toscore = algorithm.read_toscore_object(toscore_element)
if algorithm.performs_projection:
toscore = algorithm.read_feature(toscore_element)
toscore = extractor.read_feature(toscore_element)
# compute score
if isinstance(toscore, list) or isinstance(toscore[0], numpy.ndarray):
scores.insert(i, algorithm.score_for_multiple_projections(toscore))
......@@ -120,7 +123,7 @@ def _save_scores(score_file, scores, toscore_objects, write_compressed=False):
_close_written(score_file, f, write_compressed)
def _scores_all(algorithm, group, force, allow_missing_files=False, write_compressed=False):
def _scores_all(algorithm, extractor, group, force, allow_missing_files=False, write_compressed=False):
"""Computes scores for all (real, attack) files in a given group using the provided algorithm."""
# the file selector object
fs = FileSelector.instance()
......@@ -148,7 +151,7 @@ def _scores_all(algorithm, group, force, allow_missing_files=False, write_compre
# get the attack files
current_files = fs.get_paths(current_objects, 'projected' if algorithm.performs_projection else 'extracted')
# compute scores for the list of File objects
cur_scores = _compute_scores(algorithm, current_files, allow_missing_files)
cur_scores = _compute_scores(algorithm, extractor, current_files, allow_missing_files)
total_scores += cur_scores
# Save scores to text file
_save_scores(score_file, cur_scores, current_objects, write_compressed)
......@@ -164,7 +167,7 @@ def _scores_all(algorithm, group, force, allow_missing_files=False, write_compre
current_toscore_objects[0]+current_toscore_objects[1], write_compressed)
def compute_scores(algorithm, force=False, groups=['dev', 'eval'], allow_missing_files=False, write_compressed=False):
def compute_scores(algorithm, extractor, force=False, groups=['dev', 'eval'], allow_missing_files=False, write_compressed=False):
"""Computes the scores for the given groups.
This function computes all scores for the experiment and writes them to score files.
......@@ -175,6 +178,8 @@ def compute_scores(algorithm, force=False, groups=['dev', 'eval'], allow_missing
algorithm : py:class:`` or derived
The algorithm, used for enrolling model and writing them to file.
extractor : py:class:`` or derived
force : bool
If given, files are regenerated, even if they already exist.
......@@ -192,4 +197,4 @@ def compute_scores(algorithm, force=False, groups=['dev', 'eval'], allow_missing
for group in groups:
_scores_all(algorithm, group, force, allow_missing_files, write_compressed)
_scores_all(algorithm, extractor, group, force, allow_missing_files, write_compressed)
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