ResultsIterator

class hybrid_learning.experimentation.fuzzy_exp.fuzzy_exp_eval.ResultsIterator(conf, root='..', load_images=True, device=None, only_filenames=None, raise_on_missing=False, recalc='necessary', additional_formulas=None, additional_formula_mods=None, changed_constants=None, verbose=False, use_pretty_names=True)[source]

Bases: object

Allow to get all output infos and potentially additionally calculated values for one sample.

Public Methods:

from_cache(img_fn)

recalc_predicate_masks(img_t)

recalc_formula_masks(masks_t, recalc_formulas)

get_all_masks(img_fn)

Special Methods:

__init__(conf[, root, load_images, device, ...])

Given a sacred experiment conf dict, yield pairs of image file name, original image, and dict of output masks for that experiment.

__len__()

__getitem__(i)


Parameters
__getitem__(i)[source]
Parameters

i (Union[str, int]) –

Return type

Tuple[Tensor, Tuple[Tensor, Dict[str, Union[Tensor, bool, float]]]]

__init__(conf, root='..', load_images=True, device=None, only_filenames=None, raise_on_missing=False, recalc='necessary', additional_formulas=None, additional_formula_mods=None, changed_constants=None, verbose=False, use_pretty_names=True)[source]

Given a sacred experiment conf dict, yield pairs of image file name, original image, and dict of output masks for that experiment. This is a convenience wrapper around load_orig_and_masks() and recalc_formula_masks(). Included pairs can be restricted by setting the only_filenames list. Included masks are the concept model outputs and the fuzzy logic formula output. Formula masks may be recalculated or further ones calculated and added via additional_formula_mods argument.

Parameters
  • conf (dict) – the experiment config dict (loaded using get_exp_config)

  • root (str) – the root folder in which the experiment was run

  • load_images (bool) – whether to also load the original images; else set to None

  • recalc (Union[bool, str]) – whether to recalculate missing 'formula' mask; set to True or 'always' to always recalculate the formula mask, set to False or None to never calculate masks (also disable calculation of additional_formula_mods), set to "necessary" to calculate additional_formula_mods and only recalculate missing formula masks.

  • additional_formula_mods (Optional[Dict[str, Callable[[Merge, Merge], Merge]]]) – dict of callables that accept the original formula object and the ground truth formula object of the experiment, and return a new formula object that shall be calculated (cf. recalc). Recalculated formulas are added to the output masks using the keys from the additional_formula_mods dict. This can also be used to overwrite the original formula(s) by using the keys 'formula' and 'gt_formula'. Example application: For a monitor formula, add its underlying formula body {'body': lambda f, gt_f: f.in_keys[0]} (assuming f=NOT(some_body)).

  • verbose (bool) – in case of recalculation, print some recalcuation information

  • use_pretty_names (bool) – whether to transform mask names using formula_to_display_name()

  • raise_on_missing (bool) – see load_orig_and_masks()

  • device (Optional[str]) –

  • only_filenames (Optional[Iterable]) –

  • additional_formulas (Optional[Dict[str, Merge]]) –

  • changed_constants (Optional[Dict[str, Any]]) –

Yields

tuples of (image_filename, (original_image_or_none, dict_of_masks)); for the format of the second tuple entry have a look at load_orig_and_masks.

__len__()[source]
from_cache(img_fn)[source]
Parameters

img_fn (str) –

Return type

Tuple[Tensor, Dict[str, Union[Tensor, bool, float]]]

get_all_masks(img_fn)[source]
Parameters

img_fn (str) –

recalc_formula_masks(masks_t, recalc_formulas)[source]
Parameters
Return type

Dict[str, Union[Tensor, bool, float]]

recalc_predicate_masks(img_t)[source]
Parameters

img_t (Tensor) –