-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins_custom.html
More file actions
921 lines (813 loc) · 45.1 KB
/
Copy pathplugins_custom.html
File metadata and controls
921 lines (813 loc) · 45.1 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
<!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>Custom Dataset — 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>
<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="Animal Keypoints" href="plugins_animalpose.html" />
<link rel="prev" title="FAQ" href="faq.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="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">
<a class="reference internal" href="train.html">
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="current nav bd-sidenav">
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
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/plugins_custom.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%2Fplugins_custom.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/plugins_custom.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/plugins_custom.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="#overview">
Overview
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#plugin-structure">
Plugin structure
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#data-module">
1. Data Module
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#plugin-registration">
2. Plugin Registration
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#constants">
3. Constants
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#data-loading">
4. Data Loading
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#annotations-format">
5. Annotations format
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#training">
Training
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#evaluation">
Evaluation
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#prediction">
Prediction
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#final-remarks">
Final remarks
</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>Custom Dataset</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="#overview">
Overview
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#plugin-structure">
Plugin structure
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#data-module">
1. Data Module
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#plugin-registration">
2. Plugin Registration
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#constants">
3. Constants
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#data-loading">
4. Data Loading
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#annotations-format">
5. Annotations format
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#training">
Training
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#evaluation">
Evaluation
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#prediction">
Prediction
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#final-remarks">
Final remarks
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<main id="main-content" role="main">
<div>
<section class="tex2jax_ignore mathjax_ignore" id="custom-dataset">
<h1>Custom Dataset<a class="headerlink" href="#custom-dataset" title="Permalink to this headline">#</a></h1>
<div style="text-align: right"> by <a href="https://scholar.google.com/citations?user=f-4YHeMAAAAJ&hl=en">Lorenzo Bertoni</a> 13/04/2021 </div>
<section id="overview">
<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">#</a></h2>
<p>In this section of the guide, we will see how to train and evaluate OpenPifPaf on a custom dataset. OpenPifPaf is based on the concept of <strong><a class="reference external" href="https://cs.uwaterloo.ca/~m2nagapp/courses/CS446/1195/Arch_Design_Activity/PlugIn.pdf">Plugin architecture pattern</a></strong>, and the overall system is composed of a core component and auxiliary plug-in modules. To train a model on a custom dataset, you don’t need to change the core system, only to create a small plugin for it.
This tutorial will go through the steps required to create a new plugin for a custom dataset.</p>
<p>Let’s go through the steps of implementing a 2D pose estimator for vehicles, as a case study. If you are interested in how this specific plugin works, please check its <a class="reference internal" href="plugins_apollocar3d.html"><span class="doc">guide section</span></a>. We suggest to create and debug your own plugin copying a pre-existing plugin, changing its name, and adapting its files to your needs.
Below, a description of the structure of the plugin to give you some intuition of what you will need to change.</p>
</section>
<section id="plugin-structure">
<h2>Plugin structure<a class="headerlink" href="#plugin-structure" title="Permalink to this headline">#</a></h2>
<section id="data-module">
<h3>1. Data Module<a class="headerlink" href="#data-module" title="Permalink to this headline">#</a></h3>
<p>This module handles the interface of your custom dataset with the core system and it is the main component of the plugin. For the <a class="reference external" href="http://apolloscape.auto/car_instance.html">ApolloCar3D Dataset</a>, we created a module called <em>apollo_kp.py</em> containing the class <a class="reference external" href="https://github.com/openpifpaf/openpifpaf/blob/main/openpifpaf/plugins/apollocar3d/apollo_kp.py">ApolloKp</a> which inherits from the <a class="reference external" href="https://github.com/openpifpaf/openpifpaf/blob/main/openpifpaf/datasets/module.py">DataModule</a> class.</p>
<p>The base class to inherit from has the following structure:</p>
<dl class="py class">
<dt class="sig sig-object py">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">openpifpaf.datasets.</span></span><span class="sig-name descname"><span class="pre">DataModule</span></span></dt>
<dd><p>Base class to extend OpenPifPaf with custom data.</p>
<p>This class gives you all the handles to train OpenPifPaf on a new dataset.
Create a new class that inherits from this to handle a new datasets.</p>
<ol class="arabic simple">
<li><p>Define the PifPaf heads you would like to train. For example, CIF (Composite Intensity Fields) to detect keypoints, and CAF (Composite Association Fields) to associate joints</p></li>
<li><p>Add class variables, such as annotations, training/validation image paths.</p></li>
</ol>
<dl class="py method">
<dt class="sig sig-object py">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">cli</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">parser</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">argparse.ArgumentParser</span></span></em><span class="sig-paren">)</span></dt>
<dd><p>Command line interface (CLI) to extend argument parser for your custom dataset.</p>
<p>Make sure to use unique CLI arguments for your dataset.
For clarity, we suggest to start every CLI argument with the name of your new dataset,
i.e. --<dataset_name>-train-annotations.</p>
<p>All PifPaf commands will still work.
E.g. to load a model, there is no need to implement the command --checkpoint</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">configure</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">args</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">argparse.Namespace</span></span></em><span class="sig-paren">)</span></dt>
<dd><p>Take the parsed argument parser output and configure class variables.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">metrics</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">List</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="moduledocs.html#openpifpaf.metric.Base" title="openpifpaf.metric.base.Base"><span class="pre">openpifpaf.metric.base.Base</span></a><span class="p"><span class="pre">]</span></span></span></span></dt>
<dd><p>Define a list of metrics to be used for eval.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">train_loader</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">torch.utils.data.dataloader.DataLoader</span></span></span></dt>
<dd><p>Loader of the training dataset.</p>
<p>A Coco Data loader is already available, or a custom one can be created and called here.
To modify preprocessing steps of your images (for example scaling image during training):</p>
<ol class="arabic simple">
<li><p>chain them using torchvision.transforms.Compose(transforms)</p></li>
<li><p>pass them to the preprocessing argument of the dataloader</p></li>
</ol>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">val_loader</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">torch.utils.data.dataloader.DataLoader</span></span></span></dt>
<dd><p>Loader of the validation dataset.</p>
<p>The augmentation and preprocessing should be the same as for train_loader.
The only difference is the set of data. This allows to inspect the
train/val curves for overfitting.</p>
<p>As in the train_loader, the annotations should be encoded fields
so that the loss function can be computed.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">eval_loader</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">torch.utils.data.dataloader.DataLoader</span></span></span></dt>
<dd><p>Loader of the evaluation dataset.</p>
<p>For local runs, it is common that the validation dataset is also the
evaluation dataset. This is then changed to test datasets (without
ground truth) to produce predictions for submissions to a competition
server that holds the private ground truth.</p>
<p>This loader shouldn’t have any data augmentation. The images should be
as close as possible to the real application.
The annotations should be the ground truth annotations similarly to
what the output of the decoder is expected to be.</p>
</dd></dl>
</dd></dl>
<p>Now that you have a general view of the structure of a data module, we suggest you to refer to the implementation of the <a class="reference external" href="https://github.com/openpifpaf/openpifpaf/blob/main/openpifpaf/plugins/apollocar3d/apollo_kp.py">ApolloKp</a> class. You can get started by copying and modifying this class according to your needs.</p>
</section>
<section id="plugin-registration">
<h3>2. Plugin Registration<a class="headerlink" href="#plugin-registration" title="Permalink to this headline">#</a></h3>
<p>For the core system to recognize the new plugin you need to create a <a class="reference external" href="https://github.com/openpifpaf/openpifpaf/blob/main/openpifpaf/plugins/apollocar3d/__init__.py">__init__.py</a> file specifying:</p>
<ol class="simple">
<li><p><strong>Name Convention</strong>: include all the plugins file into a folder named <strong>openpifpaf_<plugin_name></strong>. Only folders, which names start with openpifpaf_ are recognized</p></li>
<li><p><strong>Registration</strong>: Inside the folder, create an <em><a class="reference external" href="http://init.py">init.py</a></em> file and add to the list of existing plugins the datamodule that we have just created (<strong>ApolloKp</strong>). In this case, the name <strong>apollo</strong> represents the name of the dataset.</p></li>
</ol>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">register</span><span class="p">():</span>
<span class="n">openpifpaf</span><span class="o">.</span><span class="n">DATAMODULES</span><span class="p">[</span><span class="s1">'apollo'</span><span class="p">]</span> <span class="o">=</span> <span class="n">ApolloKp</span>
</pre></div>
</div>
</div>
</div>
</section>
<section id="constants">
<h3>3. Constants<a class="headerlink" href="#constants" title="Permalink to this headline">#</a></h3>
<p>Create a module <em><a class="reference external" href="http://constants.py">constants.py</a></em> containing all the constants needed to define the 2D keypoints of vehicles. The most important are:</p>
<ul class="simple">
<li><p><strong>Names</strong> of the keypoints, as a list of strings. In our plugin this is called CAR_KEYPOINTS</p></li>
<li><p><strong>Skeleton</strong>: the connections between the keypooints, as a list of lists of two elements indicating the indeces of the starting and ending connections. In our plugin this is called CAR_SKELETON</p></li>
<li><p><strong>Sigmas</strong>: the size of the area to compute the object keypoint similarity (OKS), if you wish to use average precision (AP) as a metric.</p></li>
<li><p><strong>Score weights</strong>:the weights to compute the overall score of an object (e.g. car or person). When computing the overall score the highest weights will be assigned to the most confident joints.</p></li>
<li><p><strong>Categories</strong> of the keypoints. In this case, the only category is car.</p></li>
<li><p><strong>Standard pose</strong> of the keypoints, to visualize the connections between the keypoints and as an argument for the head network.</p></li>
<li><p><strong>Horizontal flip</strong> equivalents, if you use horizontal flipping as augmentation technique, you will need to define the corresponding left and right and keypoints as a dictionary. E.g. left_ear –> right_ear. In our plugin this is called HFLIP</p></li>
</ul>
<p>In addition to the constants, the module contains two functions to draw the skeleton and save it as an image. The functions are only for debugging and can usually be used as they are, only changing the arguments with the new constants. For additional information, refer to the file <a class="reference external" href="https://github.com/openpifpaf/openpifpaf/blob/main/openpifpaf/plugins/apollocar3d/constants.py">constants.py</a>.</p>
</section>
<section id="data-loading">
<h3>4. Data Loading<a class="headerlink" href="#data-loading" title="Permalink to this headline">#</a></h3>
<p>If you are using COCO-style annotations, there is no need to create a datalader to load images and annotations. A default <a class="reference external" href="https://github.com/openpifpaf/openpifpaf/blob/main/openpifpaf/plugins/coco/dataset.py">CocoLoader</a> is already available to be called inside the data module <a class="reference external" href="https://github.com/openpifpaf/openpifpaf/blob/main/openpifpaf/plugins/apollocar3d/apollo_kp.py">ApolloKp</a></p>
<p>If you wish to load different annotations, you can either write your own dataloader, or you can transform your annotations to COCO style .json files. In this plugin, we first convert ApolloCar3D annotations into COCO style .json files and then load them as standard annotations.</p>
</section>
<section id="annotations-format">
<h3>5. Annotations format<a class="headerlink" href="#annotations-format" title="Permalink to this headline">#</a></h3>
<p>This step transforms custom annotations, in this case from ApolloCar3D, into COCO-style annotations. Below we describe how to populate a json file using COCO-style format. For the full working example, check the module <a class="reference external" href="https://github.com/openpifpaf/openpifpaf/blob/main/openpifpaf/plugins/apollocar3d/apollo_to_coco.py">apollo_to_coco.py</a> inside the plugin.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">initiate_json</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> Initiate json file: one for training phase and another one for validation.</span>
<span class="sd"> """</span>
<span class="bp">self</span><span class="o">.</span><span class="n">json_file</span><span class="p">[</span><span class="s2">"info"</span><span class="p">]</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="s2">"https://github.com/openpifpaf/openpifpaf"</span><span class="p">,</span>
<span class="n">date_created</span><span class="o">=</span><span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">"</span><span class="si">%a</span><span class="s2">, </span><span class="si">%d</span><span class="s2"> %b %Y %H:%M:%S +0000"</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">localtime</span><span class="p">()),</span>
<span class="n">description</span><span class="o">=</span><span class="s2">"Conversion of ApolloCar3D dataset into MS-COCO format"</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">json_file</span><span class="p">[</span><span class="s2">"categories"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">dict</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="c1"># Category name</span>
<span class="nb">id</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="c1"># Id of category</span>
<span class="n">skeleton</span><span class="o">=</span><span class="p">[],</span> <span class="c1"># Skeleton connections (check constants.py)</span>
<span class="n">supercategory</span><span class="o">=</span><span class="s1">''</span><span class="p">,</span> <span class="c1"># Same as category if no supercategory</span>
<span class="n">keypoints</span><span class="o">=</span><span class="p">[])]</span> <span class="c1"># Keypoint names</span>
<span class="bp">self</span><span class="o">.</span><span class="n">json_file</span><span class="p">[</span><span class="s2">"images"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> <span class="c1"># Empty for initialization</span>
<span class="bp">self</span><span class="o">.</span><span class="n">json_file</span><span class="p">[</span><span class="s2">"annotations"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> <span class="c1"># Empty for initialization</span>
<span class="k">def</span> <span class="nf">process_image</span><span class="p">(</span><span class="n">json_file</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> Update image field in json file</span>
<span class="sd"> """</span>
<span class="c1"># ------------------</span>
<span class="c1"># Add here your code</span>
<span class="c1"># -------------------</span>
<span class="n">json_file</span><span class="p">[</span><span class="s2">"images"</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">({</span>
<span class="s1">'coco_url'</span><span class="p">:</span> <span class="s2">"unknown"</span><span class="p">,</span>
<span class="s1">'file_name'</span><span class="p">:</span> <span class="s1">''</span><span class="p">,</span> <span class="c1"># Image name</span>
<span class="s1">'id'</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="c1"># Image id</span>
<span class="s1">'license'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="c1"># License type</span>
<span class="s1">'date_captured'</span><span class="p">:</span> <span class="s2">"unknown"</span><span class="p">,</span>
<span class="s1">'width'</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="c1"># Image width (pixels)</span>
<span class="s1">'height'</span><span class="p">:</span> <span class="mi">0</span><span class="p">})</span> <span class="c1"># Image height (pixels)</span>
<span class="k">def</span> <span class="nf">process_annotation</span><span class="p">(</span><span class="n">json_file</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> Process and include in the json file a single annotation (instance) from a given image</span>
<span class="sd"> """</span>
<span class="c1"># ------------------</span>
<span class="c1"># Add here your code</span>
<span class="c1"># -------------------</span>
<span class="n">json_file</span><span class="p">[</span><span class="s2">"annotations"</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">({</span>
<span class="s1">'image_id'</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="c1"># Image id</span>
<span class="s1">'category_id'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="c1"># Id of the category (like car or person)</span>
<span class="s1">'iscrowd'</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="c1"># 1 to mask crowd regions, 0 if the annotation is not a crowd annotation</span>
<span class="s1">'id'</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="c1"># Id of the annotations</span>
<span class="s1">'area'</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="c1"># Bounding box area of the annotation (width*height)</span>
<span class="s1">'bbox'</span><span class="p">:</span> <span class="p">[],</span> <span class="c1"># Bounding box coordinates (x0, y0, width, heigth), where x0, y0 are the left corner</span>
<span class="s1">'num_keypoints'</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="c1"># number of keypoints</span>
<span class="s1">'keypoints'</span><span class="p">:</span> <span class="p">[],</span> <span class="c1"># Flattened list of keypoints [x, y, visibility, x, y, visibility, .. ]</span>
<span class="s1">'segmentation'</span><span class="p">:</span> <span class="p">[]})</span> <span class="c1"># To add a segmentation of the annotation, empty otherwise</span>
</pre></div>
</div>
</div>
</div>
</section>
</section>
<section id="training">
<h2>Training<a class="headerlink" href="#training" title="Permalink to this headline">#</a></h2>
<p>We have seen all the elements needed to create your own plugin on a custom dataset. To train the dataset, all OpenPifPaf commands are still valid. There are only two differences:</p>
<ol class="simple">
<li><p>Specify the dataset name in the training command. In this case, we have called our dataset <em>apollo</em> during the registration phase, therefore we will have <code class="docutils literal notranslate"><span class="pre">--dataset=apollo</span></code>.</p></li>
<li><p>Include the commands we have created in the data module for this specific dataset, for example <code class="docutils literal notranslate"><span class="pre">--apollo-square-edge</span></code> to define the size of the training crops.</p></li>
</ol>
<p>A training command may look like this:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.train<span class="w"> </span>--dataset<span class="w"> </span>apollo<span class="w"> </span><span class="se">\</span>
--apollo-square-edge<span class="o">=</span><span class="m">769</span><span class="w"> </span><span class="se">\</span>
--basenet<span class="o">=</span>shufflenetv2k16<span class="w"> </span>--lr<span class="o">=</span><span class="m">0</span>.00002<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">5</span>.0<span class="w"> </span><span class="se">\</span>
--epochs<span class="o">=</span><span class="m">300</span><span class="w"> </span>--lr-decay<span class="w"> </span><span class="m">160</span><span class="w"> </span><span class="m">260</span><span class="w"> </span>--lr-decay-epochs<span class="o">=</span><span class="m">10</span><span class="w"> </span>--weight-decay<span class="o">=</span>1e-5<span class="w"> </span><span class="se">\</span>
--weight-decay<span class="o">=</span>1e-5<span class="w"> </span>--val-interval<span class="w"> </span><span class="m">10</span><span class="w"> </span>--loader-workers<span class="w"> </span><span class="m">16</span><span class="w"> </span>--apollo-upsample<span class="w"> </span><span class="m">2</span><span class="w"> </span><span class="se">\</span>
--apollo-bmin<span class="w"> </span><span class="m">2</span><span class="w"> </span>--batch-size<span class="w"> </span><span class="m">8</span>
</pre></div>
</div>
</section>
<section id="evaluation">
<h2>Evaluation<a class="headerlink" href="#evaluation" title="Permalink to this headline">#</a></h2>
<p>Evaluation on the COCO metric is supported by pifpaf and a simple evaluation command may look like this:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python3<span class="w"> </span>-m<span class="w"> </span>openpifpaf.eval<span class="w"> </span>--dataset<span class="o">=</span>apollo<span class="w"> </span>--checkpoint<span class="w"> </span><path<span class="w"> </span>of<span class="w"> </span>the<span class="w"> </span>model>
</pre></div>
</div>
<p>To evaluate on custom metrics, we would need to define a new metric and add it in the list of metrics, inside the data module. In our case, we have a a DataModule class called <strong>ApolloKp</strong>, and its function <em><strong>metrics</strong></em> returns the list of metrics to run. Each metric is defined as a class that inherits from openpifpaf.metric.base.Base</p>
<p>For more information, please check how we implemented a simple metric for the ApolloCar3D dataset called MeanPixelError, that calculate mean pixel error and detection rate for a given image.</p>
</section>
<section id="prediction">
<h2>Prediction<a class="headerlink" href="#prediction" title="Permalink to this headline">#</a></h2>
<p>To run your model trained on a different dataset, you simply need to run the standard OpenPifPaf command specifying your model. A prediction command looks like this:</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>--checkpoint<span class="w"> </span><model<span class="w"> </span>path>
</pre></div>
</div>
<p>All the command line options are still valid, check them with:</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>--help
</pre></div>
</div>
</section>
<section id="final-remarks">
<h2>Final remarks<a class="headerlink" href="#final-remarks" title="Permalink to this headline">#</a></h2>
<p>We hope you’ll find this guide useful to create your own plugin. For more information check the guide section for the <a class="reference internal" href="plugins_apollocar3d.html"><span class="doc">ApolloCar3D plugin</span></a>.</p>
<p>Please keep us posted on issues you encounter (using the issue section on GitHub) and especially on your successes! We will be more than happy to add your plugin to the list of OpenPifPaf <a class="reference external" href="https://openpifpaf.github.io/intro.html#related-projects">related projects</a>.</p>
<p>Finally, if you find OpenPifPaf useful for your research, we would be happy if you <a class="reference internal" href="intro.html#citation"><span class="std std-ref">cite us</span></a>!</p>
</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="faq.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">FAQ</p>
</div>
</a>
<a class='right-next' id="next-link" href="plugins_animalpose.html" title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Animal Keypoints</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/>
© Copyright 2020-2022.<br/>
<div class="extra_footer">
<p>Powered by <a href="https://jupyterbook.org/">Jupyter Book</a>.</p>
</div>
</p>
</footer>
</div>
</div>
</div>
</div>
<!-- Scripts loaded after <body> so the DOM is not blocked -->
<script src="_static/scripts/pydata-sphinx-theme.js?digest=1999514e3f237ded88cf"></script>
</body>
</html>