Skip to content

Commit 3ffaa4c

Browse files
committed
Read model from files
1 parent 6b24588 commit 3ffaa4c

File tree

6 files changed

+304
-30
lines changed

6 files changed

+304
-30
lines changed

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,40 @@ Run:
1313
Output:
1414

1515
```
16-
--- Reading from mnist.onnx ---
1716
---- Model info ----
18-
IR Version is 5
17+
IR Version is 1073821696
1918
Produceer name is keras2onnx
2019
Produceer version is 1.5.1
2120
Produceer version is onnx
2221
---- Graph Info ----
23-
Graph inputs number: 1
2422
---- Graph Input Info ----
25-
Input name conv2d_1_input
23+
Graph inputs number: 1
24+
Input name conv2d_12_input
2625
Input type FLOAT
2726
Input dimension 4
28-
N x 28 x 28 x 1
29-
Graph outputs number: 1
27+
N x 0 x 0 x 0
3028
---- Graph Output Info ----
31-
Output name dense_2/Softmax:0
29+
Graph outputs number: 1
30+
Output name dense_14/Softmax:0
3231
Output type FLOAT
3332
Output dimension 2
34-
? x 10
33+
? x 0
34+
---- Graph Node Info ----
35+
Graph nodes number: 15
36+
Transpose : conv2d_12_input -> adjusted_input1 [Transpose6]
37+
Conv : adjusted_input1 -> convolution_output1 [conv2d_12]
38+
Relu : convolution_output1 -> conv2d_12/Relu:0 [Relu1]
39+
MaxPool : conv2d_12/Relu:0 -> pooling_output1 [max_pooling2d_12]
40+
Conv : pooling_output1 -> convolution_output [conv2d_13]
41+
Relu : convolution_output -> conv2d_13/Relu:0 [Relu]
42+
MaxPool : conv2d_13/Relu:0 -> pooling_output [max_pooling2d_13]
43+
Transpose : pooling_output -> max_pooling2d_13/MaxPool:0 [Transpose1]
44+
Reshape : max_pooling2d_13/MaxPool:0 -> flatten_7/Reshape:0 [flatten_7]
45+
MatMul : flatten_7/Reshape:0 -> transformed_tensor1 [dense_13]
46+
Add : transformed_tensor1 -> biased_tensor_name1 [Add1]
47+
MatMul : biased_tensor_name1 -> transformed_tensor [dense_14]
48+
Add : transformed_tensor -> biased_tensor_name [Add]
49+
Softmax : biased_tensor_name -> dense_14/Softmax:01 [Softmax]
50+
Identity : dense_14/Softmax:01 -> dense_14/Softmax:0 [Identity1]
3551
3652
```

SConscript

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ src = Glob('src/*.c')
99
if GetDepend('ONNX_PARSER_USING_EXAMPLE'):
1010
src += Glob('examples/onnx_parser_example.c')
1111

12+
if GetDepend('ONNX_PARSER_USING_RAM_EXAMPLE'):
13+
src += Glob('examples/mnist_onnx.c')
14+
src += Glob('examples/onnx_parser_ram_example.c')
15+
1216
path = [cwd + '/src']
1317
path += [cwd + '/examples']
1418

