vertebrae.extractors.keras

Optional Keras module extractor for local user-supplied models.

Classes

KerasExtractor

Wrap a locally loaded Keras model as a feature extractor.

Module Contents

class vertebrae.extractors.keras.KerasExtractor(name, model, collate_fn=None, output_fn=None, outputs=None, call_method='call', call_kwargs=None, predict_kwargs=None, modality='unknown', extractor_type='custom_keras', recipe_data=None, allow_sparse=False, streaming_safe=True, spatial_output_fn=None, spatial_output_specs=None, structured_output_fn=None, structured_output_specs=None, checkpoint_paths=None, profiling_device=None, cache_identity=None)[source]

Wrap a locally loaded Keras model as a feature extractor.

Parameters:
  • name (str) – User-facing extractor name.

  • model (Any) – A locally loaded Keras model or compatible callable object.

  • collate_fn (Optional[Callable[[Any], Any]]) – Callable that converts raw inputs into model inputs.

  • output_fn (Optional[Callable[[Any], Any]]) – Optional callable that converts raw model output into embeddings.

  • outputs (Optional[Sequence[Dict[str, Any]]]) – Optional named ordinary embedding-output declarations.

  • call_method (str) – Whether to use model(...) or model.predict(...).

  • call_kwargs (Optional[Dict[str, Any]]) – Extra keyword arguments passed when call_method="call".

  • predict_kwargs (Optional[Dict[str, Any]]) – Extra keyword arguments passed when call_method="predict".

  • modality (str) – Input modality metadata.

  • extractor_type (str) – Extractor family metadata.

  • recipe_data (Optional[Dict[str, Any]]) – Extra serializable metadata for reproducibility.

  • allow_sparse (bool) – Whether sparse embedding outputs are accepted.

  • streaming_safe (bool) – Whether independent batches can be embedded without full-context state.

  • spatial_output_fn (Optional[Callable[[Any], Any]])

  • spatial_output_specs (Optional[Iterable[vertebrae.extractors.spatial.SpatialOutputSpec]])

  • structured_output_fn (Optional[Callable[[Any], Any]])

  • structured_output_specs (Optional[Iterable[vertebrae.extractors.structured.StructuredOutputSpec]])

  • checkpoint_paths (Optional[Iterable[str]])

  • profiling_device (Optional[str])

  • cache_identity (Optional[str])

get_resource_profile_adapter()[source]

Return Keras-specific model-footprint hooks.

Return type:

Any

fit(X, y=None)[source]

No-op fit for local Keras models.

Parameters:
  • X (Any)

  • y (Any)

Return type:

KerasExtractor

transform(X)[source]

Apply the collate function, run the model, and validate embeddings.

Parameters:

X (Any)

Return type:

numpy.ndarray

output_specs()[source]

Return the declared ordinary embedding outputs.

Return type:

List[vertebrae.extractors.base.EmbeddingOutputSpec]

transform_many(X)[source]

Apply the model once and materialize every declared embedding output.

Parameters:

X (Any)

Return type:

List[vertebrae.extractors.base.EmbeddingOutput]

fit_transform(X, y=None)[source]

Fit the extractor and transform inputs.

Parameters:
  • X (Any)

  • y (Any)

Return type:

numpy.ndarray

recipe()[source]

Return a serializable recipe for this extractor.

Return type:

Dict[str, Any]