tfaip.predict¶
PredictorBase¶
Definition of the PredictorBase
-
class
tfaip.predict.predictorbase.PredictorBenchmarkResults(n_batches: float = 0, n_samples: float = 0, total_time: float = 1e-10, avg_time_per_batch: float = 0, avg_time_per_sample: float = 0, batches_per_second: float = 0, samples_per_second: float = 0)¶ Bases:
objectClass storing the benchmark of a full prediction
Use pretty_print to print a formatted table of the full results.
-
n_batches: float = 0¶
-
n_samples: float = 0¶
-
total_time: float = 1e-10¶
-
avg_time_per_batch: float = 0¶
-
avg_time_per_sample: float = 0¶
-
batches_per_second: float = 0¶
-
samples_per_second: float = 0¶
-
pretty_print()¶
-
__init__(n_batches: float = 0, n_samples: float = 0, total_time: float = 1e-10, avg_time_per_batch: float = 0, avg_time_per_sample: float = 0, batches_per_second: float = 0, samples_per_second: float = 0) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
-
class
tfaip.predict.predictorbase.PredictorBase(params: tfaip.predict.params.PredictorParams, data: DataBase)¶ 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)¶ Initialize self. See help(type(self)) for accurate signature.
-
property
params¶
-
property
data¶
-
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
-
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)¶
-
classmethod
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¶ 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¶
-
Predictor¶
Definition of the Predictor
-
class
tfaip.predict.predictor.Predictor(params: tfaip.predict.params.PredictorParams, data: DataBase)¶ 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, tensorflow.python.keras.engine.training.Model])¶
-
property
model¶
-
MultiModelPredictor¶
Definition of the MultiModelPredictor
-
class
tfaip.predict.multimodelpredictor.MultiModelVoter¶ Bases:
abc.ABCClass that defines how to vote a Sample produced by multiple predictors (MultiModelPredictor)
-
abstract
vote(sample: tfaip.data.pipeline.definitions.Sample) → tfaip.data.pipeline.definitions.Sample¶ Vote a sample
- Parameters
sample – The multi-sample (sample.outputs is a list of individual predictions)
- Returns
A normal sample with the expected structure of sample.outputs
-
abstract
-
class
tfaip.predict.multimodelpredictor.MultiModelPredictor(params: tfaip.predict.params.PredictorParams, data: DataBase)¶ 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[tensorflow.python.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 supportet 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 Predictior (that are not part of PredictorParams)
- Returns
An instantiated and ready to use MultiModelPredictor
-
__init__(params: tfaip.predict.params.PredictorParams, data: DataBase)¶ Initialize self. See help(type(self)) for accurate signature.
-
abstract
create_voter(data_params: DataBaseParams) → tfaip.predict.multimodelpredictor.MultiModelVoter¶
-
set_models(models: List[Union[str, tensorflow.python.keras.engine.training.Model]], datas: List[DataBase])¶
-
property
datas¶
-
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
-
classmethod