-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.html
670 lines (461 loc) · 31.6 KB
/
utils.html
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
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1"><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Utilities</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/theme.css " type="text/css" />
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
<link rel="stylesheet" href="_static/css/waveform-list.css" type="text/css" />
<!-- sphinx script_files -->
<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>
<!-- bundled in js (rollup iife) -->
<!-- <script src="_static/theme-vendors.js"></script> -->
<script src="_static/theme.js" defer></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="Constants" href="constants.html" />
</head>
<body>
<div id="app">
<div class="theme-container" :class="pageClasses"><navbar @toggle-sidebar="toggleSidebar">
<router-link to="index.html" class="home-link">
<span class="site-name">omnizart</span>
</router-link>
<div class="links">
<navlinks class="can-hide">
<div class="nav-item">
<a href="index.html#sound-samples"
class="nav-link ">
Contents
</a>
</div>
<div class="nav-item">
<a href="index.html#sound-samples"
class="nav-link ">
Command Line Interface
</a>
</div>
<div class="nav-item">
<a href="index.html#sound-samples"
class="nav-link router-link-active">
API Reference
</a>
</div>
</navlinks>
</div>
</navbar>
<div class="sidebar-mask" @click="toggleSidebar(false)">
</div>
<sidebar @toggle-sidebar="toggleSidebar">
<navlinks>
<div class="nav-item">
<a href="index.html#sound-samples"
class="nav-link ">
Contents
</a>
</div>
<div class="nav-item">
<a href="index.html#sound-samples"
class="nav-link ">
Command Line Interface
</a>
</div>
<div class="nav-item">
<a href="index.html#sound-samples"
class="nav-link router-link-active">
API Reference
</a>
</div>
</navlinks><div id="searchbox" class="searchbox" role="search">
<div class="caption"><span class="caption-text">Quick search</span>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</div><div class="sidebar-links" role="navigation" aria-label="main navigation">
<div class="sidebar-group">
<p class="caption">
<span class="caption-text"><a href="index.html#sound-samples">Contents</a></span>
</p>
<ul class="">
<li class="toctree-l1 ">
<a href="quick-start.html" class="reference internal ">Quick Start</a>
</li>
<li class="toctree-l1 ">
<a href="tutorial.html" class="reference internal ">Tutorial</a>
</li>
<li class="toctree-l1 ">
<a href="demo.html" class="reference internal ">Demonstration</a>
</li>
</ul>
</div>
<div class="sidebar-group">
<p class="caption">
<span class="caption-text"><a href="index.html#sound-samples">Command Line Interface</a></span>
</p>
<ul class="">
<li class="toctree-l1 ">
<a href="music/cli.html" class="reference internal ">omnizart music</a>
</li>
<li class="toctree-l1 ">
<a href="drum/cli.html" class="reference internal ">omnizart drum</a>
</li>
<li class="toctree-l1 ">
<a href="chord/cli.html" class="reference internal ">omnizart chord</a>
</li>
<li class="toctree-l1 ">
<a href="vocal/cli.html" class="reference internal ">omnizart vocal</a>
</li>
<li class="toctree-l1 ">
<a href="vocal-contour/cli.html" class="reference internal ">omnizart vocal-contour</a>
</li>
<li class="toctree-l1 ">
<a href="beat/cli.html" class="reference internal ">omnizart beat</a>
</li>
<li class="toctree-l1 ">
<a href="patch-cnn/cli.html" class="reference internal ">omnizart patch-cnn</a>
</li>
</ul>
</div>
<div class="sidebar-group">
<p class="caption">
<span class="caption-text"><a href="index.html#sound-samples">API Reference</a></span>
</p>
<ul class="current">
<li class="toctree-l1 ">
<a href="music/api.html" class="reference internal ">Music Transcription</a>
</li>
<li class="toctree-l1 ">
<a href="drum/api.html" class="reference internal ">Drum Transcription</a>
</li>
<li class="toctree-l1 ">
<a href="chord/api.html" class="reference internal ">Chord Transcription</a>
</li>
<li class="toctree-l1 ">
<a href="vocal/api.html" class="reference internal ">Vocal Transcription</a>
</li>
<li class="toctree-l1 ">
<a href="vocal-contour/api.html" class="reference internal ">Vocal-Contour Transcription</a>
</li>
<li class="toctree-l1 ">
<a href="patch-cnn/api.html" class="reference internal ">Patch-CNN Transcription</a>
</li>
<li class="toctree-l1 ">
<a href="beat/api.html" class="reference internal ">Beat Transcription</a>
</li>
<li class="toctree-l1 ">
<a href="feature.html" class="reference internal ">Feature</a>
</li>
<li class="toctree-l1 ">
<a href="models.html" class="reference internal ">Models</a>
</li>
<li class="toctree-l1 ">
<a href="training.html" class="reference internal ">Training</a>
</li>
<li class="toctree-l1 ">
<a href="base.html" class="reference internal ">Base Classes</a>
</li>
<li class="toctree-l1 ">
<a href="constants.html" class="reference internal ">Constants</a>
</li>
<li class="toctree-l1 current">
<a href="#" class="reference internal current">Utilities</a>
<ul>
<li class="toctree-l2"><a href="#module-omnizart.remote" class="reference internal">Remote</a></li>
<li class="toctree-l2"><a href="#module-omnizart.utils" class="reference internal">Utility Functions</a></li>
</ul>
</li>
</ul>
</div>
</div>
</sidebar>
<page>
<div class="body-header" role="navigation" aria-label="navigation">
<ul class="breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Utilities</li>
</ul>
<ul class="page-nav">
<li class="prev">
<a href="constants.html"
title="previous chapter">← Constants</a>
</li>
</ul>
</div>
<hr>
<div class="content" role="main" v-pre>
<section id="utilities">
<h1>Utilities<a class="headerlink" href="#utilities" title="Permalink to this headline">¶</a></h1>
<p>Some common utility functions.</p>
<section id="module-omnizart.remote">
<span id="remote"></span><h2>Remote<a class="headerlink" href="#module-omnizart.remote" title="Permalink to this headline">¶</a></h2>
<p>Functions related to networking.</p>
<p>Containing functions to download files from the internet. Supports
download <em>zipped</em> files from Google Drive.</p>
<dl class="py exception">
<dt class="sig sig-object py" id="omnizart.remote.GDFileAccessLimited">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">omnizart.remote.</span></span><span class="sig-name descname"><span class="pre">GDFileAccessLimited</span></span><a class="headerlink" href="#omnizart.remote.GDFileAccessLimited" title="Permalink to this definition">¶</a></dt>
<dd><p>Custom exception on failing to download GD file.</p>
<p>This exception is raised when the GD file is overly accessed during a certain
period.</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="omnizart.remote.SIZE_MAPPING">
<span class="sig-prename descclassname"><span class="pre">omnizart.remote.</span></span><span class="sig-name descname"><span class="pre">SIZE_MAPPING</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">[(1,</span> <span class="pre">'B'),</span> <span class="pre">(1024,</span> <span class="pre">'KB'),</span> <span class="pre">(1048576,</span> <span class="pre">'MB'),</span> <span class="pre">(1073741824,</span> <span class="pre">'GB'),</span> <span class="pre">(1099511627776,</span> <span class="pre">'TB')]</span></em><a class="headerlink" href="#omnizart.remote.SIZE_MAPPING" title="Permalink to this definition">¶</a></dt>
<dd><p>Mapping bytes to human-readable size unit.</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.remote.download">
<span class="sig-prename descclassname"><span class="pre">omnizart.remote.</span></span><span class="sig-name descname"><span class="pre">download</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file_length</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">save_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'./'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">save_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cookie_file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">unzip</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.remote.download" title="Permalink to this definition">¶</a></dt>
<dd><p>Download file from the internet.</p>
<p>Download file from the remote URL, with progress visualization and dynamic downloading
rate adjustment. Uses pure python built-in packages, no additional package requirement.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>url: URL</strong></dt><dd><p>The file download url.</p>
</dd>
<dt><strong>file_length: float</strong></dt><dd><p>In bytes. If the length can’t be retrieved from the response header, but can be
obtained by other approaches, you can explicitly specify the length for progress
visualization.</p>
</dd>
<dt><strong>save_path: Path</strong></dt><dd><p>The path to store the donwloaded file.</p>
</dd>
<dt><strong>save_name: str</strong></dt><dd><p>Explicitly specify the file name to be stored. If not given, default to parse the
name from the given url.</p>
</dd>
<dt><strong>cookie_file: Path</strong></dt><dd><p>Path to the cookie file. Suitable for stateful download (e.g. Google Drive).</p>
</dd>
<dt><strong>unzip: bool</strong></dt><dd><p>Whether to unzip (decompress) the downloaded file (assumed zipped). Will not delete
the original downloaded file.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt>path: Path</dt><dd><p>The absolute path to the downloaded/extracted folder/file.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.remote.download_large_file_from_google_drive">
<span class="sig-prename descclassname"><span class="pre">omnizart.remote.</span></span><span class="sig-name descname"><span class="pre">download_large_file_from_google_drive</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file_length</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">save_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'./'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">save_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">unzip</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.remote.download_large_file_from_google_drive" title="Permalink to this definition">¶</a></dt>
<dd><p>Google Drive file downloader.</p>
<p>Download function dedicated for Google Drive files. Mainly to deal with download
large files and the confirmation page.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>url: URL</strong></dt><dd><p>Could be a full google drive download url or the file ID.</p>
</dd>
<dt><strong>file_length: float</strong></dt><dd><p>In bytes. If the length can’t be retrieved from the response header, but can be
obtained by other approaches, you can explicitly specify the length for progress
visualization.</p>
</dd>
<dt><strong>save_path: Path</strong></dt><dd><p>Path to store the downloaded file.</p>
</dd>
<dt><strong>save_name: str</strong></dt><dd><p>Explicitly specify the file name to be stored. If not given, default to parse the
name from the given url.</p>
</dd>
<dt><strong>unzip: bool</strong></dt><dd><p>Whether to unzip (decompress) the downloaded file (assumed zipped). Will not delete
the original downloaded file.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt>path: Path</dt><dd><p>The absolute path to the downloaded/extracted folder/file.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.remote.format_byte">
<span class="sig-prename descclassname"><span class="pre">omnizart.remote.</span></span><span class="sig-name descname"><span class="pre">format_byte</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">digit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.remote.format_byte" title="Permalink to this definition">¶</a></dt>
<dd><p>Format the given byte size into human-readable string.</p>
</dd></dl>
</section>
<section id="module-omnizart.utils">
<span id="utility-functions"></span><h2>Utility Functions<a class="headerlink" href="#module-omnizart.utils" title="Permalink to this headline">¶</a></h2>
<p>Various utility functions for this project.</p>
<dl class="py class">
<dt class="sig sig-object py" id="omnizart.utils.LazyLoader">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">LazyLoader</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">local_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parent_module_globals</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warning</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.LazyLoader" title="Permalink to this definition">¶</a></dt>
<dd><p>Lazily import a module, mainly to avoid pulling in large dependencies.</p>
<p>Original implementations are from tensorflow <a class="reference internal" href="#r4293d5747efb-1" id="id1">[1]</a>.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r4293d5747efb-1"><span class="brackets"><a class="fn-backref" href="#id1">1</a></span></dt>
<dd><p><a class="reference external" href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/util/lazy_loader.py">https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/util/lazy_loader.py</a></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.aggregate_f0_info">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">aggregate_f0_info</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pred</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">t_unit</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.aggregate_f0_info" title="Permalink to this definition">¶</a></dt>
<dd><p>Aggregation function of F0 contour.</p>
<p>Aggregate the repeated frequencies in continuous frames into higher-level
representation, with information of start time, end time, and frequency.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>pred: 1D numpy array</strong></dt><dd><p>Array that contains F0 information (Hz) in frame-level.</p>
</dd>
<dt><strong>t_unit: float</strong></dt><dd><p>Time unit of each frame.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt>agg_f0: list[dict]</dt><dd><p>Aggregated F0 information. Each element in the list represents
a single freqeuncy with start time, end time, and frequency
recorded in <em>dict</em>.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.camel_to_snake">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">camel_to_snake</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.camel_to_snake" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a camel case to snake case</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.ensure_path_exists">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">ensure_path_exists</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.ensure_path_exists" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.get_filename">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">get_filename</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.get_filename" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.get_logger">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">get_logger</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">level</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'warn'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.get_logger" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the logger for printing informations.</p>
<p>Used for layout the information of various stages while executing the program.
Set the environment variable <code class="docutils literal notranslate"><span class="pre">LOG_LEVEL</span></code> to change the default level.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>name: str</strong></dt><dd><p>Name of the logger.</p>
</dd>
<dt><strong>level: {‘debug’, ‘info’, ‘warn’, ‘warning’, ‘error’, ‘critical’}</strong></dt><dd><p>Level of the logger. The level ‘warn’ and ‘warning’ are different. The former
is the default level and the actual level is set to logging.INFO, and for
‘warning’ which will be set to true logging.WARN level. The purpose behind this
design is to categorize the message layout into several different formats.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.json_serializable">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">json_serializable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'./'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'./'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.json_serializable" title="Permalink to this definition">¶</a></dt>
<dd><p>Class-level decorator for making a class json-serializable object.</p>
<p>This decorator makes a class serializable as a json object. All attributes
will be outputed as a key-value pair recursively if there are also attributes
that is type of json-serializable class.
Inject two functions to the decorated class: from_json, to_json.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>key_path: Path</strong></dt><dd><p>Access sub-object according to the path. E.g. Assume you have a
dictionary: d = {“a”: {“b”: {“c”: “d”}}}, and the path: p = “a/b”,
then the sub-object after being propagated would be {“c”: “d”}.</p>
</dd>
<dt><strong>value_path: Path</strong></dt><dd><p>The relative path to the key_path. This parameter makes you able
to access the value that is not at the same level as the key.
E.g. assume you have a sub-object after the propagation of key_path:
d = {“a”: {“b”: {“c”: “d”}}}, and the value_path: vp = “a/b/c”,
the corresponding value of the key should be “d”.</p>
</dd>
</dl>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><code class="xref py py-obj docutils literal notranslate"><span class="pre">tests.test_utils.test_normal_serializable</span></code></dt><dd><p>Unit test of this decorator.</p>
</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>The attributes should be defined inside ‘__init__’, or those defined as
class attributes will not be serialized as thery are invisible for
__dict__ attribute.</p>
<p class="rubric">Examples</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nd">@json_serializable</span><span class="p">()</span>
<span class="go"> class A:</span>
<span class="go"> def __init__(self):</span>
<span class="go"> self.a = 1</span>
<span class="go"> self.b = "Hello"</span>
<span class="go"> self.c = [10, 20, 30]</span>
<span class="go"> @json_serializable()</span>
<span class="go"> class B:</span>
<span class="go"> def __init__(self):</span>
<span class="go"> self.a_instance = A()</span>
<span class="go"> self.d = "World"</span>
<span class="gp">>>> </span><span class="n">inst</span> <span class="o">=</span> <span class="n">B</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">inst</span><span class="o">.</span><span class="n">to_json</span><span class="p">()</span>
<span class="go">{</span>
<span class="go"> "d": "World",</span>
<span class="go"> "a_instance": {</span>
<span class="go"> "a": 1,</span>
<span class="go"> "b": "Hello",</span>
<span class="go"> "c": [10, 20, 30]</span>
<span class="go"> }</span>
<span class="go">}</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.parallel_generator">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">parallel_generator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">input_list</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_workers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_thread</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">chunk_size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">600</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.parallel_generator" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.resolve_dataset_type">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">resolve_dataset_type</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dataset_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">keywords</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.resolve_dataset_type" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.snake_to_camel">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">snake_to_camel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.snake_to_camel" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a snake case to camel case</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="omnizart.utils.synth_midi">
<span class="sig-prename descclassname"><span class="pre">omnizart.utils.</span></span><span class="sig-name descname"><span class="pre">synth_midi</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">midi_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sampling_rate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">44100</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sf2_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'/home/runner/work/omnizart/omnizart/omnizart/resource/soundfonts.sf2'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#omnizart.utils.synth_midi" title="Permalink to this definition">¶</a></dt>
<dd><p>Synthesize MIDI into wav audio.</p>
</dd></dl>
</section>
</section>
</div>
<div class="page-nav">
<div class="inner"><ul class="page-nav">
<li class="prev">
<a href="constants.html"
title="previous chapter">← Constants</a>
</li>
</ul><div class="footer" role="contentinfo">
© Copyright 2020, MCTLab.
<br>
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 4.3.1 with <a href="https://github.com/schettino72/sphinx_press_theme">Press Theme</a> 0.8.0.
</div>
</div>
</div>
</page>
</div></div>
</body>
</html>