Skip to content

Commit f67d9c4

Browse files
authored
ITEP-69567: Update openvino version (#221)
Update the openvino and model-api versions to latest. Add changes to get BAT to pass.
1 parent 3109d86 commit f67d9c4

13 files changed

+721
-193
lines changed

percebro/requirements-runtime.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ ntplib
1414
numpy>=1.16.6,<=1.26.4
1515
onvif-zeep
1616
open3d-cpu
17-
openvino-model-api==0.2.5
18-
openvino==2024.6.0
17+
openvino-model-api==0.3.0.3
18+
openvino==2025.2.0
1919
ovmsclient
2020
paho-mqtt
2121
pillow

percebro/src/detector.py

Lines changed: 1 addition & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import uuid
1010

1111
import cv2
12-
from model_api.models.open_pose import OpenPoseDecoder
1312
import numpy as np
1413
from openvino.runtime import Core
1514
from ovmsclient import make_grpc_client
@@ -365,8 +364,7 @@ def modelPreconfigure(self):
365364
if self.device == "CPU":
366365
self.config = {'NUM_STREAMS': self.ov_cores,
367366
'INFERENCE_NUM_THREADS': str(self.ov_cores),
368-
'PERFORMANCE_HINT': 'THROUGHPUT',
369-
'AFFINITY': 'CORE'}
367+
'PERFORMANCE_HINT': 'THROUGHPUT'}
370368
self.core.set_property(device_name=self.device, properties=self.config)
371369

372370
if self.plugin:
@@ -770,150 +768,6 @@ def deserializeOutput(self, data):
770768
dec_data = json.loads(data)
771769
return dec_data
772770

