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
40
41
42
43
44
45
| import onnx
|
|
| def create_custom_mul_model():
| # === Inputs ===
| x = onnx.helper.make_tensor_value_info("X", onnx.TensorProto.FLOAT, [3, 2])
| w = onnx.helper.make_tensor_value_info("W", onnx.TensorProto.FLOAT, [3, 2])
|
| # === Output ===
| y = onnx.helper.make_tensor_value_info("Y", onnx.TensorProto.FLOAT, [3, 2])
|
| # === Custom Node: Custom_Mul ===
| # Replace "Mul" with your custom op name and domain
| custom_node = onnx.helper.make_node(
| op_type="Custom_Mul", # <-- custom op name
| inputs=["X", "W"],
| outputs=["Y"],
| domain="test", # <-- custom domain
| )
|
| # === Graph ===
| graph = onnx.helper.make_graph(
| nodes=[custom_node],
| name="CustomMulGraph",
| inputs=[x, w],
| outputs=[y],
| )
|
| # === Model (opset version 13 or later is fine) ===
| model = onnx.helper.make_model(
| graph,
| opset_imports=[
| onnx.helper.make_opsetid("", 13), # standard ONNX domain
| onnx.helper.make_opsetid("com.example", 1),
| ], # your custom domain
| producer_name="custom_mul_builder",
| )
|
| return model
|
|
| # ===== Save the Model =====
| model = create_custom_mul_model()
| onnx.save(model, "custom_mul.onnx")
| print("Saved custom_mul.onnx")
|
|