Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
Allard Hendriksen committed Jul 30, 2019
1 parent cd6848c commit ac801f7
Showing 20 changed files with 760 additions and 39 deletions.
8 changes: 8 additions & 0 deletions doc_sources/msd_pytorch.rst
Original file line number Diff line number Diff line change
@@ -52,6 +52,14 @@ msd\_pytorch.main module
:undoc-members:
:show-inheritance:

msd\_pytorch.msd\_block module
------------------------------

.. automodule:: msd_pytorch.msd_block
:members:
:undoc-members:
:show-inheritance:

msd\_pytorch.msd\_model module
------------------------------

41 changes: 35 additions & 6 deletions docs/CHANGELOG.html
Original file line number Diff line number Diff line change
@@ -87,10 +87,16 @@
<li class="toctree-l2"><a class="reference internal" href="#unreleased">Unreleased</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#added">Added</a></li>
<li class="toctree-l3"><a class="reference internal" href="#fixed">Fixed</a></li>
<li class="toctree-l3"><a class="reference internal" href="#removed">Removed</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id1">0.6.2 - 2019-05-23</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#id1">0.7.1 - 2019-05-27</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id2">Added</a></li>
<li class="toctree-l3"><a class="reference internal" href="#changed">Changed</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id3">0.6.2 - 2019-05-23</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id4">Added</a></li>
</ul>
</li>
</ul>
@@ -168,22 +174,45 @@ <h1>Changelog<a class="headerlink" href="#changelog" title="Permalink to this he
<h2><a class="reference external" href="https://www.github.com/ahendriksen/msd_pytorch/compare/v0.6.2...master">Unreleased</a><a class="headerlink" href="#unreleased" title="Permalink to this headline"></a></h2>
<div class="section" id="added">
<h3>Added<a class="headerlink" href="#added" title="Permalink to this headline"></a></h3>
<ul>
<li><div class="first"><insert-features-not-in-a-release-yet></div></li>
<ul class="simple">
<li>Support for multi-gpu execution. Use <code class="docutils literal notranslate"><span class="pre">parallel=True</span></code> when
constructing a <code class="docutils literal notranslate"><span class="pre">MSDRegressionModel</span></code> or <code class="docutils literal notranslate"><span class="pre">MSDSegmentationModel</span></code>.</li>
</ul>
</div>
<div class="section" id="fixed">
<h3>Fixed<a class="headerlink" href="#fixed" title="Permalink to this headline"></a></h3>
<ul>
<li><div class="first"><insert-bugs-fixed-not-in-a-release-yet></div></li>
<ul class="simple">
<li>Make <code class="docutils literal notranslate"><span class="pre">model.forward()</span></code> more memory-efficient.</li>
</ul>
</div>
<div class="section" id="removed">
<h3>Removed<a class="headerlink" href="#removed" title="Permalink to this headline"></a></h3>
</div>
</div>
<div class="section" id="id1">
<h2>0.6.2 - 2019-05-23<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h2>
<h2><a class="reference external" href="https://www.github.com/ahendriksen/msd_pytorch/compare/v0.6.2...v0.7.1">0.7.1</a> - 2019-05-27<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h2>
<div class="section" id="id2">
<h3>Added<a class="headerlink" href="#id2" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li>Add <code class="docutils literal notranslate"><span class="pre">weights_path</span></code> command-line argument to msd executable to indicate
where to store final weights.</li>
<li>Add <code class="docutils literal notranslate"><span class="pre">MSDBlock2d</span></code>: this is a faster and slightly more memory efficient
implementation of the same MSD component. Many thanks to Jonas
Adler for suggesting this way of structuring the code!</li>
</ul>
</div>
<div class="section" id="changed">
<h3>Changed<a class="headerlink" href="#changed" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li>The MSD models use <code class="docutils literal notranslate"><span class="pre">MSDBlock2d</span></code> implementation by default now.</li>
</ul>
</div>
</div>
<div class="section" id="id3">
<h2>0.6.2 - 2019-05-23<a class="headerlink" href="#id3" title="Permalink to this headline"></a></h2>
<div class="section" id="id4">
<h3>Added<a class="headerlink" href="#id4" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li>Initial release.</li>
</ul>
</div>
1 change: 1 addition & 0 deletions docs/README.html
Original file line number Diff line number Diff line change
@@ -280,6 +280,7 @@ <h3>Running the examples<a class="headerlink" href="#running-the-examples" title
<h2>Authors and contributors<a class="headerlink" href="#authors-and-contributors" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><strong>Allard Hendriksen</strong> - <em>Initial work</em></li>
<li><strong>Jonas Adler</strong> - <em>Discussions and code</em></li>
</ul>
<p>See also the list of <a class="reference external" href="https://github.com/ahendriksen/msd_pytorch/contributors">contributors</a> who participated in this project.</p>
</div>
1 change: 1 addition & 0 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
@@ -150,6 +150,7 @@ <h1>All modules for which code is available</h1>
<li><a href="msd_pytorch/errors.html">msd_pytorch.errors</a></li>
<li><a href="msd_pytorch/image_dataset.html">msd_pytorch.image_dataset</a></li>
<li><a href="msd_pytorch/main.html">msd_pytorch.main</a></li>
<li><a href="msd_pytorch/msd_block.html">msd_pytorch.msd_block</a></li>
<li><a href="msd_pytorch/msd_model.html">msd_pytorch.msd_model</a></li>
<li><a href="msd_pytorch/msd_module.html">msd_pytorch.msd_module</a></li>
<li><a href="msd_pytorch/msd_regression_model.html">msd_pytorch.msd_regression_model</a></li>
24 changes: 17 additions & 7 deletions docs/_modules/msd_pytorch/main.html
Original file line number Diff line number Diff line change
@@ -157,6 +157,7 @@ <h1>Source code for msd_pytorch.main</h1><div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">torch.nn</span> <span class="k">import</span> <span class="n">MSELoss</span>
<span class="kn">import</span> <span class="nn">msd_pytorch</span> <span class="k">as</span> <span class="nn">mp</span>
<span class="kn">from</span> <span class="nn">.bench</span> <span class="k">import</span> <span class="n">bench</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="k">import</span> <span class="n">Path</span>

