JATICImageClassifier
- class xaitk_jatic.interop.image_classification.model.JATICImageClassifier(classifier: Model, ids: Sequence[int], img_batch_size: int = 1)
Adapter for the JATIC image classification protocol, implementing the SMQTK ClassifyImage interface.
This adapter allows a JATIC protocol-based classifier to be used in SMQTK pipelines by transforming classification outputs into the expected format.
- Attributes:
_classifier (ic.Model): The JATIC protocol-based image classifier instance. _ids (dict[int, Hashable]): A dictionary mapping label IDs to human-readable names. _img_batch_size (int): The number of images to process in a single batch.
- Methods:
get_labels: Retrieve the human-readable class labels. classify_images: Perform classification on a batch of input images. get_config: Raise a NotImplementedError for serialization (not yet supported).
Methods
Classify an input iterable of images, in the form of np.ndarray matricies into a parallel iterable of label-to-confidence mappings (dictionaries).
from_configInstantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.
Return a JSON-compliant dictionary that could be passed to this class's
from_configmethod to produce an instance with identical configuration.get_default_configGenerate and return a default configuration dictionary for this class.
get_implsDiscover and return a set of classes that implement the calling class.
Get the sequence of class labels that this classifier can classify images into.
is_usableCheck whether this class is available for use.
- __init__(classifier: Model, ids: Sequence[int], img_batch_size: int = 1) None
Initialize the JATICImageClassifier with a JATIC protocol-based classifier.
- Args:
classifier (ic.Model): The JATIC protocol-based image classification model. ids (dict[int, Hashable]): A dictionary mapping label IDs to human-readable names. img_batch_size (int, optional): The number of images to process in a single batch. Defaults to 1.
- classify_images(img_iter: ndarray | Iterable[ndarray]) Iterator[Dict[Any, float]]
Classify an input iterable of images, in the form of np.ndarray matricies into a parallel iterable of label-to-confidence mappings (dictionaries).
We expect input image matrices to come in either the [H, W] or [H, W, C] dimension formats.
Each classification mapping should contain confidence values for each label the configured model contains. Implementations may act in a discrete manner whereby only one label is marked with a
1value (others being0), or in a continuous manner whereby each label is given a confidence-like value in the [0, 1] range.- Parameters:
array_iter – Iterable of images, as numpy arrays, to be classified.
- Raises:
ValueError – Input arrays were not all of consistent dimensionality.
- Returns:
Iterator of dictionaries, parallel in association to the input images. Each dictionary should map labels to associated confidence values.
- get_config() dict
Return a JSON-compliant dictionary that could be passed to this class’s
from_configmethod to produce an instance with identical configuration.In the most cases, this involves naming the keys of the dictionary based on the initialization argument names as if it were to be passed to the constructor via dictionary expansion. In some cases, where it doesn’t make sense to store some object constructor parameters are expected to be supplied at as configuration values (i.e. must be supplied at runtime), this method’s returned dictionary may leave those parameters out. In such cases, the object’s
from_configclass-method would also take additional positional arguments to fill in for the parameters that this returned configuration lacks.- Returns:
JSON type compliant configuration dictionary.
- Return type:
dict
- get_labels() Sequence[Hashable]
Get the sequence of class labels that this classifier can classify images into. This includes the negative or background label if the classifier embodies such a concept.
- Returns:
Sequence of possible classifier labels.
- Raises:
RuntimeError – No model loaded.