Jiahang commited on
Commit
aefff9b
1 Parent(s): 0388244

update script

Browse files
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Latency Prediction By Nn-Meter
3
- emoji: 🏃
4
- colorFrom: blue
5
- colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 3.0.26
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
1
  ---
2
+ title: Latency Prediction by nn-Meter
3
+ emoji: 🌖
4
+ colorFrom: purple
5
+ colorTo: red
6
  sdk: gradio
7
+ sdk_version: 3.0.20
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import gradio as gr
3
+ from nn_meter import load_latency_predictor
4
+
5
+
6
+ cortexA76cpu_predictor = load_latency_predictor("cortexA76cpu_tflite21")
7
+ adreno640gpu_predictor = load_latency_predictor("adreno640gpu_tflite21")
8
+ adreno630gpu = load_latency_predictor("adreno630gpu_tflite21")
9
+ myriadvpu_predictor = load_latency_predictor("myriadvpu_openvino2019r2")
10
+ predictor_map = {
11
+ "cortexA76cpu_tflite21": cortexA76cpu_predictor,
12
+ "adreno640gpu_tflite21": adreno640gpu_predictor,
13
+ "adreno630gpu_tflite21": adreno630gpu,
14
+ "myriadvpu_openvino2019r2": myriadvpu_predictor
15
+ }
16
+
17
+ feature_for_kernel = {
18
+ # remove the last two float
19
+ "conv": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
20
+ "dwconv": ["HW", "CIN", "COUT", "KERNEL_SIZE", "STRIDES"],
21
+ "fc": ["CIN", "COUT"],
22
+ # support up to 4 cin, if less than 4, the latter cin will be set to 0
23
+ "concat": ["HW", "CIN1", "CIN2", "CIN3", "CIN4"],
24
+ #
25
+ "maxpool": ["HW", "CIN", "COUT", "KERNEL_SIZE", "POOL_STRIDES"],
26
+ "avgpool": ["HW", "CIN", "COUT", "KERNEL_SIZE", "POOL_STRIDES"],
27
+ "split": ["HW", "CIN"],
28
+ "channelshuffle": ["HW", "CIN"],
29
+ "se": ["HW", "CIN"],
30
+ "global-avgpool": ["HW", "CIN"],
31
+ "bnrelu": ["HW", "CIN"],
32
+ "bn": ["HW", "CIN"],
33
+ "hswish": ["HW", "CIN"],
34
+ "relu": ["HW", "CIN"],
35
+ "addrelu": ["HW", "CIN1", "CIN2"],
36
+ "add": ["HW", "CIN1", "CIN2"],
37
+ }
38
+
39
+ def get_type(str):
40
+ operate_type = str.split("-")[0]
41
+ if operate_type == 'global' or operate_type == 'gap':
42
+ operate_type = 'global-avgpool'
43
+ return operate_type
44
+ def get_configuration(operate_type, value_arr):
45
+ feature_arr = feature_for_kernel[operate_type]
46
+ if operate_type == 'concat':
47
+ configuration_arr = []
48
+ for i in range(len(feature_arr)):
49
+ if value_arr[i] != 0:
50
+ configuration_arr.append(feature_arr[i]+"="+str(value_arr[i]))
51
+ else:
52
+ break
53
+ else:
54
+ configuration_arr = [feature_arr[i]+"="+str(value_arr[i]) for i in range(min(len(feature_arr),len(value_arr)))]
55
+ return ', '.join(configuration_arr)
56
+
57
+
58
+ def data_process(data):
59
+ new_data = []
60
+ for item in data:
61
+ operate_type = get_type(item[1])
62
+ new_item = {
63
+ "order": item[0],
64
+ "type": operate_type,
65
+ "configuration": get_configuration(operate_type, item[2]),
66
+ "latency": item[3],
67
+ "name": item[4],
68
+ }
69
+ new_data.append(new_item)
70
+ return new_data
71
+
72
+
73
+ def generate_html(hardware, latency, block_detail):
74
+ data = data_process(block_detail)
75
+
76
+ doc = """<html>
77
+ <head>
78
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
79
+ <meta name="viewport" content="width=device-width,
80
+ initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
81
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet">
82
+ <link href="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.css" rel="stylesheet">
83
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.3/font/bootstrap-icons.css">
84
+ <style>
85
+ html {
86
+ font-family: sans-serif;
87
+ padding: 5px;
88
+ }
89
+
90
+ body {
91
+ padding: 10px;
92
+ font-size: 0.875rem;
93
+ }
94
+
95
+ #dataviz {
96
+ width: 100%;
97
+ height: 300px;
98
+ position: relative;
99
+ }
100
+
101
+ #toolbar {
102
+ margin-top: 10px;
103
+ margin-bottom: 15px;
104
+ display: flex;
105
+ align-items: center;
106
+ }
107
+
108
+ input[type="number"]:focus-visible {
109
+ outline: none;
110
+ }
111
+
112
+ .bootstrap-table .fixed-table-container .fixed-table-body {
113
+ height: auto;
114
+ }
115
+ </style>
116
+ </head>
117
+
118
+ <body>
119
+ <h4 style="font-size: 1.5rem">Latency Analysis <i class="bi bi-question-circle" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="right" style="font-size:1.2rem;"></i></h4>
120
+ <div id="popoverInfo" style="display: none">
121
+ The latency results are empowered by Microsoft nn-Meter. For more technical details, please refer to the paper: <a href="https://dl.acm.org/doi/abs/10.1145/3529706.3529712" target="_blank">nn-METER: Towards Accurate Latency Prediction of DNN Inference on Diverse Edge Devices</a>.
122
+ </div>
123
+ <div id="toolbar">
124
+ <div style="display: flex;align-items: center;">
125
+ <span>Group By: </span>
126
+ <select class="form-select" id="inputGroupBy" style="width: fit-content;margin-left: 5px;">
127
+ <option value="type">Operator Type</option>
128
+ <option value="name">None</option>
129
+ </select>
130
+ </div>
131
+ <div style="margin-left: 45px;margin-top:6px;display: flex;align-items: center;">
132
+ <div><label><input type="radio" name="quantity" value="all" class="quantity" checked> Show all</label></div>
133
+
134
+ <div style="margin-left: 10px;">
135
+ <label><input type="radio" name="quantity" value="top" class="quantity"> Show top</label>
136
+ <input type="number" value="10" min="1" style="width: 50px; border: none;
137
+ border-bottom: 1px #aaa solid;" id="quantityNumber" disabled>
138
+ </div>
139
+ </div>
140
+ </div>
141
+ <div style="display: flex;">
142
+ <div id="dataviz"> </div>
143
+ </div>
144
+
145
+ <table id="table" data-search="true" data-search-align="left" data-pagination="true" data-page-size="30" data-page-list="[10, 20, 30, 50, 100, all]">
146
+ <thead>
147
+ <tr>
148
+ <th data-field="order" data-sortable="true">Excution Order</th>
149
+ <th data-field="type" data-sortable="true">Operator Type</th>
150
+ <th data-field="configuration">Configuration</th>
151
+ <th data-field="latency" data-sortable="true">Latency (ms)</th>
152
+ <th data-field="name" width="20%" data-sortable="true">Detail Operator</th>
153
+ </tr>
154
+ </thead>
155
+ </table>
156
+ <script src="https://cdn.jsdelivr.net/npm/echarts@5.3.3/dist/echarts.min.js" type="text/javascript"></script>
157
+ <script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
158
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"></script>
159
+ <script src="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.js"></script>
160
+ </body>
161
+ <script>
162
+ """ + f"""let rawData = {str(data).replace("'", '"')};""" + """
163
+ rawData.forEach(item => {
164
+ item.name = item.name.split(";").join("; ");
165
+ item.latency = Number(item.latency) ? Number(item.latency) : item.latency;
166
+ })
167
+
168
+ // table
169
+ let $table = $("#table");
170
+ $(function () {
171
+ $table.bootstrapTable({ data: rawData })
172
+ })
173
+
174
+ // visualization
175
+ const chartDom = document.getElementById("dataviz");
176
+ let myChart = echarts.init(chartDom);
177
+ Array.prototype.groupBy = function (key) {
178
+ return this.reduce(function (rv, x) {
179
+ (rv[x[key]] = rv[x[key]] || []).push(x);
180
+ return rv;
181
+ }, {});
182
+ };
183
+
184
+ function processData(rawData, groupBy, quantity) {
185
+ // transform data
186
+ let seriesData = Object.entries(rawData.groupBy(groupBy)).map(([name, arr]) => {
187
+ const value = arr.reduce((sum, curr) => sum + curr.latency, 0);
188
+ const type = arr[0].type;
189
+ return { name, value, type }
190
+ })
191
+ .sort((a, b) => {
192
+ return b.value - a.value
193
+ });
194
+ if (quantity) {
195
+ seriesData = seriesData.slice(0, quantity);
196
+ }
197
+
198
+ return {
199
+ seriesData,
200
+ legendData: seriesData.filter(d => Number(d.value)).map(d => d.name)
201
+ };
202
+ }
203
+
204
+ function formatNumber(num, fixed = 2){
205
+ if(Number(num.toFixed(fixed)) > 0){
206
+ return num.toFixed(fixed);
207
+ }else{
208
+ return num.toPrecision(1);
209
+ }
210
+ }
211
+
212
+ function render(data, groupBy) {
213
+ const sum = data.seriesData.reduce(function (prev, current) {
214
+ return prev + (Number(current.value) ? Number(current.value) : 0)
215
+ }, 0);
216
+ let option = {
217
+ title: {
218
+ text: """ + f"""`Total latency is {format(latency, '.4f')}(ms)`,
219
+ subtext: `on Hardware {hardware}`,"""+"""
220
+ left: "left",
221
+ textStyle:{
222
+ fontSize: 14
223
+ }
224
+ },
225
+ tooltip: {
226
+ trigger: "item",
227
+ formatter: (params) => groupBy==="name"? `<i>type:</i> ${params.data.type}<br><i>detail:</i> ${params.data.name}<br><b>${formatNumber(params.data.value)}</b><br><b>(${formatNumber(params.data.value / sum * 100)}%)</b>` : `${params.data.name}<br><b>${formatNumber(params.data.value)}</b><br><b>(${formatNumber(params.data.value / sum * 100)}%)</b>`,
228
+ extraCssText: "max-width: 400px; white-space: break-spaces;"
229
+ },
230
+ legend: {
231
+ type: "scroll",
232
+ orient: "vertical",
233
+ right: "10%",
234
+ top: "12%",
235
+ bottom: "12%",
236
+ data: data.legendData,
237
+ formatter: (name) => {
238
+ let arr = name.split(";");
239
+ return arr.length === 1 ? name : (arr[0]+"...");
240
+ },
241
+ tooltip: {
242
+ show: true,
243
+ formatter: (params) => {
244
+ let datum = data.seriesData.find(d => d.name === params.name);
245
+ return groupBy==="name"? `<i>type:</i> ${datum.type}<br><i>detail:</i> ${datum.name}<br><b>${formatNumber(datum.value)}</b><br><b>(${formatNumber(datum.value / sum * 100)}%)</b>` :`${datum.name}<br><b>${formatNumber(datum.value)}</b><br><b>(${formatNumber(datum.value / sum * 100)}%)</b>`
246
+ },
247
+ position: (point, params, dom, rect, { contentSize, viewSize }) => [viewSize[0] * 0.4 - contentSize[0] * 0.5, viewSize[1] * 0.5 - contentSize[1] * 0.5]
248
+ }
249
+ },
250
+ series: [
251
+ {
252
+ type: "pie",
253
+ radius: ["40%", "75%"],
254
+ center: ["40%", "50%"],
255
+ data: data.seriesData,
256
+ emphasis: {
257
+ itemStyle: {
258
+ shadowBlur: 10,
259
+ shadowOffsetX: 0,
260
+ shadowColor: "rgba(0, 0, 0, 0.5)"
261
+ }
262
+ }, label: {
263
+ formatter: "{d}%",
264
+ position: "inside",
265
+ color: "#fff",
266
+ },
267
+ }
268
+ ],
269
+ color: ["#4e79a7", "#f28e2c", "#e15759", "#76b7b2", "#59a14f", "#edc949", "#af7aa1", "#ff9da7", "#9c755f", "#bab0ab"]
270
+ };
271
+ myChart.dispose();
272
+ myChart = echarts.init(chartDom);
273
+ myChart.setOption(option);
274
+ myChart.on("selectchanged", function(params){
275
+ const index = params.fromActionPayload.dataIndexInside;
276
+ const text = data.seriesData[index].name;
277
+ $table.bootstrapTable("resetSearch", text);
278
+ });
279
+
280
+ myChart.on("legendselectchanged", function(params) {
281
+ suppressSelection(myChart, params);
282
+ });
283
+
284
+ function suppressSelection(chart, params) {
285
+ chart.setOption({ animation: false });
286
+
287
+ // Re-select what the user unselected
288
+ chart.dispatchAction({
289
+ type: "legendSelect",
290
+ name: params.name
291
+ });
292
+
293
+ chart.setOption({ animation: true });
294
+ }
295
+ }
296
+
297
+ // config
298
+ let groupBy = "type";
299
+ let quantityNumber = 10;
300
+ let showAll = true;
301
+
302
+ render(processData(rawData, groupBy), groupBy);
303
+
304
+ function redraw() {
305
+ render(processData(rawData, groupBy, showAll ? null : quantityNumber), groupBy);
306
+ }
307
+
308
+ // change groupby
309
+ document.getElementById("inputGroupBy")
310
+ .addEventListener("change", function () {
311
+ groupBy = this.value;
312
+
313
+ redraw();
314
+ });
315
+
316
+ // change the model of show
317
+ function changeShowModel() {
318
+ if (this.value === "top") {
319
+ document.getElementById("quantityNumber").disabled = false;
320
+ showAll = false;
321
+ } else {
322
+ document.getElementById("quantityNumber").disabled = true;
323
+ showAll = true;
324
+ }
325
+ redraw();
326
+ }
327
+ let items = Object.values(document.getElementsByClassName("quantity"))
328
+ .forEach(item => item.addEventListener("change", changeShowModel));
329
+
330
+ // change the number of show
331
+ document.getElementById("quantityNumber")
332
+ .addEventListener("change", function () {
333
+ quantityNumber = this.value;
334
+ redraw();
335
+ })
336
+
337
+ // enable popover
338
+ const popoverTriggerList = document.querySelectorAll(`[data-bs-toggle="popover"]`)
339
+ const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl, {
340
+ html : true,
341
+ content: function() {
342
+ return $("#popoverInfo").html();
343
+ }
344
+ }));
345
+ </script>
346
+ </html>
347
+ """
348
+ return f"""<iframe style="width: 100%; height: 480px" name="result" allow="midi; geolocation; microphone; camera; display-capture; encrypted-media;" sandbox="allow-modals allow-forms allow-scripts allow-same-origin allow-popups allow-top-navigation-by-user-activation allow-downloads" allowfullscreen="" allowpaymentrequest="" frameborder="0" srcdoc='{doc}'></iframe>"""
349
+
350
+ def generate_error_html(massage):
351
+ return f"""<div style="color:#842029;background: #f8d7da;padding: 10px;border-radius: 10px; margin-top: 15px;"><b>nn-meter meets an error in latency prediction</b>: {massage}</div>
352
+ <div style="padding: 10px;">If you have any questions about the result, you can open new issues in <a href="https://github.com/microsoft/nn-Meter" target="_blank" style="color:#2563eb">nn-meter Git repository</a>.</div>
353
+ """
354
+
355
+ def get_latency(model, hardware_name):
356
+ if model == None:
357
+ return generate_error_html("Please upload a model file or select one example below.")
358
+ model = model.name
359
+
360
+ if hardware_name == '':
361
+ return generate_error_html("Please select a device.")
362
+
363
+ predictor = predictor_map[hardware_name]
364
+ if model.endswith("onnx"):
365
+ model_type = "onnx"
366
+ elif model.endswith("pb"):
367
+ model_type = "pb"
368
+ else:
369
+ model_type = "nnmeter-ir"
370
+
371
+ try:
372
+ model_latency, block_detail = predictor.detailed_predict(model, model_type)
373
+ return generate_html(hardware_name, model_latency, block_detail)
374
+ except Exception as e:
375
+ return generate_error_html(repr(e))
376
+
377
+
378
+
379
+ title = "Interactive demo: nn-Meter (Draft Version)"
380
+ description = "Demo for Microsoft's nn-Meter, a novel and efficient system to accurately predict the inference latency of DNN models on diverse edge devices. To use it, simply upload a model file, or use one of the example below and click ‘submit’. Results will show up in a few seconds."
381
+ article = "<p style='text-align: center'><a href='https://dl.acm.org/doi/10.1145/3458864.3467882'>nn-Meter: towards accurate latency prediction of deep-learning model inference on diverse edge devices</a> | <a href='https://github.com/microsoft/nn-Meter'>Github Repo</a></p>"
382
+ examples =[
383
+ ["samples/mobilenetv3small_0.pb", "cortexA76cpu_tflite21"],
384
+ ["samples/mobilenetv3small_0.onnx", "adreno640gpu_tflite21"],
385
+ ["samples/mobilenetv3small_0.json", "adreno630gpu_tflite21"]
386
+ ]
387
+
388
+ inputs = [
389
+ gr.inputs.File(label="Model File"),
390
+ gr.inputs.Radio(choices=["cortexA76cpu_tflite21", "adreno640gpu_tflite21", "adreno630gpu_tflite21", "myriadvpu_openvino2019r2"], label="Device"),
391
+ ]
392
+ outputs = gr.outputs.HTML()
393
+
394
+ iface = gr.Interface(fn=get_latency,
395
+ inputs=inputs,
396
+ outputs=outputs,
397
+ title=title,
398
+ description=description,
399
+ article=article,
400
+ examples=examples,
401
+ allow_flagging="auto",
402
+ css="""
403
+ div[id="6"] {
404
+ flex-direction: column;
405
+ }
406
+
407
+ div[id="12"] {
408
+ margin-left: 0px !important;
409
+ margin-top: 0.75em !important;
410
+ }
411
+
412
+ div[id="12"] iframe{
413
+ height: 80vh !important;
414
+ }
415
+ """)
416
+ iface.launch()
block_latency_demo.json ADDED
@@ -0,0 +1,759 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ [
3
+ "layer1.1.conv-bn#57",
4
+ [
5
+ 224,
6
+ 3,
7
+ 16,
8
+ 3,
9
+ 2
10
+ ],
11
+ 0.08969208666666643
12
+ ],
13
+ [
14
+ "layer1.1.hswish#58",
15
+ [
16
+ 112,
17
+ 16
18
+ ],
19
+ 0.06512388473684201
20
+ ],
21
+ [
22
+ "layer2.1.conv-bn-relu#59",
23
+ [
24
+ 112,
25
+ 16,
26
+ 16,
27
+ 1,
28
+ 1
29
+ ],
30
+ 0.046539635777777595
31
+ ],
32
+ [
33
+ "layer2.2.dwconv-bn-relu#60",
34
+ [
35
+ 112,
36
+ 16,
37
+ 16,
38
+ 3,
39
+ 1
40
+ ],
41
+ 0.08458797897222242
42
+ ],
43
+ [
44
+ "layer2.3.conv-bn-add#61",
45
+ [
46
+ 112,
47
+ 16,
48
+ 16,
49
+ 1,
50
+ 1
51
+ ],
52
+ 0.046539635777777595
53
+ ],
54
+ [
55
+ "layer3.1.conv-bn-relu#62",
56
+ [
57
+ 112,
58
+ 16,
59
+ 64,
60
+ 1,
61
+ 1
62
+ ],
63
+ 0.2812146724444452
64
+ ],
65
+ [
66
+ "layer3.2.dwconv-bn-relu#63",
67
+ [
68
+ 112,
69
+ 64,
70
+ 64,
71
+ 3,
72
+ 2
73
+ ],
74
+ 0.1847138329761906
75
+ ],
76
+ [
77
+ "layer3.3.conv-bn#64",
78
+ [
79
+ 56,
80
+ 64,
81
+ 24,
82
+ 1,
83
+ 1
84
+ ],
85
+ 0.12564988711111114
86
+ ],
87
+ [
88
+ "layer4.1.conv-bn-relu#65",
89
+ [
90
+ 56,
91
+ 24,
92
+ 72,
93
+ 1,
94
+ 1
95
+ ],
96
+ 0.1313259719999998
97
+ ],
98
+ [
99
+ "layer4.2.dwconv-bn-relu#66",
100
+ [
101
+ 56,
102
+ 72,
103
+ 72,
104
+ 3,
105
+ 1
106
+ ],
107
+ 0.10148598884424595
108
+ ],
109
+ [
110
+ "layer4.3.conv-bn-add#67",
111
+ [
112
+ 56,
113
+ 72,
114
+ 24,
115
+ 1,
116
+ 1
117
+ ],
118
+ 0.12938113733333315
119
+ ],
120
+ [
121
+ "layer5.1.conv-bn-relu#68",
122
+ [
123
+ 56,
124
+ 24,
125
+ 72,
126
+ 1,
127
+ 1
128
+ ],
129
+ 0.1313259719999998
130
+ ],
131
+ [
132
+ "layer5.2.dwconv-bn#69",
133
+ [
134
+ 56,
135
+ 72,
136
+ 72,
137
+ 5,
138
+ 2
139
+ ],
140
+ 0.13221349583333308
141
+ ],
142
+ [
143
+ "layer5.2.se-relu#70",
144
+ [
145
+ 28,
146
+ 72
147
+ ],
148
+ 0.2514369789473686
149
+ ],
150
+ [
151
+ "layer5.3.conv-bn#71",
152
+ [
153
+ 28,
154
+ 72,
155
+ 40,
156
+ 1,
157
+ 1
158
+ ],
159
+ 0.06686152977777766
160
+ ],
161
+ [
162
+ "layer6.1.conv-bn-relu#72",
163
+ [
164
+ 28,
165
+ 40,
166
+ 120,
167
+ 1,
168
+ 1
169
+ ],
170
+ 0.09544240288888854
171
+ ],
172
+ [
173
+ "layer6.2.dwconv-bn#73",
174
+ [
175
+ 28,
176
+ 120,
177
+ 120,
178
+ 5,
179
+ 1
180
+ ],
181
+ 0.1791692834623016
182
+ ],
183
+ [
184
+ "layer6.2.se-relu#74",
185
+ [
186
+ 28,
187
+ 120
188
+ ],
189
+ 0.29275722631578976
190
+ ],
191
+ [
192
+ "layer6.3.conv-bn-add#75",
193
+ [
194
+ 28,
195
+ 120,
196
+ 40,
197
+ 1,
198
+ 1
199
+ ],
200
+ 0.09891386688888877
201
+ ],
202
+ [
203
+ "layer7.1.conv-bn-relu#76",
204
+ [
205
+ 28,
206
+ 40,
207
+ 120,
208
+ 1,
209
+ 1
210
+ ],
211
+ 0.09544240288888854
212
+ ],
213
+ [
214
+ "layer7.2.dwconv-bn#77",
215
+ [
216
+ 28,
217
+ 120,
218
+ 120,
219
+ 5,
220
+ 1
221
+ ],
222
+ 0.1791692834623016
223
+ ],
224
+ [
225
+ "layer7.2.se-relu#78",
226
+ [
227
+ 28,
228
+ 120
229
+ ],
230
+ 0.29275722631578976
231
+ ],
232
+ [
233
+ "layer7.3.conv-bn-add#79",
234
+ [
235
+ 28,
236
+ 120,
237
+ 40,
238
+ 1,
239
+ 1
240
+ ],
241
+ 0.09891386688888877
242
+ ],
243
+ [
244
+ "layer8.1.conv-bn#80",
245
+ [
246
+ 28,
247
+ 40,
248
+ 240,
249
+ 1,
250
+ 1
251
+ ],
252
+ 0.17468612444444476
253
+ ],
254
+ [
255
+ "layer8.1.hswish#81",
256
+ [
257
+ 28,
258
+ 240
259
+ ],
260
+ 0.034863998421052596
261
+ ],
262
+ [
263
+ "layer8.2.dwconv-bn#82",
264
+ [
265
+ 28,
266
+ 240,
267
+ 240,
268
+ 3,
269
+ 2
270
+ ],
271
+ 0.05733039375000008
272
+ ],
273
+ [
274
+ "layer8.2.hswish#83",
275
+ [
276
+ 14,
277
+ 240
278
+ ],
279
+ 0.01200028842105264
280
+ ],
281
+ [
282
+ "layer8.3.conv-bn#84",
283
+ [
284
+ 14,
285
+ 240,
286
+ 80,
287
+ 1,
288
+ 1
289
+ ],
290
+ 0.1185776239999995
291
+ ],
292
+ [
293
+ "layer9.1.conv-bn#85",
294
+ [
295
+ 14,
296
+ 80,
297
+ 200,
298
+ 1,
299
+ 1
300
+ ],
301
+ 0.07862664244444413
302
+ ],
303
+ [
304
+ "layer9.1.hswish#86",
305
+ [
306
+ 14,
307
+ 200
308
+ ],
309
+ 0.010081669999999966
310
+ ],
311
+ [
312
+ "layer9.2.dwconv-bn#87",
313
+ [
314
+ 14,
315
+ 200,
316
+ 200,
317
+ 3,
318
+ 1
319
+ ],
320
+ 0.024046657092261906
321
+ ],
322
+ [
323
+ "layer9.2.hswish#88",
324
+ [
325
+ 14,
326
+ 200
327
+ ],
328
+ 0.010081669999999966
329
+ ],
330
+ [
331
+ "layer9.3.conv-bn-add#89",
332
+ [
333
+ 14,
334
+ 200,
335
+ 80,
336
+ 1,
337
+ 1
338
+ ],
339
+ 0.10319714688888944
340
+ ],
341
+ [
342
+ "layer10.1.conv-bn#90",
343
+ [
344
+ 14,
345
+ 80,
346
+ 184,
347
+ 1,
348
+ 1
349
+ ],
350
+ 0.07391564955555524
351
+ ],
352
+ [
353
+ "layer10.1.hswish#91",
354
+ [
355
+ 14,
356
+ 184
357
+ ],
358
+ 0.00995709136842104
359
+ ],
360
+ [
361
+ "layer10.2.dwconv-bn#92",
362
+ [
363
+ 14,
364
+ 184,
365
+ 184,
366
+ 3,
367
+ 1
368
+ ],
369
+ 0.022844432440476167
370
+ ],
371
+ [
372
+ "layer10.2.hswish#93",
373
+ [
374
+ 14,
375
+ 184
376
+ ],
377
+ 0.00995709136842104
378
+ ],
379
+ [
380
+ "layer10.3.conv-bn-add#94",
381
+ [
382
+ 14,
383
+ 184,
384
+ 80,
385
+ 1,
386
+ 1
387
+ ],
388
+ 0.09344137288888908
389
+ ],
390
+ [
391
+ "layer11.1.conv-bn#95",
392
+ [
393
+ 14,
394
+ 80,
395
+ 184,
396
+ 1,
397
+ 1
398
+ ],
399
+ 0.07391564955555524
400
+ ],
401
+ [
402
+ "layer11.1.hswish#96",
403
+ [
404
+ 14,
405
+ 184
406
+ ],
407
+ 0.00995709136842104
408
+ ],
409
+ [
410
+ "layer11.2.dwconv-bn#97",
411
+ [
412
+ 14,
413
+ 184,
414
+ 184,
415
+ 3,
416
+ 1
417
+ ],
418
+ 0.022844432440476167
419
+ ],
420
+ [
421
+ "layer11.2.hswish#98",
422
+ [
423
+ 14,
424
+ 184
425
+ ],
426
+ 0.00995709136842104
427
+ ],
428
+ [
429
+ "layer11.3.conv-bn-add#99",
430
+ [
431
+ 14,
432
+ 184,
433
+ 80,
434
+ 1,
435
+ 1
436
+ ],
437
+ 0.09344137288888908
438
+ ],
439
+ [
440
+ "layer12.1.conv-bn#100",
441
+ [
442
+ 14,
443
+ 80,
444
+ 480,
445
+ 1,
446
+ 1
447
+ ],
448
+ 0.1664279088888898
449
+ ],
450
+ [
451
+ "layer12.1.hswish#101",
452
+ [
453
+ 14,
454
+ 480
455
+ ],
456
+ 0.020963691052631548
457
+ ],
458
+ [
459
+ "layer12.2.dwconv-bn#102",
460
+ [
461
+ 14,
462
+ 480,
463
+ 480,
464
+ 3,
465
+ 1
466
+ ],
467
+ 0.05033707406646825
468
+ ],
469
+ [
470
+ "layer12.2.se#103",
471
+ [
472
+ 14,
473
+ 480
474
+ ],
475
+ 0.30968490526315845
476
+ ],
477
+ [
478
+ "layer12.2.hswish#104",
479
+ [
480
+ 14,
481
+ 480
482
+ ],
483
+ 0.020963691052631548
484
+ ],
485
+ [
486
+ "layer12.3.conv-bn#105",
487
+ [
488
+ 14,
489
+ 480,
490
+ 112,
491
+ 1,
492
+ 1
493
+ ],
494
+ 0.2822340977777797
495
+ ],
496
+ [
497
+ "layer13.1.conv-bn#106",
498
+ [
499
+ 14,
500
+ 112,
501
+ 672,
502
+ 1,
503
+ 1
504
+ ],
505
+ 0.31593401333333454
506
+ ],
507
+ [
508
+ "layer13.1.hswish#107",
509
+ [
510
+ 14,
511
+ 672
512
+ ],
513
+ 0.028506453157894702
514
+ ],
515
+ [
516
+ "layer13.2.dwconv-bn#108",
517
+ [
518
+ 14,
519
+ 672,
520
+ 672,
521
+ 3,
522
+ 1
523
+ ],
524
+ 0.06833738649305546
525
+ ],
526
+ [
527
+ "layer13.2.se#109",
528
+ [
529
+ 14,
530
+ 672
531
+ ],
532
+ 0.4181391842105277
533
+ ],
534
+ [
535
+ "layer13.2.hswish#110",
536
+ [
537
+ 14,
538
+ 672
539
+ ],
540
+ 0.028506453157894702
541
+ ],
542
+ [
543
+ "layer13.3.conv-bn-add#111",
544
+ [
545
+ 14,
546
+ 672,
547
+ 112,
548
+ 1,
549
+ 1
550
+ ],
551
+ 0.38993811555555447
552
+ ],
553
+ [
554
+ "layer14.1.conv-bn#112",
555
+ [
556
+ 14,
557
+ 112,
558
+ 672,
559
+ 1,
560
+ 1
561
+ ],
562
+ 0.31593401333333454
563
+ ],
564
+ [
565
+ "layer14.1.hswish#113",
566
+ [
567
+ 14,
568
+ 672
569
+ ],
570
+ 0.028506453157894702
571
+ ],
572
+ [
573
+ "layer14.2.dwconv-bn#114",
574
+ [
575
+ 14,
576
+ 672,
577
+ 672,
578
+ 5,
579
+ 2
580
+ ],
581
+ 0.12773641041666683
582
+ ],
583
+ [
584
+ "layer14.2.se#115",
585
+ [
586
+ 7,
587
+ 672
588
+ ],
589
+ 0.15399494736842148
590
+ ],
591
+ [
592
+ "layer14.2.hswish#116",
593
+ [
594
+ 7,
595
+ 672
596
+ ],
597
+ 0.011023535789473677
598
+ ],
599
+ [
600
+ "layer14.3.conv-bn#117",
601
+ [
602
+ 7,
603
+ 672,
604
+ 160,
605
+ 1,
606
+ 1
607
+ ],
608
+ 0.27822387777777746
609
+ ],
610
+ [
611
+ "layer15.1.conv-bn#118",
612
+ [
613
+ 7,
614
+ 160,
615
+ 960,
616
+ 1,
617
+ 1
618
+ ],
619
+ 0.32120322444444405
620
+ ],
621
+ [
622
+ "layer15.1.hswish#119",
623
+ [
624
+ 7,
625
+ 960
626
+ ],
627
+ 0.014172026315789451
628
+ ],
629
+ [
630
+ "layer15.2.dwconv-bn#120",
631
+ [
632
+ 7,
633
+ 960,
634
+ 960,
635
+ 5,
636
+ 1
637
+ ],
638
+ 0.11106422500000021
639
+ ],
640
+ [
641
+ "layer15.2.se#121",
642
+ [
643
+ 7,
644
+ 960
645
+ ],
646
+ 0.21297702631578969
647
+ ],
648
+ [
649
+ "layer15.2.hswish#122",
650
+ [
651
+ 7,
652
+ 960
653
+ ],
654
+ 0.014172026315789451
655
+ ],
656
+ [
657
+ "layer15.3.conv-bn-add#123",
658
+ [
659
+ 7,
660
+ 960,
661
+ 160,
662
+ 1,
663
+ 1
664
+ ],
665
+ 0.4788489133333347
666
+ ],
667
+ [
668
+ "layer16.1.conv-bn#124",
669
+ [
670
+ 7,
671
+ 160,
672
+ 960,
673
+ 1,
674
+ 1
675
+ ],
676
+ 0.32120322444444405
677
+ ],
678
+ [
679
+ "layer16.1.hswish#125",
680
+ [
681
+ 7,
682
+ 960
683
+ ],
684
+ 0.014172026315789451
685
+ ],
686
+ [
687
+ "layer16.2.dwconv-bn#126",
688
+ [
689
+ 7,
690
+ 960,
691
+ 960,
692
+ 5,
693
+ 1
694
+ ],
695
+ 0.11106422500000021
696
+ ],
697
+ [
698
+ "layer16.2.se#127",
699
+ [
700
+ 7,
701
+ 960
702
+ ],
703
+ 0.21297702631578969
704
+ ],
705
+ [
706
+ "layer16.2.hswish#128",
707
+ [
708
+ 7,
709
+ 960
710
+ ],
711
+ 0.014172026315789451
712
+ ],
713
+ [
714
+ "layer16.3.conv-bn-add#129",
715
+ [
716
+ 7,
717
+ 960,
718
+ 160,
719
+ 1,
720
+ 1
721
+ ],
722
+ 0.4788489133333347
723
+ ],
724
+ [
725
+ "layer17.1.conv-bn#130",
726
+ [
727
+ 7,
728
+ 160,
729
+ 1280,
730
+ 1,
731
+ 1
732
+ ],
733
+ 0.40695861999999977
734
+ ],
735
+ [
736
+ "layer17.1.hswish#131",
737
+ [
738
+ 7,
739
+ 1280
740
+ ],
741
+ 0.01831055315789479
742
+ ],
743
+ [
744
+ "layer18.1.gap#132",
745
+ [
746
+ 1,
747
+ 1280
748
+ ],
749
+ 0.001
750
+ ],
751
+ [
752
+ "layer19.1.fc#133",
753
+ [
754
+ 1280,
755
+ 1920
756
+ ],
757
+ 0.168
758
+ ]
759
+ ]
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ -e git+https://github.com/microsoft/nn-Meter.git@dev/block-latency#egg=nn-Meter
2
+ tensorflow==2.6.0
3
+ torch==1.9.0
4
+ torchvision==0.10.0
5
+ onnx==1.10.0
6
+ onnx-simplifier==0.3.6
samples/mobilenetv3small_0.json ADDED
The diff for this file is too large to render. See raw diff
 
samples/mobilenetv3small_0.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25e6117900a394d143f56b53648c680ad93a7563ee472c419d4f416f5b77485a
3
+ size 10169165
samples/mobilenetv3small_0.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b7790ba98e0e6981fee7c09babae466fe29dcef1ad5dc9bd5cc28929017c0123
3
+ size 8098911