Skip to content

Commit e90f3b1

Browse files
committed
minor
1 parent 564a2bf commit e90f3b1

File tree

6 files changed

+22
-41
lines changed

6 files changed

+22
-41
lines changed

model_api/cpp/models/src/detection_model_yolo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ std::unique_ptr<ResultBase> YoloV8::postprocess(InferenceResult& infResult) {
611611
detections[0 * num_proposals + i] - detections[2 * num_proposals + i] / 2.0f,
612612
detections[1 * num_proposals + i] - detections[3 * num_proposals + i] / 2.0f,
613613
detections[0 * num_proposals + i] + detections[2 * num_proposals + i] / 2.0f,
614-
detections[1 * num_proposals + i] + detections[3 * num_proposals + i] / 2.0f
614+
detections[1 * num_proposals + i] + detections[3 * num_proposals + i] / 2.0f,
615615
});
616616
confidences.push_back(confidence);
617617
labelIDs.push_back(max_id - 4); // TODO: move 4 to const

model_api/python/openvino/model_api/adapters/utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,6 @@ def resize_image_letterbox_graph(input: Output, size, interpolation, pad_value):
123123
mode=interpolation,
124124
shape_calculation_mode="sizes",
125125
)
126-
# image = input
127-
# image_shape = opset.shape_of(input, name="shape")
128-
# nw = opset.convert(
129-
# opset.gather(image_shape, opset.constant(w_axis), axis=0),
130-
# destination_type="i32",
131-
# )
132-
# nh = opset.convert(
133-
# opset.gather(image_shape, opset.constant(h_axis), axis=0),
134-
# destination_type="i32",
135-
# )
136126
dx = opset.divide(
137127
opset.subtract(opset.constant(w, dtype=np.int32), nw),
138128
opset.constant(2, dtype=np.int32),

model_api/python/openvino/model_api/models/image_model.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,6 @@ def preprocess(self, inputs):
186186
}
187187
- the input metadata, which might be used in `postprocess` method
188188
"""
189-
# import cv2
190-
# image = inputs
191-
# ih, iw = image.shape[0:2]
192-
# w, h = (640, 640)
193-
# scale = min(w / iw, h / ih)
194-
# nw = round(iw * scale)
195-
# nh = round(ih * scale)
196-
# image = cv2.resize(image, (nw, nh), interpolation=cv2.INTER_LINEAR)
197-
198-
# from openvino.model_api.models.utils import resize_image_letterbox
199-
# processed = resize_image_letterbox(inputs, (self.w, self.h), cv2.INTER_LINEAR, 114)
200-
# processed = (
201-
# processed[None][..., ::-1].transpose((0, 3, 1, 2)).astype(np.float32)
202-
# )
203189
return {self.image_blob_name: inputs[None]}, {
204190
"original_shape": inputs.shape,
205191
"resized_shape": (self.w, self.h, self.c),

model_api/python/openvino/model_api/models/model.py

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

2828

2929
class WrapperError(Exception):
30-
"""Class for errors occurred in Model API wrappers"""
30+
"""The class for errors occurred in Model API wrappers"""
3131

3232
def __init__(self, wrapper_name, message):
3333
super().__init__(f"{wrapper_name}: {message}")

model_api/python/openvino/model_api/models/yolo.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,6 @@ def non_max_suppression(
748748
shape (num_boxes, 6 + num_masks) containing the kept boxes, with columns
749749
(x1, y1, x2, y2, confidence, class, mask1, mask2, ...).
750750
"""
751-
out_shape = prediction.shape
752-
if 3 != len(out_shape):
753-
raise RuntimeError("YoloV8 wrapper expects the output of rank 3")
754-
if 1 != out_shape[0]:
755-
raise RuntimeError("YoloV8 wrapper expects 1 as the first dim of the output")
756751
nc = nc or (prediction.shape[1] - 4) # number of classes
757752
mi = 4 + nc # mask start index
758753
xc = np.amax(prediction[:, 4:mi], 1) > conf_thres # candidates
@@ -837,15 +832,19 @@ def parameters(cls):
837832

