alibi_detect.utils.tensorflow.prediction module
- alibi_detect.utils.tensorflow.prediction.get_call_arg_mapping(model, x)[source]
Generates a dictionary mapping the first argument name of the call method of a Keras model to the provided input value.
This function is particularly useful when working with Keras 3, which enforces stricter input handling and requires named arguments for certain operations. It extracts the argument names from the call method of the provided model and maps the first argument to x.
- alibi_detect.utils.tensorflow.prediction.predict_batch(x, model, batch_size=10000000000, preprocess_fn=None, dtype=<class 'numpy.float32'>)[source]
Make batch predictions on a model.
- Parameters:
model (
Union
[Callable
,Model
]) – tf.keras model or one of the other permitted types defined in Data.batch_size (
int
) – Batch size used during prediction.preprocess_fn (
Optional
[Callable
]) – Optional preprocessing function for each batch.dtype (
Union
[Type
[generic
],DType
]) – Model output type, e.g. np.float32 or tf.float32.
- Return type:
- Returns:
Numpy array, tensorflow tensor or tuples of those with model outputs.
- alibi_detect.utils.tensorflow.prediction.predict_batch_transformer(x, model, tokenizer, max_len, batch_size=10000000000, dtype=<class 'numpy.float32'>)[source]
Make batch predictions using a transformers tokenizer and model.
- Parameters:
- Return type:
Union
[ndarray
,Tensor
]- Returns:
Numpy array or tensorflow tensor with model outputs.