modelconv 0.5.2__tar.gz → 0.5.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. {modelconv-0.5.2 → modelconv-0.5.4}/PKG-INFO +7 -4
  2. {modelconv-0.5.2 → modelconv-0.5.4}/modelconv.egg-info/PKG-INFO +7 -4
  3. {modelconv-0.5.2 → modelconv-0.5.4}/modelconv.egg-info/SOURCES.txt +8 -3
  4. {modelconv-0.5.2 → modelconv-0.5.4}/modelconv.egg-info/requires.txt +6 -3
  5. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/__init__.py +1 -1
  6. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/__main__.py +19 -5
  7. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/cli/utils.py +4 -2
  8. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/base_exporter.py +35 -12
  9. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/hailo/requirements.txt +1 -0
  10. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc3/exporter.py +5 -1
  11. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc4/analyze.py +21 -17
  12. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc4/benchmark.py +113 -157
  13. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc4/exporter.py +32 -17
  14. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc4/requirements.txt +1 -0
  15. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/__init__.py +16 -4
  16. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/calibration_data.py +25 -2
  17. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/config.py +90 -38
  18. modelconv-0.5.4/modelconverter/utils/device_handlers.py +357 -0
  19. modelconv-0.5.2/modelconverter/utils/adb_monitor.py → modelconv-0.5.4/modelconverter/utils/device_monitors.py +23 -17
  20. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/docker_utils.py +44 -1
  21. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/nn_archive.py +10 -1
  22. modelconv-0.5.4/modelconverter/utils/onnx_compatibility.py +64 -0
  23. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/onnx_tools.py +24 -20
  24. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/types.py +8 -0
  25. {modelconv-0.5.2 → modelconv-0.5.4}/requirements-analysis.txt +1 -0
  26. {modelconv-0.5.2 → modelconv-0.5.4}/requirements.txt +3 -3
  27. modelconv-0.5.4/tests/test_benchmark/conftest.py +93 -0
  28. modelconv-0.5.4/tests/test_benchmark/test_benchmark_regression.py +279 -0
  29. modelconv-0.5.4/tests/test_utils/__init__.py +0 -0
  30. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_utils/test_config.py +5 -2
  31. modelconv-0.5.4/tests/test_utils/test_onnx_compatibility.py +112 -0
  32. modelconv-0.5.2/modelconverter/utils/adb_handler.py +0 -83
  33. {modelconv-0.5.2 → modelconv-0.5.4}/LICENSE +0 -0
  34. {modelconv-0.5.2 → modelconv-0.5.4}/README.md +0 -0
  35. {modelconv-0.5.2 → modelconv-0.5.4}/modelconv.egg-info/dependency_links.txt +0 -0
  36. {modelconv-0.5.2 → modelconv-0.5.4}/modelconv.egg-info/entry_points.txt +0 -0
  37. {modelconv-0.5.2 → modelconv-0.5.4}/modelconv.egg-info/top_level.txt +0 -0
  38. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/cli/__init__.py +0 -0
  39. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/__init__.py +0 -0
  40. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/base_analyze.py +0 -0
  41. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/base_benchmark.py +0 -0
  42. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/base_inferer.py +0 -0
  43. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/base_visualize.py +0 -0
  44. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/getters.py +0 -0
  45. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/hailo/__init__.py +0 -0
  46. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/hailo/exporter.py +0 -0
  47. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/hailo/inferer.py +0 -0
  48. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/multistage_exporter.py +0 -0
  49. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc2/__init__.py +0 -0
  50. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc2/benchmark.py +0 -0
  51. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc2/exporter.py +0 -0
  52. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc2/inferer.py +0 -0
  53. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc2/requirements.txt +0 -0
  54. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc3/__init__.py +0 -0
  55. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc3/benchmark.py +0 -0
  56. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc3/inferer.py +0 -0
  57. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc3/requirements.txt +0 -0
  58. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc4/__init__.py +0 -0
  59. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc4/inferer.py +0 -0
  60. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/packages/rvc4/visualize.py +0 -0
  61. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/constants.py +0 -0
  62. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/environ.py +0 -0
  63. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/exceptions.py +0 -0
  64. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/filesystem_utils.py +0 -0
  65. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/general.py +0 -0
  66. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/hub_requests.py +0 -0
  67. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/hubai_utils.py +0 -0
  68. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/image.py +0 -0
  69. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/layout.py +0 -0
  70. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/metadata.py +0 -0
  71. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/progress_handler.py +0 -0
  72. {modelconv-0.5.2 → modelconv-0.5.4}/modelconverter/utils/subprocess.py +0 -0
  73. {modelconv-0.5.2 → modelconv-0.5.4}/pyproject.toml +0 -0
  74. {modelconv-0.5.2 → modelconv-0.5.4}/requirements-bench.txt +0 -0
  75. {modelconv-0.5.2 → modelconv-0.5.4}/requirements-dev.txt +0 -0
  76. {modelconv-0.5.2 → modelconv-0.5.4}/setup.cfg +0 -0
  77. {modelconv-0.5.2 → modelconv-0.5.4}/tests/__init__.py +0 -0
  78. {modelconv-0.5.2 → modelconv-0.5.4}/tests/conftest.py +0 -0
  79. {modelconv-0.5.2/tests/test_packages → modelconv-0.5.4/tests/test_benchmark}/__init__.py +0 -0
  80. {modelconv-0.5.2/tests/test_utils → modelconv-0.5.4/tests/test_packages}/__init__.py +0 -0
  81. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/common.py +0 -0
  82. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/metrics/__init__.py +0 -0
  83. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/metrics/base_metric.py +0 -0
  84. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/metrics/mnist_metric.py +0 -0
  85. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/metrics/resnet_metric.py +0 -0
  86. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/metrics/yolov6_metric.py +0 -0
  87. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/onnx_inferer.py +0 -0
  88. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/test_cross_format_export.py +0 -0
  89. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/test_hailo.py +0 -0
  90. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/test_rvc2.py +0 -0
  91. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/test_rvc3.py +0 -0
  92. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_packages/test_rvc4.py +0 -0
  93. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_utils/conftest.py +0 -0
  94. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_utils/test_filesystem.py +0 -0
  95. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_utils/test_image.py +0 -0
  96. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_utils/test_layout.py +0 -0
  97. {modelconv-0.5.2 → modelconv-0.5.4}/tests/test_utils/test_modifier.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modelconv
