forked from onnx/onnx-mlir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mnist-runPyRuntime.py
executable file
·289 lines (287 loc) · 17.9 KB
/
mnist-runPyRuntime.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/usr/bin/env python3
import numpy as np
from PyRuntime import OMExecutionSession
# Load the model mnist.so compiled with onnx-mlir.
model = './mnist.so'
session = OMExecutionSession(model)
# Print the models input/output signature, for display.
# Signature functions for info only, commented out if they cause problems.
print("input signature in json", session.input_signature())
print("output signature in json",session.output_signature())
# Create an input arbitrarily filled of 1.0 values.
input = np.array([-0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.029637714847922325, 0.7467845678329468,
1.7777715921401978, 2.796030282974243, 1.5104787349700928,
1.5104787349700928, 0.36493754386901855, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 0.09764464199542999, 2.5414655208587646,
2.783302068710327, 2.796030282974243, 2.783302068710327,
2.796030282974243, 2.783302068710327, 2.4141831398010254,
0.6067740321159363, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 0.4922199249267578, 2.5414655208587646,
2.808758497238159, 1.7650433778762817, -0.4242129623889923,
-0.4242129623889923, 2.0323362350463867, 2.796030282974243,
2.808758497238159, 2.2869009971618652, -0.15692004561424255,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 0.09764464199542999, 2.796030282974243,
2.783302068710327, 1.2431857585906982, -0.2969306409358978,
-0.4242129623889923, -0.4242129623889923, 0.4794916808605194,
2.783302068710327, 2.796030282974243, 2.783302068710327,
1.3831963539123535, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.2842023968696594, 1.7777715921401978,
2.808758497238159, 2.5414655208587646, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
0.09764464199542999, 2.668747901916504, 2.808758497238159,
2.796030282974243, 2.808758497238159, 1.7650433778762817,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, 0.22492696344852448,
2.783302068710327, 2.796030282974243, 0.466763436794281,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, 2.159618616104126,
1.4977505207061768, 2.5287373065948486, 2.796030282974243,
2.783302068710327, 0.6195022463798523, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
1.5104787349700928, 2.796030282974243, 2.68147611618042,
0.08491640537977219, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
0.09764464199542999, -0.4242129623889923, 0.6195022463798523,
2.5541937351226807, 2.796030282974243, 2.5541937351226807,
-0.042365945875644684, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
0.09764464199542999, 2.5414655208587646, 2.783302068710327,
1.6377609968185425, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 1.0013492107391357, 2.783302068710327,
2.796030282974243, 1.7650433778762817, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 0.8740668296813965, 2.808758497238159,
2.796030282974243, 0.6195022463798523, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.15692004561424255,
2.4141831398010254, 2.808758497238159, 2.796030282974243,
0.36493754386901855, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, 1.3831963539123535,
2.796030282974243, 2.783302068710327, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 1.1286314725875854, 2.796030282974243,
2.783302068710327, 0.8740668296813965, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.029637714847922325,
2.5414655208587646, 2.808758497238159, 2.796030282974243,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
2.808758497238159, 2.796030282974243, 2.159618616104126,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
0.22492696344852448, 2.783302068710327, 2.796030282974243,
2.783302068710327, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 2.796030282974243, 2.783302068710327,
2.159618616104126, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 0.22492696344852448, 2.796030282974243,
2.808758497238159, 2.796030282974243, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.15692004561424255, 2.808758497238159,
2.796030282974243, 1.3831963539123535, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, 0.22492696344852448,
2.783302068710327, 2.796030282974243, 2.783302068710327,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, 0.8740668296813965,
2.796030282974243, 2.783302068710327, 0.8740668296813965,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 1.905053973197937, 2.808758497238159,
2.796030282974243, 1.6504892110824585, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.029637714847922325,
2.5414655208587646, 2.808758497238159, 2.5414655208587646,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, 0.8740668296813965,
2.796030282974243, 2.783302068710327, 2.668747901916504,
0.08491640537977219, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
1.2559140920639038, 2.783302068710327, 2.796030282974243,
0.466763436794281, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 1.7777715921401978, 2.796030282974243,
2.821486711502075, 2.796030282974243, 0.6195022463798523,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
0.6195022463798523, 2.808758497238159, 2.796030282974243,
1.1413596868515015, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.2969306409358978,
1.7650433778762817, 2.796030282974243, 2.783302068710327,
2.668747901916504, 1.6377609968185425, 0.09764464199542999,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
1.6504892110824585, 2.668747901916504, 2.796030282974243,
2.274172782897949, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, 1.1413596868515015,
2.668747901916504, 2.808758497238159, 2.796030282974243,
2.5541937351226807, 1.5104787349700928, 1.5232069492340088,
2.5414655208587646, 2.808758497238159, 2.5414655208587646,
1.1413596868515015, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, 0.08491640537977219, 1.4977505207061768,
2.5287373065948486, 2.796030282974243, 2.783302068710327,
2.796030282974243, 2.783302068710327, 1.4977505207061768,
0.21219873428344727, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923, -0.4242129623889923,
-0.4242129623889923, -0.4242129623889923], np.dtype(np.float32)).reshape(1,1,28,28)
# Run the model. It is best to always use the [] around the inputs as the inputs
# are an vector of numpy arrays.
outputs = session.run([input])
# Analyze the output (first array in the list, of signature 1x10xf32).
prediction = outputs[0]
digit = -1
prob = 0.0
for i in range(0, 10):
print("prediction ", i, "=", prediction[0, i])
if prediction[0, i] > prob:
digit = i
prob = prediction[0, i]
# Print the value with the highest prediction (8 here).
print("The digit is", digit)