dataeval.utils.onnx.to_encoding_model¶
-
dataeval.utils.onnx.to_encoding_model(model_path: str | pathlib.Path, output_path: None =
None, embedding_layer: str | None =None) tuple[bytes, str]¶ -
dataeval.utils.onnx.to_encoding_model(model_path: str | pathlib.Path, output_path: str | pathlib.Path, embedding_layer: str | None =
None) tuple[str, str] Modify an ONNX model to output embeddings from an intermediate layer.
This function modifies a classification model to expose an intermediate layer as an additional output, allowing extraction of embeddings instead of (or in addition to) classification logits.
- Parameters:¶
- model_path : str or Path¶
Path to the original ONNX model file.
- output_path : str, Path, or None, default None¶
Path where the modified model will be saved. If None, returns serialized model bytes instead of writing to disk.
- embedding_layer : str or None, default None¶
Name of the layer to expose as output. If None, automatically detected using
find_embedding_layer().
- Returns:¶
If output_path is None: (model_bytes, layer_name) If output_path is provided: (output_path, layer_name)
- Return type:¶
tuple[bytes, str] or tuple[str, str]
- Raises:¶
ImportError – If the onnx package is not installed.
ValueError – If the embedding layer cannot be identified (when embedding_layer is None).