838833
def postprocess(self, outputs, meta):
839834
if 1 != len(outputs):
840-
raise RuntimeError("YoloV8 wrapper expects 1 output")
835+
self.raise_error("expect 1 output")
836+
prediction = next(iter(outputs.values()))
837+
out_shape = prediction.shape
838+
if 3 != len(out_shape):
839+
raise RuntimeError("expect the output of rank 3")
840+
if 1 != out_shape[0]:
841+
raise RuntimeError("expect 1 as the first dim of the output")
841842
boxes = non_max_suppression(
842-
next(iter(outputs.values())), self.confidence_threshold, self.iou_threshold
843+
prediction, self.confidence_threshold, self.iou_threshold
843844
)
844845

845-
inputImgWidth, inputImgHeight = (
846-
meta["original_shape"][1],
847-
meta["original_shape"][0],
848-
)
846+
inputImgWidth = meta["original_shape"][1]
847+
inputImgHeight = meta["original_shape"][0]
849848
invertedScaleX, invertedScaleY = (
850849
inputImgWidth / self.orig_width,
851850
inputImgHeight / self.orig_height,
@@ -865,7 +864,7 @@ def postprocess(self, outputs, meta):
865864
boxes[:, :4] -= (padLeft, padTop, padLeft, padTop)
866865
boxes[:, :4] *= (invertedScaleX, invertedScaleY, invertedScaleX, invertedScaleY)
867866

868-
intboxes = np.rint(boxes[:, :4]).astype(np.int32)
867+
intboxes = np.rint(boxes[:, :4]).astype(np.int32) # TODO: np.round(float_act_map, out=float_act_map).astype()
869868
np.clip(
870869
intboxes,
871870
0,

tests/python/accuracy/test_YoloV8.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ def cached_models(folder, pt):
170170
) # TODO: YOLOv5 vs v8
171171
ref_wrapper = YOLO(export_dir)
172172
ref_wrapper.overrides["imgsz"] = (impl_wrapper.w, impl_wrapper.h)
173-
compiled_model = ov.Core().compile_model(xml, "CPU")
173+
if ref_wrapper.predictor is None:
174+
ref_wrapper.predict(
175+
np.zeros([1, 1, 3], np.uint8)
176+
) # YOLO.predictor is initialized by predict
177+
core = ov.Core()
178+
ref_wrapper.predictor.model.ov_compiled_model = core.compile_model(ref_wrapper.predictor.model.ov_model, "CPU")
179+
compiled_model = core.compile_model(xml, "CPU")
174180
return impl_wrapper, ref_wrapper, compiled_model
175181

176182

@@ -290,7 +296,7 @@ def test_detector(impath, data, pt):
290296
assert (result.boxes.data == ref_predictions.boxes.data).all()
291297
assert result.boxes.orig_shape == ref_predictions.boxes.orig_shape
292298
assert result.keypoints == ref_predictions.keypoints
293-
assert result.keys == ref_predictions.keys
299+
assert result._keys == ref_predictions._keys
294300
assert result.masks == ref_predictions.masks
295301
assert result.names == ref_predictions.names
296302
assert (result.orig_img == ref_predictions.orig_img).all()
@@ -308,7 +314,7 @@ def test_classifier(data):
308314
ref_wrapper = YOLO(export_path)
309315
ref_wrapper.overrides["imgsz"] = 224
310316
im = cv2.imread(data + "/coco128/images/train2017/000000000074.jpg")
311-
ref_predictions = ref_wrapper(im)
317+
ref_predictions = ref_wrapper.predict(im)
312318

313319
model = ov.Core().compile_model(f"{export_path}/{xmls[0]}")
314320
orig_imgs = [im]

0 commit comments

Comments
 (0)