3
- Version: 0.5.2
3
+ Version: 0.5.4
4
4
  Summary: Converter for neural models into various formats.
5
5
  Author-email: Luxonis <support@luxonis.com>
6
6
  Maintainer-email: Luxonis <support@luxonis.com>
@@ -17,9 +17,9 @@ Requires-Python: >=3.10
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: Pillow
20
- Requires-Dist: luxonis-ml[data,gcs,nn_archive,s3]>=0.8.2
21
- Requires-Dist: cyclopts
22
- Requires-Dist: onnx<1.19.0,>=1.17.0
20
+ Requires-Dist: luxonis-ml[data,gcs,nn_archive,s3]>=0.8.4
21
+ Requires-Dist: cyclopts==4.8.0
22
+ Requires-Dist: onnx==1.21.0
23
23
  Requires-Dist: onnxruntime
24
24
  Requires-Dist: onnxsim
25
25
  Requires-Dist: docker
@@ -33,6 +33,7 @@ Requires-Dist: depthai~=3.0; extra == "bench"
33
33
  Provides-Extra: analysis
34
34
  Requires-Dist: polars; extra == "analysis"
35
35
  Requires-Dist: plotly; extra == "analysis"
36
+ Requires-Dist: depthai~=3.0; extra == "analysis"
36
37
  Provides-Extra: dev
37
38
  Requires-Dist: pre-commit==3.2.1; extra == "dev"
38
39
  Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
@@ -49,12 +50,14 @@ Requires-Dist: psutil; extra == "rvc4"
49
50
  Requires-Dist: numpy<2; extra == "rvc4"
50
51
  Requires-Dist: polars; extra == "rvc4"
51
52
  Requires-Dist: pytest; extra == "rvc4"
53
+ Requires-Dist: onnx==1.18.0; extra == "rvc4"
52
54
  Provides-Extra: hailo
53
55
  Requires-Dist: nvidia-dali-cuda120==1.49.0; extra == "hailo"
