-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcache.html
318 lines (287 loc) · 16.2 KB
/
cache.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
<!DOCTYPE html>
<html class="writer-html5" lang="en">
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Caching — librosa 0.10.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css?v=76b2166b" />
<link rel="stylesheet" type="text/css" href="_static/plot_directive.css" />
<link rel="stylesheet" type="text/css" href="_static/sg_gallery.css?v=d2d258e8" />
<link rel="stylesheet" type="text/css" href="_static/sg_gallery-binder.css?v=f4aeca0c" />
<link rel="stylesheet" type="text/css" href="_static/sg_gallery-dataframe.css?v=2082cf3c" />
<link rel="stylesheet" type="text/css" href="_static/sg_gallery-rendered-html.css?v=1277b6f3" />
<link rel="stylesheet" type="text/css" href="_static/css/custom.css?v=5e94ddc7" />
<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=69c39844"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=4825356b"></script>
<script src="_static/clipboard.min.js?v=a7894cd8"></script>
<script src="_static/copybutton.js?v=35a8b989"></script>
<script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Advanced I/O Use Cases" href="ioformats.html" />
<link rel="prev" title="librosa.filters.constant_q_lengths" href="generated/librosa.filters.constant_q_lengths.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" style="background: white" >
<a href="index.html">
<img src="_static/librosa_logo_text.svg" class="logo" alt="Logo"/>
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Getting started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation instructions</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="troubleshooting.html">Troubleshooting</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">API documentation</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="core.html">Core IO and DSP</a></li>
<li class="toctree-l1"><a class="reference internal" href="display.html">Display</a></li>
<li class="toctree-l1"><a class="reference internal" href="feature.html">Feature extraction</a></li>
<li class="toctree-l1"><a class="reference internal" href="onset.html">Onset detection</a></li>
<li class="toctree-l1"><a class="reference internal" href="beat.html">Beat and tempo</a></li>
<li class="toctree-l1"><a class="reference internal" href="decompose.html">Spectrogram decomposition</a></li>
<li class="toctree-l1"><a class="reference internal" href="effects.html">Effects</a></li>
<li class="toctree-l1"><a class="reference internal" href="segment.html">Temporal segmentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="sequence.html">Sequential modeling</a></li>
<li class="toctree-l1"><a class="reference internal" href="util.html">Utilities</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Advanced topics</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="multichannel.html">Multi-channel</a></li>
<li class="toctree-l1"><a class="reference internal" href="filters.html">Filters</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Caching</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#enabling-the-cache">Enabling the cache</a></li>
<li class="toctree-l2"><a class="reference internal" href="#cache-configuration">Cache configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="#cache-levels">Cache levels</a></li>
<li class="toctree-l2"><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="ioformats.html">Advanced I/O Use Cases</a></li>
<li class="toctree-l1"><a class="reference internal" href="advanced.html">Advanced examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="recordings.html">Example files</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Changelog</a></li>
<li class="toctree-l1"><a class="reference internal" href="genindex.html">Index</a></li>
<li class="toctree-l1"><a class="reference internal" href="glossary.html">Glossary</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" style="background: white" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">librosa</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">Caching</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/cache.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="caching">
<h1>Caching<a class="headerlink" href="#caching" title="Permalink to this heading"></a></h1>
<p>This section covers the <em>librosa</em> function cache. This allows you
to store and reuse intermediate computations across sessions.</p>
<section id="enabling-the-cache">
<h2>Enabling the cache<a class="headerlink" href="#enabling-the-cache" title="Permalink to this heading"></a></h2>
<p>By default, caching is disabled. To enable caching, the environment
variable <em class="xref py py-obj">LIBROSA_CACHE_DIR</em> must be set prior to loading <em>librosa</em>.
This can be done on the command line prior to instantiating a python interpreter:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ export LIBROSA_CACHE_DIR=/tmp/librosa_cache
$ ipython
</pre></div>
</div>
<p>or from within python, prior to importing <em>librosa</em>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">os</span>
<span class="gp">>>> </span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">'LIBROSA_CACHE_DIR'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'/tmp/librosa_cache'</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">librosa</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>The cache does not implement any eviction policy. As such,
it can grow without bound on disk if not purged.
To purge the cache directly, call:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">librosa</span><span class="o">.</span><span class="n">cache</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
</pre></div>
</div>
</div>
</section>
<section id="cache-configuration">
<h2>Cache configuration<a class="headerlink" href="#cache-configuration" title="Permalink to this heading"></a></h2>
<p>The cache is implemented on top of <a class="reference external" href="https://joblib.readthedocs.io/en/stable/generated/joblib.Memory.html#joblib.Memory" title="(in joblib v1.4.2)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">joblib.Memory</span></code></a>.
The default configuration can be overridden by setting the following environment variables</p>
<blockquote>
<div><ul class="simple">
<li><p><em class="xref py py-obj">LIBROSA_CACHE_DIR</em> : path (on disk) to the cache directory</p></li>
<li><p><em class="xref py py-obj">LIBROSA_CACHE_MMAP</em> : optional memory mapping mode <em class="xref py py-obj">{None, ‘r+’, ‘r’, ‘w+’, ‘c’}</em></p></li>
<li><p><em class="xref py py-obj">LIBROSA_CACHE_COMPRESS</em> : flag to enable compression of data on disk <em class="xref py py-obj">{0, 1}</em></p></li>
<li><p><em class="xref py py-obj">LIBROSA_CACHE_VERBOSE</em> : controls how much debug info is displayed. <em class="xref py py-obj">{int, non-negative}</em></p></li>
<li><p><em class="xref py py-obj">LIBROSA_CACHE_LEVEL</em> : controls the caching level: the larger this value, the more data is cached. <em class="xref py py-obj">{int}</em></p></li>
</ul>
</div></blockquote>
<p>Please refer to the <a class="reference external" href="https://joblib.readthedocs.io/en/stable/generated/joblib.Memory.html#joblib.Memory" title="(in joblib v1.4.2)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">joblib.Memory</span></code></a> documentation for a detailed explanation of these parameters.</p>
<p>As of 0.7, librosa’s cache wraps (rather than extends) the <a class="reference external" href="https://joblib.readthedocs.io/en/stable/generated/joblib.Memory.html#joblib.Memory" title="(in joblib v1.4.2)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">joblib.Memory</span></code></a> object.
The memory object can be directly accessed by <code class="xref py py-obj docutils literal notranslate"><span class="pre">librosa.cache.memory</span></code>.</p>
</section>
<section id="cache-levels">
<h2>Cache levels<a class="headerlink" href="#cache-levels" title="Permalink to this heading"></a></h2>
<p>Cache levels operate in a fashion similar to logging levels.
For small values of <em class="xref py py-obj">LIBROSA_CACHE_LEVEL</em>, only the most important (frequently used) data are cached.
As the cache level increases, broader classes of functions are cached.
As a result, application code may run faster at the expense of larger disk usage.</p>
<p>The caching levels are described as follows:</p>
<blockquote>
<div><ul class="simple">
<li><p>10: filter bases, independent of audio data (mel, chroma, constant-q)</p></li>
<li><p>20: low-level features (cqt, stft, zero-crossings, etc)</p></li>
<li><p>30: high-level features (tempo, beats, decomposition, recurrence, etc)</p></li>
<li><p>40: post-processing (delta, stack_memory, normalize, sync)</p></li>
</ul>
</div></blockquote>
<p>The default cache level is 10.</p>
</section>
<section id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this heading"></a></h2>
<p>To demonstrate how to use the cache, we’ll first call an example script twice without caching:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ time -p ./estimate_tuning.py Kevin_MacLeod_-_Vibe_Ace.ogg
Loading Kevin_MacLeod_-_Vibe_Ace.ogg
Separating harmonic component ...
Estimating tuning ...
+9.00 cents
real 6.74
user 6.03
sys 1.09
$ time -p ./estimate_tuning.py Kevin_MacLeod_-_Vibe_Ace.ogg
Loading Kevin_MacLeod_-_Vibe_Ace.ogg
Separating harmonic component ...
Estimating tuning ...
+9.00 cents
real 6.68
user 6.04
sys 1.05
</pre></div>
</div>
<p>Next, we’ll enable caching to <em class="xref py py-obj">/tmp/librosa</em>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ export LIBROSA_CACHE_DIR=/tmp/librosa
</pre></div>
</div>
<p>and set the cache level to 50:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ export LIBROSA_CACHE_LEVEL=50
</pre></div>
</div>
<p>And now we’ll re-run the example script twice. The first time, there will be no cached values, so the time
should be similar to running without cache. The second time, we’ll be able to reuse intermediate values, so
it should be significantly faster.:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ time -p ./estimate_tuning.py Kevin_MacLeod_-_Vibe_Ace.ogg
Loading Kevin_MacLeod_-_Vibe_Ace.ogg
Separating harmonic component ...
Estimating tuning ...
+9.00 cents
real 7.60
user 6.79
sys 1.15
$ time -p ./estimate_tuning.py Kevin_MacLeod_-_Vibe_Ace.ogg
Loading Kevin_MacLeod_-_Vibe_Ace.ogg
Separating harmonic component ...
Estimating tuning ...
+9.00 cents
real 1.64
user 1.30
sys 0.74
</pre></div>
</div>
<p>Reducing the cache level to 20 yields an intermediate acceleration:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ export LIBROSA_CACHE_LEVEL=20
$ time -p ./estimate_tuning.py Kevin_MacLeod_-_Vibe_Ace.ogg
Loading Kevin_MacLeod_-_Vibe_Ace.ogg
Separating harmonic component ...
Estimating tuning ...
+9.00 cents
real 4.98
user 4.17
sys 1.22
</pre></div>
</div>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="generated/librosa.filters.constant_q_lengths.html" class="btn btn-neutral float-left" title="librosa.filters.constant_q_lengths" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="ioformats.html" class="btn btn-neutral float-right" title="Advanced I/O Use Cases" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>© Copyright 2013--2023, librosa development team.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span class="fa fa-book"> Other Versions</span>
v: 0.10.2
<span class="fa fa-caret-down"></span>
</span>
<div class="rst-other-versions">
<dl>
<dt>Releases</dt>
<dd><a href="../0.10.0/cache.html">0.10.0</a></dd>
<dd><a href="../0.10.1/cache.html">0.10.1</a></dd>
<dd><a href="cache.html">0.10.2</a></dd>
<dd><a href="../0.8.1/cache.html">0.8.1</a></dd>
<dd><a href="../0.9.2/cache.html">0.9.2</a></dd>
</dl>
<dl>
<dt>Development versions</dt>
<dd><a href="../main/cache.html">main</a></dd>
</dl>
</div>
</div><script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
<!-- Theme Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-171031946-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-171031946-1', {
'anonymize_ip': false,
});
</script>
</body>
</html>