Skip to content

Commit 4caf773

Browse files
committed
black
1 parent 8f5377e commit 4caf773

File tree

10 files changed

+67
-31
lines changed

10 files changed

+67
-31
lines changed

model_api/cpp/models/src/detection_model_ssd.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ std::unique_ptr<ResultBase> ModelSSD::postprocessSingleOutput(InferenceResult& i
162162
0.f,
163163
floatInputImgHeight);
164164
desc.width = clamp(
165-
round((detections[i * objectSize + 5] * netInputWidth - padLeft) * invertedScaleX),
165+
round((detections[i * numAndStep.objectSize + 5] * netInputWidth - padLeft) * invertedScaleX),
166166
0.f,
167167
floatInputImgWidth) - desc.x;
168168
desc.height = clamp(
169-
round((detections[i * objectSize + 6] * netInputHeight - padTop) * invertedScaleY),
169+
round((detections[i * numAndStep.objectSize + 6] * netInputHeight - padTop) * invertedScaleY),
170170
0.f,
171171
floatInputImgHeight) - desc.y;
172172
result->objects.push_back(desc);
@@ -224,11 +224,11 @@ std::unique_ptr<ResultBase> ModelSSD::postprocessMultipleOutputs(InferenceResult
224224
0.f,
225225
floatInputImgHeight);
226226
desc.width = clamp(
227-
round((boxes[i * objectSize + 2] * widthScale - padLeft) * invertedScaleX),
227+
round((boxes[i * numAndStep.objectSize + 2] * widthScale - padLeft) * invertedScaleX),
228228
0.f,
229229
floatInputImgWidth) - desc.x;
230230
desc.height = clamp(
231-
round((boxes[i * objectSize + 3] * heightScale - padTop) * invertedScaleY),
231+
round((boxes[i * numAndStep.objectSize + 3] * heightScale - padTop) * invertedScaleY),
232232
0.f,
233233
floatInputImgHeight) - desc.y;
234234
result->objects.push_back(desc);

model_api/cpp/models/src/detection_model_yolo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ void YoloV8::prepareInputsOutputs(std::shared_ptr<ov::Model>& model) {
544544
throw std::runtime_error("YoloV8 wrapper requires the output to be of rank 3");
545545
}
546546
if (!labels.empty() && labels.size() + 4 != out_shape[1]) {
547-
throw std::runtime_error("YoloV8 wrapper number of labes must be smaller than output.shape[1] by 4");
547+
throw std::runtime_error("YoloV8 wrapper number of labels must be smaller than output.shape[1] by 4");
548548
}
549549
}
550550

