Skip to content

Commit fce6479

Browse files
authored
tests: full unit tests coverage for model_api (#575)
* unit tests * unit tests * fix tests * fix ut * bandit artifact name * final changes * save * combine nested * format
1 parent 60240c0 commit fce6479

51 files changed

Lines changed: 12755 additions & 19 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/security-scan.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ jobs:
7373
severity-level: "LOW"
7474
confidence-level: "LOW"
7575
config_file: "${{ matrix.project }}/pyproject.toml"
76+
artifact-name: "bandit-results-${{ matrix.project }}"
7677
fail-on-findings: ${{ (github.event_name == 'pull_request' || github.event_name == 'merge_group') && 'true' || 'false' }}
7778

7879
bandit-scan:

model_api/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,6 @@ pythonpath = ["src"]
274274
skips = ["B101", "B310"]
275275

276276
[tool.coverage.report]
277-
# Fail if total coverage is below 50%
278-
fail_under = 50
277+
# Fail if total coverage is below 100%
278+
fail_under = 100
279279
show_missing = true

model_api/src/model_api/adapters/openvino_adapter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,7 @@ def reshape_dynamic_inputs(self) -> None:
209209
static_shape.append(1)
210210
elif len(shape) == 4:
211211
if is_nchw:
212-
if i == 1:
213-
static_shape.append(3)
214-
else:
215-
static_shape.append(224)
212+
static_shape.append(224)
216213
else:
217214
if i == 3:
218215
static_shape.append(3)

model_api/src/model_api/adapters/utils.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,14 @@ def crop_resize_graph(input: Output, size: tuple[int, int], input_dtype: str = "
250250
cropped_frame = if_node.set_output(then_body_res_1, else_body_res_1)
251251

252252
elif desired_aspect_ratio < 1:
253-
new_width = opset.floor(
254-
opset.multiply(
255-
opset.convert(ih, destination_type="f32"),
256-
desired_aspect_ratio,
253+
new_width = opset.convert(
254+
opset.floor(
255+
opset.multiply(
256+
opset.convert(ih, destination_type="f32"),
257+
np.float32(desired_aspect_ratio),
258+
),
257259
),
260+
destination_type="i32",
258261
)
259262
offset = opset.unsqueeze(
260263
opset.divide(
@@ -272,11 +275,14 @@ def crop_resize_graph(input: Output, size: tuple[int, int], input_dtype: str = "
272275
axes=[w_axis],
273276
)
274277
elif desired_aspect_ratio > 1:
275-
new_hight = opset.floor(
276-
opset.multiply(
277-
opset.convert(iw, destination_type="f32"),
278-
desired_aspect_ratio,
278+
new_hight = opset.convert(
279+
opset.floor(
280+
opset.multiply(
281+
opset.convert(iw, destination_type="f32"),
282+
np.float32(desired_aspect_ratio),
283+
),
279284
),
285+
destination_type="i32",
280286
)
281287
offset = opset.unsqueeze(
282288
opset.divide(
@@ -461,6 +467,7 @@ def window_preprocess_graph(
461467
"""OV graph: window intensity scaling [center-width/2, center+width/2] to [0, 1]."""
462468
low = window_center - window_width / 2.0
463469
span = window_width
470+
# opset.clamp requires scalar float min/max, not opset.constant nodes
464471
return opset.clamp(
465472
opset.divide(
466473
opset.subtract(
@@ -469,8 +476,8 @@ def window_preprocess_graph(
469476
),
470477
opset.constant(span, dtype=Type.f32),
471478
),
472-
opset.constant(0.0, dtype=Type.f32),
473-
opset.constant(1.0, dtype=Type.f32),
479+
0.0,
480+
1.0,
474481
)
475482

476483

@@ -500,13 +507,14 @@ def range_scale_preprocess_graph(
500507
Multiplies by *scale_factor*, clamps to [min_value, max_value], then
501508
normalises to [0, 1] via ``(clamped - min) / (max - min)``.
502509
"""
510+
# opset.clamp requires scalar float min/max, not opset.constant nodes
503511
clamped = opset.clamp(
504512
opset.multiply(
505513
opset.convert(output, destination_type="f32"),
506514
opset.constant(scale_factor, dtype=Type.f32),
507515
),
508-
opset.constant(min_value, dtype=Type.f32),
509-
opset.constant(max_value, dtype=Type.f32),
516+
min_value,
517+
max_value,
510518
)
511519
range = max_value - min_value
512520
if range == 0:

model_api/src/model_api/models/keypoint_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def _get_simcc_maximum(
235235
msg = f"Invalid shape {simcc_y.shape}"
236236
raise ValueError(msg)
237237
if simcc_x.ndim != simcc_y.ndim:
238-
msg = f"{simcc_x.shape} != {simcc_y.shape}"
238+
msg = f"Invalid shape: {simcc_x.shape} != {simcc_y.shape}"
239239
raise ValueError(msg)
240240

241241
if simcc_x.ndim == 3:

0 commit comments

Comments
 (0)