tfaip.lav

LAV

Implementation of LAV

class tfaip.lav.lav.MetricsAccumulator

Bases: object

Computation of the running weighted sum (=weighted mean) of a dictionary of float (here the metrics of the scenario) Call final() to access the mean.

running_sum

The running weighted sum of all values

running_weight

The sum of all weights

__init__()

Initialize self. See help(type(self)) for accurate signature.

accumulate_dict_sum(new_values: Dict[str, float], sample_weights: Dict[str, float])
final()
class tfaip.lav.lav.LAV(params: tfaip.lav.params.LAVParams, data_fn: Callable[], DataBase], model_fn: Callable[], ModelBase], predictor_fn: Callable[[tfaip.predict.params.PredictorParams, DataBase], tfaip.predict.predictor.Predictor], evaluator_fn: Callable[], tfaip.evaluator.evaluator.EvaluatorBase])

Bases: abc.ABC

This is the base Class for Loading And Validation (LAV) a scenario. By default, LAV is independent of the scenario and should therefore not be overridden (but it is possible though in Meta of a Scenario).

LAV will open an exported (or the best) model, create the metrics of the actual scenario. Then predict is called on the model on the DataBase validation(!) set and fed to the metric to obtain results (MetricsAccumulator). During the prediction a models print_evaluate method is called to print informative text.

The first possibility to override LAV is to inherit and use _on_batch_end, _on_sample_end, _on_lav_end with custom parameters. Thus is used for instance to support rendering of attention matrices in atr.transformer.

classmethod params_cls()Type[tfaip.lav.params.LAVParams]
__init__(params: tfaip.lav.params.LAVParams, data_fn: Callable[], DataBase], model_fn: Callable[], ModelBase], predictor_fn: Callable[[tfaip.predict.params.PredictorParams, DataBase], tfaip.predict.predictor.Predictor], evaluator_fn: Callable[], tfaip.evaluator.evaluator.EvaluatorBase])

Initialize self. See help(type(self)) for accurate signature.

run(**kwargs)
extract_dump_data(sample: tfaip.data.pipeline.definitions.Sample)

MultiLAV

Implementation of MultiLAV

class tfaip.lav.multilav.MultiLAV(params: tfaip.lav.params.LAVParams, predictor_fn: Callable[[List[str], tfaip.predict.params.PredictorParams], tfaip.predict.multimodelpredictor.MultiModelPredictor], evaluator: tfaip.evaluator.evaluator.EvaluatorBase, predictor_params: tfaip.predict.params.PredictorParams)

Bases: abc.ABC

Similar to LAV but supports multiple models and voting. Drawback: does not use metrics defined in model (EvaluatorBase and Voter must handle everything)

classmethod params_cls()Type[tfaip.lav.params.LAVParams]
__init__(params: tfaip.lav.params.LAVParams, predictor_fn: Callable[[List[str], tfaip.predict.params.PredictorParams], tfaip.predict.multimodelpredictor.MultiModelPredictor], evaluator: tfaip.evaluator.evaluator.EvaluatorBase, predictor_params: tfaip.predict.params.PredictorParams)

Initialize self. See help(type(self)) for accurate signature.

run(**kwargs)
extract_dump_data(sample: tfaip.data.pipeline.definitions.Sample)

LAVParams

Implementation of the LAVParams

class tfaip.lav.params.LAVParams(pipeline: tfaip.data.databaseparams.DataPipelineParams = <factory>, model_path: Optional[Union[str, List[str]]] = None, device: tfaip.device.device_config.DeviceConfigParams = <factory>, silent: bool = False, store_results: bool = True)

Bases: object

Parameters for LAV

pipeline: tfaip.data.databaseparams.DataPipelineParams
model_path: Union[str, List[str]] = None
device: tfaip.device.device_config.DeviceConfigParams
silent: bool = False
store_results: bool = True
__init__(pipeline: tfaip.data.databaseparams.DataPipelineParams = <factory>, model_path: Optional[Union[str, List[str]]] = None, device: tfaip.device.device_config.DeviceConfigParams = <factory>, silent: bool = False, store_results: bool = True)None

Initialize self. See help(type(self)) for accurate signature.

classmethod from_dict(kvs: Optional[Union[dict, list, str, int, float, bool]], *, infer_missing=False)A
classmethod from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw)A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None)dataclasses_json.mm.SchemaF[A]
to_dict(encode_json=False)Dict[str, Optional[Union[dict, list, str, int, float, bool]]]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Optional[Union[int, str]] = None, separators: Optional[Tuple[str, str]] = None, default: Optional[Callable] = None, sort_keys: bool = False, **kw)str

Callbacks

Implementation of a general LAVCallback

class tfaip.lav.callbacks.lav_callback.LAVCallback

Bases: abc.ABC

Base class of a callback that can be added to LAV

__init__()

Initialize self. See help(type(self)) for accurate signature.

abstract on_sample_end(data_generator_params: tfaip.data.databaseparams.DataGeneratorParams, sample)
abstract on_lav_end(data_generator_params: tfaip.data.databaseparams.DataGeneratorParams, result)

Definition of the DumpResultsCallback using in LAV

class tfaip.lav.callbacks.dump_results.DumpResultsCallback(filepath: str)

Bases: tfaip.lav.callbacks.lav_callback.LAVCallback

Callback that dumps all results to a file using pickle.

__init__(filepath: str)

Initialize self. See help(type(self)) for accurate signature.

on_sample_end(data_generator_params: tfaip.data.databaseparams.DataGeneratorParams, sample)
on_lav_end(data_generator_params: tfaip.data.databaseparams.DataGeneratorParams, result)