Skip to content

Commit 0f1b97c

Browse files
committed
Merge remote-tracking branch 'origin/master' into vs/py_test_struct
2 parents 48be12d + 5830b62 commit 0f1b97c

27 files changed

+495
-308
lines changed

docs/source/python/models/detection_model.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
# Detection Model
22

3+
## Description
4+
5+
Detection model aims to detect objects in an image. The model outputs a list of detected objects, each containing a bounding box, score and class label.
6+
7+
## OpenVINO 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+
Detection model outputs a list of detection objects (i.e `list[Detection]`) wrapped in `DetectionResult`, each object containing the following attributes:
16+
17+
- `score` (float) - Confidence score of the object.
18+
- `id` (int) - Class label of the object.
19+
- `str_label` (str) - String label of the object.
20+
- `xmin` (int) - X-coordinate of the top-left corner of the bounding box.
21+
- `ymin` (int) - Y-coordinate of the top-left corner of the bounding box.
22+
- `xmax` (int) - X-coordinate of the bottom-right corner of the bounding box.
23+
- `ymax` (int) - Y-coordinate of the bottom-right corner of the bounding box.
24+
25+
## Example
26+
27+
```python
28+
import cv2
29+
from model_api.models import SSD
30+
31+
# Load the model
32+
model = SSD.create_model("model.xml")
33+
34+
# Forward pass
35+
predictions = model(image)
36+
37+
# Iterate over the segmented objects
38+
for pred_obj in predictions.objects:
39+
pred_score = pred_obj.score
40+
label_id = pred_obj.id
41+
bbox = [pred_obj.xmin, pred_obj.ymin, pred_obj.xmax, pred_obj.ymax]
42+
```
43+
344
```{eval-rst}
445
.. automodule:: model_api.models.detection_model
546
:members:

docs/source/python/models/instance_segmentation.md

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

3+
## Description
4+
5+
Instance segmentation model aims to detect and segment objects in an image. It is an extension of object detection, where each object is segmented into a separate mask. The model outputs a list of segmented objects, each containing a mask, bounding box, score and class label.
6+
7+
## OpenVINO 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+
Instance segmentation model outputs a list of segmented objects (i.e `list[SegmentedObject]`)wrapped in `InstanceSegmentationResult.segmentedObjects`, each containing the following attributes:
16+
17+
- `mask` (numpy.ndarray) - A binary mask of the object.
18+
- `score` (float) - Confidence score of the object.
19+
- `id` (int) - Class label of the object.
20+
- `str_label` (str) - String label of the object.
21+
- `xmin` (int) - X-coordinate of the top-left corner of the bounding box.
22+
- `ymin` (int) - Y-coordinate of the top-left corner of the bounding box.
23+
- `xmax` (int) - X-coordinate of the bottom-right corner of the bounding box.
24+
- `ymax` (int) - Y-coordinate of the bottom-right corner of the bounding box.
25+
26+
## Example
27+
28+
```python
29+
import cv2
30+
from model_api.models import MaskRCNNModel
31+
32+
# Load the model
33+
model = MaskRCNNModel.create_model("model.xml")
34+
35+
# Forward pass
36+
predictions = model(image)
37+
38+
# Iterate over the segmented objects
39+
for pred_obj in predictions.segmentedObjects:
40+
pred_mask = pred_obj.mask
41+
pred_score = pred_obj.score
42+
label_id = pred_obj.id
43+
bbox = [pred_obj.xmin, pred_obj.ymin, pred_obj.xmax, pred_obj.ymax]
44+
```
45+
346
```{eval-rst}
447
.. automodule:: model_api.models.instance_segmentation
548
:members:

docs/source/python/models/keypoint_detection.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
# Keypoint Detection
22

