|
|
"""Inspect custom ops in models 11, 12, 22, 33 to determine exact op names and domains.""" |
|
|
import onnx |
|
|
from pathlib import Path |
|
|
|
|
|
models_dir = Path("oneocr_extracted/onnx_models") |
|
|
|
|
|
for idx in [11, 12, 22, 33]: |
|
|
matches = list(models_dir.glob(f"model_{idx:02d}_*")) |
|
|
if not matches: |
|
|
print(f"model_{idx:02d}: NOT FOUND") |
|
|
continue |
|
|
|
|
|
model = onnx.load(str(matches[0])) |
|
|
print(f"\n{'='*60}") |
|
|
print(f"model_{idx:02d}: {matches[0].name}") |
|
|
print(f" IR version: {model.ir_version}") |
|
|
print(f" Opset imports: {[(o.domain, o.version) for o in model.opset_import]}") |
|
|
|
|
|
|
|
|
for node in model.graph.node: |
|
|
if node.domain and node.domain != "": |
|
|
print(f" Node: op_type={node.op_type!r}, domain={node.domain!r}") |
|
|
print(f" inputs: {list(node.input)}") |
|
|
print(f" outputs: {list(node.output)}") |
|
|
|
|
|
for attr in node.attribute: |
|
|
if attr.type == 2: |
|
|
print(f" attr {attr.name} = {attr.i}") |
|
|
elif attr.type == 1: |
|
|
print(f" attr {attr.name} = {attr.f}") |
|
|
elif attr.type == 3: |
|
|
print(f" attr {attr.name} = {attr.s.decode()!r}") |
|
|
elif attr.type == 4: |
|
|
t = attr.t |
|
|
print(f" attr {attr.name} = tensor(dtype={t.data_type}, dims={list(t.dims)}, raw_bytes={len(t.raw_data)})") |
|
|
|
|
|
|
|
|
print(f" Graph inputs: {[(i.name, [d.dim_value or d.dim_param for d in i.type.tensor_type.shape.dim]) for i in model.graph.input]}") |
|
|
print(f" Graph outputs: {[(o.name, [d.dim_value or d.dim_param for d in o.type.tensor_type.shape.dim]) for o in model.graph.output]}") |
|
|
|