Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
postpop committed Mar 9, 2024
1 parent f0cfcf9 commit 9d2a994
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
11 changes: 9 additions & 2 deletions _modules/das/predict.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ <h1>Source code for das.predict</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;Code for training and evaluating networks.&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">import</span> <span class="nn">flammkuchen</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">utils</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">models</span><span class="p">,</span> <span class="n">event_utils</span><span class="p">,</span> <span class="n">segment_utils</span><span class="p">,</span> <span class="n">annot</span>
Expand Down Expand Up @@ -320,6 +321,7 @@ <h1>Source code for das.predict</h1><div class="highlight"><pre>
<span class="n">class_probabilities</span> <span class="o">=</span> <span class="n">zarr</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span>
<span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">params</span><span class="p">[</span><span class="s2">&quot;nb_classes&quot;</span><span class="p">]),</span> <span class="n">chunks</span><span class="o">=</span><span class="p">(</span><span class="mi">100_000</span><span class="p">,</span> <span class="n">params</span><span class="p">[</span><span class="s2">&quot;nb_classes&quot;</span><span class="p">]),</span> <span class="n">dtype</span><span class="o">=</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="n">store</span><span class="o">=</span><span class="n">temp_store</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">True</span>
<span class="p">)</span>

<span class="c1"># predict and unpack batch by batch to memmaped np or zarr array</span>
<span class="k">for</span> <span class="n">batch_number</span><span class="p">,</span> <span class="n">batch_data</span> <span class="ow">in</span> <span class="n">tqdm</span><span class="p">(</span><span class="nb">enumerate</span><span class="p">(</span><span class="n">pred_gen</span><span class="p">),</span> <span class="n">total</span><span class="o">=</span><span class="n">nb_batches</span><span class="p">,</span> <span class="n">disable</span><span class="o">=</span><span class="n">verbose</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">y_pred_batch</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict_on_batch</span><span class="p">(</span><span class="n">batch_data</span><span class="p">)</span> <span class="c1"># run the network</span>
Expand All @@ -341,6 +343,7 @@ <h1>Source code for das.predict</h1><div class="highlight"><pre>

<span class="n">class_probabilities</span> <span class="o">=</span> <span class="n">da</span><span class="o">.</span><span class="n">from_zarr</span><span class="p">(</span><span class="n">class_probabilities</span><span class="p">,</span> <span class="n">inline_array</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">class_probabilities</span> <span class="o">=</span> <span class="n">class_probabilities</span><span class="o">.</span><span class="n">rechunk</span><span class="p">((</span><span class="mi">1_000_000</span><span class="p">,</span> <span class="n">params</span><span class="p">[</span><span class="s2">&quot;nb_classes&quot;</span><span class="p">]))</span>
<span class="n">class_probabilities</span><span class="o">.</span><span class="n">temp_dir</span> <span class="o">=</span> <span class="n">temp_store</span><span class="o">.</span><span class="n">dir_path</span><span class="p">()</span> <span class="c1"># save path to temp store so we can explicitly delete it</span>
<span class="k">return</span> <span class="n">class_probabilities</span></div>


Expand Down Expand Up @@ -787,7 +790,7 @@ <h1>Source code for das.predict</h1><div class="highlight"><pre>
<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="n">pad_len</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span> <span class="n">mode</span><span class="o">=</span><span class="s2">&quot;edge&quot;</span><span class="p">)</span>

<span class="n">class_probabilities</span> <span class="o">=</span> <span class="n">predict_probabilities</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="n">verbose</span><span class="p">,</span> <span class="n">prepend_data_padding</span><span class="p">)</span>

