Skip to content

Commit c5d0dbe

Browse files
🧹 Enable more ruff rules (#221)
* enable pycodestyle Signed-off-by: Ashwin Vaidya <[email protected]> * enable more rules Signed-off-by: Ashwin Vaidya <[email protected]> * disable pyupgrade Signed-off-by: Ashwin Vaidya <[email protected]> * Fix incorrect type check in ListValue validation Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent 23620d1 commit c5d0dbe

File tree

16 files changed

+99
-58
lines changed

16 files changed

+99
-58
lines changed

model_api/python/model_api/adapters/inference_adapter.py

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

66
from abc import ABC, abstractmethod
77
from dataclasses import dataclass, field
8-
from typing import Any, Dict, List, Set, Tuple
8+
from typing import Any
99

1010

1111
@dataclass

model_api/python/model_api/adapters/openvino_adapter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def await_any(self) -> None:
301301
def _get_meta_from_ngraph(self, layers_info):
302302
for node in self.model.get_ordered_ops():
303303
layer_name = node.get_friendly_name()
304-
if layer_name not in layers_info.keys():
304+
if layer_name not in layers_info:
305305
continue
306306
layers_info[layer_name].meta = node.get_attributes()
307307
layers_info[layer_name].type = node.get_type_name()
@@ -339,9 +339,9 @@ def embed_preprocessing(
339339
ppp = PrePostProcessor(self.model)
340340

341341
# Change the input type to the 8-bit image
342-
if dtype == int:
342+
if dtype is int:
343343
ppp.input(input_idx).tensor().set_element_type(Type.u8)
344-
elif dtype == float:
344+
elif dtype is float:
345345
ppp.input(input_idx).tensor().set_element_type(Type.f32)
346346

347347
ppp.input(input_idx).tensor().set_layout(ov.Layout("NHWC")).set_color_format(

model_api/python/model_api/adapters/ovms_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def _verify_model_available(client, model_name, model_version):
185185
def _prepare_inputs(dict_data, inputs_meta):
186186
inputs = {}
187187
for input_name, input_data in dict_data.items():
188-
if input_name not in inputs_meta.keys():
188+
if input_name not in inputs_meta:
189189
raise ValueError("Input data does not match model inputs")
190190
input_info = inputs_meta[input_name]
191191
model_precision = _tf2np_precision[input_info["dtype"]]

model_api/python/model_api/adapters/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from __future__ import annotations # TODO: remove when Python3.9 support is dropped
77

88
import math
9+
from collections.abc import Callable
910
from functools import partial
10-
from typing import Callable, Optional
1111

1212
import cv2
1313
import numpy as np

model_api/python/model_api/models/action_classification.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ def parameters(cls) -> dict[str, Any]:
9999
description="Path to file with labels. Overrides the labels, if they sets via 'labels' parameter",
100100
),
101101
"mean_values": ListValue(
102-
description="Normalization values, which will be subtracted from image channels for image-input layer during preprocessing",
102+
description=(
103+
"Normalization values, which will be subtracted from image channels "
104+
"for image-input layer during preprocessing"
105+
),
103106
default_value=[],
104107
),
105108
"pad_value": NumericalValue(

model_api/python/model_api/models/classification.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,11 @@ def resolve_labels(self, predictions):
374374
"""
375375

376376
def get_predecessors(lbl, candidates):
377-
"""Returns all the predecessors of the input label or an empty list if one of the predecessors is not a candidate."""
377+
"""Return all predecessors.
378+
379+
Returns all the predecessors of the input label or an empty list if one of the predecessors is not a
380+
candidate.
381+
"""
378382
predecessors = []
379383

380384
last_parent = self.label_tree.get_parent(lbl)
@@ -517,7 +521,8 @@ def _resolve_exclusive_labels(
517521
For labels in `label_to_probability` sets labels that are most likely (maximum probability) in their exclusive
518522
group to 1.0 and other (non-max) labels to probability 0.
519523
"""
520-
# actual exclusive group selection should happen when extracting initial probs (apply argmax to exclusive groups)
524+
# actual exclusive group selection should happen when extracting initial probs
525+
# (apply argmax to exclusive groups)
521526
hard_classification = {}
522527
for label, probability in label_to_probability.items():
523528
hard_classification[label] = float(probability > 0.0)

model_api/python/model_api/models/image_model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ def parameters(cls):
9090
default_value=False,
9191
),
9292
"mean_values": ListValue(
93-
description="Normalization values, which will be subtracted from image channels for image-input layer during preprocessing",
93+
description=(
94+
"Normalization values, which will be subtracted from image "
95+
"channels for image-input layer during preprocessing"
96+
),
9497
default_value=[],
9598
),
9699
"orig_height": NumericalValue(

model_api/python/model_api/models/instance_segmentation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ def postprocess(self, outputs, meta):
207207
output_mask,
208208
),
209209
)
210-
if has_feature_vector_name:
211-
if confidence > self.confidence_threshold:
212-
saliency_maps[cls - 1].append(resized_mask)
210+
if has_feature_vector_name and confidence > self.confidence_threshold:
211+
saliency_maps[cls - 1].append(resized_mask)
213212
return InstanceSegmentationResult(
214213
objects,
215214
_average_and_normalize(saliency_maps),

model_api/python/model_api/models/model.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import logging as log
77
import re
8-
from abc import ABC
98
from contextlib import contextmanager
109

1110
from model_api.adapters.inference_adapter import InferenceAdapter
@@ -135,9 +134,11 @@ def create_model(
135134
136135
Args:
137136
model (str): model name from OpenVINO Model Zoo, path to model, OVMS URL
138-
configuration (:obj:`dict`, optional): dictionary of model config with model properties, for example confidence_threshold, labels
137+
configuration (:obj:`dict`, optional): dictionary of model config with model properties, for example
138+
confidence_threshold, labels
139139
model_type (:obj:`str`, optional): name of model wrapper to create (e.g. "ssd")
140-
preload (:obj:`bool`, optional): whether to call load_model(). Can be set to false to reshape model before loading
140+
preload (:obj:`bool`, optional): whether to call load_model(). Can be set to false to reshape model before
141+
loading.
141142
core (optional): openvino.Core instance, passed to OpenvinoAdapter
142143
weights_path (:obj:`str`, optional): path to .bin file with model weights
143144
adaptor_parameters (:obj:`dict`, optional): parameters of ModelAdaptor
@@ -147,7 +148,8 @@ def create_model(
147148
max_num_requests (:obj:`int`, optional): number of infer requests for asynchronous inference
148149
precision (:obj:`str`, optional): inference precision (e.g. "FP16")
149150
download_dir (:obj:`str`, optional): directory where to store downloaded models
150-
cache_dir (:obj:`str`, optional): directory where to store compiled models to reduce the load time before the inference
151+
cache_dir (:obj:`str`, optional): directory where to store compiled models to reduce the load time before
152+
the inference.
151153
152154
Returns:
153155
Model object
@@ -482,11 +484,13 @@ def log_layers_info(self):
482484
"""Prints the shape, precision and layout for all model inputs/outputs."""
483485
for name, metadata in self.inputs.items():
484486
self.logger.info(
485-
f"\tInput layer: {name}, shape: {metadata.shape}, precision: {metadata.precision}, layout: {metadata.layout}",
487+
f"\tInput layer: {name}, shape: {metadata.shape}, "
488+
f"precision: {metadata.precision}, layout: {metadata.layout}",
486489
)
487490
for name, metadata in self.outputs.items():
488491
self.logger.info(
489-
f"\tOutput layer: {name}, shape: {metadata.shape}, precision: {metadata.precision}, layout: {metadata.layout}",
492+
f"\tOutput layer: {name}, shape: {metadata.shape}, "
493+
f"precision: {metadata.precision}, layout: {metadata.layout}",
490494
)
491495

492496
def save(self, xml_path, bin_path="", version="UNSPECIFIED"):

model_api/python/model_api/models/segmentation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ def parameters(cls):
9999
),
100100
"soft_threshold": NumericalValue(
101101
value_type=float,
102-
description="Probability threshold value for bounding box filtering. inf value means no blurring and no soft_threshold",
102+
description=(
103+
"Probability threshold value for bounding box filtering. "
104+
"inf value means no blurring and no soft_threshold"
105+
),
103106
default_value=float("-inf"),
104107
),
105108
"return_soft_prediction": BooleanValue(

0 commit comments

Comments
 (0)