classify#

Shared image classification inference for pretrained detector models.

Functions#

predict_classes(→ dict[Any, str | None])

Predict one class label for each image in an ImageSet.

Module Contents#

openplaces.io.enricher.detectors.classify.predict_classes(images: openplaces.io.scrapers.types.ImageSet, model_path: str | pathlib.Path, classes: list[str], batch_size: int = 32, device: str | None = None, verbose: bool = True, checkpoint: openplaces.io.enricher.detectors.checkpoint.PredictionCheckpoint | None = None) dict[Any, str | None]#

Predict one class label for each image in an ImageSet.

Parameters:
  • images – Image collection with dir_path and images entries.

  • model_path – Path to a serialized full PyTorch model checkpoint.

  • classes – Class labels in the order used by the model output layer.

  • batch_size – Number of images per forward pass. Within a batch, tensors are grouped by shape (the aspect-preserving resize can yield varying shapes), so per-image preprocessing is identical to unbatched inference.

  • device – Device override (e.g. ‘cpu’); defaults to the best available device from get_device.

  • verbose – Print the image count and show a progress bar.

  • checkpoint – When given, previously checkpointed predictions are reused, new ones are persisted periodically, and an interrupted run resumes where it left off.

Returns:

Mapping from image keys to predicted class labels. Missing, unsupported, or unreadable image files are mapped to None.

Return type:

dict