3+
## Description
4+
5+
Keypoint detection model aims to detect a set of pre-defined keypoints on a cropped object.
6+
If a crop is not tight enough, quality of keypoints degrades. Having this model and an
7+
object detector, one can organize keypoint detection for all objects of interest presented on an image (top-down approach).
8+
9+
## Models
10+
11+
Top-down keypoint detection pipeline uses detections that come from any appropriate detector,
12+
and a keypoints regression model acting on crops.
13+
14+
### Parameters
15+
16+
The following parameters can be provided via python API or RT Info embedded into OV model:
17+
18+
- `labels`(`list(str)`) : a list of keypoints names.
19+
20+
## OpenVINO Model Specifications
21+
22+
### Inputs
23+
24+
A single `NCHW` tensor representing a batch of images.
25+
26+
### Outputs
27+
28+
Two vectors in Simple Coordinate Classification Perspective ([SimCC](https://arxiv.org/abs/2107.03332)) format:
29+
30+
- `pred_x` (B, N, D1) - `x` coordinate representation, where `N` is the number of keypoints.
31+
- `pred_y` (B, N, D2) - `y` coordinate representation, where `N` is the number of keypoints.
32+
33+
## Example
34+
35+
```python
36+
import cv2
37+
from model_api.models import TopDownKeypointDetectionPipeline, Detection, KeypointDetectionModel
38+
39+
model = KeypointDetectionModel.create_model("kp_model.xml")
40+
# a list of detections in (x_min, y_min, x_max, y_max, score, class_id) format
41+
detections = [Detection(0, 0, 100, 100, 1.0, 0)]
42+
top_down_pipeline = TopDownKeypointDetectionPipeline(model)
43+
predictions = top_down_detector.predict(image, detections)
44+
45+
# iterating over a list of DetectedKeypoints. Each of the items corresponds to a detection
46+
for obj_keypoints in predictions:
47+
for point in obj_keypoints.keypoints.astype(np.int32):
48+
cv2.circle(
49+
image, point, radius=0, color=(0, 255, 0), thickness=5
50+
)
51+
```
52+
353
```{eval-rst}
454
.. automodule:: model_api.models.keypoint_detection
555
:members:

model_api/python/model_api/adapters/inference_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from abc import ABC, abstractmethod
77
from dataclasses import dataclass, field
8-
from typing import Any, Dict, List, Set, Tuple
8+
from typing import Any
99

1010

1111
@dataclass

model_api/python/model_api/adapters/openvino_adapter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def await_any(self) -> None:
301301
def _get_meta_from_ngraph(self, layers_info):
302302
for node in self.model.get_ordered_ops():
303303
layer_name = node.get_friendly_name()
304-
if layer_name not in layers_info.keys():
304+
if layer_name not in layers_info:
305305
continue
306306
layers_info[layer_name].meta = node.get_attributes()
307307
layers_info[layer_name].type = node.get_type_name()
@@ -339,9 +339,9 @@ def embed_preprocessing(
339339
ppp = PrePostProcessor(self.model)
340340

341341
# Change the input type to the 8-bit image
342-
if dtype == int:
342+
if dtype is int:
343343
ppp.input(input_idx).tensor().set_element_type(Type.u8)
344-
elif dtype == float:
344+
elif dtype is float:
345345
ppp.input(input_idx).tensor().set_element_type(Type.f32)
346346

347347
ppp.input(input_idx).tensor().set_layout(ov.Layout("NHWC")).set_color_format(

model_api/python/model_api/adapters/ovms_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def _verify_model_available(client, model_name, model_version):
185185
def _prepare_inputs(dict_data, inputs_meta):
186186
inputs = {}
187187
for input_name, input_data in dict_data.items():
188-
if input_name not in inputs_meta.keys():
188+
if input_name not in inputs_meta:
189189
raise ValueError("Input data does not match model inputs")
190190
input_info = inputs_meta[input_name]
191191
model_precision = _tf2np_precision[input_info["dtype"]]

model_api/python/model_api/adapters/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from __future__ import annotations # TODO: remove when Python3.9 support is dropped
77

88
import math
9+
from collections.abc import Callable
910
from functools import partial
10-
from typing import Callable, Optional
1111

1212
import cv2
1313
import numpy as np

model_api/python/model_api/models/__init__.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,26 @@
1111
from .instance_segmentation import MaskRCNNModel
1212
from .keypoint_detection import KeypointDetectionModel, TopDownKeypointDetectionPipeline
1313
from .model import Model
14-
from .sam_models import SAMDecoder, SAMImageEncoder
15-
from .segmentation import SalientObjectDetectionModel, SegmentationModel
16-
from .ssd import SSD
17-
from .utils import (
14+
from .result_types import (
1815
AnomalyResult,
1916
ClassificationResult,
2017
Contour,
2118
DetectedKeypoints,
2219
Detection,
2320
DetectionResult,
24-
DetectionWithLandmarks,
2521
ImageResultWithSoftPrediction,
2622
InstanceSegmentationResult,
27-
OutputTransform,
2823
PredictedMask,
2924
SegmentedObject,
3025
SegmentedObjectWithRects,
3126
VisualPromptingResult,
3227
ZSLVisualPromptingResult,
28+
)
29+
from .sam_models import SAMDecoder, SAMImageEncoder
30+
from .segmentation import SalientObjectDetectionModel, SegmentationModel
31+
from .ssd import SSD
32+
from .utils import (
33+
OutputTransform,
3334
add_rotated_rects,
3435
get_contours,
3536
)
@@ -62,8 +63,6 @@
6263
"ClassificationModel",
6364
"Contour",
6465
"DetectionModel",
65-
"DetectionWithLandmarks",
66-
"ImageMattingWithBackground",
6766
"ImageModel",
6867
"ImageResultWithSoftPrediction",
6968
"InstanceSegmentationResult",
@@ -77,11 +76,9 @@
7776
"MaskRCNNModel",
7877
"Model",
7978
"OutputTransform",
80-
"PortraitBackgroundMatting",
8179
"SalientObjectDetectionModel",
8280
"SegmentationModel",
8381
"SSD",
84-
"VideoBackgroundMatting",
8582
"YOLO",
8683
"YoloV3ONNX",
8784
"YoloV4",
@@ -95,7 +92,6 @@
9592
"Prompt",
9693
"Detection",
9794
"DetectionResult",
98-
"DetectionWithLandmarks",
9995
"DetectedKeypoints",
10096
"classification_models",
10197
"detection_models",

model_api/python/model_api/models/action_classification.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
from model_api.adapters.utils import RESIZE_TYPES, InputTransform
1313

1414
from .model import Model
15+
from .result_types import ClassificationResult
1516
from .types import BooleanValue, ListValue, NumericalValue, StringValue
16-
from .utils import ClassificationResult, load_labels
17+
from .utils import load_labels
1718

1819
if TYPE_CHECKING:
1920
from model_api.adapters.inference_adapter import InferenceAdapter
@@ -99,7 +100,10 @@ def parameters(cls) -> dict[str, Any]:
99100
description="Path to file with labels. Overrides the labels, if they sets via 'labels' parameter",
100101
),
101102
"mean_values": ListValue(
102-
description="Normalization values, which will be subtracted from image channels for image-input layer during preprocessing",
103+
description=(
104+
"Normalization values, which will be subtracted from image channels "
105+
"for image-input layer during preprocessing"
106+
),
103107
default_value=[],
104108
),
105109
"pad_value": NumericalValue(

model_api/python/model_api/models/anomaly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
from model_api.adapters.inference_adapter import InferenceAdapter
1818

1919
from .image_model import ImageModel
20+
from .result_types import AnomalyResult
2021
from .types import ListValue, NumericalValue, StringValue
21-
from .utils import AnomalyResult
2222

2323

2424
class AnomalyDetection(ImageModel):

0 commit comments

Comments
 (0)