imgutils.generic.classify

Overview:

Generic tools for classification models.

ClassifyModel

class imgutils.generic.classify.ClassifyModel(repo_id: str)[source]

Class for managing classification models.

This class provides methods for loading classification models, predicting scores, and predictions.

Methods:

predict_score: Predicts the scores for each class. predict: Predicts the class with the highest score. clear: Clears the loaded models and labels.

Attributes:

None

__init__(repo_id: str)[source]

Initialize the ClassifyModel instance.

Parameters:

repo_id (str) – The repository ID containing the models.

clear()[source]

Clear the loaded models and labels.

predict(image: str | PathLike | bytes | bytearray | BinaryIO | Image, model_name: str) Tuple[str, float][source]

Predict the class with the highest score.

Parameters:
  • image (ImageTyping) – The input image.

  • model_name (str) – The name of the model.

Returns:

The predicted class and its score.

Return type:

Tuple[str, float]

predict_score(image: str | PathLike | bytes | bytearray | BinaryIO | Image, model_name: str) Dict[str, float][source]

Predict the scores for each class.

Parameters:
  • image (ImageTyping) – The input image.

  • model_name (str) – The name of the model.

Returns:

The dictionary containing class scores.

Return type:

Dict[str, float]

classify_predict_score

imgutils.generic.classify.classify_predict_score(image: str | PathLike | bytes | bytearray | BinaryIO | Image, repo_id: str, model_name: str) Dict[str, float][source]

Predict the scores for each class using the specified model.

Parameters:
  • image (ImageTyping) – The input image.

  • repo_id (str) – The repository ID containing the models.

  • model_name (str) – The name of the model.

Returns:

The dictionary containing class scores.

Return type:

Dict[str, float]

classify_predict

imgutils.generic.classify.classify_predict(image: str | PathLike | bytes | bytearray | BinaryIO | Image, repo_id: str, model_name: str) Tuple[str, float][source]

Predict the class with the highest score using the specified model.

Parameters:
  • image (ImageTyping) – The input image.

  • repo_id (str) – The repository ID containing the models.

  • model_name (str) – The name of the model.

Returns:

The predicted class and its score.

Return type:

Tuple[str, float]