alibi_detect.saving.registry module

This registry allows Python objects to be registered and accessed by their string reference later on. The primary usage is to register objects so that they can be specified in a config.toml file. A number of Alibi Detect functions are also pre-registered in the registry for convenience. See the Registering artefacts # noqa: E501 documentation.

Examples

Registering a simple function using the @registry.register decorator, and immediately fetching it:

import numpy as np
from alibi_detect.saving import registry

# Register a simple function
@registry.register('my_function.v1')
def my_function(x: np.ndarray) -> np.ndarray:
    "A custom function to normalise input data."
    return (x - x.mean()) / x.std()

# Get function from registry
fetched_function = registry.get('my_function.v1')

Instead of using a decorator, objects can also be registered by directly using the registry.register() function:

from alibi_detect.saving import registry

my_object = ...
registry.register("my_object.v1", func=my_object)