Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions model_api/python/model_api/adapters/onnx_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ def embed_preprocessing(
resize_fn = partial(RESIZE_TYPES[resize_mode], size=target_shape)
preproc_funcs.append(resize_fn)
input_transform = InputTransform(brg2rgb, mean, scale)
preproc_funcs.append(input_transform.__call__)
preproc_funcs.append(partial(change_layout, layout=layout))
preproc_funcs.extend((input_transform.__call__, partial(change_layout, layout=layout)))

self.preprocessor = reduce(
lambda f, g: lambda x: f(g(x)),
Expand Down
2 changes: 1 addition & 1 deletion model_api/python/model_api/adapters/ovms_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def infer_async(self, dict_data, callback_data):
# For models with single output ovmsclient returns ndarray with results,
# so the dict must be created to correctly implement interface.
if isinstance(raw_result, np.ndarray):
output_name = list(self.metadata["outputs"].keys())[0]
output_name = next(iter(self.metadata["outputs"].keys()))
raw_result = {output_name: raw_result}
self.callback_fn(raw_result, (lambda x: x, callback_data))

Expand Down
2 changes: 1 addition & 1 deletion model_api/python/model_api/models/anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def postprocess(self, outputs: dict[str, np.ndarray], meta: dict[str, Any]) -> A
pred_label: str | None = None
pred_mask: np.ndarray | None = None
pred_boxes: np.ndarray | None = None
predictions = outputs[list(self.outputs)[0]]
predictions = outputs[next(iter(self.outputs))]

if len(predictions.shape) == 1:
pred_score = predictions
Expand Down
5 changes: 3 additions & 2 deletions model_api/python/model_api/models/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import copy
import json
from itertools import starmap
from pathlib import Path
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -303,7 +304,7 @@ def get_multilabel_predictions(self, logits: np.ndarray) -> list[Label]:
scores.append(logits[i])
labels = [self.labels[i] if self.labels else "" for i in indices]

return [Label(*data) for data in zip(indices, labels, scores)]
return list(starmap(Label, zip(indices, labels, scores)))

def get_multiclass_predictions(self, outputs: dict) -> list[Label]:
if self.embedded_topk:
Expand All @@ -314,7 +315,7 @@ def get_multiclass_predictions(self, outputs: dict) -> list[Label]:
scoresTensor = softmax(outputs[self.out_layer_names[0]][0])
indicesTensor = [int(np.argmax(scoresTensor))]
labels = [self.labels[i] if self.labels else "" for i in indicesTensor]
return [Label(*data) for data in zip(indicesTensor, labels, scoresTensor)]
return list(starmap(Label, zip(indicesTensor, labels, scoresTensor)))


def addOrFindSoftmaxAndTopkOutputs(inference_adapter: InferenceAdapter, topk: int, output_raw_scores: bool) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def postprocess(self, outputs: dict, meta: dict) -> InstanceSegmentationResult:
labels=labels,
scores=scores,
masks=_masks,
label_names=label_names if label_names else None,
label_names=label_names or None,
saliency_map=_average_and_normalize(saliency_maps),
feature_vector=outputs.get(_feature_vector_name, np.ndarray(0)),
)
Expand Down
2 changes: 1 addition & 1 deletion model_api/python/model_api/models/sam_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
preload: bool = False,
):
super().__init__(inference_adapter, configuration, preload)
self.output_name: str = list(self.outputs.keys())[0]
self.output_name: str = next(iter(self.outputs.keys()))
self.resize_type: str
self.image_size: int

Expand Down
10 changes: 5 additions & 5 deletions model_api/python/model_api/models/visual_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ def _predict_masks(
elif i == 1:
# Cascaded Post-refinement-1
mask_input, masks, _ = _decide_masks(
masks,
logits,
scores,
masks, # noqa: F821 masks are set in the first iteration
logits, # noqa: F821 masks are set in the first iteration
scores, # noqa: F821 masks are set in the first iteration
is_single=True,
)
if masks.sum() == 0:
Expand All @@ -498,8 +498,8 @@ def _predict_masks(
# Cascaded Post-refinement-2
mask_input, masks, _ = _decide_masks(
masks,
logits,
scores,
logits, # noqa: F821 masks are set in the first iteration
scores, # noqa: F821 masks are set in the first iteration
)
if masks.sum() == 0:
return {"upscaled_masks": masks}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _merge_results(self, results, shape) -> InstanceSegmentationResult:
labels=labels.squeeze(),
scores=scores.squeeze(),
masks=resized_masks,
label_names=label_names if label_names else None,
label_names=label_names or None,
saliency_map=saliency_map,
feature_vector=merged_vector,
)
Expand Down
2 changes: 1 addition & 1 deletion model_api/python/model_api/tilers/tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class Tiler(abc.ABC):
EXECUTION_MODES = ["async", "sync"]
EXECUTION_MODES = ("async", "sync")
"""
An abstract tiler

Expand Down
12 changes: 6 additions & 6 deletions model_api/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ preview = true

# Enable rules
lint.select = [
# "F", # Pyflakes (`F`)
"F", # Pyflakes (`F`)
"E", # pycodestyle error (`E`)
"W", # pycodestyle warning (`W`)
"C90", # mccabe (`C90`)
Expand Down Expand Up @@ -127,18 +127,18 @@ lint.select = [
# "ARG", # flake8-unsused-arguments (`ARG`)
"PTH", # flake8-use-pathlib (`PTH`)
# "TD", # flake8-todos (`TD`)
# "FIX", # flake8-fixme (`FIX`)
"FIX", # flake8-fixme (`FIX`)
"ERA", # eradicate (`ERA`)
"PD", # pandas-vet (`PD`)
"PGH", # pygrep-hooks (`PGH`)
# "PL", # pylint (`PL`)
# "TRY", # tryceratos (`TRY`)
# "FLY", # flynt (`FLY`)
"FLY", # flynt (`FLY`)
"NPY", # NumPy-specific rules (`NPY`)
# "PERF", # Perflint (`PERF`)
# "RUF", # Ruff-specific rules (`RUF`)
# "FURB", # refurb (`FURB`) - ERROR: Unknown rule selector: `FURB`
# "LOG", # flake8-logging (`LOG`) - ERROR: Unknown rule selector: `LOG`
"RUF", # Ruff-specific rules (`RUF`)
"FURB", # refurb (`FURB`) - ERROR: Unknown rule selector: `FURB`
"LOG", # flake8-logging (`LOG`) - ERROR: Unknown rule selector: `LOG`
]

lint.ignore = [
Expand Down
Loading