54
56
  Requires-Dist: nvidia-dali-tf-plugin-cuda120==1.49.0; extra == "hailo"
55
57
  Requires-Dist: protobuf==3.20.3; extra == "hailo"
56
58
  Requires-Dist: matplotlib==3.10.6; extra == "hailo"
57
59
  Requires-Dist: pyparsing==2.4.7; extra == "hailo"
60
+ Requires-Dist: onnx==1.17.0; extra == "hailo"
58
61
  Dynamic: license-file
59
62
 
60
63
  # ModelConverter - Compilation Library
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modelconv
3
- Version: 0.5.2
3
+ Version: 0.5.4
4
4
  Summary: Converter for neural models into various formats.
5
5
  Author-email: Luxonis <support@luxonis.com>
6
6
  Maintainer-email: Luxonis <support@luxonis.com>
@@ -17,9 +17,9 @@ Requires-Python: >=3.10
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: Pillow
20
- Requires-Dist: luxonis-ml[data,gcs,nn_archive,s3]>=0.8.2
21
- Requires-Dist: cyclopts
22
- Requires-Dist: onnx<1.19.0,>=1.17.0
20
+ Requires-Dist: luxonis-ml[data,gcs,nn_archive,s3]>=0.8.4
21
+ Requires-Dist: cyclopts==4.8.0
22
+ Requires-Dist: onnx==1.21.0
23
23
  Requires-Dist: onnxruntime
24
24
  Requires-Dist: onnxsim
25
25
  Requires-Dist: docker
@@ -33,6 +33,7 @@ Requires-Dist: depthai~=3.0; extra == "bench"
33
33
  Provides-Extra: analysis
34
34
  Requires-Dist: polars; extra == "analysis"
35
35
  Requires-Dist: plotly; extra == "analysis"
36
+ Requires-Dist: depthai~=3.0; extra == "analysis"
36
37
  Provides-Extra: dev
37
38
  Requires-Dist: pre-commit==3.2.1; extra == "dev"
38
39
  Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
@@ -49,12 +50,14 @@ Requires-Dist: psutil; extra == "rvc4"
49
50
  Requires-Dist: numpy<2; extra == "rvc4"
50
51
  Requires-Dist: polars; extra == "rvc4"
51
52
  Requires-Dist: pytest; extra == "rvc4"
53
+ Requires-Dist: onnx==1.18.0; extra == "rvc4"
52
54
  Provides-Extra: hailo
53
55
  Requires-Dist: nvidia-dali-cuda120==1.49.0; extra == "hailo"
54
56
  Requires-Dist: nvidia-dali-tf-plugin-cuda120==1.49.0; extra == "hailo"
55
57
  Requires-Dist: protobuf==3.20.3; extra == "hailo"
56
58
  Requires-Dist: matplotlib==3.10.6; extra == "hailo"
57
59
  Requires-Dist: pyparsing==2.4.7; extra == "hailo"
60
+ Requires-Dist: onnx==1.17.0; extra == "hailo"
58
61
  Dynamic: license-file
59
62
 
60
63
  # ModelConverter - Compilation Library
@@ -45,11 +45,11 @@ modelconverter/packages/rvc4/inferer.py
45
45
  modelconverter/packages/rvc4/requirements.txt
46
46
  modelconverter/packages/rvc4/visualize.py
47
47
  modelconverter/utils/__init__.py
48
- modelconverter/utils/adb_handler.py
49
- modelconverter/utils/adb_monitor.py
50
48
  modelconverter/utils/calibration_data.py
51
49
  modelconverter/utils/config.py
52
50
  modelconverter/utils/constants.py
51
+ modelconverter/utils/device_handlers.py
52
+ modelconverter/utils/device_monitors.py
53
53
  modelconverter/utils/docker_utils.py
54
54
  modelconverter/utils/environ.py
55
55
  modelconverter/utils/exceptions.py
@@ -61,12 +61,16 @@ modelconverter/utils/image.py
61
61
  modelconverter/utils/layout.py
62
62
  modelconverter/utils/metadata.py
63
63
  modelconverter/utils/nn_archive.py
64
+ modelconverter/utils/onnx_compatibility.py
64
65
  modelconverter/utils/onnx_tools.py
65
66
  modelconverter/utils/progress_handler.py