<span class="n">msd_ingredient</span> <span class="o">=</span> <span class="n">Ingredient</span><span class="p">(</span><span class="s2">&quot;msd&quot;</span><span class="p">)</span>
<span class="n">ex</span> <span class="o">=</span> <span class="n">Experiment</span><span class="p">(</span><span class="s2">&quot;MSD&quot;</span><span class="p">,</span> <span class="n">ingredients</span><span class="o">=</span><span class="p">[</span><span class="n">msd_ingredient</span><span class="p">])</span>
@@ -204,6 +205,8 @@ <h1>Source code for msd_pytorch.main</h1><div class="highlight"><pre>
<span class="c1"># Benchmark specific</span>
<span class="n">input_size</span> <span class="o">=</span> <span class="mi">1024</span>

<span class="c1"># Path where to store the final weights (msd will append &#39;.torch&#39;)</span>
<span class="n">weights_path</span> <span class="o">=</span> <span class="s2">&quot;weights&quot;</span>

<div class="viewcode-block" id="segmentation"><a class="viewcode-back" href="../../msd_pytorch.html#msd_pytorch.main.segmentation">[docs]</a><span class="nd">@ex</span><span class="o">.</span><span class="n">command</span>
<span class="k">def</span> <span class="nf">segmentation</span><span class="p">(</span>
@@ -215,6 +218,7 @@ <h1>Source code for msd_pytorch.main</h1><div class="highlight"><pre>
<span class="n">train_target_glob</span><span class="p">,</span>
<span class="n">val_input_glob</span><span class="p">,</span>
<span class="n">val_target_glob</span><span class="p">,</span>
<span class="n">weights_path</span><span class="p">,</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;Load training dataset&quot;</span><span class="p">)</span>
<span class="c1"># Create train (always) and validation (only if specified) datasets.</span>
@@ -230,7 +234,7 @@ <h1>Source code for msd_pytorch.main</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="s2">&quot;Create network model&quot;</span><span class="p">)</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">MSDSegmentationModel</span><span class="p">(</span><span class="n">num_labels</span><span class="o">=</span><span class="n">train_ds</span><span class="o">.</span><span class="n">num_labels</span><span class="p">)</span>
<span class="n">train</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">epochs</span><span class="p">,</span> <span class="n">train_dl</span><span class="p">,</span> <span class="n">val_dl</span><span class="p">)</span></div>
<span class="n">train</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">epochs</span><span class="p">,</span> <span class="n">train_dl</span><span class="p">,</span> <span class="n">val_dl</span><span class="p">,</span> <span class="n">weights_path</span><span class="p">)</span></div>


<div class="viewcode-block" id="regression"><a class="viewcode-back" href="../../msd_pytorch.html#msd_pytorch.main.regression">[docs]</a><span class="nd">@ex</span><span class="o">.</span><span class="n">command</span>
@@ -242,6 +246,7 @@ <h1>Source code for msd_pytorch.main</h1><div class="highlight"><pre>
<span class="n">train_target_glob</span><span class="p">,</span>
<span class="n">val_input_glob</span><span class="p">,</span>
<span class="n">val_target_glob</span><span class="p">,</span>
<span class="n">weights_path</span><span class="p">,</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;Load training dataset&quot;</span><span class="p">)</span>
<span class="c1"># Create train (always) and validation (only if specified) datasets.</span>
@@ -257,7 +262,7 @@ <h1>Source code for msd_pytorch.main</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="s2">&quot;Create network model&quot;</span><span class="p">)</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">mp</span><span class="o">.</span><span class="n">MSDRegressionModel</span><span class="p">()</span>
<span class="n">train</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">epochs</span><span class="p">,</span> <span class="n">train_dl</span><span class="p">,</span> <span class="n">val_dl</span><span class="p">)</span></div>
<span class="n">train</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">epochs</span><span class="p">,</span> <span class="n">train_dl</span><span class="p">,</span> <span class="n">val_dl</span><span class="p">,</span> <span class="n">weights_path</span><span class="p">)</span></div>


