Skip to content

Commit

Permalink
📋 Add documentation for Anomaly, Classification, and Segmentation (#228)
Browse files Browse the repository at this point in the history
* Add documentation

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>

* Update section header

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>

---------

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
  • Loading branch information
ashwinvaidya17 authored Nov 6, 2024
1 parent 5000bb6 commit 4cc192d
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/source/cpp/models/anomaly_model.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/source/python/models/anomaly.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
17 changes: 17 additions & 0 deletions docs/source/python/models/classification.md
Original file line number Diff line number Diff line change
@@ -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.

## 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:
Expand Down
15 changes: 15 additions & 0 deletions docs/source/python/models/segmentation.md
Original file line number Diff line number Diff line change
@@ -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.

## 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:
Expand Down
34 changes: 34 additions & 0 deletions model_api/python/model_api/models/anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
21 changes: 21 additions & 0 deletions model_api/python/model_api/models/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 18 additions & 0 deletions model_api/python/model_api/models/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4cc192d

Please sign in to comment.