66
67
  modelconverter/utils/subprocess.py
67
68
  modelconverter/utils/types.py
68
69
  tests/__init__.py
69
70
  tests/conftest.py
71
+ tests/test_benchmark/__init__.py
72
+ tests/test_benchmark/conftest.py
73
+ tests/test_benchmark/test_benchmark_regression.py
70
74
  tests/test_packages/__init__.py
71
75
  tests/test_packages/common.py
72
76
  tests/test_packages/onnx_inferer.py
@@ -86,4 +90,5 @@ tests/test_utils/test_config.py
86
90
  tests/test_utils/test_filesystem.py
87
91
  tests/test_utils/test_image.py
88
92
  tests/test_utils/test_layout.py
89
- tests/test_utils/test_modifier.py
93
+ tests/test_utils/test_modifier.py
94
+ tests/test_utils/test_onnx_compatibility.py
@@ -1,7 +1,7 @@
1
1
  Pillow
2
- luxonis-ml[data,gcs,nn_archive,s3]>=0.8.2
3
- cyclopts
4
- onnx<1.19.0,>=1.17.0
2
+ luxonis-ml[data,gcs,nn_archive,s3]>=0.8.4
3
+ cyclopts==4.8.0
4
+ onnx==1.21.0
5
5
  onnxruntime
6
6
  onnxsim
7
7
  docker
@@ -14,6 +14,7 @@ psutil
14
14
  [analysis]
15
15
  polars
16
16
  plotly
17
+ depthai~=3.0
17
18
 
18
19
  [bench]
19
20
  depthai~=3.0
@@ -29,6 +30,7 @@ nvidia-dali-tf-plugin-cuda120==1.49.0
29
30
  protobuf==3.20.3
30
31
  matplotlib==3.10.6
31
32
  pyparsing==2.4.7
33
+ onnx==1.17.0
32
34
 
33
35
  [rvc2]
34
36
  tflite2onnx
@@ -44,3 +46,4 @@ psutil
44
46
  numpy<2
45
47
  polars
46
48
  pytest
49
+ onnx==1.18.0
@@ -4,7 +4,7 @@ from typing import Final
4
4
  from luxonis_ml.utils import PUT_FILE_REGISTRY
5
5
  from pydantic_extra_types.semantic_version import SemanticVersion
6
6
 
7
- __version__: Final[str] = "0.5.2"
7
+ __version__: Final[str] = "0.5.4"
8
8
  __semver__: Final[SemanticVersion] = SemanticVersion.parse(__version__)
9
9
 
10
10
 