<span class="n">temp_dir</span> <span class="o">=</span> <span class="n">class_probabilities</span><span class="o">.</span><span class="n">temp_dir</span>
<span class="k">if</span> <span class="n">pad</span><span class="p">:</span>
<span class="c1"># set all song probs in padded section to zero to avoid out of bounds detections!</span>
<span class="c1"># assumes that the non-song class is at index 0</span>
Expand All @@ -813,6 +816,7 @@ <h1>Source code for das.predict</h1><div class="highlight"><pre>
<span class="n">segments</span><span class="p">[</span><span class="s2">&quot;probabilities&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">_to_np</span><span class="p">(</span><span class="n">segments</span><span class="p">[</span><span class="s2">&quot;probabilities&quot;</span><span class="p">])</span>
<span class="n">segments</span><span class="p">[</span><span class="s2">&quot;samples&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">_to_np</span><span class="p">(</span><span class="n">segments</span><span class="p">[</span><span class="s2">&quot;samples&quot;</span><span class="p">])</span>
<span class="n">class_probabilities</span> <span class="o">=</span> <span class="n">_to_np</span><span class="p">(</span><span class="n">class_probabilities</span><span class="p">)</span>
<span class="n">class_probabilities</span><span class="o">.</span><span class="n">temp_dir</span> <span class="o">=</span> <span class="n">temp_dir</span>
<span class="k">return</span> <span class="n">events</span><span class="p">,</span> <span class="n">segments</span><span class="p">,</span> <span class="n">class_probabilities</span><span class="p">,</span> <span class="n">params</span><span class="p">[</span><span class="s2">&quot;class_names&quot;</span><span class="p">]</span></div>


Expand Down Expand Up @@ -971,8 +975,11 @@ <h1>Source code for das.predict</h1><div class="highlight"><pre>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Saving results to </span><span class="si">{</span><span class="n">save_filename</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="n">evt</span><span class="o">.</span><span class="n">to_df</span><span class="p">()</span><span class="o">.</span><span class="n">to_csv</span><span class="p">(</span><span class="n">save_filename</span><span class="p">)</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Done.&quot;</span><span class="p">)</span>

<span class="c1"># reset</span>
<span class="n">temp_dir</span> <span class="o">=</span> <span class="n">class_probabilities</span><span class="o">.</span><span class="n">temp_dir</span>
<span class="k">del</span> <span class="n">class_probabilities</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">temp_dir</span><span class="p">,</span> <span class="n">ignore_errors</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</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">temp_dir</span><span class="p">))</span>
<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">isdir</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="n">save_filename</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
Expand Down
6 changes: 2 additions & 4 deletions _sources/installation.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