773-
class PoseEstimator(Detector):
774-
POSE_PAIRS = ((15, 13), (13, 11), (16, 14), (14, 12), (11, 12), (5, 11),
775-
(6, 12), (5, 6), (5, 7), (6, 8), (7, 9), (8, 10), (1, 2),
776-
(0, 1), (0, 2), (1, 3), (2, 4), (3, 5), (4, 6))
777-
778-
bodyPartKP = ['Nose', 'Left-Eye', 'Right-Eye', 'Left-Ear', 'Right-Ear',
779-
'Left-Shoulder', 'Right-Shoulder', 'Left-Elbow', 'Right-Elbow',
780-
'Left-Wrist', 'Right-Wrist', 'Left-Hip', 'Right-Hip',
781-
'Left-Knee', 'Right-Knee', 'Left-Ankle', 'Right-Ankle']
782-
783-
colors = [ (255,0,0), (255,85,0), (255,170,0), (255,255,0), (170,255,0), (85,255,0),
784-
(0,255,0), (0,255,85), (0,255,170), (0,255,255), (0,170,255), (0,85,255),
785-
(0,0,255), (85,0,255), (170,0,255), (255,0,255), (255,0,170)]
786-
787-
def __init__(self, asynchronous=False, distributed=Distributed.NONE):
788-
super().__init__(asynchronous=asynchronous, distributed=distributed)
789-
self.decoder = OpenPoseDecoder()
790-
self.saveDict = True
791-
792-
return
793-
794-
def setParameters(self, model, device, plugin, threshold, ov_cores):
795-
super().setParameters(model, device, plugin, threshold, ov_cores)
796-
797-
if self.distributed == Distributed.OVMS:
798-
self.output_keys = list(self.model_metadata["outputs"].keys())
799-
self.n, self.c, self.h, self.w = self.model_metadata["inputs"]["data"]["shape"]
800-
else:
801-
self.output_keys = [out.get_any_name() for out in self.model.outputs]
802-
self.n, self.c, self.h, self.w = self.model.inputs[0].shape
803-
804-
return
805-
806-
def postprocess(self, result):
807-
people = []
808-
poses = self.processResults(result)
809-
810-
for pose in poses:
811-
points = pose[:, :2]
812-
points_scores = pose[:, 2]
813-
814-
hpe_bounds = [None] * 4
815-
published_pose = []
816-
for point, score in zip(points, points_scores):
817-
if len(point) == 0 or score == 0:
818-
published_pose.append(())
819-
continue
820-
821-
point_x, point_y = point[0], point[1]
822-
published_pose.append((point_x, point_y))
823-
824-
if hpe_bounds[0] is None or point_x < hpe_bounds[0]:
825-
hpe_bounds[0] = point_x
826-
if hpe_bounds[2] is None or point_x > hpe_bounds[2]:
827-
hpe_bounds[2] = point_x
828-
if hpe_bounds[1] is None or point_y < hpe_bounds[1]:
829-
hpe_bounds[1] = point_y
830-
if hpe_bounds[3] is None or point_y > hpe_bounds[3]:
831-
hpe_bounds[3] = point_y
832-
833-
if hpe_bounds[0] == None:
834-
continue
835-
836-
if self.hasKeypoints(published_pose,
837-
('Right-Hip', 'Right-Knee', 'Right-Ankle',
838-
'Left-Hip', 'Left-Knee', 'Left-Ankle')) \
839-
or self.hasKeypoints(published_pose,
840-
('Right-Shoulder', 'Right-Elbow', 'Right-Wrist',
841-
'Left-Shoulder', 'Left-Elbow', 'Left-Wrist')):
842-
843-
bounds = Rectangle(origin=Point(hpe_bounds[0], hpe_bounds[1]),
844-
opposite=Point(hpe_bounds[2], hpe_bounds[3]))
845-
if bounds.width == 0 or bounds.height == 0:
846-
continue
847-
848-
comw = bounds.width / 3
849-
comh = bounds.height / 4
850-
center_of_mass = Rectangle(origin=Point(bounds.x + comw, bounds.y + comh),
851-
size=(comw, comh))
852-
person = {'id': len(people) + 1,
853-
'category': 'person',
854-
'bounding_box': bounds.asDict,
855-
'center_of_mass': center_of_mass.asDict,
856-
'pose': published_pose}
857-
people.append(person)
858-
859-
return people
860-
861-
def hasKeypoints(self, pose, points):
862-
for point in points:
863-
idx = self.bodyPartKP.index(point)
864-
if idx >= len(pose) or not len(pose[idx]):
865-
return False
866-
return True
867-
868-
def processResults(self, results):
869-
870-
pafs = results.data[self.output_keys[0]]
871-
heatmaps = results.data[self.output_keys[1]]
872-
873-
pooled_heatmaps = np.array(
874-
[[self.maxpool(h, kernel_size=3, stride=1, padding=1) for h in heatmaps[0]]])
875-
nms_heatmaps = self.nonMaxSuppression(heatmaps, pooled_heatmaps)
876-
877-
image_shape = results.save
878-
poses, _ = self.decoder(heatmaps, nms_heatmaps, pafs)
879-
880-
if self.distributed == Distributed.OVMS:
881-
output_shape = self.model_metadata["outputs"][self.output_keys[0]]['shape']
882-
else:
883-
output_shape = self.model.get_output_shape(0)
884-
885-
image_width, image_height = image_shape
886-
_, _, output_height, output_width = output_shape
887-
x_scale, y_scale = image_width / output_width, image_height / output_height
888-
889-
if self.keep_aspect:
890-
height_ratio = self.h / image_height
891-
width_ratio = self.w / image_width
892-
if height_ratio <= width_ratio:
893-
x_scale = x_scale / (height_ratio / width_ratio)
894-
else:
895-
y_scale = y_scale / (width_ratio / height_ratio)
896-
897-
poses[:, :, :2] *= (x_scale, y_scale)
898-
return poses
899-
900-
def maxpool(self, matrix, kernel_size, stride, padding):
901-
matrix = np.pad(matrix, padding, mode="constant")
902-
output_shape = ((matrix.shape[0] - kernel_size) // stride + 1,
903-
(matrix.shape[1] - kernel_size) // stride + 1,)
904-
905-
kernel_size = (kernel_size, kernel_size)
906-
907-
matrix_view = np.lib.stride_tricks.as_strided(matrix,
908-
shape=output_shape + kernel_size,
909-
strides=(stride * matrix.strides[0], stride * matrix.strides[1]) + matrix.strides)
910-
matrix_view = matrix_view.reshape(-1, *kernel_size)
911-
912-
return matrix_view.max(axis=(1, 2)).reshape(output_shape)
913-
914-
def nonMaxSuppression(self, result, pooled_result):
915-
return result * (result == pooled_result)
916-
917771
class REIDDetector(Detector):
918772

919773
def postprocess(self, result):

percebro/src/detector_geti.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
import numpy as np
88

99
from scene_common import log
10-
from openvino.runtime import Core
11-
from model_api.adapters import OpenvinoAdapter, create_core
1210
from model_api.models import Model
13-
from model_api.models.utils import Detection
11+
from model_api.models.result.detection import DetectionResult
1412
from detector import Detector, Distributed, IAData
15-
from wrapper_otxssd import OTXSSDModel
1613

1714
from scene_common.geometry import Point, Rectangle
1815

19-
def getDetectionCoords(detection : Detection):
20-
return [detection.xmin, detection.ymin, detection.xmax, detection.ymax]
21-
2216
class GetiDetector(Detector):
2317
def __init__(self, asynchronous=False, distributed=Distributed.NONE):
2418
super().__init__(asynchronous=asynchronous, distributed=distributed)
@@ -77,54 +71,54 @@ def postprocess(self, result):
7771
# 'predictions' is now of type DetectionResult
7872
# which is a tuple of (detections, saliency_map, feature_vector).
7973
# Therefore just looking at first tuple member.
80-
for res in predictions[0]:
74+
for idx, res in enumerate(predictions.scores):
8175
# Leave early when we're done with high confidence detections
82-
if res.score < self.threshold:
76+
if res < self.threshold:
8377
continue
8478

8579
# Avoid crash due to out of bounds index
86-
if res.id >= len(self.categories):
80+
if idx >= len(self.categories):
8781
log.debug("Skipping out of bounds category index")
8882
continue
8983

90-
if self.categories[res.id] in self.blacklist:
91-
log.debug(f"Skipping blacklisted category {self.categories[res.id]}")
84+
if self.categories[idx] in self.blacklist:
85+
log.debug(f"Skipping blacklisted category {self.categories[idx]}")
9286
continue
9387

9488
bounds = [None] * 4
95-
rect = getDetectionCoords(res)
89+
rect = predictions.bboxes[idx]
9690
bounds[0] = rect[0]
9791
bounds[1] = rect[1]
9892
bounds[2] = rect[2]
9993
bounds[3] = rect[3]
10094
# Avoid reporting invalid detections (0 height or width)
10195
if bounds[0] == bounds[2] \
102-
or bounds[1] == bounds[3]:
96+
or bounds[1] == bounds[3]:
10397
continue
10498

10599
if bounds[2] < bounds[0]:
106100
tmp = bounds[0]
107101
bounds[0] = bounds[2]
108102
bounds[2] = tmp
109103
if bounds[3] < bounds[1]:
110-
tmp = bounds[0]
111-
bounds[0] = bounds[3]
104+
tmp = bounds[1]
105+
bounds[1] = bounds[3]
112106
bounds[3] = tmp
113107

114108
bound_box = Rectangle(origin=Point(bounds[0], bounds[1]),
115-
opposite=Point(bounds[2], bounds[3]))
109+
opposite=Point(bounds[2], bounds[3]))
116110
comw = bound_box.width / 3
117111
comh = bound_box.height / 4
118112
center_of_mass = Rectangle(origin=Point(bound_box.x + comw, bound_box.y + comh),
119-
size=(comw, comh))
120-
object = {
113+
size=(comw, comh))
114+
detected_object = {
121115
'id': len(found) + 1,
122-
'category': self.categories[res.id] ,
123-
'confidence': float(res.score),
116+
'category': self.categories[idx],
117+
'confidence': float(res),
124118
'bounding_box': bound_box.asDict,
125119
'center_of_mass': center_of_mass.asDict
126120
}
127-
found.append( object )
121+
found.append(detected_object)
128122

129123
return found
130124

0 commit comments

Comments
 (0)