@@ -33,6 +33,8 @@ from modelconverter.utils import (
33
33
  archive_from_model,
34
34
  docker_build,
35
35
  docker_exec,
36
+ get_default_target_version,
37
+ get_local_docker_image,
36
38
  in_docker,
37
39
  resolve_path,
38
40
  upload_to_remote,
@@ -127,7 +129,7 @@ def convert(
127
129
 
128
130
  with catch_exceptions():
129
131
  init_dirs()
130
- cfg, archive_cfg, _main_stage = get_configs(path, opts)
132
+ cfg, archive_cfg, _main_stage = get_configs(target, path, opts)
131
133
  main_stage = main_stage or _main_stage
132
134
  is_multistage = len(cfg.stages) > 1
133
135
  if is_multistage and main_stage is None:
@@ -264,7 +266,7 @@ def infer(
264
266
  if path is not None:
265
267
  config = path
266
268
  with catch_exceptions():
267
- mult_cfg, _, _ = get_configs(str(config), opts)
269
+ mult_cfg, _, _ = get_configs(target, str(config), opts)
268
270
  cfg = mult_cfg.get_stage_config(stage)
269
271
  setup_logging(
270
272
  file="modelconverter.log", use_rich=mult_cfg.rich_logging
@@ -630,9 +632,21 @@ def launcher(
630
632
  target = bound.arguments["target"]
631
633
 
632
634
  if dev:
633
- docker_build(
634
- target.value, bare_tag=tag, version=tool_version, image=image
635
- )
635
+ version = tool_version or get_default_target_version(target.value)
636
+ # CI invokes multiple dev docker commands per job; reuse the first
637
+ # local build so later commands don't rebuild the same image again.
638
+ if not (
639
+ os.getenv("CI") == "true"
640
+ and get_local_docker_image(
641
+ target.value,
642
+ bare_tag=tag,
643
+ version=version,
644
+ image=image,
645
+ )
646
+ ):
647
+ docker_build(
648
+ target.value, bare_tag=tag, version=version, image=image
649
+ )
636
650
 
637
651
  docker_exec(
638
652
  target.value,
@@ -72,7 +72,9 @@ def init_dirs() -> None:
72
72
 
73
73
 
74
74
  def get_configs(
75
- path: str | None, opts: list[str] | dict[str, Any] | None = None
75
+ target: Target,
76
+ path: str | None,
77
+ opts: list[str] | dict[str, Any] | None = None,
76
78
  ) -> tuple[Config, NNArchiveConfig | None, str | None]:
77
79
  """Sets up the configuration.
78
80
 
@@ -99,7 +101,7 @@ def get_configs(
99
101
  if path is not None:
100
102
  path_ = resolve_path(path, MISC_DIR)
101
103
  if path_.is_dir() or is_nn_archive(path_):
102
- return process_nn_archive(path_, overrides)
104
+ return process_nn_archive(target, path_, overrides)
103
105
  cfg = Config.get_config(path, overrides)
104
106
 
105
107
  main_stage_key = None
@@ -5,8 +5,8 @@ from importlib.metadata import version
5
5
  from pathlib import Path
6
6
  from typing import Any
7
7
 
8
+ import cv2
8
9
  import numpy as np
9
- import onnx
10
10
  from loguru import logger
11
11
 
12
12
  from modelconverter.utils import (
@@ -20,6 +20,7 @@ from modelconverter.utils.config import (
20
20
  RandomCalibrationConfig,
21
21
  SingleStageConfig,
22
22
  )
23
+ from modelconverter.utils.onnx_compatibility import save_onnx_model
23
24
  from modelconverter.utils.subprocess import SubprocessResult
24
25
  from modelconverter.utils.types import InputFileType, Target
25
26
 
@@ -129,7 +130,13 @@ class Exporter(ABC):
129
130
  )
130
131
  return self.input_model
131
132
 
132
- onnx_sim, check = simplify(str(self.input_model))
133
+ try:
134
+ onnx_sim, check = simplify(str(self.input_model))
135
+ except Exception as e:
136
+ logger.warning(
137
+ f"Failed to simplify ONNX: {e}. Proceeding without simplification."
138
+ )
139
+ return self.input_model
133
140
  if not check:
134
141
  logger.warning(
135
142
  "Provided ONNX could not be simplified. "
@@ -141,15 +148,14 @@ class Exporter(ABC):
141
148
  self.input_model, "simplified.onnx"
142
149
  )
143
150
  logger.info(f"Saving simplified ONNX to {onnx_sim_path}")
144
- if self.input_model.with_suffix(".onnx_data").exists():
145
- onnx.save(
146
- onnx_sim,
147
- str(onnx_sim_path),
148
- save_as_external_data=True,
149
- location=f"{onnx_sim_path.name}_data",
150
- )
151
- else:
152
- onnx.save(onnx_sim, str(onnx_sim_path))
151
+ save_onnx_model(
152
+ onnx_sim,
153
+ onnx_sim_path,
154
+ save_as_external_data=self.input_model.with_suffix(
155
+ ".onnx_data"
156
+ ).exists(),
157
+ location=f"{onnx_sim_path.name}_data",
158
+ )
153
159
  return onnx_sim_path
154
160
 
155
161
  @abstractmethod
@@ -220,7 +226,24 @@ class Exporter(ABC):
220
226
  arr = np.clip(arr, calib.min_value, calib.max_value)
221
227
 
222
228
  arr = arr.astype(calib.data_type.as_numpy_dtype())
223
- np.save(dest / f"{i}.npy", arr)
229
+ if len(arr.shape) in {2, 3} or (
230
+ len(arr.shape) in {3, 4} and arr.shape[0] == 1
231
+ ):
232
+ layout = inp.layout
233
+ if arr.shape[0] == 1 and len(arr.shape) > 2:
234
+ arr = arr.squeeze(0)
235
+ if layout is not None:
236
+ layout = layout[1:]
237
+
238
+ if layout is not None and "C" in layout:
239
+ channel_dim = layout.index("C")
240
+ if channel_dim == 0 and len(arr.shape) == 3:
241
+ arr = arr.transpose(1, 2, 0)
242
+ elif arr.shape[0] in {1, 3}: # type: ignore
243
+ arr = arr.transpose(1, 2, 0)
244
+ cv2.imwrite(str(dest / f"{i}.png"), arr)
245
+ else:
246
+ np.save(dest / f"{i}.npy", arr)
224
247
 
225
248
  self.inputs[name].calibration = ImageCalibrationConfig(path=dest)
226
249
 
@@ -3,3 +3,4 @@ nvidia-dali-tf-plugin-cuda120==1.49.0
3
3
  protobuf==3.20.3
4
4
  matplotlib==3.10.6
5
5
  pyparsing==2.4.7
6
+ onnx==1.17.0 # Hailo SDK still imports onnx.mapping and still pins protobuf==3.20.3.
@@ -31,6 +31,7 @@ class RVC3Exporter(RVC2Exporter):
31
31
  self.mo_args = config.rvc3.mo_args
32
32
  self.compile_tool_args = config.rvc3.compile_tool_args
33
33
  self.device = "VPUX.3400"
34
+ self.reverse_input_channels = False
34
35
  self._device_specific_buildinfo = {}
35
36
 
36
37
  def export(self) -> Path:
@@ -106,7 +107,10 @@ class RVC3Exporter(RVC2Exporter):
106
107
  data_type=DataType.UINT8,
107
108
  transpose=False,
108
109
  )
109
- cv2.imwrite(str(calibration_img_dir / file.name), img)
110
+ suffix = ".png" if file.suffix == ".npy" else file.suffix
111
+ cv2.imwrite(
112
+ str((calibration_img_dir / file.stem).with_suffix(suffix)), img
113
+ )
110
114
 
111
115
  config = {
112
116
  "model": {
@@ -14,7 +14,7 @@ from PIL import Image
14
14
 
15
15
  from modelconverter.packages.base_analyze import Analyzer
16
16
  from modelconverter.packages.rvc4.benchmark import get_device_info
17
- from modelconverter.utils import AdbHandler, constants, subprocess_run
17
+ from modelconverter.utils import constants, create_handler, subprocess_run
18
18
 
19
19
 
20
20
  class RVC4Analyzer(Analyzer):
@@ -27,7 +27,7 @@ class RVC4Analyzer(Analyzer):
27
27
  ):
28
28
  super().__init__(dlc_model_path, image_dirs)
29
29
  _, device_adb_id = get_device_info(device_ip, device_id)
30
- self.adb = AdbHandler(device_adb_id)
30
+ self.handler = create_handler(device_ip, device_adb_id)
31
31
 
32
32
  def analyze_layer_outputs(self, onnx_model_path: Path) -> None:
33
33
  input_matcher = self._prepare_input_matcher()
@@ -76,8 +76,8 @@ class RVC4Analyzer(Analyzer):
76
76
  self, input_matcher: dict[str, dict[str, str]], type: type = np.uint8
77
77
  ) -> dict[str, str]:
78
78
  logger.info("Preparing raw inputs for RVC4 analysis.")
79
- self.adb.shell(f"rm -rf /data/modelconverter/{self.model_name}")
80
- self.adb.shell(
79
+ self.handler.shell(f"rm -rf /data/modelconverter/{self.model_name}")
80
+ self.handler.shell(
81
81
  f"mkdir -p /data/modelconverter/{self.model_name}/inputs"
82
82
  )
83
83
 
@@ -109,7 +109,7 @@ class RVC4Analyzer(Analyzer):
109
109
 
110
110
  with tempfile.NamedTemporaryFile() as f:
111
111
  raw_image.tofile(f)
112
- self.adb.push(
112
+ self.handler.push(
113
113
  f.name,
114
114
  f"/data/modelconverter/{self.model_name}/inputs/{input_name}_{img_name}.raw",
115
115
  )
@@ -122,7 +122,7 @@ class RVC4Analyzer(Analyzer):
122
122
  with tempfile.NamedTemporaryFile() as f:
123
123
  f.write(input_list.encode())
124
124
  f.flush()
125
- self.adb.push(
125
+ self.handler.push(
126
126
  f.name,
127
127
  f"/data/modelconverter/{self.model_name}/input_list.txt",
128
128
  )
@@ -133,8 +133,12 @@ class RVC4Analyzer(Analyzer):
133
133
  return dlc_matcher
134
134
 
135
135
  def _add_outputs_to_all_layers(self, onnx_file_path: str) -> Path:
136
- if Path(onnx_file_path.replace(".onnx", "-all-layers.onnx")).exists():
137
- Path(onnx_file_path.replace(".onnx", "-all-layers.onnx")).unlink()
136
+ onnx_path = Path(onnx_file_path)
137
+ all_output_path = onnx_path.with_name(
138
+ f"{onnx_path.stem}-all-layers{onnx_path.suffix}"
139
+ )
140
+ if all_output_path.exists():
141
+ all_output_path.unlink()
138
142
 
139
143
  model = onnx.load(onnx_file_path)
140
144
  onnx.checker.check_model(model)
@@ -152,10 +156,10 @@ class RVC4Analyzer(Analyzer):
152
156
 
153
157
  for output in orig_graph_output:
154
158
  graph.output.append(output)
155
- all_output_name = onnx_file_path.replace(".onnx", "-all-layers.onnx")
156
- onnx.save(model, all_output_name)
159
+ all_output_path.parent.mkdir(parents=True, exist_ok=True)
160
+ onnx.save(model, all_output_path)
157
161
 
158
- return Path(all_output_name)
162
+ return all_output_path
159
163
 
160
164
  def transpose_to_match(
161
165
  self, src: np.ndarray, target_shape: tuple[int, ...]
@@ -321,14 +325,14 @@ class RVC4Analyzer(Analyzer):
321
325
  def _run_dlc(self, command: str) -> str:
322
326
  logger.info("Inferencing DLC model on device.")
323
327
  try:
324
- self.adb.push(
328
+ self.handler.push(
325
329
  str(self.dlc_model_path),
326
330
  f"/data/modelconverter/{self.model_name}/{self.model_name}.dlc",
327
331
  )
328
- self.adb.shell(
332
+ self.handler.shell(
329
333
  f"rm -rf /data/modelconverter/{self.model_name}/output"
330
334
  )
331
- self.adb.shell(
335
+ self.handler.shell(
332
336
  f"cd /data/modelconverter/{self.model_name} && {command}"
333
337
  )
334
338
 
@@ -337,7 +341,7 @@ class RVC4Analyzer(Analyzer):
337
341
  shutil.rmtree(target_dir / "output")
338
342
 
339
343
  target_dir.mkdir(parents=True, exist_ok=True)
340
- self.adb.pull(
344
+ self.handler.pull(
341
345
  f"/data/modelconverter/{self.model_name}/output",
342
346
  f"{target_dir}/output",
343
347
  )
@@ -397,7 +401,7 @@ class RVC4Analyzer(Analyzer):
397
401
 
398
402
  logger.info("Running DLC model to analyze layer cycles.")
399
403
  output_dir = self._run_dlc(
400
- f"snpe-net-run --container {self.model_name}.dlc --input_list input_list.txt --use_dsp --use_native_input_files --use_native_output_files --perf_profile balanced --userbuffer_tf8"
404
+ f"snpe-net-run --container {self.model_name}.dlc --input_list input_list.txt --use_dsp --use_native_input_files --use_native_output_files --perf_profile balanced --userbuffer_auto"
401
405
  )
402
406
 
403
407
  csv_path = Path(output_dir + "/layer_stats.csv")
@@ -456,7 +460,7 @@ class RVC4Analyzer(Analyzer):
456
460
 
457
461
  # cleanup
458
462
  def _cleanup_dlc_outputs(self) -> None:
459
- self.adb.shell(f"rm -rf /data/modelconverter/{self.model_name}")
463
+ self.handler.shell(f"rm -rf /data/modelconverter/{self.model_name}")
460
464
 
461
465
  output_dir = Path(
462
466
  f"{constants.OUTPUTS_DIR!s}/analysis/{self.model_name}/output"