From 4cf9782fcfb79f8a87518748a49aa4904865d107 Mon Sep 17 00:00:00 2001 From: Ashwin Vaidya Date: Wed, 6 Nov 2024 11:04:23 +0100 Subject: [PATCH 1/2] Add documentation Signed-off-by: Ashwin Vaidya --- docs/source/cpp/models/anomaly_model.md | 7 ++++ docs/source/python/models/anomaly.md | 7 ++++ docs/source/python/models/classification.md | 17 ++++++++++ docs/source/python/models/segmentation.md | 15 ++++++++ model_api/python/model_api/models/anomaly.py | 34 +++++++++++++++++++ .../python/model_api/models/classification.py | 21 ++++++++++++ .../python/model_api/models/segmentation.py | 18 ++++++++++ 7 files changed, 119 insertions(+) diff --git a/docs/source/cpp/models/anomaly_model.md b/docs/source/cpp/models/anomaly_model.md index 62c057d2..aecc60bb 100644 --- a/docs/source/cpp/models/anomaly_model.md +++ b/docs/source/cpp/models/anomaly_model.md @@ -1,5 +1,12 @@ # Anomaly Model +The `AnomalyModel` is a generic OpenVINO model that aims to provide a single interface for all the exported models based on [Anomalib](https://github.com/openvinotoolkit/anomalib). + +Currently, the `AnomalyModel` supports the following models: + +- Padim +- STFPM + ```{eval-rst} .. doxygenclass:: AnomalyModel diff --git a/docs/source/python/models/anomaly.md b/docs/source/python/models/anomaly.md index c3b4fb6f..64683fe0 100644 --- a/docs/source/python/models/anomaly.md +++ b/docs/source/python/models/anomaly.md @@ -1,5 +1,12 @@ # Anomaly +The `AnomalyModel` is a generic OpenVINO model that aims to provide a single interface for all the exported models based on [Anomalib](https://github.com/openvinotoolkit/anomalib). + +Currently, the `AnomalyModel` supports the following models: + +- Padim +- STFPM + ```{eval-rst} .. automodule:: model_api.models.anomaly :members: diff --git a/docs/source/python/models/classification.md b/docs/source/python/models/classification.md index 62f577e4..8ccd6ce8 100644 --- a/docs/source/python/models/classification.md +++ b/docs/source/python/models/classification.md @@ -1,5 +1,22 @@ # Classification +## Description + +The `ClassificationModel` is the OpenVINO wrapper for models exported from [OpenVINO Training Extensions](https://github.com/openvinotoolkit/training_extensions). It supports multi-label classification as well as hierarchical classification. + +## OpenVINO Model Specifications + +## Inputs + +A single input image of shape (H, W, 3) where H and W are the height and width of the image, respectively. + +## Outputs + +- `top_labels`: List of tuples containing the top labels of the classification model. +- `saliency_map`: Saliency map of the input image. +- `feature_vector`: Feature vector of the input image. This is useful for Active Learning. +- `raw_scores`: Raw scores of the classification model. + ```{eval-rst} .. automodule:: model_api.models.classification :members: diff --git a/docs/source/python/models/segmentation.md b/docs/source/python/models/segmentation.md index ef6c36c5..a1f15301 100644 --- a/docs/source/python/models/segmentation.md +++ b/docs/source/python/models/segmentation.md @@ -1,5 +1,20 @@ # Segmentation +The `SegmentationModel` is the OpenVINO wrapper for models exported from [OpenVINO Training Extensions](https://github.com/openvinotoolkit/training_extensions). It produces a segmentation mask for the input image. + +## OpenVINO Model Specifications + +### Inputs + +A single input image of shape (H, W, 3) where H and W are the height and width of the image, respectively. + +### Outputs + +- `resultImage`: Image with the segmentation mask. +- `soft_prediction`: Soft prediction of the segmentation model. +- `saliency_map`: Saliency map of the input image. +- `feature_vector`: Feature vector of the input image. This is useful for Active Learning. + ```{eval-rst} .. automodule:: model_api.models.segmentation :members: diff --git a/model_api/python/model_api/models/anomaly.py b/model_api/python/model_api/models/anomaly.py index a8529d89..b5ad9427 100644 --- a/model_api/python/model_api/models/anomaly.py +++ b/model_api/python/model_api/models/anomaly.py @@ -22,6 +22,40 @@ class AnomalyDetection(ImageModel): + """Anomaly Detection model. + + Generic anomaly detection model that acts as an inference wrapper for all the exported models from + Anomalib. + + Args: + inference_adapter (InferenceAdapter): Inference adapter + configuration (dict, optional): Configuration parameters. Defaults to {}. + preload (bool, optional): Whether to preload the model. Defaults to False. + + Example: + >>> from model_api.models import AnomalyDetection + >>> import cv2 + >>> model = AnomalyDetection.create_model("./path_to_model.xml") + >>> image = cv2.imread("path_to_image.jpg") + >>> result = model.predict(image) + AnomalyResult(anomaly_map=array([[150, 150, 150, ..., 138, 138, 138], + [150, 150, 150, ..., 138, 138, 138], + [150, 150, 150, ..., 138, 138, 138], + ..., + [134, 134, 134, ..., 138, 138, 138], + [134, 134, 134, ..., 138, 138, 138], + [134, 134, 134, ..., 138, 138, 138]], dtype=uint8), + pred_boxes=None, pred_label='Anomaly', + pred_mask=array([[1, 1, 1, ..., 1, 1, 1], + [1, 1, 1, ..., 1, 1, 1], + [1, 1, 1, ..., 1, 1, 1], + ..., + [1, 1, 1, ..., 1, 1, 1], + [1, 1, 1, ..., 1, 1, 1], + [1, 1, 1, ..., 1, 1, 1]], dtype=uint8), + pred_score=0.8536462108391619) + """ + __model__ = "AnomalyDetection" def __init__( diff --git a/model_api/python/model_api/models/classification.py b/model_api/python/model_api/models/classification.py index a3f2eb80..d238b614 100644 --- a/model_api/python/model_api/models/classification.py +++ b/model_api/python/model_api/models/classification.py @@ -23,6 +23,27 @@ class ClassificationModel(ImageModel): + """Classification Model. + + Args: + inference_adapter (InferenceAdapter): Inference adapter + configuration (dict, optional): Configuration parameters. Defaults to {}. + preload (bool, optional): Whether to preload the model. Defaults to False. + + Example: + >>> from model_api.models import ClassificationModel + >>> import cv2 + >>> model = ClassificationModel.create_model("./path_to_model.xml") + >>> image = cv2.imread("path_to_image.jpg") + >>> result = model.predict(image) + ClassificationResult( + top_labels=[(1, 'bicycle', 0.90176445), (6, 'car', 0.85433626), (7, 'cat', 0.60699755)], + saliency_map=array([], dtype=float64), + feature_vector=array([], dtype=float64), + raw_scores=array([], dtype=float64) + ) + """ + __model__ = "Classification" def __init__(self, inference_adapter: InferenceAdapter, configuration: dict = {}, preload: bool = False): diff --git a/model_api/python/model_api/models/segmentation.py b/model_api/python/model_api/models/segmentation.py index 5056b95c..fdd88764 100644 --- a/model_api/python/model_api/models/segmentation.py +++ b/model_api/python/model_api/models/segmentation.py @@ -49,6 +49,24 @@ def create_hard_prediction_from_soft_prediction( class SegmentationModel(ImageModel): + """Segmentation Model. + + Args: + inference_adapter (InferenceAdapter): Inference adapter + configuration (dict, optional): Configuration parameters. Defaults to {}. + preload (bool, optional): Whether to preload the model. Defaults to False. + + Example: + >>> from model_api.models import SegmentationModel + >>> import cv2 + >>> model = SegmentationModel.create_model("./path_to_model.xml") + >>> image = cv2.imread("path_to_image.jpg") + >>> result = model.predict(image) + ImageResultWithSoftPrediction( + ... + ) + """ + __model__ = "Segmentation" def __init__(self, inference_adapter, configuration: dict = {}, preload=False): From e968404246b0a8c22b06471bff96af5a74379237 Mon Sep 17 00:00:00 2001 From: Ashwin Vaidya Date: Wed, 6 Nov 2024 14:17:35 +0100 Subject: [PATCH 2/2] Update section header Signed-off-by: Ashwin Vaidya --- docs/source/python/models/classification.md | 2 +- docs/source/python/models/segmentation.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/python/models/classification.md b/docs/source/python/models/classification.md index 8ccd6ce8..f0a71ffc 100644 --- a/docs/source/python/models/classification.md +++ b/docs/source/python/models/classification.md @@ -4,7 +4,7 @@ The `ClassificationModel` is the OpenVINO wrapper for models exported from [OpenVINO Training Extensions](https://github.com/openvinotoolkit/training_extensions). It supports multi-label classification as well as hierarchical classification. -## OpenVINO Model Specifications +## Model Specifications ## Inputs diff --git a/docs/source/python/models/segmentation.md b/docs/source/python/models/segmentation.md index a1f15301..53149c4f 100644 --- a/docs/source/python/models/segmentation.md +++ b/docs/source/python/models/segmentation.md @@ -2,7 +2,7 @@ The `SegmentationModel` is the OpenVINO wrapper for models exported from [OpenVINO Training Extensions](https://github.com/openvinotoolkit/training_extensions). It produces a segmentation mask for the input image. -## OpenVINO Model Specifications +## Model Specifications ### Inputs