Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

user_guide.html 70 KB

You have to be logged in to leave a comment. Sign In
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
  1. <!DOCTYPE html>
  2. <html class="writer-html5" lang="en" >
  3. <head>
  4. <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>What is SuperGradients? &mdash; SuperGradients 1.0 documentation</title>
  7. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  9. <link rel="stylesheet" href="_static/graphviz.css" type="text/css" />
  10. <!--[if lt IE 9]>
  11. <script src="_static/js/html5shiv.min.js"></script>
  12. <![endif]-->
  13. <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
  14. <script src="_static/jquery.js"></script>
  15. <script src="_static/underscore.js"></script>
  16. <script src="_static/doctools.js"></script>
  17. <script src="_static/js/theme.js"></script>
  18. <link rel="index" title="Index" href="genindex.html" />
  19. <link rel="search" title="Search" href="search.html" />
  20. <link rel="prev" title="Training package" href="super_gradients.training.html" />
  21. </head>
  22. <body class="wy-body-for-nav">
  23. <div class="wy-grid-for-nav">
  24. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  25. <div class="wy-side-scroll">
  26. <div class="wy-side-nav-search" >
  27. <a href="index.html" class="icon icon-home"> SuperGradients
  28. </a>
  29. <div role="search">
  30. <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
  31. <input type="text" name="q" placeholder="Search docs" />
  32. <input type="hidden" name="check_keywords" value="yes" />
  33. <input type="hidden" name="area" value="default" />
  34. </form>
  35. </div>
  36. </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
  37. <p class="caption"><span class="caption-text">Welcome To SuperGradients</span></p>
  38. <ul>
  39. <li class="toctree-l1"><a class="reference internal" href="welcome.html">SuperGradients</a></li>
  40. </ul>
  41. <p class="caption"><span class="caption-text">Technical Documentation</span></p>
  42. <ul>
  43. <li class="toctree-l1"><a class="reference internal" href="super_gradients.common.html">Common package</a></li>
  44. <li class="toctree-l1"><a class="reference internal" href="super_gradients.training.html">Training package</a></li>
  45. </ul>
  46. <p class="caption"><span class="caption-text">User Guide</span></p>
  47. <ul class="current">
  48. <li class="toctree-l1 current"><a class="current reference internal" href="#">What is SuperGradients?</a></li>
  49. <li class="toctree-l1"><a class="reference internal" href="#introducing-the-supergradients-library">Introducing the SuperGradients library</a></li>
  50. <li class="toctree-l1"><a class="reference internal" href="#installation">Installation</a></li>
  51. <li class="toctree-l1"><a class="reference internal" href="#integrating-your-training-code-complete-walkthrough">Integrating Your Training Code - Complete Walkthrough</a><ul>
  52. <li class="toctree-l2"><a class="reference internal" href="#integrating-your-training-code-main-components">Integrating Your Training Code: Main components:</a></li>
  53. <li class="toctree-l2"><a class="reference internal" href="#integrating-your-training-code-complete-walkthrough-dataset">Integrating Your Training Code - Complete Walkthrough: Dataset</a></li>
  54. <li class="toctree-l2"><a class="reference internal" href="#integrating-your-training-code-complete-walkthrough-model">Integrating Your Training Code - Complete Walkthrough: Model</a></li>
  55. <li class="toctree-l2"><a class="reference internal" href="#integrating-your-training-code-complete-walkthrough-loss-function">Integrating Your Training Code - Complete Walkthrough: Loss Function</a></li>
  56. <li class="toctree-l2"><a class="reference internal" href="#integrating-your-training-code-complete-walkthrough-metrics">Integrating Your Training Code - Complete Walkthrough: Metrics</a></li>
  57. <li class="toctree-l2"><a class="reference internal" href="#integrating-your-training-code-complete-walkthrough-training-script">Integrating Your Training Code- Complete Walkthrough: Training script</a><ul>
  58. <li class="toctree-l3"><a class="reference internal" href="#training-parameter-notes">Training Parameter Notes:</a></li>
  59. </ul>
  60. </li>
  61. </ul>
  62. </li>
  63. <li class="toctree-l1"><a class="reference internal" href="#training-parameters">Training Parameters</a></li>
  64. <li class="toctree-l1"><a class="reference internal" href="#logs-and-checkpoints">Logs and Checkpoints</a></li>
  65. <li class="toctree-l1"><a class="reference internal" href="#dataset-parameters">Dataset Parameters</a></li>
  66. <li class="toctree-l1"><a class="reference internal" href="#network-architectures">Network Architectures</a></li>
  67. <li class="toctree-l1"><a class="reference internal" href="#pretrained-models">Pretrained Models</a></li>
  68. <li class="toctree-l1"><a class="reference internal" href="#how-to-reproduce-our-training-recipes">How To Reproduce Our Training Recipes</a></li>
  69. <li class="toctree-l1"><a class="reference internal" href="#supergradients-faq">SuperGradients FAQ</a><ul>
  70. <li class="toctree-l2"><a class="reference internal" href="#what-type-of-tasks-does-the-supergradients-support">What Type of Tasks Does the SuperGradients Support?</a></li>
  71. </ul>
  72. </li>
  73. </ul>
  74. </div>
  75. </div>
  76. </nav>
  77. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
  78. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  79. <a href="index.html">SuperGradients</a>
  80. </nav>
  81. <div class="wy-nav-content">
  82. <div class="rst-content">
  83. <div role="navigation" aria-label="Page navigation">
  84. <ul class="wy-breadcrumbs">
  85. <li><a href="index.html" class="icon icon-home"></a> &raquo;</li>
  86. <li>What is SuperGradients?</li>
  87. <li class="wy-breadcrumbs-aside">
  88. <a href="_sources/user_guide.md.txt" rel="nofollow"> View page source</a>
  89. </li>
  90. </ul>
  91. <hr/>
  92. </div>
  93. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  94. <div itemprop="articleBody">
  95. <p><strong>Contact Information</strong></p>
  96. <p>Email – <a class="reference external" href="mailto:info&#37;&#52;&#48;deci&#46;ai">support<span>&#64;</span>deci<span>&#46;</span>ai</a></p>
  97. <p>**Israel <br />
  98. **Sasson Hugi Tower, Abba Hillel Silver Rd 12, <br />
  99. Ramat Gan, Israel</p>
  100. <p><strong>Revision History</strong></p>
  101. <table>
  102. <tr>
  103. <td>1.0.1
  104. </td>
  105. <td>December 2021
  106. </td>
  107. <td>Initial version
  108. </td>
  109. </tr>
  110. </table>
  111. <section id="what-is-supergradients">
  112. <h1>What is SuperGradients?<a class="headerlink" href="#what-is-supergradients" title="Permalink to this headline"></a></h1>
  113. <p>The SuperGradients PyTorch-based training library provides a quick, simple and free open-source platform in which you can train your models using state of the art techniques.</p>
  114. <p>Who can use SuperGradients:</p>
  115. <ul class="simple">
  116. <li><p>**Open Source Users – **The SuperGradients can be used to easily train your models regardless of whether you ever have or ever will use the <span style="text-decoration:underline;">Deci platform</span>.</p></li>
  117. <li><p>**Deci Customers – **The SuperGradients library can reproduce the training procedure performed by Deci for their optimized models.</p></li>
  118. </ul>
  119. </section>
  120. <section id="introducing-the-supergradients-library">
  121. <h1>Introducing the SuperGradients library<a class="headerlink" href="#introducing-the-supergradients-library" title="Permalink to this headline"></a></h1>
  122. <p>The <strong>SuperGradients</strong> training library** **provides all of the scripts, example code and configurations required to demonstrate how to train your model on a dataset and to enable you to do it by yourself.</p>
  123. <p>SuperGradients comes as an easily installed Python package (pip install) that you can integrate into your code base in order to train your models.</p>
  124. </section>
  125. <section id="installation">
  126. <h1>Installation<a class="headerlink" href="#installation" title="Permalink to this headline"></a></h1>
  127. <ul class="simple">
  128. <li></li>
  129. </ul>
  130. <p><strong>To install the SuperGradients library –</strong></p>
  131. <ol class="arabic">
  132. <li><p>Run the following command on your machine’s terminal –</p>
  133. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pip</span> <span class="n">install</span> <span class="n">super_gradients</span>
  134. </pre></div>
  135. </div>
  136. </li>
  137. </ol>
  138. </section>
  139. <section id="integrating-your-training-code-complete-walkthrough">
  140. <h1>Integrating Your Training Code - Complete Walkthrough<a class="headerlink" href="#integrating-your-training-code-complete-walkthrough" title="Permalink to this headline"></a></h1>
  141. <p>Whether you are a Deci customer, or an open source SuperGradients user- it is likely that you already have your own training script, model, loss function implementation etc.</p>
  142. <p>In this section we present the modifications needed in order to launch your training using SuperGradients.</p>
  143. <section id="integrating-your-training-code-main-components">
  144. <h2>Integrating Your Training Code: Main components:<a class="headerlink" href="#integrating-your-training-code-main-components" title="Permalink to this headline"></a></h2>
  145. <p><span style="text-decoration:underline;">SgModel </span>- the main class in charge of training, testing, logging and basically everything that has to do with the execution of training code.</p>
  146. <p><span style="text-decoration:underline;">DatasetInterface</span> - which is passed as an argument to the SgModel and wraps the training set, validation set and optionally a test set for the SgModel instance to work with accordingly.</p>
  147. <p><span style="text-decoration:underline;">SgModel.net</span> -The network to be used for training/testing (of torch.nn.Module type).</p>
  148. </section>
  149. <section id="integrating-your-training-code-complete-walkthrough-dataset">
  150. <h2>Integrating Your Training Code - Complete Walkthrough: Dataset<a class="headerlink" href="#integrating-your-training-code-complete-walkthrough-dataset" title="Permalink to this headline"></a></h2>
  151. <p>The specified dataset interface class must inherit from <strong>super_gradients.training.datasets.dataset_interfaces.dataset_interface</strong>, which is where data augmentation and data loader configurations are defined.</p>
  152. <p>For instance, a dataset interface for Cifar10:</p>
  153. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>
  154. <span class="kn">import</span> <span class="nn">torchvision.datasets</span> <span class="k">as</span> <span class="nn">datasets</span>
  155. <span class="kn">import</span> <span class="nn">torchvision.transforms</span> <span class="k">as</span> <span class="nn">transforms</span>
  156. <span class="kn">from</span> <span class="nn">super_gradients.training</span> <span class="kn">import</span> <span class="n">utils</span> <span class="k">as</span> <span class="n">core_utils</span>
  157. <span class="kn">from</span> <span class="nn">super_gradients.training.datasets.dataset_interfaces</span> <span class="kn">import</span> <span class="n">DatasetInterface</span>
  158. <span class="k">class</span> <span class="nc">UserDataset</span><span class="p">(</span><span class="n">DatasetInterface</span><span class="p">):</span>
  159. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;cifar10&quot;</span><span class="p">,</span> <span class="n">dataset_params</span><span class="o">=</span><span class="p">{}):</span>
  160. <span class="nb">super</span><span class="p">(</span><span class="n">UserDataset</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">dataset_params</span><span class="p">)</span>
  161. <span class="bp">self</span><span class="o">.</span><span class="n">dataset_name</span> <span class="o">=</span> <span class="n">name</span>
  162. <span class="bp">self</span><span class="o">.</span><span class="n">lib_dataset_params</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;mean&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mf">0.4914</span><span class="p">,</span> <span class="mf">0.4822</span><span class="p">,</span> <span class="mf">0.4465</span><span class="p">),</span> <span class="s1">&#39;std&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mf">0.2023</span><span class="p">,</span> <span class="mf">0.1994</span><span class="p">,</span> <span class="mf">0.2010</span><span class="p">)}</span>
  163. <span class="n">crop_size</span> <span class="o">=</span> <span class="n">core_utils</span><span class="o">.</span><span class="n">get_param</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_params</span><span class="p">,</span> <span class="s1">&#39;crop_size&#39;</span><span class="p">,</span> <span class="n">default_val</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
  164. <span class="n">transform_train</span> <span class="o">=</span> <span class="n">transforms</span><span class="o">.</span><span class="n">Compose</span><span class="p">([</span>
  165. <span class="n">transforms</span><span class="o">.</span><span class="n">RandomCrop</span><span class="p">(</span><span class="n">crop_size</span><span class="p">,</span> <span class="n">padding</span><span class="o">=</span><span class="mi">4</span><span class="p">),</span>
  166. <span class="n">transforms</span><span class="o">.</span><span class="n">RandomHorizontalFlip</span><span class="p">(),</span>
  167. <span class="n">transforms</span><span class="o">.</span><span class="n">ToTensor</span><span class="p">(),</span>
  168. <span class="n">transforms</span><span class="o">.</span><span class="n">Normalize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lib_dataset_params</span><span class="p">[</span><span class="s1">&#39;mean&#39;</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">lib_dataset_params</span><span class="p">[</span><span class="s1">&#39;std&#39;</span><span class="p">]),</span>
  169. <span class="p">])</span>
  170. <span class="n">transform_val</span> <span class="o">=</span> <span class="n">transforms</span><span class="o">.</span><span class="n">Compose</span><span class="p">([</span>
  171. <span class="n">transforms</span><span class="o">.</span><span class="n">ToTensor</span><span class="p">(),</span>
  172. <span class="n">transforms</span><span class="o">.</span><span class="n">Normalize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lib_dataset_params</span><span class="p">[</span><span class="s1">&#39;mean&#39;</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">lib_dataset_params</span><span class="p">[</span><span class="s1">&#39;std&#39;</span><span class="p">]),</span>
  173. <span class="p">])</span>
  174. <span class="bp">self</span><span class="o">.</span><span class="n">trainset</span> <span class="o">=</span> <span class="n">datasets</span><span class="o">.</span><span class="n">CIFAR10</span><span class="p">(</span><span class="n">root</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_params</span><span class="o">.</span><span class="n">dataset_dir</span><span class="p">,</span> <span class="n">train</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">download</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
  175. <span class="n">transform</span><span class="o">=</span><span class="n">transform_train</span><span class="p">)</span>
  176. <span class="bp">self</span><span class="o">.</span><span class="n">valset</span> <span class="o">=</span> <span class="n">datasets</span><span class="o">.</span><span class="n">CIFAR10</span><span class="p">(</span><span class="n">root</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_params</span><span class="o">.</span><span class="n">dataset_dir</span><span class="p">,</span> <span class="n">train</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">download</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
  177. <span class="n">transform</span><span class="o">=</span><span class="n">transform_val</span><span class="p">)</span>
  178. </pre></div>
  179. </div>
  180. <p>Required parameters can be passed using the <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">dataset_params</span></code> argument. When implementing a dataset interface, the<code class="docutils literal notranslate"><span class="pre">trainset</span></code> and <code class="docutils literal notranslate"><span class="pre">valset</span></code> attributes are required and must be initiated with a <em>torch.utils.data.Dataset</em> type. These fields will cause the <em>SgModule</em> instance to use them accordingly, such as during training, testing, and so on.</p>
  181. </section>
  182. <section id="integrating-your-training-code-complete-walkthrough-model">
  183. <h2>Integrating Your Training Code - Complete Walkthrough: Model<a class="headerlink" href="#integrating-your-training-code-complete-walkthrough-model" title="Permalink to this headline"></a></h2>
  184. <p>This is rather straightforward- the only requirement is that the model must be of torch.nn.Module type. In our case, a simple Lenet implementation (taken from https://github.com/icpm/pytorch-cifar10/blob/master/models/LeNet.py).</p>
  185. <table>
  186. <tr>
  187. </tr>
  188. </table>
  189. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">torch.nn</span> <span class="k">as</span> <span class="nn">nn</span>
  190. <span class="kn">import</span> <span class="nn">torch.nn.functional</span> <span class="k">as</span> <span class="nn">func</span>
  191. <span class="k">class</span> <span class="nc">LeNet</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">):</span>
  192. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  193. <span class="nb">super</span><span class="p">(</span><span class="n">LeNet</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
  194. <span class="bp">self</span><span class="o">.</span><span class="n">conv1</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Conv2d</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="n">kernel_size</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
  195. <span class="bp">self</span><span class="o">.</span><span class="n">conv2</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Conv2d</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="mi">16</span><span class="p">,</span> <span class="n">kernel_size</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
  196. <span class="bp">self</span><span class="o">.</span><span class="n">fc1</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Linear</span><span class="p">(</span><span class="mi">16</span><span class="o">*</span><span class="mi">5</span><span class="o">*</span><span class="mi">5</span><span class="p">,</span> <span class="mi">120</span><span class="p">)</span>
  197. <span class="bp">self</span><span class="o">.</span><span class="n">fc2</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Linear</span><span class="p">(</span><span class="mi">120</span><span class="p">,</span> <span class="mi">84</span><span class="p">)</span>
  198. <span class="bp">self</span><span class="o">.</span><span class="n">fc3</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Linear</span><span class="p">(</span><span class="mi">84</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
  199. <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
  200. <span class="n">x</span> <span class="o">=</span> <span class="n">func</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">conv1</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
  201. <span class="n">x</span> <span class="o">=</span> <span class="n">func</span><span class="o">.</span><span class="n">max_pool2d</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
  202. <span class="n">x</span> <span class="o">=</span> <span class="n">func</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">conv2</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
  203. <span class="n">x</span> <span class="o">=</span> <span class="n">func</span><span class="o">.</span><span class="n">max_pool2d</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
  204. <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
  205. <span class="n">x</span> <span class="o">=</span> <span class="n">func</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fc1</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
  206. <span class="n">x</span> <span class="o">=</span> <span class="n">func</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fc2</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
  207. <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fc3</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
  208. <span class="k">return</span> <span class="n">x</span>
  209. </pre></div>
  210. </div>
  211. </section>
  212. <section id="integrating-your-training-code-complete-walkthrough-loss-function">
  213. <h2>Integrating Your Training Code - Complete Walkthrough: Loss Function<a class="headerlink" href="#integrating-your-training-code-complete-walkthrough-loss-function" title="Permalink to this headline"></a></h2>
  214. <p>The loss function class must be of _torch.nn.module.<em>LOSS</em> type. For example, our _LabelSmoothingCrossEntropyLoss _implementation.</p>
  215. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">torch.nn</span> <span class="k">as</span> <span class="nn">nn</span>
  216. <span class="kn">from</span> <span class="nn">super_gradients.training.losses.label_smoothing_cross_entropy_loss</span> <span class="kn">import</span> <span class="n">cross_entropy</span>
  217. <span class="k">class</span> <span class="nc">LabelSmoothingCrossEntropyLoss</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">CrossEntropyLoss</span><span class="p">):</span>
  218. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">weight</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=-</span><span class="mi">100</span><span class="p">,</span> <span class="n">reduction</span><span class="o">=</span><span class="s1">&#39;mean&#39;</span><span class="p">,</span> <span class="n">smooth_eps</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">smooth_dist</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
  219. <span class="n">from_logits</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
  220. <span class="nb">super</span><span class="p">(</span><span class="n">LabelSmoothingCrossEntropyLoss</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">weight</span><span class="o">=</span><span class="n">weight</span><span class="p">,</span>
  221. <span class="n">ignore_index</span><span class="o">=</span><span class="n">ignore_index</span><span class="p">,</span> <span class="n">reduction</span><span class="o">=</span><span class="n">reduction</span><span class="p">)</span>
  222. <span class="bp">self</span><span class="o">.</span><span class="n">smooth_eps</span> <span class="o">=</span> <span class="n">smooth_eps</span>
  223. <span class="bp">self</span><span class="o">.</span><span class="n">smooth_dist</span> <span class="o">=</span> <span class="n">smooth_dist</span>
  224. <span class="bp">self</span><span class="o">.</span><span class="n">from_logits</span> <span class="o">=</span> <span class="n">from_logits</span>
  225. <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">smooth_dist</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
  226. <span class="k">if</span> <span class="n">smooth_dist</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
  227. <span class="n">smooth_dist</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">smooth_dist</span>
  228. <span class="n">loss</span> <span class="o">=</span> <span class="n">cross_entropy</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">weight</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">weight</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ignore_index</span><span class="p">,</span>
  229. <span class="n">reduction</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">reduction</span><span class="p">,</span> <span class="n">smooth_eps</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">smooth_eps</span><span class="p">,</span>
  230. <span class="n">smooth_dist</span><span class="o">=</span><span class="n">smooth_dist</span><span class="p">,</span> <span class="n">from_logits</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">from_logits</span><span class="p">)</span>
  231. <span class="k">return</span> <span class="n">loss</span>
  232. </pre></div>
  233. </div>
  234. <p><strong>Important –</strong> <em>forward(…)</em> may return a (loss, loss_items) tuple instead of just a single item (i.e loss), where –</p>
  235. <p><em>loss</em> is the tensor used for backprop, meaning what your original loss function returns.</p>
  236. <p><em>loss_items</em> must be a tensor of shape (n_items) that is composed of values that are computed during the forward pass, so that it can be logged over the entire epoch.</p>
  237. <p>For example, the loss itself should always be logged. Another example is a scenario where the computed loss is the sum of a few components. These entries should be logged in loss_items.</p>
  238. <p>During training, set the <em><span style="text-decoration:underline;">loss_logging_items_names</span></em> parameter in _<span style="text-decoration:underline;">training_params</span> _to be a list of strings of length <em>n_items</em>, whose ith element is the name of the ith entry in loss_items. In this way, each item will be logged, rendered and monitored in TensorBoard, thus saving model checkpoints accordingly.</p>
  239. <p>Because running logs save the loss_items in some internal state. It is therefore recommended that loss_items be detached from their computational graph for memory efficiency.</p>
  240. </section>
  241. <section id="integrating-your-training-code-complete-walkthrough-metrics">
  242. <h2>Integrating Your Training Code - Complete Walkthrough: Metrics<a class="headerlink" href="#integrating-your-training-code-complete-walkthrough-metrics" title="Permalink to this headline"></a></h2>
  243. <p>The metrics objects to be logged during training must be of torchmetrics.Metric type. For more information on how to use torchmetric.Metric objects and implement your own metrics. see https://torchmetrics.readthedocs.io/en/latest/pages/overview.html.</p>
  244. <p>During training, the metric’s update is called with the model’s raw outputs and raw targets. Therefore, any processing of the two must be taken into account and applied in the <em>update</em>.</p>
  245. <p>Training works out of the box with any of the module torchmetrics (full list in <a class="reference external" href="https://torchmetrics.readthedocs.io/en/latest/references/modules.html">https://torchmetrics.readthedocs.io/en/latest/references/modules.html</a>). Additional metrics implementations such as mean average precision for object detection can be found at <em>super_gradients.training.metrics</em>)</p>
  246. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">torchmetrics</span>
  247. <span class="kn">import</span> <span class="nn">torch</span>
  248. <span class="k">class</span> <span class="nc">Accuracy</span><span class="p">(</span><span class="n">torchmetrics</span><span class="o">.</span><span class="n">Accuracy</span><span class="p">):</span>
  249. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dist_sync_on_step</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
  250. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">dist_sync_on_step</span><span class="o">=</span><span class="n">dist_sync_on_step</span><span class="p">,</span> <span class="n">top_k</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
  251. <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">preds</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">):</span>
  252. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">preds</span><span class="o">=</span><span class="n">preds</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">target</span><span class="o">=</span><span class="n">target</span><span class="p">)</span>
  253. <span class="k">class</span> <span class="nc">Top5</span><span class="p">(</span><span class="n">torchmetrics</span><span class="o">.</span><span class="n">Accuracy</span><span class="p">):</span>
  254. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dist_sync_on_step</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
  255. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">dist_sync_on_step</span><span class="o">=</span><span class="n">dist_sync_on_step</span><span class="p">,</span> <span class="n">top_k</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
  256. <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">preds</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">):</span>
  257. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">preds</span><span class="o">=</span><span class="n">preds</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">target</span><span class="o">=</span><span class="n">target</span><span class="p">)</span>
  258. </pre></div>
  259. </div>
  260. </section>
  261. <section id="integrating-your-training-code-complete-walkthrough-training-script">
  262. <h2>Integrating Your Training Code- Complete Walkthrough: Training script<a class="headerlink" href="#integrating-your-training-code-complete-walkthrough-training-script" title="Permalink to this headline"></a></h2>
  263. <p>We instantiate an SgModel and a UserDatasetInterface, then call connect_dataset_interface which will initialize the dataloaders and pass additional dataset parameters to the SgModel instance.</p>
  264. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">super_gradients.training</span> <span class="kn">import</span> <span class="n">SgModel</span>
  265. <span class="n">sg_model</span> <span class="o">=</span> <span class="n">SgModel</span><span class="p">(</span><span class="n">experiment_name</span><span class="o">=</span><span class="s1">&#39;LeNet_cifar10_example&#39;</span><span class="p">)</span>
  266. <span class="n">dataset_params</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;batch_size&quot;</span><span class="p">:</span> <span class="mi">256</span><span class="p">}</span>
  267. <span class="n">dataset</span> <span class="o">=</span> <span class="n">UserDataset</span><span class="p">(</span><span class="n">dataset_params</span><span class="p">)</span>
  268. <span class="n">sg_model</span><span class="o">.</span><span class="n">connect_dataset_interface</span><span class="p">(</span><span class="n">dataset</span><span class="p">)</span>
  269. </pre></div>
  270. </div>
  271. <p><strong>Now, we pass a LeNet instance we defined above to the SgModel:</strong></p>
  272. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">network</span> <span class="o">=</span> <span class="n">LeNet</span><span class="p">()</span>
  273. <span class="n">sg_model</span><span class="o">.</span><span class="n">build_model</span><span class="p">(</span><span class="n">network</span><span class="p">)</span>
  274. </pre></div>
  275. </div>
  276. <p><strong>Next, we define metrics in order to evaluate our model.</strong></p>
  277. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">super_gradients.training.metrics</span> <span class="kn">import</span> <span class="n">Accuracy</span><span class="p">,</span> <span class="n">Top5</span>
  278. <span class="n">train_metrics_list</span> <span class="o">=</span> <span class="p">[</span><span class="n">Accuracy</span><span class="p">(),</span> <span class="n">Top5</span><span class="p">()]</span>
  279. <span class="n">valid_metrics_list</span> <span class="o">=</span> <span class="p">[</span><span class="n">Accuracy</span><span class="p">(),</span> <span class="n">Top5</span><span class="p">()]</span>
  280. </pre></div>
  281. </div>
  282. <p>Initializing the loss, and specifying training parameters</p>
  283. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">train_params</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;max_epochs&quot;</span><span class="p">:</span> <span class="mi">250</span><span class="p">,</span>
  284. <span class="s2">&quot;lr_updates&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">100</span><span class="p">,</span> <span class="mi">150</span><span class="p">,</span> <span class="mi">200</span><span class="p">],</span>
  285. <span class="s2">&quot;lr_decay_factor&quot;</span><span class="p">:</span> <span class="mf">0.1</span><span class="p">,</span>
  286. <span class="s2">&quot;lr_mode&quot;</span><span class="p">:</span> <span class="s2">&quot;step&quot;</span><span class="p">,</span>
  287. <span class="s2">&quot;lr_warmup_epochs&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
  288. <span class="s2">&quot;initial_lr&quot;</span><span class="p">:</span> <span class="mf">0.1</span><span class="p">,</span>
  289. <span class="s2">&quot;loss&quot;</span><span class="p">:</span> <span class="n">LabelSmoothingCrossEntropyLoss</span><span class="p">(),</span>
  290. <span class="s2">&quot;criterion_params&quot;</span><span class="p">:</span> <span class="p">{},</span>
  291. <span class="s2">&quot;optimizer&quot;</span><span class="p">:</span> <span class="s2">&quot;SGD&quot;</span><span class="p">,</span>
  292. <span class="s2">&quot;optimizer_params&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;weight_decay&quot;</span><span class="p">:</span> <span class="mf">1e-4</span><span class="p">,</span> <span class="s2">&quot;momentum&quot;</span><span class="p">:</span><span class="mf">0.9</span><span class="p">},</span>
  293. <span class="s2">&quot;launch_tensorboard&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
  294. <span class="s2">&quot;train_metrics_list&quot;</span><span class="p">:</span> <span class="n">train_metrics_list</span><span class="p">,</span>
  295. <span class="s2">&quot;valid_metrics_list&quot;</span><span class="p">:</span> <span class="n">valid_metrics_list</span><span class="p">,</span>
  296. <span class="s2">&quot;loss_logging_items_names&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Loss&quot;</span><span class="p">],</span>
  297. <span class="s2">&quot;metric_to_watch&quot;</span><span class="p">:</span> <span class="s2">&quot;Accuracy&quot;</span><span class="p">,</span>
  298. <span class="s2">&quot;greater_metric_to_watch_is_better&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">}</span>
  299. <span class="n">sg_model</span><span class="o">.</span><span class="n">train</span><span class="p">(</span><span class="n">train_params</span><span class="p">)</span>
  300. </pre></div>
  301. </div>
  302. <section id="training-parameter-notes">
  303. <h3>Training Parameter Notes:<a class="headerlink" href="#training-parameter-notes" title="Permalink to this headline"></a></h3>
  304. <ul class="simple">
  305. <li><p>_<span style="text-decoration:underline;">loss_logging_items_names</span> _parameter – Refers to the single item returned in <em>loss_items</em> in our loss function described above.</p></li>
  306. <li><p><em><span style="text-decoration:underline;">metric_to_watch</span></em> – Is the model’s metric that determines the checkpoint to be saved. In our example, this parameter is set to <em>Accuracy</em>, and can be set to any of the following:</p></li>
  307. <li><p>A metric name (str) of one of the metric objects from the _valid_metrics_lis_t.</p></li>
  308. <li><p>A <em>metric_name</em> that represents a metric that appears in <em>valid_metrics_list</em> and has an attribute <em>component_names</em>. <em>component_names</em> is a list that refers to the names of each entry in the output metric (torch tensor of size n).</p></li>
  309. <li><p>One of the <em>loss_logging_items_names</em>, such as one that corresponds to an item returned during the loss function’s forward pass as discussed earlier.</p></li>
  310. <li><p><em><span style="text-decoration:underline;">greater_metric_to_watch_is_better flag </span></em>– Determines when to save a model’s checkpoint according to the value of the <code class="docutils literal notranslate"><span class="pre">metric_to_watch</span></code>.</p></li>
  311. </ul>
  312. </section>
  313. </section>
  314. </section>
  315. <section id="training-parameters">
  316. <h1>Training Parameters<a class="headerlink" href="#training-parameters" title="Permalink to this headline"></a></h1>
  317. <p>The following is a description of all the parameters passed in _training_params _when _<span style="text-decoration:underline;">train() </span>_is called.</p>
  318. <p><code class="docutils literal notranslate"><span class="pre">max_epochs</span></code>: int</p>
  319. <p>Number of epochs to run during training.</p>
  320. <p><code class="docutils literal notranslate"><span class="pre">lr_updates</span></code>: list(int)</p>
  321. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>List of fixed epoch numbers to perform learning rate updates when `lr_mode=&#39;step&#39;`.
  322. </pre></div>
  323. </div>
  324. <p><code class="docutils literal notranslate"><span class="pre">lr_decay_factor</span></code>: float</p>
  325. <p>Decay factor to apply to the learning rate at each update when <em>lr_mode=’step’</em>.</p>
  326. <p><code class="docutils literal notranslate"><span class="pre">lr_mode</span></code>: str</p>
  327. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Learning rate scheduling policy, one of [&#39;step&#39;,&#39;poly&#39;,&#39;cosine&#39;,&#39;function&#39;].
  328. </pre></div>
  329. </div>
  330. <ul class="simple">
  331. <li><p>‘step’ refers to constant updates of epoch numbers passed through <code class="docutils literal notranslate"><span class="pre">lr_updates</span></code>.</p></li>
  332. <li><p>‘cosine’ refers to Cosine Annealing policy as described in https://arxiv.org/abs/1608.03983.</p></li>
  333. <li><p>‘poly’ refers to polynomial decrease, such as in each epoch iteration <code class="docutils literal notranslate"><span class="pre">self.lr</span> <span class="pre">=</span> <span class="pre">self.initial_lr</span> <span class="pre">*</span> <span class="pre">pow((1.0</span> <span class="pre">-</span> <span class="pre">(current_iter</span> <span class="pre">/</span> <span class="pre">max_iter)),</span> <span class="pre">0.9)</span></code></p></li>
  334. <li><p>‘function’ refers to a user defined learning rate scheduling function, that is passed through <code class="docutils literal notranslate"><span class="pre">lr_schedule_function</span></code>.</p></li>
  335. </ul>
  336. <p><code class="docutils literal notranslate"><span class="pre">lr_schedule_function</span></code>: Union[callable,None]</p>
  337. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Learning rate scheduling function to be used when `lr_mode` is &#39;function&#39;.
  338. </pre></div>
  339. </div>
  340. <p><code class="docutils literal notranslate"><span class="pre">lr_warmup_epochs</span></code>: int (default=0)</p>
  341. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Number of epochs for learning rate warm up. For more information, you may refer to https://arxiv.org/pdf/1706.02677.pdf (Section 2.2).
  342. </pre></div>
  343. </div>
  344. <p><code class="docutils literal notranslate"><span class="pre">cosine_final_lr_ratio</span></code>: float (default=0.01)</p>
  345. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Final learning rate ratio (only relevant when `lr_mode`=&#39;cosine&#39;). The cosine starts from initial_lr and reaches initial_lr * cosine_final_lr_ratio in the last epoch.
  346. </pre></div>
  347. </div>
  348. <p><code class="docutils literal notranslate"><span class="pre">inital_lr</span></code>: float</p>
  349. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Initial learning rate.
  350. </pre></div>
  351. </div>
  352. <p><code class="docutils literal notranslate"><span class="pre">loss</span></code>: Union[nn.module, str]</p>
  353. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Loss function to be used for training.
  354. One of super_gradients&#39;s built in options:
  355. &quot;cross_entropy&quot;: LabelSmoothingCrossEntropyLoss,
  356. &quot;mse&quot;: MSELoss,
  357. &quot;r_squared_loss&quot;: RSquaredLoss,
  358. &quot;detection_loss&quot;: YoLoV3DetectionLoss,
  359. &quot;shelfnet_ohem_loss&quot;: ShelfNetOHEMLoss,
  360. &quot;shelfnet_se_loss&quot;: ShelfNetSemanticEncodingLoss,
  361. &quot;yolo_v5_loss&quot;: YoLoV5DetectionLoss,
  362. &quot;ssd_loss&quot;: SSDLoss,
  363. or user defined nn.module loss function.
  364. **Important –** _forward(...)_ should return a (loss, loss_items) tuple, where –
  365. </pre></div>
  366. </div>
  367. <ul>
  368. <li><p><em>loss</em> is the tensor used for backprop, meaning what your original loss function returns</p></li>
  369. <li><p><em>loss_items</em> must be a tensor of shape (n_items) of values computed during the forward pass, so that they can be logged over the entire epoch.</p>
  370. <p>For example, the loss itself should always be logged. Another example is a scenario where the computed loss is the sum of a few components. These entries should be returned in loss_items.</p>
  371. <p>During training, set the <em>loss_logging_items_names</em> parameter in _training_params _to be a list of strings of length <em>n_items</em>, whose ith element is the name of the ith entry in loss_items. In this way, each item will be logged, rendered on TensorBoard and monitored, thus saving model checkpoints accordingly.</p>
  372. <p>Running logs saves the loss_items in some internal state. It is therefore recommended that loss_items be detached from their computational graph for memory efficiency.</p>
  373. </li>
  374. </ul>
  375. <p><code class="docutils literal notranslate"><span class="pre">optimizer</span></code>: str</p>
  376. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Optimization algorithm. One of [&#39;Adam&#39;,&#39;SGD&#39;,&#39;RMSProp&#39;] corresponding to the torch.optim optimzer implementations.
  377. </pre></div>
  378. </div>
  379. <p><code class="docutils literal notranslate"><span class="pre">criterion_params</span></code>: dict</p>
  380. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Loss function parameters.
  381. </pre></div>
  382. </div>
  383. <p><code class="docutils literal notranslate"><span class="pre">optimizer_params</span></code>: dict</p>
  384. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Optimizer parameters. You may refer to https://pytorch.org/docs/stable/optim.html for the full list of the parameters for each optimizer.
  385. </pre></div>
  386. </div>
  387. <p><code class="docutils literal notranslate"><span class="pre">train_metrics_list</span></code>: list(torchmetrics.Metric)</p>
  388. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Metrics to log during training. You may refer to [https://torchmetrics.rtfd.io/en/latest/](https://torchmetrics.rtfd.io/en/latest/), for more information about TorchMetrics.
  389. </pre></div>
  390. </div>
  391. <p><code class="docutils literal notranslate"><span class="pre">valid_metrics_list</span></code>: list(torchmetrics.Metric)</p>
  392. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Metrics to log during validation/testing. You may refer to [https://torchmetrics.rtfd.io/en/latest/](https://torchmetrics.rtfd.io/en/latest/), for more information about TorchMetrics.
  393. </pre></div>
  394. </div>
  395. <p><code class="docutils literal notranslate"><span class="pre">loss_logging_items_names</span></code>: list(str)</p>
  396. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>The list of names/titles for the outputs returned from the loss function’s forward pass. These names are used to log their values.
  397. **Note – **The loss function should return the tuple (loss, loss_items).
  398. </pre></div>
  399. </div>
  400. <p><code class="docutils literal notranslate"><span class="pre">metric_to_watch</span></code>: str (default=”Accuracy”)</p>
  401. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Specifies the metric according to which the model checkpoint is saved. It can be set to any of the following:
  402. </pre></div>
  403. </div>
  404. <ul>
  405. <li><p>A metric name (str) of one of the metric objects from the valid_metrics_list</p></li>
  406. <li><p>A “metric_name” to be used if any metric in the valid_metrics_list has an attribute component_names, which is a list referring to the names of each entry in the output metric (torch tensor of size n).</p></li>
  407. <li><p>One of the “loss_logging_items_names” <code class="docutils literal notranslate"><span class="pre">that</span></code> corresponds to an item to be returned during the loss function’s forward pass.</p>
  408. <p>At the end of each epoch, if a new best _metric_to_watch _value is achieved, the model’s checkpoint is saved in YOUR_PYTHON_PATH/checkpoints/ckpt_best.pth.</p>
  409. </li>
  410. </ul>
  411. <p><code class="docutils literal notranslate"><span class="pre">greater_metric_to_watch_is_better</span></code>: bool</p>
  412. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Determines when to save a model&#39;s checkpoint according to the value of the` metric_to_watch:`
  413. </pre></div>
  414. </div>
  415. <ul class="simple">
  416. <li><p>_True: _A model’s checkpoint is saved when the model achieves the highest metric_to_watch.</p></li>
  417. <li><p><em>False:</em> A model’s checkpoint is saved when the model achieves the lowest metric_to_watch.</p></li>
  418. </ul>
  419. <p><code class="docutils literal notranslate"><span class="pre">ema</span></code>: bool (default=False)</p>
  420. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Specifies whether to use Model Exponential Moving Average. You may refer to https://github.com/rwightman/pytorch-image-models ema implementation), for more information.
  421. </pre></div>
  422. </div>
  423. <p><code class="docutils literal notranslate"><span class="pre">batch_accumulate</span></code>: int (default=1)</p>
  424. <p>Number of batches to accumulate before every backward pass.</p>
  425. <p><code class="docutils literal notranslate"><span class="pre">ema_params</span></code>: dict</p>
  426. <p>Parameters for the ema model.</p>
  427. <p><code class="docutils literal notranslate"><span class="pre">zero_weight_decay_on_bias_and_bn</span></code>: bool (default=False)</p>
  428. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Specifies whether to apply weight decay on batch normalization parameters or not.
  429. </pre></div>
  430. </div>
  431. <p><code class="docutils literal notranslate"><span class="pre">load_opt_params</span></code>: bool (default=True)</p>
  432. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Specifies whether to load the optimizers parameters (as well) when loading a model&#39;s checkpoint.
  433. </pre></div>
  434. </div>
  435. <p><code class="docutils literal notranslate"><span class="pre">run_validation_freq</span></code>: int (default=1)</p>
  436. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>The frequency at which validation is performed during training. This means that the validation is run every `run_validation_freq` epochs.
  437. </pre></div>
  438. </div>
  439. <p><code class="docutils literal notranslate"><span class="pre">save_model</span></code>: bool (default=True)</p>
  440. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span> Specifies whether to save the model’s checkpoints.
  441. </pre></div>
  442. </div>
  443. <p><code class="docutils literal notranslate"><span class="pre">launch_tensorboard</span></code>: bool (default=False)</p>
  444. <p>Specifies whether to launch a TensorBoard process.</p>
  445. <p><code class="docutils literal notranslate"><span class="pre">tb_files_user_prompt</span></code>: bool</p>
  446. <p>Displays the TensorBoard deletion user prompt.</p>
  447. <p><code class="docutils literal notranslate"><span class="pre">silent_mode</span></code>: bool</p>
  448. <p>Deactivates the printouts.</p>
  449. <p><code class="docutils literal notranslate"><span class="pre">mixed_precision</span></code>: bool</p>
  450. <p>Specifies whether to use mixed precision or not.</p>
  451. <p><code class="docutils literal notranslate"><span class="pre">tensorboard_port</span></code>: int, None (default=None)</p>
  452. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Specific port number for the TensorBoard to use when launched (when set to None, some free port number will be used).
  453. </pre></div>
  454. </div>
  455. <p><code class="docutils literal notranslate"><span class="pre">save_ckpt_epoch_list</span></code>: list(int) (default=[])</p>
  456. <p>Specifies the list of fixed epoch indices in which to save checkpoints.</p>
  457. <p><code class="docutils literal notranslate"><span class="pre">average_best_models</span></code>: bool (default=False)</p>
  458. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>If True, a snapshot dictionary file and the average model will be saved / updated at every epoch and only evaluated after the training has completed. The snapshot file will only be deleted upon completing the training. The snapshot dict will be managed on the CPU.
  459. </pre></div>
  460. </div>
  461. <p><code class="docutils literal notranslate"><span class="pre">save_tensorboard_to_s3</span></code>: bool (default=False)</p>
  462. <p>If True, saves the TensorBoard in S3.</p>
  463. <p><code class="docutils literal notranslate"><span class="pre">precise_bn</span></code>: bool (default=False)</p>
  464. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span> Whether to use precise_bn calculation during the training.
  465. </pre></div>
  466. </div>
  467. <p><code class="docutils literal notranslate"><span class="pre">precise_bn_batch_size</span></code>: int (default=None)</p>
  468. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>The effective batch size we want to calculate the batchnorm on. For example, if we are training a model on 8 gpus, with a batch of 128 on each gpu, a good rule of thumb would be to give it 8192 (ie: effective_batch_size * num_gpus = batch_per_gpu * m_gpus * num_gpus). If precise_bn_batch_size is not provided in the training_params, the latter heuristic will be taken.
  469. </pre></div>
  470. </div>
  471. <p><code class="docutils literal notranslate"><span class="pre">seed</span></code> : int (default=42)</p>
  472. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Random seed to be set for torch, numpy, and random. When using DDP each process will have it&#39;s seed set to seed + rank.
  473. </pre></div>
  474. </div>
  475. <p><code class="docutils literal notranslate"><span class="pre">log_installed_packages</span></code>: bool (default=False)</p>
  476. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>When set, the list of all installed packages (and their versions) will be written to the tensorboard and logfile (useful when trying to reproduce results).
  477. </pre></div>
  478. </div>
  479. <p><code class="docutils literal notranslate"><span class="pre">dataset_statistics</span></code>:: bool (default=False)</p>
  480. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Enable a statistic analysis of the dataset. If set to True the dataset will be analyzed and a report will be added to the tensorboard along with some sample images from the dataset. Currently only detection datasets are supported for analysis.
  481. </pre></div>
  482. </div>
  483. <p><code class="docutils literal notranslate"><span class="pre">save_full_train_log</span></code> : bool (default=False)</p>
  484. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>When set, a full log (of all super_gradients modules, including uncaught exceptions from any other module) of the training will be saved in the checkpoint directory under full_train_log.log
  485. </pre></div>
  486. </div>
  487. </section>
  488. <section id="logs-and-checkpoints">
  489. <h1>Logs and Checkpoints<a class="headerlink" href="#logs-and-checkpoints" title="Permalink to this headline"></a></h1>
  490. <p>The model’s weights, logs and tensorboards are saved in _”YOUR_PYTHONPATH”/ checkpoints/”YOUR_EXPERIMENT_NAME” _. (In our walkthrough example, _”YOUR_EXPERIMENT_NAME” _ is <em>user_model_training)</em>.</p>
  491. <ul class="simple">
  492. <li></li>
  493. </ul>
  494. <p><strong>To watch training progress –</strong></p>
  495. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>**1st option:**
  496. </pre></div>
  497. </div>
  498. <ol class="arabic">
  499. <li><p>Open a terminal.</p></li>
  500. <li><p>Navigate to _”YOUR_LOCAL_PATH_TO_super_gradients_PACKAGE”/ _and run ``tensorboard –logdir checkpoints –bind_all`.</p>
  501. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span> The message `TensorBoard 2.4.1 at http://localhost:XXXX/` appears.
  502. </pre></div>
  503. </div>
  504. </li>
  505. <li><p>Follow the link in this message to see the progress of the training.</p>
  506. <p><strong>2nd option:</strong></p>
  507. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span> Set the “launch_tensorboard_process” flag in your training_params passed to SgModel.train(...), and follow instructions displayed in the shell.
  508. </pre></div>
  509. </div>
  510. </li>
  511. </ol>
  512. <ul class="simple">
  513. <li></li>
  514. </ul>
  515. <p><strong>To resume training –</strong>
  516. When building the network- call SgModel.build_model(…load_checkpoint=True). Doing so, will load the network’s weights, as well as any relevant information for resuming training (monitored metric values, optimizer states, etc) with the latest checkpoint. For more advanced usage see SgModel.build_model docs in code.</p>
  517. <ul class="simple">
  518. <li></li>
  519. </ul>
  520. <p><strong>Checkpoint structure – state_dict (see <a class="reference external" href="https://pytorch.org/tutorials/beginner/saving_loading_models.html">https://pytorch.org/tutorials/beginner/saving_loading_models.html</a> for more information regarding state_dicts) with the following keys:</strong>
  521. <strong>-”net”- The network’s state_dict.</strong></p>
  522. <p><strong>-”acc”- The value of <code class="docutils literal notranslate"><span class="pre">metric_to_watch</span></code> from training.</strong></p>
  523. <p><strong>-”epoch”- Last epoch performed before saving this checkpoint.</strong></p>
  524. <p>**-”ema_net” [Optionall, exists if training was performed with EMA] - **</p>
  525. <p><strong>The state dict of the EMA net.</strong></p>
  526. <p><strong>-”optimizer_state_dict”- Optimizer’s state dict from training.</strong></p>
  527. <p><strong>-”scaler_state_dict”- Gradient scalar state_dict from training.</strong></p>
  528. </section>
  529. <section id="dataset-parameters">
  530. <h1>Dataset Parameters<a class="headerlink" href="#dataset-parameters" title="Permalink to this headline"></a></h1>
  531. <p>dataset_params argument passed to SgModel.build_model().</p>
  532. <p><code class="docutils literal notranslate"><span class="pre">batch_size</span></code>: int (default=64)</p>
  533. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Number of examples per batch for training. Large batch sizes are recommended.
  534. </pre></div>
  535. </div>
  536. <p><code class="docutils literal notranslate"><span class="pre">test_batch_size</span></code>: int (default=200)</p>
  537. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Number of examples per batch for test/validation. Large batch sizes are recommended.
  538. </pre></div>
  539. </div>
  540. <p><code class="docutils literal notranslate"><span class="pre">dataset_dir</span></code>: str (default=”./data/”)</p>
  541. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Directory location for the data. Data will be downloaded to this directory when received from a remote URL.
  542. </pre></div>
  543. </div>
  544. <p><code class="docutils literal notranslate"><span class="pre">s3_link</span></code>: str (default=None)</p>
  545. <p>The remote s3 link from which to download the data (optional).</p>
  546. </section>
  547. <section id="network-architectures">
  548. <h1>Network Architectures<a class="headerlink" href="#network-architectures" title="Permalink to this headline"></a></h1>
  549. <p>The following architectures are implemented in SuperGradients’ code, and can be initialized by passing their name (i.e string) to SgModel.build_model easily.</p>
  550. <p>For example:</p>
  551. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sg_model</span> <span class="o">=</span> <span class="n">SgModel</span><span class="p">(</span><span class="s2">&quot;resnet50_experiment&quot;</span><span class="p">)</span>
  552. <span class="n">sg_model</span><span class="o">.</span><span class="n">build_model</span><span class="p">(</span><span class="n">architecture</span><span class="o">=</span><span class="s2">&quot;resnet50&quot;</span><span class="p">)</span>
  553. </pre></div>
  554. </div>
  555. <p>Will initialize a resnet50 and set it to be sg_model’s network attribute, which will be used for training.</p>
  556. <p><strong>‘resnet18’,</strong></p>
  557. <p>** ‘resnet34’,**</p>
  558. <p>** ‘resnet50_3343’,**</p>
  559. <p>** ‘resnet50’,**</p>
  560. <p>** ‘resnet101’,**</p>
  561. <p>** ‘resnet152’,**</p>
  562. <p>** ‘resnet18_cifar’,**</p>
  563. <p>** ‘custom_resnet’,**</p>
  564. <p>** ‘custom_resnet50’,**</p>
  565. <p>** ‘custom_resnet_cifar’,**</p>
  566. <p>** ‘custom_resnet50_cifar’,**</p>
  567. <p>** ‘mobilenet_v2’,**</p>
  568. <p>** ‘mobile_net_v2_135’,**</p>
  569. <p>** ‘custom_mobilenet_v2’,**</p>
  570. <p>** ‘mobilenet_v3_large’,**</p>
  571. <p>** ‘mobilenet_v3_small’,**</p>
  572. <p>** ‘mobilenet_v3_custom’,**</p>
  573. <p>** ‘yolo_v3’,**</p>
  574. <p>** ‘tiny_yolo_v3’,**</p>
  575. <p>** ‘custom_densenet’,**</p>
  576. <p>** ‘densenet121’,**</p>
  577. <p>** ‘densenet161’,**</p>
  578. <p>** ‘densenet169’,**</p>
  579. <p>** ‘densenet201’,**</p>
  580. <p>** ‘shelfnet18’,**</p>
  581. <p>** ‘shelfnet34’,**</p>
  582. <p>** ‘shelfnet50_3343’,**</p>
  583. <p>** ‘shelfnet50’,**</p>
  584. <p>** ‘shelfnet101’,**</p>
  585. <p>** ‘shufflenet_v2_x0_5’,**</p>
  586. <p>** ‘shufflenet_v2_x1_0’,**</p>
  587. <p>** ‘shufflenet_v2_x1_5’,**</p>
  588. <p>** ‘shufflenet_v2_x2_0’,**</p>
  589. <p>** ‘shufflenet_v2_custom5’,**</p>
  590. <p>** ‘darknet53’,**</p>
  591. <p>** ‘csp_darknet53’,**</p>
  592. <p>** ‘resnext50’,**</p>
  593. <p>** ‘resnext101’,**</p>
  594. <p>** ‘googlenet_v1’,**</p>
  595. <p>** ‘efficientnet_b0’,**</p>
  596. <p>** ‘efficientnet_b1’,**</p>
  597. <p>** ‘efficientnet_b2’,**</p>
  598. <p>** ‘efficientnet_b3’,**</p>
  599. <p>** ‘efficientnet_b4’,**</p>
  600. <p>** ‘efficientnet_b5’,**</p>
  601. <p>** ‘efficientnet_b6’,**</p>
  602. <p>** ‘efficientnet_b7’,**</p>
  603. <p>** ‘efficientnet_b8’,**</p>
  604. <p>** ‘efficientnet_l2’,**</p>
  605. <p>** ‘CustomizedEfficientnet’,**</p>
  606. <p>** ‘regnetY200’,**</p>
  607. <p>** ‘regnetY400’,**</p>
  608. <p>** ‘regnetY600’,**</p>
  609. <p>** ‘regnetY800’,**</p>
  610. <p>** ‘custom_regnet’,**</p>
  611. <p>** ‘nas_regnet’,**</p>
  612. <p>** ‘yolo_v5s’,**</p>
  613. <p>** ‘yolo_v5m’,**</p>
  614. <p>** ‘yolo_v5l’,**</p>
  615. <p>** ‘yolo_v5x’,**</p>
  616. <p>** ‘custom_yolov5’,**</p>
  617. <p>** ‘ssd_mobilenet_v1’,**</p>
  618. <p>** ‘ssd_lite_mobilenet_v2’,**</p>
  619. <p>** ‘repvgg_a0’,**</p>
  620. <p>** ‘repvgg_a1’,**</p>
  621. <p>** ‘repvgg_a2’,**</p>
  622. <p>** ‘repvgg_b0’,**</p>
  623. <p>** ‘repvgg_b1’,**</p>
  624. <p>** ‘repvgg_b2’,**</p>
  625. <p>** ‘repvgg_b3’,**</p>
  626. <p>** ‘repvgg_d2se’,**</p>
  627. <p>** ‘repvgg_custom’**</p>
  628. </section>
  629. <section id="pretrained-models">
  630. <h1>Pretrained Models<a class="headerlink" href="#pretrained-models" title="Permalink to this headline"></a></h1>
  631. <p>Classification models</p>
  632. <table>
  633. <tr>
  634. <td><strong>Model</strong>
  635. </td>
  636. <td><strong>Dataset</strong>
  637. </td>
  638. <td><strong>arch_params</strong>
  639. </td>
  640. <td><strong>Top-1</strong>
  641. </td>
  642. <td><strong>Latency b1 T4</strong>
  643. </td>
  644. </tr>
  645. <tr>
  646. <td>EfficientNet B0
  647. </td>
  648. <td>ImageNet
  649. </td>
  650. <td>
  651. </td>
  652. <td>77.62
  653. </td>
  654. <td>1.16ms
  655. </td>
  656. </tr>
  657. <tr>
  658. <td>RegNetY200
  659. </td>
  660. <td>ImageNet
  661. </td>
  662. <td>
  663. </td>
  664. <td>70.88
  665. </td>
  666. <td>-
  667. </td>
  668. </tr>
  669. <tr>
  670. <td>RegNetY400
  671. </td>
  672. <td>ImageNet
  673. </td>
  674. <td>
  675. </td>
  676. <td>74.74
  677. </td>
  678. <td>-
  679. </td>
  680. </tr>
  681. <tr>
  682. <td>RegNetY600
  683. </td>
  684. <td>ImageNet
  685. </td>
  686. <td>
  687. </td>
  688. <td>76.18
  689. </td>
  690. <td>-
  691. </td>
  692. </tr>
  693. <tr>
  694. <td>RegNetY800
  695. </td>
  696. <td>ImageNet
  697. </td>
  698. <td>
  699. </td>
  700. <td>77.07
  701. </td>
  702. <td>-
  703. </td>
  704. </tr>
  705. <tr>
  706. <td>ResNet18
  707. </td>
  708. <td>ImageNet
  709. </td>
  710. <td>
  711. </td>
  712. <td>70.6
  713. </td>
  714. <td>0.599ms
  715. </td>
  716. </tr>
  717. <tr>
  718. <td>ResNet34
  719. </td>
  720. <td>ImageNet
  721. </td>
  722. <td>
  723. </td>
  724. <td>74.13
  725. </td>
  726. <td>0.89ms
  727. </td>
  728. </tr>
  729. <tr>
  730. <td>ResNet50
  731. </td>
  732. <td>ImageNet
  733. </td>
  734. <td>{"pretrained_weights": "imagenet", “num_classes”:1000}
  735. </td>
  736. <td>76.3
  737. </td>
  738. <td>0.94ms
  739. </td>
  740. </tr>
  741. <tr>
  742. <td>MobileNetV3_large-150 epochs
  743. </td>
  744. <td>ImageNet
  745. </td>
  746. <td>
  747. </td>
  748. <td>73.79
  749. </td>
  750. <td>0.87ms
  751. </td>
  752. </tr>
  753. <tr>
  754. <td>MobileNetV3_large-300 epochs
  755. </td>
  756. <td>ImageNet
  757. </td>
  758. <td>
  759. </td>
  760. <td>74.52
  761. </td>
  762. <td>0.87ms
  763. </td>
  764. </tr>
  765. <tr>
  766. <td>MobileNetV3_small
  767. </td>
  768. <td>ImageNet
  769. </td>
  770. <td>
  771. </td>
  772. <td>67.45
  773. </td>
  774. <td>0.75ms
  775. </td>
  776. </tr>
  777. <tr>
  778. <td>MobileNetV2_w1
  779. </td>
  780. <td>ImageNet
  781. </td>
  782. <td>
  783. </td>
  784. <td>73.08
  785. </td>
  786. <td>0.58ms
  787. </td>
  788. </tr>
  789. </table>
  790. <p>Object Detection models</p>
  791. <table>
  792. <tr>
  793. <td><strong>Model</strong>
  794. </td>
  795. <td><strong>Dataset</strong>
  796. </td>
  797. <td><strong>arch_params</strong>
  798. </td>
  799. <td><strong>mAPval</strong>
  800. <p>
  801. <strong>0.5:0.95</strong>
  802. </td>
  803. <td><strong>Latency b1T4</strong>
  804. </td>
  805. <td><strong>Throughout b64T4</strong>
  806. </td>
  807. </tr>
  808. <tr>
  809. <td>YOLOv5 small
  810. </td>
  811. <td>CoCo
  812. </td>
  813. <td>640x640
  814. </td>
  815. <td>37.3
  816. </td>
  817. <td>10.09ms
  818. </td>
  819. <td>101.85fps
  820. </td>
  821. </tr>
  822. <tr>
  823. <td>YOLOv5 medium
  824. </td>
  825. <td>CoCo
  826. </td>
  827. <td>640x640
  828. </td>
  829. <td>45.2
  830. </td>
  831. <td>17.55ms
  832. </td>
  833. <td>57.66fps
  834. </td>
  835. </tr>
  836. </table>
  837. <p>Semantic Segmentation models</p>
  838. <table>
  839. <tr>
  840. <td><strong>Model</strong>
  841. </td>
  842. <td><strong>Dataset</strong>
  843. </td>
  844. <td><strong>arch_params</strong>
  845. </td>
  846. <td><strong>mIoU</strong>
  847. </td>
  848. <td><strong>Latency b1T4</strong>
  849. </td>
  850. <td><strong>Throughout b64T4</strong>
  851. </td>
  852. </tr>
  853. <tr>
  854. <td>DDRNet23
  855. </td>
  856. <td>Cityscapes
  857. </td>
  858. <td>
  859. </td>
  860. <td>78.65
  861. </td>
  862. <td>-
  863. </td>
  864. <td>-
  865. </td>
  866. </tr>
  867. <tr>
  868. <td>DDRNet23 slim
  869. </td>
  870. <td>Cityscapes
  871. </td>
  872. <td>
  873. </td>
  874. <td>76.6
  875. </td>
  876. <td>
  877. </td>
  878. <td>
  879. </td>
  880. </tr>
  881. </table>
  882. <p>Example- how to load a pretrained model:</p>
  883. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sg_model</span> <span class="o">=</span> <span class="n">SgModel</span><span class="p">(</span><span class="s2">&quot;resnet50_experiment&quot;</span><span class="p">)</span>
  884. <span class="n">sg_model</span><span class="o">.</span><span class="n">build_model</span><span class="p">(</span><span class="n">architecture</span><span class="o">=</span><span class="s2">&quot;resnet50&quot;</span><span class="p">,</span>
  885. <span class="n">arch_params</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;pretrained_weights&quot;</span><span class="p">:</span> <span class="s2">&quot;imagenet&quot;</span><span class="p">,</span> <span class="s2">&quot;num_classes&quot;</span><span class="p">:</span> <span class="mi">1000</span><span class="p">}</span>
  886. <span class="p">)</span>
  887. </pre></div>
  888. </div>
  889. </section>
  890. <section id="how-to-reproduce-our-training-recipes">
  891. <h1>How To Reproduce Our Training Recipes<a class="headerlink" href="#how-to-reproduce-our-training-recipes" title="Permalink to this headline"></a></h1>
  892. <p>The training recipes for the pretrained models are completely visible for the SuperGradients’ users and can be found under “<em>YOUR_LOCAL_PATH_TO_SUPER_GRADIENTS_PACKAGE”/ examples/{DATASET_NAME}</em>{ARCHITECTURE_NAME}_example. _</p>
  893. <p>_The corresponding YAML configuration files can be found under _“<em>YOUR_LOCAL_PATH_TO_SUPER_GRADIENTS_PACKAGE”/conf/{DATASET_NAME}</em>{ARCHITECTURE_NAME}_conf _</p>
  894. <p>The configuration files include the specific instructions on how to run the training recipes for reproducibility, as well as links to our tensorboards and logs from their training. Additional information regarding training time, metric scores on different configurations can be found in the configuration files as comments as well.</p>
  895. </section>
  896. <section id="supergradients-faq">
  897. <h1>SuperGradients FAQ<a class="headerlink" href="#supergradients-faq" title="Permalink to this headline"></a></h1>
  898. <section id="what-type-of-tasks-does-the-supergradients-support">
  899. <h2>What Type of Tasks Does the SuperGradients Support?<a class="headerlink" href="#what-type-of-tasks-does-the-supergradients-support" title="Permalink to this headline"></a></h2>
  900. <ul class="simple">
  901. <li><p>Classification</p></li>
  902. <li><p>Object Detection</p></li>
  903. <li><p>Segmentation</p></li>
  904. </ul>
  905. </section>
  906. </section>
  907. </div>
  908. </div>
  909. <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
  910. <a href="super_gradients.training.html" class="btn btn-neutral float-left" title="Training package" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
  911. </div>
  912. <hr/>
  913. <div role="contentinfo">
  914. <p>&#169; Copyright 2021, SuperGradients team.</p>
  915. </div>
  916. Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
  917. <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
  918. provided by <a href="https://readthedocs.org">Read the Docs</a>.
  919. </footer>
  920. </div>
  921. </div>
  922. </section>
  923. </div>
  924. <script>
  925. jQuery(function () {
  926. SphinxRtdTheme.Navigation.enable(true);
  927. });
  928. </script>
  929. </body>
  930. </html>
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...