Ivan Lazarevich commited on
Commit
796b62e
1 Parent(s): db87971

release app

Browse files
Files changed (7) hide show
  1. LICENSE +201 -0
  2. README.md +2 -2
  3. app.py +285 -0
  4. banner.png +0 -0
  5. plotting.py +205 -0
  6. requirements.txt +3 -0
  7. utils.py +58 -0
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
- title: Yolobench
3
- emoji: 🌖
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
 
1
  ---
2
+ title: YOLOBench
3
+ emoji: 🚀
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from plotting import create_yolobench_plots, get_pareto_table
4
+ from utils import DEEPLITE_DARK_BLUE_GRADIO
5
+
6
+ def get_hw_description(hw_name):
7
+ HW_URLS = {
8
+ 'Jetson Nano (GPU, ONNX Runtime, FP32)': 'https://8074457.fs1.hubspotusercontent-na1.net/hubfs/8074457/YOLOBench%20Hardware%20product%20sheets/JetsonNano_DataSheet_DS09366001v1.1.pdf',
9
+ 'Raspberry Pi 4 Model B (CPU, TFLite, FP32)': 'https://8074457.fs1.hubspotusercontent-na1.net/hubfs/8074457/YOLOBench%20Hardware%20product%20sheets/raspberry-pi-4-datasheet.pdf',
10
+ 'Intel® Core™i7-10875H (CPU, OpenVINO, FP32)': 'https://8074457.fs1.hubspotusercontent-na1.net/hubfs/8074457/YOLOBench%20Hardware%20product%20sheets/Intel_ARK_SpecificationsChart_2023_10_11.pdf',
11
+ 'Khadas VIM3 (NPU, INT16)': 'https://8074457.fs1.hubspotusercontent-na1.net/hubfs/8074457/YOLOBench%20Hardware%20product%20sheets/khadas_vim3_specs.pdf',
12
+ 'Orange Pi 5 (NPU, FP16)': 'https://8074457.fs1.hubspotusercontent-na1.net/hubfs/8074457/YOLOBench%20Hardware%20product%20sheets/OrangePi_5_RK3588S_User%20Manual_v1.5.pdf',
13
+ }
14
+
15
+ hw_url = HW_URLS[hw_name]
16
+ DESC = f"""
17
+ 🔸 <span style="font-size:16px">Click </span>[<span style="font-size:16px">here</span>]({hw_url})<span style="font-size:16px"> for more information on the selected hardware platform.</span>
18
+ 🔸 <span style="font-size:16px">Refer to the [Deeplite Torch Zoo](https://github.com/Deeplite/deeplite-torch-zoo/tree/develop/results/yolobench) for details about latency measurement experiments.</span>
19
+ """
20
+ return DESC
21
+
22
+
23
+ with gr.Blocks(theme=gr.themes.Default(secondary_hue=DEEPLITE_DARK_BLUE_GRADIO),
24
+ css="table { width: 100%; }", analytics_enabled=True) as demo:
25
+
26
+ gr.HTML(
27
+ """
28
+ <div align="center">
29
+ <img src="file/banner.png"/>
30
+ </div>
31
+ """
32
+ )
33
+
34
+ # switch to light theme by default
35
+ demo.load(
36
+ None,
37
+ _js="""
38
+ () => {
39
+ let mediaQueryObj = window.matchMedia('(prefers-color-scheme: dark)');
40
+ let systemDarkTheme = window.location.href.includes("theme=system") && mediaQueryObj.matches;
41
+ if (mediaQueryObj.matches){
42
+ document.body.classList.toggle('dark');
43
+ document.querySelector('gradio-app').style.backgroundColor = 'var(--color-background-primary)'
44
+ }
45
+ }
46
+ """,
47
+ )
48
+
49
+ demo.load(
50
+ None,
51
+ _js="""
52
+ () => {
53
+ const script2 = document.createElement("script");
54
+ script2.src = "https://www.googletagmanager.com/gtag/js?id=G-01G83VTHE0";
55
+ script2.async = true;
56
+ document.head.appendChild(script2);
57
+ window.dataLayer = window.dataLayer || [];
58
+ function gtag(){dataLayer.push(arguments);}
59
+ gtag('js', new Date());
60
+ gtag('config', 'G-01G83VTHE0', {
61
+ 'page_path': "/spaces/deepliteai/yolobench",
62
+ 'page_title': 'yolobench',
63
+ 'cookie_flags': 'SameSite=None;Secure',
64
+ 'debug_mode':true,
65
+ });
66
+ }
67
+ """,
68
+ )
69
+
70
+ with gr.Row():
71
+ gr.Markdown(
72
+ """
73
+ <span style="font-size:16px">
74
+
75
+ 🚀 <b>YOLOBench</b> 🚀 is a latency-accuracy benchmark of popular single-stage detectors from the YOLO series. Major highlights of this work are:
76
+
77
+ 🔸 includes architectures from YOLOv3 to YOLOv8, <br>
78
+ 🔸 trained on <span style="font-weight:bold">four</span> popular object detection datasets (COCO, VOC, WIDER FACE, SKU-110k), <br>
79
+ 🔸 latency measured on <span style="font-weight:bold">five embedded hardware platforms</span> (Jetson Nano GPU, ARM CPU, Intel CPU, Khadas VIM3 NPU, Orange Pi NPU), <br>
80
+ 🔸 all models are trained with <span style="font-weight:bold">the same</span> training loop and hyperparameters (as implemented in the [Ultralytics YOLOv8 codebase](https://github.com/ultralytics/ultralytics)), <br>
81
+ 🔸 both <span style="font-weight:bold">the detection head structure</span> and <span style="font-weight:bold"> the loss function </span> used are that of YOLOv8, giving a chance to isolate the contribution of the backbone/neck architecture on the latency-accuracy trade-off of YOLO models. <br>
82
+ In particular, we show that older backbone/neck structures like those of YOLOv3 and YOLOv4 are still competitive compared to more recent architectures in a controlled environment. For more details, please refer to the [arXiv preprint](https://arxiv.org/abs/2307.13901) and the [codebase](https://github.com/Deeplite/deeplite-torch-zoo).
83
+
84
+ #
85
+
86
+ </span>
87
+
88
+ #
89
+ """
90
+ )
91
+
92
+ with gr.Row(equal_height=True):
93
+ with gr.Column():
94
+ hardware_name = gr.Dropdown(
95
+ choices=[
96
+ 'Jetson Nano (GPU, ONNX Runtime, FP32)',
97
+ 'Raspberry Pi 4 Model B (CPU, TFLite, FP32)',
98
+ 'Intel® Core™i7-10875H (CPU, OpenVINO, FP32)',
99
+ 'Khadas VIM3 (NPU, INT16)',
100
+ 'Orange Pi 5 (NPU, FP16)',
101
+ ],
102
+ value='Jetson Nano (GPU, ONNX Runtime, FP32)',
103
+ label='Hardware',
104
+ )
105
+ with gr.Column():
106
+ dataset_name = gr.Dropdown(
107
+ choices=['COCO', 'PASCAL VOC', 'SKU-110K', 'WIDERFACE'],
108
+ value='COCO',
109
+ label='Dataset',
110
+ )
111
+
112
+ with gr.Row(equal_height=True):
113
+ with gr.Column():
114
+ hardware_desc = gr.Markdown(get_hw_description(hardware_name.value))
115
+
116
+ with gr.Column():
117
+ metric_name = gr.Radio(
118
+ ['mAP@0.5:0.95', 'mAP@0.5', 'Precision', 'Recall'],
119
+ value='mAP@0.5:0.95',
120
+ label='Accuracy metric to plot',
121
+ )
122
+
123
+ with gr.Row(equal_height=True):
124
+ with gr.Column():
125
+ gr.Markdown("""
126
+ <span style="font-size:16px">
127
+
128
+ 🚀 <span style="font-weight:bold">Want to add your own hardware benchmarks to YOLOBench?</span> 🚀
129
+ Contact us [here](https://info.deeplite.ai/add_yolobench_data) for your benchmarking kit and we'll set you up!
130
+
131
+ </span>
132
+ """)
133
+
134
+ with gr.Column():
135
+ vis_options = gr.CheckboxGroup(
136
+ [
137
+ 'Model family',
138
+ 'Highlight Pareto',
139
+ 'Show Pareto only',
140
+ 'Log x-axis'
141
+ ],
142
+ value=['Model family',],
143
+ label='Visualization options',
144
+ )
145
+
146
+
147
+ with gr.Row():
148
+ upper_panel_fig = gr.Plot(show_label=False)
149
+
150
+ gr.Markdown(
151
+ """
152
+ ##
153
+ <span style="font-size:16px">
154
+
155
+ Models from this benchmark can be loaded using [Deeplite Torch Zoo](https://github.com/Deeplite/deeplite-torch-zoo) as follows:
156
+
157
+ </span>
158
+
159
+ ##
160
+
161
+ ```python
162
+ from deeplite_torch_zoo import get_model
163
+ model = get_model(
164
+ model_name='yolo4n', # create a YOLOv4n model for the COCO dataset
165
+ dataset_name='coco', # (`n` corresponds to width factor 0.25, depth factor 0.33)
166
+ pretrained=False, #
167
+ custom_head='v8' # attach a YOLOv8 detection head to YOLOv4n backbone+neck
168
+ )
169
+ ```
170
+
171
+ <span style="font-size:16px">
172
+
173
+ To train a model, run
174
+
175
+ </span>
176
+
177
+ ```python
178
+ from deeplite_torch_zoo.trainer import Detector
179
+ model = Detector(torch_model=model) # previously created YOLOv4n model
180
+ model.train(data='VOC.yaml', epochs=100, imgsz=480) # same arguments as the Ultralytics trainer object
181
+ ```
182
+
183
+ ##
184
+
185
+ <details>
186
+ <summary>Model naming conventions</summary>
187
+
188
+ ##
189
+
190
+ The model naming convention is that a model named `yolo8d67w25` is a YOLOv8 model with a depth factor of 0.67 and width factor of 0.25. Conventional depth/width factor value namings (n, s, m, l models) are used where possible. YOLOv6(s, m, l) models are considered to be different architectures due to differences other than the depth/width factor value. For every architecture, there are 3 variations in depth factor (0.33, 0.67, 1.0) and 4 variations in width factor (0.25, 0.5, 0.75, 1.0), except for YOLOv7 models, for which only width factor variations are considered while depth is fixed.
191
+ </details>
192
+
193
+ ##
194
+
195
+ <span style="font-size:20px">
196
+ Pareto-optimal models
197
+ </span>
198
+
199
+ ##
200
+
201
+ COCO pre-trained models are ready for download. Other models coming soon!
202
+ """
203
+ )
204
+
205
+ table_mode = gr.Radio(
206
+ ['Show top-10 models', 'Show all'],
207
+ value='Show top-10 models',
208
+ label='Pareto model table'
209
+ )
210
+
211
+ with gr.Row():
212
+ # pareto_table = gr.DataFrame(interactive=False)
213
+ pareto_table = gr.HTML()
214
+
215
+ gr.Markdown(
216
+ """
217
+ ## Citation
218
+ ```
219
+ Accepted at ICCV 2023 Workshop on Resource-Efficient Deep Learning for Computer Vision (RCV'23)
220
+ @article{lazarevich2023yolobench,
221
+ title={YOLOBench: Benchmarking Efficient Object Detectors on Embedded Systems},
222
+ author={Lazarevich, Ivan and Grimaldi, Matteo and Kumar, Ravish and Mitra, Saptarshi and Khan, Shahrukh and Sah, Sudhakar},
223
+ journal={arXiv preprint arXiv:2307.13901},
224
+ year={2023}
225
+ }
226
+ ```
227
+ """
228
+ )
229
+
230
+ inputs = [dataset_name, hardware_name, metric_name, vis_options, table_mode]
231
+
232
+ # plot by default (VOC, Raspi4)
233
+ demo.load(
234
+ fn=create_yolobench_plots,
235
+ inputs=inputs,
236
+ outputs=[upper_panel_fig, pareto_table],
237
+ )
238
+
239
+ demo.load(
240
+ fn=get_pareto_table,
241
+ inputs=[dataset_name, hardware_name, metric_name],
242
+ outputs=[pareto_table],
243
+ )
244
+
245
+ # update in case of dataset selection
246
+ dataset_name.change(
247
+ fn=create_yolobench_plots,
248
+ inputs=inputs,
249
+ outputs=[upper_panel_fig, pareto_table],
250
+ )
251
+ # update in case of metric selection
252
+ metric_name.change(
253
+ fn=create_yolobench_plots,
254
+ inputs=inputs,
255
+ outputs=[upper_panel_fig, pareto_table],
256
+ )
257
+
258
+ vis_options.change(
259
+ fn=create_yolobench_plots,
260
+ inputs=inputs,
261
+ outputs=[upper_panel_fig, pareto_table],
262
+ )
263
+
264
+ table_mode.change(
265
+ fn=create_yolobench_plots,
266
+ inputs=inputs,
267
+ outputs=[upper_panel_fig, pareto_table],
268
+ )
269
+
270
+ # update in case of device selection
271
+ hardware_name.change(
272
+ fn=create_yolobench_plots,
273
+ inputs=inputs,
274
+ outputs=[upper_panel_fig, pareto_table],
275
+ )
276
+
277
+ hardware_name.change(
278
+ fn=get_hw_description,
279
+ inputs=[hardware_name],
280
+ outputs=[hardware_desc],
281
+ )
282
+
283
+
284
+ if __name__ == "__main__":
285
+ demo.launch()
banner.png ADDED
plotting.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import plotly.express as px
2
+ import plotly.graph_objects as go
3
+
4
+ from utils import DEEPLITE_LIGHT_BLUE_HEX, load_yolobench_data
5
+
6
+
7
+ df, pareto_indices = load_yolobench_data()
8
+
9
+
10
+ METRIC_NAME_MAPPING = {
11
+ 'mAP@0.5': 'mAP_0.5',
12
+ 'mAP@0.5:0.95': 'mAP_0.5:0.95',
13
+ 'Precision': 'precision',
14
+ 'Recall': 'recall',
15
+ }
16
+
17
+ METRIC_KEYS_TO_NAMES = {v: k for k, v in METRIC_NAME_MAPPING.items()}
18
+
19
+
20
+ LATENCY_KEYS = {
21
+ 'Raspberry Pi 4 Model B (CPU, TFLite, FP32)': 'raspi4_tflite_latency',
22
+ 'Jetson Nano (GPU, ONNX Runtime, FP32)': 'nano_gpu_latency',
23
+ 'Intel® Core™i7-10875H (CPU, OpenVINO, FP32)': 'openvino_latency',
24
+ 'Khadas VIM3 (NPU, INT16)': 'vim3_latency',
25
+ 'Orange Pi 5 (NPU, FP16)': 'orange_pi_latency',
26
+ }
27
+
28
+ LATENCY_KEYS_TO_NAMES = {v: k for k, v in LATENCY_KEYS.items()}
29
+
30
+ DATASET_TAGS = {
31
+ 'PASCAL VOC': 'voc',
32
+ 'SKU-110K': 'sku',
33
+ 'WIDERFACE': 'wider',
34
+ 'COCO': 'coco',
35
+ }
36
+
37
+ DATASET_TAGS_TO_NAMES = {v: k for k, v in DATASET_TAGS.items()}
38
+
39
+
40
+ def get_scatter_plot(
41
+ dataset_tag,
42
+ metric_tag,
43
+ latency_key,
44
+ model_family_coloring=True,
45
+ add_pareto_frontier=False,
46
+ plot_pareto_only=False,
47
+ log_axis=False,
48
+ ):
49
+ fig_opts, layout_opts = {'opacity': 0.5, 'color_discrete_sequence': [DEEPLITE_LIGHT_BLUE_HEX]}, {}
50
+ if model_family_coloring:
51
+ fig_opts = {
52
+ 'color': 'model_family',
53
+ 'opacity': 0.75,
54
+ 'color_discrete_sequence': px.colors.qualitative.Plotly,
55
+ }
56
+ layout_opts = {
57
+ 'legend': dict(
58
+ title='Model family<br>(click to toggle)',
59
+ )
60
+ }
61
+
62
+ frontier = None
63
+ if plot_pareto_only:
64
+ metric_key = f'{metric_tag}_{dataset_tag}'
65
+ frontier = pareto_indices[metric_key][latency_key]
66
+
67
+ fig = px.scatter(
68
+ df if frontier is None else df.iloc[frontier, :],
69
+ x=latency_key,
70
+ y=f'{metric_tag}_{dataset_tag}',
71
+ title=f'{METRIC_KEYS_TO_NAMES[metric_tag]}-latency scatter plot',
72
+ hover_data={
73
+ 'model_name': True,
74
+ 'model_family': False,
75
+ latency_key: ':.2f',
76
+ f'{metric_tag}_{dataset_tag}': ':.2f',
77
+ },
78
+ labels={
79
+ 'model_name': 'Model name',
80
+ latency_key: 'Latency',
81
+ f'{metric_tag}_{dataset_tag}': METRIC_KEYS_TO_NAMES[metric_tag],
82
+ },
83
+ template='plotly_white',
84
+ **fig_opts,
85
+ )
86
+ if log_axis:
87
+ fig.update_xaxes(type='log')
88
+
89
+ fig.update_layout(
90
+ height=600,
91
+ modebar_remove=['lasso', 'autoscale', 'zoomin', 'zoomout', 'select2d', 'select'],
92
+ xaxis_title=f'{LATENCY_KEYS_TO_NAMES[latency_key]} latency, ms',
93
+ yaxis_title=f"{METRIC_KEYS_TO_NAMES[metric_tag]}",
94
+ xaxis=dict(
95
+ rangeslider=dict(
96
+ visible=True,
97
+ bgcolor=DEEPLITE_LIGHT_BLUE_HEX,
98
+ thickness=0.02,
99
+ ),
100
+ ),
101
+ yaxis=dict(
102
+ fixedrange=False,
103
+ ),
104
+ hoverlabel=dict(
105
+ # bgcolor="white",
106
+ font_size=14,
107
+ font_family='Source Sans Pro'
108
+ ),
109
+ **layout_opts,
110
+ )
111
+ if add_pareto_frontier:
112
+ fig = pareto_frontier_layer(fig, dataset_tag, metric_tag, latency_key)
113
+ return fig
114
+
115
+
116
+ def create_yolobench_plots(
117
+ dataset_name,
118
+ hardware_name,
119
+ metric_name,
120
+ vis_options,
121
+ table_mode,
122
+ ):
123
+ model_family_coloring = 'Model family' in vis_options
124
+ add_pareto_frontier = 'Highlight Pareto' in vis_options
125
+ plot_pareto_only = 'Show Pareto only' in vis_options
126
+ log_axis = 'Log x-axis' in vis_options
127
+ fig = get_scatter_plot(
128
+ DATASET_TAGS[dataset_name],
129
+ METRIC_NAME_MAPPING[metric_name],
130
+ LATENCY_KEYS[hardware_name],
131
+ model_family_coloring,
132
+ add_pareto_frontier,
133
+ plot_pareto_only,
134
+ log_axis,
135
+ )
136
+ pareto_table = get_pareto_table(
137
+ dataset_name, hardware_name, metric_name, expand_table='Show all' in table_mode
138
+ )
139
+ return fig, pareto_table
140
+
141
+
142
+ def pareto_frontier_layer(
143
+ fig,
144
+ dataset_tag,
145
+ metric_tag,
146
+ latency_key,
147
+ ):
148
+ metric_key = f'{metric_tag}_{dataset_tag}'
149
+ frontier = pareto_indices[metric_key][latency_key]
150
+ fig.add_trace(
151
+ go.Scatter(
152
+ x=df.iloc[frontier, :][latency_key],
153
+ y=df.iloc[frontier, :][metric_key],
154
+ mode='lines',
155
+ opacity=0.5,
156
+ line=go.scatter.Line(color='grey'),
157
+ showlegend=False,
158
+ name=metric_key,
159
+ )
160
+ )
161
+ return fig
162
+
163
+
164
+ def get_pareto_table(
165
+ dataset_name, hardware_name, metric_name, expand_table=False,
166
+ ):
167
+ dataset_tag = DATASET_TAGS[dataset_name]
168
+ metric_tag = METRIC_NAME_MAPPING[metric_name]
169
+ latency_key = LATENCY_KEYS[hardware_name]
170
+ metric_key = f'{metric_tag}_{dataset_tag}'
171
+
172
+ latency_key_final = f'{LATENCY_KEYS_TO_NAMES[latency_key]} latency, ms'
173
+ metric_key_final = METRIC_KEYS_TO_NAMES[metric_tag]
174
+
175
+ frontier = pareto_indices[metric_key][latency_key]
176
+ table_df = df.iloc[frontier, :][['model_name', metric_key, latency_key]]
177
+ table_df['Input resolution (px)'] = table_df['model_name'].apply(lambda name: name.split('_')[-1])
178
+ table_df['Model name'] = table_df['model_name'].apply(lambda name: name.split('_')[0])
179
+ table_df[metric_key_final] = table_df[metric_key].apply(lambda val: round(val, 3))
180
+ table_df[latency_key_final] = table_df[latency_key].apply(lambda val: round(val, 2))
181
+
182
+ def make_clickable(url, name):
183
+ return f'<a href="{url}">{name}</a>'
184
+
185
+
186
+ if dataset_name == 'COCO':
187
+ table_df['Download link'] = table_df['model_name'].apply(
188
+ lambda name: f'https://download.deeplite.ai/zoo/models/YOLOBench/{name.split("_")[0]}_640.pt'
189
+ )
190
+ table_df['Download link'] = table_df.apply(lambda x: make_clickable(x['Download link'], 'Weights download'), axis=1)
191
+ else:
192
+ table_df['Download link'] = table_df['model_name'].apply(lambda s: 'Coming soon')
193
+
194
+
195
+ table_df = table_df[['Model name', 'Input resolution (px)',
196
+ metric_key_final, latency_key_final, 'Download link']].sort_values(by=metric_key_final, ascending=False)
197
+ if not expand_table:
198
+ table_df = table_df.iloc[:10, :]
199
+
200
+ table_df = table_df.to_html(
201
+ classes='table',
202
+ escape=False, render_links=True, index=False
203
+ )
204
+
205
+ return table_df
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio==3.41.2
2
+ plotly==5.16.1
3
+ pandas==1.4.4
utils.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import urllib.parse
2
+
3
+ import pandas as pd
4
+ from gradio.themes.utils.colors import Color
5
+
6
+
7
+ DATA_URL = 'https://raw.githubusercontent.com/Deeplite/deeplite-torch-zoo/develop/results/yolobench/'
8
+
9
+ DEEPLITE_DARK_BLUE_RGB = (0, 66, 107)
10
+ DEEPLITE_DARK_BLUE_HEX = '#00426B'
11
+
12
+ DEEPLITE_LIGHT_BLUE_RGB = (0, 148, 206)
13
+ DEEPLITE_LIGHT_BLUE_HEX = '#0094CE'
14
+
15
+ DEEPLITE_DARK_BLUE_GRADIO = Color(
16
+ name='deeplite_dark_blue',
17
+ c50=DEEPLITE_DARK_BLUE_HEX,
18
+ c100=DEEPLITE_DARK_BLUE_HEX,
19
+ c200=DEEPLITE_DARK_BLUE_HEX,
20
+ c300=DEEPLITE_DARK_BLUE_HEX,
21
+ c400=DEEPLITE_DARK_BLUE_HEX,
22
+ c500=DEEPLITE_DARK_BLUE_HEX,
23
+ c600=DEEPLITE_DARK_BLUE_HEX,
24
+ c700=DEEPLITE_DARK_BLUE_HEX,
25
+ c800=DEEPLITE_DARK_BLUE_HEX,
26
+ c900=DEEPLITE_DARK_BLUE_HEX,
27
+ c950=DEEPLITE_DARK_BLUE_HEX,
28
+ )
29
+
30
+ DEEPLITE_LIGHT_BLUE_GRADIO = Color(
31
+ name='deeplite_dark_blue',
32
+ c50=DEEPLITE_LIGHT_BLUE_HEX,
33
+ c100=DEEPLITE_LIGHT_BLUE_HEX,
34
+ c200=DEEPLITE_LIGHT_BLUE_HEX,
35
+ c300=DEEPLITE_LIGHT_BLUE_HEX,
36
+ c400=DEEPLITE_LIGHT_BLUE_HEX,
37
+ c500=DEEPLITE_LIGHT_BLUE_HEX,
38
+ c600=DEEPLITE_LIGHT_BLUE_HEX,
39
+ c700=DEEPLITE_LIGHT_BLUE_HEX,
40
+ c800=DEEPLITE_LIGHT_BLUE_HEX,
41
+ c900=DEEPLITE_LIGHT_BLUE_HEX,
42
+ c950=DEEPLITE_LIGHT_BLUE_HEX,
43
+ )
44
+
45
+
46
+ def load_yolobench_data():
47
+ df = pd.read_csv(urllib.parse.urljoin(DATA_URL, 'merged_results.csv'))
48
+ pareto_indices_df = pd.read_csv(urllib.parse.urljoin(DATA_URL, 'pareto_indices.csv'))
49
+ pareto_indices = {}
50
+ for row_idx in range(pareto_indices_df.shape[0]):
51
+ data_key = pareto_indices_df.iloc[row_idx, :]['data']
52
+ if data_key not in pareto_indices:
53
+ pareto_indices[data_key] = {}
54
+ hw_key = pareto_indices_df.iloc[row_idx, :]['hardware']
55
+ indices = pareto_indices_df.iloc[row_idx, :]['pareto_indices']
56
+ indices = [int(val) for val in indices.split(',')]
57
+ pareto_indices[data_key][hw_key] = indices
58
+ return df, pareto_indices