-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathops_decoder.py
More file actions
39 lines (29 loc) · 970 Bytes
/
ops_decoder.py
File metadata and controls
39 lines (29 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import argparse
import xir
def main():
parser = argparse.ArgumentParser(description="Inspect subgraphs and ops in an .xmodel file")
parser.add_argument(
"--xmodel",
type=str,
required=True,
help="Path to the .xmodel file, e.g. ./DPU_models/Model_0312.xmodel"
)
args = parser.parse_args()
g = xir.Graph.deserialize(args.xmodel)
root = g.get_root_subgraph()
# 有些版本可直接用 children,有些建議用 toposort_child_subgraph()
try:
subgraphs = root.toposort_child_subgraph()
except Exception:
subgraphs = root.children
for sg in subgraphs:
print("SUBGRAPH:", sg.get_name())
if sg.has_attr("device"):
print("DEVICE:", sg.get_attr("device"))
else:
print("DEVICE: N/A")
for op in sg.get_ops():
print(" ", op.get_name(), op.get_type())
print("-" * 60)
if __name__ == "__main__":
main()