examples/mnist_onnx.c

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
unsigned char mnist_onnx[] = {
2+
0x08, 0x05, 0x12, 0x0a, 0x6b, 0x65, 0x72, 0x61, 0x73, 0x32, 0x6f, 0x6e,
3+
0x6e, 0x78, 0x1a, 0x05, 0x31, 0x2e, 0x35, 0x2e, 0x31, 0x22, 0x04, 0x6f,
4+
0x6e, 0x6e, 0x78, 0x28, 0x00, 0x32, 0x00, 0x3a, 0x84, 0x10, 0x0a, 0x40,
5+
0x0a, 0x13, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x31, 0x34, 0x2f, 0x53,
6+
0x6f, 0x66, 0x74, 0x6d, 0x61, 0x78, 0x3a, 0x30, 0x31, 0x12, 0x12, 0x64,
7+
0x65, 0x6e, 0x73, 0x65, 0x5f, 0x31, 0x34, 0x2f, 0x53, 0x6f, 0x66, 0x74,
8+
0x6d, 0x61, 0x78, 0x3a, 0x30, 0x1a, 0x09, 0x49, 0x64, 0x65, 0x6e, 0x74,
9+
0x69, 0x74, 0x79, 0x31, 0x22, 0x08, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69,
10+
0x74, 0x79, 0x3a, 0x00, 0x0a, 0x42, 0x0a, 0x13, 0x62, 0x69, 0x61, 0x73,
11+
0x65, 0x64, 0x5f, 0x74, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x5f, 0x6e, 0x61,
12+
0x6d, 0x65, 0x31, 0x0a, 0x01, 0x57, 0x12, 0x12, 0x74, 0x72, 0x61, 0x6e,
13+
0x73, 0x66, 0x6f, 0x72, 0x6d, 0x65, 0x64, 0x5f, 0x74, 0x65, 0x6e, 0x73,
14+
0x6f, 0x72, 0x1a, 0x08, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x31, 0x34,
15+
0x22, 0x06, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x32, 0x00, 0x3a, 0x00,
16+
0x0a, 0x37, 0x0a, 0x12, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72,
17+
0x6d, 0x65, 0x64, 0x5f, 0x74, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x0a, 0x01,
18+
0x42, 0x12, 0x12, 0x62, 0x69, 0x61, 0x73, 0x65, 0x64, 0x5f, 0x74, 0x65,
19+
0x6e, 0x73, 0x6f, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x1a, 0x03, 0x41,
20+
0x64, 0x64, 0x22, 0x03, 0x41, 0x64, 0x64, 0x3a, 0x00, 0x0a, 0x53, 0x0a,
21+
0x12, 0x62, 0x69, 0x61, 0x73, 0x65, 0x64, 0x5f, 0x74, 0x65, 0x6e, 0x73,
22+
0x6f, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x13, 0x64, 0x65, 0x6e,
23+
0x73, 0x65, 0x5f, 0x31, 0x34, 0x2f, 0x53, 0x6f, 0x66, 0x74, 0x6d, 0x61,
24+
0x78, 0x3a, 0x30, 0x31, 0x1a, 0x07, 0x53, 0x6f, 0x66, 0x74, 0x6d, 0x61,
25+
0x78, 0x22, 0x07, 0x53, 0x6f, 0x66, 0x74, 0x6d, 0x61, 0x78, 0x2a, 0x14,
26+
0x0a, 0x04, 0x61, 0x78, 0x69, 0x73, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff,
27+
0xff, 0xff, 0xff, 0xff, 0x01, 0xa0, 0x01, 0x02, 0x3a, 0x00, 0x0a, 0x42,
28+
0x0a, 0x13, 0x66, 0x6c, 0x61, 0x74, 0x74, 0x65, 0x6e, 0x5f, 0x37, 0x2f,
29+
0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x3a, 0x30, 0x0a, 0x02, 0x57,
30+
0x31, 0x12, 0x13, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d,
31+
0x65, 0x64, 0x5f, 0x74, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x31, 0x1a, 0x08,
32+
0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x31, 0x33, 0x22, 0x06, 0x4d, 0x61,
33+
0x74, 0x4d, 0x75, 0x6c, 0x3a, 0x00, 0x0a, 0x3b, 0x0a, 0x13, 0x74, 0x72,
34+
0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d, 0x65, 0x64, 0x5f, 0x74, 0x65,
35+
0x6e, 0x73, 0x6f, 0x72, 0x31, 0x0a, 0x02, 0x42, 0x31, 0x12, 0x13, 0x62,
36+
0x69, 0x61, 0x73, 0x65, 0x64, 0x5f, 0x74, 0x65, 0x6e, 0x73, 0x6f, 0x72,
37+
0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x31, 0x1a, 0x04, 0x41, 0x64, 0x64, 0x31,
38+
0x22, 0x03, 0x41, 0x64, 0x64, 0x3a, 0x00, 0x0a, 0x57, 0x0a, 0x1a, 0x6d,
39+
0x61, 0x78, 0x5f, 0x70, 0x6f, 0x6f, 0x6c, 0x69, 0x6e, 0x67, 0x32, 0x64,
40+
0x5f, 0x31, 0x33, 0x2f, 0x4d, 0x61, 0x78, 0x50, 0x6f, 0x6f, 0x6c, 0x3a,
41+
0x30, 0x0a, 0x0c, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, 0x74, 0x65, 0x6e,
42+
0x73, 0x6f, 0x72, 0x12, 0x13, 0x66, 0x6c, 0x61, 0x74, 0x74, 0x65, 0x6e,
43+
0x5f, 0x37, 0x2f, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x3a, 0x30,
44+
0x1a, 0x09, 0x66, 0x6c, 0x61, 0x74, 0x74, 0x65, 0x6e, 0x5f, 0x37, 0x22,
45+
0x07, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x32, 0x00, 0x3a, 0x00,
46+
0x0a, 0x97, 0x01, 0x0a, 0x10, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x5f,
47+
0x31, 0x33, 0x2f, 0x52, 0x65, 0x6c, 0x75, 0x3a, 0x30, 0x12, 0x0e, 0x70,
48+
0x6f, 0x6f, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75,
49+
0x74, 0x1a, 0x10, 0x6d, 0x61, 0x78, 0x5f, 0x70, 0x6f, 0x6f, 0x6c, 0x69,
50+
0x6e, 0x67, 0x32, 0x64, 0x5f, 0x31, 0x33, 0x22, 0x07, 0x4d, 0x61, 0x78,
51+
0x50, 0x6f, 0x6f, 0x6c, 0x2a, 0x19, 0x0a, 0x08, 0x61, 0x75, 0x74, 0x6f,
52+
0x5f, 0x70, 0x61, 0x64, 0x22, 0x0a, 0x53, 0x41, 0x4d, 0x45, 0x5f, 0x55,
53+
0x50, 0x50, 0x45, 0x52, 0xa0, 0x01, 0x03, 0x2a, 0x10, 0x0a, 0x09, 0x63,
54+
0x65, 0x69, 0x6c, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x18, 0x00, 0xa0, 0x01,
55+
0x02, 0x2a, 0x15, 0x0a, 0x0c, 0x6b, 0x65, 0x72, 0x6e, 0x65, 0x6c, 0x5f,
56+
0x73, 0x68, 0x61, 0x70, 0x65, 0x40, 0x02, 0x40, 0x02, 0xa0, 0x01, 0x07,
57+
0x2a, 0x10, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x69, 0x64, 0x65, 0x73, 0x40,
58+
0x02, 0x40, 0x02, 0xa0, 0x01, 0x07, 0x32, 0x00, 0x3a, 0x00, 0x0a, 0x58,
59+
0x0a, 0x0e, 0x70, 0x6f, 0x6f, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x6f, 0x75,
60+
0x74, 0x70, 0x75, 0x74, 0x12, 0x1a, 0x6d, 0x61, 0x78, 0x5f, 0x70, 0x6f,
61+
0x6f, 0x6c, 0x69, 0x6e, 0x67, 0x32, 0x64, 0x5f, 0x31, 0x33, 0x2f, 0x4d,
62+
0x61, 0x78, 0x50, 0x6f, 0x6f, 0x6c, 0x3a, 0x30, 0x1a, 0x0a, 0x54, 0x72,
63+
0x61, 0x6e, 0x73, 0x70, 0x6f, 0x73, 0x65, 0x31, 0x22, 0x09, 0x54, 0x72,
64+
0x61, 0x6e, 0x73, 0x70, 0x6f, 0x73, 0x65, 0x2a, 0x11, 0x0a, 0x04, 0x70,
65+
0x65, 0x72, 0x6d, 0x40, 0x00, 0x40, 0x02, 0x40, 0x03, 0x40, 0x01, 0xa0,
66+
0x01, 0x07, 0x3a, 0x00, 0x0a, 0xb7, 0x01, 0x0a, 0x0f, 0x70, 0x6f, 0x6f,
67+
0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x31,
68+
0x0a, 0x02, 0x57, 0x32, 0x0a, 0x02, 0x42, 0x32, 0x12, 0x12, 0x63, 0x6f,
69+
0x6e, 0x76, 0x6f, 0x6c, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6f, 0x75,
70+
0x74, 0x70, 0x75, 0x74, 0x1a, 0x09, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64,
71+
0x5f, 0x31, 0x33, 0x22, 0x04, 0x43, 0x6f, 0x6e, 0x76, 0x2a, 0x15, 0x0a,
72+
0x08, 0x61, 0x75, 0x74, 0x6f, 0x5f, 0x70, 0x61, 0x64, 0x22, 0x06, 0x4e,
73+
0x4f, 0x54, 0x53, 0x45, 0x54, 0xa0, 0x01, 0x03, 0x2a, 0x12, 0x0a, 0x09,
74+
0x64, 0x69, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x40, 0x01, 0x40,
75+
0x01, 0xa0, 0x01, 0x07, 0x2a, 0x0c, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75,
76+
0x70, 0x18, 0x01, 0xa0, 0x01, 0x02, 0x2a, 0x15, 0x0a, 0x0c, 0x6b, 0x65,
77+
0x72, 0x6e, 0x65, 0x6c, 0x5f, 0x73, 0x68, 0x61, 0x70, 0x65, 0x40, 0x03,
78+
0x40, 0x03, 0xa0, 0x01, 0x07, 0x2a, 0x11, 0x0a, 0x04, 0x70, 0x61, 0x64,
79+
0x73, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xa0, 0x01, 0x07,
80+
0x2a, 0x10, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x69, 0x64, 0x65, 0x73, 0x40,
81+
0x01, 0x40, 0x01, 0xa0, 0x01, 0x07, 0x32, 0x00, 0x3a, 0x00, 0x0a, 0x36,
82+
0x0a, 0x12, 0x63, 0x6f, 0x6e, 0x76, 0x6f, 0x6c, 0x75, 0x74, 0x69, 0x6f,
83+
0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x10, 0x63, 0x6f,
84+
0x6e, 0x76, 0x32, 0x64, 0x5f, 0x31, 0x33, 0x2f, 0x52, 0x65, 0x6c, 0x75,
85+
0x3a, 0x30, 0x1a, 0x04, 0x52, 0x65, 0x6c, 0x75, 0x22, 0x04, 0x52, 0x65,
86+
0x6c, 0x75, 0x32, 0x00, 0x3a, 0x00, 0x0a, 0x98, 0x01, 0x0a, 0x10, 0x63,
87+
0x6f, 0x6e, 0x76, 0x32, 0x64, 0x5f, 0x31, 0x32, 0x2f, 0x52, 0x65, 0x6c,
88+
0x75, 0x3a, 0x30, 0x12, 0x0f, 0x70, 0x6f, 0x6f, 0x6c, 0x69, 0x6e, 0x67,
89+
0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x31, 0x1a, 0x10, 0x6d, 0x61,
90+
0x78, 0x5f, 0x70, 0x6f, 0x6f, 0x6c, 0x69, 0x6e, 0x67, 0x32, 0x64, 0x5f,
91+
0x31, 0x32, 0x22, 0x07, 0x4d, 0x61, 0x78, 0x50, 0x6f, 0x6f, 0x6c, 0x2a,
92+
0x19, 0x0a, 0x08, 0x61, 0x75, 0x74, 0x6f, 0x5f, 0x70, 0x61, 0x64, 0x22,
93+
0x0a, 0x53, 0x41, 0x4d, 0x45, 0x5f, 0x55, 0x50, 0x50, 0x45, 0x52, 0xa0,
94+
0x01, 0x03, 0x2a, 0x10, 0x0a, 0x09, 0x63, 0x65, 0x69, 0x6c, 0x5f, 0x6d,
95+
0x6f, 0x64, 0x65, 0x18, 0x00, 0xa0, 0x01, 0x02, 0x2a, 0x15, 0x0a, 0x0c,
96+
0x6b, 0x65, 0x72, 0x6e, 0x65, 0x6c, 0x5f, 0x73, 0x68, 0x61, 0x70, 0x65,
97+
0x40, 0x02, 0x40, 0x02, 0xa0, 0x01, 0x07, 0x2a, 0x10, 0x0a, 0x07, 0x73,
98+
0x74, 0x72, 0x69, 0x64, 0x65, 0x73, 0x40, 0x02, 0x40, 0x02, 0xa0, 0x01,
99+
0x07, 0x32, 0x00, 0x3a, 0x00, 0x0a, 0x50, 0x0a, 0x0f, 0x63, 0x6f, 0x6e,
100+
0x76, 0x32, 0x64, 0x5f, 0x31, 0x32, 0x5f, 0x69, 0x6e, 0x70, 0x75, 0x74,
101+
0x12, 0x0f, 0x61, 0x64, 0x6a, 0x75, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x69,
102+
0x6e, 0x70, 0x75, 0x74, 0x31, 0x1a, 0x0a, 0x54, 0x72, 0x61, 0x6e, 0x73,
103+
0x70, 0x6f, 0x73, 0x65, 0x36, 0x22, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73,
104+
0x70, 0x6f, 0x73, 0x65, 0x2a, 0x11, 0x0a, 0x04, 0x70, 0x65, 0x72, 0x6d,
105+
0x40, 0x00, 0x40, 0x03, 0x40, 0x01, 0x40, 0x02, 0xa0, 0x01, 0x07, 0x32,
106+
0x00, 0x3a, 0x00, 0x0a, 0xb6, 0x01, 0x0a, 0x0f, 0x61, 0x64, 0x6a, 0x75,
107+
0x73, 0x74, 0x65, 0x64, 0x5f, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x31, 0x0a,
108+
0x02, 0x57, 0x33, 0x0a, 0x02, 0x42, 0x33, 0x12, 0x13, 0x63, 0x6f, 0x6e,
109+
0x76, 0x6f, 0x6c, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6f, 0x75, 0x74,
110+
0x70, 0x75, 0x74, 0x31, 0x1a, 0x09, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64,
111+
0x5f, 0x31, 0x32, 0x22, 0x04, 0x43, 0x6f, 0x6e, 0x76, 0x2a, 0x15, 0x0a,
112+
0x08, 0x61, 0x75, 0x74, 0x6f, 0x5f, 0x70, 0x61, 0x64, 0x22, 0x06, 0x4e,
113+
0x4f, 0x54, 0x53, 0x45, 0x54, 0xa0, 0x01, 0x03, 0x2a, 0x12, 0x0a, 0x09,
114+
0x64, 0x69, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x40, 0x01, 0x40,
115+
0x01, 0xa0, 0x01, 0x07, 0x2a, 0x0c, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75,
116+
0x70, 0x18, 0x01, 0xa0, 0x01, 0x02, 0x2a, 0x15, 0x0a, 0x0c, 0x6b, 0x65,
117+
0x72, 0x6e, 0x65, 0x6c, 0x5f, 0x73, 0x68, 0x61, 0x70, 0x65, 0x40, 0x03,
118+
0x40, 0x03, 0xa0, 0x01, 0x07, 0x2a, 0x11, 0x0a, 0x04, 0x70, 0x61, 0x64,
119+
0x73, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xa0, 0x01, 0x07,
120+
0x2a, 0x10, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x69, 0x64, 0x65, 0x73, 0x40,
121+
0x01, 0x40, 0x01, 0xa0, 0x01, 0x07, 0x3a, 0x00, 0x0a, 0x38, 0x0a, 0x13,
122+
0x63, 0x6f, 0x6e, 0x76, 0x6f, 0x6c, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x5f,
123+
0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x31, 0x12, 0x10, 0x63, 0x6f, 0x6e,
124+
0x76, 0x32, 0x64, 0x5f, 0x31, 0x32, 0x2f, 0x52, 0x65, 0x6c, 0x75, 0x3a,
125+
0x30, 0x1a, 0x05, 0x52, 0x65, 0x6c, 0x75, 0x31, 0x22, 0x04, 0x52, 0x65,
126+
0x6c, 0x75, 0x32, 0x00, 0x3a, 0x00, 0x12, 0x05, 0x6d, 0x6e, 0x69, 0x73,
127+
0x74, 0x2a, 0x33, 0x08, 0x01, 0x08, 0x0a, 0x10, 0x01, 0x22, 0x28, 0x50,
128+
0x17, 0x4e, 0x3e, 0x61, 0xf6, 0xca, 0xbd, 0xab, 0xbd, 0x9a, 0x3e, 0x92,
129+
0xf6, 0x3d, 0x3e, 0x6e, 0x9c, 0x36, 0xbe, 0x64, 0x6b, 0xab, 0x3d, 0x2f,
130+
0x41, 0x74, 0x3e, 0x5f, 0xd5, 0x32, 0xbf, 0xd5, 0x6d, 0x4e, 0x3d, 0xa9,
131+
0xcc, 0x08, 0xbf, 0x42, 0x01, 0x57, 0x2a, 0x31, 0x08, 0x0a, 0x10, 0x01,
132+
0x22, 0x28, 0x13, 0x04, 0xd4, 0xbe, 0x03, 0x91, 0x44, 0x3f, 0x3b, 0xb7,
133+
0x94, 0xbf, 0xa8, 0x8f, 0x61, 0xbe, 0x08, 0x19, 0x31, 0x3f, 0x9d, 0x99,
134+
0xff, 0x3d, 0x18, 0x47, 0x17, 0xbf, 0x73, 0xa8, 0x91, 0xbc, 0x4d, 0x04,
135+
0xb7, 0x3e, 0xac, 0xdd, 0xcd, 0x3e, 0x42, 0x01, 0x42, 0x2a, 0xd1, 0x01,
136+
0x08, 0x31, 0x08, 0x01, 0x10, 0x01, 0x22, 0xc4, 0x01, 0x1d, 0x98, 0x30,
137+
0x3f, 0x26, 0x95, 0x98, 0x3f, 0xf0, 0x82, 0x67, 0x3f, 0x21, 0x7f, 0x23,
138+
0x3f, 0xeb, 0x59, 0x04, 0x3f, 0xa5, 0x18, 0xd7, 0x3e, 0x9c, 0xe2, 0x13,
139+
0x3e, 0xf4, 0xf1, 0x0e, 0xbe, 0xf8, 0x34, 0x18, 0xbd, 0xf0, 0xea, 0xa9,
140+
0xbc, 0x75, 0xde, 0x94, 0x3a, 0x8a, 0xb2, 0x7a, 0xbb, 0x48, 0x51, 0x42,
141+
0xb9, 0xc0, 0x9a, 0xc5, 0x3d, 0x48, 0x79, 0xb1, 0xbe, 0xd1, 0x6b, 0xe6,
142+
0xbd, 0x1e, 0x2c, 0x5d, 0xbd, 0x06, 0x5c, 0xf0, 0xbc, 0x61, 0x60, 0x07,
143+
0xbd, 0xc1, 0x27, 0x86, 0xbd, 0x09, 0x05, 0x03, 0x3e, 0x7b, 0xc6, 0x11,
144+
0xbe, 0x98, 0xb6, 0x9e, 0x3c, 0x9e, 0x05, 0x0f, 0x3d, 0xf6, 0x7a, 0x56,
145+
0xba, 0xbf, 0x70, 0xe4, 0xbb, 0xbe, 0x89, 0x9d, 0x3c, 0x74, 0x56, 0x75,
146+
0x3e, 0xf2, 0x65, 0xfd, 0x3e, 0x5f, 0xef, 0x85, 0x3e, 0xd8, 0xa2, 0x51,
147+
0x3d, 0xbc, 0x5a, 0xd2, 0x3c, 0x67, 0x09, 0x4c, 0x3d, 0x52, 0x0e, 0x8b,
148+
0x3e, 0x5e, 0x71, 0x2d, 0x3f, 0x05, 0x9f, 0x10, 0x3f, 0x60, 0x72, 0x3b,
149+
0x3e, 0x21, 0xff, 0x9f, 0x3d, 0xdd, 0x0d, 0x30, 0x3d, 0x63, 0xfa, 0x93,
150+
0x3d, 0xc8, 0x3e, 0x21, 0x3e, 0x29, 0xdd, 0xd4, 0x3e, 0xf8, 0xe0, 0x13,
151+
0xbf, 0xf8, 0x1a, 0xff, 0xbe, 0xe4, 0x2a, 0xb4, 0xbe, 0x32, 0x5f, 0x90,
152+
0xbe, 0xe8, 0x09, 0x87, 0xbe, 0x52, 0x7e, 0x11, 0xbf, 0x5d, 0x91, 0x2e,
153+
0xbf, 0x42, 0x02, 0x57, 0x31, 0x2a, 0x0e, 0x08, 0x01, 0x10, 0x01, 0x22,
154+
0x04, 0x7b, 0x82, 0xca, 0xbf, 0x42, 0x02, 0x42, 0x31, 0x2a, 0x1f, 0x08,
155+
0x02, 0x10, 0x07, 0x3a, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
156+
0xff, 0xff, 0x01, 0x31, 0x42, 0x0c, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f,
157+
0x74, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x2a, 0x34, 0x08, 0x01, 0x08, 0x01,
158+
0x08, 0x03, 0x08, 0x03, 0x10, 0x01, 0x22, 0x24, 0xc4, 0x92, 0x0b, 0xbe,
159+
0x6a, 0x55, 0x17, 0xbe, 0xf6, 0x7e, 0x08, 0xbe, 0xe8, 0xa6, 0xc0, 0x3f,
160+
0xb2, 0x9e, 0xde, 0xbe, 0xe1, 0xeb, 0x8c, 0x3f, 0x49, 0x1d, 0x7b, 0x3e,
161+
0x3f, 0x3f, 0xb5, 0xbd, 0xf1, 0x25, 0x65, 0x3e, 0x42, 0x02, 0x57, 0x32,
162+
0x2a, 0x0e, 0x08, 0x01, 0x10, 0x01, 0x22, 0x04, 0x47, 0xb1, 0x6a, 0x3a,
163+
0x42, 0x02, 0x42, 0x32, 0x2a, 0x34, 0x08, 0x01, 0x08, 0x01, 0x08, 0x03,
164+
0x08, 0x03, 0x10, 0x01, 0x22, 0x24, 0x63, 0xba, 0x48, 0xbf, 0x6d, 0xef,
165+
0x08, 0xbf, 0xe8, 0x2c, 0xdd, 0x3b, 0xd3, 0xf2, 0x45, 0x3f, 0xb7, 0xe0,
166+
0x70, 0x3e, 0x7a, 0x1a, 0x2b, 0x3f, 0x93, 0x04, 0x22, 0x3f, 0x17, 0xc0,
167+
0xa9, 0x3c, 0xbf, 0x04, 0x11, 0x3f, 0x42, 0x02, 0x57, 0x33, 0x2a, 0x0e,
168+
0x08, 0x01, 0x10, 0x01, 0x22, 0x04, 0x14, 0x01, 0x9a, 0xbc, 0x42, 0x02,
169+
0x42, 0x33, 0x5a, 0x2a, 0x0a, 0x0f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64,
170+
0x5f, 0x31, 0x32, 0x5f, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x12, 0x17, 0x0a,
171+
0x15, 0x08, 0x01, 0x12, 0x11, 0x0a, 0x03, 0x12, 0x01, 0x4e, 0x0a, 0x02,
172+
0x08, 0x1c, 0x0a, 0x02, 0x08, 0x1c, 0x0a, 0x02, 0x08, 0x01, 0x62, 0x22,
173+
0x0a, 0x12, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x31, 0x34, 0x2f, 0x53,
174+
0x6f, 0x66, 0x74, 0x6d, 0x61, 0x78, 0x3a, 0x30, 0x12, 0x0c, 0x0a, 0x0a,
175+
0x08, 0x01, 0x12, 0x06, 0x0a, 0x00, 0x0a, 0x02, 0x08, 0x0a, 0x42, 0x04,
176+
0x0a, 0x00, 0x10, 0x0a
177+
};
178+
unsigned int mnist_onnx_len = 2092;