_Anaconda python_: Install the [anaconda python distribution](https://docs.anaconda.com/anaconda/install/) (or [miniconda](https://docs.conda.io/en/latest/miniconda.html)). If conda is already installed on your system, make sure you have conda v4.8.4+. If not, update from an older version with `conda update conda`.

<!-- _CUDA libraries for using the GPU_: While _DAS_ works on a standard desktop CPU, a dedicated GPU will greatly improve annotation speed and is highly recommended for training. _DAS_ uses Tensorflow as a deep-learning backend. To ensure that Tensorflow can utilize the GPU, the CUDA and cuDNN libraries need to be installed. See the [tensorflow docs](https://www.tensorflow.org/install/gpu) for details. -->

_Libsoundfile (Linux only)_: If you are on Linux and want to load audio from a wide range of audio formats (other than `wav`), then you need to install `libsndfile`. The GUI uses the [soundfile](http://pysoundfile.readthedocs.io/) python package, which relies on `libsndfile`. `libsndfile` will be automatically installed on Windows and macOS. On Linux, the library needs to be installed manually with: `sudo apt-get install libsndfile1`. Again, this is only required if you work with more exotic audio files.

_Visual C++ runtime (Windows only)_: This is typically installed so only required if _DAS_ fails to load the native tensorflow runtime. Download the latest version [here](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads).
Expand All @@ -16,13 +14,13 @@ Create an anaconda environment called `das` that contains all the required packa
On windows
```shell
conda install mamba -c conda-forge -n base -y
mamba create python=3.9 das=0.32.0 "numpy<1.24" -c conda-forge -c ncb -c anaconda -c nvidia -n das -y
mamba create python=3.9 das=0.32.1 "numpy<1.24" -c conda-forge -c ncb -c anaconda -c nvidia -n das -y
```

On Linux or MacOS (intel and arm):
```shell
conda install mamba -c conda-forge -n base -y
mamba create python=3.10 das=0.32.0 -c conda-forge -c ncb -c anaconda -c nvidia -c apple -n das -y
mamba create python=3.10 das=0.32.1 -c conda-forge -c ncb -c anaconda -c nvidia -c apple -n das -y
```


Expand Down
5 changes: 2 additions & 3 deletions installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ <h1>Installation<a class="headerlink" href="#installation" title="Permalink to t
<section id="pre-requisites">
<h2>Pre-requisites<a class="headerlink" href="#pre-requisites" title="Permalink to this headline">#</a></h2>
<p><em>Anaconda python</em>: Install the <a class="reference external" href="https://docs.anaconda.com/anaconda/install/">anaconda python distribution</a> (or <a class="reference external" href="https://docs.conda.io/en/latest/miniconda.html">miniconda</a>). If conda is already installed on your system, make sure you have conda v4.8.4+. If not, update from an older version with <code class="docutils literal notranslate"><span class="pre">conda</span> <span class="pre">update</span> <span class="pre">conda</span></code>.</p>
<!-- _CUDA libraries for using the GPU_: While _DAS_ works on a standard desktop CPU, a dedicated GPU will greatly improve annotation speed and is highly recommended for training. _DAS_ uses Tensorflow as a deep-learning backend. To ensure that Tensorflow can utilize the GPU, the CUDA and cuDNN libraries need to be installed. See the [tensorflow docs](https://www.tensorflow.org/install/gpu) for details. -->
<p><em>Libsoundfile (Linux only)</em>: If you are on Linux and want to load audio from a wide range of audio formats (other than <code class="docutils literal notranslate"><span class="pre">wav</span></code>), then you need to install <code class="docutils literal notranslate"><span class="pre">libsndfile</span></code>. The GUI uses the <a class="reference external" href="http://pysoundfile.readthedocs.io/">soundfile</a> python package, which relies on <code class="docutils literal notranslate"><span class="pre">libsndfile</span></code>. <code class="docutils literal notranslate"><span class="pre">libsndfile</span></code> will be automatically installed on Windows and macOS. On Linux, the library needs to be installed manually with: <code class="docutils literal notranslate"><span class="pre">sudo</span> <span class="pre">apt-get</span> <span class="pre">install</span> <span class="pre">libsndfile1</span></code>. Again, this is only required if you work with more exotic audio files.</p>
<p><em>Visual C++ runtime (Windows only)</em>: This is typically installed so only required if <em>DAS</em> fails to load the native tensorflow runtime. Download the latest version <a class="reference external" href="https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads">here</a>.</p>
</section>
Expand All @@ -285,12 +284,12 @@ <h2>Install <em>DAS</em><a class="headerlink" href="#install-das" title="Permali
<p>Create an anaconda environment called <code class="docutils literal notranslate"><span class="pre">das</span></code> that contains all the required packages.</p>
<p>On windows</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>conda install mamba -c conda-forge -n base -y
mamba create <span class="nv">python</span><span class="o">=</span><span class="m">3</span>.9 <span class="nv">das</span><span class="o">=</span><span class="m">0</span>.32.0 <span class="s2">&quot;numpy&lt;1.24&quot;</span> -c conda-forge -c ncb -c anaconda -c nvidia -n das -y
mamba create <span class="nv">python</span><span class="o">=</span><span class="m">3</span>.9 <span class="nv">das</span><span class="o">=</span><span class="m">0</span>.32.1 <span class="s2">&quot;numpy&lt;1.24&quot;</span> -c conda-forge -c ncb -c anaconda -c nvidia -n das -y
</pre></div>
</div>
<p>On Linux or MacOS (intel and arm):</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>conda install mamba -c conda-forge -n base -y
mamba create <span class="nv">python</span><span class="o">=</span><span class="m">3</span>.10 <span class="nv">das</span><span class="o">=</span><span class="m">0</span>.32.0 -c conda-forge -c ncb -c anaconda -c nvidia -c apple -n das -y
mamba create <span class="nv">python</span><span class="o">=</span><span class="m">3</span>.10 <span class="nv">das</span><span class="o">=</span><span class="m">0</span>.32.1 -c conda-forge -c ncb -c anaconda -c nvidia -c apple -n das -y
</pre></div>
</div>
</section>
Expand Down

0 comments on commit 9d2a994

Please sign in to comment.