model_api/cpp/utils/include/utils/nms.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ struct AnchorLabeled : public Anchor {
5454

5555
template <typename Anchor>
5656
std::vector<size_t> nms(const std::vector<Anchor>& boxes, const std::vector<float>& scores,
57-
const float thresh, bool includeBoundaries=false, size_t maxNum=std::numeric_limits<size_t>::max()) {
57+
const float thresh, bool includeBoundaries=false, size_t keep_top_k=0) {
58+
if (keep_top_k == 0) {
59+
keep_top_k = boxes.size();
60+
}
5861
std::vector<float> areas(boxes.size());
5962
for (size_t i = 0; i < boxes.size(); ++i) {
6063
areas[i] = (boxes[i].right - boxes[i].left + includeBoundaries) * (boxes[i].bottom - boxes[i].top + includeBoundaries);
@@ -64,7 +67,7 @@ std::vector<size_t> nms(const std::vector<Anchor>& boxes, const std::vector<floa
6467
std::sort(order.begin(), order.end(), [&scores](int o1, int o2) { return scores[o1] > scores[o2]; });
6568

6669
size_t ordersNum = 0;
67-
for (; ordersNum < order.size() && scores[order[ordersNum]] >= 0 && ordersNum < maxNum; ordersNum++);
70+
for (; ordersNum < order.size() && scores[order[ordersNum]] >= 0 && ordersNum < keep_top_k; ordersNum++);
6871

6972
std::vector<size_t> keep;
7073
bool shouldContinue = true;

model_api/python/openvino/model_api/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"YOLO",
119119
"YoloV3ONNX",
120120
"YoloV4",
121-
"YOLOv5"
121+
"YOLOv5",
122122
"YOLOv8",
123123
"YOLOF",
124124
"YOLOX",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def create_model(
126126
core=None,
127127
weights_path="",
128128
adaptor_parameters={},
129-
device="CPU",
129+
device="AUTO",
130130
nstreams="1",
131131
nthreads=None,
132132
max_num_requests=0,

model_api/python/openvino/model_api/models/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def crop_resize(image, size):
340340
}
341341

342342

343-
def nms(x1, y1, x2, y2, scores, thresh, include_boundaries=False, keep_top_k=None):
343+
def nms(x1, y1, x2, y2, scores, thresh, include_boundaries=False, keep_top_k=0):
344344
b = 1 if include_boundaries else 0
345345
areas = (x2 - x1 + b) * (y2 - y1 + b)
346346
order = scores.argsort()[::-1]
@@ -363,11 +363,10 @@ def nms(x1, y1, x2, y2, scores, thresh, include_boundaries=False, keep_top_k=Non
363363
intersection = w * h
364364

365365
union = areas[i] + areas[order[1:]] - intersection
366-
overlap = np.zeros_like(intersection, dtype=float)
367366
overlap = np.divide(
368367
intersection,
369368
union,
370-
out=overlap,
369+
out=np.zeros_like(intersection, dtype=float),
371370
where=union != 0,
372371
)
373372

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@ def set_strides_grids(self):
574574
self.expanded_strides = np.concatenate(expanded_strides, 1)
575575

576576

577-
578577
class YoloV3ONNX(DetectionModel):
579578
__model__ = "YOLOv3-ONNX"
580579

@@ -766,7 +765,9 @@ def non_max_suppression(
766765

767766
# Detections matrix nx6 (xyxy, conf, cls)
768767
box, cls, mask = x[:, :4], x[:, 4 : nc + 4], x[:, nc + 4 :]
769-
box = xywh2xyxy(box) # center_x, center_y, width, height) to (x1, y1, x2, y2) # TODO: first cut by conf_thres
768+
box = xywh2xyxy(
769+
box
770+
) # center_x, center_y, width, height) to (x1, y1, x2, y2) # TODO: first cut by conf_thres
770771
if multi_label:
771772
i, j = (cls > conf_thres).nonzero(as_tuple=False).T
772773
x = torch.cat((box[i], x[i, 4 + j, None], j[:, None].float(), mask[i]), 1)
@@ -808,13 +809,9 @@ def __init__(self, inference_adapter, configuration, preload=False):
808809
self.raise_error("the output must be of precision f32")
809810
out_shape = output.shape
810811
if 3 != len(out_shape):
811-
self.raise_error(
812-
"the output must be of rank 3"
813-
)
812+
self.raise_error("the output must be of rank 3")
814813
if self.labels and len(self.labels) + 4 != out_shape[1]:
815-
self.raise_error(
816-
"number of labes must be smaller than out_shape[1] by 4"
817-
)
814+
self.raise_error("number of labels must be smaller than out_shape[1] by 4")
818815

819816
@classmethod
820817
def parameters(cls):
@@ -841,7 +838,9 @@ def parameters(cls):
841838
def postprocess(self, outputs, meta):
842839
if 1 != len(outputs):
843840
raise RuntimeError("YoloV8 wrapper expects 1 output")
844-
boxes = non_max_suppression(next(iter(outputs.values())), self.confidence_threshold, self.iou_threshold)
841+
boxes = non_max_suppression(
842+
next(iter(outputs.values())), self.confidence_threshold, self.iou_threshold
843+
)
845844

846845
inputImgWidth, inputImgHeight = (
847846
meta["original_shape"][1],
@@ -884,4 +883,5 @@ def postprocess(self, outputs, meta):
884883

885884
class YOLOv8(YOLOv5):
886885
"""YOLOv5 and YOLOv8 are identical in terms of inference"""
886+
887887
__model__ = "YOLOv8"

model_api/python/setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838
install_requires=(SETUP_DIR / "requirements.txt").read_text(),
3939
extras_require={
4040
"ovms": (SETUP_DIR / "requirements_ovms.txt").read_text(),
41-
"tests": ["httpx", "pytest", "openvino-dev[onnx,pytorch,tensorflow2]", "ultralytics>=8.0.114"],
41+
"tests": [
42+
"httpx",
43+
"pytest",
44+
"openvino-dev[onnx,pytorch,tensorflow2]",
45+
"ultralytics>=8.0.114",
46+
],
4247
},
4348
long_description=(SETUP_DIR.parents[1] / "README.md").read_text(),
4449
long_description_content_type="text/markdown",

tests/python/accuracy/conftest.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,36 @@ def pytest_addoption(parser):
1414

1515

1616
def _impaths(data):
17-
impaths = sorted(file for file in (Path(data) / "coco128/images/train2017/").iterdir())
17+
impaths = sorted(
18+
file for file in (Path(data) / "coco128/images/train2017/").iterdir()
19+
)
1820
if not impaths:
1921
raise RuntimeError(f"{Path(data) / 'coco128/images/train2017/'} is empty")
2022
return impaths
2123

2224

2325
def pytest_generate_tests(metafunc):
2426
if "pt" in metafunc.fixturenames:
25-
metafunc.parametrize("pt", ("yolov5n6u.pt", "yolov5s6u.pt", "yolov5m6u.pt", "yolov5l6u.pt", "yolov5x6u.pt", "yolov8n.pt", "yolov8s.pt", "yolov8m.pt", "yolov8l.pt", "yolov8x.pt", "yolov5nu.pt", "yolov5su.pt", "yolov5mu.pt", "yolov5lu.pt", "yolov5xu.pt"))
27+
metafunc.parametrize(
28+
"pt",
29+
(
30+
"yolov5n6u.pt",
31+
"yolov5s6u.pt",
32+
"yolov5m6u.pt",
33+
"yolov5l6u.pt",
34+
"yolov5x6u.pt",
35+
"yolov8n.pt",
36+
"yolov8s.pt",
37+
"yolov8m.pt",
38+
"yolov8l.pt",
39+
"yolov8x.pt",
40+
"yolov5nu.pt",
41+
"yolov5su.pt",
42+
"yolov5mu.pt",
43+
"yolov5lu.pt",
44+
"yolov5xu.pt",
45+
),
46+
)
2647
if "impath" in metafunc.fixturenames:
2748
metafunc.parametrize("impath", _impaths(metafunc.config.getoption("data")))
2849

tests/python/accuracy/test_YoloV8.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
from pathlib import Path
1616
import functools
1717

18+
1819
# TODO: update docs
1920
def patch_export(yolo):
2021
# TODO: move to https://github.com/ultralytics/ultralytics/
2122
if yolo.predictor is None:
22-
yolo.predict(np.zeros([1, 1, 3], np.uint8)) # YOLO.predictor is initialized by predict
23+
yolo.predict(
24+
np.zeros([1, 1, 3], np.uint8)
25+
) # YOLO.predictor is initialized by predict
2326
export_dir = Path(yolo.export(format="openvino"))
2427
xml = [path for path in export_dir.iterdir() if path.suffix == ".xml"]
2528
if 1 != len(xml):
@@ -154,13 +157,17 @@ def cached_models(folder, pt):
154157
pt = Path(pt)
155158
yolo_folder = folder / "YOLOv8"
156159
yolo_folder.mkdir(exist_ok=True) # TODO: maybe remove
157-
export_dir = patch_export(YOLO(yolo_folder / pt)) # If there is no file it is downloaded
160+
export_dir = patch_export(
161+
YOLO(yolo_folder / pt)
162+
) # If there is no file it is downloaded
158163
copy_path = folder / "YOLOv8/detector" / pt.stem
159164
copy_tree(str(export_dir), str(copy_path)) # C++ tests expect a model here
160-
xml = (copy_path / (pt.stem + ".xml"))
165+
xml = copy_path / (pt.stem + ".xml")
161166
ref_dir = copy_path / "ref"
162167
ref_dir.mkdir(exist_ok=True)
163-
impl_wrapper = YOLOv5.create_model(xml, device="CPU", model_type="YOLOv5") # TODO: YOLOv5 vs v8
168+
impl_wrapper = YOLOv5.create_model(
169+
xml, device="CPU", model_type="YOLOv5"
170+
) # TODO: YOLOv5 vs v8
164171
ref_wrapper = YOLO(export_dir)
165172
ref_wrapper.overrides["imgsz"] = (impl_wrapper.w, impl_wrapper.h)
166173
compiled_model = ov.Core().compile_model(xml, "CPU")
@@ -243,10 +250,11 @@ def test_detector(impath, data, pt):
243250
)
244251
ref_preprocessed = ref_wrapper.predictor.preprocess([im]).numpy()
245252

246-
processed = resize_image_letterbox(im, (impl_wrapper.w, impl_wrapper.h), cv2.INTER_LINEAR, 114)
253+
processed = resize_image_letterbox(
254+
im, (impl_wrapper.w, impl_wrapper.h), cv2.INTER_LINEAR, 114
255+
)
247256
processed = (
248-
processed[None][..., ::-1].transpose((0, 3, 1, 2)).astype(np.float32)
249-
/ 255.0
257+
processed[None][..., ::-1].transpose((0, 3, 1, 2)).astype(np.float32) / 255.0
250258
)
251259
assert (processed == ref_preprocessed).all()
252260
preds = next(iter(compiled_model({0: processed}).values()))

0 commit comments

Comments
 (0)