Skip to content

Commit 6be2167

Browse files
authored
Create onnxvis entry point; fix when main graph does not have a name (#22)
Also fixed a bug when the main graph does not have a name
1 parent dceb257 commit 6be2167

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,7 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161+
162+
*.onnx
163+
*.textproto
164+
*.pb

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ pip install --upgrade model-explorer-onnx
1414

1515
```bash
1616
model-explorer --extensions=model_explorer_onnx
17+
18+
# Or as a shortcut
19+
onnxvis
20+
21+
# Supply model path
22+
onnxvis model.onnx
1723
```
1824

1925
## Screenshots
@@ -29,4 +35,3 @@ model-explorer --extensions=model_explorer_onnx
2935
<img width="1293" alt="image" src="https://github.com/justinchuby/model-explorer-onnx/assets/11205048/fbf2fa05-bd29-4938-93d1-709690d9f9c6">
3036

3137
<img width="1301" alt="image" src="https://github.com/justinchuby/model-explorer-onnx/assets/11205048/a68f7ecd-1fa1-4eac-9e1f-8e9a5bbf9fe3">
32-

pyproject.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ description = "Adapter for ai-edge-model-explorer to support ONNX models"
99
authors = [{ name = "Justin Chu", email = "[email protected]" }]
1010
readme = "README.md"
1111
requires-python = ">=3.8"
12-
license = { file = "LICENSE" }
12+
license = {text = "MIT License"}
13+
keywords = ["onnx", "model-explorer", "visualization"]
1314
classifiers = [
14-
"Development Status :: 3 - Alpha",
15-
"Environment :: Console",
15+
"Development Status :: 4 - Beta",
1616
"Intended Audience :: Developers",
1717
"Operating System :: POSIX",
1818
"Operating System :: MacOS :: MacOS X",
@@ -33,5 +33,8 @@ dependencies = [
3333
"ml_dtypes",
3434
]
3535

36+
[project.scripts]
37+
onnxvis = "model_explorer_onnx.bin.onnxvis:main"
38+
3639
[project.urls]
3740
Repository = "https://github.com/justinchuby/model-explorer-onnx"

src/model_explorer_onnx/bin/__init__.py

Whitespace-only changes.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
"""A shortcut to run model explorer with ONNX extension."""
3+
4+
import subprocess
5+
import sys
6+
7+
8+
def main():
9+
# Run model explorer
10+
subprocess.run(
11+
[
12+
"model-explorer",
13+
"--extensions",
14+
"model_explorer_onnx",
15+
*sys.argv[1:],
16+
]
17+
)
18+
19+
20+
if __name__ == "__main__":
21+
main()

src/model_explorer_onnx/main.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,16 @@ def convert(
482482
if opset_version is None:
483483
opset_version = _DEFAULT_OPSET_VERSION
484484
# TODO: Better support subgraphs in nodes
485+
if model.graph.name is None:
486+
model.graph.name = "<main>"
487+
logger.warning(
488+
"Main graph of ONNX file '%s' does not have a name. Set name to '<main>'",
489+
model_path,
490+
)
485491
main_graph = create_graph(
486492
model.graph, all_function_ids, opset_version=opset_version
487493
)
488-
assert main_graph is not None
494+
assert main_graph is not None, "Bug: Main graph should not be None"
489495
graphs.append(main_graph)
490496

491497
for function in model.functions.values():

0 commit comments

Comments
 (0)