<div class="viewcode-block" id="benchmark"><a class="viewcode-back" href="../../msd_pytorch.html#msd_pytorch.main.benchmark">[docs]</a><span class="nd">@ex</span><span class="o">.</span><span class="n">command</span>
@@ -277,7 +282,12 @@ <h1>Source code for msd_pytorch.main</h1><div class="highlight"><pre>
<span class="nb">print</span><span class="p">(</span><span class="n">bench</span><span class="p">(</span><span class="s2">&quot;Gradient&quot;</span><span class="p">,</span> <span class="n">t</span><span class="p">))</span></div>


<div class="viewcode-block" id="train"><a class="viewcode-back" href="../../msd_pytorch.html#msd_pytorch.main.train">[docs]</a><span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">epochs</span><span class="p">,</span> <span class="n">train_dl</span><span class="p">,</span> <span class="n">val_dl</span><span class="p">):</span>
<div class="viewcode-block" id="train"><a class="viewcode-back" href="../../msd_pytorch.html#msd_pytorch.main.train">[docs]</a><span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">epochs</span><span class="p">,</span> <span class="n">train_dl</span><span class="p">,</span> <span class="n">val_dl</span><span class="p">,</span> <span class="n">weights_path</span><span class="p">):</span>

<span class="n">weights_path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">weights_path</span><span class="p">)</span><span class="o">.</span><span class="n">expanduser</span><span class="p">()</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span>
<span class="k">if</span> <span class="n">weights_path</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span>
<span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;Overwriting weights file </span><span class="si">{weights_path}</span><span class="s2">&quot;</span><span class="p">)</span>

<span class="c1"># The network works best if the input data has mean zero and has a</span>
<span class="c1"># standard deviation of 1. To achieve this, we get a rough estimate of</span>
<span class="c1"># correction parameters from the training data. These parameters are</span>
@@ -307,16 +317,16 @@ <h1>Source code for msd_pytorch.main</h1><div class="highlight"><pre>
<span class="c1"># Save network if worthwile</span>
<span class="k">if</span> <span class="n">validation_error</span> <span class="o">&lt;</span> <span class="n">best_validation_error</span> <span class="ow">or</span> <span class="n">val_dl</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">best_validation_error</span> <span class="o">=</span> <span class="n">validation_error</span>
<span class="n">model</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;msd_network_epoch_</span><span class="si">{epoch}</span><span class="s2">.torch&quot;</span><span class="p">,</span> <span class="n">epoch</span><span class="p">)</span>
<span class="n">ex</span><span class="o">.</span><span class="n">add_artifact</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;msd_network_epoch_</span><span class="si">{epoch}</span><span class="s2">.torch&quot;</span><span class="p">)</span>
<span class="n">model</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;</span><span class="si">{weights_path}</span><span class="s2">_epoch_</span><span class="si">{epoch}</span><span class="s2">.torch&quot;</span><span class="p">,</span> <span class="n">epoch</span><span class="p">)</span>
<span class="n">ex</span><span class="o">.</span><span class="n">add_artifact</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;</span><span class="si">{weights_path}</span><span class="s2">_epoch_</span><span class="si">{epoch}</span><span class="s2">.torch&quot;</span><span class="p">)</span>

<span class="n">end</span> <span class="o">=</span> <span class="n">timer</span><span class="p">()</span>
<span class="n">ex</span><span class="o">.</span><span class="n">log_scalar</span><span class="p">(</span><span class="s2">&quot;Iteration time&quot;</span><span class="p">,</span> <span class="n">end</span> <span class="o">-</span> <span class="n">start</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="n">f</span><span class="s2">&quot;</span><span class="si">{epoch:05}</span><span class="s2"> Iteration time: {end-start: 0.6f}&quot;</span><span class="p">)</span>

<span class="c1"># Always save final network parameters</span>
<span class="n">model</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;msd_network_epoch_</span><span class="si">{epoch}</span><span class="s2">.torch&quot;</span><span class="p">,</span> <span class="n">epoch</span><span class="p">)</span>
<span class="n">ex</span><span class="o">.</span><span class="n">add_artifact</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;msd_network_epoch_</span><span class="si">{epoch}</span><span class="s2">.torch&quot;</span><span class="p">)</span></div>
<span class="n">model</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;</span><span class="si">{weights_path}</span><span class="s2">.torch&quot;</span><span class="p">,</span> <span class="n">epoch</span><span class="p">)</span>
<span class="n">ex</span><span class="o">.</span><span class="n">add_artifact</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;</span><span class="si">{weights_path}</span><span class="s2">.torch&quot;</span><span class="p">)</span></div>


<div class="viewcode-block" id="experiment_main"><a class="viewcode-back" href="../../msd_pytorch.html#msd_pytorch.main.experiment_main">[docs]</a><span class="nd">@ex</span><span class="o">.</span><span class="n">main</span>
Loading

0 comments on commit ac801f7

Please sign in to comment.