examples/onnx_parser_example.c

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,58 @@
1+
#include <string.h>
12
#include "onnx-parser.h"
23

3-
static void onnx_parser_example(int argc,char *argv[])
4+
#define THREAD_PRIORITY 8
5+
#define THREAD_STACK_SIZE 25600
6+
#define THREAD_TIMESLICE 5
7+
8+
static rt_thread_t tid1 = RT_NULL;
9+
static char onnx_file_name[20];
10+
11+
static void onnx_parser_entry(void* parameter)
412
{
5-
if (argc < 2) {
6-
rt_kprintf("Usage: %s onnx_file_name \n", argv[0]);
7-
rt_kprintf("Example: %s /mnist.onnx \n", argv[0]);
8-
return;
9-
}
10-
rt_kprintf("--- Reading from %s ---\n", argv[1]);
1113

12-
// Load Model
13-
Onnx__ModelProto* model = onnx_load_model(argv[1]);
14+
Onnx__ModelProto* model = onnx_load_model(onnx_file_name);
1415

1516
// Print Model Info
1617
if( model != NULL)
1718
{
1819
onnx_model_info(*model);
20+
21+
// Print Graph Info
22+
Onnx__GraphProto* graph = model->graph;
23+
if(graph != NULL)
24+
{
25+
onnx_graph_info_sorted(*graph);
26+
}
27+
28+
// Free Model
29+
onnx__model_proto__free_unpacked(model, NULL);
1930
}
2031
else
2132
{
2233
rt_kprintf("Decode model failed\n");
2334
}
24-
/*
25-
// Print Graph Info
26-
Onnx__GraphProto* graph = model->graph;
27-
if(graph != NULL)
28-
{
29-
onnx_graph_info_sorted(*graph);
30-
}
31-
*/
35+
}
3236

