-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain.html
More file actions
1022 lines (921 loc) · 56.4 KB
/
train.html
File metadata and controls
1022 lines (921 loc) · 56.4 KB
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
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Training — OpenPifPaf Guide</title>
<!-- Loaded before other Sphinx assets -->
<link href="_static/styles/theme.css?digest=1999514e3f237ded88cf" rel="stylesheet">
<link href="_static/styles/pydata-sphinx-theme.css?digest=1999514e3f237ded88cf" rel="stylesheet">
<link rel="stylesheet"
href="_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" href="_static/styles/sphinx-book-theme.css?digest=5115cc725059bd94278eecd172e13a965bf8f5a9" type="text/css" />
<link rel="stylesheet" type="text/css" href="_static/togglebutton.css" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="_static/mystnb.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-thebe.css" />
<link rel="stylesheet" type="text/css" href="_static/mystyle.css" />
<link rel="stylesheet" type="text/css" href="_static/design-style.b7bb847fb20b106c3d81b95245e65545.min.css" />
<!-- Pre-loaded scripts that we'll load fully later -->
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=1999514e3f237ded88cf">
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/clipboard.min.js"></script>
<script src="_static/copybutton.js"></script>
<script src="_static/scripts/sphinx-book-theme.js?digest=9c920249402e914e316237a7dbc6769907cce411"></script>
<script>let toggleHintShow = 'Click to show';</script>
<script>let toggleHintHide = 'Click to hide';</script>
<script>let toggleOpenOnPrint = 'true';</script>
<script src="_static/togglebutton.js"></script>
<script>var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
<script src="_static/design-tabs.js"></script>
<script>const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js"
const thebe_selector = ".thebe,.cell"
const thebe_selector_input = "pre"
const thebe_selector_output = ".output, .cell_output"
</script>
<script async="async" src="_static/sphinx-thebe.js"></script>
<script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="shortcut icon" href="_static/favicon.png"/>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Command Line" href="cli_help.html" />
<link rel="prev" title="Datasets" href="datasets.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en">
<!-- Google Analytics -->
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="60">
<!-- Checkboxes to toggle the left sidebar -->
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation" aria-label="Toggle navigation sidebar">
<label class="overlay overlay-navbar" for="__navigation">
<div class="visually-hidden">Toggle navigation sidebar</div>
</label>
<!-- Checkboxes to toggle the in-page toc -->
<input type="checkbox" class="sidebar-toggle" name="__page-toc" id="__page-toc" aria-label="Toggle in-page Table of Contents">
<label class="overlay overlay-pagetoc" for="__page-toc">
<div class="visually-hidden">Toggle in-page Table of Contents</div>
</label>
<!-- Headers at the top -->
<div class="announcement header-item noprint"></div>
<div class="header header-item noprint"></div>
<div class="container-fluid" id="banner"></div>
<div class="container-xl">
<div class="row">
<!-- Sidebar -->
<div class="bd-sidebar noprint" id="site-navigation">
<div class="bd-sidebar__content">
<div class="bd-sidebar__top"><div class="navbar-brand-box">
<a class="navbar-brand text-wrap" href="index.html">
<!-- `logo` is deprecated in Sphinx 4.0, so remove this when we stop supporting 3 -->
<img src="_static/logo.png" class="logo" alt="logo">
<h1 class="site-logo" id="site-title">OpenPifPaf Guide</h1>
</a>
</div><form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main">
<div class="bd-toc-item active">
<ul class="nav bd-sidenav bd-sidenav__home-link">
<li class="toctree-l1">
<a class="reference internal" href="intro.html">
Introduction
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Getting Started
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="predict_cli.html">
Prediction
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="examples.html">
Examples
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Chapters
</span>
</p>
<ul class="current nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="predict_api.html">
Prediction API
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="compute.html">
Compute
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="models.html">
Models
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="datasets.html">
Datasets
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
Training
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="cli_help.html">
Command Line
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="plugins_overview.html">
Plugins
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="faq.html">
FAQ
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Tutorials
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="plugins_custom.html">
Custom Dataset
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="plugins_animalpose.html">
Animal Keypoints
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="plugins_wholebody.html">
WholeBody
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="plugins_apollocar3d.html">
Car Keypoints
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="plugins_crowdpose.html">
CrowdPose
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="plugins_nuscenes.html">
NuScenes 2D detection
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="tutorial_opencv.html">
OpenCV
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="plugins_cifar10.html">
Cifar10
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="plugins_extras.html">
Extras
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Reference
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="moduledocs.html">
Modules
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="bibliography.html">
Bibliography
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Development
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="dev.html">
Contribute
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="performance.html">
Performance
</a>
</li>
<li class="toctree-l1">
<a class="reference external" href="https://github.com/openpifpaf/openpifpaf">
GitHub
</a>
</li>
</ul>
</div>
</nav></div>
<div class="bd-sidebar__bottom">
<!-- To handle the deprecated key -->
</div>
</div>
<div id="rtd-footer-container"></div>
</div>
<!-- A tiny helper pixel to detect if we've scrolled -->
<div class="sbt-scroll-pixel-helper"></div>
<!-- Main content -->
<div class="col py-0 content-container">
<div class="header-article row sticky-top noprint">
<div class="col py-1 d-flex header-article-main">
<div class="header-article__left">
<label for="__navigation"
class="headerbtn"
data-toggle="tooltip"
data-placement="right"
title="Toggle navigation"
>
<span class="headerbtn__icon-container">
<i class="fas fa-bars"></i>
</span>
</label>
</div>
<div class="header-article__right">
<div class="menu-dropdown menu-dropdown-launch-buttons">
<button class="headerbtn menu-dropdown__trigger"
aria-label="Launch interactive content">
<i class="fas fa-rocket"></i>
</button>
<div class="menu-dropdown__content">
<ul>
<li>
<a href="https://mybinder.org/v2/gh/openpifpaf/openpifpaf/stable?urlpath=tree/guide/train.ipynb"
class="headerbtn"
data-toggle="tooltip"
data-placement="left"
title="Launch on Binder"
>
<span class="headerbtn__icon-container">
<img src="_static/images/logo_binder.svg">
</span>
<span class="headerbtn__text-container">Binder</span>
</a>
</li>
</ul>
</div>
</div>
<div class="menu-dropdown menu-dropdown-repository-buttons">
<button class="headerbtn menu-dropdown__trigger"
aria-label="Source repositories">
<i class="fab fa-github"></i>
</button>
<div class="menu-dropdown__content">
<ul>
<li>
<a href="https://github.com/openpifpaf/openpifpaf"
class="headerbtn"
data-toggle="tooltip"
data-placement="left"
title="Source repository"
>
<span class="headerbtn__icon-container">
<i class="fab fa-github"></i>
</span>
<span class="headerbtn__text-container">repository</span>
</a>
</li>
<li>
<a href="https://github.com/openpifpaf/openpifpaf/issues/new?title=Issue%20on%20page%20%2Ftrain.html&body=Your%20issue%20content%20here."
class="headerbtn"
data-toggle="tooltip"
data-placement="left"
title="Open an issue"
>
<span class="headerbtn__icon-container">
<i class="fas fa-lightbulb"></i>
</span>
<span class="headerbtn__text-container">open issue</span>
</a>
</li>
<li>
<a href="https://github.com/openpifpaf/openpifpaf/edit/stable/guide/train.ipynb"
class="headerbtn"
data-toggle="tooltip"
data-placement="left"
title="Edit this page"
>
<span class="headerbtn__icon-container">
<i class="fas fa-pencil-alt"></i>
</span>
<span class="headerbtn__text-container">suggest edit</span>
</a>
</li>
</ul>
</div>
</div>
<div class="menu-dropdown menu-dropdown-download-buttons">
<button class="headerbtn menu-dropdown__trigger"
aria-label="Download this page">
<i class="fas fa-download"></i>
</button>
<div class="menu-dropdown__content">
<ul>
<li>
<a href="_sources/train.ipynb"
class="headerbtn"
data-toggle="tooltip"
data-placement="left"
title="Download source file"
>
<span class="headerbtn__icon-container">
<i class="fas fa-file"></i>
</span>
<span class="headerbtn__text-container">.ipynb</span>
</a>
</li>
<li>
<button onclick="printPdf(this)"
class="headerbtn"
data-toggle="tooltip"
data-placement="left"
title="Print to PDF"
>
<span class="headerbtn__icon-container">
<i class="fas fa-file-pdf"></i>
</span>
<span class="headerbtn__text-container">.pdf</span>
</button>
</li>
</ul>
</div>
</div>
<label for="__page-toc"
class="headerbtn headerbtn-page-toc"
>
<span class="headerbtn__icon-container">
<i class="fas fa-list"></i>
</span>
</label>
</div>
</div>
<!-- Table of contents -->
<div class="col-md-3 bd-toc show noprint">
<div class="tocsection onthispage pt-5 pb-3">
<i class="fas fa-list"></i> On this page
</div>
<nav id="bd-toc-nav" aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#composite-loss-function">
Composite Loss Function
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#training-crop-size">
Training Crop Size
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#reproducibility">
Reproducibility
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#multiple-datasets">
Multiple Datasets
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#overfitting">
Overfitting
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#shufflenet">
ShuffleNet
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#resnet">
ResNet
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#debug-plots">
Debug Plots
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#logs">
Logs
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#testset-submission">
Testset Submission
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#detection-experimental">
Detection (experimental)
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#cloud-and-hpc">
Cloud and HPC
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#distributeddataparallel">
DistributedDataParallel
</a>
</li>
</ul>
</nav>
</div>
</div>
<div class="article row">
<div class="col pl-md-3 pl-lg-5 content-container">
<!-- Table of contents that is only displayed when printing the page -->
<div id="jb-print-docs-body" class="onlyprint">
<h1>Training</h1>
<!-- Table of contents -->
<div id="print-main-content">
<div id="jb-print-toc">
<div>
<h2> On this page </h2>
</div>
<nav aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#composite-loss-function">
Composite Loss Function
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#training-crop-size">
Training Crop Size
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#reproducibility">
Reproducibility
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#multiple-datasets">
Multiple Datasets
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#overfitting">
Overfitting
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#shufflenet">
ShuffleNet
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#resnet">
ResNet
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#debug-plots">
Debug Plots
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#logs">
Logs
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#testset-submission">
Testset Submission
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#detection-experimental">
Detection (experimental)
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#cloud-and-hpc">
Cloud and HPC
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#distributeddataparallel">
DistributedDataParallel
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<main id="main-content" role="main">
<div>
<section class="tex2jax_ignore mathjax_ignore" id="training">
<h1>Training<a class="headerlink" href="#training" title="Permalink to this headline">#</a></h1>
<p>This section introduces training to create your own models. You don’t need to do this step
if you use pre-trained models for <a class="reference internal" href="predict_cli.html"><span class="doc">Prediction</span></a> on your own images.
For training, you will need a dataset. See <a class="reference internal" href="datasets.html"><span class="doc">Datasets</span></a> for instructions about a few popular datasets.</p>
<p>Training a model can take several days even with a good GPU. Many times existing models can be refined to avoid training from scratch.</p>
<p>The main interface for training with OpenPifPaf is the command line tool <a class="reference internal" href="cli_help.html#cli-help-train"><span class="std std-ref">openpifpaf.train</span></a>.
A quick way to get started is with the training commands of the pre-trained models.
The exact training command that was used for a model is in the first
line of the training log file. Below are a few examples for various backbones.</p>
<section id="composite-loss-function">
<h2>Composite Loss Function<a class="headerlink" href="#composite-loss-function" title="Permalink to this headline">#</a></h2>
<p>OpenPifPaf uses an off-the-shelf backbone like a ResNet and then adds the smallest
possible (approx) head networks on top: a single 1x1 convolution.
The outputs of the head networks are the composite fields. At each location,
the composite head produces a confidence together with some location and attribute
information.</p>
<p>In our first paper <span id="id1">[<a class="reference internal" href="bibliography.html#id2" title="Sven Kreiss, Lorenzo Bertoni, and Alexandre Alahi. PifPaf: Composite Fields for Human Pose Estimation. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR). June 2019.">KBA19</a>]</span>, we show how to learn these composite
fields with a binary cross entropy for the confidence, a Laplace loss for regression
and a plain L1 regression loss for scale. The Laplace loss has been valuable
for OpenPifPaf as it proved to be better than any other of the regression losses
for us. One interpretation is from its original motivation as a better objective
for a probabilistic problem of location prediction:</p>
<div class="math notranslate nohighlight">
\[
L_\textrm{Laplace} = \frac{1}{\hat{b}}|\hat{x} - x|^1_2 + \log \hat{b}
\]</div>
<p>That is the main motivation
why I used this loss and defended its continued use. Over time, I also came to
appreciate an empirical interpretation: an adversarial trade-off between
the two terms in the sum that evolves as the network learns. During the initial
phase of training, predictions <span class="math notranslate nohighlight">\(\hat{x}\)</span> are poor and the network better predicts
large <span class="math notranslate nohighlight">\(\hat{b}\)</span> to reduce the first term at the cost of a logarithmic penalty
from the second term. As the network learns to predict better, it starts to predict
smaller values of <span class="math notranslate nohighlight">\(\hat{b}\)</span> to reduce the logarithmic penalty while not incuring
too large costs anymore because its predictions for <span class="math notranslate nohighlight">\(\hat{x}\)</span> are good.
This mechanism also has consequences as the network continues to train and starts
overfitting. Other regression losses just overfit gently more and more. The
Laplace loss, however, will really try to profit from its overfitted knowledge
and become very agressive and reduce <span class="math notranslate nohighlight">\(\hat{b}\)</span>. As explained in our paper,
we add an extra constant <span class="math notranslate nohighlight">\(b_\textrm{min}\)</span> that prevents aggressive regression
losses below fractions of pixels.</p>
<p><strong>Aside on negative losses</strong>: A loss function is something that is minimized.
A valid loss is, for example, the L1 loss <span class="math notranslate nohighlight">\(|\hat{x} - x|\)</span> but equally valid is
the loss <span class="math notranslate nohighlight">\(|\hat{x} - x| - 5000\)</span>. These losses would lead to the exact same
trained networks as they produce exactly the same gradients. Most loss functions
are not negative because their final operation is a square or an absolute value
as in the case
of L1 or L2 loss but it is not a generic property of loss functions. The Laplace
loss above can become negative infinity when <span class="math notranslate nohighlight">\(\hat{b} \to 0\)</span> and is still a
valid objective to minimize.</p>
<p><strong>New in v0.13</strong>: To produce truely composite objects, I would like the
adversarial trade-off to be shared across confidence and regression: the
predicted <span class="math notranslate nohighlight">\(\hat{b}\)</span> should only become smaller as both confidence and regression
become better. We don’t have to learn a fantastic regression when the confidence
predictions are poor. We saw signs of the problem when we started to train
composite fields for detection: confidence predictions were almost random
while regressions started to manifest. The solution is to implement the
adversarial mechanism discussed above for the Laplace regression to both
confidence and regression tasks and to share the predicted <span class="math notranslate nohighlight">\(\hat{b}\)</span>.</p>
<p>While the exact form of the Laplace loss came from a probabilistic interpretation
that lead naturally to the adversarial mechanism, this step is not as obvious
for confidence predictions and there are multiple options (including one
suggested in the paper by Kendall et al on the Laplace loss). Here, I chose to
to map the Focal loss to a Gaussian loss by gradient matching and then applying
the probabilistic interpretation in that mapped space leading to the adversarial
terms. The gradient of the Focal loss FL w.r.t. <span class="math notranslate nohighlight">\(\hat{x}\)</span> for positive samples
<span class="math notranslate nohighlight">\(x=1\)</span>:</p>
<div class="math notranslate nohighlight">
\[\begin{split}
\frac{\partial}{\partial \hat{x}}\textrm{FL}(\hat{x}, x=1)
&= - \frac{\partial}{\partial \hat{x}} (1 - p(\hat{x}))^\gamma \ln p(\hat{x}) \\
&= - \overline{p}(\hat{x}) \left[
\overline{p}(\hat{x})^\gamma - \gamma \overline{p}(\hat{x})^{\gamma - 1} p(\hat{x}) \ln p(\hat{x})
\right]
\end{split}\]</div>
<p>where the part in square brackets is due to the Focal loss modification of BCE.
I have used the standard <span class="math notranslate nohighlight">\(p(\hat{x}) \equiv 1 / (1+e^{-\hat{x}})\)</span> and
<span class="math notranslate nohighlight">\(\overline{p}(\hat{x}) \equiv 1 / (1+e^{\hat{x}})\)</span>
which gives the helpful identities <span class="math notranslate nohighlight">\(1-p(\hat{x}) = \overline{p}(\hat{x})\)</span> and
<span class="math notranslate nohighlight">\(\partial \ln p(\hat{x}) / \partial \hat{x} = \overline{p}(\hat{x})\)</span>.
The second step is to match this gradient to the gradient of an L2 loss. This
matching provides the fictituous target point <span class="math notranslate nohighlight">\(t_2\)</span> for the L2 regression:</p>
<div class="math notranslate nohighlight">
\[
t_2 = \hat{x} + \overline{p}(\hat{x}) \left[
\overline{p}(\hat{x})^\gamma - \gamma \overline{p}(\hat{x})^{\gamma - 1} p(\hat{x}) \ln p(\hat{x})
\right]
\]</div>
<p>This target point depends on the prediction <span class="math notranslate nohighlight">\(\hat{x}\)</span> but it is still a target as
far as the L2 loss is concerned, i.e. the gradients on <span class="math notranslate nohighlight">\(\hat{x}\)</span> are detached and,
therefore, there are no gradients back-propagating through <span class="math notranslate nohighlight">\(t_2\)</span>.</p>
<p>Finally, as we have cast classification to an exactly matched regression
problem, we are in a position to apply Gaussian uncertainties on this
L2 regression loss. There is, of course, no good interpretation for what
this uncertainty represents in the space before the mapping.
We use a single predicted <span class="math notranslate nohighlight">\(\hat{b}\)</span> for both the confidence and regression
uncertainties and in that way achieved our goal: only when we have both
good confidence and good regression predictions will our network reduce its
predictions of <span class="math notranslate nohighlight">\(\hat{b}\)</span>.</p>
</section>
<section id="training-crop-size">
<h2>Training Crop Size<a class="headerlink" href="#training-crop-size" title="Permalink to this headline">#</a></h2>
<p>Training and evaluation image sizes are <em>unrelated</em> in fully convolutional architectures like OpenPifPaf. <em>Instance size distribution</em> between training and evaluation needs to be preserved. The size of the image that surrounds the instance to detect has little impact: for humans of height 100px, it does not matter whether that is inside a <span class="math notranslate nohighlight">\(640\times480\)</span> image or inside a 4k or 8k image. Therefore, you can keep the size of your training crops (selected with <code class="docutils literal notranslate"><span class="pre">--square-edge</span></code>) quite small even when evaluating on large images. The default is <code class="docutils literal notranslate"><span class="pre">--square-edge=385</span></code> for <code class="docutils literal notranslate"><span class="pre">cocokp</span></code> and that is reasonable when most of the humans are not larger than 300px during evaluation.
<img alt="training crop size" src="_images/trainingcrop.png" /></p>
<p>The training crop size is a major factor for GPU memory consumption and for training time.</p>
</section>
<section id="reproducibility">
<h2>Reproducibility<a class="headerlink" href="#reproducibility" title="Permalink to this headline">#</a></h2>
<p>Every training log file contains the command that was used to train under the key <code class="docutils literal notranslate"><span class="pre">args</span></code>. There is also a <code class="docutils literal notranslate"><span class="pre">version</span></code> key that specifies the precise version of OpenPifPaf that was used to train, like “0.11.9+204.g987345” (generated by <a class="reference external" href="https://github.com/python-versioneer/python-versioneer">versioneer</a>). This means that the last tag was 0.11.9, that there are 204 additional commits beyond that tag, and that the hash of the current commit is “987345” (without the “g” as that simply stands for <code class="docutils literal notranslate"><span class="pre">git</span></code>). If you had uncommitted changes, there is an additional “dirty” suffix. Try to avoid “dirty” version numbers for training as it is impossible to tell whether you were just correcting a typo in the readme or had a substantial change that influences the training. Your local git command line client but also GitHub can compare to the short git hashes.</p>
</section>
<section id="multiple-datasets">
<h2>Multiple Datasets<a class="headerlink" href="#multiple-datasets" title="Permalink to this headline">#</a></h2>
<p>OpenPifPaf supports simultaneous training on multiple datasets. You specify multiple datasets by concatenating them with a <code class="docutils literal notranslate"><span class="pre">-</span></code>, e.g. to train on COCO Keypoints <code class="docutils literal notranslate"><span class="pre">cocokp</span></code> and on COCO Detections <code class="docutils literal notranslate"><span class="pre">cocodet</span></code> you specify in your training command <code class="docutils literal notranslate"><span class="pre">--dataset=cocokp-cocodet</span></code>. This also works for custom datasets defined in plugins.</p>
<p>The samples from each dataset are tracked with weighted counters and the dataset for the next batch is chosen by the lowest counter. You specify the dataset weights (or you can think of it as an importance), for example, as <code class="docutils literal notranslate"><span class="pre">--dataset-weights</span> <span class="pre">1.0</span> <span class="pre">0.5</span></code>. That means that the first dataset (<code class="docutils literal notranslate"><span class="pre">cocokp</span></code> in the above example) is twice as important as the second one (e.g. <code class="docutils literal notranslate"><span class="pre">cocodet</span></code>) and two-thirds of the batches will be from the first dataset and one-third will be from the second.</p>
<p>An epoch is over once the first of the datasets is out of samples. As the datasets are randomized during training, a different set of samples will be used from epoch to epoch. That means that eventually all data will be utilized of the larger datasets even if not all data is used during a single epoch.</p>
</section>
<section id="overfitting">
<h2>Overfitting<a class="headerlink" href="#overfitting" title="Permalink to this headline">#</a></h2>
<p>An effective way to validate the pipeline is working, loss functions are implemented correctly, encoders are correct, etc. is to overfit on a single image. You should be able to produce perfect predictions for that image. Some caveats: you need to deactivate augmentations, you must evaluate at the exact trained image size and the image should not contain crowd annotations (i.e. areas that will be ignored during training). Here is an example training command for a <code class="docutils literal notranslate"><span class="pre">cocokp</span></code> overfitting experiment:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nb">time</span><span class="w"> </span><span class="nv">CUDA_VISIBLE_DEVICES</span><span class="o">=</span><span class="m">1</span><span class="w"> </span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.train<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--lr<span class="o">=</span><span class="m">0</span>.01<span class="w"> </span>--momentum<span class="o">=</span><span class="m">0</span>.9<span class="w"> </span>--b-scale<span class="o">=</span><span class="m">5</span>.0<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--epochs<span class="o">=</span><span class="m">1000</span><span class="w"> </span>--lr-warm-up-epochs<span class="o">=</span><span class="m">100</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--batch-size<span class="o">=</span><span class="m">4</span><span class="w"> </span>--train-batches<span class="o">=</span><span class="m">1</span><span class="w"> </span>--val-batches<span class="o">=</span><span class="m">1</span><span class="w"> </span>--val-interval<span class="o">=</span><span class="m">100</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--weight-decay<span class="o">=</span>1e-5<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--dataset<span class="o">=</span>cocokp<span class="w"> </span>--cocokp-upsample<span class="o">=</span><span class="m">2</span><span class="w"> </span>--cocokp-no-augmentation<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--basenet<span class="o">=</span>shufflenetv2k16
</pre></div>
</div>
<p>The very first image in the training set has a large crowd annotation. Therefore, the above command overfits on four images.
Here is the corresponding predict command for the <a class="reference external" href="https://www.flickr.com/photos/infiniteworld/5341741494/">second image</a> in the training set:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.predict<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--checkpoint<span class="w"> </span>outputs/shufflenetv2k16-201007-153356-cocokp-1de9503b.pkl<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--debug-indices<span class="w"> </span>cif:5<span class="w"> </span>caf:5<span class="w"> </span>--debug-images<span class="w"> </span>--long-edge<span class="o">=</span><span class="m">385</span><span class="w"> </span>--loader-workers<span class="o">=</span><span class="m">0</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--save-all<span class="w"> </span>--image-output<span class="w"> </span>all-images/overfitted.jpeg<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>data-mscoco/images/train2017/000000262146.jpg
</pre></div>
</div>
<p>While the field predictions are almost perfect, it will predict two annotations while there is only one ground truth annotation. That is because the standard skeleton has no connection that goes directly from left-ear to nose and the left-eye is not visible and not annotated. You can add <code class="docutils literal notranslate"><span class="pre">--dense-connections</span></code> to include additional connections in the skeleton which will connect the nose keypoint to the rest of the skeleton.</p>
</section>
<section id="shufflenet">
<h2>ShuffleNet<a class="headerlink" href="#shufflenet" title="Permalink to this headline">#</a></h2>
<p>ShuffleNet models are trained without ImageNet pretraining:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nb">time</span><span class="w"> </span><span class="nv">CUDA_VISIBLE_DEVICES</span><span class="o">=</span><span class="m">0</span>,1<span class="w"> </span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.train<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--lr<span class="o">=</span><span class="m">0</span>.0003<span class="w"> </span>--momentum<span class="o">=</span><span class="m">0</span>.95<span class="w"> </span>--b-scale<span class="o">=</span><span class="m">10</span>.0<span class="w"> </span>--clip-grad-value<span class="o">=</span><span class="m">10</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--epochs<span class="o">=</span><span class="m">250</span><span class="w"> </span>--lr-decay<span class="w"> </span><span class="m">220</span><span class="w"> </span><span class="m">240</span><span class="w"> </span>--lr-decay-epochs<span class="o">=</span><span class="m">10</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--batch-size<span class="o">=</span><span class="m">32</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--weight-decay<span class="o">=</span>1e-5<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--dataset<span class="o">=</span>cocokp<span class="w"> </span>--cocokp-upsample<span class="o">=</span><span class="m">2</span><span class="w"> </span>--cocokp-extended-scale<span class="w"> </span>--cocokp-orientation-invariant<span class="o">=</span><span class="m">0</span>.1<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--basenet<span class="o">=</span>shufflenetv2k16
</pre></div>
</div>
<p>You can refine an existing model with the <code class="docutils literal notranslate"><span class="pre">--checkpoint</span></code> option.
We found that for stable training, the learning rate <span class="math notranslate nohighlight">\(\lambda\)</span>,
the <code class="docutils literal notranslate"><span class="pre">clip-grad-value</span></code> <span class="math notranslate nohighlight">\(c\)</span> and the <span class="math notranslate nohighlight">\(\epsilon\)</span> from the denominator of the
BatchNorm should obey:</p>
<div class="amsmath math notranslate nohighlight" id="equation-68ae636c-df2c-4e8c-8f24-072886204d99">
<span class="eqno">(1)<a class="headerlink" href="#equation-68ae636c-df2c-4e8c-8f24-072886204d99" title="Permalink to this equation">#</a></span>\[\begin{align}
\lambda \cdot c &\leq \sqrt{\epsilon}
\end{align}\]</div>
<p>where the default <span class="math notranslate nohighlight">\(\epsilon\)</span> is <span class="math notranslate nohighlight">\(10^{-4}\)</span> (different from the PyTorch default).
To fit large models in your GPU memory, reduce the batch size and learning rate by the same factor.</p>
</section>
<section id="resnet">
<h2>ResNet<a class="headerlink" href="#resnet" title="Permalink to this headline">#</a></h2>
<p>ResNet models are initialized with weights pre-trained on ImageNet.
That makes their training characteristics different from ShuffleNet (i.e. they look great at the beginning of training).</p>
</section>
<section id="debug-plots">
<h2>Debug Plots<a class="headerlink" href="#debug-plots" title="Permalink to this headline">#</a></h2>
<p>As for all commands, you need to decide whether you want to interactively show the plots in matplotlib with <code class="docutils literal notranslate"><span class="pre">--show</span></code> (I use <a class="reference external" href="https://github.com/daleroberts/itermplot">itermplot</a>) or to save image files with <code class="docutils literal notranslate"><span class="pre">--save-all</span></code> (defaults to the <code class="docutils literal notranslate"><span class="pre">all-images/</span></code> directory).</p>
<p>You can inspect the ground truth fields that are used for training. Add <code class="docutils literal notranslate"><span class="pre">--debug-images</span></code> to activate all types of debug plots and, for example, select to visualize field 5 of CIF and field 5 of CAF with <code class="docutils literal notranslate"><span class="pre">--debug-indices</span> <span class="pre">cif:5</span> <span class="pre">caf:5</span></code>.</p>
<p>You can run this on your laptop without a GPU. When debug is enabled, the training dataset is not randomized and therefore you only need the first few images in your dataset locally.</p>
</section>
<section id="logs">
<h2>Logs<a class="headerlink" href="#logs" title="Permalink to this headline">#</a></h2>
<p>For reference, check out the log files of the pretrained models. Models with their log files are shared as release “Assets” in the separate <a class="reference external" href="https://github.com/openpifpaf/torchhub">openpifpaf/torchhub</a> repository: click on “releases” and expand “Assets” on the latest release.</p>
<p>To visualize log files with <a class="reference internal" href="cli_help.html#cli-help-logs"><span class="std std-ref">openpifpaf.logs</span></a>:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.logs<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>outputs/resnet50block5-pif-paf-edge401-190424-122009.pkl.log<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>outputs/resnet101block5-pif-paf-edge401-190412-151013.pkl.log<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>outputs/resnet152block5-pif-paf-edge401-190412-121848.pkl.log
</pre></div>
</div>
<p>Evaluation metrics like average precision (AP) are created with the <a class="reference internal" href="cli_help.html#cli-help-eval"><span class="std std-ref">openpifpaf.eval</span></a> tool.
To produce evaluation metrics every five epochs for every new checkpoint that is created:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nv">CUDA_VISIBLE_DEVICES</span><span class="o">=</span><span class="m">0</span><span class="w"> </span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.eval<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--watch<span class="w"> </span>--checkpoint<span class="w"> </span><span class="s2">"outputs/shufflenetv2k??-*-cocokp*.pkl.epoch??[0,5]"</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--loader-workers<span class="o">=</span><span class="m">2</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--decoder<span class="o">=</span>cifcaf:0<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--dataset<span class="o">=</span>cocokp<span class="w"> </span>--force-complete-pose<span class="w"> </span>--seed-threshold<span class="o">=</span><span class="m">0</span>.2
</pre></div>
</div>
</section>
<section id="testset-submission">
<h2>Testset Submission<a class="headerlink" href="#testset-submission" title="Permalink to this headline">#</a></h2>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nv">CUDA_VISIBLE_DEVICES</span><span class="o">=</span><span class="m">0</span><span class="w"> </span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.eval<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--checkpoint<span class="w"> </span>shufflenetv2k30<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--loader-workers<span class="o">=</span><span class="m">2</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--decoder<span class="o">=</span>cifcaf:0<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--dataset<span class="o">=</span>cocokp<span class="w"> </span>--force-complete-pose<span class="w"> </span>--seed-threshold<span class="o">=</span><span class="m">0</span>.2<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--cocokp-eval-testdev2017<span class="w"> </span>--coco-no-eval-annotation-filter<span class="w"> </span>--write-predictions
</pre></div>
</div>
<p>This will produce the file <code class="docutils literal notranslate"><span class="pre">shufflenetv2k30.eval-cocokp.zip</span></code> which you can submit to the competition on codalab.</p>
</section>
<section id="detection-experimental">
<h2>Detection (experimental)<a class="headerlink" href="#detection-experimental" title="Permalink to this headline">#</a></h2>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nb">time</span><span class="w"> </span><span class="nv">CUDA_VISIBLE_DEVICES</span><span class="o">=</span><span class="m">0</span>,1<span class="w"> </span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.train<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--lr<span class="o">=</span><span class="m">0</span>.0003<span class="w"> </span>--momentum<span class="o">=</span><span class="m">0</span>.95<span class="w"> </span>--clip-grad-value<span class="o">=</span><span class="m">10</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--epochs<span class="o">=</span><span class="m">150</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--lr-decay<span class="w"> </span><span class="m">130</span><span class="w"> </span><span class="m">140</span><span class="w"> </span>--lr-decay-epochs<span class="o">=</span><span class="m">10</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--batch-size<span class="o">=</span><span class="m">64</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--weight-decay<span class="o">=</span>1e-5<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--dataset<span class="o">=</span>cocodet<span class="w"> </span>--cocodet-upsample<span class="o">=</span><span class="m">2</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--basenet<span class="o">=</span>resnet18<span class="w"> </span>--resnet-input-conv2-stride<span class="o">=</span><span class="m">2</span><span class="w"> </span>--resnet-block5-dilation<span class="o">=</span><span class="m">2</span>
</pre></div>
</div>
<p>with eval code:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nv">CUDA_VISIBLE_DEVICES</span><span class="o">=</span><span class="m">0</span><span class="w"> </span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.eval<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--watch<span class="w"> </span>--checkpoint<span class="w"> </span><span class="s2">"outputs/resnet??-*-cocodet*.pkl.epoch??[0,5]"</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--loader-workers<span class="o">=</span><span class="m">2</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--dataset<span class="o">=</span>cocodet<span class="w"> </span>--decoder<span class="o">=</span>cifdet:0<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--seed-threshold<span class="o">=</span><span class="m">0</span>.1<span class="w"> </span>--instance-threshold<span class="o">=</span><span class="m">0</span>.1
</pre></div>
</div>
<p>COCO AP=24.3% at epoch 90 (now outdated).</p>
</section>
<section id="cloud-and-hpc">
<h2>Cloud and HPC<a class="headerlink" href="#cloud-and-hpc" title="Permalink to this headline">#</a></h2>
<p>OpenPifPaf can be trained on cloud infrastructure and in high performance computing (HPC) environments. We have good experience with the <a class="reference external" href="https://hub.docker.com/r/pytorch/pytorch/tags">pytorch/pytorch docker containers</a>. The <code class="docutils literal notranslate"><span class="pre">latest</span></code> tag does not include any development packages like <code class="docutils literal notranslate"><span class="pre">gcc</span></code>. For that, you need a “devel” package (e.g. <a class="reference external" href="https://hub.docker.com/layers/pytorch/pytorch/1.6.0-cuda10.1-cudnn7-devel/images/sha256-ccebb46f954b1d32a4700aaeae0e24bd68653f92c6f276a608bf592b660b63d7?context=explore">pytorch/1.6.0-cuda10.1-cudnn7-devel</a>).</p>
<p>This is a development flow that worked well for us:</p>
<ul class="simple">
<li><p>start with an empty directory</p></li>
<li><p>launch the “devel” container and bind/link your current empty directory</p></li>
<li><p>create a Python virtualenv and install all software from within the devel container into the virtualenv</p></li>
<li><p>never modify this virtualenv from the host, always from within the devel container</p></li>
</ul>
<p>After setting up your environment, you can execute the training. You can even use the container without the “devel” tools to submit the job.</p>
<p><strong>HPC job submission</strong>: Our environment supports <a class="reference external" href="https://slurm.schedmd.com/quickstart.html">Slurm</a> and <a class="reference external" href="https://sylabs.io/guides/3.6/user-guide/">Singularity</a>. Run</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>sbatch<span class="w"> </span>./train.sh<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--lr<span class="o">=</span><span class="m">0</span>.0003<span class="w"> </span><span class="c1"># and all the other parameters for training from above</span>
</pre></div>
</div>
<p>with <code class="docutils literal notranslate"><span class="pre">train.sh</span></code> containing:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/bin/bash -l</span>
<span class="c1">#SBATCH --nodes 1</span>
<span class="c1">#SBATCH --ntasks 1</span>
<span class="c1">#SBATCH --cpus-per-task 40</span>
<span class="c1">#SBATCH --mem 96G</span>
<span class="c1">#SBATCH --time 72:00:00</span>
<span class="c1">#SBATCH --account=<your-account-name></span>
<span class="c1">#SBATCH --gres gpu:2</span>
srun<span class="w"> </span>singularity<span class="w"> </span><span class="nb">exec</span><span class="w"> </span>--bind<span class="w"> </span><make-host-dir-available><span class="w"> </span>--nv<span class="w"> </span>pytorch_latest.sif<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>/bin/bash<span class="w"> </span>-c<span class="w"> </span><span class="s2">"source ./venv3/bin/activate && python3 -u -m openpifpaf.train </span><span class="k">$(</span><span class="nb">printf</span><span class="w"> </span><span class="s1">'%q '</span><span class="w"> </span><span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span><span class="k">)</span><span class="s2">"</span>
</pre></div>
</div>
<p>Similarly, an <code class="docutils literal notranslate"><span class="pre">eval.sh</span></code> script might be run with</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>sbatch<span class="w"> </span>./eval.sh<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--watch<span class="w"> </span>--checkpoint<span class="w"> </span><span class="s2">"outputs/shufflenetv2k16-201023-163830-cocokp.pkl.epoch??[0,5]"</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--dataset<span class="o">=</span>cocokp<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--loader-workers<span class="o">=</span><span class="m">2</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--force-complete-pose<span class="w"> </span>--seed-threshold<span class="o">=</span><span class="m">0</span>.2
</pre></div>
</div>
<p>and look like this:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/bin/bash -l</span>
<span class="c1">#SBATCH --nodes 1</span>
<span class="c1">#SBATCH --ntasks 1</span>
<span class="c1">#SBATCH --cpus-per-task 20</span>
<span class="c1">#SBATCH --mem 48G</span>
<span class="c1">#SBATCH --time 06:00:00</span>
<span class="c1">#SBATCH --account=<your-account-name></span>
<span class="c1">#SBATCH --gres gpu:1</span>
<span class="nv">pattern</span><span class="o">=</span><span class="nv">$1</span>
<span class="nb">shift</span>
srun<span class="w"> </span>singularity<span class="w"> </span><span class="nb">exec</span><span class="w"> </span>--bind<span class="w"> </span><make-host-dir-available><span class="w"> </span>--nv<span class="w"> </span>pytorch_latest.sif<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>/bin/bash<span class="w"> </span>-c<span class="w"> </span><span class="s2">"source ./venv3/bin/activate && python3 -m openpifpaf.eval </span><span class="k">$(</span><span class="nb">printf</span><span class="w"> </span><span class="s1">'%q '</span><span class="w"> </span><span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span><span class="k">)</span><span class="s2">"</span>
</pre></div>
</div>
</section>
<section id="distributeddataparallel">
<h2>DistributedDataParallel<a class="headerlink" href="#distributeddataparallel" title="Permalink to this headline">#</a></h2>
<p>This mode of parallelization is activated with the <code class="docutils literal notranslate"><span class="pre">--ddp</span></code> argument.
With <code class="docutils literal notranslate"><span class="pre">torch.distributed.launch</span></code>:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>-m<span class="w"> </span>torch.distributed.launch<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-m<span class="w"> </span>openpifpaf.train<span class="w"> </span>--ddp<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--all-other-args
</pre></div>
</div>
<p>By default, this will replace all BatchNorms in the model with SyncBatchNorms.
The only argument that behaves differently is <code class="docutils literal notranslate"><span class="pre">--batch-size</span></code> which is
the total batch size across all GPUs with DataParallel but here with
DistributedDataParallel it is the batch size of a single process/GPU.
This is the behavior of PyTorch in these two modes and we did not add
any code to change that.
On SLURM, the equivalent sbatch script is:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/bin/bash -l</span>
<span class="c1">#SBATCH --ntasks 4</span>
<span class="c1">#SBATCH --cpus-per-task 20</span>
<span class="c1">#SBATCH --mem 48G</span>
<span class="c1">#SBATCH --time 72:00:00</span>
<span class="c1">#SBATCH --gres gpu:2 # or as many GPUs as you have in a node</span>
srun<span class="w"> </span>--gpu-bind<span class="o">=</span>closest<span class="w"> </span>singularity<span class="w"> </span><span class="nb">exec</span><span class="w"> </span>--bind<span class="w"> </span>/scratch/izar<span class="w"> </span>--nv<span class="w"> </span>pytorch_latest.sif<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>/bin/bash<span class="w"> </span>-c<span class="w"> </span><span class="s2">"source ./venv3/bin/activate && MASTER_ADDR=</span><span class="k">$(</span>hostname<span class="k">)</span><span class="s2"> MASTER_PORT=7142 python3 -u -m openpifpaf.train --ddp </span><span class="k">$(</span><span class="nb">printf</span><span class="w"> </span><span class="s2">"%s "</span><span class="w"> </span><span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span><span class="k">)</span><span class="s2">"</span>
</pre></div>
</div>
</section>
</section>
<script type="text/x-thebe-config">
{
requestKernel: true,
binderOptions: {
repo: "binder-examples/jupyter-stacks-datascience",
ref: "master",
},
codeMirrorConfig: {
theme: "abcdef",
mode: "python"
},
kernelOptions: {
kernelName: "python3",
path: "./."
},
predefinedOutput: true
}
</script>
<script>kernelName = 'python3'</script>
</div>
</main>
<footer class="footer-article noprint">
<!-- Previous / next buttons -->
<div class='prev-next-area'>
<a class='left-prev' id="prev-link" href="datasets.html" title="previous page">
<i class="fas fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">Datasets</p>
</div>
</a>
<a class='right-next' id="next-link" href="cli_help.html" title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Command Line</p>
</div>
<i class="fas fa-angle-right"></i>
</a>
</div>
</footer>
</div>
</div>
<div class="footer-content row">
<footer class="col footer"><p>
By <a href="https://www.svenkreiss.com">Sven Kreiss</a> and <a href="https://github.com/openpifpaf/openpifpaf/graphs/contributors">contributors</a>.<br/>