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

#609 Ci fix

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:bugfix/infra-000_ci
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
  1. <!DOCTYPE html>
  2. <html class="writer-html5" lang="en" >
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>super_gradients.training.datasets.segmentation_datasets.pascal_voc_segmentation &mdash; SuperGradients 3.0.3 documentation</title>
  7. <link rel="stylesheet" href="../../../../../_static/pygments.css" type="text/css" />
  8. <link rel="stylesheet" href="../../../../../_static/css/theme.css" type="text/css" />
  9. <link rel="stylesheet" href="../../../../../_static/graphviz.css" type="text/css" />
  10. <link rel="stylesheet" href="../../../../../_static/custom.css" type="text/css" />
  11. <!--[if lt IE 9]>
  12. <script src="../../../../../_static/js/html5shiv.min.js"></script>
  13. <![endif]-->
  14. <script data-url_root="../../../../../" id="documentation_options" src="../../../../../_static/documentation_options.js"></script>
  15. <script src="../../../../../_static/jquery.js"></script>
  16. <script src="../../../../../_static/underscore.js"></script>
  17. <script src="../../../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
  18. <script src="../../../../../_static/doctools.js"></script>
  19. <script src="../../../../../_static/sphinx_highlight.js"></script>
  20. <script src="../../../../../_static/js/theme.js"></script>
  21. <link rel="index" title="Index" href="../../../../../genindex.html" />
  22. <link rel="search" title="Search" href="../../../../../search.html" />
  23. </head>
  24. <body class="wy-body-for-nav">
  25. <div class="wy-grid-for-nav">
  26. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  27. <div class="wy-side-scroll">
  28. <div class="wy-side-nav-search" >
  29. <a href="../../../../../index.html" class="icon icon-home"> SuperGradients
  30. </a>
  31. <div role="search">
  32. <form id="rtd-search-form" class="wy-form" action="../../../../../search.html" method="get">
  33. <input type="text" name="q" placeholder="Search docs" />
  34. <input type="hidden" name="check_keywords" value="yes" />
  35. <input type="hidden" name="area" value="default" />
  36. </form>
  37. </div>
  38. </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
  39. <p class="caption" role="heading"><span class="caption-text">Welcome To SuperGradients</span></p>
  40. <ul>
  41. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html">Version 3 is out! Notebooks have been updated!</a></li>
  42. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#build-with-supergradients">Build with SuperGradients</a></li>
  43. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#quick-installation">Quick Installation</a></li>
  44. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#what-s-new">What’s New</a></li>
  45. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#coming-soon">Coming soon</a></li>
  46. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#table-of-content">Table of Content</a></li>
  47. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#getting-started">Getting Started</a></li>
  48. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#advanced-features">Advanced Features</a></li>
  49. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#installation-methods">Installation Methods</a></li>
  50. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#implemented-model-architectures">Implemented Model Architectures</a></li>
  51. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#documentation">Documentation</a></li>
  52. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#contributing">Contributing</a></li>
  53. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#citation">Citation</a></li>
  54. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#community">Community</a></li>
  55. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#license">License</a></li>
  56. <li class="toctree-l1"><a class="reference internal" href="../../../../../welcome.html#deci-platform">Deci Platform</a></li>
  57. </ul>
  58. <p class="caption" role="heading"><span class="caption-text">Technical Documentation</span></p>
  59. <ul>
  60. <li class="toctree-l1"><a class="reference internal" href="../../../../../super_gradients.common.html">Common package</a></li>
  61. <li class="toctree-l1"><a class="reference internal" href="../../../../../super_gradients.training.html">Training package</a></li>
  62. </ul>
  63. </div>
  64. </div>
  65. </nav>
  66. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
  67. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  68. <a href="../../../../../index.html">SuperGradients</a>
  69. </nav>
  70. <div class="wy-nav-content">
  71. <div class="rst-content">
  72. <div role="navigation" aria-label="Page navigation">
  73. <ul class="wy-breadcrumbs">
  74. <li><a href="../../../../../index.html" class="icon icon-home"></a> &raquo;</li>
  75. <li><a href="../../../../index.html">Module code</a> &raquo;</li>
  76. <li>super_gradients.training.datasets.segmentation_datasets.pascal_voc_segmentation</li>
  77. <li class="wy-breadcrumbs-aside">
  78. </li>
  79. </ul>
  80. <hr/>
  81. </div>
  82. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  83. <div itemprop="articleBody">
  84. <h1>Source code for super_gradients.training.datasets.segmentation_datasets.pascal_voc_segmentation</h1><div class="highlight"><pre>
  85. <span></span><span class="kn">import</span> <span class="nn">os</span>
  86. <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
  87. <span class="kn">import</span> <span class="nn">scipy.io</span>
  88. <span class="kn">from</span> <span class="nn">PIL</span> <span class="kn">import</span> <span class="n">Image</span>
  89. <span class="kn">from</span> <span class="nn">torch.utils.data</span> <span class="kn">import</span> <span class="n">ConcatDataset</span>
  90. <span class="kn">from</span> <span class="nn">super_gradients.training.datasets.segmentation_datasets.segmentation_dataset</span> <span class="kn">import</span> <span class="n">SegmentationDataSet</span>
  91. <span class="kn">from</span> <span class="nn">super_gradients.common.abstractions.abstract_logger</span> <span class="kn">import</span> <span class="n">get_logger</span>
  92. <span class="n">logger</span> <span class="o">=</span> <span class="n">get_logger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>
  93. <span class="n">PASCAL_VOC_2012_CLASSES</span> <span class="o">=</span> <span class="p">[</span>
  94. <span class="s2">&quot;background&quot;</span><span class="p">,</span>
  95. <span class="s2">&quot;aeroplane&quot;</span><span class="p">,</span>
  96. <span class="s2">&quot;bicycle&quot;</span><span class="p">,</span>
  97. <span class="s2">&quot;bird&quot;</span><span class="p">,</span>
  98. <span class="s2">&quot;boat&quot;</span><span class="p">,</span>
  99. <span class="s2">&quot;bottle&quot;</span><span class="p">,</span>
  100. <span class="s2">&quot;bus&quot;</span><span class="p">,</span>
  101. <span class="s2">&quot;car&quot;</span><span class="p">,</span>
  102. <span class="s2">&quot;cat&quot;</span><span class="p">,</span>
  103. <span class="s2">&quot;chair&quot;</span><span class="p">,</span>
  104. <span class="s2">&quot;cow&quot;</span><span class="p">,</span>
  105. <span class="s2">&quot;diningtable&quot;</span><span class="p">,</span>
  106. <span class="s2">&quot;dog&quot;</span><span class="p">,</span>
  107. <span class="s2">&quot;horse&quot;</span><span class="p">,</span>
  108. <span class="s2">&quot;motorbike&quot;</span><span class="p">,</span>
  109. <span class="s2">&quot;person&quot;</span><span class="p">,</span>
  110. <span class="s2">&quot;potted-plant&quot;</span><span class="p">,</span>
  111. <span class="s2">&quot;sheep&quot;</span><span class="p">,</span>
  112. <span class="s2">&quot;sofa&quot;</span><span class="p">,</span>
  113. <span class="s2">&quot;train&quot;</span><span class="p">,</span>
  114. <span class="s2">&quot;tv/monitor&quot;</span><span class="p">,</span>
  115. <span class="p">]</span>
  116. <div class="viewcode-block" id="PascalVOC2012SegmentationDataSet"><a class="viewcode-back" href="../../../../../super_gradients.training.html#super_gradients.training.datasets.PascalVOC2012SegmentationDataSet">[docs]</a><span class="k">class</span> <span class="nc">PascalVOC2012SegmentationDataSet</span><span class="p">(</span><span class="n">SegmentationDataSet</span><span class="p">):</span>
  117. <span class="sd">&quot;&quot;&quot;</span>
  118. <span class="sd"> PascalVOC2012SegmentationDataSet - Segmentation Data Set Class for Pascal VOC 2012 Data Set</span>
  119. <span class="sd"> &quot;&quot;&quot;</span>
  120. <span class="n">IGNORE_LABEL</span> <span class="o">=</span> <span class="mi">21</span>
  121. <span class="n">_ORIGINAL_IGNORE_LABEL</span> <span class="o">=</span> <span class="mi">255</span>
  122. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sample_suffix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">target_suffix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
  123. <span class="bp">self</span><span class="o">.</span><span class="n">sample_suffix</span> <span class="o">=</span> <span class="s2">&quot;.jpg&quot;</span> <span class="k">if</span> <span class="n">sample_suffix</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">sample_suffix</span>
  124. <span class="bp">self</span><span class="o">.</span><span class="n">target_suffix</span> <span class="o">=</span> <span class="s2">&quot;.png&quot;</span> <span class="k">if</span> <span class="n">target_suffix</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">target_suffix</span>
  125. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
  126. <span class="bp">self</span><span class="o">.</span><span class="n">classes</span> <span class="o">=</span> <span class="n">PASCAL_VOC_2012_CLASSES</span>
  127. <div class="viewcode-block" id="PascalVOC2012SegmentationDataSet.target_transform"><a class="viewcode-back" href="../../../../../super_gradients.training.html#super_gradients.training.datasets.PascalVOC2012SegmentationDataSet.target_transform">[docs]</a> <span class="nd">@staticmethod</span>
  128. <span class="k">def</span> <span class="nf">target_transform</span><span class="p">(</span><span class="n">target</span><span class="p">):</span>
  129. <span class="sd">&quot;&quot;&quot;</span>
  130. <span class="sd"> target_transform - Transforms the label mask</span>
  131. <span class="sd"> This function overrides the original function from SegmentationDataSet and changes target pixels with value</span>
  132. <span class="sd"> 255 to value = IGNORE_LABEL. This was done since current IoU metric from torchmetrics does not</span>
  133. <span class="sd"> support such a high ignore label value (crashed on OOM)</span>
  134. <span class="sd"> :param target: The target mask to transform</span>
  135. <span class="sd"> :return: The transformed target mask</span>
  136. <span class="sd"> &quot;&quot;&quot;</span>
  137. <span class="n">out</span> <span class="o">=</span> <span class="n">SegmentationDataSet</span><span class="o">.</span><span class="n">target_transform</span><span class="p">(</span><span class="n">target</span><span class="p">)</span>
  138. <span class="n">out</span><span class="p">[</span><span class="n">out</span> <span class="o">==</span> <span class="n">PascalVOC2012SegmentationDataSet</span><span class="o">.</span><span class="n">_ORIGINAL_IGNORE_LABEL</span><span class="p">]</span> <span class="o">=</span> <span class="n">PascalVOC2012SegmentationDataSet</span><span class="o">.</span><span class="n">IGNORE_LABEL</span>
  139. <span class="k">return</span> <span class="n">out</span></div>
  140. <div class="viewcode-block" id="PascalVOC2012SegmentationDataSet.decode_segmentation_mask"><a class="viewcode-back" href="../../../../../super_gradients.training.html#super_gradients.training.datasets.PascalVOC2012SegmentationDataSet.decode_segmentation_mask">[docs]</a> <span class="k">def</span> <span class="nf">decode_segmentation_mask</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label_mask</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
  141. <span class="sd">&quot;&quot;&quot;</span>
  142. <span class="sd"> decode_segmentation_mask - Decodes the colors for the Segmentation Mask</span>
  143. <span class="sd"> :param: label_mask: an (M,N) array of integer values denoting</span>
  144. <span class="sd"> the class label at each spatial location.</span>
  145. <span class="sd"> :return:</span>
  146. <span class="sd"> &quot;&quot;&quot;</span>
  147. <span class="n">label_colours</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_pascal_labels</span><span class="p">()</span>
  148. <span class="n">r</span> <span class="o">=</span> <span class="n">label_mask</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
  149. <span class="n">g</span> <span class="o">=</span> <span class="n">label_mask</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
  150. <span class="n">b</span> <span class="o">=</span> <span class="n">label_mask</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
  151. <span class="n">num_classes_to_plot</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">classes</span><span class="p">)</span>
  152. <span class="k">for</span> <span class="n">ll</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">num_classes_to_plot</span><span class="p">):</span>
  153. <span class="n">r</span><span class="p">[</span><span class="n">label_mask</span> <span class="o">==</span> <span class="n">ll</span><span class="p">]</span> <span class="o">=</span> <span class="n">label_colours</span><span class="p">[</span><span class="n">ll</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
  154. <span class="n">g</span><span class="p">[</span><span class="n">label_mask</span> <span class="o">==</span> <span class="n">ll</span><span class="p">]</span> <span class="o">=</span> <span class="n">label_colours</span><span class="p">[</span><span class="n">ll</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
  155. <span class="n">b</span><span class="p">[</span><span class="n">label_mask</span> <span class="o">==</span> <span class="n">ll</span><span class="p">]</span> <span class="o">=</span> <span class="n">label_colours</span><span class="p">[</span><span class="n">ll</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
  156. <span class="n">rgb</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">label_mask</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">label_mask</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">3</span><span class="p">))</span>
  157. <span class="n">rgb</span><span class="p">[:,</span> <span class="p">:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">r</span> <span class="o">/</span> <span class="mf">255.0</span>
  158. <span class="n">rgb</span><span class="p">[:,</span> <span class="p">:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">g</span> <span class="o">/</span> <span class="mf">255.0</span>
  159. <span class="n">rgb</span><span class="p">[:,</span> <span class="p">:,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">b</span> <span class="o">/</span> <span class="mf">255.0</span>
  160. <span class="k">return</span> <span class="n">rgb</span></div>
  161. <span class="k">def</span> <span class="nf">_generate_samples_and_targets</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  162. <span class="sd">&quot;&quot;&quot;</span>
  163. <span class="sd"> _generate_samples_and_targets</span>
  164. <span class="sd"> &quot;&quot;&quot;</span>
  165. <span class="c1"># GENERATE SAMPLES AND TARGETS HERE SPECIFICALLY FOR PASCAL VOC 2012</span>
  166. <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">root</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">list_file_path</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">lines</span><span class="p">:</span>
  167. <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">:</span>
  168. <span class="n">image_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">samples_sub_directory</span><span class="p">,</span> <span class="n">line</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">sample_suffix</span><span class="p">)</span>
  169. <span class="n">mask_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">targets_sub_directory</span><span class="p">,</span> <span class="n">line</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">target_suffix</span><span class="p">)</span>
  170. <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">mask_path</span><span class="p">)</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">image_path</span><span class="p">):</span>
  171. <span class="bp">self</span><span class="o">.</span><span class="n">samples_targets_tuples_list</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">image_path</span><span class="p">,</span> <span class="n">mask_path</span><span class="p">))</span>
  172. <span class="c1"># GENERATE SAMPLES AND TARGETS OF THE SEGMENTATION DATA SET CLASS</span>
  173. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_generate_samples_and_targets</span><span class="p">()</span>
  174. <span class="k">def</span> <span class="nf">_get_pascal_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  175. <span class="sd">&quot;&quot;&quot;Load the mapping that associates pascal classes with label colors</span>
  176. <span class="sd"> Returns:</span>
  177. <span class="sd"> np.ndarray with dimensions (21, 3)</span>
  178. <span class="sd"> &quot;&quot;&quot;</span>
  179. <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span>
  180. <span class="p">[</span>
  181. <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  182. <span class="p">[</span><span class="mi">128</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  183. <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">128</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  184. <span class="p">[</span><span class="mi">128</span><span class="p">,</span> <span class="mi">128</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  185. <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">128</span><span class="p">],</span>
  186. <span class="p">[</span><span class="mi">128</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">128</span><span class="p">],</span>
  187. <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">128</span><span class="p">,</span> <span class="mi">128</span><span class="p">],</span>
  188. <span class="p">[</span><span class="mi">128</span><span class="p">,</span> <span class="mi">128</span><span class="p">,</span> <span class="mi">128</span><span class="p">],</span>
  189. <span class="p">[</span><span class="mi">64</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  190. <span class="p">[</span><span class="mi">192</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  191. <span class="p">[</span><span class="mi">64</span><span class="p">,</span> <span class="mi">128</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  192. <span class="p">[</span><span class="mi">192</span><span class="p">,</span> <span class="mi">128</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  193. <span class="p">[</span><span class="mi">64</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">128</span><span class="p">],</span>
  194. <span class="p">[</span><span class="mi">192</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">128</span><span class="p">],</span>
  195. <span class="p">[</span><span class="mi">64</span><span class="p">,</span> <span class="mi">128</span><span class="p">,</span> <span class="mi">128</span><span class="p">],</span>
  196. <span class="p">[</span><span class="mi">192</span><span class="p">,</span> <span class="mi">128</span><span class="p">,</span> <span class="mi">128</span><span class="p">],</span>
  197. <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">64</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  198. <span class="p">[</span><span class="mi">128</span><span class="p">,</span> <span class="mi">64</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  199. <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">192</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  200. <span class="p">[</span><span class="mi">128</span><span class="p">,</span> <span class="mi">192</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
  201. <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">64</span><span class="p">,</span> <span class="mi">128</span><span class="p">],</span>
  202. <span class="p">]</span>
  203. <span class="p">)</span></div>
  204. <div class="viewcode-block" id="PascalAUG2012SegmentationDataSet"><a class="viewcode-back" href="../../../../../super_gradients.training.html#super_gradients.training.datasets.PascalAUG2012SegmentationDataSet">[docs]</a><span class="k">class</span> <span class="nc">PascalAUG2012SegmentationDataSet</span><span class="p">(</span><span class="n">PascalVOC2012SegmentationDataSet</span><span class="p">):</span>
  205. <span class="sd">&quot;&quot;&quot;</span>
  206. <span class="sd"> PascalAUG2012SegmentationDataSet - Segmentation Data Set Class for Pascal AUG 2012 Data Set</span>
  207. <span class="sd"> &quot;&quot;&quot;</span>
  208. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
  209. <span class="bp">self</span><span class="o">.</span><span class="n">sample_suffix</span> <span class="o">=</span> <span class="s2">&quot;.jpg&quot;</span>
  210. <span class="bp">self</span><span class="o">.</span><span class="n">target_suffix</span> <span class="o">=</span> <span class="s2">&quot;.mat&quot;</span>
  211. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">sample_suffix</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sample_suffix</span><span class="p">,</span> <span class="n">target_suffix</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">target_suffix</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
  212. <div class="viewcode-block" id="PascalAUG2012SegmentationDataSet.target_loader"><a class="viewcode-back" href="../../../../../super_gradients.training.html#super_gradients.training.datasets.PascalAUG2012SegmentationDataSet.target_loader">[docs]</a> <span class="nd">@staticmethod</span>
  213. <span class="k">def</span> <span class="nf">target_loader</span><span class="p">(</span><span class="n">target_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Image</span><span class="p">:</span>
  214. <span class="sd">&quot;&quot;&quot;</span>
  215. <span class="sd"> target_loader</span>
  216. <span class="sd"> :param target_path: The path to the target data</span>
  217. <span class="sd"> :return: The loaded target</span>
  218. <span class="sd"> &quot;&quot;&quot;</span>
  219. <span class="n">mat</span> <span class="o">=</span> <span class="n">scipy</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">loadmat</span><span class="p">(</span><span class="n">target_path</span><span class="p">,</span> <span class="n">mat_dtype</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">squeeze_me</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">struct_as_record</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
  220. <span class="n">mask</span> <span class="o">=</span> <span class="n">mat</span><span class="p">[</span><span class="s2">&quot;GTcls&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">Segmentation</span>
  221. <span class="k">return</span> <span class="n">Image</span><span class="o">.</span><span class="n">fromarray</span><span class="p">(</span><span class="n">mask</span><span class="p">)</span></div></div>
  222. <div class="viewcode-block" id="PascalVOCAndAUGUnifiedDataset"><a class="viewcode-back" href="../../../../../super_gradients.training.html#super_gradients.training.datasets.PascalVOCAndAUGUnifiedDataset">[docs]</a><span class="k">class</span> <span class="nc">PascalVOCAndAUGUnifiedDataset</span><span class="p">(</span><span class="n">ConcatDataset</span><span class="p">):</span>
  223. <span class="sd">&quot;&quot;&quot;</span>
  224. <span class="sd"> Pascal VOC + AUG train dataset, aka `SBD` dataset contributed in &quot;Semantic contours from inverse detectors&quot;.</span>
  225. <span class="sd"> This is class implement the common usage of the SBD and PascalVOC datasets as a unified augmented trainset.</span>
  226. <span class="sd"> The unified dataset includes a total of 10,582 samples and don&#39;t contains duplicate samples from the PascalVOC</span>
  227. <span class="sd"> validation set.</span>
  228. <span class="sd"> &quot;&quot;&quot;</span>
  229. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
  230. <span class="nb">print</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
  231. <span class="k">if</span> <span class="nb">any</span><span class="p">([</span><span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;list_file&quot;</span><span class="p">),</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;samples_sub_directory&quot;</span><span class="p">),</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;targets_sub_directory&quot;</span><span class="p">)]):</span>
  232. <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span>
  233. <span class="s2">&quot;[list_file, samples_sub_directory, targets_sub_directory] arguments passed will not be used&quot;</span>
  234. <span class="s2">&quot; when passed to `PascalVOCAndAUGUnifiedDataset`. Those values are predefined for initiating&quot;</span>
  235. <span class="s2">&quot; the Pascal VOC + AUG training set.&quot;</span>
  236. <span class="p">)</span>
  237. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
  238. <span class="n">datasets</span><span class="o">=</span><span class="p">[</span>
  239. <span class="n">PascalVOC2012SegmentationDataSet</span><span class="p">(</span>
  240. <span class="n">list_file</span><span class="o">=</span><span class="s2">&quot;VOCdevkit/VOC2012/ImageSets/Segmentation/train.txt&quot;</span><span class="p">,</span>
  241. <span class="n">samples_sub_directory</span><span class="o">=</span><span class="s2">&quot;VOCdevkit/VOC2012/JPEGImages&quot;</span><span class="p">,</span>
  242. <span class="n">targets_sub_directory</span><span class="o">=</span><span class="s2">&quot;VOCdevkit/VOC2012/SegmentationClass&quot;</span><span class="p">,</span>
  243. <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
  244. <span class="p">),</span>
  245. <span class="n">PascalAUG2012SegmentationDataSet</span><span class="p">(</span>
  246. <span class="n">list_file</span><span class="o">=</span><span class="s2">&quot;VOCaug/dataset/aug.txt&quot;</span><span class="p">,</span> <span class="n">samples_sub_directory</span><span class="o">=</span><span class="s2">&quot;VOCaug/dataset/img&quot;</span><span class="p">,</span> <span class="n">targets_sub_directory</span><span class="o">=</span><span class="s2">&quot;VOCaug/dataset/cls&quot;</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span>
  247. <span class="p">),</span>
  248. <span class="p">]</span>
  249. <span class="p">)</span></div>
  250. </pre></div>
  251. </div>
  252. </div>
  253. <footer>
  254. <hr/>
  255. <div role="contentinfo">
  256. <p>&#169; Copyright 2021, SuperGradients team.</p>
  257. </div>
  258. Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
  259. <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
  260. provided by <a href="https://readthedocs.org">Read the Docs</a>.
  261. </footer>
  262. </div>
  263. </div>
  264. </section>
  265. </div>
  266. <script>
  267. jQuery(function () {
  268. SphinxRtdTheme.Navigation.enable(true);
  269. });
  270. </script>
  271. </body>
  272. </html>
Discard
Tip!

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