33-
// Free Model
34-
if(model != RT_NULL)
35-
{
36-
onnx__model_proto__free_unpacked(model, NULL);
37+
static void onnx_parser_example(int argc, char *argv[])
38+
{
39+
if (argc < 2) {
40+
rt_kprintf("Usage: %s onnx_file_name \n", argv[0]);
41+
rt_kprintf("Example: %s /mnist.onnx \n", argv[0]);
42+
return;
3743
}
44+
rt_kprintf("--- Reading from %s ---\n", argv[1]);
45+
strcpy (onnx_file_name, argv[1]);
46+
47+
tid1 = rt_thread_create("tonnx_file",
48+
onnx_parser_entry, RT_NULL,
49+
THREAD_STACK_SIZE,
50+
THREAD_PRIORITY, THREAD_TIMESLICE);
51+
52+
if (tid1 != RT_NULL)
53+
rt_thread_startup(tid1);
54+
else
55+
rt_kprintf("Failed to start onnx thread\n");
56+
3857
}
3958
MSH_CMD_EXPORT(onnx_parser_example, decode onnx model from file);

examples/onnx_parser_ram_example.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "onnx-parser.h"
2+
3+
extern unsigned char mnist_onnx[];
4+
extern unsigned int mnist_onnx_len;
5+
6+
#define THREAD_PRIORITY 8
7+
#define THREAD_STACK_SIZE 25600
8+
#define THREAD_TIMESLICE 5
9+
10+
static rt_thread_t tid1 = RT_NULL;
11+
12+
static void onnx_parser_entry(void* parameters)
13+
{
14+
// Load Model
15+
Onnx__ModelProto* model = onnx__model_proto__unpack(NULL, mnist_onnx_len, mnist_onnx);
16+
17+
// Print Model Info
18+
if( model != NULL)
19+
{
20+
onnx_model_info(*model);
21+
// Print Graph Info
22+
Onnx__GraphProto* graph = model->graph;
23+
if(graph != NULL)
24+
{
25+
onnx_graph_info_sorted(*graph);
26+
}
27+
28+
// Free Model
29+
onnx__model_proto__free_unpacked(model, NULL);
30+
}
31+
else
32+
{
33+
rt_kprintf("Decode model failed\n");
34+
}
35+
}
36+
37+
static void onnx_parser_ram_example(int argc, char *argv[])
38+
{
39+
40+
tid1 = rt_thread_create("tonnx_ram",
41+
onnx_parser_entry, RT_NULL,
42+
THREAD_STACK_SIZE,
43+
THREAD_PRIORITY, THREAD_TIMESLICE);
44+
45+
if (tid1 != RT_NULL)
46+
rt_thread_startup(tid1);
47+
else
48+
rt_kprintf("Start failed\n");
49+
50+
}
51+
MSH_CMD_EXPORT(onnx_parser_ram_example, decode onnx model from file);

src/onnx-parser.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const char* onnx_tensor_proto_data_type[] = {
2121

2222
Onnx__ModelProto* onnx_load_model(const char* onnx_file_name)
2323
{
24+
rt_kprintf("Load model %s\n", onnx_file_name);
2425
// Get file size first
2526
int ret;
2627
struct stat buf;
@@ -54,9 +55,14 @@ Onnx__ModelProto* onnx_load_model(const char* onnx_file_name)
5455
rt_kprintf("Read file %s failed \n", onnx_file_name);
5556
return RT_NULL;
5657
}
58+
rt_kprintf("Sucessfully read file %s\n", onnx_file_name);
5759
}
5860

59-
return onnx__model_proto__unpack(NULL, msg_len, buffer);
61+
Onnx__ModelProto* model = onnx__model_proto__unpack(NULL, msg_len, buffer);
62+
rt_kprintf("Free memory %s\n", onnx_file_name);
63+
rt_free(buffer);
64+
65+
return model;
6066
}
6167

6268
void onnx_model_info(Onnx__ModelProto model)

0 commit comments

Comments
 (0)