Skip to content

Commit 4cc192d

Browse files
📋 Add documentation for Anomaly, Classification, and Segmentation (#228)
* Add documentation Signed-off-by: Ashwin Vaidya <[email protected]> * Update section header Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent 5000bb6 commit 4cc192d

File tree

7 files changed

+119
-0
lines changed

7 files changed

+119
-0
lines changed

docs/source/cpp/models/anomaly_model.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Anomaly Model
22

3+
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).
4+
5+
Currently, the `AnomalyModel` supports the following models:
6+
7+
- Padim
8+
- STFPM
9+
310
```{eval-rst}
411
.. doxygenclass:: AnomalyModel
512

docs/source/python/models/anomaly.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Anomaly
22

3+
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).
4+
5+
Currently, the `AnomalyModel` supports the following models:
6+
7+
- Padim
8+
- STFPM
9+
310
```{eval-rst}
411
.. automodule:: model_api.models.anomaly
512
:members:

docs/source/python/models/classification.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Classification
22

3+
## Description
4+
5+
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.
6+
7+
## Model Specifications
8+
9+
## Inputs
10+
11+
A single input image of shape (H, W, 3) where H and W are the height and width of the image, respectively.
12+
13+
## Outputs
14+
15+
- `top_labels`: List of tuples containing the top labels of the classification model.
16+
- `saliency_map`: Saliency map of the input image.
17+
- `feature_vector`: Feature vector of the input image. This is useful for Active Learning.
18+
- `raw_scores`: Raw scores of the classification model.
19+
320
```{eval-rst}
421
.. automodule:: model_api.models.classification
522
:members:

docs/source/python/models/segmentation.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Segmentation
22

3+
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.
4+
5+
## Model Specifications
6+
7+
### Inputs
8+
9+
A single input image of shape (H, W, 3) where H and W are the height and width of the image, respectively.
10+
11+
### Outputs
12+
13+
- `resultImage`: Image with the segmentation mask.
14+
- `soft_prediction`: Soft prediction of the segmentation model.
15+
- `saliency_map`: Saliency map of the input image.
16+
- `feature_vector`: Feature vector of the input image. This is useful for Active Learning.
17+
318
```{eval-rst}
419
.. automodule:: model_api.models.segmentation
520
:members:

model_api/python/model_api/models/anomaly.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,40 @@
2222

2323

2424
class AnomalyDetection(ImageModel):
25+
"""Anomaly Detection model.
26+
27+
Generic anomaly detection model that acts as an inference wrapper for all the exported models from
28+
Anomalib.
29+
30+
Args:
31+
inference_adapter (InferenceAdapter): Inference adapter
32+
configuration (dict, optional): Configuration parameters. Defaults to {}.
33+
preload (bool, optional): Whether to preload the model. Defaults to False.
34+
35+
Example:
36+
>>> from model_api.models import AnomalyDetection
37+
>>> import cv2
38+
>>> model = AnomalyDetection.create_model("./path_to_model.xml")
39+
>>> image = cv2.imread("path_to_image.jpg")
40+
>>> result = model.predict(image)
41+
AnomalyResult(anomaly_map=array([[150, 150, 150, ..., 138, 138, 138],
42+
[150, 150, 150, ..., 138, 138, 138],
43+
[150, 150, 150, ..., 138, 138, 138],
44+
...,
45+
[134, 134, 134, ..., 138, 138, 138],
46+
[134, 134, 134, ..., 138, 138, 138],
47+
[134, 134, 134, ..., 138, 138, 138]], dtype=uint8),
48+
pred_boxes=None, pred_label='Anomaly',
49+
pred_mask=array([[1, 1, 1, ..., 1, 1, 1],
50+
[1, 1, 1, ..., 1, 1, 1],
51+
[1, 1, 1, ..., 1, 1, 1],
52+
...,
53+
[1, 1, 1, ..., 1, 1, 1],
54+
[1, 1, 1, ..., 1, 1, 1],
55+
[1, 1, 1, ..., 1, 1, 1]], dtype=uint8),
56+
pred_score=0.8536462108391619)
57+
"""
58+
2559
__model__ = "AnomalyDetection"
2660

2761
def __init__(

model_api/python/model_api/models/classification.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@
2323

2424

2525
class ClassificationModel(ImageModel):
26+
"""Classification Model.
27+
28+
Args:
29+
inference_adapter (InferenceAdapter): Inference adapter
30+
configuration (dict, optional): Configuration parameters. Defaults to {}.
31+
preload (bool, optional): Whether to preload the model. Defaults to False.
32+
33+
Example:
34+
>>> from model_api.models import ClassificationModel
35+
>>> import cv2
36+
>>> model = ClassificationModel.create_model("./path_to_model.xml")
37+
>>> image = cv2.imread("path_to_image.jpg")
38+
>>> result = model.predict(image)
39+
ClassificationResult(
40+
top_labels=[(1, 'bicycle', 0.90176445), (6, 'car', 0.85433626), (7, 'cat', 0.60699755)],
41+
saliency_map=array([], dtype=float64),
42+
feature_vector=array([], dtype=float64),
43+
raw_scores=array([], dtype=float64)
44+
)
45+
"""
46+
2647
__model__ = "Classification"
2748

2849
def __init__(self, inference_adapter: InferenceAdapter, configuration: dict = {}, preload: bool = False):

model_api/python/model_api/models/segmentation.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ def create_hard_prediction_from_soft_prediction(
4949

5050

5151
class SegmentationModel(ImageModel):
52+
"""Segmentation Model.
53+
54+
Args:
55+
inference_adapter (InferenceAdapter): Inference adapter
56+
configuration (dict, optional): Configuration parameters. Defaults to {}.
57+
preload (bool, optional): Whether to preload the model. Defaults to False.
58+
59+
Example:
60+
>>> from model_api.models import SegmentationModel
61+
>>> import cv2
62+
>>> model = SegmentationModel.create_model("./path_to_model.xml")
63+
>>> image = cv2.imread("path_to_image.jpg")
64+
>>> result = model.predict(image)
65+
ImageResultWithSoftPrediction(
66+
...
67+
)
68+
"""
69+
5270
__model__ = "Segmentation"
5371

5472
def __init__(self, inference_adapter, configuration: dict = {}, preload=False):

0 commit comments

Comments
 (0)