tfaip.predict
PredictorBase
Definition of the PredictorBase
- class tfaip.predict.predictorbase.PredictorBase(params: tfaip.predict.params.PredictorParams, data: DataBase, **kwargs)
Bases:
abc.ABCThe PredictorBase handles the prediction of data. For instantiation or subclassing see Predictor or MultiPredictor.
Several data formats are allowed: - predict: predict with given DataGeneratorParams - predict_raw: predict with a given raw sample - predict_pipeline: predict a DataPipeline - predict_dataset: predict a tf.data.Dataset predict and predict_raw will automatically apply the pre_proc pipeline of Data. The post_proc pipeline is always applied.
Metrics (e.g. timing) of the prediction will be stored in benchmark_results .. seealso:
- Predictor - MultiPredictor - ScenarioBase.create_predictor - ScenarioBase.create_multi_predictor - LAV
- classmethod params_cls() Type[tfaip.predict.params.PredictorParams]
- __init__(params: tfaip.predict.params.PredictorParams, data: DataBase, **kwargs)
- property params
- property data
- raw() tfaip.predict.raw_predictor.RawPredictor
Create a raw predictor from this predictor that allows to asynchronly predict raw samples.
Usage:
Either call
- with predictor.raw() as raw_pred:
raw_pred(sample1) raw_pred(sample2) …
or
raw_pred = predictor.raw().__enter__() raw_pred(sample1) raw_pred(sample2)
- predict(params: tfaip.data.databaseparams.DataGeneratorParams) Iterable[tfaip.data.pipeline.definitions.Sample]
Predict a DataGenerator based on its params. The generated samples will be fed in the pre_proc pipeline, the model and the post_proc pipeline
- Parameters
params – DataGeneratorParams
- Returns
The predicted Samples
- predict_raw(inputs: Iterable[Any], *, size=None) Iterable[tfaip.data.pipeline.definitions.Sample]
Predict input samples.
The raw samples will directly be fed in the pre_proc pipeline, the model and the post_proc pipeline :param inputs: Raw input which must match to the expected input of the pre_proc pipeline of Data :param size: The number of samples (to be expected).
If None, the inputs will be converted to a list to automatically compute the size. Hint, but also Warning: Set this to 1 if the length is unknown. In this case however the progress cant be computed.
- Returns
The predicted samples
See also
predict_pipeline
predict_dataset
predict
raw
- predict_pipeline(pipeline: tfaip.data.pipeline.datapipeline.DataPipeline) Iterable[tfaip.data.pipeline.definitions.Sample]
Predict a instantiated DataPipeline which is used for data generation, pre- and post-processing.
- Parameters
pipeline – the DataPipeline
- Returns
The preprocessed samples
See also
predict_dataset
predict_raw
predict
- predict_dataset(**kwargs)
PredictorParams
Definition of the PredictorParams
- class tfaip.predict.params.PredictorParams(device: tfaip.device.device_config.DeviceConfigParams = <factory>, pipeline: tfaip.data.databaseparams.DataPipelineParams = <factory>, silent: bool = False, progress_bar: bool = True, run_eagerly: bool = False, include_targets: bool = False, include_meta: bool = False)
Bases:
objectParameters for the PredictorBase.
- device: tfaip.device.device_config.DeviceConfigParams
- silent: bool = False
- progress_bar: bool = True
- run_eagerly: bool = False
- include_targets: bool = False
- include_meta: bool = False
- __init__(device: tfaip.device.device_config.DeviceConfigParams = <factory>, pipeline: tfaip.data.databaseparams.DataPipelineParams = <factory>, silent: bool = False, progress_bar: bool = True, run_eagerly: bool = False, include_targets: bool = False, include_meta: bool = False) None
- classmethod from_dict(kvs: Optional[Union[dict, list, str, int, float, bool]], *, infer_missing=False) dataclasses_json.api.A
- classmethod from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) dataclasses_json.api.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[dataclasses_json.mm.A]
- to_dict(encode_json=False, include_cls=True) 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
Predictor
Definition of the Predictor
- class tfaip.predict.predictor.Predictor(params: tfaip.predict.params.PredictorParams, data: DataBase, **kwargs)
Bases:
tfaip.predict.predictorbase.PredictorBasePredictor that applies a single model on data. This is the most common case.
For usage either call Scenario.create_predictor or instantiate the Predictor directly and then call set_model.
- set_model(model: Union[str, keras.engine.training.Model])
- property model
MultiModelPredictor
Definition of the MultiModelPredictor
- class tfaip.predict.multimodelpredictor.MultiModelPredictor(params: tfaip.predict.params.PredictorParams, data: DataBase, **kwargs)
Bases:
tfaip.predict.predictorbase.PredictorBaseThe MultiModelPredictor supports to apply multiple models on the same data and then apply a MultiModelVoter to fuse their results into one.
Create either with Scenario.create_multi_predictor or MultiModelPredictor.from_paths.
To use a MultiModelPredictor the create_voter method must be implemented that defines how to vote the multiple individual results. Note that the pre processing pipeline of all predictors must be identical. The post_processing pipeline of the provided data will be applied
See also
PredictorBase
- classmethod from_paths(paths: List[str], params: tfaip.predict.params.PredictorParams, scenario: Type[ScenarioBase], use_first_params=False, model_paths: List[str] = None, models: List[keras.engine.training.Model] = None, predictor_args=None) MultiModelPredictor
Create a MultiModePredictor. The data of the first model (in paths) will be used as the defining scenario and data (i.e. the post-processing). All data pre-procs must be identical.
- Parameters
paths – paths to the scenario_params (see ScenarioBase.params_from_path)
params – PredictorParams
scenario – Type of the ScenarioBase
use_first_params – Only False is supported ATM.
model_paths – Paths to the actual models saved dirs (optional), by default based on paths
models – Already instantiated models (optional), by default created based on paths
predictor_args – Additional args for instantiating the Predictor (that are not part of PredictorParams)
- Returns
An instantiated and ready to use MultiModelPredictor
- __init__(params: tfaip.predict.params.PredictorParams, data: DataBase, **kwargs)
- abstract create_voter(data_params: tfaip.data.databaseparams.DataBaseParams) tfaip.predict.multimodelvoter.MultiModelVoter
- set_models(models: List[Union[str, keras.engine.training.Model]], datas: List[DataBase])
- property datas: List[DataBase]
- predict_pipeline(pipeline: tfaip.data.pipeline.datapipeline.DataPipeline) Iterable[tfaip.data.pipeline.definitions.Sample]
Predict a instantiated DataPipeline which is used for data generation, pre- and post-processing.
- Parameters
pipeline – the DataPipeline
- Returns
The preprocessed samples
See also
predict_dataset
predict_raw
predict