zea.models.preset_utils

Mostly from keras_hub.src.models import preset_utils

Functions

builtin_presets(cls)

Find all registered built-in presets for a class.

check_config_class(config)

Validate a preset is being loaded on the correct class.

check_file_exists(preset, path)

Check if a file exists in a preset.

get_file(preset, path)

Download a preset file in necessary and return the local path.

get_preset_loader(preset)

Get a preset loader.

get_preset_saver(preset)

Get a preset saver.

jax_memory_cleanup(layer)

Cleanup memory for JAX models.

keras_to_zea_registry(keras_name, zea_registry)

Convert a Keras class name to a zea registry name.

load_json(preset[, config_file])

Load a JSON file from a preset.

load_serialized_object(config, **kwargs)

Load a serialized Keras object from a config.

register_presets(presets, model_cls)

Register built-in presets for a set of classes.

set_dtype_in_config(config[, dtype])

Set the dtype in a serialized Keras config.

Classes

KerasPresetLoader(preset, config)

Loader for Keras serialized presets.

KerasPresetSaver(preset_dir)

Saver for Keras serialized presets.

PresetLoader(preset, config)

Base class for loading a model from a preset.

class zea.models.preset_utils.KerasPresetLoader(preset, config)[source]

Bases: PresetLoader

Loader for Keras serialized presets.

check_model_class()[source]

Check the model class is correct for the preset.

get_file(path)[source]

Get a file from the preset.

load_image_converter(cls, **kwargs)[source]

Load an image converter from the preset.

load_model(cls, load_weights, **kwargs)[source]

Load a model from a serialized Keras config.

load_preprocessor(cls, config_file='preprocessor.json', **kwargs)[source]

Load a preprocessor from the preset.

class zea.models.preset_utils.KerasPresetSaver(preset_dir)[source]

Bases: object

Saver for Keras serialized presets.

save_image_converter(converter)[source]

Save an image converter to a preset.

save_model(model)[source]

Save a model to a preset.

save_preprocessor(preprocessor)[source]

Save a preprocessor to a preset.

class zea.models.preset_utils.PresetLoader(preset, config)[source]

Bases: object

Base class for loading a model from a preset.

get_model_kwargs(**kwargs)[source]

Extract model kwargs from the preset.

load_model(cls, load_weights, **kwargs)[source]

Load the backbone model from the preset.

load_preprocessor(cls, config_file='preprocessor.json', **kwargs)[source]

Load a prepocessor layer from the preset.

zea.models.preset_utils.builtin_presets(cls)[source]

Find all registered built-in presets for a class.

zea.models.preset_utils.check_config_class(config)[source]

Validate a preset is being loaded on the correct class.

zea.models.preset_utils.check_file_exists(preset, path)[source]

Check if a file exists in a preset.

zea.models.preset_utils.get_file(preset, path)[source]

Download a preset file in necessary and return the local path.

zea.models.preset_utils.get_preset_loader(preset)[source]

Get a preset loader.

zea.models.preset_utils.get_preset_saver(preset)[source]

Get a preset saver.

zea.models.preset_utils.jax_memory_cleanup(layer)[source]

Cleanup memory for JAX models.

zea.models.preset_utils.keras_to_zea_registry(keras_name, zea_registry)[source]

Convert a Keras class name to a zea registry name.

zea.models.preset_utils.load_json(preset, config_file='config.json')[source]

Load a JSON file from a preset.

zea.models.preset_utils.load_serialized_object(config, **kwargs)[source]

Load a serialized Keras object from a config.

zea.models.preset_utils.register_presets(presets, model_cls)[source]

Register built-in presets for a set of classes.

Note that this is intended only for models and presets shipped in the library itself.

zea.models.preset_utils.set_dtype_in_config(config, dtype=None)[source]

Set the dtype in a serialized Keras config.