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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.4
rev: v0.15.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -18,11 +18,11 @@ repos:
args: [--in-place, --black, --style=epytext]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.22
rev: 1.0.0
hooks:
- id: mdformat
additional_dependencies:
- mdformat-gfm==0.3.6
- mdformat-gfm

- repo: https://github.com/ComPWA/taplo-pre-commit
rev: v0.9.3
Expand All @@ -31,7 +31,7 @@ repos:
- id: taplo-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: check-docstring-first
Expand Down
4 changes: 3 additions & 1 deletion modelconverter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@

app = App(
name="Modelconverter",
version=lambda: f"ModelConverter v{importlib.metadata.version('modelconv')}",
version=lambda: (
f"ModelConverter v{importlib.metadata.version('modelconv')}"
),
)

app.meta.group_parameters = Group("Global Parameters", sort_key=0)
Expand Down
4 changes: 1 addition & 3 deletions modelconverter/packages/rvc2/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def _benchmark(
model_path,
platform=device.getPlatformAsString(),
),
apiKey=environ.HUBAI_API_KEY
if environ.HUBAI_API_KEY
else "",
apiKey=environ.HUBAI_API_KEY or "",
)
)
elif (
Expand Down
4 changes: 1 addition & 3 deletions modelconverter/packages/rvc4/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,7 @@ def _process_diagview_csv(self, csv_path: str) -> None:
pl.col("layer_name")
.str.split(":")
.list.first()
.map_elements(
lambda x: self._replace_bad_layer_name(x), return_dtype=pl.Utf8
)
.map_elements(self._replace_bad_layer_name, return_dtype=pl.Utf8)
.alias("layer_name"),
pl.col("time_mean")
.mul(1 / total_time)
Expand Down
4 changes: 2 additions & 2 deletions modelconverter/packages/rvc4/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _benchmark_snpe(
model_path,
platform=dai.Platform.RVC4.name,
),
apiKey=environ.HUBAI_API_KEY if environ.HUBAI_API_KEY else "",
apiKey=environ.HUBAI_API_KEY or "",
)
tmp_dir = Path(model_archive).parent / "tmp"
shutil.unpack_archive(model_archive, tmp_dir)
Expand Down Expand Up @@ -413,7 +413,7 @@ def _benchmark_dai(
model_path,
platform=device.getPlatformAsString(),
),
apiKey=environ.HUBAI_API_KEY if environ.HUBAI_API_KEY else "",
apiKey=environ.HUBAI_API_KEY or "",
)
elif str(model_path).endswith(".tar.xz"):
modelPath = str(model_path)
Expand Down
2 changes: 1 addition & 1 deletion modelconverter/packages/rvc4/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _visualize_layer_outputs(self) -> go.Figure:
def _get_csv_paths(
self, dir_path: Path, comparison_type: str = "layer_comparison"
) -> dict[str, str]:
dir_path = dir_path if dir_path else constants.OUTPUTS_DIR / "analysis"
dir_path = dir_path or constants.OUTPUTS_DIR / "analysis"
csv_paths = {}

for file in dir_path.glob(f"*{comparison_type}*.csv"):
Expand Down
2 changes: 1 addition & 1 deletion modelconverter/utils/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

import psutil
import yaml
from docker.utils import parse_repository_tag
from loguru import logger
from luxonis_ml.utils import environ
from rich.progress import BarColumn, Progress, TaskProgressColumn, TextColumn

import docker
from docker.utils import parse_repository_tag


def get_docker_client_from_active_context() -> docker.DockerClient:
Expand Down Expand Up @@ -217,7 +217,7 @@
tmp_path: Path | None = None
try:
request = Request(url, headers={"User-Agent": "modelconverter"}) # noqa: S310
with urlopen(request, timeout=30) as response: # noqa: S310

Check failure on line 220 in modelconverter/utils/docker_utils.py

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

Detected a dynamic value being used with urllib. urllib supports 'file://' schemes, so a dynamic value controlled by a malicious actor may allow them to read arbitrary files. Audit uses of urllib calls to ensure user data cannot control the URLs, or consider using the 'requests' library instead.
if getattr(response, "status", 200) >= 400:
raise RuntimeError(
f"HTTP {response.status} while downloading {url}"
Expand Down
20 changes: 11 additions & 9 deletions modelconverter/utils/onnx_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def get_extra_quant_tensors(
output_configs: dict[str, OutputConfig],
depth: int = 2,
) -> list[str]:
"""Return unique tensor names that are inputs to producer nodes encountered when walking upstream from the selected graph outputs, up to depth producer hops.
"""Return unique tensor names that are inputs to producer nodes
encountered when walking upstream from the selected graph outputs,
up to depth producer hops.

- Starts from graph outputs whose names are keys in output_configs.
- At each hop: for each tensor, find its producing node; add that node's
Expand Down Expand Up @@ -1398,21 +1400,21 @@ def compare_outputs(self, from_modelproto: bool = False) -> bool:

inputs = {}
for input in ort_session_1.get_inputs():
if input.type in ["tensor(float64)"]:
if input.type == "tensor(float64)":
input_type = np.float64
elif input.type in ["tensor(float32)", "tensor(float)"]:
elif input.type in {"tensor(float32)", "tensor(float)"}:
input_type = np.float32
elif input.type in ["tensor(float16)"]:
elif input.type == "tensor(float16)":
input_type = np.float16
elif input.type in ["tensor(int64)"]:
elif input.type == "tensor(int64)":
input_type = np.int64
elif input.type in ["tensor(int32)"]:
elif input.type == "tensor(int32)":
input_type = np.int32
elif input.type in ["tensor(int16)"]:
elif input.type == "tensor(int16)":
input_type = np.int16
elif input.type in ["tensor(int8)"]:
elif input.type == "tensor(int8)":
input_type = np.int8
elif input.type in ["tensor(bool)"]:
elif input.type == "tensor(bool)":
input_type = "bool"

inputs[input.name] = np.random.rand(*input.shape).astype(
Expand Down
3 changes: 2 additions & 1 deletion modelconverter/utils/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import psutil
from loguru import logger
from typing_extensions import Self

from .exceptions import SubprocessException

Expand Down Expand Up @@ -161,7 +162,7 @@
"""
return self.proc.wait(timeout=self.timeout or timeout)

def __enter__(self) -> "SubprocessHandle":
def __enter__(self) -> Self:
if shutil.which(self.cmd_name) is None:
raise SubprocessException(
f"Command `{self.cmd_name}` not found. Ensure it is in PATH."
Expand All @@ -171,7 +172,7 @@
logger.info(f"Executing `{' '.join(self.cmd)}`")

self._start_time = time.time()
self._proc = subprocess.Popen(

Check failure on line 175 in modelconverter/utils/subprocess.py

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

the `encoding` argument to Popen is only available on Python 3.6+

Check failure on line 175 in modelconverter/utils/subprocess.py

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

the `errors` argument to Popen is only available on Python 3.6+
self.cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down
Loading