diff --git a/docs/_build/doctrees/environment.pickle b/docs/_build/doctrees/environment.pickle index b5d2a32cc7b84de76609c5e82123a94be3160a1f..8177ee83cc892e37ca93cbc2fa2760d075755b87 100644 Binary files a/docs/_build/doctrees/environment.pickle and b/docs/_build/doctrees/environment.pickle differ diff --git a/docs/_build/doctrees/modules.doctree b/docs/_build/doctrees/modules.doctree deleted file mode 100644 index f4b5ab1c6821b4bd1146fc514f26bd0e9cf83af2..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/modules.doctree and /dev/null differ diff --git a/docs/_build/doctrees/modules/pysegcnn.core.cli.doctree b/docs/_build/doctrees/modules/pysegcnn.core.cli.doctree deleted file mode 100644 index e81222aa7975321050fa44856af1818779d651f1..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/modules/pysegcnn.core.cli.doctree and /dev/null differ diff --git a/docs/_build/doctrees/modules/pysegcnn.core.constants.doctree b/docs/_build/doctrees/modules/pysegcnn.core.constants.doctree deleted file mode 100644 index f7ef0115fbb77442bba1a7026cb3ebc36d90736a..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/modules/pysegcnn.core.constants.doctree and /dev/null differ diff --git a/docs/_build/doctrees/modules/pysegcnn.core.dataset.doctree b/docs/_build/doctrees/modules/pysegcnn.core.dataset.doctree deleted file mode 100644 index 750417c49169527f3062f7259bc39aa8fe1e65a0..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/modules/pysegcnn.core.dataset.doctree and /dev/null differ diff --git a/docs/_build/doctrees/readme.doctree b/docs/_build/doctrees/readme.doctree deleted file mode 100644 index a30cca3727e1fd6192fd34b4fad6b7aefd97bf08..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/readme.doctree and /dev/null differ diff --git a/docs/_build/doctrees/source/api.doctree b/docs/_build/doctrees/source/api.doctree index ddc9fbb6751ea5f248a723f91a03c3bcea5d78fe..e95d50af9bdf74e2cc1ed8fe7def65694ec5bfc3 100644 Binary files a/docs/_build/doctrees/source/api.doctree and b/docs/_build/doctrees/source/api.doctree differ diff --git a/docs/_build/doctrees/source/core.doctree b/docs/_build/doctrees/source/core.doctree deleted file mode 100644 index 4284a31b29f3c1dcf035cddd700c98f325eec1d3..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/source/core.doctree and /dev/null differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.Cloud95Dataset.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.Cloud95Dataset.doctree index 0d580be980e1cdecbb3dd9284ecf7a3905bc9ab3..5ef86132fb7c28b8990bc6e08b74291855adb746 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.Cloud95Dataset.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.Cloud95Dataset.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.ImageDataset.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.ImageDataset.doctree index d3d8263e389faa1a9785e2f986c1a8c8b6867056..419113a28a9c3ab7364d1f88fa99c703ebdd275f 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.ImageDataset.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.ImageDataset.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.SparcsDataset.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.SparcsDataset.doctree index 09ffadd51e5d992e099585385ba906deb751727c..20aad787c0af6cccc82308a42b2f2995910e626d 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.SparcsDataset.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.dataset.SparcsDataset.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Block.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Block.doctree index cea7dcb2ebd3e2955e4740ba5e433b8a9272b9f6..23c8160fee9d36e17b17ef1ba2e82de2fad14887 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Block.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Block.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Conv2dSame.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Conv2dSame.doctree index aa7807531296decd72e116b6c2622581b031ee6e..69c0fd72092fcdc2070369b78e183ae42e5e3190 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Conv2dSame.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Conv2dSame.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.doctree index 541b14d3a65f0b1f66766b2b1f461192b96948d2..8137ca9dd91d89ad824f5f5fd3171fa0b892eb5e 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.doctree index bc1ac7f948be56eff1ce5bb5e6c0c4062c16a12a..bc7a303b51b774ecc224b78ededae4354a6ba137 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.doctree index 138065b0fe4285d469ccde5dac5d702365626cd0..7ae0b90e42a8438aeb0b968bbf44dac505134158 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Decoder.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Decoder.doctree index f42921f7fe87e17d8af1dba21fcc9d66bf68e036..c5db12d335ea6ef9b6e03c97981ebcc795e9b949 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Decoder.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Decoder.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.DecoderBlock.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.DecoderBlock.doctree index 050a01236c62ddc6683a68129434b660471a5332..951a1fdb5678105b9674507c191f4ea840e50f34 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.DecoderBlock.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.DecoderBlock.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Encoder.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Encoder.doctree index 443e2179a37b744b3483d9770eaed40988d9e567..3c96ed7f91ef33f310ac27623fbe2e44ce193639 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Encoder.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.Encoder.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.EncoderBlock.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.EncoderBlock.doctree index 140acc3978a3b14f87cecee09fb329a27f7b17ba..c995fe994747a627df70b5eae6aaef20da4f50fa 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.EncoderBlock.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.EncoderBlock.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.layers.doctree deleted file mode 100644 index 5cee477b5e57fbafaed6fdddff78b47cc155da38..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.layers.doctree and /dev/null differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.models.Network.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.models.Network.doctree index b897c77c0e8f679d5d321aca5a887450fbbb06fe..3b66c63724c97ade22e24070a3b643f8c9103532 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.models.Network.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.models.Network.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.models.UNet.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.models.UNet.doctree index b2dbf831d1a9438737d3807c76722aa3d44862eb..b89ad75eb33b76b2c53d7e87facdcb23b1b23395 100644 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.models.UNet.doctree and b/docs/_build/doctrees/source/generated/pysegcnn.core.models.UNet.doctree differ diff --git a/docs/_build/doctrees/source/generated/pysegcnn.core.models.doctree b/docs/_build/doctrees/source/generated/pysegcnn.core.models.doctree deleted file mode 100644 index c0daf6db0f35aa1799069dd78e475da38cf05b35..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/source/generated/pysegcnn.core.models.doctree and /dev/null differ diff --git a/docs/_build/doctrees/source/install.doctree b/docs/_build/doctrees/source/install.doctree deleted file mode 100644 index 9b01515b3c55b59c5170d8c51e6ff4ef1fc4040a..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/source/install.doctree and /dev/null differ diff --git a/docs/_build/doctrees/source/main.doctree b/docs/_build/doctrees/source/main.doctree deleted file mode 100644 index 765811a4dbdd68a8f38b5c5f4f6ca1634cbada14..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/source/main.doctree and /dev/null differ diff --git a/docs/_build/doctrees/source/modules.doctree b/docs/_build/doctrees/source/modules.doctree deleted file mode 100644 index df0a22b202133625edfbfdd0f85c30b6070565e8..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/source/modules.doctree and /dev/null differ diff --git a/docs/_build/doctrees/source/preprocessing.doctree b/docs/_build/doctrees/source/preprocessing.doctree deleted file mode 100644 index 9447189fbe4a1974df0cdac3501add9a5d4e10f4..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/source/preprocessing.doctree and /dev/null differ diff --git a/docs/_build/doctrees/source/readme.doctree b/docs/_build/doctrees/source/readme.doctree deleted file mode 100644 index 1fda9e038780a91cbb0ab13fa6d2d65f95a88802..0000000000000000000000000000000000000000 Binary files a/docs/_build/doctrees/source/readme.doctree and /dev/null differ diff --git a/docs/_build/html/_modules/core/cli.html b/docs/_build/html/_modules/core/cli.html deleted file mode 100644 index d73d939362fb8c78c8d6ea841ac865401f2d21aa..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/cli.html +++ /dev/null @@ -1,264 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.cli — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.cli</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.cli</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Command line interface parsers.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">pathlib</span> -<span class="kn">import</span> <span class="nn">argparse</span> - - -<span class="c1"># epilogue to display at the end of each parser</span> -<span class="n">EPILOGUE</span> <span class="o">=</span> <span class="s1">'Author: Daniel Frisinghelli, daniel.frisinghelli@gmail.com'</span> - - -<div class="viewcode-block" id="structure_parser"><a class="viewcode-back" href="../../source/core.html#core.cli.structure_parser">[docs]</a><span class="k">def</span> <span class="nf">structure_parser</span><span class="p">():</span> - <span class="sd">"""Command line argument parser to standardize dataset structure.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span> - <span class="n">description</span><span class="o">=</span><span class="s1">'Standardize the dataset directory structure.'</span><span class="p">,</span> - <span class="n">epilog</span><span class="o">=</span><span class="n">EPILOGUE</span><span class="p">,</span> - <span class="n">formatter_class</span><span class="o">=</span><span class="k">lambda</span> <span class="n">prog</span><span class="p">:</span> <span class="n">argparse</span><span class="o">.</span><span class="n">RawDescriptionHelpFormatter</span><span class="p">(</span> - <span class="n">prog</span><span class="p">,</span> <span class="n">max_help_position</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="n">indent_increment</span><span class="o">=</span><span class="mi">2</span><span class="p">))</span> - - <span class="c1"># positional arguments</span> - - <span class="c1"># positional argument: path to the archive</span> - <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'archive'</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">,</span> - <span class="n">help</span><span class="o">=</span><span class="s1">'Path to the dataset archive.'</span><span class="p">)</span> - - <span class="c1"># positional argument: path to extract and restructure the dataset</span> - <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'target'</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">,</span> - <span class="n">help</span><span class="o">=</span><span class="s1">'Path to save standardized dataset structure.'</span><span class="p">)</span> - - <span class="c1"># optional arguments</span> - - <span class="c1"># default values</span> - <span class="n">default</span> <span class="o">=</span> <span class="s1">'(default: </span><span class="si">%(default)s</span><span class="s1">)'</span> - - <span class="c1"># optional argument: whether to overwrite existing files</span> - <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-o'</span><span class="p">,</span> <span class="s1">'--overwrite'</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">bool</span><span class="p">,</span> - <span class="n">help</span><span class="o">=</span><span class="s1">'Overwrite files </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">default</span><span class="p">),</span> - <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="s1">'?'</span><span class="p">,</span> <span class="n">const</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s1">''</span><span class="p">)</span> - - <span class="c1"># optional argument: whether to copy or move extracted files</span> - <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-r'</span><span class="p">,</span> <span class="s1">'--remove'</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">bool</span><span class="p">,</span> - <span class="n">help</span><span class="o">=</span><span class="s1">'Remove original dataset </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">default</span><span class="p">),</span> - <span class="n">default</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="s1">'?'</span><span class="p">,</span> <span class="n">const</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s1">''</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">parser</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/constants.html b/docs/_build/html/_modules/core/constants.html deleted file mode 100644 index 046478e122c847eff12af3f24609a186efd49625..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/constants.html +++ /dev/null @@ -1,314 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.constants — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.constants</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.constants</h1><div class="highlight"><pre> -<span></span><span class="sd">"""A collection of constant values.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">enum</span> - - -<span class="c1"># Landsat 8 bands</span> -<div class="viewcode-block" id="Landsat8"><a class="viewcode-back" href="../../source/core.html#core.constants.Landsat8">[docs]</a><span class="k">class</span> <span class="nc">Landsat8</span><span class="p">(</span><span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">):</span> - <span class="sd">"""The spectral bands of the Landsat 8 sensors.</span> - -<span class="sd"> sensors:</span> -<span class="sd"> - Operational Land Imager (OLI), (bands 1-9)</span> -<span class="sd"> - Thermal Infrared Sensor (TIRS), (bands 10, 11)</span> - -<span class="sd"> """</span> - - <span class="n">violet</span> <span class="o">=</span> <span class="mi">1</span> - <span class="n">blue</span> <span class="o">=</span> <span class="mi">2</span> - <span class="n">green</span> <span class="o">=</span> <span class="mi">3</span> - <span class="n">red</span> <span class="o">=</span> <span class="mi">4</span> - <span class="n">nir</span> <span class="o">=</span> <span class="mi">5</span> - <span class="n">swir1</span> <span class="o">=</span> <span class="mi">6</span> - <span class="n">swir2</span> <span class="o">=</span> <span class="mi">7</span> - <span class="n">pan</span> <span class="o">=</span> <span class="mi">8</span> - <span class="n">cirrus</span> <span class="o">=</span> <span class="mi">9</span> - <span class="n">tir1</span> <span class="o">=</span> <span class="mi">10</span></div> - <span class="c1"># tir2 = 11</span> - - -<span class="c1"># Sentinel 2 bands</span> -<div class="viewcode-block" id="Sentinel2"><a class="viewcode-back" href="../../source/core.html#core.constants.Sentinel2">[docs]</a><span class="k">class</span> <span class="nc">Sentinel2</span><span class="p">(</span><span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">):</span> - <span class="sd">"""The spectral bands of the Sentinel-2 MultiSpectral Instrument (MSI)."""</span> - - <span class="n">aerosol</span> <span class="o">=</span> <span class="mi">1</span> - <span class="n">blue</span> <span class="o">=</span> <span class="mi">2</span> - <span class="n">green</span> <span class="o">=</span> <span class="mi">3</span> - <span class="n">red</span> <span class="o">=</span> <span class="mi">4</span> - <span class="n">vnir1</span> <span class="o">=</span> <span class="mi">5</span> - <span class="n">vnir2</span> <span class="o">=</span> <span class="mi">6</span> - <span class="n">vnir3</span> <span class="o">=</span> <span class="mi">7</span> - <span class="n">nir</span> <span class="o">=</span> <span class="mi">8</span> - <span class="n">nnir</span> <span class="o">=</span> <span class="s1">'8A'</span> - <span class="n">vapor</span> <span class="o">=</span> <span class="mi">9</span> - <span class="n">cirrus</span> <span class="o">=</span> <span class="mi">10</span> - <span class="n">swir1</span> <span class="o">=</span> <span class="mi">11</span> - <span class="n">swir2</span> <span class="o">=</span> <span class="mi">12</span></div> - - -<span class="c1"># generic class label enumeration class</span> -<div class="viewcode-block" id="Label"><a class="viewcode-back" href="../../source/core.html#core.constants.Label">[docs]</a><span class="k">class</span> <span class="nc">Label</span><span class="p">(</span><span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">):</span> - <span class="sd">"""Generic enumeration for class labels."""</span> - - <span class="nd">@property</span> - <span class="k">def</span> <span class="nf">id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Return the value of a class in the ground truth."""</span> - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> - - <span class="nd">@property</span> - <span class="k">def</span> <span class="nf">color</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Return the color to plot a class."""</span> - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></div> - - -<span class="c1"># labels of the Sparcs dataset</span> -<div class="viewcode-block" id="SparcsLabels"><a class="viewcode-back" href="../../source/core.html#core.constants.SparcsLabels">[docs]</a><span class="k">class</span> <span class="nc">SparcsLabels</span><span class="p">(</span><span class="n">Label</span><span class="p">):</span> - <span class="sd">"""Class labels of the `Sparcs`_ dataset.</span> - -<span class="sd"> .. _Sparcs:</span> -<span class="sd"> https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation</span> - -<span class="sd"> """</span> - - <span class="n">Shadow</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">'grey'</span> - <span class="n">Shadow_over_water</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'darkblue'</span> - <span class="n">Water</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">'blue'</span> - <span class="n">Snow</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">'lightblue'</span> - <span class="n">Land</span> <span class="o">=</span> <span class="mi">4</span><span class="p">,</span> <span class="s1">'sienna'</span> - <span class="n">Cloud</span> <span class="o">=</span> <span class="mi">5</span><span class="p">,</span> <span class="s1">'white'</span> - <span class="n">Flooded</span> <span class="o">=</span> <span class="mi">6</span><span class="p">,</span> <span class="s1">'yellow'</span></div> - - -<span class="c1"># labels of the Cloud95 dataset</span> -<div class="viewcode-block" id="Cloud95Labels"><a class="viewcode-back" href="../../source/core.html#core.constants.Cloud95Labels">[docs]</a><span class="k">class</span> <span class="nc">Cloud95Labels</span><span class="p">(</span><span class="n">Label</span><span class="p">):</span> - <span class="sd">"""Class labels of the `Cloud-95`_ dataset.</span> - -<span class="sd"> .. _Cloud-95:</span> -<span class="sd"> https://github.com/SorourMo/95-Cloud-An-Extension-to-38-Cloud-Dataset</span> - -<span class="sd"> """</span> - - <span class="n">Clear</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">'skyblue'</span> - <span class="n">Cloud</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'white'</span></div> - - -<span class="c1"># labels of the ProSnow dataset</span> -<div class="viewcode-block" id="ProSnowLabels"><a class="viewcode-back" href="../../source/core.html#core.constants.ProSnowLabels">[docs]</a><span class="k">class</span> <span class="nc">ProSnowLabels</span><span class="p">(</span><span class="n">Label</span><span class="p">):</span> - <span class="sd">"""Class labels of the ProSnow datasets."""</span> - - <span class="n">Cloud</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">'white'</span> - <span class="n">Snow</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'lightblue'</span> - <span class="n">Snow_free</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">'sienna'</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/dataset.html b/docs/_build/html/_modules/core/dataset.html deleted file mode 100644 index 8b56cc4a6d83fc94d4da3de1595f26d220538245..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/dataset.html +++ /dev/null @@ -1,1594 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.dataset — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.dataset</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.dataset</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Custom dataset classes compliant to the PyTorch standard.</span> - -<span class="sd">Each custom dataset should inherit from torch.utils.data.Dataset to benefit</span> -<span class="sd">from the torch.utils.data.DataLoader class, which implements helpful utilities</span> -<span class="sd">during model training.</span> - -<span class="sd">For any kind of image-like dataset, inherit the ImageDataset class to create</span> -<span class="sd">your custom dataset.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">os</span> -<span class="kn">import</span> <span class="nn">re</span> -<span class="kn">import</span> <span class="nn">csv</span> -<span class="kn">import</span> <span class="nn">enum</span> -<span class="kn">import</span> <span class="nn">itertools</span> -<span class="kn">import</span> <span class="nn">logging</span> - -<span class="c1"># externals</span> -<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> -<span class="kn">import</span> <span class="nn">torch</span> -<span class="kn">from</span> <span class="nn">torch.utils.data</span> <span class="kn">import</span> <span class="n">Dataset</span> - -<span class="c1"># locals</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.constants</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Landsat8</span><span class="p">,</span> <span class="n">Sentinel2</span><span class="p">,</span> <span class="n">Label</span><span class="p">,</span> <span class="n">SparcsLabels</span><span class="p">,</span> - <span class="n">Cloud95Labels</span><span class="p">,</span> <span class="n">ProSnowLabels</span><span class="p">)</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.utils</span> <span class="kn">import</span> <span class="p">(</span><span class="n">img2np</span><span class="p">,</span> <span class="n">is_divisible</span><span class="p">,</span> <span class="n">tile_topleft_corner</span><span class="p">,</span> - <span class="n">parse_landsat_scene</span><span class="p">,</span> <span class="n">parse_sentinel2_scene</span><span class="p">)</span> - -<span class="c1"># module level logger</span> -<span class="n">LOGGER</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> - - -<div class="viewcode-block" id="ImageDataset"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset">[docs]</a><span class="k">class</span> <span class="nc">ImageDataset</span><span class="p">(</span><span class="n">Dataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Base class for multispectral image data.</span> - -<span class="sd"> Inheriting from `torch.utils.data.Dataset` to be compliant to the PyTorch</span> -<span class="sd"> standard. Furthermore, using instances of `torch.utils.data.Dataset`</span> -<span class="sd"> enables the use of the handy `torch.utils.data.DataLoader` class during</span> -<span class="sd"> model training.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention.</span> -<span class="sd"> All directories and subdirectories in ``root_dir`` are searched for</span> -<span class="sd"> files matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - - <span class="c1"># dataset configuration</span> - <span class="bp">self</span><span class="o">.</span><span class="n">root</span> <span class="o">=</span> <span class="n">root_dir</span> - <span class="bp">self</span><span class="o">.</span><span class="n">use_bands</span> <span class="o">=</span> <span class="n">use_bands</span> - <span class="bp">self</span><span class="o">.</span><span class="n">tile_size</span> <span class="o">=</span> <span class="n">tile_size</span> - <span class="bp">self</span><span class="o">.</span><span class="n">pad</span> <span class="o">=</span> <span class="n">pad</span> - <span class="bp">self</span><span class="o">.</span><span class="n">gt_pattern</span> <span class="o">=</span> <span class="n">gt_pattern</span> - <span class="bp">self</span><span class="o">.</span><span class="n">sort</span> <span class="o">=</span> <span class="n">sort</span> - <span class="bp">self</span><span class="o">.</span><span class="n">seed</span> <span class="o">=</span> <span class="n">seed</span> - <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span> <span class="o">=</span> <span class="n">transforms</span> - - <span class="c1"># initialize instance attributes</span> - <span class="bp">self</span><span class="o">.</span><span class="n">_init_attributes</span><span class="p">()</span> - - <span class="c1"># the samples of the dataset</span> - <span class="bp">self</span><span class="o">.</span><span class="n">scenes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">compose_scenes</span><span class="p">()</span> - <span class="bp">self</span><span class="o">.</span><span class="n">_assert_compose_scenes</span><span class="p">()</span> - - <span class="k">def</span> <span class="nf">_init_attributes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Initialize the class instance attributes."""</span> - <span class="c1"># the size of a scene/patch in the dataset</span> - <span class="bp">self</span><span class="o">.</span><span class="n">size</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_size</span><span class="p">()</span> - <span class="bp">self</span><span class="o">.</span><span class="n">_assert_get_size</span><span class="p">()</span> - - <span class="c1"># the available spectral bands in the dataset</span> - <span class="bp">self</span><span class="o">.</span><span class="n">sensor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sensor</span><span class="p">()</span> - <span class="bp">self</span><span class="o">.</span><span class="n">_assert_get_sensor</span><span class="p">()</span> - <span class="bp">self</span><span class="o">.</span><span class="n">bands</span> <span class="o">=</span> <span class="p">{</span><span class="n">band</span><span class="o">.</span><span class="n">value</span><span class="p">:</span> <span class="n">band</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">band</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sensor</span><span class="p">}</span> - - <span class="c1"># the class labels</span> - <span class="bp">self</span><span class="o">.</span><span class="n">_label_class</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_labels</span><span class="p">()</span> - <span class="bp">self</span><span class="o">.</span><span class="n">_assert_get_labels</span><span class="p">()</span> - <span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_build_labels</span><span class="p">()</span> - - <span class="c1"># check which bands to use</span> - <span class="bp">self</span><span class="o">.</span><span class="n">use_bands</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">use_bands</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_bands</span> <span class="k">else</span> - <span class="p">[</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">values</span><span class="p">()])</span> - - <span class="c1"># calculate number of resulting tiles and check whether the images are</span> - <span class="c1"># evenly divisible in square tiles of size (tile_size x tile_size)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">tiles</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="mi">1</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="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tile_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - <span class="bp">self</span><span class="o">.</span><span class="n">tiles</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="n">is_divisible</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tile_size</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">pad</span><span class="p">)</span> - - <span class="c1"># the size of the padded scenes</span> - <span class="bp">self</span><span class="o">.</span><span class="n">height</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> - <span class="bp">self</span><span class="o">.</span><span class="n">width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> - - <span class="c1"># the topleft corners of the tiles</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tile_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - <span class="bp">self</span><span class="o">.</span><span class="n">topleft</span> <span class="o">=</span> <span class="n">tile_topleft_corner</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">height</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">width</span><span class="p">),</span> - <span class="bp">self</span><span class="o">.</span><span class="n">tile_size</span><span class="p">)</span> - - <span class="c1"># always use the original dataset together with the augmentations</span> - <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span> - - <span class="c1"># when padding, add a new "no data" label to the ground truth</span> - <span class="bp">self</span><span class="o">.</span><span class="n">cval</span> <span class="o">=</span> <span class="mi">0</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pad</span> <span class="ow">and</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> - <span class="bp">self</span><span class="o">.</span><span class="n">cval</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">labels</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span> - <span class="bp">self</span><span class="o">.</span><span class="n">labels</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">cval</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'label'</span><span class="p">:</span> <span class="s1">'No data'</span><span class="p">,</span> <span class="s1">'color'</span><span class="p">:</span> <span class="s1">'black'</span><span class="p">}</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Adding label "No data" with value=</span><span class="si">{}</span><span class="s1"> to ground truth.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cval</span><span class="p">))</span> - - <span class="k">def</span> <span class="nf">_build_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Build the label dictionary.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> labels : `dict` [`int`, `dict`]</span> -<span class="sd"> The label dictionary. The keys are the values of the class labels</span> -<span class="sd"> in the ground truth ``y``. Each nested `dict` should have keys:</span> -<span class="sd"> ``'color'``</span> -<span class="sd"> A named color (`str`).</span> -<span class="sd"> ``'label'``</span> -<span class="sd"> The name of the class label (`str`).</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="p">{</span><span class="n">band</span><span class="o">.</span><span class="n">id</span><span class="p">:</span> <span class="p">{</span><span class="s1">'label'</span><span class="p">:</span> <span class="n">band</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'_'</span><span class="p">,</span> <span class="s1">' '</span><span class="p">),</span> - <span class="s1">'color'</span><span class="p">:</span> <span class="n">band</span><span class="o">.</span><span class="n">color</span><span class="p">}</span> - <span class="k">for</span> <span class="n">band</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_label_class</span><span class="p">}</span> - - <span class="k">def</span> <span class="nf">_assert_compose_scenes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check whether compose_scenes() is correctly implemented."""</span> - <span class="c1"># list of required keys</span> - <span class="bp">self</span><span class="o">.</span><span class="n">keys</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_bands</span> <span class="o">+</span> <span class="p">[</span><span class="s1">'gt'</span><span class="p">,</span> <span class="s1">'date'</span><span class="p">,</span> <span class="s1">'tile'</span><span class="p">,</span> <span class="s1">'transform'</span><span class="p">,</span> <span class="s1">'id'</span><span class="p">]</span> - - <span class="c1"># check if each scene is correctly composed</span> - <span class="k">for</span> <span class="n">scene</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">scenes</span><span class="p">:</span> - <span class="c1"># check the type of each scene</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">scene</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1">.compose_scenes() should return a list of '</span> - <span class="s1">'dictionaries.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</span> - <span class="p">)</span> - - <span class="c1"># check if each scene dictionary has the correct keys</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">([</span><span class="n">k</span> <span class="ow">in</span> <span class="n">scene</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">keys</span><span class="p">]):</span> - <span class="k">raise</span> <span class="ne">KeyError</span><span class="p">(</span><span class="s1">'Each scene dictionary should have keys </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">keys</span><span class="p">))</span> - - <span class="k">def</span> <span class="nf">_assert_get_size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check whether get_size() is correctly implemented."""</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1">.get_size() should return the spatial size of '</span> - <span class="s1">'an image sample as tuple, i.e. (height, width).'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">))</span> - - <span class="k">def</span> <span class="nf">_assert_get_sensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check whether get_sensor() is correctly implemented."""</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sensor</span><span class="p">,</span> <span class="n">enum</span><span class="o">.</span><span class="n">EnumMeta</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1">.get_sensor() should return an instance of '</span> - <span class="s1">'enum.Enum, containing an enumeration of the '</span> - <span class="s1">'spectral bands of the sensor the dataset is '</span> - <span class="s1">'derived from. Examples can be found in '</span> - <span class="s1">'pysegcnn.core.constants.py.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">))</span> - - <span class="k">def</span> <span class="nf">_assert_get_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check whether get_labels() is correctly implemented."""</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">issubclass</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_label_class</span><span class="p">,</span> <span class="n">Label</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1">.get_labels() should return an instance of '</span> - <span class="s1">'pysegcnn.core.constants.Label, '</span> - <span class="s1">'containing an enumeration of the '</span> - <span class="s1">'class labels, together with the corresponing id '</span> - <span class="s1">'in the ground truth mask and a color for '</span> - <span class="s1">'visualization. Examples can be found in '</span> - <span class="s1">'pysegcnn.core.constants.py.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">))</span> - - <span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Return the number of samples in the dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> nsamples : `int`</span> -<span class="sd"> The number of samples in the dataset.</span> -<span class="sd"> """</span> - <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scenes</span><span class="p">)</span> - - <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">idx</span><span class="p">):</span> - <span class="sd">"""Return the data of a sample of the dataset given an index ``idx``.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> idx : `int`</span> -<span class="sd"> The index of the sample.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`</span> -<span class="sd"> The sample input data.</span> -<span class="sd"> y : `torch.Tensor`</span> -<span class="sd"> The sample ground truth.</span> - -<span class="sd"> """</span> - <span class="c1"># select a scene</span> - <span class="n">scene</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_scene</span><span class="p">(</span><span class="n">idx</span><span class="p">)</span> - - <span class="c1"># get samples</span> - <span class="c1"># data: (tiles, bands, height, width)</span> - <span class="c1"># gt: (height, width)</span> - <span class="n">data</span><span class="p">,</span> <span class="n">gt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_samples</span><span class="p">(</span><span class="n">scene</span><span class="p">)</span> - - <span class="c1"># preprocess samples</span> - <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">gt</span><span class="p">)</span> - - <span class="c1"># apply transformation</span> - <span class="k">if</span> <span class="n">scene</span><span class="p">[</span><span class="s1">'transform'</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">scene</span><span class="p">[</span><span class="s1">'transform'</span><span class="p">](</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span> - - <span class="c1"># convert to torch tensors</span> - <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_tensor</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span> - <span class="n">y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_tensor</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">uint8</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span> - -<div class="viewcode-block" id="ImageDataset.compose_scenes"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset.compose_scenes">[docs]</a> <span class="k">def</span> <span class="nf">compose_scenes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Build the list of samples of the dataset.</span> - -<span class="sd"> Each sample is represented by a dictionary.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if the `pysegcnn.core.dataset.ImageDataset` class is not</span> -<span class="sd"> inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> samples : `list` [`dict`]</span> -<span class="sd"> Each dictionary representing a sample should have keys:</span> -<span class="sd"> ``'band_name_1'``</span> -<span class="sd"> Path to the file of band_1.</span> -<span class="sd"> ``'band_name_2'``</span> -<span class="sd"> Path to the file of band_2.</span> -<span class="sd"> ``'band_name_n'``</span> -<span class="sd"> Path to the file of band_n.</span> -<span class="sd"> ``'gt'``</span> -<span class="sd"> Path to the ground truth file.</span> -<span class="sd"> ``'date'``</span> -<span class="sd"> The date of the sample.</span> -<span class="sd"> ``'tile'``</span> -<span class="sd"> The tile id of the sample.</span> -<span class="sd"> ``'transform'``</span> -<span class="sd"> The transformation to apply.</span> -<span class="sd"> ``'id'``</span> -<span class="sd"> The scene identifier.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Inherit the ImageDataset class and '</span> - <span class="s1">'implement the method.'</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ImageDataset.get_size"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset.get_size">[docs]</a> <span class="k">def</span> <span class="nf">get_size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Return the size of the images in the dataset.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if the `pysegcnn.core.dataset.ImageDataset` class is not</span> -<span class="sd"> inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> size : `tuple`</span> -<span class="sd"> The image size (height, width).</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Inherit the ImageDataset class and '</span> - <span class="s1">'implement the method.'</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ImageDataset.get_sensor"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset.get_sensor">[docs]</a> <span class="k">def</span> <span class="nf">get_sensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Return an enumeration of the bands of the sensor of the dataset.</span> - -<span class="sd"> Examples can be found in `pysegcnn.core.constants`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if the `pysegcnn.core.dataset.ImageDataset` class is not</span> -<span class="sd"> inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> sensor : `enum.Enum`</span> -<span class="sd"> An enumeration of the bands of the sensor.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Inherit the ImageDataset class and '</span> - <span class="s1">'implement the method.'</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ImageDataset.get_labels"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset.get_labels">[docs]</a> <span class="k">def</span> <span class="nf">get_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Return an enumeration of the class labels of the dataset.</span> - -<span class="sd"> Examples can be found in `pysegcnn.core.constants`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if the `pysegcnn.core.dataset.ImageDataset` class is not</span> -<span class="sd"> inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> labels : `enum.Enum`</span> -<span class="sd"> The class labels.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Inherit the ImageDataset class and '</span> - <span class="s1">'implement the method.'</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ImageDataset.preprocess"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset.preprocess">[docs]</a> <span class="k">def</span> <span class="nf">preprocess</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">gt</span><span class="p">):</span> - <span class="sd">"""Preprocess a sample before feeding it to a model.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> data : `numpy.ndarray`</span> -<span class="sd"> The sample input data.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The sample ground truth.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if the `pysegcnn.core.dataset.ImageDataset` class is not</span> -<span class="sd"> inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> data : `numpy.ndarray`</span> -<span class="sd"> The preprocessed input data.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The preprocessed ground truth data.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Inherit the ImageDataset class and '</span> - <span class="s1">'implement the method.'</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ImageDataset.parse_scene_id"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset.parse_scene_id">[docs]</a> <span class="k">def</span> <span class="nf">parse_scene_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scene_id</span><span class="p">):</span> - <span class="sd">"""Parse the scene identifier.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> scene_id : `str`</span> -<span class="sd"> A scene identifier.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if the `pysegcnn.core.dataset.ImageDataset` class is not</span> -<span class="sd"> inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scene : `dict` or `None`</span> -<span class="sd"> A dictionary containing scene metadata. If `None`, ``scene_id`` is</span> -<span class="sd"> not a valid scene identifier.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Inherit the ImageDataset class and '</span> - <span class="s1">'implement the method.'</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ImageDataset.read_scene"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset.read_scene">[docs]</a> <span class="k">def</span> <span class="nf">read_scene</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">idx</span><span class="p">):</span> - <span class="sd">"""Read the data of the sample with index ``idx``.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> idx : `int`</span> -<span class="sd"> The index of the sample.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scene_data : `dict`</span> -<span class="sd"> The sample data dictionary with keys:</span> -<span class="sd"> ``'band_name_1'``</span> -<span class="sd"> data of band_1 (`numpy.ndarray`).</span> -<span class="sd"> ``'band_name_2'``</span> -<span class="sd"> data of band_2 (`numpy.ndarray`).</span> -<span class="sd"> ``'band_name_n'``</span> -<span class="sd"> data of band_n (`numpy.ndarray`).</span> -<span class="sd"> ``'gt'``</span> -<span class="sd"> data of the ground truth (`numpy.ndarray`).</span> -<span class="sd"> ``'date'``</span> -<span class="sd"> The date of the sample.</span> -<span class="sd"> ``'tile'``</span> -<span class="sd"> The tile id of the sample.</span> -<span class="sd"> ``'transform'``</span> -<span class="sd"> The transformation to apply.</span> -<span class="sd"> ``'id'``</span> -<span class="sd"> The scene identifier.</span> - -<span class="sd"> """</span> - <span class="c1"># select a scene from the root directory</span> - <span class="n">scene</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">scenes</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span> - - <span class="c1"># read each band of the scene into a numpy array</span> - <span class="n">scene_data</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">scene</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> - - <span class="c1"># pad zeros to each band if self.pad=True, but pad self.cval to</span> - <span class="c1"># the ground truth</span> - <span class="n">npad</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s1">'gt'</span> <span class="k">else</span> <span class="mi">0</span> - <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="ow">and</span> <span class="n">key</span> <span class="o">!=</span> <span class="s1">'id'</span><span class="p">:</span> - <span class="n">scene_data</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">img2np</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tile_size</span><span class="p">,</span> <span class="n">scene</span><span class="p">[</span><span class="s1">'tile'</span><span class="p">],</span> - <span class="bp">self</span><span class="o">.</span><span class="n">pad</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cval</span> <span class="o">*</span> <span class="n">npad</span><span class="p">)</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">scene_data</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span> - - <span class="k">return</span> <span class="n">scene_data</span></div> - -<div class="viewcode-block" id="ImageDataset.build_samples"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset.build_samples">[docs]</a> <span class="k">def</span> <span class="nf">build_samples</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scene</span><span class="p">):</span> - <span class="sd">"""Stack the bands of a sample in a single array.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> scene : `dict`</span> -<span class="sd"> The sample data dictionary with keys:</span> -<span class="sd"> ``'band_name_1'``</span> -<span class="sd"> data of band_1 (`numpy.ndarray`).</span> -<span class="sd"> ``'band_name_2'``</span> -<span class="sd"> data of band_2 (`numpy.ndarray`).</span> -<span class="sd"> ``'band_name_n'``</span> -<span class="sd"> data of band_n (`numpy.ndarray`).</span> -<span class="sd"> ``'gt'``</span> -<span class="sd"> data of the ground truth (`numpy.ndarray`).</span> -<span class="sd"> ``'date'``</span> -<span class="sd"> The date of the sample.</span> -<span class="sd"> ``'tile'``</span> -<span class="sd"> The tile id of the sample.</span> -<span class="sd"> ``'transform'``</span> -<span class="sd"> The transformation to apply.</span> -<span class="sd"> ``'id'``</span> -<span class="sd"> The scene identifier.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> stack : `numpy.ndarray`</span> -<span class="sd"> The input data of the sample.</span> -<span class="sd"> gt : TYPE</span> -<span class="sd"> The ground truth of the sample.</span> - -<span class="sd"> """</span> - <span class="c1"># iterate over the channels to stack</span> - <span class="n">stack</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">stack</span><span class="p">([</span><span class="n">scene</span><span class="p">[</span><span class="n">band</span><span class="p">]</span> <span class="k">for</span> <span class="n">band</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_bands</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> - <span class="n">gt</span> <span class="o">=</span> <span class="n">scene</span><span class="p">[</span><span class="s1">'gt'</span><span class="p">]</span> - - <span class="k">return</span> <span class="n">stack</span><span class="p">,</span> <span class="n">gt</span></div> - -<div class="viewcode-block" id="ImageDataset.to_tensor"><a class="viewcode-back" href="../../source/core.html#core.dataset.ImageDataset.to_tensor">[docs]</a> <span class="k">def</span> <span class="nf">to_tensor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="p">):</span> - <span class="sd">"""Convert ``x`` to `torch.Tensor`.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : array_like</span> -<span class="sd"> The input data.</span> -<span class="sd"> dtype : `torch.dtype`</span> -<span class="sd"> The data type used to convert ``x``.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`</span> -<span class="sd"> The input data tensor.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">torch</span><span class="o">.</span><span class="n">tensor</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div> - - <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Dataset representation.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> fs : `str`</span> -<span class="sd"> Representation string.</span> - -<span class="sd"> """</span> - <span class="c1"># representation string to print</span> - <span class="n">fs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">+</span> <span class="s1">'(</span><span class="se">\n</span><span class="s1">'</span> - - <span class="c1"># sensor</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">' (sensor):</span><span class="se">\n</span><span class="s1"> - '</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">sensor</span><span class="o">.</span><span class="vm">__name__</span> - - <span class="c1"># bands used for the segmentation</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> (bands):</span><span class="se">\n</span><span class="s1"> '</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">'- Band </span><span class="si">{}</span><span class="s1">: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">b</span> <span class="ow">in</span> - <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">use_bands</span><span class="p">))</span> - - <span class="c1"># scenes</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> (scene):</span><span class="se">\n</span><span class="s1"> '</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'- size (h, w): </span><span class="si">{}</span><span class="se">\n</span><span class="s1"> '</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">height</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">width</span><span class="p">))</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'- number of scenes: </span><span class="si">{}</span><span class="se">\n</span><span class="s1"> '</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="nb">len</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">([</span><span class="n">f</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">scenes</span><span class="p">])))</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'- padding (bottom, left, top, right): </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">padding</span><span class="p">)</span> - - <span class="c1"># tiles</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> (tiles):</span><span class="se">\n</span><span class="s1"> '</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'- number of tiles per scene: </span><span class="si">{}</span><span class="se">\n</span><span class="s1"> '</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tiles</span><span class="p">)</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'- tile size: </span><span class="si">{}</span><span class="se">\n</span><span class="s1"> '</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">tile_size</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">tile_size</span><span class="p">))</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'- number of tiles: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scenes</span><span class="p">))</span> - - <span class="c1"># classes of interest</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> (classes):</span><span class="se">\n</span><span class="s1"> '</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">'- Class </span><span class="si">{}</span><span class="s1">: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">[</span><span class="s1">'label'</span><span class="p">])</span> <span class="k">for</span> - <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels</span><span class="o">.</span><span class="n">items</span><span class="p">())</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">)'</span> - <span class="k">return</span> <span class="n">fs</span></div> - - -<div class="viewcode-block" id="StandardEoDataset"><a class="viewcode-back" href="../../source/core.html#core.dataset.StandardEoDataset">[docs]</a><span class="k">class</span> <span class="nc">StandardEoDataset</span><span class="p">(</span><span class="n">ImageDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Base class for standard Earth Observation style datasets.</span> - -<span class="sd"> `pysegcnn.core.dataset.StandardEoDataset` implements the</span> -<span class="sd"> `~pysegcnn.core.dataset.StandardEoDataset.compose_scenes` method for</span> -<span class="sd"> datasets with the following directory structure:</span> - -<span class="sd"> root_dir/</span> -<span class="sd"> scene_id_1/</span> -<span class="sd"> scene_id_1_B1.tif</span> -<span class="sd"> scene_id_1_B2.tif</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> scene_id_1_BN.tif</span> -<span class="sd"> scene_id_2/</span> -<span class="sd"> scene_id_2_B1.tif</span> -<span class="sd"> scene_id_2_B2.tif</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> scene_id_2_BN.tif</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> scene_id_N/</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> .</span> - -<span class="sd"> If your dataset shares this directory structure, you can directly inherit</span> -<span class="sd"> `pysegcnn.core.dataset.StandardEoDataset` and implement the remaining</span> -<span class="sd"> methods.</span> - -<span class="sd"> See `pysegcnn.core.dataset.SparcsDataset` for an example.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> - <span class="c1"># initialize super class ImageDataset</span> - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="p">,</span> - <span class="n">sort</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">transforms</span><span class="p">)</span> - - <span class="k">def</span> <span class="nf">_get_band_number</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span> - <span class="sd">"""Return the band number of a scene .tif file.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> path : `str`</span> -<span class="sd"> The path to the .tif file.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> band : `int` or `str`</span> -<span class="sd"> The band number.</span> - -<span class="sd"> """</span> - <span class="c1"># filename</span> - <span class="n">fname</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">basename</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> - - <span class="c1"># search for numbers following a "B" in the filename</span> - <span class="n">band</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s1">'B</span><span class="se">\\</span><span class="s1">dA|B</span><span class="se">\\</span><span class="s1">d{1,2}'</span><span class="p">,</span> <span class="n">fname</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'B'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> - - <span class="c1"># try converting to an integer:</span> - <span class="c1"># raises a ValueError for Sentinel2 8A band</span> - <span class="k">try</span><span class="p">:</span> - <span class="n">band</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">band</span><span class="p">)</span> - <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> - <span class="k">pass</span> - - <span class="k">return</span> <span class="n">band</span> - - <span class="k">def</span> <span class="nf">_store_bands</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bands</span><span class="p">,</span> <span class="n">gt</span><span class="p">):</span> - <span class="sd">"""Write the bands of interest to a dictionary.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> bands : `list` [`str`]</span> -<span class="sd"> Paths to the .tif files of the bands of the scene.</span> -<span class="sd"> gt : `str`</span> -<span class="sd"> Path to the ground truth of the scene.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scene_data : `dict`</span> -<span class="sd"> The scene data dictionary with keys:</span> -<span class="sd"> ``'band_name_1'``</span> -<span class="sd"> Path to the .tif file of band_1.</span> -<span class="sd"> ``'band_name_2'``</span> -<span class="sd"> Path to the .tif file of band_2.</span> -<span class="sd"> ``'band_name_n'``</span> -<span class="sd"> Path to the .tif file of band_n.</span> -<span class="sd"> ``'gt'``</span> -<span class="sd"> Path to the ground truth file.</span> - -<span class="sd"> """</span> - <span class="c1"># store the bands of interest in a dictionary</span> - <span class="n">scene_data</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">b</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">bands</span><span class="p">):</span> - <span class="n">band</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_band_number</span><span class="p">(</span><span class="n">b</span><span class="p">)]</span> - <span class="k">if</span> <span class="n">band</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_bands</span><span class="p">:</span> - <span class="n">scene_data</span><span class="p">[</span><span class="n">band</span><span class="p">]</span> <span class="o">=</span> <span class="n">b</span> - - <span class="c1"># store ground truth</span> - <span class="n">scene_data</span><span class="p">[</span><span class="s1">'gt'</span><span class="p">]</span> <span class="o">=</span> <span class="n">gt</span> - - <span class="k">return</span> <span class="n">scene_data</span> - -<div class="viewcode-block" id="StandardEoDataset.compose_scenes"><a class="viewcode-back" href="../../source/core.html#core.dataset.StandardEoDataset.compose_scenes">[docs]</a> <span class="k">def</span> <span class="nf">compose_scenes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Build the list of samples of the dataset.</span> - -<span class="sd"> Each sample is represented by a dictionary.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scenes : `list` [`dict`]</span> -<span class="sd"> Each item in ``scenes`` is a `dict` with keys:</span> -<span class="sd"> ``'band_name_1'``</span> -<span class="sd"> Path to the file of band_1.</span> -<span class="sd"> ``'band_name_2'``</span> -<span class="sd"> Path to the file of band_2.</span> -<span class="sd"> ``'band_name_n'``</span> -<span class="sd"> Path to the file of band_n.</span> -<span class="sd"> ``'gt'``</span> -<span class="sd"> Path to the ground truth file.</span> -<span class="sd"> ``'date'``</span> -<span class="sd"> The date of the sample.</span> -<span class="sd"> ``'tile'``</span> -<span class="sd"> The tile id of the sample.</span> -<span class="sd"> ``'transform'``</span> -<span class="sd"> The transformation to apply.</span> -<span class="sd"> ``'id'``</span> -<span class="sd"> The scene identifier.</span> - -<span class="sd"> """</span> - <span class="c1"># search the root directory</span> - <span class="n">scenes</span> <span class="o">=</span> <span class="p">[]</span> - <span class="bp">self</span><span class="o">.</span><span class="n">gt</span> <span class="o">=</span> <span class="p">[]</span> - <span class="k">for</span> <span class="n">dirpath</span><span class="p">,</span> <span class="n">dirname</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</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="c1"># search for a ground truth in the current directory</span> - <span class="bp">self</span><span class="o">.</span><span class="n">gt</span><span class="o">.</span><span class="n">extend</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">join</span><span class="p">(</span><span class="n">dirpath</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">files</span> - <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">gt_pattern</span><span class="p">,</span> <span class="n">f</span><span class="p">)])</span> - - <span class="c1"># check if the current directory name matches a scene identifier</span> - <span class="n">scene</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse_scene_id</span><span class="p">(</span><span class="n">dirpath</span><span class="p">)</span> - - <span class="k">if</span> <span class="n">scene</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - - <span class="c1"># get the date of the current scene</span> - <span class="n">date</span> <span class="o">=</span> <span class="n">scene</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> - - <span class="c1"># list the spectral bands of the scene</span> - <span class="n">bands</span> <span class="o">=</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">join</span><span class="p">(</span><span class="n">dirpath</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">files</span> - <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s1">'B</span><span class="se">\\</span><span class="s1">dA|B</span><span class="se">\\</span><span class="s1">d{1,2}'</span><span class="p">,</span> <span class="n">f</span><span class="p">)]</span> - - <span class="c1"># get the ground truth mask</span> - <span class="k">try</span><span class="p">:</span> - <span class="n">gt</span> <span class="o">=</span> <span class="p">[</span><span class="n">truth</span> <span class="k">for</span> <span class="n">truth</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">gt</span> <span class="k">if</span> <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="ow">in</span> <span class="n">truth</span><span class="p">]</span> - <span class="n">gt</span> <span class="o">=</span> <span class="n">gt</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span> - - <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Skipping scene </span><span class="si">{}</span><span class="s1">: ground truth not available'</span> - <span class="s1">' (pattern = </span><span class="si">{}</span><span class="s1">).'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">],</span> - <span class="bp">self</span><span class="o">.</span><span class="n">gt_pattern</span><span class="p">))</span> - <span class="k">continue</span> - - <span class="c1"># iterate over the tiles</span> - <span class="k">for</span> <span class="n">tile</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tiles</span><span class="p">):</span> - - <span class="c1"># iterate over the transformations to apply</span> - <span class="k">for</span> <span class="n">transf</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span><span class="p">:</span> - - <span class="c1"># store the bands and the ground truth mask of the tile</span> - <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_store_bands</span><span class="p">(</span><span class="n">bands</span><span class="p">,</span> <span class="n">gt</span><span class="p">)</span> - - <span class="c1"># the name of the scene</span> - <span class="n">data</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="o">=</span> <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> - - <span class="c1"># store tile number</span> - <span class="n">data</span><span class="p">[</span><span class="s1">'tile'</span><span class="p">]</span> <span class="o">=</span> <span class="n">tile</span> - - <span class="c1"># store date</span> - <span class="n">data</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">date</span> - - <span class="c1"># store optional transformation</span> - <span class="n">data</span><span class="p">[</span><span class="s1">'transform'</span><span class="p">]</span> <span class="o">=</span> <span class="n">transf</span> - - <span class="c1"># append to list</span> - <span class="n">scenes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> - - <span class="c1"># sort list of scenes and ground truths in chronological order</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sort</span><span class="p">:</span> - <span class="n">scenes</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">k</span><span class="p">:</span> <span class="n">k</span><span class="p">[</span><span class="s1">'date'</span><span class="p">])</span> - <span class="bp">self</span><span class="o">.</span><span class="n">gt</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">k</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse_scene_id</span><span class="p">(</span><span class="n">k</span><span class="p">)[</span><span class="s1">'date'</span><span class="p">])</span> - - <span class="k">return</span> <span class="n">scenes</span></div></div> - - -<div class="viewcode-block" id="SparcsDataset"><a class="viewcode-back" href="../../source/core.html#core.dataset.SparcsDataset">[docs]</a><span class="k">class</span> <span class="nc">SparcsDataset</span><span class="p">(</span><span class="n">StandardEoDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the `Sparcs`_ dataset.</span> - -<span class="sd"> .. _Sparcs:</span> -<span class="sd"> https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> - <span class="c1"># initialize super class StandardEoDataset</span> - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="p">,</span> - <span class="n">sort</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">transforms</span><span class="p">)</span> - -<div class="viewcode-block" id="SparcsDataset.get_size"><a class="viewcode-back" href="../../source/core.html#core.dataset.SparcsDataset.get_size">[docs]</a> <span class="k">def</span> <span class="nf">get_size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Image size of the Sparcs dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> size : `tuple`</span> -<span class="sd"> The image size (height, width).</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span></div> - -<div class="viewcode-block" id="SparcsDataset.get_sensor"><a class="viewcode-back" href="../../source/core.html#core.dataset.SparcsDataset.get_sensor">[docs]</a> <span class="k">def</span> <span class="nf">get_sensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Landsat 8 bands of the Sparcs dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> sensor : `enum.Enum`</span> -<span class="sd"> An enumeration of the bands of the sensor.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">Landsat8</span></div> - -<div class="viewcode-block" id="SparcsDataset.get_labels"><a class="viewcode-back" href="../../source/core.html#core.dataset.SparcsDataset.get_labels">[docs]</a> <span class="k">def</span> <span class="nf">get_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Class labels of the Sparcs dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> labels : `enum.Enum`</span> -<span class="sd"> The class labels.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">SparcsLabels</span></div> - -<div class="viewcode-block" id="SparcsDataset.preprocess"><a class="viewcode-back" href="../../source/core.html#core.dataset.SparcsDataset.preprocess">[docs]</a> <span class="k">def</span> <span class="nf">preprocess</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">gt</span><span class="p">):</span> - <span class="sd">"""Preprocess Sparcs dataset images.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> data : `numpy.ndarray`</span> -<span class="sd"> The sample input data.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The sample ground truth.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> data : `numpy.ndarray`</span> -<span class="sd"> The preprocessed input data.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The preprocessed ground truth data.</span> - -<span class="sd"> """</span> - <span class="c1"># if the preprocessing is not done externally, implement it here</span> - <span class="k">return</span> <span class="n">data</span><span class="p">,</span> <span class="n">gt</span></div> - -<div class="viewcode-block" id="SparcsDataset.parse_scene_id"><a class="viewcode-back" href="../../source/core.html#core.dataset.SparcsDataset.parse_scene_id">[docs]</a> <span class="k">def</span> <span class="nf">parse_scene_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scene_id</span><span class="p">):</span> - <span class="sd">"""Parse Sparcs scene identifiers (Landsat 8).</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> scene_id : `str`</span> -<span class="sd"> A scene identifier.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scene : `dict` or `None`</span> -<span class="sd"> A dictionary containing scene metadata. If `None`, ``scene_id`` is</span> -<span class="sd"> not a valid Landsat scene identifier.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">parse_landsat_scene</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="ProSnowDataset"><a class="viewcode-back" href="../../source/core.html#core.dataset.ProSnowDataset">[docs]</a><span class="k">class</span> <span class="nc">ProSnowDataset</span><span class="p">(</span><span class="n">StandardEoDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the ProSnow datasets.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> - <span class="c1"># initialize super class StandardEoDataset</span> - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="p">,</span> - <span class="n">sort</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">transforms</span><span class="p">)</span> - -<div class="viewcode-block" id="ProSnowDataset.get_sensor"><a class="viewcode-back" href="../../source/core.html#core.dataset.ProSnowDataset.get_sensor">[docs]</a> <span class="k">def</span> <span class="nf">get_sensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Sentinel 2 bands of the ProSnow datasets.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> sensor : `enum.Enum`</span> -<span class="sd"> An enumeration of the bands of the sensor.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">Sentinel2</span></div> - -<div class="viewcode-block" id="ProSnowDataset.get_labels"><a class="viewcode-back" href="../../source/core.html#core.dataset.ProSnowDataset.get_labels">[docs]</a> <span class="k">def</span> <span class="nf">get_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Class labels of the ProSnow datasets.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> labels : `enum.Enum`</span> -<span class="sd"> The class labels.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">ProSnowLabels</span></div> - -<div class="viewcode-block" id="ProSnowDataset.preprocess"><a class="viewcode-back" href="../../source/core.html#core.dataset.ProSnowDataset.preprocess">[docs]</a> <span class="k">def</span> <span class="nf">preprocess</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">gt</span><span class="p">):</span> - <span class="sd">"""Preprocess ProSnow dataset images.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> data : `numpy.ndarray`</span> -<span class="sd"> The sample input data.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The sample ground truth.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> data : `numpy.ndarray`</span> -<span class="sd"> The preprocessed input data.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The preprocessed ground truth data.</span> - -<span class="sd"> """</span> - <span class="c1"># if the preprocessing is not done externally, implement it here</span> - <span class="k">return</span> <span class="n">data</span><span class="p">,</span> <span class="n">gt</span></div> - -<div class="viewcode-block" id="ProSnowDataset.parse_scene_id"><a class="viewcode-back" href="../../source/core.html#core.dataset.ProSnowDataset.parse_scene_id">[docs]</a> <span class="k">def</span> <span class="nf">parse_scene_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scene_id</span><span class="p">):</span> - <span class="sd">"""Parse ProSnow scene identifiers (Sentinel 2).</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> scene_id : `str`</span> -<span class="sd"> A scene identifier.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scene : `dict` or `None`</span> -<span class="sd"> A dictionary containing scene metadata. If `None`, ``scene_id`` is</span> -<span class="sd"> not a valid Sentinel-2 scene identifier.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">parse_sentinel2_scene</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="ProSnowGarmisch"><a class="viewcode-back" href="../../source/core.html#core.dataset.ProSnowGarmisch">[docs]</a><span class="k">class</span> <span class="nc">ProSnowGarmisch</span><span class="p">(</span><span class="n">ProSnowDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the ProSnow Garmisch dataset.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> - <span class="c1"># initialize super class StandardEoDataset</span> - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="p">,</span> - <span class="n">sort</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">transforms</span><span class="p">)</span> - -<div class="viewcode-block" id="ProSnowGarmisch.get_size"><a class="viewcode-back" href="../../source/core.html#core.dataset.ProSnowGarmisch.get_size">[docs]</a> <span class="k">def</span> <span class="nf">get_size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Image size of the ProSnow Garmisch dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> size : `tuple`</span> -<span class="sd"> The image size (height, width).</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="p">(</span><span class="mi">615</span><span class="p">,</span> <span class="mi">543</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="ProSnowObergurgl"><a class="viewcode-back" href="../../source/core.html#core.dataset.ProSnowObergurgl">[docs]</a><span class="k">class</span> <span class="nc">ProSnowObergurgl</span><span class="p">(</span><span class="n">ProSnowDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the ProSnow Obergurgl dataset.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> - <span class="c1"># initialize super class StandardEoDataset</span> - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="p">,</span> - <span class="n">sort</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">transforms</span><span class="p">)</span> - -<div class="viewcode-block" id="ProSnowObergurgl.get_size"><a class="viewcode-back" href="../../source/core.html#core.dataset.ProSnowObergurgl.get_size">[docs]</a> <span class="k">def</span> <span class="nf">get_size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Image size of the ProSnow Obergurgl dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> size : `tuple`</span> -<span class="sd"> The image size (height, width).</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="p">(</span><span class="mi">310</span><span class="p">,</span> <span class="mi">270</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="Cloud95Dataset"><a class="viewcode-back" href="../../source/core.html#core.dataset.Cloud95Dataset">[docs]</a><span class="k">class</span> <span class="nc">Cloud95Dataset</span><span class="p">(</span><span class="n">ImageDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the `Cloud-95`_ dataset by `Mohajerani et al. (2020)`_.</span> - -<span class="sd"> .. _Cloud95:</span> -<span class="sd"> https://github.com/SorourMo/95-Cloud-An-Extension-to-38-Cloud-Dataset</span> -<span class="sd"> .. _`Mohajerani et al. (2020)`:</span> -<span class="sd"> https://arxiv.org/abs/2001.08768</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> - <span class="c1"># initialize super class StandardEoDataset</span> - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="p">,</span> - <span class="n">sort</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">transforms</span><span class="p">)</span> - - <span class="c1"># the csv file containing the names of the informative patches</span> - <span class="c1"># patches with more than 80% black pixels, i.e. patches resulting from</span> - <span class="c1"># the black margins around a Landsat 8 scene are excluded</span> - <span class="bp">self</span><span class="o">.</span><span class="n">exclude</span> <span class="o">=</span> <span class="s1">'training_patches_95-cloud_nonempty.csv'</span> - -<div class="viewcode-block" id="Cloud95Dataset.get_size"><a class="viewcode-back" href="../../source/core.html#core.dataset.Cloud95Dataset.get_size">[docs]</a> <span class="k">def</span> <span class="nf">get_size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Image size of the Cloud-95 dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> size : `tuple`</span> -<span class="sd"> The image size (height, width).</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="p">(</span><span class="mi">384</span><span class="p">,</span> <span class="mi">384</span><span class="p">)</span></div> - -<div class="viewcode-block" id="Cloud95Dataset.get_sensor"><a class="viewcode-back" href="../../source/core.html#core.dataset.Cloud95Dataset.get_sensor">[docs]</a> <span class="k">def</span> <span class="nf">get_sensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Landsat 8 bands of the Cloud-95 dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> sensor : `enum.Enum`</span> -<span class="sd"> An enumeration of the bands of the sensor.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">Landsat8</span></div> - -<div class="viewcode-block" id="Cloud95Dataset.get_labels"><a class="viewcode-back" href="../../source/core.html#core.dataset.Cloud95Dataset.get_labels">[docs]</a> <span class="k">def</span> <span class="nf">get_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Class labels of the Cloud-95 dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> labels : `enum.Enum`</span> -<span class="sd"> The class labels.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">Cloud95Labels</span></div> - -<div class="viewcode-block" id="Cloud95Dataset.preprocess"><a class="viewcode-back" href="../../source/core.html#core.dataset.Cloud95Dataset.preprocess">[docs]</a> <span class="k">def</span> <span class="nf">preprocess</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">gt</span><span class="p">):</span> - <span class="sd">"""Preprocess Cloud-95 dataset images.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> data : `numpy.ndarray`</span> -<span class="sd"> The sample input data.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The sample ground truth.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> data : `numpy.ndarray`</span> -<span class="sd"> The preprocessed input data.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The preprocessed ground truth data.</span> - -<span class="sd"> """</span> - <span class="c1"># normalize the data</span> - <span class="c1"># here, we use the normalization of the authors of Cloud-95, i.e.</span> - <span class="c1"># Mohajerani and Saeedi (2019, 2020)</span> - <span class="n">data</span> <span class="o">/=</span> <span class="mi">65535</span> - <span class="n">gt</span><span class="p">[</span><span class="n">gt</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cval</span><span class="p">]</span> <span class="o">/=</span> <span class="mi">255</span> - <span class="k">return</span> <span class="n">data</span><span class="p">,</span> <span class="n">gt</span></div> - -<div class="viewcode-block" id="Cloud95Dataset.parse_scene_id"><a class="viewcode-back" href="../../source/core.html#core.dataset.Cloud95Dataset.parse_scene_id">[docs]</a> <span class="k">def</span> <span class="nf">parse_scene_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scene_id</span><span class="p">):</span> - <span class="sd">"""Parse Sparcs scene identifiers (Landsat 8).</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> scene_id : `str`</span> -<span class="sd"> A scene identifier.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scene : `dict` or `None`</span> -<span class="sd"> A dictionary containing scene metadata. If `None`, ``scene_id`` is</span> -<span class="sd"> not a valid Landsat scene identifier.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">parse_landsat_scene</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)</span></div> - -<div class="viewcode-block" id="Cloud95Dataset.compose_scenes"><a class="viewcode-back" href="../../source/core.html#core.dataset.Cloud95Dataset.compose_scenes">[docs]</a> <span class="k">def</span> <span class="nf">compose_scenes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Build the list of samples of the dataset.</span> - -<span class="sd"> Each sample is represented by a dictionary.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scenes : `list` [`dict`]</span> -<span class="sd"> Each item in ``scenes`` is a `dict` with keys:</span> -<span class="sd"> ``'band_name_1'``</span> -<span class="sd"> Path to the file of band_1.</span> -<span class="sd"> ``'band_name_2'``</span> -<span class="sd"> Path to the file of band_2.</span> -<span class="sd"> ``'band_name_n'``</span> -<span class="sd"> Path to the file of band_n.</span> -<span class="sd"> ``'gt'``</span> -<span class="sd"> Path to the ground truth file.</span> -<span class="sd"> ``'date'``</span> -<span class="sd"> The date of the sample.</span> -<span class="sd"> ``'tile'``</span> -<span class="sd"> The tile id of the sample.</span> -<span class="sd"> ``'transform'``</span> -<span class="sd"> The transformation to apply.</span> -<span class="sd"> ``'id'``</span> -<span class="sd"> The scene identifier.</span> - -<span class="sd"> """</span> - <span class="c1"># whether to exclude patches with more than 80% black pixels</span> - <span class="n">ipatches</span> <span class="o">=</span> <span class="p">[]</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">exclude</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - <span class="k">with</span> <span class="nb">open</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">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">exclude</span><span class="p">),</span> <span class="n">newline</span><span class="o">=</span><span class="s1">''</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> - <span class="n">reader</span> <span class="o">=</span> <span class="n">csv</span><span class="o">.</span><span class="n">reader</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> - <span class="c1"># list of informative patches</span> - <span class="n">ipatches</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span><span class="n">chain</span><span class="o">.</span><span class="n">from_iterable</span><span class="p">(</span><span class="n">reader</span><span class="p">))</span> - - <span class="c1"># get the names of the directories containing the tif files of</span> - <span class="c1"># the bands of interest</span> - <span class="n">band_dirs</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">for</span> <span class="n">dirpath</span><span class="p">,</span> <span class="n">dirname</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</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="c1"># check if the current directory path includes the name of a band</span> - <span class="c1"># or the name of the ground truth mask</span> - <span class="n">cband</span> <span class="o">=</span> <span class="p">[</span><span class="n">band</span> <span class="k">for</span> <span class="n">band</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_bands</span> <span class="o">+</span> <span class="p">[</span><span class="s1">'gt'</span><span class="p">]</span> <span class="k">if</span> - <span class="n">dirpath</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="n">band</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">isdir</span><span class="p">(</span><span class="n">dirpath</span><span class="p">)]</span> - - <span class="c1"># add path to current band files to dictionary</span> - <span class="k">if</span> <span class="n">cband</span><span class="p">:</span> - <span class="n">band_dirs</span><span class="p">[</span><span class="n">cband</span><span class="o">.</span><span class="n">pop</span><span class="p">()]</span> <span class="o">=</span> <span class="n">dirpath</span> - - <span class="c1"># create empty list to store all patches to</span> - <span class="n">scenes</span> <span class="o">=</span> <span class="p">[]</span> - - <span class="c1"># iterate over all the patches of the following band</span> - <span class="n">biter</span> <span class="o">=</span> <span class="p">[</span><span class="o">*</span><span class="n">band_dirs</span><span class="o">.</span><span class="n">keys</span><span class="p">()][</span><span class="mi">0</span><span class="p">]</span> - <span class="k">for</span> <span class="n">file</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">band_dirs</span><span class="p">[</span><span class="n">biter</span><span class="p">]):</span> - - <span class="c1"># get name of the current patch</span> - <span class="n">patchname</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">biter</span> <span class="o">+</span> <span class="s1">'_'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> - - <span class="c1"># get the date of the current scene</span> - <span class="n">scene_meta</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse_scene_id</span><span class="p">(</span><span class="n">patchname</span><span class="p">)</span> - - <span class="c1"># check whether the current file is an informative patch</span> - <span class="k">if</span> <span class="n">ipatches</span> <span class="ow">and</span> <span class="n">patchname</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ipatches</span><span class="p">:</span> - <span class="k">continue</span> - - <span class="c1"># iterate over the tiles</span> - <span class="k">for</span> <span class="n">tile</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tiles</span><span class="p">):</span> - - <span class="c1"># iterate over the transformations to apply</span> - <span class="k">for</span> <span class="n">transf</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span><span class="p">:</span> - - <span class="c1"># initialize dictionary to store bands of current patch</span> - <span class="n">scene</span> <span class="o">=</span> <span class="p">{}</span> - - <span class="c1"># iterate over the bands of interest</span> - <span class="k">for</span> <span class="n">band</span> <span class="ow">in</span> <span class="n">band_dirs</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span> - <span class="c1"># save path to current band tif file to dictionary</span> - <span class="n">scene</span><span class="p">[</span><span class="n">band</span><span class="p">]</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="n">band_dirs</span><span class="p">[</span><span class="n">band</span><span class="p">],</span> - <span class="n">file</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">biter</span><span class="p">,</span> <span class="n">band</span><span class="p">))</span> - - <span class="c1"># the name of the scene the patch was extracted from</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="o">=</span> <span class="n">scene_meta</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> - - <span class="c1"># store tile number</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'tile'</span><span class="p">]</span> <span class="o">=</span> <span class="n">tile</span> - - <span class="c1"># store date</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">scene_meta</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> - - <span class="c1"># store optional transformation</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'transform'</span><span class="p">]</span> <span class="o">=</span> <span class="n">transf</span> - - <span class="c1"># append patch to list of all patches</span> - <span class="n">scenes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">scene</span><span class="p">)</span> - - <span class="c1"># sort list of scenes in chronological order</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sort</span><span class="p">:</span> - <span class="n">scenes</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">k</span><span class="p">:</span> <span class="n">k</span><span class="p">[</span><span class="s1">'date'</span><span class="p">])</span> - - <span class="k">return</span> <span class="n">scenes</span></div></div> - - -<div class="viewcode-block" id="SupportedDatasets"><a class="viewcode-back" href="../../source/core.html#core.dataset.SupportedDatasets">[docs]</a><span class="k">class</span> <span class="nc">SupportedDatasets</span><span class="p">(</span><span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">):</span> - <span class="sd">"""Names and corresponding classes of the implemented datasets."""</span> - - <span class="n">Sparcs</span> <span class="o">=</span> <span class="n">SparcsDataset</span> - <span class="n">Cloud95</span> <span class="o">=</span> <span class="n">Cloud95Dataset</span> - <span class="n">Garmisch</span> <span class="o">=</span> <span class="n">ProSnowGarmisch</span> - <span class="n">Obergurgl</span> <span class="o">=</span> <span class="n">ProSnowObergurgl</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/graphics.html b/docs/_build/html/_modules/core/graphics.html deleted file mode 100644 index 4ed801e9a6fad5fb01791535cea76224e5445f75..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/graphics.html +++ /dev/null @@ -1,592 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.graphics — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.graphics</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.graphics</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Functions to plot multispectral image data and model output.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">os</span> -<span class="kn">import</span> <span class="nn">itertools</span> - -<span class="c1"># externals</span> -<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> -<span class="kn">import</span> <span class="nn">torch</span> -<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> -<span class="kn">import</span> <span class="nn">matplotlib.patches</span> <span class="k">as</span> <span class="nn">mpatches</span> -<span class="kn">import</span> <span class="nn">matplotlib.lines</span> <span class="k">as</span> <span class="nn">mlines</span> -<span class="kn">from</span> <span class="nn">matplotlib.colors</span> <span class="kn">import</span> <span class="n">ListedColormap</span><span class="p">,</span> <span class="n">BoundaryNorm</span> -<span class="kn">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">cm</span> <span class="k">as</span> <span class="n">colormap</span> - -<span class="c1"># locals</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.trainer</span> <span class="kn">import</span> <span class="n">accuracy_function</span> -<span class="kn">from</span> <span class="nn">pysegcnn.main.config</span> <span class="kn">import</span> <span class="n">HERE</span> - - -<div class="viewcode-block" id="contrast_stretching"><a class="viewcode-back" href="../../source/core.html#core.graphics.contrast_stretching">[docs]</a><span class="k">def</span> <span class="nf">contrast_stretching</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mi">5</span><span class="p">):</span> - <span class="sd">"""Apply percentile stretching to an image to increase constrast.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> the input image.</span> -<span class="sd"> alpha : `int`, optional</span> -<span class="sd"> The level of the percentiles. The default is 5.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> norm : `numpy.ndarray`</span> -<span class="sd"> the stretched image.</span> - -<span class="sd"> """</span> - <span class="c1"># compute upper and lower percentiles defining the range of the stretch</span> - <span class="n">inf</span><span class="p">,</span> <span class="n">sup</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">percentile</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="p">(</span><span class="n">alpha</span><span class="p">,</span> <span class="mi">100</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">))</span> - - <span class="c1"># normalize image intensity distribution to</span> - <span class="c1"># (alpha, 100 - alpha) percentiles</span> - <span class="n">norm</span> <span class="o">=</span> <span class="p">((</span><span class="n">image</span> <span class="o">-</span> <span class="n">inf</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> <span class="o">-</span> <span class="n">image</span><span class="o">.</span><span class="n">min</span><span class="p">())</span> <span class="o">/</span> - <span class="p">(</span><span class="n">sup</span> <span class="o">-</span> <span class="n">inf</span><span class="p">))</span> <span class="o">+</span> <span class="n">image</span><span class="o">.</span><span class="n">min</span><span class="p">()</span> - - <span class="c1"># clip: values < min = min, values > max = max</span> - <span class="n">norm</span><span class="p">[</span><span class="n">norm</span> <span class="o"><=</span> <span class="n">image</span><span class="o">.</span><span class="n">min</span><span class="p">()]</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">min</span><span class="p">()</span> - <span class="n">norm</span><span class="p">[</span><span class="n">norm</span> <span class="o">>=</span> <span class="n">image</span><span class="o">.</span><span class="n">max</span><span class="p">()]</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> - - <span class="k">return</span> <span class="n">norm</span></div> - - -<div class="viewcode-block" id="running_mean"><a class="viewcode-back" href="../../source/core.html#core.graphics.running_mean">[docs]</a><span class="k">def</span> <span class="nf">running_mean</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">w</span><span class="p">):</span> - <span class="sd">"""Compute a running mean of the input sequence.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : array_like</span> -<span class="sd"> The sequence to compute a running mean on.</span> -<span class="sd"> w : `int`</span> -<span class="sd"> The window length of the running mean.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> rm : `numpy.ndarray`</span> -<span class="sd"> The running mean of the sequence ``x``.</span> - -<span class="sd"> """</span> - <span class="n">cumsum</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cumsum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="n">x</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="k">return</span> <span class="p">(</span><span class="n">cumsum</span><span class="p">[</span><span class="n">w</span><span class="p">:]</span> <span class="o">-</span> <span class="n">cumsum</span><span class="p">[:</span><span class="o">-</span><span class="n">w</span><span class="p">])</span> <span class="o">/</span> <span class="n">w</span></div> - - -<div class="viewcode-block" id="plot_sample"><a class="viewcode-back" href="../../source/core.html#core.graphics.plot_sample">[docs]</a><span class="k">def</span> <span class="nf">plot_sample</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">use_bands</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">y_pred</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> - <span class="n">bands</span><span class="o">=</span><span class="p">[</span><span class="s1">'nir'</span><span class="p">,</span> <span class="s1">'red'</span><span class="p">,</span> <span class="s1">'green'</span><span class="p">],</span> <span class="n">state</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> - <span class="n">outpath</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="n">HERE</span><span class="p">,</span> <span class="s1">'_samples/'</span><span class="p">),</span> <span class="n">alpha</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span> - <span class="sd">"""Plot false color composite (FCC), ground truth and model prediction.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `numpy.ndarray` or `torch.Tensor`, (b, h, w)</span> -<span class="sd"> Array containing the raw data of the tile, shape=(bands, height, width)</span> -<span class="sd"> use_bands : `list` of `str`</span> -<span class="sd"> List describing the order of the bands in ``x``.</span> -<span class="sd"> labels : `dict` [`int`, `dict`]</span> -<span class="sd"> The label dictionary. The keys are the values of the class labels</span> -<span class="sd"> in the ground truth ``y``. Each nested `dict` should have keys:</span> -<span class="sd"> ``'color'``</span> -<span class="sd"> A named color (`str`).</span> -<span class="sd"> ``'label'``</span> -<span class="sd"> The name of the class label (`str`).</span> -<span class="sd"> y : `numpy.ndarray` or `torch.Tensor` or `None`, optional</span> -<span class="sd"> Array containing the ground truth of tile ``x``, shape=(height, width).</span> -<span class="sd"> The default is None.</span> -<span class="sd"> y_pred : `numpy.ndarray` or `torch.Tensor` or `None`, optional</span> -<span class="sd"> Array containing the prediction for tile ``x``, shape=(height, width).</span> -<span class="sd"> The default is None.</span> -<span class="sd"> figsize : `tuple`, optional</span> -<span class="sd"> The figure size in centimeters. The default is (10, 10).</span> -<span class="sd"> bands : `list` [`str`], optional</span> -<span class="sd"> The bands to build the FCC. The default is ['nir', 'red', 'green'].</span> -<span class="sd"> state : `str` or `None`, optional</span> -<span class="sd"> Filename to save the plot to. ``state`` should be an existing model</span> -<span class="sd"> state file ending with '.pt'. The default is None, i.e. plot is not</span> -<span class="sd"> saved to disk.</span> -<span class="sd"> outpath : `str` or `pathlib.Path`, optional</span> -<span class="sd"> Output path. The default is 'pysegcnn/main/_samples'.</span> -<span class="sd"> alpha : `int`, optional</span> -<span class="sd"> The level of the percentiles to increase constrast in the FCC.</span> -<span class="sd"> The default is 0, i.e. no stretching.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> fig : `matplotlib.figure.Figure`</span> -<span class="sd"> The figure handle.</span> -<span class="sd"> ax : `numpy.ndarray` [`matplotlib.axes._subplots.AxesSubplot`]</span> -<span class="sd"> An array of the axes handles.</span> - -<span class="sd"> """</span> - <span class="c1"># check whether to apply constrast stretching</span> - <span class="n">rgb</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dstack</span><span class="p">([</span><span class="n">contrast_stretching</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">use_bands</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">band</span><span class="p">)],</span> <span class="n">alpha</span><span class="p">)</span> - <span class="k">for</span> <span class="n">band</span> <span class="ow">in</span> <span class="n">bands</span><span class="p">])</span> - - <span class="c1"># get labels and corresponding colors</span> - <span class="n">ulabels</span> <span class="o">=</span> <span class="p">[</span><span class="n">label</span><span class="p">[</span><span class="s1">'label'</span><span class="p">]</span> <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">labels</span><span class="o">.</span><span class="n">values</span><span class="p">()]</span> - <span class="n">colors</span> <span class="o">=</span> <span class="p">[</span><span class="n">label</span><span class="p">[</span><span class="s1">'color'</span><span class="p">]</span> <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">labels</span><span class="o">.</span><span class="n">values</span><span class="p">()]</span> - - <span class="c1"># create a ListedColormap</span> - <span class="n">cmap</span> <span class="o">=</span> <span class="n">ListedColormap</span><span class="p">(</span><span class="n">colors</span><span class="p">)</span> - <span class="n">boundaries</span> <span class="o">=</span> <span class="p">[</span><span class="o">*</span><span class="n">labels</span><span class="o">.</span><span class="n">keys</span><span class="p">(),</span> <span class="n">cmap</span><span class="o">.</span><span class="n">N</span><span class="p">]</span> - <span class="n">norm</span> <span class="o">=</span> <span class="n">BoundaryNorm</span><span class="p">(</span><span class="n">boundaries</span><span class="p">,</span> <span class="n">cmap</span><span class="o">.</span><span class="n">N</span><span class="p">)</span> - - <span class="c1"># create a patch (proxy artist) for every color</span> - <span class="n">patches</span> <span class="o">=</span> <span class="p">[</span><span class="n">mpatches</span><span class="o">.</span><span class="n">Patch</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="n">c</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">l</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span><span class="p">,</span> <span class="n">l</span> <span class="ow">in</span> - <span class="nb">zip</span><span class="p">(</span><span class="n">colors</span><span class="p">,</span> <span class="n">ulabels</span><span class="p">)]</span> - - <span class="c1"># initialize figure</span> - <span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="n">figsize</span><span class="p">)</span> - - <span class="c1"># plot false color composite</span> - <span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">rgb</span><span class="p">)</span> - <span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'R = </span><span class="si">{}</span><span class="s1">, G = </span><span class="si">{}</span><span class="s1">, B = </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">*</span><span class="n">bands</span><span class="p">),</span> <span class="n">pad</span><span class="o">=</span><span class="mi">15</span><span class="p">)</span> - - <span class="c1"># check whether to plot ground truth</span> - <span class="n">acc</span> <span class="o">=</span> <span class="kc">None</span> - <span class="k">if</span> <span class="n">y</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> - <span class="c1"># remove axis to plot ground truth from figure</span> - <span class="n">fig</span><span class="o">.</span><span class="n">delaxes</span><span class="p">(</span><span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> - <span class="k">else</span><span class="p">:</span> - <span class="c1"># plot ground thruth mask</span> - <span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="n">cmap</span><span class="p">,</span> <span class="n">interpolation</span><span class="o">=</span><span class="s1">'nearest'</span><span class="p">,</span> <span class="n">norm</span><span class="o">=</span><span class="n">norm</span><span class="p">)</span> - <span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'Ground truth'</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="mi">15</span><span class="p">)</span> - - <span class="c1"># check whether to plot model prediction</span> - <span class="k">if</span> <span class="n">y_pred</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> - <span class="c1"># remove axis to plot model prediction from figure</span> - <span class="n">fig</span><span class="o">.</span><span class="n">delaxes</span><span class="p">(</span><span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> - <span class="k">else</span><span class="p">:</span> - <span class="c1"># plot model prediction</span> - <span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="n">cmap</span><span class="p">,</span> <span class="n">interpolation</span><span class="o">=</span><span class="s1">'nearest'</span><span class="p">,</span> <span class="n">norm</span><span class="o">=</span><span class="n">norm</span><span class="p">)</span> - - <span class="c1"># set title</span> - <span class="n">title</span> <span class="o">=</span> <span class="s1">'Prediction'</span> - <span class="k">if</span> <span class="n">y</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - <span class="n">acc</span> <span class="o">=</span> <span class="n">accuracy_function</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span> - <span class="n">title</span> <span class="o">+=</span> <span class="s1">' (</span><span class="si">{:.2f}</span><span class="s1">%)'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">acc</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span> - <span class="n">ax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="n">title</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="mi">15</span><span class="p">)</span> - - <span class="c1"># if a ground truth or a model prediction is plotted, add legend</span> - <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">fig</span><span class="o">.</span><span class="n">axes</span><span class="p">)</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> - <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles</span><span class="o">=</span><span class="n">patches</span><span class="p">,</span> <span class="n">bbox_to_anchor</span><span class="o">=</span><span class="p">(</span><span class="mf">1.05</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">loc</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> - <span class="n">frameon</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> - - <span class="c1"># save figure</span> - <span class="k">if</span> <span class="n">state</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">outpath</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - <span class="n">fig</span><span class="o">.</span><span class="n">savefig</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">join</span><span class="p">(</span><span class="n">outpath</span><span class="p">,</span> <span class="n">state</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'.pt'</span><span class="p">,</span> <span class="s1">'.png'</span><span class="p">)),</span> - <span class="n">dpi</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span> <span class="n">bbox_inches</span><span class="o">=</span><span class="s1">'tight'</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">fig</span><span class="p">,</span> <span class="n">ax</span></div> - - -<div class="viewcode-block" id="plot_confusion_matrix"><a class="viewcode-back" href="../../source/core.html#core.graphics.plot_confusion_matrix">[docs]</a><span class="k">def</span> <span class="nf">plot_confusion_matrix</span><span class="p">(</span><span class="n">cm</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">normalize</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> - <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">'Blues'</span><span class="p">,</span> <span class="n">state</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> - <span class="n">outpath</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="n">HERE</span><span class="p">,</span> <span class="s1">'_graphics/'</span><span class="p">)):</span> - <span class="sd">"""Plot the confusion matrix ``cm``.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> cm : `numpy.ndarray`</span> -<span class="sd"> The confusion matrix.</span> -<span class="sd"> labels : `dict` [`int`, `dict`]</span> -<span class="sd"> The label dictionary. The keys are the values of the class labels</span> -<span class="sd"> in the ground truth ``y``. Each nested `dict` should have keys:</span> -<span class="sd"> ``'color'``</span> -<span class="sd"> A named color (`str`).</span> -<span class="sd"> ``'label'``</span> -<span class="sd"> The name of the class label (`str`).</span> -<span class="sd"> normalize : `bool`, optional</span> -<span class="sd"> Whether to normalize the confusion matrix. The default is True.</span> -<span class="sd"> figsize : `tuple`, optional</span> -<span class="sd"> The figure size in centimeters. The default is (10, 10).</span> -<span class="sd"> cmap : `str`, optional</span> -<span class="sd"> A colormap in `matplotlib.pyplot.colormaps()`. The default is 'Blues'.</span> -<span class="sd"> state : `str` or `None`, optional</span> -<span class="sd"> Filename to save the plot to. ``state`` should be an existing model</span> -<span class="sd"> state file ending with '.pt'. The default is None, i.e. plot is not</span> -<span class="sd"> saved to disk.</span> -<span class="sd"> outpath : `str` or `pathlib.Path`, optional</span> -<span class="sd"> Output path. The default is 'pysegcnn/main/_graphics/'.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> fig : `matplotlib.figure.Figure`</span> -<span class="sd"> The figure handle.</span> -<span class="sd"> ax : `matplotlib.axes._subplots.AxesSubplot`</span> -<span class="sd"> The axes handle.</span> - -<span class="sd"> """</span> - <span class="c1"># number of classes</span> - <span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">label</span><span class="p">[</span><span class="s1">'label'</span><span class="p">]</span> <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">labels</span><span class="o">.</span><span class="n">values</span><span class="p">()]</span> - <span class="n">nclasses</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">labels</span><span class="p">)</span> - - <span class="c1"># string format to plot values of confusion matrix</span> - <span class="n">fmt</span> <span class="o">=</span> <span class="s1">'.0f'</span> - - <span class="c1"># minimum and maximum values of the colorbar</span> - <span class="n">vmin</span><span class="p">,</span> <span class="n">vmax</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">cm</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> - - <span class="c1"># check whether to normalize the confusion matrix</span> - <span class="k">if</span> <span class="n">normalize</span><span class="p">:</span> - <span class="c1"># normalize</span> - <span class="n">norm</span> <span class="o">=</span> <span class="n">cm</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - - <span class="c1"># check for division by zero</span> - <span class="n">norm</span><span class="p">[</span><span class="n">norm</span> <span class="o">==</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> - <span class="n">cm</span> <span class="o">=</span> <span class="n">cm</span> <span class="o">/</span> <span class="n">norm</span> - - <span class="c1"># change string format to floating point</span> - <span class="n">fmt</span> <span class="o">=</span> <span class="s1">'.2f'</span> - <span class="n">vmin</span><span class="p">,</span> <span class="n">vmax</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> - - <span class="c1"># create figure</span> - <span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="n">figsize</span><span class="p">)</span> - - <span class="c1"># get colormap</span> - <span class="n">cmap</span> <span class="o">=</span> <span class="n">colormap</span><span class="o">.</span><span class="n">get_cmap</span><span class="p">(</span><span class="n">cmap</span><span class="p">,</span> <span class="mi">256</span><span class="p">)</span> - - <span class="c1"># plot confusion matrix</span> - <span class="n">im</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">cm</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="n">cmap</span><span class="p">,</span> <span class="n">vmin</span><span class="o">=</span><span class="n">vmin</span><span class="p">,</span> <span class="n">vmax</span><span class="o">=</span><span class="n">vmax</span><span class="p">)</span> - - <span class="c1"># threshold determining the color of the values</span> - <span class="n">thresh</span> <span class="o">=</span> <span class="p">(</span><span class="n">cm</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> <span class="o">+</span> <span class="n">cm</span><span class="o">.</span><span class="n">min</span><span class="p">())</span> <span class="o">/</span> <span class="mi">2</span> - - <span class="c1"># brightest/darkest color of current colormap</span> - <span class="n">cmap_min</span><span class="p">,</span> <span class="n">cmap_max</span> <span class="o">=</span> <span class="n">cmap</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">cmap</span><span class="p">(</span><span class="mi">256</span><span class="p">)</span> - - <span class="c1"># plot values of confusion matrix</span> - <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">nclasses</span><span class="p">),</span> <span class="nb">range</span><span class="p">(</span><span class="n">nclasses</span><span class="p">)):</span> - <span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="n">j</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="nb">format</span><span class="p">(</span><span class="n">cm</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">],</span> <span class="n">fmt</span><span class="p">),</span> <span class="n">ha</span><span class="o">=</span><span class="s1">'center'</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">'center'</span><span class="p">,</span> - <span class="n">color</span><span class="o">=</span><span class="n">cmap_max</span> <span class="k">if</span> <span class="n">cm</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">]</span> <span class="o"><</span> <span class="n">thresh</span> <span class="k">else</span> <span class="n">cmap_min</span><span class="p">)</span> - - <span class="c1"># axes properties and labels</span> - <span class="n">ax</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">xticks</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">nclasses</span><span class="p">),</span> - <span class="n">yticks</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">nclasses</span><span class="p">),</span> - <span class="n">xticklabels</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span> - <span class="n">yticklabels</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span> - <span class="n">ylabel</span><span class="o">=</span><span class="s1">'True'</span><span class="p">,</span> - <span class="n">xlabel</span><span class="o">=</span><span class="s1">'Predicted'</span><span class="p">)</span> - - <span class="c1"># add colorbar axes</span> - <span class="n">cax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="n">ax</span><span class="o">.</span><span class="n">get_position</span><span class="p">()</span><span class="o">.</span><span class="n">x1</span> <span class="o">+</span> <span class="mf">0.025</span><span class="p">,</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_position</span><span class="p">()</span><span class="o">.</span><span class="n">y0</span><span class="p">,</span> - <span class="mf">0.05</span><span class="p">,</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_position</span><span class="p">()</span><span class="o">.</span><span class="n">y1</span> <span class="o">-</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_position</span><span class="p">()</span><span class="o">.</span><span class="n">y0</span><span class="p">])</span> - <span class="n">fig</span><span class="o">.</span><span class="n">colorbar</span><span class="p">(</span><span class="n">im</span><span class="p">,</span> <span class="n">cax</span><span class="o">=</span><span class="n">cax</span><span class="p">)</span> - - <span class="c1"># save figure</span> - <span class="k">if</span> <span class="n">state</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">outpath</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - <span class="n">fig</span><span class="o">.</span><span class="n">savefig</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">join</span><span class="p">(</span><span class="n">outpath</span><span class="p">,</span> <span class="n">state</span><span class="p">),</span> <span class="n">dpi</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span> <span class="n">bbox_inches</span><span class="o">=</span><span class="s1">'tight'</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">fig</span><span class="p">,</span> <span class="n">ax</span></div> - - -<div class="viewcode-block" id="plot_loss"><a class="viewcode-back" href="../../source/core.html#core.graphics.plot_loss">[docs]</a><span class="k">def</span> <span class="nf">plot_loss</span><span class="p">(</span><span class="n">state_file</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">step</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> - <span class="n">colors</span><span class="o">=</span><span class="p">[</span><span class="s1">'lightgreen'</span><span class="p">,</span> <span class="s1">'green'</span><span class="p">,</span> <span class="s1">'skyblue'</span><span class="p">,</span> <span class="s1">'steelblue'</span><span class="p">],</span> - <span class="n">outpath</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="n">HERE</span><span class="p">,</span> <span class="s1">'_graphics/'</span><span class="p">)):</span> - <span class="sd">"""Plot the observed loss and accuracy of a model run.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> state_file : `str` or `pathlib.Path`</span> -<span class="sd"> The model state file. Model state files are stored in</span> -<span class="sd"> pysegcnn/main/_models.</span> -<span class="sd"> figsize : `tuple`, optional</span> -<span class="sd"> The figure size in centimeters. The default is (10, 10).</span> -<span class="sd"> step : `int`, optional</span> -<span class="sd"> The step of epochs for the x-axis labels. The default is 5, i.e. label</span> -<span class="sd"> each fifth epoch.</span> -<span class="sd"> colors : `list` [`str`], optional</span> -<span class="sd"> A list of four named colors supported by `matplotlib`.</span> -<span class="sd"> The default is ['lightgreen', 'green', 'skyblue', 'steelblue'].</span> -<span class="sd"> outpath : `str` or `pathlib.Path`, optional</span> -<span class="sd"> Output path. The default is 'pysegcnn/main/_graphics/'.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> fig : `matplotlib.figure.Figure`</span> -<span class="sd"> The figure handle.</span> - -<span class="sd"> """</span> - <span class="c1"># load the model state</span> - <span class="n">model_state</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">state_file</span><span class="p">)</span> - - <span class="c1"># get all non-zero elements, i.e. get number of epochs trained before</span> - <span class="c1"># early stop</span> - <span class="n">loss</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">nonzero</span><span class="p">(</span><span class="n">v</span><span class="p">)]</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">v</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="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> - - <span class="c1"># compute running mean with a window equal to the number of batches in</span> - <span class="c1"># an epoch</span> - <span class="n">rm</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">running_mean</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="s1">'F'</span><span class="p">),</span> <span class="n">v</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="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">loss</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> - - <span class="c1"># sort the keys of the dictionary alphabetically</span> - <span class="n">rm</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">rm</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">rm</span><span class="p">)}</span> - - <span class="c1"># number of epochs trained</span> - <span class="n">epochs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">loss</span><span class="p">[</span><span class="s1">'tl'</span><span class="p">]</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="c1"># instanciate figure</span> - <span class="n">fig</span><span class="p">,</span> <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="n">figsize</span><span class="p">)</span> - - <span class="c1"># create axes for each parameter to plot</span> - <span class="n">ax2</span> <span class="o">=</span> <span class="n">ax1</span><span class="o">.</span><span class="n">twinx</span><span class="p">()</span> - <span class="n">ax3</span> <span class="o">=</span> <span class="n">ax1</span><span class="o">.</span><span class="n">twiny</span><span class="p">()</span> - <span class="n">ax4</span> <span class="o">=</span> <span class="n">ax2</span><span class="o">.</span><span class="n">twiny</span><span class="p">()</span> - - <span class="c1"># list of axes</span> - <span class="n">axes</span> <span class="o">=</span> <span class="p">[</span><span class="n">ax2</span><span class="p">,</span> <span class="n">ax1</span><span class="p">,</span> <span class="n">ax4</span><span class="p">,</span> <span class="n">ax3</span><span class="p">]</span> - - <span class="c1"># plot running mean loss and accuracy of the training dataset</span> - <span class="p">[</span><span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">),</span> <span class="n">ax</span><span class="p">,</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">rm</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span> <span class="n">axes</span><span class="p">,</span> <span class="n">colors</span><span class="p">)</span> - <span class="k">if</span> <span class="n">v</span><span class="o">.</span><span class="n">any</span><span class="p">()]</span> - - <span class="c1"># axes properties and labels</span> - <span class="n">nbatches</span> <span class="o">=</span> <span class="n">loss</span><span class="p">[</span><span class="s1">'tl'</span><span class="p">]</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">ax3</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">xticks</span><span class="o">=</span><span class="p">[],</span> <span class="n">xticklabels</span><span class="o">=</span><span class="p">[])</span> - <span class="n">ax4</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">xticks</span><span class="o">=</span><span class="p">[],</span> <span class="n">xticklabels</span><span class="o">=</span><span class="p">[])</span> - <span class="n">ax1</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">xticks</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">nbatches</span> <span class="o">*</span> <span class="n">epochs</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">nbatches</span> <span class="o">*</span> <span class="n">step</span><span class="p">),</span> - <span class="n">xticklabels</span><span class="o">=</span><span class="n">epochs</span><span class="p">[::</span><span class="n">step</span><span class="p">],</span> - <span class="n">xlabel</span><span class="o">=</span><span class="s1">'Epoch'</span><span class="p">,</span> - <span class="n">ylabel</span><span class="o">=</span><span class="s1">'Loss'</span><span class="p">,</span> - <span class="n">ylim</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span> - <span class="n">ax2</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">ylabel</span><span class="o">=</span><span class="s1">'Accuracy'</span><span class="p">,</span> - <span class="n">ylim</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span> - - <span class="c1"># compute early stopping point</span> - <span class="k">if</span> <span class="n">loss</span><span class="p">[</span><span class="s1">'va'</span><span class="p">]</span><span class="o">.</span><span class="n">any</span><span class="p">():</span> - <span class="n">esepoch</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">loss</span><span class="p">[</span><span class="s1">'va'</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span> <span class="o">*</span> <span class="n">nbatches</span> <span class="o">+</span> <span class="mi">1</span> - <span class="n">esacc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">loss</span><span class="p">[</span><span class="s1">'va'</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span> - <span class="n">ax1</span><span class="o">.</span><span class="n">vlines</span><span class="p">(</span><span class="n">esepoch</span><span class="p">,</span> <span class="n">ymin</span><span class="o">=</span><span class="n">ax1</span><span class="o">.</span><span class="n">get_ylim</span><span class="p">()[</span><span class="mi">0</span><span class="p">],</span> <span class="n">ymax</span><span class="o">=</span><span class="n">ax1</span><span class="o">.</span><span class="n">get_ylim</span><span class="p">()[</span><span class="mi">1</span><span class="p">],</span> - <span class="n">ls</span><span class="o">=</span><span class="s1">'--'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'grey'</span><span class="p">)</span> - <span class="n">ax1</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="n">esepoch</span> <span class="o">-</span> <span class="n">nbatches</span><span class="p">,</span> <span class="n">ax1</span><span class="o">.</span><span class="n">get_ylim</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mf">0.01</span><span class="p">,</span> - <span class="s1">'epoch = </span><span class="si">{}</span><span class="s1">, accuracy = </span><span class="si">{:.1f}</span><span class="s1">%'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">esepoch</span> <span class="o">/</span> <span class="n">nbatches</span><span class="p">),</span> <span class="n">esacc</span> <span class="o">*</span> <span class="mi">100</span><span class="p">),</span> - <span class="n">ha</span><span class="o">=</span><span class="s1">'right'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'grey'</span><span class="p">)</span> - - <span class="c1"># create a patch (proxy artist) for every color</span> - <span class="n">ulabels</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'Training accuracy'</span><span class="p">,</span> <span class="s1">'Training loss'</span><span class="p">,</span> - <span class="s1">'Validation accuracy'</span><span class="p">,</span> <span class="s1">'Validation loss'</span><span class="p">]</span> - <span class="n">patches</span> <span class="o">=</span> <span class="p">[</span><span class="n">mlines</span><span class="o">.</span><span class="n">Line2D</span><span class="p">([],</span> <span class="p">[],</span> <span class="n">color</span><span class="o">=</span><span class="n">c</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">l</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span><span class="p">,</span> <span class="n">l</span> <span class="ow">in</span> - <span class="nb">zip</span><span class="p">(</span><span class="n">colors</span><span class="p">,</span> <span class="n">ulabels</span><span class="p">)]</span> - <span class="c1"># plot patches as legend</span> - <span class="n">ax1</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">handles</span><span class="o">=</span><span class="n">patches</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="s1">'lower left'</span><span class="p">,</span> <span class="n">frameon</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> - - <span class="c1"># save figure</span> - <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">outpath</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - <span class="n">fig</span><span class="o">.</span><span class="n">savefig</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">join</span><span class="p">(</span> - <span class="n">outpath</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">basename</span><span class="p">(</span><span class="n">state_file</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'.pt'</span><span class="p">,</span> <span class="s1">'.png'</span><span class="p">)),</span> - <span class="n">dpi</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span> <span class="n">bbox_inches</span><span class="o">=</span><span class="s1">'tight'</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">fig</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/layers.html b/docs/_build/html/_modules/core/layers.html deleted file mode 100644 index 81af4ab31d865ed5ebee3be36baef12f8dd5c715..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/layers.html +++ /dev/null @@ -1,954 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.layers — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.layers</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.layers</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Layers of a convolutional encoder-decoder network.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># externals</span> -<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> -<span class="kn">import</span> <span class="nn">torch</span> -<span class="kn">import</span> <span class="nn">torch.nn</span> <span class="k">as</span> <span class="nn">nn</span> -<span class="kn">import</span> <span class="nn">torch.nn.functional</span> <span class="k">as</span> <span class="nn">F</span> - - -<div class="viewcode-block" id="Conv2dSame"><a class="viewcode-back" href="../../source/core.html#core.layers.Conv2dSame">[docs]</a><span class="k">class</span> <span class="nc">Conv2dSame</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Conv2d</span><span class="p">):</span> - <span class="sd">"""A convolution preserving the shape of its input.</span> - -<span class="sd"> Given the kernel size, the dilation and a stride of 1, the padding is</span> -<span class="sd"> calculated such that the output of the convolution has the same spatial</span> -<span class="sd"> dimensions as the input.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> *args: `list` [`str`]</span> -<span class="sd"> positional arguments passed to `torch.nn.Conv2d`:</span> -<span class="sd"> ``'in_channels'``: `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> ``'out_channels'``: `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> ``'kernel_size'``: `int` or `tuple` [`int`]</span> -<span class="sd"> Size of the convolving kernel.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional keyword arguments passed to `torch.nn.Conv2d`_.</span> - -<span class="sd"> .. _torch.nn.Conv2d:</span> -<span class="sd"> https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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> - <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> - - <span class="c1"># define tensorflows "SAME" padding for stride = 1</span> - <span class="n">x_pad</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">same_padding</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dilation</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> - <span class="n">y_pad</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">same_padding</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dilation</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel_size</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> - - <span class="bp">self</span><span class="o">.</span><span class="n">padding</span> <span class="o">=</span> <span class="p">(</span><span class="n">y_pad</span><span class="p">,</span> <span class="n">x_pad</span><span class="p">)</span> - -<div class="viewcode-block" id="Conv2dSame.same_padding"><a class="viewcode-back" href="../../source/core.html#core.layers.Conv2dSame.same_padding">[docs]</a> <span class="nd">@staticmethod</span> - <span class="k">def</span> <span class="nf">same_padding</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">k</span><span class="p">):</span> - <span class="sd">"""Calculate the amount of padding.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> d : `int`</span> -<span class="sd"> The dilation of the convolution.</span> -<span class="sd"> k : `int`</span> -<span class="sd"> The kernel size.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> p : `int`</span> -<span class="sd"> the amount of padding.</span> - -<span class="sd"> """</span> - <span class="c1"># calculates the padding so that the convolution</span> - <span class="c1"># conserves the shape of its input when stride = 1</span> - <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">d</span> <span class="o">*</span> <span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="conv_bn_relu"><a class="viewcode-back" href="../../source/core.html#core.layers.conv_bn_relu">[docs]</a><span class="k">def</span> <span class="nf">conv_bn_relu</span><span class="p">(</span><span class="n">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <span class="sd">"""Block of convolution, batch normalization and rectified linear unit.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> block : `torch.nn.Sequential` [`torch.nn.Module`]</span> -<span class="sd"> An instance of `torch.nn.Sequential` containing a sequence of</span> -<span class="sd"> convolution, batch normalization and rectified linear unit layers.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">nn</span><span class="o">.</span><span class="n">Sequential</span><span class="p">(</span> - <span class="n">Conv2dSame</span><span class="p">(</span><span class="n">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">),</span> - <span class="n">nn</span><span class="o">.</span><span class="n">BatchNorm2d</span><span class="p">(</span><span class="n">out_channels</span><span class="p">),</span> - <span class="n">nn</span><span class="o">.</span><span class="n">ReLU</span><span class="p">(),</span> - <span class="n">Conv2dSame</span><span class="p">(</span><span class="n">out_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">),</span> - <span class="n">nn</span><span class="o">.</span><span class="n">BatchNorm2d</span><span class="p">(</span><span class="n">out_channels</span><span class="p">),</span> - <span class="n">nn</span><span class="o">.</span><span class="n">ReLU</span><span class="p">()</span> - <span class="p">)</span></div> - - -<div class="viewcode-block" id="Block"><a class="viewcode-back" href="../../source/core.html#core.layers.Block">[docs]</a><span class="k">class</span> <span class="nc">Block</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">):</span> - <span class="sd">"""Basic convolutional block.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if `~pysegcnn.core.layers.Block.layers` method does not return</span> -<span class="sd"> an instance of `torch.nn.Sequential`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - - <span class="c1"># number of input and output channels</span> - <span class="bp">self</span><span class="o">.</span><span class="n">in_channels</span> <span class="o">=</span> <span class="n">in_channels</span> - <span class="bp">self</span><span class="o">.</span><span class="n">out_channels</span> <span class="o">=</span> <span class="n">out_channels</span> - - <span class="c1"># keyword arguments configuring convolutions</span> - <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span> <span class="o">=</span> <span class="n">kwargs</span> - - <span class="c1"># the layers of the block</span> - <span class="bp">self</span><span class="o">.</span><span class="n">conv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">layers</span><span class="p">()</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">conv</span><span class="p">,</span> <span class="n">nn</span><span class="o">.</span><span class="n">Sequential</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1">.layers() should return an instance of </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> - <span class="nb">repr</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Sequential</span><span class="p">)))</span> - -<div class="viewcode-block" id="Block.layers"><a class="viewcode-back" href="../../source/core.html#core.layers.Block.layers">[docs]</a> <span class="k">def</span> <span class="nf">layers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Define the layers of the block.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.layers.Block` is not inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> layers : `torch.nn.Sequential` [`torch.nn.Module`]</span> -<span class="sd"> Return an instance of `torch.nn.Sequential` containing a sequence</span> -<span class="sd"> of layer (`torch.nn.Module` ) instances.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Return an instance of </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Sequential</span><span class="p">)))</span></div> - -<div class="viewcode-block" id="Block.forward"><a class="viewcode-back" href="../../source/core.html#core.layers.Block.forward">[docs]</a> <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Forward pass of the block.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.layers.Block` is not inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Implement the forward pass.'</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="EncoderBlock"><a class="viewcode-back" href="../../source/core.html#core.layers.EncoderBlock">[docs]</a><span class="k">class</span> <span class="nc">EncoderBlock</span><span class="p">(</span><span class="n">Block</span><span class="p">):</span> - <span class="sd">"""Block of a convolutional encoder.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - -<div class="viewcode-block" id="EncoderBlock.forward"><a class="viewcode-back" href="../../source/core.html#core.layers.EncoderBlock.forward">[docs]</a> <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span> - <span class="sd">"""Forward pass of an encoder block.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`</span> -<span class="sd"> Input tensor, e.g. output of the previous block/layer.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> y : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Output of the encoder block.</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Intermediate output before applying downsampling. Useful to</span> -<span class="sd"> implement skip connections.</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> -<span class="sd"> Optional indices of the downsampling method, e.g. indices of the</span> -<span class="sd"> maxima when using `torch.nn.functional.max_pool2d`. Useful for</span> -<span class="sd"> upsampling later. If no indices are required to upsample, simply</span> -<span class="sd"> return ``indices`` = `None`.</span> - -<span class="sd"> """</span> - <span class="c1"># the forward pass of the layers of the block</span> - <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">conv</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> - - <span class="c1"># the downsampling layer</span> - <span class="n">y</span><span class="p">,</span> <span class="n">indices</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">downsample</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> - - <span class="k">return</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">indices</span><span class="p">)</span></div> - -<div class="viewcode-block" id="EncoderBlock.downsample"><a class="viewcode-back" href="../../source/core.html#core.layers.EncoderBlock.downsample">[docs]</a> <span class="k">def</span> <span class="nf">downsample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span> - <span class="sd">"""Define the downsampling method.</span> - -<span class="sd"> The `~pysegcnn.core.layers.EncoderBlock.downsample` method should</span> -<span class="sd"> implement the spatial pooling operation.</span> - -<span class="sd"> Use one of the following functions to downsample:</span> -<span class="sd"> - `torch.nn.functional.max_pool2d`</span> -<span class="sd"> - `torch.nn.functional.interpolate`</span> - -<span class="sd"> See `pysegcnn.core.layers.ConvBnReluMaxPool` for an example</span> -<span class="sd"> implementation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Input tensor, e.g. output of a convolutional block.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.layers.EncoderBlock` is not inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> The spatially downsampled tensor.</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> -<span class="sd"> Optional indices of the downsampling method, e.g. indices of the</span> -<span class="sd"> maxima when using `torch.nn.functional.max_pool2d`. Useful for</span> -<span class="sd"> upsampling later. If no indices are required to upsample, simply</span> -<span class="sd"> return ``indices`` = `None`.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Implement the downsampling function.'</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="DecoderBlock"><a class="viewcode-back" href="../../source/core.html#core.layers.DecoderBlock">[docs]</a><span class="k">class</span> <span class="nc">DecoderBlock</span><span class="p">(</span><span class="n">Block</span><span class="p">):</span> - <span class="sd">"""Block of a convolutional decoder.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - -<div class="viewcode-block" id="DecoderBlock.forward"><a class="viewcode-back" href="../../source/core.html#core.layers.DecoderBlock.forward">[docs]</a> <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">feature</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">skip</span><span class="p">):</span> - <span class="sd">"""Forward pass of a decoder block.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Input tensor.</span> -<span class="sd"> feature : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Intermediate output of a layer in the encoder.</span> -<span class="sd"> If ``skip`` = True, ``feature`` is concatenated (along the channel</span> -<span class="sd"> axis) to the output of the respective upsampling layer in the</span> -<span class="sd"> decoder (skip connection).</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> -<span class="sd"> Indices of the encoder downsampling method.</span> -<span class="sd"> skip : `bool`</span> -<span class="sd"> Whether to apply the skip connection.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Output of the decoder block.</span> - -<span class="sd"> """</span> - <span class="c1"># upsample</span> - <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">upsample</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">feature</span><span class="p">,</span> <span class="n">indices</span><span class="p">)</span> - - <span class="c1"># check whether to apply the skip connection</span> - <span class="c1"># skip connection: concatenate the output of a layer in the encoder to</span> - <span class="c1"># the corresponding layer in the decoder (along the channel axis)</span> - <span class="k">if</span> <span class="n">skip</span><span class="p">:</span> - <span class="n">x</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">cat</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">feature</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> - - <span class="c1"># output of the convolutional layer</span> - <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">conv</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">x</span></div> - -<div class="viewcode-block" id="DecoderBlock.upsample"><a class="viewcode-back" href="../../source/core.html#core.layers.DecoderBlock.upsample">[docs]</a> <span class="k">def</span> <span class="nf">upsample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">feature</span><span class="p">,</span> <span class="n">indices</span><span class="p">):</span> - <span class="sd">"""Define the upsampling method.</span> - -<span class="sd"> The `~pysegcnn.core.layers.DecoderBlock.upsample` method should</span> -<span class="sd"> implement the spatial upsampling operation.</span> - -<span class="sd"> Use one of the following functions to upsample:</span> -<span class="sd"> - `torch.nn.functional.max_unpool2d`</span> -<span class="sd"> - `torch.nn.functional.interpolate`</span> - -<span class="sd"> See `pysegcnn.core.layers.ConvBnReluMaxUnpool` or</span> -<span class="sd"> `pysegcnn.core.layers.ConvBnReluUpsample` for an example</span> -<span class="sd"> implementation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Input tensor, e.g. output of a convolutional block.</span> -<span class="sd"> feature : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Intermediate output of a layer in the encoder. Used to implement</span> -<span class="sd"> skip connections.</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> -<span class="sd"> Indices of the encoder downsampling method.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.layers.DecoderBlock` is not inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> The spatially upsampled tensor.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Implement the upsampling function'</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="Encoder"><a class="viewcode-back" href="../../source/core.html#core.layers.Encoder">[docs]</a><span class="k">class</span> <span class="nc">Encoder</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">):</span> - <span class="sd">"""Generic convolutional encoder.</span> - -<span class="sd"> When instanciating an encoder-decoder architechure, ``filters`` should be</span> -<span class="sd"> the same for `pysegcnn.core.layers.Encoder` and</span> -<span class="sd"> `pysegcnn.core.layers.Decoder`.</span> - -<span class="sd"> See `pysegcnn.core.models.UNet` for an example implementation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> filters : `list` [`int`]</span> -<span class="sd"> List of input channels to each convolutional block. The length of</span> -<span class="sd"> ``filters`` determines the depth of the encoder. The first element of</span> -<span class="sd"> ``filters`` has to be the number of channels of the input images.</span> -<span class="sd"> block : `pysegcnn.core.layers.EncoderBlock`</span> -<span class="sd"> The convolutional block defining a layer in the encoder.</span> -<span class="sd"> A subclass of `pysegcnn.core.layers.EncoderBlock`, e.g.</span> -<span class="sd"> `pysegcnn.core.layers.ConvBnReluMaxPool`.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">filters</span><span class="p">,</span> <span class="n">block</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - - <span class="c1"># the number of filters for each block: the first element of filters</span> - <span class="c1"># has to be the number of input channels</span> - <span class="bp">self</span><span class="o">.</span><span class="n">features</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">filters</span><span class="p">)</span> - - <span class="c1"># the block of operations defining a layer in the encoder</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">block</span><span class="p">,</span> <span class="n">EncoderBlock</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'"block" expected to be a subclass of </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">EncoderBlock</span><span class="p">)))</span> - <span class="bp">self</span><span class="o">.</span><span class="n">block</span> <span class="o">=</span> <span class="n">block</span> - - <span class="c1"># construct the encoder layers</span> - <span class="bp">self</span><span class="o">.</span><span class="n">layers</span> <span class="o">=</span> <span class="p">[]</span> - <span class="k">for</span> <span class="n">lyr</span><span class="p">,</span> <span class="n">lyrp1</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">features</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">features</span><span class="p">[</span><span class="mi">1</span><span class="p">:]):</span> - <span class="c1"># append blocks to the encoder layers</span> - <span class="bp">self</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">block</span><span class="p">(</span><span class="n">lyr</span><span class="p">,</span> <span class="n">lyrp1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span> - - <span class="c1"># convert list of layers to ModuleList</span> - <span class="bp">self</span><span class="o">.</span><span class="n">layers</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">ModuleList</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">layers</span><span class="p">])</span> - -<div class="viewcode-block" id="Encoder.forward"><a class="viewcode-back" href="../../source/core.html#core.layers.Encoder.forward">[docs]</a> <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span> - <span class="sd">"""Forward pass of the encoder.</span> - -<span class="sd"> Stores intermediate outputs in a dictionary. The keys of the dictionary</span> -<span class="sd"> are the number of the network layers and the values are dictionaries</span> -<span class="sd"> with the following (key, value) pairs:</span> -<span class="sd"> ``"feature"``</span> -<span class="sd"> The intermediate encoder outputs (`torch.Tensor`).</span> -<span class="sd"> ``"indices"``</span> -<span class="sd"> The indices of the max pooling layer, if required</span> -<span class="sd"> (`torch.Tensor`).</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Input image.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Output of the encoder.</span> - -<span class="sd"> """</span> - <span class="c1"># initialize a dictionary that caches the intermediate outputs, i.e.</span> - <span class="c1"># features and pooling indices of each block in the encoder</span> - <span class="bp">self</span><span class="o">.</span><span class="n">cache</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">layer</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">layers</span><span class="p">):</span> - <span class="c1"># apply current encoder layer forward pass</span> - <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">ind</span> <span class="o">=</span> <span class="n">layer</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> - - <span class="c1"># store intermediate outputs for optional skip connections</span> - <span class="bp">self</span><span class="o">.</span><span class="n">cache</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'feature'</span><span class="p">:</span> <span class="n">y</span><span class="p">,</span> <span class="s1">'indices'</span><span class="p">:</span> <span class="n">ind</span><span class="p">}</span> - - <span class="k">return</span> <span class="n">x</span></div></div> - - -<div class="viewcode-block" id="Decoder"><a class="viewcode-back" href="../../source/core.html#core.layers.Decoder">[docs]</a><span class="k">class</span> <span class="nc">Decoder</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">):</span> - <span class="sd">"""Generic convolutional decoder.</span> - -<span class="sd"> When instanciating an encoder-decoder architechure, ``filters`` should be</span> -<span class="sd"> the same for `pysegcnn.core.layers.Encoder` and</span> -<span class="sd"> `pysegcnn.core.layers.Decoder`.</span> - -<span class="sd"> See `pysegcnn.core.models.UNet` for an example implementation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> filters : `list` [`int`]</span> -<span class="sd"> List of input channels to each convolutional block. The length of</span> -<span class="sd"> ``filters`` determines the depth of the decoder. The first element of</span> -<span class="sd"> ``filters`` has to be the number of channels of the input images.</span> -<span class="sd"> block : `pysegcnn.core.layers.DecoderBlock`</span> -<span class="sd"> The convolutional block defining a layer in the decoder.</span> -<span class="sd"> A subclass of `pysegcnn.core.layers.DecoderBlock`, e.g.</span> -<span class="sd"> `pysegcnn.core.layers.ConvBnReluMaxUnpool`.</span> -<span class="sd"> skip : `bool`</span> -<span class="sd"> Whether to apply skip connections from the encoder to the decoder.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">filters</span><span class="p">,</span> <span class="n">block</span><span class="p">,</span> <span class="n">skip</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - - <span class="c1"># the block of operations defining a layer in the decoder</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">block</span><span class="p">,</span> <span class="n">DecoderBlock</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'"block" expected to be a subclass of </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">DecoderBlock</span><span class="p">)))</span> - <span class="bp">self</span><span class="o">.</span><span class="n">block</span> <span class="o">=</span> <span class="n">block</span> - - <span class="c1"># the number of filters for each block is symmetric to the encoder:</span> - <span class="c1"># the last two element of filters have to be equal in order to apply</span> - <span class="c1"># last skip connection</span> - <span class="bp">self</span><span class="o">.</span><span class="n">features</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">filters</span><span class="p">)[::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> - <span class="bp">self</span><span class="o">.</span><span class="n">features</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">features</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span> - - <span class="c1"># whether to apply skip connections</span> - <span class="bp">self</span><span class="o">.</span><span class="n">skip</span> <span class="o">=</span> <span class="n">skip</span> - - <span class="c1"># in case of skip connections, the number of input channels to</span> - <span class="c1"># each block of the decoder is doubled</span> - <span class="n">n_in</span> <span class="o">=</span> <span class="mi">2</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">skip</span> <span class="k">else</span> <span class="mi">1</span> - - <span class="c1"># construct decoder layers</span> - <span class="bp">self</span><span class="o">.</span><span class="n">layers</span> <span class="o">=</span> <span class="p">[]</span> - <span class="k">for</span> <span class="n">lyr</span><span class="p">,</span> <span class="n">lyrp1</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">n_in</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">features</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">features</span><span class="p">[</span><span class="mi">1</span><span class="p">:]):</span> - <span class="bp">self</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">block</span><span class="p">(</span><span class="n">lyr</span><span class="p">,</span> <span class="n">lyrp1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span> - - <span class="c1"># convert list of layers to ModuleList</span> - <span class="bp">self</span><span class="o">.</span><span class="n">layers</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">ModuleList</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">layers</span><span class="p">])</span> - -<div class="viewcode-block" id="Decoder.forward"><a class="viewcode-back" href="../../source/core.html#core.layers.Decoder.forward">[docs]</a> <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">enc_cache</span><span class="p">):</span> - <span class="sd">"""Forward pass of the decoder.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Output of the encoder.</span> -<span class="sd"> enc_cache : `dict` [`dict`]</span> -<span class="sd"> Cache dictionary. The keys of the dictionary are the number of the</span> -<span class="sd"> network layers and the values are dictionaries with the following</span> -<span class="sd"> (key, value) pairs:</span> -<span class="sd"> ``"feature"``</span> -<span class="sd"> The intermediate encoder outputs (`torch.Tensor`).</span> -<span class="sd"> ``"indices"``</span> -<span class="sd"> The indices of the max pooling layer (`torch.Tensor`).</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Output of the decoder.</span> - -<span class="sd"> """</span> - <span class="c1"># for each layer, upsample input and apply optional skip connection</span> - <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">layer</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">layers</span><span class="p">):</span> - - <span class="c1"># get intermediate outputs from encoder: iterate the encoder cache</span> - <span class="c1"># in reversed direction, i.e. from last to first encoder layer</span> - <span class="n">cache</span> <span class="o">=</span> <span class="n">enc_cache</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">layers</span><span class="p">)</span> <span class="o">-</span> <span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)]</span> - <span class="n">feature</span><span class="p">,</span> <span class="n">indices</span> <span class="o">=</span> <span class="n">cache</span><span class="p">[</span><span class="s1">'feature'</span><span class="p">],</span> <span class="n">cache</span><span class="p">[</span><span class="s1">'indices'</span><span class="p">]</span> - - <span class="c1"># apply current decoder layer forward pass</span> - <span class="n">x</span> <span class="o">=</span> <span class="n">layer</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">feature</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">skip</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">x</span></div></div> - - -<div class="viewcode-block" id="ConvBnReluMaxPool"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluMaxPool">[docs]</a><span class="k">class</span> <span class="nc">ConvBnReluMaxPool</span><span class="p">(</span><span class="n">EncoderBlock</span><span class="p">):</span> - <span class="sd">"""Block of convolution, batchnorm, relu and 2x2 max pool.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional keyword arguments passed to</span> -<span class="sd"> `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - -<div class="viewcode-block" id="ConvBnReluMaxPool.layers"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluMaxPool.layers">[docs]</a> <span class="k">def</span> <span class="nf">layers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Sequence of convolution, batchnorm and relu layers.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> layers : `torch.nn.Sequential` [`torch.nn.Module`]</span> -<span class="sd"> An instance of `torch.nn.Sequential` containing the sequence</span> -<span class="sd"> of convolution, batchnorm and relu layer (`torch.nn.Module`)</span> -<span class="sd"> instances.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">conv_bn_relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">in_channels</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ConvBnReluMaxPool.downsample"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluMaxPool.downsample">[docs]</a> <span class="k">def</span> <span class="nf">downsample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span> - <span class="sd">"""2x2 max pooling layer, `torch.nn.functional.max_pool2d`.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Input tensor.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height // 2, width // 2)</span> -<span class="sd"> The 2x2 max pooled tensor.</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> -<span class="sd"> The indices of the maxima. Useful for upsampling with</span> -<span class="sd"> `torch.nn.functional.max_unpool2d`.</span> -<span class="sd"> """</span> - <span class="n">x</span><span class="p">,</span> <span class="n">indices</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">max_pool2d</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">kernel_size</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">return_indices</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - <span class="k">return</span> <span class="n">x</span><span class="p">,</span> <span class="n">indices</span></div> - -<div class="viewcode-block" id="ConvBnReluMaxPool.extra_repr"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluMaxPool.extra_repr">[docs]</a> <span class="k">def</span> <span class="nf">extra_repr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Define optional extra information about this module.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> `str`</span> -<span class="sd"> Extra representation string.</span> -<span class="sd"> """</span> - <span class="k">return</span> <span class="p">(</span><span class="s1">'(pool): MaxPool2d(kernel_size=2, stride=2, padding=0, '</span> - <span class="s1">'dilation=1, ceil_mode=False)'</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="ConvBnReluMaxUnpool"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluMaxUnpool">[docs]</a><span class="k">class</span> <span class="nc">ConvBnReluMaxUnpool</span><span class="p">(</span><span class="n">DecoderBlock</span><span class="p">):</span> - <span class="sd">"""Block of convolution, batchnorm, relu and 2x2 max unpool.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional keyword arguments passed to</span> -<span class="sd"> `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - -<div class="viewcode-block" id="ConvBnReluMaxUnpool.layers"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluMaxUnpool.layers">[docs]</a> <span class="k">def</span> <span class="nf">layers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Sequence of convolution, batchnorm and relu layers.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> layers : `torch.nn.Sequential` [`torch.nn.Module`]</span> -<span class="sd"> An instance of `torch.nn.Sequential` containing the sequence</span> -<span class="sd"> of convolution, batchnorm and relu layer (`torch.nn.Module`)</span> -<span class="sd"> instances.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">conv_bn_relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">in_channels</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ConvBnReluMaxUnpool.upsample"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluMaxUnpool.upsample">[docs]</a> <span class="k">def</span> <span class="nf">upsample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">feature</span><span class="p">,</span> <span class="n">indices</span><span class="p">):</span> - <span class="sd">"""2x2 max unpooling layer.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Input tensor.</span> -<span class="sd"> feature : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Intermediate output of a layer in the encoder. Used to determine</span> -<span class="sd"> the output shape of the upsampling operation.</span> -<span class="sd"> indices : `torch.Tensor`</span> -<span class="sd"> The indices of the maxima of the max pooling operation</span> -<span class="sd"> (as returned by `torch.nn.functional.max_pool2d`).</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height * 2, width * 2)</span> -<span class="sd"> The 2x2 max unpooled tensor.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">max_unpool2d</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">kernel_size</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> - <span class="n">output_size</span><span class="o">=</span><span class="n">feature</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">:])</span></div> - -<div class="viewcode-block" id="ConvBnReluMaxUnpool.extra_repr"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluMaxUnpool.extra_repr">[docs]</a> <span class="k">def</span> <span class="nf">extra_repr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Define optional extra information about this module.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> `str`</span> -<span class="sd"> Extra representation string.</span> -<span class="sd"> """</span> - <span class="k">return</span> <span class="p">(</span><span class="s1">'(pool): MaxUnpool2d(kernel_size=(2, 2), stride=(2, 2), '</span> - <span class="s1">'padding=(0, 0))'</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="ConvBnReluUpsample"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluUpsample">[docs]</a><span class="k">class</span> <span class="nc">ConvBnReluUpsample</span><span class="p">(</span><span class="n">DecoderBlock</span><span class="p">):</span> - <span class="sd">"""Block of convolution, batchnorm, relu and nearest neighbor upsampling.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - -<div class="viewcode-block" id="ConvBnReluUpsample.layers"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluUpsample.layers">[docs]</a> <span class="k">def</span> <span class="nf">layers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Sequence of convolution, batchnorm and relu layers.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> layers : `torch.nn.Sequential` [`torch.nn.Module`]</span> -<span class="sd"> An instance of `torch.nn.Sequential` containing the sequence</span> -<span class="sd"> of convolution, batchnorm and relu layer (`torch.nn.Module`)</span> -<span class="sd"> instances.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">conv_bn_relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">in_channels</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ConvBnReluUpsample.upsample"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluUpsample.upsample">[docs]</a> <span class="k">def</span> <span class="nf">upsample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">feature</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> - <span class="sd">"""Nearest neighbor upsampling.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Input tensor.</span> -<span class="sd"> feature : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Intermediate output of a layer in the encoder. Used to determine</span> -<span class="sd"> the output shape of the upsampling operation.</span> -<span class="sd"> indices : `None`, optional</span> -<span class="sd"> The indices of the maxima of the max pooling operation</span> -<span class="sd"> (as returned by `torch.nn.functional.max_pool2d`). Not required by</span> -<span class="sd"> this upsampling method.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> The 2x2 upsampled tensor.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">interpolate</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">feature</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">:],</span> <span class="n">mode</span><span class="o">=</span><span class="s1">'nearest'</span><span class="p">)</span></div> - -<div class="viewcode-block" id="ConvBnReluUpsample.extra_repr"><a class="viewcode-back" href="../../source/core.html#core.layers.ConvBnReluUpsample.extra_repr">[docs]</a> <span class="k">def</span> <span class="nf">extra_repr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Define optional extra information about this module.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> `str`</span> -<span class="sd"> Extra representation string.</span> -<span class="sd"> """</span> - <span class="k">return</span> <span class="s1">'(pool): Upsample(mode="nearest")'</span></div></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/logging.html b/docs/_build/html/_modules/core/logging.html deleted file mode 100644 index 11127c5d2986e6d074a7d8ceb2514b0173f85232..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/logging.html +++ /dev/null @@ -1,282 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.logging — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.logging</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.logging</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Logging configuration.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">pathlib</span> - - -<span class="c1"># the logging configuration dictionary</span> -<div class="viewcode-block" id="log_conf"><a class="viewcode-back" href="../../source/core.html#core.logging.log_conf">[docs]</a><span class="k">def</span> <span class="nf">log_conf</span><span class="p">(</span><span class="n">logfile</span><span class="p">):</span> - <span class="sd">"""Set basic logging configuration passed to `logging.config.dictConfig`.</span> - -<span class="sd"> See the logging `docs`_ for a detailed description of the configuration</span> -<span class="sd"> dictionary.</span> - -<span class="sd"> .. _docs:</span> -<span class="sd"> https://docs.python.org/3/library/logging.config.html#dictionary-schema-details</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> logfile : `str` or `pathlib.Path`</span> -<span class="sd"> The file to save the logs to.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> LOGGING_CONFIG : `dict`</span> -<span class="sd"> The logging configuration.</span> - -<span class="sd"> """</span> - <span class="c1"># check if the parent directory of the log file exists</span> - <span class="n">logfile</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">logfile</span><span class="p">)</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">logfile</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">is_dir</span><span class="p">():</span> - <span class="n">logfile</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - - <span class="n">LOGGING_CONFIG</span> <span class="o">=</span> <span class="p">{</span> - <span class="s1">'version'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> - <span class="s1">'disable_existing_loggers'</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> - <span class="s1">'formatters'</span><span class="p">:</span> <span class="p">{</span> - <span class="s1">'brief'</span><span class="p">:</span> <span class="p">{</span> - <span class="s1">'format'</span><span class="p">:</span> <span class="s1">'</span><span class="si">%(name)s</span><span class="s1">: </span><span class="si">%(message)s</span><span class="s1">'</span> - <span class="p">},</span> - <span class="s1">'standard'</span><span class="p">:</span> <span class="p">{</span> - <span class="s1">'format'</span><span class="p">:</span> <span class="s1">'</span><span class="si">%(asctime)s</span><span class="s1"> [</span><span class="si">%(levelname)s</span><span class="s1">] </span><span class="si">%(name)s</span><span class="s1">: </span><span class="si">%(message)s</span><span class="s1">'</span><span class="p">,</span> - <span class="s1">'datefmt'</span><span class="p">:</span> <span class="s1">'%Y-%m-</span><span class="si">%d</span><span class="s1">T%H:%M:%S'</span> - <span class="p">},</span> - <span class="p">},</span> - <span class="s1">'handlers'</span><span class="p">:</span> <span class="p">{</span> - <span class="s1">'console'</span><span class="p">:</span> <span class="p">{</span> - <span class="s1">'class'</span><span class="p">:</span> <span class="s1">'logging.StreamHandler'</span><span class="p">,</span> - <span class="s1">'formatter'</span><span class="p">:</span> <span class="s1">'brief'</span><span class="p">,</span> - <span class="s1">'level'</span><span class="p">:</span> <span class="s1">'INFO'</span><span class="p">,</span> - <span class="s1">'stream'</span><span class="p">:</span> <span class="s1">'ext://sys.stderr'</span><span class="p">,</span> - <span class="p">},</span> - - <span class="s1">'file'</span><span class="p">:</span> <span class="p">{</span> - <span class="s1">'class'</span><span class="p">:</span> <span class="s1">'logging.FileHandler'</span><span class="p">,</span> - <span class="s1">'formatter'</span><span class="p">:</span> <span class="s1">'standard'</span><span class="p">,</span> - <span class="s1">'level'</span><span class="p">:</span> <span class="s1">'INFO'</span><span class="p">,</span> - <span class="s1">'filename'</span><span class="p">:</span> <span class="n">logfile</span><span class="p">,</span> - <span class="s1">'mode'</span><span class="p">:</span> <span class="s1">'a'</span> - <span class="p">}</span> - <span class="p">},</span> - <span class="s1">'loggers'</span><span class="p">:</span> <span class="p">{</span> - <span class="s1">''</span><span class="p">:</span> <span class="p">{</span> - <span class="s1">'handlers'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'console'</span><span class="p">,</span> <span class="s1">'file'</span><span class="p">],</span> - <span class="s1">'level'</span><span class="p">:</span> <span class="s1">'INFO'</span><span class="p">,</span> - <span class="p">},</span> - <span class="p">}</span> - <span class="p">}</span> - - <span class="k">return</span> <span class="n">LOGGING_CONFIG</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/models.html b/docs/_build/html/_modules/core/models.html deleted file mode 100644 index a9f1a461bf768dbe89819e0b9377f6d25accf7b8..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/models.html +++ /dev/null @@ -1,532 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.models — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.models</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.models</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Neural networks for semantic image segmentation.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">enum</span> -<span class="kn">import</span> <span class="nn">logging</span> -<span class="kn">import</span> <span class="nn">pathlib</span> - -<span class="c1"># externals</span> -<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> -<span class="kn">import</span> <span class="nn">torch</span> -<span class="kn">import</span> <span class="nn">torch.nn</span> <span class="k">as</span> <span class="nn">nn</span> -<span class="kn">import</span> <span class="nn">torch.optim</span> <span class="k">as</span> <span class="nn">optim</span> - -<span class="c1"># locals</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.layers</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Encoder</span><span class="p">,</span> <span class="n">Decoder</span><span class="p">,</span> <span class="n">ConvBnReluMaxPool</span><span class="p">,</span> - <span class="n">ConvBnReluMaxUnpool</span><span class="p">,</span> <span class="n">Conv2dSame</span><span class="p">)</span> - -<span class="c1"># module level logger</span> -<span class="n">LOGGER</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> - - -<div class="viewcode-block" id="Network"><a class="viewcode-back" href="../../source/core.html#core.models.Network">[docs]</a><span class="k">class</span> <span class="nc">Network</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">):</span> - <span class="sd">"""Generic Network class.</span> - -<span class="sd"> The base class for each model. If you want to implement a new model,</span> -<span class="sd"> inherit the ``~pysegcnn.core.models.Network`` class.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - - <span class="c1"># initialize state file</span> - <span class="bp">self</span><span class="o">.</span><span class="n">state_file</span> <span class="o">=</span> <span class="kc">None</span> - -<div class="viewcode-block" id="Network.freeze"><a class="viewcode-back" href="../../source/core.html#core.models.Network.freeze">[docs]</a> <span class="k">def</span> <span class="nf">freeze</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Freeze the weights of a model.</span> - -<span class="sd"> Disables gradient computation: useful when using a pretrained model for</span> -<span class="sd"> inference.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="k">for</span> <span class="n">param</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">():</span> - <span class="n">param</span><span class="o">.</span><span class="n">requires_grad</span> <span class="o">=</span> <span class="kc">False</span></div> - -<div class="viewcode-block" id="Network.unfreeze"><a class="viewcode-back" href="../../source/core.html#core.models.Network.unfreeze">[docs]</a> <span class="k">def</span> <span class="nf">unfreeze</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Unfreeze the weights of a model.</span> - -<span class="sd"> Enables gradient computation: useful when adjusting a pretrained model</span> -<span class="sd"> to a new dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="k">for</span> <span class="n">param</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">():</span> - <span class="n">param</span><span class="o">.</span><span class="n">requires_grad</span> <span class="o">=</span> <span class="kc">True</span></div> - -<div class="viewcode-block" id="Network.save"><a class="viewcode-back" href="../../source/core.html#core.models.Network.save">[docs]</a> <span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">state_file</span><span class="p">,</span> <span class="n">optimizer</span><span class="p">,</span> <span class="n">bands</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <span class="sd">"""Save the model state.</span> - -<span class="sd"> Saves the model and optimizer states together with the model</span> -<span class="sd"> construction parameters, to easily re-instanciate the model.</span> - -<span class="sd"> Optional ``kwargs`` are also saved.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> state_file : `str` or `pathlib.Path`</span> -<span class="sd"> Path to save the model state.</span> -<span class="sd"> optimizer : `torch.optim.Optimizer`</span> -<span class="sd"> The optimizer used to train the model.</span> -<span class="sd"> bands : `list` [`str`] or `None`, optional</span> -<span class="sd"> List of bands the model is trained with. The default is None.</span> -<span class="sd"> **kwargs</span> -<span class="sd"> Arbitrary keyword arguments. Each keyword argument will be saved</span> -<span class="sd"> as (key, value) pair in ``state_file``.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> model_state : `dict`</span> -<span class="sd"> A dictionary containing the model and optimizer state</span> - -<span class="sd"> """</span> - <span class="c1"># check if the output path exists and if not, create it</span> - <span class="n">state_file</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">state_file</span><span class="p">)</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">state_file</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">is_dir</span><span class="p">():</span> - <span class="n">state_file</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - - <span class="c1"># initialize dictionary to store network parameters</span> - <span class="n">model_state</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">kwargs</span><span class="p">}</span> - - <span class="c1"># store the spectral bands the model is trained with</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'bands'</span><span class="p">]</span> <span class="o">=</span> <span class="n">bands</span> - - <span class="c1"># store model and optimizer class</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'cls'</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'optim_cls'</span><span class="p">]</span> <span class="o">=</span> <span class="n">optimizer</span><span class="o">.</span><span class="vm">__class__</span> - - <span class="c1"># store construction parameters to instanciate the network</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'params'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> - <span class="s1">'skip'</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">skip</span><span class="p">,</span> - <span class="s1">'filters'</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nfilters</span><span class="p">,</span> - <span class="s1">'nclasses'</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nclasses</span><span class="p">,</span> - <span class="s1">'in_channels'</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">in_channels</span> - <span class="p">}</span> - - <span class="c1"># store optimizer construction parameters</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'optim_params'</span><span class="p">]</span> <span class="o">=</span> <span class="n">optimizer</span><span class="o">.</span><span class="n">defaults</span> - - <span class="c1"># store optional keyword arguments</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'params'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">model_state</span><span class="p">[</span><span class="s1">'params'</span><span class="p">],</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">}</span> - - <span class="c1"># store model epoch</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'epoch'</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">epoch</span> - - <span class="c1"># store model and optimizer state</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'model_state_dict'</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">state_dict</span><span class="p">()</span> - <span class="n">model_state</span><span class="p">[</span><span class="s1">'optim_state_dict'</span><span class="p">]</span> <span class="o">=</span> <span class="n">optimizer</span><span class="o">.</span><span class="n">state_dict</span><span class="p">()</span> - - <span class="c1"># model state dictionary stores the values of all trainable parameters</span> - <span class="n">torch</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">model_state</span><span class="p">,</span> <span class="n">state_file</span><span class="p">)</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Network parameters saved in </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">state_file</span><span class="p">))</span> - - <span class="k">return</span> <span class="n">model_state</span></div> - -<div class="viewcode-block" id="Network.load"><a class="viewcode-back" href="../../source/core.html#core.models.Network.load">[docs]</a> <span class="nd">@staticmethod</span> - <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="n">state_file</span><span class="p">):</span> - <span class="sd">"""Load a model state.</span> - -<span class="sd"> Returns the model in ``state_file`` with the pretrained model and</span> -<span class="sd"> optimizer weights. Useful when resuming training an existing model.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> state_file : `str` or `pathlib.Path`</span> -<span class="sd"> The model state file. Model state files are stored in</span> -<span class="sd"> pysegcnn/main/_models.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> FileNotFoundError</span> -<span class="sd"> Raised if ``state_file`` does not exist.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> model : `pysegcnn.core.models.Network`</span> -<span class="sd"> The pretrained model.</span> -<span class="sd"> optimizer : `torch.optim.Optimizer`</span> -<span class="sd"> The optimizer used to train the model.</span> -<span class="sd"> model_state : '`dict`</span> -<span class="sd"> A dictionary containing the model and optimizer state, as</span> -<span class="sd"> constructed by `~pysegcnn.core.Network.save`.</span> - -<span class="sd"> """</span> - <span class="c1"># load the pretrained model</span> - <span class="n">state_file</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">state_file</span><span class="p">)</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">state_file</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="k">raise</span> <span class="ne">FileNotFoundError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> does not exist.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">state_file</span><span class="p">))</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Loading pretrained weights from: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">state_file</span><span class="p">))</span> - - <span class="c1"># load the model state</span> - <span class="n">model_state</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">state_file</span><span class="p">)</span> - - <span class="c1"># the model and optimizer class</span> - <span class="n">model_class</span> <span class="o">=</span> <span class="n">model_state</span><span class="p">[</span><span class="s1">'cls'</span><span class="p">]</span> - <span class="n">optim_class</span> <span class="o">=</span> <span class="n">model_state</span><span class="p">[</span><span class="s1">'optim_cls'</span><span class="p">]</span> - - <span class="c1"># instanciate pretrained model architecture</span> - <span class="n">model</span> <span class="o">=</span> <span class="n">model_class</span><span class="p">(</span><span class="o">**</span><span class="n">model_state</span><span class="p">[</span><span class="s1">'params'</span><span class="p">])</span> - - <span class="c1"># store state file as instance attribute</span> - <span class="n">model</span><span class="o">.</span><span class="n">state_file</span> <span class="o">=</span> <span class="n">state_file</span> - - <span class="c1"># load pretrained model weights</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Loading model parameters ...'</span><span class="p">)</span> - <span class="n">model</span><span class="o">.</span><span class="n">load_state_dict</span><span class="p">(</span><span class="n">model_state</span><span class="p">[</span><span class="s1">'model_state_dict'</span><span class="p">])</span> - <span class="n">model</span><span class="o">.</span><span class="n">epoch</span> <span class="o">=</span> <span class="n">model_state</span><span class="p">[</span><span class="s1">'epoch'</span><span class="p">]</span> - - <span class="c1"># resume optimizer parameters</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Loading optimizer parameters ...'</span><span class="p">)</span> - <span class="n">optimizer</span> <span class="o">=</span> <span class="n">optim_class</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">parameters</span><span class="p">(),</span> - <span class="o">**</span><span class="n">model_state</span><span class="p">[</span><span class="s1">'optim_params'</span><span class="p">])</span> - <span class="n">optimizer</span><span class="o">.</span><span class="n">load_state_dict</span><span class="p">(</span><span class="n">model_state</span><span class="p">[</span><span class="s1">'optim_state_dict'</span><span class="p">])</span> - - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Model epoch: </span><span class="si">{:d}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">epoch</span><span class="p">))</span> - - <span class="k">return</span> <span class="n">model</span><span class="p">,</span> <span class="n">optimizer</span><span class="p">,</span> <span class="n">model_state</span></div> - - <span class="nd">@property</span> - <span class="k">def</span> <span class="nf">state</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Return the model state file.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> state_file : `pathlib.Path` or `None`</span> -<span class="sd"> The model state file.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">state_file</span></div> - - -<div class="viewcode-block" id="UNet"><a class="viewcode-back" href="../../source/core.html#core.models.UNet">[docs]</a><span class="k">class</span> <span class="nc">UNet</span><span class="p">(</span><span class="n">Network</span><span class="p">):</span> - <span class="sd">"""A PyTorch implementation of `U-Net`_.</span> - -<span class="sd"> Slightly modified version of U-Net:</span> -<span class="sd"> - each convolution is followed by a batch normalization layer</span> -<span class="sd"> - the upsampling is implemented by a 2x2 max unpooling operation</span> - -<span class="sd"> .. _U-Net:</span> -<span class="sd"> https://arxiv.org/abs/1505.04597</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of channels of the input images.</span> -<span class="sd"> nclasses : `int`</span> -<span class="sd"> Number of classes.</span> -<span class="sd"> filters : `list` [`int`]</span> -<span class="sd"> List of input channels to each convolutional block.</span> -<span class="sd"> skip : `bool`</span> -<span class="sd"> Whether to apply skip connections from the encoder to the decoder.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional keyword arguments passed to</span> -<span class="sd"> `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">in_channels</span><span class="p">,</span> <span class="n">nclasses</span><span class="p">,</span> <span class="n">filters</span><span class="p">,</span> <span class="n">skip</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - - <span class="c1"># number of input channels</span> - <span class="bp">self</span><span class="o">.</span><span class="n">in_channels</span> <span class="o">=</span> <span class="n">in_channels</span> - - <span class="c1"># number of classes</span> - <span class="bp">self</span><span class="o">.</span><span class="n">nclasses</span> <span class="o">=</span> <span class="n">nclasses</span> - - <span class="c1"># configuration of the convolutional layers in the network</span> - <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span> <span class="o">=</span> <span class="n">kwargs</span> - <span class="bp">self</span><span class="o">.</span><span class="n">nfilters</span> <span class="o">=</span> <span class="n">filters</span> - - <span class="c1"># convolutional layers of the encoder</span> - <span class="bp">self</span><span class="o">.</span><span class="n">filters</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">in_channels</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">filters</span><span class="p">)])</span> - - <span class="c1"># whether to apply skip connections</span> - <span class="bp">self</span><span class="o">.</span><span class="n">skip</span> <span class="o">=</span> <span class="n">skip</span> - - <span class="c1"># number of epochs trained</span> - <span class="bp">self</span><span class="o">.</span><span class="n">epoch</span> <span class="o">=</span> <span class="mi">0</span> - - <span class="c1"># construct the encoder</span> - <span class="bp">self</span><span class="o">.</span><span class="n">encoder</span> <span class="o">=</span> <span class="n">Encoder</span><span class="p">(</span><span class="n">filters</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">filters</span><span class="p">,</span> <span class="n">block</span><span class="o">=</span><span class="n">ConvBnReluMaxPool</span><span class="p">,</span> - <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - - <span class="c1"># construct the decoder</span> - <span class="bp">self</span><span class="o">.</span><span class="n">decoder</span> <span class="o">=</span> <span class="n">Decoder</span><span class="p">(</span><span class="n">filters</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">filters</span><span class="p">,</span> <span class="n">block</span><span class="o">=</span><span class="n">ConvBnReluMaxUnpool</span><span class="p">,</span> - <span class="n">skip</span><span class="o">=</span><span class="n">skip</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - - <span class="c1"># construct the classifier</span> - <span class="bp">self</span><span class="o">.</span><span class="n">classifier</span> <span class="o">=</span> <span class="n">Conv2dSame</span><span class="p">(</span><span class="n">in_channels</span><span class="o">=</span><span class="n">filters</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> - <span class="n">out_channels</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">nclasses</span><span class="p">,</span> - <span class="n">kernel_size</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> - -<div class="viewcode-block" id="UNet.forward"><a class="viewcode-back" href="../../source/core.html#core.models.UNet.forward">[docs]</a> <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span> - <span class="sd">"""Forward propagation of U-Net.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`</span> -<span class="sd"> The input image, shape=(batch_size, channels, height, width).</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> y : 'torch.tensor'</span> -<span class="sd"> The classified image, shape=(batch_size, height, width).</span> - -<span class="sd"> """</span> - <span class="c1"># forward pass: encoder</span> - <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">encoder</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> - - <span class="c1"># forward pass: decoder</span> - <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decoder</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">encoder</span><span class="o">.</span><span class="n">cache</span><span class="p">)</span> - - <span class="c1"># clear intermediate outputs</span> - <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">encoder</span><span class="o">.</span><span class="n">cache</span> - - <span class="c1"># classification</span> - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">classifier</span><span class="p">(</span><span class="n">x</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="SupportedModels"><a class="viewcode-back" href="../../source/core.html#core.models.SupportedModels">[docs]</a><span class="k">class</span> <span class="nc">SupportedModels</span><span class="p">(</span><span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">):</span> - <span class="sd">"""Names and corresponding classes of the implemented models."""</span> - - <span class="n">Unet</span> <span class="o">=</span> <span class="n">UNet</span></div> - - -<div class="viewcode-block" id="SupportedOptimizers"><a class="viewcode-back" href="../../source/core.html#core.models.SupportedOptimizers">[docs]</a><span class="k">class</span> <span class="nc">SupportedOptimizers</span><span class="p">(</span><span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">):</span> - <span class="sd">"""Names and corresponding classes of the tested optimizers."""</span> - - <span class="n">Adam</span> <span class="o">=</span> <span class="n">optim</span><span class="o">.</span><span class="n">Adam</span></div> - - -<div class="viewcode-block" id="SupportedLossFunctions"><a class="viewcode-back" href="../../source/core.html#core.models.SupportedLossFunctions">[docs]</a><span class="k">class</span> <span class="nc">SupportedLossFunctions</span><span class="p">(</span><span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">):</span> - <span class="sd">"""Names and corresponding classes of the tested loss functions."""</span> - - <span class="n">CrossEntropy</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">CrossEntropyLoss</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/predict.html b/docs/_build/html/_modules/core/predict.html deleted file mode 100644 index b8c6d4862a2f94578daca6f468b7d6a722e3e764..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/predict.html +++ /dev/null @@ -1,504 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.predict — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.predict</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.predict</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Functions for model inference.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">logging</span> - -<span class="c1"># externals</span> -<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> -<span class="kn">import</span> <span class="nn">torch</span> -<span class="kn">from</span> <span class="nn">torch.utils.data</span> <span class="kn">import</span> <span class="n">DataLoader</span> -<span class="kn">from</span> <span class="nn">torch.utils.data.dataset</span> <span class="kn">import</span> <span class="n">Subset</span> -<span class="kn">import</span> <span class="nn">torch.nn.functional</span> <span class="k">as</span> <span class="nn">F</span> - -<span class="c1"># locals</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.utils</span> <span class="kn">import</span> <span class="n">reconstruct_scene</span><span class="p">,</span> <span class="n">accuracy_function</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.graphics</span> <span class="kn">import</span> <span class="n">plot_sample</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.split</span> <span class="kn">import</span> <span class="n">RandomSubset</span><span class="p">,</span> <span class="n">SceneSubset</span> - -<span class="c1"># module level logger</span> -<span class="n">LOGGER</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> - - -<span class="k">def</span> <span class="nf">_get_scene_tiles</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">scene_id</span><span class="p">):</span> - <span class="sd">"""Return the tiles of the scene with id = ``scene_id``.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `pysegcnn.core.split.SceneSubset`</span> -<span class="sd"> An instance of `~pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `~pysegcnn.core.split.SceneSubset`.</span> -<span class="sd"> scene_id : `str`</span> -<span class="sd"> A valid scene identifier.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> ValueError</span> -<span class="sd"> Raised if ``scene_id`` is not a valid scene identifier for the dataset</span> -<span class="sd"> ``ds``.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> indices : `list` [`int`]</span> -<span class="sd"> List of indices of the tiles from scene with id ``scene_id`` in ``ds``.</span> - -<span class="sd"> """</span> - <span class="c1"># check if the scene id is valid</span> - <span class="n">scene_meta</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">parse_scene_id</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)</span> - <span class="k">if</span> <span class="n">scene_meta</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> - <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> is not a valid scene identifier'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">scene_id</span><span class="p">))</span> - - <span class="c1"># iterate over the scenes of the dataset</span> - <span class="n">indices</span> <span class="o">=</span> <span class="p">[]</span> - <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">scene</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">scenes</span><span class="p">):</span> - <span class="c1"># if the scene id matches a given id, save the index of the scene</span> - <span class="k">if</span> <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="o">==</span> <span class="n">scene_id</span><span class="p">:</span> - <span class="n">indices</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">indices</span> - - -<div class="viewcode-block" id="predict_samples"><a class="viewcode-back" href="../../source/core.html#core.predict.predict_samples">[docs]</a><span class="k">def</span> <span class="nf">predict_samples</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">cm</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">plot</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <span class="sd">"""Classify each sample in ``ds`` with model ``model``.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `pysegcnn.core.split.SceneSubset`</span> -<span class="sd"> An instance of `~pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `~pysegcnn.core.split.SceneSubset`.</span> -<span class="sd"> model : `pysegcnn.core.models.Network`</span> -<span class="sd"> An instance of `~pysegcnn.core.models.Network`.</span> -<span class="sd"> cm : `bool`, optional</span> -<span class="sd"> Whether to compute the confusion matrix. The default is False.</span> -<span class="sd"> plot : `bool`, optional</span> -<span class="sd"> Whether to plot a false color composite, ground truth and model</span> -<span class="sd"> prediction for each sample. The default is False.</span> -<span class="sd"> **kwargs</span> -<span class="sd"> Additional keyword arguments passed to</span> -<span class="sd"> `pysegcnn.core.graphics.plot_sample`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if ``ds`` is not an instance of</span> -<span class="sd"> `~pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `~pysegcnn.core.split.SceneSubset`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> output : `dict`</span> -<span class="sd"> Output dictionary with keys:</span> -<span class="sd"> ``'input'``</span> -<span class="sd"> Model input data</span> -<span class="sd"> ``'labels'``</span> -<span class="sd"> The ground truth</span> -<span class="sd"> ``'prediction'``</span> -<span class="sd"> Model prediction</span> -<span class="sd"> conf_mat : `numpy.ndarray`</span> -<span class="sd"> The confusion matrix. Note that the confusion matrix ``conf_mat`` is</span> -<span class="sd"> only computed if ``cm`` = True.</span> -<span class="sd"> """</span> - <span class="c1"># check whether the dataset is a valid subset, i.e.</span> - <span class="c1"># an instance of pysegcnn.core.split.SceneSubset or</span> - <span class="c1"># an instance of pysegcnn.core.split.RandomSubset</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">RandomSubset</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">SceneSubset</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'ds should be an instance of </span><span class="si">{}</span><span class="s1"> or of </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">RandomSubset</span><span class="p">),</span> <span class="nb">repr</span><span class="p">(</span><span class="n">SceneSubset</span><span class="p">)))</span> - - <span class="c1"># the device to compute on, use gpu if available</span> - <span class="n">device</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">device</span><span class="p">(</span><span class="s2">"cuda:0"</span> <span class="k">if</span> <span class="n">torch</span><span class="o">.</span><span class="n">cuda</span><span class="o">.</span><span class="n">is_available</span><span class="p">()</span> <span class="k">else</span> <span class="s2">"cpu"</span><span class="p">)</span> - - <span class="c1"># set the model to evaluation mode</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Setting model to evaluation mode ...'</span><span class="p">)</span> - <span class="n">model</span><span class="o">.</span><span class="n">eval</span><span class="p">()</span> - <span class="n">model</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">device</span><span class="p">)</span> - - <span class="c1"># base filename for each sample</span> - <span class="n">fname</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">state_file</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'.pt'</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> - - <span class="c1"># initialize confusion matrix</span> - <span class="n">conf_mat</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">shape</span><span class="o">=</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">nclasses</span><span class="p">,</span> <span class="n">model</span><span class="o">.</span><span class="n">nclasses</span><span class="p">))</span> - - <span class="c1"># create the dataloader</span> - <span class="n">dataloader</span> <span class="o">=</span> <span class="n">DataLoader</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">drop_last</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> - - <span class="c1"># iterate over the samples and plot inputs, ground truth and</span> - <span class="c1"># model predictions</span> - <span class="n">output</span> <span class="o">=</span> <span class="p">{}</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Predicting samples of the </span><span class="si">{}</span><span class="s1"> dataset ...'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> - <span class="k">for</span> <span class="n">batch</span><span class="p">,</span> <span class="p">(</span><span class="n">inputs</span><span class="p">,</span> <span class="n">labels</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">dataloader</span><span class="p">):</span> - - <span class="c1"># send inputs and labels to device</span> - <span class="n">inputs</span> <span class="o">=</span> <span class="n">inputs</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">device</span><span class="p">)</span> - <span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">device</span><span class="p">)</span> - - <span class="c1"># compute model predictions</span> - <span class="k">with</span> <span class="n">torch</span><span class="o">.</span><span class="n">no_grad</span><span class="p">():</span> - <span class="n">prd</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="n">model</span><span class="p">(</span><span class="n">inputs</span><span class="p">),</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span> - - <span class="c1"># store output for current batch</span> - <span class="n">output</span><span class="p">[</span><span class="n">batch</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'input'</span><span class="p">:</span> <span class="n">inputs</span><span class="p">,</span> <span class="s1">'labels'</span><span class="p">:</span> <span class="n">labels</span><span class="p">,</span> <span class="s1">'prediction'</span><span class="p">:</span> <span class="n">prd</span><span class="p">}</span> - - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Sample: </span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1">, Accuracy: </span><span class="si">{:.2f}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="n">batch</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">dataloader</span><span class="p">),</span> <span class="n">accuracy_function</span><span class="p">(</span><span class="n">prd</span><span class="p">,</span> <span class="n">labels</span><span class="p">)))</span> - - <span class="c1"># update confusion matrix</span> - <span class="k">if</span> <span class="n">cm</span><span class="p">:</span> - <span class="k">for</span> <span class="n">ytrue</span><span class="p">,</span> <span class="n">ypred</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">labels</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">),</span> <span class="n">prd</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)):</span> - <span class="n">conf_mat</span><span class="p">[</span><span class="n">ytrue</span><span class="o">.</span><span class="n">long</span><span class="p">(),</span> <span class="n">ypred</span><span class="o">.</span><span class="n">long</span><span class="p">()]</span> <span class="o">+=</span> <span class="mi">1</span> - - <span class="c1"># save plot of current batch to disk</span> - <span class="k">if</span> <span class="n">plot</span><span class="p">:</span> - - <span class="c1"># plot inputs, ground truth and model predictions</span> - <span class="n">sname</span> <span class="o">=</span> <span class="n">fname</span> <span class="o">+</span> <span class="s1">'_</span><span class="si">{}</span><span class="s1">_</span><span class="si">{}</span><span class="s1">.pt'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">batch</span><span class="p">)</span> - <span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plot_sample</span><span class="p">(</span><span class="n">inputs</span><span class="o">.</span><span class="n">numpy</span><span class="p">()</span><span class="o">.</span><span class="n">clip</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> - <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">use_bands</span><span class="p">,</span> - <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">labels</span><span class="p">,</span> - <span class="n">y</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span> - <span class="n">y_pred</span><span class="o">=</span><span class="n">prd</span><span class="p">,</span> - <span class="n">state</span><span class="o">=</span><span class="n">sname</span><span class="p">,</span> - <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">output</span><span class="p">,</span> <span class="n">conf_mat</span></div> - - -<div class="viewcode-block" id="predict_scenes"><a class="viewcode-back" href="../../source/core.html#core.predict.predict_scenes">[docs]</a><span class="k">def</span> <span class="nf">predict_scenes</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">scene_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cm</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">plot</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> - <span class="sd">"""Classify each scene in ``ds`` with model ``model``.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.split.SceneSubset`</span> -<span class="sd"> An instance of `~pysegcnn.core.split.SceneSubset`.</span> -<span class="sd"> model : `pysegcnn.core.models.Network`</span> -<span class="sd"> An instance of `~pysegcnn.core.models.Network`.</span> -<span class="sd"> scene_id : `str` or `None`</span> -<span class="sd"> A valid scene identifier.</span> -<span class="sd"> cm : `bool`, optional</span> -<span class="sd"> Whether to compute the confusion matrix. The default is False.</span> -<span class="sd"> plot : `bool`, optional</span> -<span class="sd"> Whether to plot a false color composite, ground truth and model</span> -<span class="sd"> prediction for each scene. The default is False.</span> -<span class="sd"> **kwargs</span> -<span class="sd"> Additional keyword arguments passed to</span> -<span class="sd"> `pysegcnn.core.graphics.plot_sample`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if ``ds`` is not an instance of</span> -<span class="sd"> `~pysegcnn.core.split.SceneSubset`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> output : `dict`</span> -<span class="sd"> Output dictionary with keys:</span> -<span class="sd"> ``'input'``</span> -<span class="sd"> Model input data</span> -<span class="sd"> ``'labels'``</span> -<span class="sd"> The ground truth</span> -<span class="sd"> ``'prediction'``</span> -<span class="sd"> Model prediction</span> -<span class="sd"> conf_mat : `numpy.ndarray`</span> -<span class="sd"> The confusion matrix. Note that the confusion matrix ``conf_mat`` is</span> -<span class="sd"> only computed if ``cm`` = True.</span> -<span class="sd"> """</span> - <span class="c1"># check whether the dataset is a valid subset, i.e. an instance of</span> - <span class="c1"># pysegcnn.core.split.SceneSubset</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">SceneSubset</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'ds should be an instance of </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">SceneSubset</span><span class="p">)))</span> - - <span class="c1"># the device to compute on, use gpu if available</span> - <span class="n">device</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">device</span><span class="p">(</span><span class="s2">"cuda:0"</span> <span class="k">if</span> <span class="n">torch</span><span class="o">.</span><span class="n">cuda</span><span class="o">.</span><span class="n">is_available</span><span class="p">()</span> <span class="k">else</span> <span class="s2">"cpu"</span><span class="p">)</span> - - <span class="c1"># set the model to evaluation mode</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Setting model to evaluation mode ...'</span><span class="p">)</span> - <span class="n">model</span><span class="o">.</span><span class="n">eval</span><span class="p">()</span> - <span class="n">model</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">device</span><span class="p">)</span> - - <span class="c1"># base filename for each scene</span> - <span class="n">fname</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">state_file</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'.pt'</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> - - <span class="c1"># initialize confusion matrix</span> - <span class="n">conf_mat</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">shape</span><span class="o">=</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">nclasses</span><span class="p">,</span> <span class="n">model</span><span class="o">.</span><span class="n">nclasses</span><span class="p">))</span> - - <span class="c1"># check whether a scene id is provided</span> - <span class="k">if</span> <span class="n">scene_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> - <span class="n">scene_ids</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">ids</span> - <span class="k">else</span><span class="p">:</span> - <span class="c1"># the name of the selected scene</span> - <span class="n">scene_ids</span> <span class="o">=</span> <span class="p">[</span><span class="n">scene_id</span><span class="p">]</span> - - <span class="c1"># iterate over the scenes</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Predicting scenes of the </span><span class="si">{}</span><span class="s1"> dataset ...'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> - <span class="n">output</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">sid</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">scene_ids</span><span class="p">):</span> - - <span class="c1"># filename for the current scene</span> - <span class="n">sname</span> <span class="o">=</span> <span class="n">fname</span> <span class="o">+</span> <span class="s1">'_</span><span class="si">{}</span><span class="s1">_</span><span class="si">{}</span><span class="s1">.pt'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">sid</span><span class="p">)</span> - - <span class="c1"># get the indices of the tiles of the scene</span> - <span class="n">indices</span> <span class="o">=</span> <span class="n">_get_scene_tiles</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">sid</span><span class="p">)</span> - <span class="n">indices</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span> - - <span class="c1"># create a subset of the dataset</span> - <span class="n">scene_ds</span> <span class="o">=</span> <span class="n">Subset</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">indices</span><span class="p">)</span> - - <span class="c1"># create the dataloader</span> - <span class="n">scene_dl</span> <span class="o">=</span> <span class="n">DataLoader</span><span class="p">(</span><span class="n">scene_ds</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">scene_ds</span><span class="p">),</span> - <span class="n">shuffle</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">drop_last</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> - - <span class="c1"># predict the current scene</span> - <span class="k">for</span> <span class="n">b</span><span class="p">,</span> <span class="p">(</span><span class="n">inp</span><span class="p">,</span> <span class="n">lab</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">scene_dl</span><span class="p">):</span> - - <span class="c1"># send inputs and labels to device</span> - <span class="n">inp</span> <span class="o">=</span> <span class="n">inp</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">device</span><span class="p">)</span> - <span class="n">lab</span> <span class="o">=</span> <span class="n">lab</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">device</span><span class="p">)</span> - - <span class="c1"># apply forward pass: model prediction</span> - <span class="k">with</span> <span class="n">torch</span><span class="o">.</span><span class="n">no_grad</span><span class="p">():</span> - <span class="n">prd</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="n">model</span><span class="p">(</span><span class="n">inp</span><span class="p">),</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span> - - <span class="c1"># update confusion matrix</span> - <span class="k">if</span> <span class="n">cm</span><span class="p">:</span> - <span class="k">for</span> <span class="n">ytrue</span><span class="p">,</span> <span class="n">ypred</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">lab</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">),</span> <span class="n">prd</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)):</span> - <span class="n">conf_mat</span><span class="p">[</span><span class="n">ytrue</span><span class="o">.</span><span class="n">long</span><span class="p">(),</span> <span class="n">ypred</span><span class="o">.</span><span class="n">long</span><span class="p">()]</span> <span class="o">+=</span> <span class="mi">1</span> - - <span class="c1"># reconstruct the entire scene</span> - <span class="n">inputs</span> <span class="o">=</span> <span class="n">reconstruct_scene</span><span class="p">(</span><span class="n">inp</span><span class="p">)</span> - <span class="n">labels</span> <span class="o">=</span> <span class="n">reconstruct_scene</span><span class="p">(</span><span class="n">lab</span><span class="p">)</span> - <span class="n">prdtcn</span> <span class="o">=</span> <span class="n">reconstruct_scene</span><span class="p">(</span><span class="n">prd</span><span class="p">)</span> - - <span class="c1"># print progress</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Scene </span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1">, Id: </span><span class="si">{}</span><span class="s1">, Accuracy: </span><span class="si">{:.2f}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">scene_ids</span><span class="p">),</span> <span class="n">sid</span><span class="p">,</span> <span class="n">accuracy_function</span><span class="p">(</span><span class="n">prdtcn</span><span class="p">,</span> <span class="n">labels</span><span class="p">)))</span> - - <span class="c1"># save outputs to dictionary</span> - <span class="n">output</span><span class="p">[</span><span class="n">sid</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'input'</span><span class="p">:</span> <span class="n">inputs</span><span class="p">,</span> <span class="s1">'labels'</span><span class="p">:</span> <span class="n">labels</span><span class="p">,</span> <span class="s1">'prediction'</span><span class="p">:</span> <span class="n">prdtcn</span><span class="p">}</span> - - <span class="c1"># plot current scene</span> - <span class="k">if</span> <span class="n">plot</span><span class="p">:</span> - <span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plot_sample</span><span class="p">(</span><span class="n">inputs</span><span class="o">.</span><span class="n">clip</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> - <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">use_bands</span><span class="p">,</span> - <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">labels</span><span class="p">,</span> - <span class="n">y</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span> - <span class="n">y_pred</span><span class="o">=</span><span class="n">prdtcn</span><span class="p">,</span> - <span class="n">state</span><span class="o">=</span><span class="n">sname</span><span class="p">,</span> - <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">output</span><span class="p">,</span> <span class="n">conf_mat</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/split.html b/docs/_build/html/_modules/core/split.html deleted file mode 100644 index 452103871c0eb76a67777b8c3bd3bfb5434709e1..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/split.html +++ /dev/null @@ -1,885 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.split — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.split</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.split</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Split the dataset into training, validation and test set.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">datetime</span> -<span class="kn">import</span> <span class="nn">enum</span> - -<span class="c1"># externals</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">torch.utils.data.dataset</span> <span class="kn">import</span> <span class="n">Subset</span> - -<span class="c1"># the names of the subsets</span> -<span class="n">SUBSET_NAMES</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'train'</span><span class="p">,</span> <span class="s1">'valid'</span><span class="p">,</span> <span class="s1">'test'</span><span class="p">]</span> - - -<span class="k">def</span> <span class="nf">_ds_len</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">ratio</span><span class="p">):</span> - <span class="sd">"""Calcute number of samples in a dataset given a ratio.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `collections.Sized`</span> -<span class="sd"> An object with a __len__ attribute.</span> -<span class="sd"> ratio : `float`</span> -<span class="sd"> A ratio to multiply with the length of ``ds``.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> n_samples: `int`</span> -<span class="sd"> Length of ``ds`` * ``ratio``.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">ds</span><span class="p">)</span> <span class="o">*</span> <span class="n">ratio</span><span class="p">))</span> - - -<div class="viewcode-block" id="random_tile_split"><a class="viewcode-back" href="../../source/core.html#core.split.random_tile_split">[docs]</a><span class="k">def</span> <span class="nf">random_tile_split</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">tvratio</span><span class="p">,</span> <span class="n">ttratio</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span> - <span class="sd">"""Randomly split the tiles of a dataset.</span> - -<span class="sd"> For each scene, the tiles of the scene can be distributed among the</span> -<span class="sd"> training, validation and test set.</span> - -<span class="sd"> The parameters ``ttratio`` and ``tvratio`` control the size of the</span> -<span class="sd"> training, validation and test datasets.</span> - -<span class="sd"> Test dataset size : (1 - ``ttratio``) * len(``ds``)</span> -<span class="sd"> Train dataset size : ``ttratio`` * ``tvratio`` * len(``ds``)</span> -<span class="sd"> Validation dataset size: ``ttratio`` * (1 - ``tvratio``) * len(``ds``)</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> tvratio : `float`</span> -<span class="sd"> The ratio of training data to validation data, e.g. ``tvratio`` = 0.8</span> -<span class="sd"> means 80% training, 20% validation.</span> -<span class="sd"> ttratio : `float`, optional</span> -<span class="sd"> The ratio of training and validation data to test data, e.g.</span> -<span class="sd"> ``ttratio`` = 0.6 means 60% for training and validation, 40% for</span> -<span class="sd"> testing. The default is 1.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed for reproducibility. The default is 0.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> AssertionError</span> -<span class="sd"> Raised if the splits are not pairwise disjoint.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> subsets : `dict`</span> -<span class="sd"> Subset dictionary with keys:</span> -<span class="sd"> ``'train'``</span> -<span class="sd"> dictionary containing the training scenes.</span> -<span class="sd"> ``'valid'``</span> -<span class="sd"> dictionary containing the validation scenes.</span> -<span class="sd"> ``'test'``</span> -<span class="sd"> dictionary containing the test scenes.</span> - -<span class="sd"> """</span> - <span class="c1"># set the random seed for reproducibility</span> - <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="n">seed</span><span class="p">)</span> - - <span class="c1"># randomly permute indices to access dataset</span> - <span class="n">indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">permutation</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">ds</span><span class="p">))</span> - - <span class="c1"># length of the training and validation dataset</span> - <span class="c1"># number of samples: (ttratio * len(ds))</span> - <span class="n">trav_len</span> <span class="o">=</span> <span class="n">_ds_len</span><span class="p">(</span><span class="n">indices</span><span class="p">,</span> <span class="n">ttratio</span><span class="p">)</span> - <span class="n">trav_indices</span> <span class="o">=</span> <span class="n">indices</span><span class="p">[:</span><span class="n">trav_len</span><span class="p">]</span> - - <span class="c1"># length of the training dataset</span> - <span class="c1"># number of samples: (ttratio * tvratio * len(ds))</span> - <span class="n">train_len</span> <span class="o">=</span> <span class="n">_ds_len</span><span class="p">(</span><span class="n">trav_indices</span><span class="p">,</span> <span class="n">tvratio</span><span class="p">)</span> - <span class="n">train_ind</span> <span class="o">=</span> <span class="n">trav_indices</span><span class="p">[:</span><span class="n">train_len</span><span class="p">]</span> - - <span class="c1"># length of the validation dataset</span> - <span class="c1"># number of samples: (ttratio * (1- tvratio) * len(ds))</span> - <span class="n">valid_ind</span> <span class="o">=</span> <span class="n">trav_indices</span><span class="p">[</span><span class="n">train_len</span><span class="p">:]</span> - - <span class="c1"># length of the test dataset</span> - <span class="c1"># number of samples: ((1 - ttratio) * len(ds))</span> - <span class="n">test_ind</span> <span class="o">=</span> <span class="n">indices</span><span class="p">[</span><span class="n">trav_len</span><span class="p">:]</span> - - <span class="c1"># get the tiles of the scenes of each dataset</span> - <span class="n">subsets</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">dataset</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">([</span><span class="n">train_ind</span><span class="p">,</span> <span class="n">valid_ind</span><span class="p">,</span> <span class="n">test_ind</span><span class="p">]):</span> - - <span class="c1"># store the indices and corresponding tiles of the current subset to</span> - <span class="c1"># dictionary</span> - <span class="n">subsets</span><span class="p">[</span><span class="n">SUBSET_NAMES</span><span class="p">[</span><span class="n">name</span><span class="p">]]</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">ds</span><span class="o">.</span><span class="n">scenes</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">dataset</span><span class="p">}</span> - - <span class="c1"># check if the splits are disjoint</span> - <span class="k">assert</span> <span class="n">pairwise_disjoint</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">subsets</span><span class="o">.</span><span class="n">values</span><span class="p">()])</span> - - <span class="k">return</span> <span class="n">subsets</span></div> - - -<div class="viewcode-block" id="random_scene_split"><a class="viewcode-back" href="../../source/core.html#core.split.random_scene_split">[docs]</a><span class="k">def</span> <span class="nf">random_scene_split</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">tvratio</span><span class="p">,</span> <span class="n">ttratio</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span> - <span class="sd">"""Randomly split the tiles of a dataset.</span> - -<span class="sd"> For each scene, all the tiles of the scene are included in either the</span> -<span class="sd"> training, validation or test set, respectively.</span> - -<span class="sd"> The parameters ``ttratio`` and ``tvratio`` control the size of the</span> -<span class="sd"> training, validation and test datasets.</span> - -<span class="sd"> Test dataset size : (1 - ``ttratio``) * len(``ds``)</span> -<span class="sd"> Train dataset size : ``ttratio`` * ``tvratio`` * len(``ds``)</span> -<span class="sd"> Validation dataset size: ``ttratio`` * (1 - ``tvratio``) * len(``ds``)</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> tvratio : `float`</span> -<span class="sd"> The ratio of training data to validation data, e.g. ``tvratio`` = 0.8</span> -<span class="sd"> means 80% training, 20% validation.</span> -<span class="sd"> ttratio : `float`, optional</span> -<span class="sd"> The ratio of training and validation data to test data, e.g.</span> -<span class="sd"> ``ttratio`` = 0.6 means 60% for training and validation, 40% for</span> -<span class="sd"> testing. The default is 1.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed for reproducibility. The default is 0.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> AssertionError</span> -<span class="sd"> Raised if the splits are not pairwise disjoint.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> subsets : `dict`</span> -<span class="sd"> Subset dictionary with keys:</span> -<span class="sd"> ``'train'``</span> -<span class="sd"> dictionary containing the training scenes.</span> -<span class="sd"> ``'valid'``</span> -<span class="sd"> dictionary containing the validation scenes.</span> -<span class="sd"> ``'test'``</span> -<span class="sd"> dictionary containing the test scenes.</span> - -<span class="sd"> """</span> - <span class="c1"># set the random seed for reproducibility</span> - <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="n">seed</span><span class="p">)</span> - - <span class="c1"># get the names of the scenes and generate random permutation</span> - <span class="n">scene_ids</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">permutation</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">([</span><span class="n">s</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">ds</span><span class="o">.</span><span class="n">scenes</span><span class="p">]))</span> - - <span class="c1"># the training and validation scenes</span> - <span class="c1"># number of samples: (ttratio * nscenes)</span> - <span class="n">trav_len</span> <span class="o">=</span> <span class="n">_ds_len</span><span class="p">(</span><span class="n">scene_ids</span><span class="p">,</span> <span class="n">ttratio</span><span class="p">)</span> - <span class="n">trav_scenes</span> <span class="o">=</span> <span class="n">scene_ids</span><span class="p">[:</span><span class="n">trav_len</span><span class="p">]</span> - - <span class="c1"># the training scenes</span> - <span class="c1"># number of samples: (ttratio * tvratio * nscenes)</span> - <span class="n">train_len</span> <span class="o">=</span> <span class="n">_ds_len</span><span class="p">(</span><span class="n">trav_scenes</span><span class="p">,</span> <span class="n">tvratio</span><span class="p">)</span> - <span class="n">train_scenes</span> <span class="o">=</span> <span class="n">trav_scenes</span><span class="p">[:</span><span class="n">train_len</span><span class="p">]</span> - - <span class="c1"># the validation scenes</span> - <span class="c1"># number of samples: (ttratio * (1- tvratio) * nscenes)</span> - <span class="n">valid_scenes</span> <span class="o">=</span> <span class="n">trav_scenes</span><span class="p">[</span><span class="n">train_len</span><span class="p">:]</span> - - <span class="c1"># the test scenes</span> - <span class="c1"># number of samples:((1 - ttratio) * nscenes)</span> - <span class="n">test_scenes</span> <span class="o">=</span> <span class="n">scene_ids</span><span class="p">[</span><span class="n">trav_len</span><span class="p">:]</span> - - <span class="c1"># get the tiles of the scenes of each dataset</span> - <span class="n">subsets</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">dataset</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">([</span><span class="n">train_scenes</span><span class="p">,</span> <span class="n">valid_scenes</span><span class="p">,</span> <span class="n">test_scenes</span><span class="p">]):</span> - - <span class="c1"># store the indices and corresponding tiles of the current subset to</span> - <span class="c1"># dictionary</span> - <span class="n">subsets</span><span class="p">[</span><span class="n">SUBSET_NAMES</span><span class="p">[</span><span class="n">name</span><span class="p">]]</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">scenes</span><span class="p">)</span> - <span class="k">if</span> <span class="n">v</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="ow">in</span> <span class="n">dataset</span><span class="p">}</span> - - <span class="c1"># check if the splits are disjoint</span> - <span class="k">assert</span> <span class="n">pairwise_disjoint</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">subsets</span><span class="o">.</span><span class="n">values</span><span class="p">()])</span> - - <span class="k">return</span> <span class="n">subsets</span></div> - - -<span class="c1"># split the scenes of a dataset based on a date, useful for time series data</span> -<span class="c1"># scenes before date build the training set, scenes after the date build the</span> -<span class="c1"># validation set, the test set is empty</span> -<div class="viewcode-block" id="date_scene_split"><a class="viewcode-back" href="../../source/core.html#core.split.date_scene_split">[docs]</a><span class="k">def</span> <span class="nf">date_scene_split</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">date</span><span class="p">,</span> <span class="n">dateformat</span><span class="o">=</span><span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">):</span> - <span class="sd">"""Split the dataset based on a date.</span> - -<span class="sd"> Scenes before ``date`` build the training set, scenes after ``date`` build</span> -<span class="sd"> the validation set, the test set is empty.</span> - -<span class="sd"> Useful for time series data.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> date : `str`</span> -<span class="sd"> A date.</span> -<span class="sd"> dateformat : `str`, optional</span> -<span class="sd"> The format of ``date``. ``dateformat`` is used by</span> -<span class="sd"> `datetime.datetime.strptime' to parse ``date`` to a `datetime.datetime`</span> -<span class="sd"> object. The default is '%Y%m%d'.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> AssertionError</span> -<span class="sd"> Raised if the splits are not pairwise disjoint.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> subsets : `dict`</span> -<span class="sd"> Subset dictionary with keys:</span> -<span class="sd"> ``'train'``</span> -<span class="sd"> dictionary containing the training scenes.</span> -<span class="sd"> ``'valid'``</span> -<span class="sd"> dictionary containing the validation scenes.</span> -<span class="sd"> ``'test'``</span> -<span class="sd"> dictionary containing the test scenes, empty.</span> - -<span class="sd"> """</span> - <span class="c1"># convert date to datetime object</span> - <span class="n">date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">date</span><span class="p">,</span> <span class="n">dateformat</span><span class="p">)</span> - - <span class="c1"># the training, validation and test scenes</span> - <span class="n">train_scenes</span> <span class="o">=</span> <span class="p">{</span><span class="n">i</span><span class="p">:</span> <span class="n">s</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">s</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">scenes</span><span class="p">)</span> <span class="k">if</span> <span class="n">s</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> <span class="o"><=</span> <span class="n">date</span><span class="p">}</span> - <span class="n">valid_scenes</span> <span class="o">=</span> <span class="p">{</span><span class="n">i</span><span class="p">:</span> <span class="n">s</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">s</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">scenes</span><span class="p">)</span> <span class="k">if</span> <span class="n">s</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> <span class="o">></span> <span class="n">date</span><span class="p">}</span> - <span class="n">test_scenes</span> <span class="o">=</span> <span class="p">{}</span> - - <span class="c1"># build the training and test datasets</span> - <span class="n">subsets</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">scenes</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">([</span><span class="n">train_scenes</span><span class="p">,</span> <span class="n">valid_scenes</span><span class="p">,</span> <span class="n">test_scenes</span><span class="p">]):</span> - - <span class="c1"># store the indices and corresponding tiles of the current subset to</span> - <span class="c1"># dictionary</span> - <span class="n">subsets</span><span class="p">[</span><span class="n">SUBSET_NAMES</span><span class="p">[</span><span class="n">name</span><span class="p">]]</span> <span class="o">=</span> <span class="n">scenes</span> - - <span class="c1"># check if the splits are disjoint</span> - <span class="k">assert</span> <span class="n">pairwise_disjoint</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">subsets</span><span class="o">.</span><span class="n">values</span><span class="p">()])</span> - - <span class="k">return</span> <span class="n">subsets</span></div> - - -<div class="viewcode-block" id="pairwise_disjoint"><a class="viewcode-back" href="../../source/core.html#core.split.pairwise_disjoint">[docs]</a><span class="k">def</span> <span class="nf">pairwise_disjoint</span><span class="p">(</span><span class="n">sets</span><span class="p">):</span> - <span class="sd">"""Check if ``sets`` are pairwise disjoint.</span> - -<span class="sd"> Sets are pairwise disjoint if the length of their union equals the sum of</span> -<span class="sd"> their lengths.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> sets : `list` [`collections.Sized`]</span> -<span class="sd"> A list of sized objects.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> disjoint : `bool`</span> -<span class="sd"> Whether the sets are pairwise disjoint.</span> - -<span class="sd"> """</span> - <span class="n">union</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span><span class="o">.</span><span class="n">union</span><span class="p">(</span><span class="o">*</span><span class="n">sets</span><span class="p">)</span> - <span class="n">n</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="k">for</span> <span class="n">u</span> <span class="ow">in</span> <span class="n">sets</span><span class="p">)</span> - <span class="k">return</span> <span class="n">n</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">union</span><span class="p">)</span></div> - - -<div class="viewcode-block" id="CustomSubset"><a class="viewcode-back" href="../../source/core.html#core.split.CustomSubset">[docs]</a><span class="k">class</span> <span class="nc">CustomSubset</span><span class="p">(</span><span class="n">Subset</span><span class="p">):</span> - <span class="sd">"""Custom subset inheriting `torch.utils.data.Subset`."""</span> - - <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Representation of ``~pysegcnn.core.split.CustomSubset``."""</span> - <span class="c1"># representation string</span> - <span class="n">fs</span> <span class="o">=</span> <span class="s1">'- </span><span class="si">{}</span><span class="s1">: </span><span class="si">{:d}</span><span class="s1"> tiles (</span><span class="si">{:.2f}</span><span class="s1">%)'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scenes</span><span class="p">),</span> <span class="mi">100</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">scenes</span><span class="p">)</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">dataset</span><span class="p">))</span> - - <span class="k">return</span> <span class="n">fs</span></div> - - -<div class="viewcode-block" id="SceneSubset"><a class="viewcode-back" href="../../source/core.html#core.split.SceneSubset">[docs]</a><span class="k">class</span> <span class="nc">SceneSubset</span><span class="p">(</span><span class="n">CustomSubset</span><span class="p">):</span> - <span class="sd">"""A custom subset for dataset splits where the scenes are preserved.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> indices : `list` [`int`]</span> -<span class="sd"> List of the subset indices to access ``ds``.</span> -<span class="sd"> name : `str`</span> -<span class="sd"> Name of the subset.</span> -<span class="sd"> scenes : `list` [`dict`]</span> -<span class="sd"> List of the subset tiles.</span> -<span class="sd"> scene_ids : `list` or `numpy.ndarray`</span> -<span class="sd"> Container of the scene ids.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">ds</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">scenes</span><span class="p">,</span> <span class="n">scene_ids</span><span class="p">):</span> - <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">dataset</span><span class="o">=</span><span class="n">ds</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="n">indices</span><span class="p">)</span> - - <span class="c1"># the name of the subset</span> - <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span> - - <span class="c1"># the scene in the subset</span> - <span class="bp">self</span><span class="o">.</span><span class="n">scenes</span> <span class="o">=</span> <span class="n">scenes</span> - - <span class="c1"># the names of the scenes</span> - <span class="bp">self</span><span class="o">.</span><span class="n">ids</span> <span class="o">=</span> <span class="n">scene_ids</span></div> - - -<div class="viewcode-block" id="RandomSubset"><a class="viewcode-back" href="../../source/core.html#core.split.RandomSubset">[docs]</a><span class="k">class</span> <span class="nc">RandomSubset</span><span class="p">(</span><span class="n">CustomSubset</span><span class="p">):</span> - <span class="sd">"""A custom subset for random dataset splits.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> indices : `list` [`int`]</span> -<span class="sd"> List of the subset indices to access ``ds``.</span> -<span class="sd"> name : `str`</span> -<span class="sd"> Name of the subset.</span> -<span class="sd"> scenes : `list` [`dict`]</span> -<span class="sd"> List of the subset tiles.</span> -<span class="sd"> scene_ids : `list` or `numpy.ndarray`</span> -<span class="sd"> Container of the scene ids.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">ds</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">scenes</span><span class="p">,</span> <span class="n">scene_ids</span><span class="p">):</span> - <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">dataset</span><span class="o">=</span><span class="n">ds</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="n">indices</span><span class="p">)</span> - - <span class="c1"># the name of the subset</span> - <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span> - - <span class="c1"># the scene in the subset</span> - <span class="bp">self</span><span class="o">.</span><span class="n">scenes</span> <span class="o">=</span> <span class="n">scenes</span></div> - - -<div class="viewcode-block" id="Split"><a class="viewcode-back" href="../../source/core.html#core.split.Split">[docs]</a><span class="k">class</span> <span class="nc">Split</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> - <span class="sd">"""Generic class handling how ``ds`` is split.</span> - -<span class="sd"> Inherit `~pysegcnn.core.split.Split` and implement the</span> -<span class="sd"> `~pysegcnn.core.split.Split.subsets` and</span> -<span class="sd"> `~pysegcnn.core.split.Split.subset_type` method.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">ds</span><span class="p">):</span> - - <span class="c1"># the dataset to split</span> - <span class="bp">self</span><span class="o">.</span><span class="n">ds</span> <span class="o">=</span> <span class="n">ds</span> - -<div class="viewcode-block" id="Split.split"><a class="viewcode-back" href="../../source/core.html#core.split.Split.split">[docs]</a> <span class="k">def</span> <span class="nf">split</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Split dataset into training, validation and test set.</span> - -<span class="sd"> `~pysegcnn.core.split.Split.split` works only if</span> -<span class="sd"> `~pysegcnn.core.split.Split.subsets` and</span> -<span class="sd"> `~pysegcnn.core.split.Split.subset_type` are implemented.</span> - -<span class="sd"> """</span> - <span class="c1"># build the subsets</span> - <span class="n">ds_split</span> <span class="o">=</span> <span class="p">[]</span> - <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">sub</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">subsets</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> - - <span class="c1"># the scene identifiers of the current subset</span> - <span class="n">ids</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">([</span><span class="n">s</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">sub</span><span class="o">.</span><span class="n">values</span><span class="p">()])</span> - - <span class="c1"># build the subset</span> - <span class="n">sbst</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">subset_type</span><span class="p">()(</span><span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">sub</span><span class="o">.</span><span class="n">keys</span><span class="p">()),</span> <span class="n">name</span><span class="p">,</span> - <span class="nb">list</span><span class="p">(</span><span class="n">sub</span><span class="o">.</span><span class="n">values</span><span class="p">()),</span> <span class="n">ids</span><span class="p">)</span> - <span class="n">ds_split</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sbst</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">ds_split</span></div> - -<div class="viewcode-block" id="Split.subsets"><a class="viewcode-back" href="../../source/core.html#core.split.Split.subsets">[docs]</a> <span class="k">def</span> <span class="nf">subsets</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Define training, validation and test sets.</span> - -<span class="sd"> Wrapper method for</span> -<span class="sd"> `pysegcnn.core.split.Split.random_tile_split`,</span> -<span class="sd"> `pysegcnn.core.split.Split.random_scene_split` or</span> -<span class="sd"> `pysegcnn.core.split.Split.date_scene_split`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.split.Split` is not inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span></div> - -<div class="viewcode-block" id="Split.subset_type"><a class="viewcode-back" href="../../source/core.html#core.split.Split.subset_type">[docs]</a> <span class="k">def</span> <span class="nf">subset_type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Define the type of each subset.</span> - -<span class="sd"> Wrapper method for</span> -<span class="sd"> `pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `pysegcnn.core.split.SceneSubset`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.split.Split` is not inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span></div></div> - - -<div class="viewcode-block" id="DateSplit"><a class="viewcode-back" href="../../source/core.html#core.split.DateSplit">[docs]</a><span class="k">class</span> <span class="nc">DateSplit</span><span class="p">(</span><span class="n">Split</span><span class="p">):</span> - <span class="sd">"""Split the dataset based on a date.</span> - -<span class="sd"> Class wrapper for `pysegcnn.core.split.Split.date_scene_split`.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> date : 'str'</span> -<span class="sd"> A date.</span> -<span class="sd"> dateformat : 'str', optional</span> -<span class="sd"> The format of ``date``. ``dateformat`` is used by</span> -<span class="sd"> `datetime.datetime.strptime' to parse ``date`` to a `datetime.datetime`</span> -<span class="sd"> object. The default is '%Y%m%d'.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">ds</span><span class="p">,</span> <span class="n">date</span><span class="p">,</span> <span class="n">dateformat</span><span class="p">):</span> - <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">ds</span><span class="p">)</span> - - <span class="c1"># the date to split the dataset</span> - <span class="c1"># before: training set</span> - <span class="c1"># after : validation set</span> - <span class="bp">self</span><span class="o">.</span><span class="n">date</span> <span class="o">=</span> <span class="n">date</span> - - <span class="c1"># the format of the date</span> - <span class="bp">self</span><span class="o">.</span><span class="n">dateformat</span> <span class="o">=</span> <span class="n">dateformat</span> - -<div class="viewcode-block" id="DateSplit.subsets"><a class="viewcode-back" href="../../source/core.html#core.split.DateSplit.subsets">[docs]</a> <span class="k">def</span> <span class="nf">subsets</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Wrap `pysegcnn.core.split.Split.date_scene_split`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> subsets : `dict`</span> -<span class="sd"> Subset dictionary with keys:</span> -<span class="sd"> ``'train'``</span> -<span class="sd"> dictionary containing the training scenes.</span> -<span class="sd"> ``'valid'``</span> -<span class="sd"> dictionary containing the validation scenes.</span> -<span class="sd"> ``'test'``</span> -<span class="sd"> dictionary containing the test scenes, empty.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">date_scene_split</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">date</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dateformat</span><span class="p">)</span></div> - -<div class="viewcode-block" id="DateSplit.subset_type"><a class="viewcode-back" href="../../source/core.html#core.split.DateSplit.subset_type">[docs]</a> <span class="k">def</span> <span class="nf">subset_type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Wrap `pysegcnn.core.split.SceneSubset`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> SceneSubset : `pysegcnn.core.split.SceneSubset`</span> -<span class="sd"> The subset type.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">SceneSubset</span></div></div> - - -<div class="viewcode-block" id="RandomSplit"><a class="viewcode-back" href="../../source/core.html#core.split.RandomSplit">[docs]</a><span class="k">class</span> <span class="nc">RandomSplit</span><span class="p">(</span><span class="n">Split</span><span class="p">):</span> - <span class="sd">"""Randomly split the dataset.</span> - -<span class="sd"> Generic class for random dataset splits.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> tvratio : `float`</span> -<span class="sd"> The ratio of training data to validation data, e.g. ``tvratio`` = 0.8</span> -<span class="sd"> means 80% training, 20% validation.</span> -<span class="sd"> ttratio : `float`, optional</span> -<span class="sd"> The ratio of training and validation data to test data, e.g.</span> -<span class="sd"> ``ttratio`` = 0.6 means 60% for training and validation, 40% for</span> -<span class="sd"> testing. The default is 1.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed for reproducibility. The default is 0.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">ds</span><span class="p">,</span> <span class="n">ttratio</span><span class="p">,</span> <span class="n">tvratio</span><span class="p">,</span> <span class="n">seed</span><span class="p">):</span> - <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">ds</span><span class="p">)</span> - - <span class="c1"># the training, validation and test set ratios</span> - <span class="bp">self</span><span class="o">.</span><span class="n">ttratio</span> <span class="o">=</span> <span class="n">ttratio</span> - <span class="bp">self</span><span class="o">.</span><span class="n">tvratio</span> <span class="o">=</span> <span class="n">tvratio</span> - - <span class="c1"># the random seed: useful for reproducibility</span> - <span class="bp">self</span><span class="o">.</span><span class="n">seed</span> <span class="o">=</span> <span class="n">seed</span></div> - - -<div class="viewcode-block" id="RandomTileSplit"><a class="viewcode-back" href="../../source/core.html#core.split.RandomTileSplit">[docs]</a><span class="k">class</span> <span class="nc">RandomTileSplit</span><span class="p">(</span><span class="n">RandomSplit</span><span class="p">):</span> - <span class="sd">"""Randomly split the dataset.</span> - -<span class="sd"> For each scene, the tiles of the scene can be distributed among the</span> -<span class="sd"> training, validation and test set.</span> - -<span class="sd"> Class wrapper for `pysegcnn.core.split.Split.random_tile_split`.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> tvratio : `float`</span> -<span class="sd"> The ratio of training data to validation data, e.g. ``tvratio`` = 0.8</span> -<span class="sd"> means 80% training, 20% validation.</span> -<span class="sd"> ttratio : `float`, optional</span> -<span class="sd"> The ratio of training and validation data to test data, e.g.</span> -<span class="sd"> ``ttratio`` = 0.6 means 60% for training and validation, 40% for</span> -<span class="sd"> testing. The default is 1.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed for reproducibility. The default is 0.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">ds</span><span class="p">,</span> <span class="n">ttratio</span><span class="p">,</span> <span class="n">tvratio</span><span class="p">,</span> <span class="n">seed</span><span class="p">):</span> - <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">ds</span><span class="p">,</span> <span class="n">ttratio</span><span class="p">,</span> <span class="n">tvratio</span><span class="p">,</span> <span class="n">seed</span><span class="p">)</span> - -<div class="viewcode-block" id="RandomTileSplit.subsets"><a class="viewcode-back" href="../../source/core.html#core.split.RandomTileSplit.subsets">[docs]</a> <span class="k">def</span> <span class="nf">subsets</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Wrap `pysegcnn.core.split.Split.random_tile_split`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> subsets : `dict`</span> -<span class="sd"> Subset dictionary with keys:</span> -<span class="sd"> ``'train'``</span> -<span class="sd"> dictionary containing the training scenes.</span> -<span class="sd"> ``'valid'``</span> -<span class="sd"> dictionary containing the validation scenes.</span> -<span class="sd"> ``'test'``</span> -<span class="sd"> dictionary containing the test scenes, empty.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">random_tile_split</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tvratio</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ttratio</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">seed</span><span class="p">)</span></div> - -<div class="viewcode-block" id="RandomTileSplit.subset_type"><a class="viewcode-back" href="../../source/core.html#core.split.RandomTileSplit.subset_type">[docs]</a> <span class="k">def</span> <span class="nf">subset_type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Wrap `pysegcnn.core.split.RandomSubset`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> SceneSubset : `pysegcnn.core.split.RandomSubset`</span> -<span class="sd"> The subset type.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">RandomSubset</span></div></div> - - -<div class="viewcode-block" id="RandomSceneSplit"><a class="viewcode-back" href="../../source/core.html#core.split.RandomSceneSplit">[docs]</a><span class="k">class</span> <span class="nc">RandomSceneSplit</span><span class="p">(</span><span class="n">RandomSplit</span><span class="p">):</span> - <span class="sd">"""Randomly split the dataset.</span> - -<span class="sd"> For each scene, all the tiles of the scene are included in either the</span> -<span class="sd"> training, validation or test set, respectively.</span> - -<span class="sd"> Class wrapper for `pysegcnn.core.split.Split.random_scene_split`.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `~pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> tvratio : `float`</span> -<span class="sd"> The ratio of training data to validation data, e.g. ``tvratio`` = 0.8</span> -<span class="sd"> means 80% training, 20% validation.</span> -<span class="sd"> ttratio : `float`, optional</span> -<span class="sd"> The ratio of training and validation data to test data, e.g.</span> -<span class="sd"> ``ttratio`` = 0.6 means 60% for training and validation, 40% for</span> -<span class="sd"> testing. The default is 1.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed for reproducibility. The default is 0.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">ds</span><span class="p">,</span> <span class="n">ttratio</span><span class="p">,</span> <span class="n">tvratio</span><span class="p">,</span> <span class="n">seed</span><span class="p">):</span> - <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">ds</span><span class="p">,</span> <span class="n">ttratio</span><span class="p">,</span> <span class="n">tvratio</span><span class="p">,</span> <span class="n">seed</span><span class="p">)</span> - -<div class="viewcode-block" id="RandomSceneSplit.subsets"><a class="viewcode-back" href="../../source/core.html#core.split.RandomSceneSplit.subsets">[docs]</a> <span class="k">def</span> <span class="nf">subsets</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Wrap `pysegcnn.core.split.Split.random_scene_split`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> subsets : `dict`</span> -<span class="sd"> Subset dictionary with keys:</span> -<span class="sd"> ``'train'``</span> -<span class="sd"> dictionary containing the training scenes.</span> -<span class="sd"> ``'valid'``</span> -<span class="sd"> dictionary containing the validation scenes.</span> -<span class="sd"> ``'test'``</span> -<span class="sd"> dictionary containing the test scenes, empty.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">random_scene_split</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tvratio</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ttratio</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">seed</span><span class="p">)</span></div> - -<div class="viewcode-block" id="RandomSceneSplit.subset_type"><a class="viewcode-back" href="../../source/core.html#core.split.RandomSceneSplit.subset_type">[docs]</a> <span class="k">def</span> <span class="nf">subset_type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Wrap `pysegcnn.core.split.SceneSubset`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> SceneSubset : `pysegcnn.core.split.SceneSubset`</span> -<span class="sd"> The subset type.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">SceneSubset</span></div></div> - - -<div class="viewcode-block" id="SupportedSplits"><a class="viewcode-back" href="../../source/core.html#core.split.SupportedSplits">[docs]</a><span class="k">class</span> <span class="nc">SupportedSplits</span><span class="p">(</span><span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">):</span> - <span class="sd">"""Names and corresponding classes of the implemented split modes."""</span> - - <span class="n">random</span> <span class="o">=</span> <span class="n">RandomTileSplit</span> - <span class="n">scene</span> <span class="o">=</span> <span class="n">RandomSceneSplit</span> - <span class="n">date</span> <span class="o">=</span> <span class="n">DateSplit</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/trainer.html b/docs/_build/html/_modules/core/trainer.html deleted file mode 100644 index 1822007ba38b704ee90ffb1f66e5a33d6b973067..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/trainer.html +++ /dev/null @@ -1,1760 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.trainer — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.trainer</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.trainer</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Model configuration and training.</span> - -<span class="sd">This module provides an end-to-end framework of dataclasses designed to train</span> -<span class="sd">segmentation models on image datasets.</span> - -<span class="sd">See pysegcnn/main/train.py for a complete walkthrough.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">dataclasses</span> -<span class="kn">import</span> <span class="nn">pathlib</span> -<span class="kn">import</span> <span class="nn">logging</span> -<span class="kn">import</span> <span class="nn">datetime</span> - -<span class="c1"># externals</span> -<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> -<span class="kn">import</span> <span class="nn">torch</span> -<span class="kn">import</span> <span class="nn">torch.nn</span> <span class="k">as</span> <span class="nn">nn</span> -<span class="kn">import</span> <span class="nn">torch.nn.functional</span> <span class="k">as</span> <span class="nn">F</span> -<span class="kn">from</span> <span class="nn">torch.utils.data</span> <span class="kn">import</span> <span class="n">DataLoader</span><span class="p">,</span> <span class="n">Dataset</span> -<span class="kn">from</span> <span class="nn">torch.optim</span> <span class="kn">import</span> <span class="n">Optimizer</span> - -<span class="c1"># locals</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.dataset</span> <span class="kn">import</span> <span class="n">SupportedDatasets</span><span class="p">,</span> <span class="n">ImageDataset</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.transforms</span> <span class="kn">import</span> <span class="n">Augment</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.utils</span> <span class="kn">import</span> <span class="n">img2np</span><span class="p">,</span> <span class="n">item_in_enum</span><span class="p">,</span> <span class="n">accuracy_function</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.split</span> <span class="kn">import</span> <span class="n">SupportedSplits</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.models</span> <span class="kn">import</span> <span class="p">(</span><span class="n">SupportedModels</span><span class="p">,</span> <span class="n">SupportedOptimizers</span><span class="p">,</span> - <span class="n">SupportedLossFunctions</span><span class="p">,</span> <span class="n">Network</span><span class="p">)</span> -<span class="kn">from</span> <span class="nn">pysegcnn.core.layers</span> <span class="kn">import</span> <span class="n">Conv2dSame</span> -<span class="kn">from</span> <span class="nn">pysegcnn.main.config</span> <span class="kn">import</span> <span class="n">HERE</span> - -<span class="c1"># module level logger</span> -<span class="n">LOGGER</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> - - -<div class="viewcode-block" id="BaseConfig"><a class="viewcode-back" href="../../source/core.html#core.trainer.BaseConfig">[docs]</a><span class="nd">@dataclasses</span><span class="o">.</span><span class="n">dataclass</span> -<span class="k">class</span> <span class="nc">BaseConfig</span><span class="p">:</span> - <span class="sd">"""Base `dataclasses.dataclass` for each configuration."""</span> - - <span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check the type of each argument.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if the conversion to the specified type of the argument</span> -<span class="sd"> fails.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="c1"># check input types</span> - <span class="k">for</span> <span class="n">field</span> <span class="ow">in</span> <span class="n">dataclasses</span><span class="o">.</span><span class="n">fields</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="c1"># the value of the current field</span> - <span class="n">value</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">field</span><span class="o">.</span><span class="n">name</span><span class="p">)</span> - - <span class="c1"># check whether the value is of the correct type</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">field</span><span class="o">.</span><span class="n">type</span><span class="p">):</span> - <span class="c1"># try to convert the value to the correct type</span> - <span class="k">try</span><span class="p">:</span> - <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">field</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">field</span><span class="o">.</span><span class="n">type</span><span class="p">(</span><span class="n">value</span><span class="p">))</span> - <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span> - <span class="c1"># raise an exception if the conversion fails</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'Expected </span><span class="si">{}</span><span class="s1"> to be </span><span class="si">{}</span><span class="s1">, got </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">field</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">field</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> - <span class="nb">type</span><span class="p">(</span><span class="n">value</span><span class="p">)))</span></div> - - -<div class="viewcode-block" id="DatasetConfig"><a class="viewcode-back" href="../../source/core.html#core.trainer.DatasetConfig">[docs]</a><span class="nd">@dataclasses</span><span class="o">.</span><span class="n">dataclass</span> -<span class="k">class</span> <span class="nc">DatasetConfig</span><span class="p">(</span><span class="n">BaseConfig</span><span class="p">):</span> - <span class="sd">"""Dataset configuration class.</span> - -<span class="sd"> Instanciate a dataset.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> dataset_name : `str`</span> -<span class="sd"> The name of the dataset.</span> -<span class="sd"> root_dir : `pathlib.Path`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> bands : `list` [`str`]</span> -<span class="sd"> A list of the spectral bands to use.</span> -<span class="sd"> tile_size : `int`</span> -<span class="sd"> The size of the tiles. Each scene is divided into square tiles of shape</span> -<span class="sd"> (tile_size, tile_size).</span> -<span class="sd"> gt_pattern : `str`</span> -<span class="sd"> A pattern to match the ground truth naming convention. All directories</span> -<span class="sd"> and subdirectories in ``root_dir`` are searched for files matching</span> -<span class="sd"> ``gt_pattern``.</span> -<span class="sd"> seed : `int`</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <span class="n">dataset_name</span><span class="p">:</span> <span class="nb">str</span> - <span class="n">root_dir</span><span class="p">:</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span> - <span class="n">bands</span><span class="p">:</span> <span class="nb">list</span> - <span class="n">tile_size</span><span class="p">:</span> <span class="nb">int</span> - <span class="n">gt_pattern</span><span class="p">:</span> <span class="nb">str</span> - <span class="n">seed</span><span class="p">:</span> <span class="nb">int</span> - <span class="n">sort</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span> - <span class="n">transforms</span><span class="p">:</span> <span class="nb">list</span> <span class="o">=</span> <span class="n">dataclasses</span><span class="o">.</span><span class="n">field</span><span class="p">(</span><span class="n">default_factory</span><span class="o">=</span><span class="nb">list</span><span class="p">)</span> - <span class="n">pad</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span> - - <span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check the type of each argument.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> ValueError</span> -<span class="sd"> Raised if ``dataset_name`` is not supported.</span> -<span class="sd"> FileNotFoundError</span> -<span class="sd"> Raised if ``root_dir`` does not exist.</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if not each item in ``transforms`` is an instance of</span> -<span class="sd"> `pysegcnn.core.split.Augment` in case ``transforms`` is not empty.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="c1"># check input types</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span> - - <span class="c1"># check whether the dataset is currently supported</span> - <span class="bp">self</span><span class="o">.</span><span class="n">dataset_class</span> <span class="o">=</span> <span class="n">item_in_enum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset_name</span><span class="p">,</span> <span class="n">SupportedDatasets</span><span class="p">)</span> - - <span class="c1"># check whether the root directory exists</span> - <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_dir</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="k">raise</span> <span class="ne">FileNotFoundError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> does not exist.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">root_dir</span><span class="p">))</span> - - <span class="c1"># check whether the transformations inherit from the correct class</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">([</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">Augment</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span> <span class="k">if</span> - <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span><span class="p">]):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'Each transformation is expected to be an instance'</span> - <span class="s1">' of </span><span class="si">{}</span><span class="s1">.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">'.'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">Augment</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span> - <span class="n">Augment</span><span class="o">.</span><span class="vm">__name__</span><span class="p">])))</span> - -<div class="viewcode-block" id="DatasetConfig.init_dataset"><a class="viewcode-back" href="../../source/core.html#core.trainer.DatasetConfig.init_dataset">[docs]</a> <span class="k">def</span> <span class="nf">init_dataset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Instanciate the dataset.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> dataset : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `pysegcnn.core.dataset.ImageDataset`.</span> - -<span class="sd"> """</span> - <span class="c1"># instanciate the dataset</span> - <span class="n">dataset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset_class</span><span class="p">(</span> - <span class="n">root_dir</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">root_dir</span><span class="p">),</span> - <span class="n">use_bands</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">bands</span><span class="p">,</span> - <span class="n">tile_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">tile_size</span><span class="p">,</span> - <span class="n">seed</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">seed</span><span class="p">,</span> - <span class="n">sort</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sort</span><span class="p">,</span> - <span class="n">transforms</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transforms</span><span class="p">,</span> - <span class="n">pad</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">pad</span><span class="p">,</span> - <span class="n">gt_pattern</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">gt_pattern</span> - <span class="p">)</span> - - <span class="k">return</span> <span class="n">dataset</span></div></div> - - -<div class="viewcode-block" id="SplitConfig"><a class="viewcode-back" href="../../source/core.html#core.trainer.SplitConfig">[docs]</a><span class="nd">@dataclasses</span><span class="o">.</span><span class="n">dataclass</span> -<span class="k">class</span> <span class="nc">SplitConfig</span><span class="p">(</span><span class="n">BaseConfig</span><span class="p">):</span> - <span class="sd">"""Dataset split configuration class.</span> - -<span class="sd"> Split a dataset into training, validation and test set.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> split_mode : `str`</span> -<span class="sd"> The mode to split the dataset.</span> -<span class="sd"> ttratio : `float`</span> -<span class="sd"> The ratio of training and validation data to test data, e.g.</span> -<span class="sd"> ``ttratio`` = 0.6 means 60% for training and validation, 40% for</span> -<span class="sd"> testing.</span> -<span class="sd"> tvratio : `float`</span> -<span class="sd"> The ratio of training data to validation data, e.g. ``tvratio`` = 0.8</span> -<span class="sd"> means 80% training, 20% validation.</span> -<span class="sd"> date : `str`, optional</span> -<span class="sd"> A date. Used if ``split_mode`` = 'date'. The default is 'yyyymmdd'.</span> -<span class="sd"> dateformat : `str`, optional</span> -<span class="sd"> The format of ``date``. ``dateformat`` is used by</span> -<span class="sd"> `datetime.datetime.strptime' to parse ``date`` to a `datetime.datetime`</span> -<span class="sd"> object. The default is '%Y%m%d'.</span> -<span class="sd"> drop : `float`, optional</span> -<span class="sd"> Whether to drop samples (during training only) with a fraction of</span> -<span class="sd"> pixels equal to the constant padding value >= ``drop``. ``drop`` = 0</span> -<span class="sd"> means, do not drop any samples. The default is 0.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <span class="n">split_mode</span><span class="p">:</span> <span class="nb">str</span> - <span class="n">ttratio</span><span class="p">:</span> <span class="nb">float</span> - <span class="n">tvratio</span><span class="p">:</span> <span class="nb">float</span> - <span class="n">date</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">'yyyymmdd'</span> - <span class="n">dateformat</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span> - <span class="n">drop</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">0</span> - - <span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check the type of each argument.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> ValueError</span> -<span class="sd"> Raised if ``split_mode`` is not supported.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="c1"># check input types</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span> - - <span class="c1"># check if the split mode is valid</span> - <span class="bp">self</span><span class="o">.</span><span class="n">split_class</span> <span class="o">=</span> <span class="n">item_in_enum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">split_mode</span><span class="p">,</span> <span class="n">SupportedSplits</span><span class="p">)</span> - - <span class="nd">@staticmethod</span> - <span class="k">def</span> <span class="nf">_drop_samples</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">drop_threshold</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span> - <span class="sd">"""Drop samples with a fraction of pixels equal to the padding value.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `pysegcnn.core.split.SceneSubset`.</span> -<span class="sd"> An instance of `pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `pysegcnn.core.split.SceneSubset`.</span> -<span class="sd"> drop_threshold : `float`, optional</span> -<span class="sd"> The threshold above which samples are dropped. ``drop_threshold`` =</span> -<span class="sd"> 1 means a sample is dropped, if all pixels are equal to the padding</span> -<span class="sd"> value. ``drop_threshold`` = 0.8 means, drop a sample if 80% of the</span> -<span class="sd"> pixels are equal to the padding value, etc. The default is 1.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> dropped : `list` [`dict`]</span> -<span class="sd"> List of the dropped samples.</span> - -<span class="sd"> """</span> - <span class="c1"># iterate over the scenes returned by self.compose_scenes()</span> - <span class="n">dropped</span> <span class="o">=</span> <span class="p">[]</span> - <span class="k">for</span> <span class="n">pos</span><span class="p">,</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">indices</span><span class="p">):</span> - - <span class="c1"># the current scene</span> - <span class="n">s</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">scenes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> - - <span class="c1"># the current tile in the ground truth</span> - <span class="n">tile_gt</span> <span class="o">=</span> <span class="n">img2np</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="s1">'gt'</span><span class="p">],</span> <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">tile_size</span><span class="p">,</span> <span class="n">s</span><span class="p">[</span><span class="s1">'tile'</span><span class="p">],</span> - <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">pad</span><span class="p">,</span> <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">cval</span><span class="p">)</span> - - <span class="c1"># percent of pixels equal to the constant padding value</span> - <span class="n">npixels</span> <span class="o">=</span> <span class="p">(</span><span class="n">tile_gt</span><span class="p">[</span><span class="n">tile_gt</span> <span class="o">==</span> <span class="n">ds</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">cval</span><span class="p">]</span><span class="o">.</span><span class="n">size</span> <span class="o">/</span> <span class="n">tile_gt</span><span class="o">.</span><span class="n">size</span><span class="p">)</span> - - <span class="c1"># drop samples where npixels >= self.drop</span> - <span class="k">if</span> <span class="n">npixels</span> <span class="o">>=</span> <span class="n">drop_threshold</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Skipping scene </span><span class="si">{}</span><span class="s1">, tile </span><span class="si">{}</span><span class="s1">: </span><span class="si">{:.2f}</span><span class="s1">% padded pixels'</span> - <span class="s1">' ...'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="s1">'id'</span><span class="p">],</span> <span class="n">s</span><span class="p">[</span><span class="s1">'tile'</span><span class="p">],</span> <span class="n">npixels</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))</span> - <span class="n">dropped</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> - <span class="n">_</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">indices</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">pos</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">dropped</span> - -<div class="viewcode-block" id="SplitConfig.train_val_test_split"><a class="viewcode-back" href="../../source/core.html#core.trainer.SplitConfig.train_val_test_split">[docs]</a> <span class="k">def</span> <span class="nf">train_val_test_split</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ds</span><span class="p">):</span> - <span class="sd">"""Split ``ds`` into training, validation and test set.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `pysegcnn.core.dataset.ImageDataset`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if ``ds`` is not an instance of</span> -<span class="sd"> `pysegcnn.core.dataset.ImageDataset`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> train_ds : `pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `pysegcnn.core.split.SceneSubset`.</span> -<span class="sd"> The training set.</span> -<span class="sd"> valid_ds : `pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `pysegcnn.core.split.SceneSubset`.</span> -<span class="sd"> The validation set.</span> -<span class="sd"> test_ds : `pysegcnn.core.split.RandomSubset` or</span> -<span class="sd"> `pysegcnn.core.split.SceneSubset`.</span> -<span class="sd"> The test set.</span> - -<span class="sd"> """</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">ImageDataset</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'Expected "ds" to be </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">'.'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">ImageDataset</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span> - <span class="n">ImageDataset</span><span class="o">.</span><span class="vm">__name__</span><span class="p">])))</span> - - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">split_mode</span> <span class="o">==</span> <span class="s1">'random'</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">split_mode</span> <span class="o">==</span> <span class="s1">'scene'</span><span class="p">:</span> - <span class="n">subset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">split_class</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">ttratio</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">tvratio</span><span class="p">,</span> - <span class="n">ds</span><span class="o">.</span><span class="n">seed</span><span class="p">)</span> - - <span class="k">else</span><span class="p">:</span> - <span class="n">subset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">split_class</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">date</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dateformat</span><span class="p">)</span> - - <span class="c1"># the training, validation and test dataset</span> - <span class="n">train_ds</span><span class="p">,</span> <span class="n">valid_ds</span><span class="p">,</span> <span class="n">test_ds</span> <span class="o">=</span> <span class="n">subset</span><span class="o">.</span><span class="n">split</span><span class="p">()</span> - - <span class="c1"># whether to drop training samples with a fraction of pixels equal to</span> - <span class="c1"># the constant padding value cval >= drop</span> - <span class="k">if</span> <span class="n">ds</span><span class="o">.</span><span class="n">pad</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">drop</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> - <span class="bp">self</span><span class="o">.</span><span class="n">dropped</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_drop_samples</span><span class="p">(</span><span class="n">train_ds</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">drop</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">train_ds</span><span class="p">,</span> <span class="n">valid_ds</span><span class="p">,</span> <span class="n">test_ds</span></div> - -<div class="viewcode-block" id="SplitConfig.dataloaders"><a class="viewcode-back" href="../../source/core.html#core.trainer.SplitConfig.dataloaders">[docs]</a> <span class="nd">@staticmethod</span> - <span class="k">def</span> <span class="nf">dataloaders</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> - <span class="sd">"""Build `torch.utils.data.DataLoader` instances.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> *args : `list` [`torch.utils.data.Dataset`]</span> -<span class="sd"> List of instances of `torch.utils.data.Dataset`.</span> -<span class="sd"> **kwargs</span> -<span class="sd"> Additional keyword arguments passed to</span> -<span class="sd"> `torch.utils.data.DataLoader`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if not each item in ``args`` is an instance of</span> -<span class="sd"> `torch.utils.data.Dataset`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> loaders : `list` [`torch.utils.data.DataLoader`]</span> -<span class="sd"> List of instances of `torch.utils.data.DataLoader`. If an instance</span> -<span class="sd"> of `torch.utils.data.Dataset` in ``args`` is empty, `None` is</span> -<span class="sd"> appended to ``loaders`` instead of an instance of</span> -<span class="sd"> `torch.utils.data.DataLoader`.</span> - -<span class="sd"> """</span> - <span class="c1"># check whether each dataset in args has the correct type</span> - <span class="n">loaders</span> <span class="o">=</span> <span class="p">[]</span> - <span class="k">for</span> <span class="n">ds</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">Dataset</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'Expected </span><span class="si">{}</span><span class="s1">, got </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">Dataset</span><span class="p">),</span> <span class="nb">type</span><span class="p">(</span><span class="n">ds</span><span class="p">)))</span> - - <span class="c1"># check if the dataset is not empty</span> - <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ds</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> - <span class="c1"># build the dataloader</span> - <span class="n">loader</span> <span class="o">=</span> <span class="n">DataLoader</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">loader</span> <span class="o">=</span> <span class="kc">None</span> - <span class="n">loaders</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">loader</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">loaders</span></div></div> - - -<div class="viewcode-block" id="ModelConfig"><a class="viewcode-back" href="../../source/core.html#core.trainer.ModelConfig">[docs]</a><span class="nd">@dataclasses</span><span class="o">.</span><span class="n">dataclass</span> -<span class="k">class</span> <span class="nc">ModelConfig</span><span class="p">(</span><span class="n">BaseConfig</span><span class="p">):</span> - <span class="sd">"""Model configuration class.</span> - -<span class="sd"> Instanciate a (pretrained) model.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> model_name : `str`</span> -<span class="sd"> The name of the model.</span> -<span class="sd"> filters : `list` [`int`]</span> -<span class="sd"> List of input channels to the convolutional layers.</span> -<span class="sd"> torch_seed : `int`</span> -<span class="sd"> The random seed to initialize the model weights.</span> -<span class="sd"> Useful for reproducibility.</span> -<span class="sd"> optim_name : `str`</span> -<span class="sd"> The name of the optimizer to update the model weights.</span> -<span class="sd"> loss_name : `str`</span> -<span class="sd"> The name of the loss function measuring the model error.</span> -<span class="sd"> skip_connection : `bool`, optional</span> -<span class="sd"> Whether to apply skip connections. The defaul is True.</span> -<span class="sd"> kwargs: `dict`, optional</span> -<span class="sd"> The configuration for each convolution in the model. The default is</span> -<span class="sd"> {'kernel_size': 3, 'stride': 1, 'dilation': 1}.</span> -<span class="sd"> batch_size : `int`, optional</span> -<span class="sd"> The model batch size. Determines the number of samples to process</span> -<span class="sd"> before updating the model weights. The default is 64.</span> -<span class="sd"> checkpoint : `bool`, optional</span> -<span class="sd"> Whether to resume training from an existing model checkpoint. The</span> -<span class="sd"> default is False.</span> -<span class="sd"> transfer : `bool`, optional</span> -<span class="sd"> Whether to use a model for transfer learning on a new dataset. If True,</span> -<span class="sd"> the model architecture of ``pretrained_model`` is adjusted to a new</span> -<span class="sd"> dataset. The default is False.</span> -<span class="sd"> pretrained_model : `str`, optional</span> -<span class="sd"> The name of the pretrained model to use for transfer learning.</span> -<span class="sd"> The default is ''.</span> -<span class="sd"> lr : `float`, optional</span> -<span class="sd"> The learning rate used by the gradient descent algorithm.</span> -<span class="sd"> The default is 0.001.</span> -<span class="sd"> early_stop : `bool`, optional</span> -<span class="sd"> Whether to apply `early stopping`_. The default is False.</span> -<span class="sd"> mode : `str`, optional</span> -<span class="sd"> The mode of the early stopping. Depends on the metric measuring</span> -<span class="sd"> performance. When using model loss as metric, use ``mode`` = 'min',</span> -<span class="sd"> however, when using accuracy as metric, use ``mode`` = 'max'. For now,</span> -<span class="sd"> only ``mode`` = 'max' is supported. Only used if ``early_stop`` = True.</span> -<span class="sd"> The default is 'max'.</span> -<span class="sd"> delta : `float`, optional</span> -<span class="sd"> Minimum change in early stopping metric to be considered as an</span> -<span class="sd"> improvement. Only used if ``early_stop`` = True. The default is 0.</span> -<span class="sd"> patience : `int`, optional</span> -<span class="sd"> The number of epochs to wait for an improvement in the early stopping</span> -<span class="sd"> metric. If the model does not improve over more than ``patience``</span> -<span class="sd"> epochs, quit training. Only used if ``early_stop`` = True.</span> -<span class="sd"> The default is 10.</span> -<span class="sd"> epochs : `int`, optional</span> -<span class="sd"> The maximum number of epochs to train. The default is 50.</span> -<span class="sd"> nthreads : `int`, optional</span> -<span class="sd"> The number of cpu threads to use during training. The default is</span> -<span class="sd"> torch.get_num_threads().</span> -<span class="sd"> save : `bool`, optional</span> -<span class="sd"> Whether to save the model state to disk. Model states are saved in</span> -<span class="sd"> pysegcnn/main/_models. The default is True.</span> - -<span class="sd"> .. _early stopping:</span> -<span class="sd"> https://en.wikipedia.org/wiki/Early_stopping</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <span class="n">model_name</span><span class="p">:</span> <span class="nb">str</span> - <span class="n">filters</span><span class="p">:</span> <span class="nb">list</span> - <span class="n">torch_seed</span><span class="p">:</span> <span class="nb">int</span> - <span class="n">optim_name</span><span class="p">:</span> <span class="nb">str</span> - <span class="n">loss_name</span><span class="p">:</span> <span class="nb">str</span> - <span class="n">skip_connection</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> - <span class="n">kwargs</span><span class="p">:</span> <span class="nb">dict</span> <span class="o">=</span> <span class="n">dataclasses</span><span class="o">.</span><span class="n">field</span><span class="p">(</span> - <span class="n">default_factory</span><span class="o">=</span><span class="k">lambda</span><span class="p">:</span> <span class="p">{</span><span class="s1">'kernel_size'</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">'stride'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'dilation'</span><span class="p">:</span> <span class="mi">1</span><span class="p">})</span> - <span class="n">batch_size</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">64</span> - <span class="n">checkpoint</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span> - <span class="n">transfer</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span> - <span class="n">pretrained_model</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">''</span> - <span class="n">lr</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.001</span> - <span class="n">early_stop</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span> - <span class="n">mode</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">'max'</span> - <span class="n">delta</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">0</span> - <span class="n">patience</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">10</span> - <span class="n">epochs</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">50</span> - <span class="n">nthreads</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">get_num_threads</span><span class="p">()</span> - <span class="n">save</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> - - <span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check the type of each argument.</span> - -<span class="sd"> Configure path to save model state.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> ValueError</span> -<span class="sd"> Raised if the model ``model_name``, the optimizer ``optim_name`` or</span> -<span class="sd"> the loss function ``loss_name`` is not supported.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="c1"># check input types</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span> - - <span class="c1"># check whether the model is currently supported</span> - <span class="bp">self</span><span class="o">.</span><span class="n">model_class</span> <span class="o">=</span> <span class="n">item_in_enum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_name</span><span class="p">,</span> <span class="n">SupportedModels</span><span class="p">)</span> - - <span class="c1"># check whether the optimizer is currently supported</span> - <span class="bp">self</span><span class="o">.</span><span class="n">optim_class</span> <span class="o">=</span> <span class="n">item_in_enum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">optim_name</span><span class="p">,</span> <span class="n">SupportedOptimizers</span><span class="p">)</span> - - <span class="c1"># check whether the loss function is currently supported</span> - <span class="bp">self</span><span class="o">.</span><span class="n">loss_class</span> <span class="o">=</span> <span class="n">item_in_enum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">loss_name</span><span class="p">,</span> <span class="n">SupportedLossFunctions</span><span class="p">)</span> - - <span class="c1"># path to model states</span> - <span class="bp">self</span><span class="o">.</span><span class="n">state_path</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">HERE</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'_models/'</span><span class="p">)</span> - - <span class="c1"># path to pretrained model</span> - <span class="bp">self</span><span class="o">.</span><span class="n">pretrained_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">state_path</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pretrained_model</span><span class="p">)</span> - -<div class="viewcode-block" id="ModelConfig.init_optimizer"><a class="viewcode-back" href="../../source/core.html#core.trainer.ModelConfig.init_optimizer">[docs]</a> <span class="k">def</span> <span class="nf">init_optimizer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">):</span> - <span class="sd">"""Instanciate the optimizer.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> model : `torch.nn.Module`</span> -<span class="sd"> An instance of `torch.nn.Module`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> optimizer : `torch.optim.Optimizer`</span> -<span class="sd"> An instance of `torch.optim.Optimizer`.</span> - -<span class="sd"> """</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Optimizer: </span><span class="si">{}</span><span class="s1">.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">optim_class</span><span class="p">)))</span> - - <span class="c1"># initialize the optimizer for the specified model</span> - <span class="n">optimizer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">optim_class</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">parameters</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">lr</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">optimizer</span></div> - -<div class="viewcode-block" id="ModelConfig.init_loss_function"><a class="viewcode-back" href="../../source/core.html#core.trainer.ModelConfig.init_loss_function">[docs]</a> <span class="k">def</span> <span class="nf">init_loss_function</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Instanciate the loss function.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> loss_function : `torch.nn.Module`</span> -<span class="sd"> An instance of `torch.nn.Module`.</span> - -<span class="sd"> """</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Loss function: </span><span class="si">{}</span><span class="s1">.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">loss_class</span><span class="p">)))</span> - - <span class="c1"># instanciate the loss function</span> - <span class="n">loss_function</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_class</span><span class="p">()</span> - - <span class="k">return</span> <span class="n">loss_function</span></div> - -<div class="viewcode-block" id="ModelConfig.init_model"><a class="viewcode-back" href="../../source/core.html#core.trainer.ModelConfig.init_model">[docs]</a> <span class="k">def</span> <span class="nf">init_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ds</span><span class="p">,</span> <span class="n">state_file</span><span class="p">):</span> - <span class="sd">"""Instanciate the model and the optimizer.</span> - -<span class="sd"> If the model checkpoint ``state_file`` exists, the pretrained model and</span> -<span class="sd"> optimizer states are loaded, otherwise the model and the optimizer are</span> -<span class="sd"> initialized from scratch.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> state_file : `pathlib.Path`</span> -<span class="sd"> Path to a model checkpoint.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> model : `pysegcnn.core.models.Network`</span> -<span class="sd"> An instance of `pysegcnn.core.models.Network`.</span> -<span class="sd"> optimizer : `torch.optim.Optimizer`</span> -<span class="sd"> An instance of `torch.optim.Optimizer`.</span> -<span class="sd"> checkpoint_state : `dict` [`str`, `numpy.ndarray`]</span> -<span class="sd"> If the model checkpoint ``state_file`` exists, ``checkpoint_state``</span> -<span class="sd"> has keys:</span> -<span class="sd"> ``'ta'``</span> -<span class="sd"> The accuracy on the training set (`numpy.ndarray`).</span> -<span class="sd"> ``'tl'``</span> -<span class="sd"> The loss on the training set (`numpy.ndarray`).</span> -<span class="sd"> ``'va'``</span> -<span class="sd"> The accuracy on the validation set (`numpy.ndarray`).</span> -<span class="sd"> ``'vl'``</span> -<span class="sd"> The loss on the validation set (`numpy.ndarray`).</span> - -<span class="sd"> """</span> - <span class="c1"># write an initialization string to the log file</span> - <span class="n">LogConfig</span><span class="o">.</span><span class="n">init_log</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1">: Initializing model run. '</span><span class="p">)</span> - - <span class="c1"># case (1): build a new model</span> - <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">transfer</span><span class="p">:</span> - - <span class="c1"># set the random seed for reproducibility</span> - <span class="n">torch</span><span class="o">.</span><span class="n">manual_seed</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">torch_seed</span><span class="p">)</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Initializing model: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">state_file</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> - - <span class="c1"># instanciate the model</span> - <span class="n">model</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model_class</span><span class="p">(</span> - <span class="n">in_channels</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">use_bands</span><span class="p">),</span> - <span class="n">nclasses</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">labels</span><span class="p">),</span> - <span class="n">filters</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">filters</span><span class="p">,</span> - <span class="n">skip</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">skip_connection</span><span class="p">,</span> - <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span> - - <span class="c1"># case (2): load a pretrained model for transfer learning</span> - <span class="k">else</span><span class="p">:</span> - <span class="c1"># load pretrained model</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Loading pretrained model for transfer learning from: '</span> - <span class="s1">'</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pretrained_path</span><span class="p">))</span> - <span class="n">model</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">transfer_model</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pretrained_path</span><span class="p">,</span> <span class="n">ds</span><span class="p">)</span> - - <span class="c1"># initialize the optimizer</span> - <span class="n">optimizer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">init_optimizer</span><span class="p">(</span><span class="n">model</span><span class="p">)</span> - - <span class="c1"># whether to resume training from an existing model checkpoint</span> - <span class="n">checkpoint_state</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">checkpoint</span><span class="p">:</span> - <span class="n">model</span><span class="p">,</span> <span class="n">optimizer</span><span class="p">,</span> <span class="n">checkpoint_state</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">load_checkpoint</span><span class="p">(</span> - <span class="n">model</span><span class="p">,</span> <span class="n">optimizer</span><span class="p">,</span> <span class="n">state_file</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">model</span><span class="p">,</span> <span class="n">optimizer</span><span class="p">,</span> <span class="n">checkpoint_state</span></div> - -<div class="viewcode-block" id="ModelConfig.load_checkpoint"><a class="viewcode-back" href="../../source/core.html#core.trainer.ModelConfig.load_checkpoint">[docs]</a> <span class="nd">@staticmethod</span> - <span class="k">def</span> <span class="nf">load_checkpoint</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">optimizer</span><span class="p">,</span> <span class="n">state_file</span><span class="p">):</span> - <span class="sd">"""Load an existing model checkpoint.</span> - -<span class="sd"> If the model checkpoint ``state_file`` exists, the pretrained model and</span> -<span class="sd"> optimizer states are loaded.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> model : `pysegcnn.core.models.Network`</span> -<span class="sd"> An instance of `pysegcnn.core.models.Network`.</span> -<span class="sd"> optimizer : `torch.optim.Optimizer`</span> -<span class="sd"> An instance of `torch.optim.Optimizer`.</span> -<span class="sd"> state_file : `pathlib.Path`</span> -<span class="sd"> Path to the model checkpoint.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> model : `pysegcnn.core.models.Network`</span> -<span class="sd"> An instance of `pysegcnn.core.models.Network`.</span> -<span class="sd"> optimizer : `torch.optim.Optimizer`</span> -<span class="sd"> An instance of `torch.optim.Optimizer`.</span> -<span class="sd"> checkpoint_state : `dict` [`str`, `numpy.ndarray`]</span> -<span class="sd"> If the model checkpoint ``state_file`` exists, ``checkpoint_state``</span> -<span class="sd"> has keys:</span> -<span class="sd"> ``'ta'``</span> -<span class="sd"> The accuracy on the training set (`numpy.ndarray`).</span> -<span class="sd"> ``'tl'``</span> -<span class="sd"> The loss on the training set (`numpy.ndarray`).</span> -<span class="sd"> ``'va'``</span> -<span class="sd"> The accuracy on the validation set (`numpy.ndarray`).</span> -<span class="sd"> ``'vl'``</span> -<span class="sd"> The loss on the validation set (`numpy.ndarray`).</span> - -<span class="sd"> """</span> - <span class="c1"># whether to resume training from an existing model checkpoint</span> - <span class="n">checkpoint_state</span> <span class="o">=</span> <span class="p">{}</span> - - <span class="c1"># if no checkpoint exists, file a warning and continue with a model</span> - <span class="c1"># initialized from scratch</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">state_file</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">'Checkpoint for model </span><span class="si">{}</span><span class="s1"> does not exist. '</span> - <span class="s1">'Initializing new model.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">state_file</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> - <span class="k">else</span><span class="p">:</span> - <span class="c1"># load model checkpoint</span> - <span class="n">model</span><span class="p">,</span> <span class="n">optimizer</span><span class="p">,</span> <span class="n">model_state</span> <span class="o">=</span> <span class="n">Network</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">state_file</span><span class="p">)</span> - - <span class="c1"># load model loss and accuracy</span> - - <span class="c1"># get all non-zero elements, i.e. get number of epochs trained</span> - <span class="c1"># before the early stop</span> - <span class="n">checkpoint_state</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">nonzero</span><span class="p">(</span><span class="n">v</span><span class="p">)]</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">v</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="o">-</span><span class="mi">1</span><span class="p">)</span> - <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">model_state</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> - - <span class="k">return</span> <span class="n">model</span><span class="p">,</span> <span class="n">optimizer</span><span class="p">,</span> <span class="n">checkpoint_state</span></div> - -<div class="viewcode-block" id="ModelConfig.transfer_model"><a class="viewcode-back" href="../../source/core.html#core.trainer.ModelConfig.transfer_model">[docs]</a> <span class="nd">@staticmethod</span> - <span class="k">def</span> <span class="nf">transfer_model</span><span class="p">(</span><span class="n">state_file</span><span class="p">,</span> <span class="n">ds</span><span class="p">):</span> - <span class="sd">"""Adjust a pretrained model to a new dataset.</span> - -<span class="sd"> The classification layer of the pretrained model in ``state_file`` is</span> -<span class="sd"> initilialized from scratch with the classes of the new dataset ``ds``.</span> - -<span class="sd"> The remaining model weights are preserved.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> state_file : `pathlib.Path`</span> -<span class="sd"> Path to a pretrained model.</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `pysegcnn.core.dataset.ImageDataset`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if ``ds`` is not an instance of</span> -<span class="sd"> `pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> ValueError</span> -<span class="sd"> Raised if the bands of ``ds`` do not match the bands of the dataset</span> -<span class="sd"> the pretrained model was trained with.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> model : `pysegcnn.core.models.Network`</span> -<span class="sd"> An instance of `pysegcnn.core.models.Network`. The pretrained model</span> -<span class="sd"> adjusted to the new dataset.</span> - -<span class="sd"> """</span> - <span class="c1"># check input type</span> - <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">ImageDataset</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'Expected "ds" to be </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">'.'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">ImageDataset</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span> - <span class="n">ImageDataset</span><span class="o">.</span><span class="vm">__name__</span><span class="p">])))</span> - - <span class="c1"># load the pretrained model</span> - <span class="n">model</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">model_state</span> <span class="o">=</span> <span class="n">Network</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">state_file</span><span class="p">)</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Configuring model for new dataset: </span><span class="si">{}</span><span class="s1">.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="n">ds</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">))</span> - - <span class="c1"># check whether the current dataset uses the correct spectral bands</span> - <span class="k">if</span> <span class="n">ds</span><span class="o">.</span><span class="n">use_bands</span> <span class="o">!=</span> <span class="n">model_state</span><span class="p">[</span><span class="s1">'bands'</span><span class="p">]:</span> - <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'The pretrained network was trained with '</span> - <span class="s1">'bands </span><span class="si">{}</span><span class="s1">, not with bands </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">model_state</span><span class="p">[</span><span class="s1">'bands'</span><span class="p">],</span> <span class="n">ds</span><span class="o">.</span><span class="n">use_bands</span><span class="p">))</span> - - <span class="c1"># get the number of convolutional filters</span> - <span class="n">filters</span> <span class="o">=</span> <span class="n">model_state</span><span class="p">[</span><span class="s1">'params'</span><span class="p">][</span><span class="s1">'filters'</span><span class="p">]</span> - - <span class="c1"># reset model epoch to 0, since the model is trained on a different</span> - <span class="c1"># dataset</span> - <span class="n">model</span><span class="o">.</span><span class="n">epoch</span> <span class="o">=</span> <span class="mi">0</span> - - <span class="c1"># adjust the number of classes in the model</span> - <span class="n">model</span><span class="o">.</span><span class="n">nclasses</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">labels</span><span class="p">)</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Replacing classification layer to classes: </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">'(</span><span class="si">{}</span><span class="s1">, </span><span class="si">{}</span><span class="s1">)'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">[</span><span class="s1">'label'</span><span class="p">])</span> - <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">ds</span><span class="o">.</span><span class="n">labels</span><span class="o">.</span><span class="n">items</span><span class="p">())))</span> - - <span class="c1"># adjust the classification layer to the classes of the new dataset</span> - <span class="n">model</span><span class="o">.</span><span class="n">classifier</span> <span class="o">=</span> <span class="n">Conv2dSame</span><span class="p">(</span><span class="n">in_channels</span><span class="o">=</span><span class="n">filters</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> - <span class="n">out_channels</span><span class="o">=</span><span class="n">model</span><span class="o">.</span><span class="n">nclasses</span><span class="p">,</span> - <span class="n">kernel_size</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">model</span></div></div> - - -<div class="viewcode-block" id="StateConfig"><a class="viewcode-back" href="../../source/core.html#core.trainer.StateConfig">[docs]</a><span class="nd">@dataclasses</span><span class="o">.</span><span class="n">dataclass</span> -<span class="k">class</span> <span class="nc">StateConfig</span><span class="p">(</span><span class="n">BaseConfig</span><span class="p">):</span> - <span class="sd">"""Model state configuration class.</span> - -<span class="sd"> Generate the model state filename according to the following naming</span> -<span class="sd"> convention:</span> - -<span class="sd"> model_dataset_optimizer_splitmode_splitparams_tilesize_batchsize_bands.pt</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> ds : `pysegcnn.core.dataset.ImageDataset`</span> -<span class="sd"> An instance of `pysegcnn.core.dataset.ImageDataset`.</span> -<span class="sd"> sc : `pysegcnn.core.trainer.SplitConfig`</span> -<span class="sd"> An instance of `pysegcnn.core.trainer.SplitConfig`.</span> -<span class="sd"> mc : `pysegcnn.core.trainer.ModelConfig`</span> -<span class="sd"> An instance of `pysegcnn.core.trainer.SplitConfig`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <span class="n">ds</span><span class="p">:</span> <span class="n">ImageDataset</span> - <span class="n">sc</span><span class="p">:</span> <span class="n">SplitConfig</span> - <span class="n">mc</span><span class="p">:</span> <span class="n">ModelConfig</span> - - <span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check the type of each argument.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span> - -<div class="viewcode-block" id="StateConfig.init_state"><a class="viewcode-back" href="../../source/core.html#core.trainer.StateConfig.init_state">[docs]</a> <span class="k">def</span> <span class="nf">init_state</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Generate the model state filename.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> state : `pathlib.Path`</span> -<span class="sd"> The path to the model state file.</span> - -<span class="sd"> """</span> - <span class="c1"># file to save model state to:</span> - <span class="c1"># network_dataset_optim_split_splitparams_tilesize_batchsize_bands.pt</span> - - <span class="c1"># model state filename</span> - <span class="n">state_file</span> <span class="o">=</span> <span class="s1">'</span><span class="si">{}</span><span class="s1">_</span><span class="si">{}</span><span class="s1">_</span><span class="si">{}</span><span class="s1">_</span><span class="si">{}</span><span class="s1">Split_</span><span class="si">{}</span><span class="s1">_t</span><span class="si">{}</span><span class="s1">_b</span><span class="si">{}</span><span class="s1">_</span><span class="si">{}</span><span class="s1">.pt'</span> - - <span class="c1"># get the band numbers</span> - <span class="n">bformat</span> <span class="o">=</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">band</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> - <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="o">.</span><span class="n">sensor</span><span class="o">.</span><span class="n">__members__</span><span class="p">[</span><span class="n">band</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> - <span class="n">band</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="o">.</span><span class="n">use_bands</span><span class="p">)</span> - - <span class="c1"># check which split mode was used</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sc</span><span class="o">.</span><span class="n">split_mode</span> <span class="o">==</span> <span class="s1">'date'</span><span class="p">:</span> - <span class="c1"># store the date that was used to split the dataset</span> - <span class="n">state_file</span> <span class="o">=</span> <span class="n">state_file</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mc</span><span class="o">.</span><span class="n">model_name</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">mc</span><span class="o">.</span><span class="n">optim_name</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">sc</span><span class="o">.</span><span class="n">split_mode</span><span class="o">.</span><span class="n">capitalize</span><span class="p">(),</span> - <span class="bp">self</span><span class="o">.</span><span class="n">sc</span><span class="o">.</span><span class="n">date</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="o">.</span><span class="n">tile_size</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">mc</span><span class="o">.</span><span class="n">batch_size</span><span class="p">,</span> - <span class="n">bformat</span><span class="p">)</span> - <span class="k">else</span><span class="p">:</span> - <span class="c1"># store the random split parameters</span> - <span class="n">split_params</span> <span class="o">=</span> <span class="s1">'s</span><span class="si">{}</span><span class="s1">_t</span><span class="si">{}</span><span class="s1">v</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="o">.</span><span class="n">seed</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sc</span><span class="o">.</span><span class="n">ttratio</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'.'</span><span class="p">,</span> <span class="s1">''</span><span class="p">),</span> - <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sc</span><span class="o">.</span><span class="n">tvratio</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'.'</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> - - <span class="c1"># model state filename</span> - <span class="n">state_file</span> <span class="o">=</span> <span class="n">state_file</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mc</span><span class="o">.</span><span class="n">model_name</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">mc</span><span class="o">.</span><span class="n">optim_name</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">sc</span><span class="o">.</span><span class="n">split_mode</span><span class="o">.</span><span class="n">capitalize</span><span class="p">(),</span> - <span class="n">split_params</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">ds</span><span class="o">.</span><span class="n">tile_size</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">mc</span><span class="o">.</span><span class="n">batch_size</span><span class="p">,</span> - <span class="n">bformat</span><span class="p">)</span> - - <span class="c1"># check whether a pretrained model was used and change state filename</span> - <span class="c1"># accordingly</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mc</span><span class="o">.</span><span class="n">transfer</span><span class="p">:</span> - <span class="c1"># add the configuration of the pretrained model to the state name</span> - <span class="n">state_file</span> <span class="o">=</span> <span class="p">(</span><span class="n">state_file</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'.pt'</span><span class="p">,</span> <span class="s1">'_'</span><span class="p">)</span> <span class="o">+</span> - <span class="s1">'pretrained_'</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">mc</span><span class="o">.</span><span class="n">pretrained_model</span><span class="p">)</span> - - <span class="c1"># path to model state</span> - <span class="n">state</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mc</span><span class="o">.</span><span class="n">state_path</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="n">state_file</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">state</span></div></div> - - -<div class="viewcode-block" id="EvalConfig"><a class="viewcode-back" href="../../source/core.html#core.trainer.EvalConfig">[docs]</a><span class="nd">@dataclasses</span><span class="o">.</span><span class="n">dataclass</span> -<span class="k">class</span> <span class="nc">EvalConfig</span><span class="p">(</span><span class="n">BaseConfig</span><span class="p">):</span> - <span class="sd">"""Model inference configuration.</span> - -<span class="sd"> Evaluate a model.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> state_file : `pathlib.Path`</span> -<span class="sd"> Path to the model to evaluate.</span> -<span class="sd"> test : `bool` or `None`</span> -<span class="sd"> Whether to evaluate the model on the training(``test`` = `None`), the</span> -<span class="sd"> validation (``test`` = False) or the test set (``test`` = True).</span> -<span class="sd"> predict_scene : `bool`, optional</span> -<span class="sd"> The model prediction order. If False, the samples (tiles) of a dataset</span> -<span class="sd"> are predicted in any order and the scenes are not reconstructed.</span> -<span class="sd"> If True, the samples (tiles) are ordered according to the scene they</span> -<span class="sd"> belong to and a model prediction for each entire reconstructed scene is</span> -<span class="sd"> returned. The default is False.</span> -<span class="sd"> plot_samples : `bool`, optional</span> -<span class="sd"> Whether to save a plot of false color composite, ground truth and model</span> -<span class="sd"> prediction for each sample (tile). Only used if ``predict_scene`` =</span> -<span class="sd"> False. The default is False.</span> -<span class="sd"> plot_scenes : `bool`, optional</span> -<span class="sd"> Whether to save a plot of false color composite, ground truth and model</span> -<span class="sd"> prediction for each entire scene. Only used if ``predict_scene`` =</span> -<span class="sd"> True. The default is False.</span> -<span class="sd"> plot_bands : `list` [`str`], optional</span> -<span class="sd"> The bands to build the false color composite. The default is</span> -<span class="sd"> ['nir', 'red', 'green'].</span> -<span class="sd"> cm : `bool`, optional</span> -<span class="sd"> Whether to compute and plot the confusion matrix. The default is True.</span> -<span class="sd"> figsize : `tuple`, optional</span> -<span class="sd"> The figure size in centimeters. The default is (10, 10).</span> -<span class="sd"> alpha : `int`, optional</span> -<span class="sd"> The level of the percentiles for contrast stretching of the false color</span> -<span class="sd"> compsite. The default is 0, i.e. no stretching.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <span class="n">state_file</span><span class="p">:</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span> - <span class="n">test</span><span class="p">:</span> <span class="nb">object</span> - <span class="n">predict_scene</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span> - <span class="n">plot_samples</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span> - <span class="n">plot_scenes</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span> - <span class="n">plot_bands</span><span class="p">:</span> <span class="nb">list</span> <span class="o">=</span> <span class="n">dataclasses</span><span class="o">.</span><span class="n">field</span><span class="p">(</span> - <span class="n">default_factory</span><span class="o">=</span><span class="k">lambda</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nir'</span><span class="p">,</span> <span class="s1">'red'</span><span class="p">,</span> <span class="s1">'green'</span><span class="p">])</span> - <span class="n">cm</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> - <span class="n">figsize</span><span class="p">:</span> <span class="nb">tuple</span> <span class="o">=</span> <span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span> - <span class="n">alpha</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">5</span> - - <span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check the type of each argument.</span> - -<span class="sd"> Configure figure output paths.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if ``test`` is not of type `bool` or `None`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span> - - <span class="c1"># check whether the test input parameter is correctly specified</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">test</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">True</span><span class="p">]:</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'Expected "test" to be None, True or False, got '</span> - <span class="s1">'</span><span class="si">{}</span><span class="s1">.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">test</span><span class="p">))</span> - - <span class="c1"># the output paths for the different graphics</span> - <span class="bp">self</span><span class="o">.</span><span class="n">base_path</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">HERE</span><span class="p">)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">sample_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_path</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'_samples'</span><span class="p">)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">scenes_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_path</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'_scenes'</span><span class="p">)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">perfmc_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_path</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'_graphics'</span><span class="p">)</span> - - <span class="c1"># input path for model state files</span> - <span class="bp">self</span><span class="o">.</span><span class="n">models_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_path</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'_models'</span><span class="p">)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">state_file</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">models_path</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">state_file</span><span class="p">)</span> - - <span class="c1"># write initialization string to log file</span> - <span class="n">LogConfig</span><span class="o">.</span><span class="n">init_log</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1">: '</span> <span class="o">+</span> <span class="s1">'Evaluating model: </span><span class="si">{}</span><span class="s1">.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="bp">self</span><span class="o">.</span><span class="n">state_file</span><span class="o">.</span><span class="n">name</span><span class="p">))</span></div> - - -<div class="viewcode-block" id="LogConfig"><a class="viewcode-back" href="../../source/core.html#core.trainer.LogConfig">[docs]</a><span class="nd">@dataclasses</span><span class="o">.</span><span class="n">dataclass</span> -<span class="k">class</span> <span class="nc">LogConfig</span><span class="p">(</span><span class="n">BaseConfig</span><span class="p">):</span> - <span class="sd">"""Logging configuration class.</span> - -<span class="sd"> Generate the model log file.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> state_file : `pathlib.Path`</span> -<span class="sd"> Path to a model state file.</span> - -<span class="sd"> """</span> - - <span class="n">state_file</span><span class="p">:</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span> - - <span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check the type of each argument.</span> - -<span class="sd"> Generate model log file.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span> - - <span class="c1"># the path to store model logs</span> - <span class="bp">self</span><span class="o">.</span><span class="n">log_path</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">HERE</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'_logs'</span><span class="p">)</span> - - <span class="c1"># the log file of the current model</span> - <span class="bp">self</span><span class="o">.</span><span class="n">log_file</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">log_path</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span> - <span class="bp">self</span><span class="o">.</span><span class="n">state_file</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'.pt'</span><span class="p">,</span> <span class="s1">'.log'</span><span class="p">))</span> - -<div class="viewcode-block" id="LogConfig.now"><a class="viewcode-back" href="../../source/core.html#core.trainer.LogConfig.now">[docs]</a> <span class="nd">@staticmethod</span> - <span class="k">def</span> <span class="nf">now</span><span class="p">():</span> - <span class="sd">"""Return the current date and time.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> date : `datetime.datetime`</span> -<span class="sd"> The current date and time.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">(),</span> - <span class="s1">'%Y-%m-</span><span class="si">%d</span><span class="s1">T%H:%M:%S'</span><span class="p">)</span></div> - -<div class="viewcode-block" id="LogConfig.init_log"><a class="viewcode-back" href="../../source/core.html#core.trainer.LogConfig.init_log">[docs]</a> <span class="nd">@staticmethod</span> - <span class="k">def</span> <span class="nf">init_log</span><span class="p">(</span><span class="n">init_str</span><span class="p">):</span> - <span class="sd">"""Generate a string to identify a new model run.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> init_str : `str`</span> -<span class="sd"> The string to write to the model log file.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="mi">80</span> <span class="o">*</span> <span class="s1">'-'</span><span class="p">)</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">init_str</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">LogConfig</span><span class="o">.</span><span class="n">now</span><span class="p">()))</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="mi">80</span> <span class="o">*</span> <span class="s1">'-'</span><span class="p">)</span></div></div> - - -<div class="viewcode-block" id="NetworkTrainer"><a class="viewcode-back" href="../../source/core.html#core.trainer.NetworkTrainer">[docs]</a><span class="nd">@dataclasses</span><span class="o">.</span><span class="n">dataclass</span> -<span class="k">class</span> <span class="nc">NetworkTrainer</span><span class="p">(</span><span class="n">BaseConfig</span><span class="p">):</span> - <span class="sd">"""Model training class.</span> - -<span class="sd"> Generic class to train an instance of `pysegcnn.core.models.Network` on</span> -<span class="sd"> a dataset of type `pysegcnn.core.dataset.ImageDataset`.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> model : `pysegcnn.core.models.Network`</span> -<span class="sd"> The model to train. An instance of `pysegcnn.core.models.Network`.</span> -<span class="sd"> optimizer : `torch.optim.Optimizer`</span> -<span class="sd"> The optimizer to update the model weights. An instance of</span> -<span class="sd"> `torch.optim.Optimizer`.</span> -<span class="sd"> loss_function : `torch.nn.Module`</span> -<span class="sd"> The loss function to compute the model error. An instance of</span> -<span class="sd"> `torch.nn.Module`.</span> -<span class="sd"> train_dl : `torch.utils.data.DataLoader`</span> -<span class="sd"> The training `torch.utils.data.DataLoader` instance.</span> -<span class="sd"> valid_dl : `torch.utils.data.DataLoader`</span> -<span class="sd"> The validation `torch.utils.data.DataLoader` instance.</span> -<span class="sd"> test_dl : `torch.utils.data.DataLoader`</span> -<span class="sd"> The test `torch.utils.data.DataLoader` instance.</span> -<span class="sd"> state_file : `pathlib.Path`</span> -<span class="sd"> Path to save the model state.</span> -<span class="sd"> epochs : `int`, optional</span> -<span class="sd"> The maximum number of epochs to train. The default is 1.</span> -<span class="sd"> nthreads : `int`, optional</span> -<span class="sd"> The number of cpu threads to use during training. The default is</span> -<span class="sd"> torch.get_num_threads().</span> -<span class="sd"> early_stop : `bool`, optional</span> -<span class="sd"> Whether to apply `early stopping`_. The default is False.</span> -<span class="sd"> mode : `str`, optional</span> -<span class="sd"> The mode of the early stopping. Depends on the metric measuring</span> -<span class="sd"> performance. When using model loss as metric, use ``mode`` = 'min',</span> -<span class="sd"> however, when using accuracy as metric, use ``mode`` = 'max'. For now,</span> -<span class="sd"> only ``mode`` = 'max' is supported. Only used if ``early_stop`` = True.</span> -<span class="sd"> The default is 'max'.</span> -<span class="sd"> delta : `float`, optional</span> -<span class="sd"> Minimum change in early stopping metric to be considered as an</span> -<span class="sd"> improvement. Only used if ``early_stop`` = True. The default is 0.</span> -<span class="sd"> patience : `int`, optional</span> -<span class="sd"> The number of epochs to wait for an improvement in the early stopping</span> -<span class="sd"> metric. If the model does not improve over more than ``patience``</span> -<span class="sd"> epochs, quit training. Only used if ``early_stop`` = True.</span> -<span class="sd"> The default is 10.</span> -<span class="sd"> checkpoint_state : `dict` [`str`, `numpy.ndarray`], optional</span> -<span class="sd"> A model checkpoint for ``model``. If specified, ``checkpoint_state``</span> -<span class="sd"> should be a dictionary with keys:</span> -<span class="sd"> ``'ta'``</span> -<span class="sd"> The accuracy on the training set (`numpy.ndarray`).</span> -<span class="sd"> ``'tl'``</span> -<span class="sd"> The loss on the training set (`numpy.ndarray`).</span> -<span class="sd"> ``'va'``</span> -<span class="sd"> The accuracy on the validation set (`numpy.ndarray`).</span> -<span class="sd"> ``'vl'``</span> -<span class="sd"> The loss on the validation set (`numpy.ndarray`).</span> -<span class="sd"> The default is {}.</span> -<span class="sd"> save : `bool`, optional</span> -<span class="sd"> Whether to save the model state to ``state_file``. The default is True.</span> - -<span class="sd"> .. _early stopping:</span> -<span class="sd"> https://en.wikipedia.org/wiki/Early_stopping</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <span class="n">model</span><span class="p">:</span> <span class="n">Network</span> - <span class="n">optimizer</span><span class="p">:</span> <span class="n">Optimizer</span> - <span class="n">loss_function</span><span class="p">:</span> <span class="n">nn</span><span class="o">.</span><span class="n">Module</span> - <span class="n">train_dl</span><span class="p">:</span> <span class="n">DataLoader</span> - <span class="n">valid_dl</span><span class="p">:</span> <span class="n">DataLoader</span> - <span class="n">test_dl</span><span class="p">:</span> <span class="n">DataLoader</span> - <span class="n">state_file</span><span class="p">:</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span> - <span class="n">epochs</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span> - <span class="n">nthreads</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">get_num_threads</span><span class="p">()</span> - <span class="n">early_stop</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span> - <span class="n">mode</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">'max'</span> - <span class="n">delta</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">0</span> - <span class="n">patience</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">10</span> - <span class="n">checkpoint_state</span><span class="p">:</span> <span class="nb">dict</span> <span class="o">=</span> <span class="n">dataclasses</span><span class="o">.</span><span class="n">field</span><span class="p">(</span><span class="n">default_factory</span><span class="o">=</span><span class="nb">dict</span><span class="p">)</span> - <span class="n">save</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> - - <span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Check the type of each argument.</span> - -<span class="sd"> Configure the device to train the model on, i.e. train on the gpu if</span> -<span class="sd"> available.</span> - -<span class="sd"> Configure early stopping if required.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span> - - <span class="c1"># whether to use the gpu</span> - <span class="bp">self</span><span class="o">.</span><span class="n">device</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">device</span><span class="p">(</span><span class="s2">"cuda:0"</span> <span class="k">if</span> <span class="n">torch</span><span class="o">.</span><span class="n">cuda</span><span class="o">.</span><span class="n">is_available</span><span class="p">()</span> - <span class="k">else</span> <span class="s2">"cpu"</span><span class="p">)</span> - - <span class="c1"># send the model to the gpu if available</span> - <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span> - - <span class="c1"># maximum accuracy on the validation dataset</span> - <span class="bp">self</span><span class="o">.</span><span class="n">max_accuracy</span> <span class="o">=</span> <span class="mi">0</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">checkpoint_state</span><span class="p">:</span> - <span class="bp">self</span><span class="o">.</span><span class="n">max_accuracy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">checkpoint_state</span><span class="p">[</span><span class="s1">'va'</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span> - <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">max</span><span class="p">()</span><span class="o">.</span><span class="n">item</span><span class="p">()</span> - - <span class="c1"># whether to use early stopping</span> - <span class="bp">self</span><span class="o">.</span><span class="n">es</span> <span class="o">=</span> <span class="kc">None</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">early_stop</span><span class="p">:</span> - <span class="bp">self</span><span class="o">.</span><span class="n">es</span> <span class="o">=</span> <span class="n">EarlyStopping</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_accuracy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">delta</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">patience</span><span class="p">)</span> - - <span class="c1"># log representation</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span> - -<div class="viewcode-block" id="NetworkTrainer.train"><a class="viewcode-back" href="../../source/core.html#core.trainer.NetworkTrainer.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Train the model.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> training_state : `dict` [`str`, `numpy.ndarray`]</span> -<span class="sd"> The training state dictionary with keys:</span> -<span class="sd"> ``'ta'``</span> -<span class="sd"> The accuracy on the training set (`numpy.ndarray`).</span> -<span class="sd"> ``'tl'``</span> -<span class="sd"> The loss on the training set (`numpy.ndarray`).</span> -<span class="sd"> ``'va'``</span> -<span class="sd"> The accuracy on the validation set (`numpy.ndarray`).</span> -<span class="sd"> ``'vl'``</span> -<span class="sd"> The loss on the validation set (`numpy.ndarray`).</span> - -<span class="sd"> """</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="mi">35</span> <span class="o">*</span> <span class="s1">'-'</span> <span class="o">+</span> <span class="s1">' Training '</span> <span class="o">+</span> <span class="mi">35</span> <span class="o">*</span> <span class="s1">'-'</span><span class="p">)</span> - - <span class="c1"># set the number of threads</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Device: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">))</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Number of cpu threads: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nthreads</span><span class="p">))</span> - <span class="n">torch</span><span class="o">.</span><span class="n">set_num_threads</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nthreads</span><span class="p">)</span> - - <span class="c1"># create dictionary of the observed losses and accuracies on the</span> - <span class="c1"># training and validation dataset</span> - <span class="n">tshape</span> <span class="o">=</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">epochs</span><span class="p">)</span> - <span class="n">vshape</span> <span class="o">=</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">valid_dl</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">epochs</span><span class="p">)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">training_state</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'tl'</span><span class="p">:</span> <span class="n">np</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="n">tshape</span><span class="p">),</span> - <span class="s1">'ta'</span><span class="p">:</span> <span class="n">np</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="n">tshape</span><span class="p">),</span> - <span class="s1">'vl'</span><span class="p">:</span> <span class="n">np</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="n">vshape</span><span class="p">),</span> - <span class="s1">'va'</span><span class="p">:</span> <span class="n">np</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="n">vshape</span><span class="p">)</span> - <span class="p">}</span> - - <span class="c1"># initialize the training: iterate over the entire training dataset</span> - <span class="k">for</span> <span class="n">epoch</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">epochs</span><span class="p">):</span> - - <span class="c1"># set the model to training mode</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Setting model to training mode ...'</span><span class="p">)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">train</span><span class="p">()</span> - - <span class="c1"># iterate over the dataloader object</span> - <span class="k">for</span> <span class="n">batch</span><span class="p">,</span> <span class="p">(</span><span class="n">inputs</span><span class="p">,</span> <span class="n">labels</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="p">):</span> - - <span class="c1"># send the data to the gpu if available</span> - <span class="n">inputs</span> <span class="o">=</span> <span class="n">inputs</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span> - <span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span> - - <span class="c1"># reset the gradients</span> - <span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">zero_grad</span><span class="p">()</span> - - <span class="c1"># perform forward pass</span> - <span class="n">outputs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="n">inputs</span><span class="p">)</span> - - <span class="c1"># compute loss</span> - <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_function</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="n">labels</span><span class="o">.</span><span class="n">long</span><span class="p">())</span> - <span class="n">observed_loss</span> <span class="o">=</span> <span class="n">loss</span><span class="o">.</span><span class="n">detach</span><span class="p">()</span><span class="o">.</span><span class="n">numpy</span><span class="p">()</span><span class="o">.</span><span class="n">item</span><span class="p">()</span> - <span class="bp">self</span><span class="o">.</span><span class="n">training_state</span><span class="p">[</span><span class="s1">'tl'</span><span class="p">][</span><span class="n">batch</span><span class="p">,</span> <span class="n">epoch</span><span class="p">]</span> <span class="o">=</span> <span class="n">observed_loss</span> - - <span class="c1"># compute the gradients of the loss function w.r.t.</span> - <span class="c1"># the network weights</span> - <span class="n">loss</span><span class="o">.</span><span class="n">backward</span><span class="p">()</span> - - <span class="c1"># update the weights</span> - <span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">step</span><span class="p">()</span> - - <span class="c1"># calculate predicted class labels</span> - <span class="n">ypred</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> - - <span class="c1"># calculate accuracy on current batch</span> - <span class="n">observed_accuracy</span> <span class="o">=</span> <span class="n">accuracy_function</span><span class="p">(</span><span class="n">ypred</span><span class="p">,</span> <span class="n">labels</span><span class="p">)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">training_state</span><span class="p">[</span><span class="s1">'ta'</span><span class="p">][</span><span class="n">batch</span><span class="p">,</span> <span class="n">epoch</span><span class="p">]</span> <span class="o">=</span> <span class="n">observed_accuracy</span> - - <span class="c1"># print progress</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Epoch: </span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1">, Mini-batch: </span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1">, '</span> - <span class="s1">'Loss: </span><span class="si">{:.2f}</span><span class="s1">, Accuracy: </span><span class="si">{:.2f}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="n">epoch</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">epochs</span><span class="p">,</span> - <span class="n">batch</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> - <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="p">),</span> - <span class="n">observed_loss</span><span class="p">,</span> - <span class="n">observed_accuracy</span><span class="p">))</span> - - <span class="c1"># update the number of epochs trained</span> - <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">epoch</span> <span class="o">+=</span> <span class="mi">1</span> - - <span class="c1"># whether to evaluate model performance on the validation set and</span> - <span class="c1"># early stop the training process</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">early_stop</span><span class="p">:</span> - - <span class="c1"># model predictions on the validation set</span> - <span class="n">vacc</span><span class="p">,</span> <span class="n">vloss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">predict</span><span class="p">()</span> - - <span class="c1"># append observed accuracy and loss to arrays</span> - <span class="bp">self</span><span class="o">.</span><span class="n">training_state</span><span class="p">[</span><span class="s1">'va'</span><span class="p">][:,</span> <span class="n">epoch</span><span class="p">]</span> <span class="o">=</span> <span class="n">vacc</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span> - <span class="bp">self</span><span class="o">.</span><span class="n">training_state</span><span class="p">[</span><span class="s1">'vl'</span><span class="p">][:,</span> <span class="n">epoch</span><span class="p">]</span> <span class="o">=</span> <span class="n">vloss</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span> - - <span class="c1"># metric to assess model performance on the validation set</span> - <span class="n">epoch_acc</span> <span class="o">=</span> <span class="n">vacc</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span> - - <span class="c1"># whether the model improved with respect to the previous epoch</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">es</span><span class="o">.</span><span class="n">increased</span><span class="p">(</span><span class="n">epoch_acc</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_accuracy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">delta</span><span class="p">):</span> - <span class="bp">self</span><span class="o">.</span><span class="n">max_accuracy</span> <span class="o">=</span> <span class="n">epoch_acc</span> - - <span class="c1"># save model state if the model improved with</span> - <span class="c1"># respect to the previous epoch</span> - <span class="bp">self</span><span class="o">.</span><span class="n">save_state</span><span class="p">()</span> - - <span class="c1"># whether the early stopping criterion is met</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">es</span><span class="o">.</span><span class="n">stop</span><span class="p">(</span><span class="n">epoch_acc</span><span class="p">):</span> - <span class="k">break</span> - - <span class="k">else</span><span class="p">:</span> - <span class="c1"># if no early stopping is required, the model state is</span> - <span class="c1"># saved after each epoch</span> - <span class="bp">self</span><span class="o">.</span><span class="n">save_state</span><span class="p">()</span> - - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">training_state</span></div> - -<div class="viewcode-block" id="NetworkTrainer.predict"><a class="viewcode-back" href="../../source/core.html#core.trainer.NetworkTrainer.predict">[docs]</a> <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Model inference at training time.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> accuracies : `numpy.ndarray`</span> -<span class="sd"> The mean model prediction accuracy on each mini-batch in the</span> -<span class="sd"> validation set.</span> -<span class="sd"> losses : `numpy.ndarray`</span> -<span class="sd"> The model loss for each mini-batch in the validation set.</span> - -<span class="sd"> """</span> - <span class="c1"># set the model to evaluation mode</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Setting model to evaluation mode ...'</span><span class="p">)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">eval</span><span class="p">()</span> - - <span class="c1"># create arrays of the observed losses and accuracies</span> - <span class="n">accuracies</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">shape</span><span class="o">=</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">valid_dl</span><span class="p">),</span> <span class="mi">1</span><span class="p">))</span> - <span class="n">losses</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">shape</span><span class="o">=</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">valid_dl</span><span class="p">),</span> <span class="mi">1</span><span class="p">))</span> - - <span class="c1"># iterate over the validation/test set</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Calculating accuracy on the validation set ...'</span><span class="p">)</span> - <span class="k">for</span> <span class="n">batch</span><span class="p">,</span> <span class="p">(</span><span class="n">inputs</span><span class="p">,</span> <span class="n">labels</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">valid_dl</span><span class="p">):</span> - - <span class="c1"># send the data to the gpu if available</span> - <span class="n">inputs</span> <span class="o">=</span> <span class="n">inputs</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span> - <span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span> - - <span class="c1"># calculate network outputs</span> - <span class="k">with</span> <span class="n">torch</span><span class="o">.</span><span class="n">no_grad</span><span class="p">():</span> - <span class="n">outputs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="n">inputs</span><span class="p">)</span> - - <span class="c1"># compute loss</span> - <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_function</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="n">labels</span><span class="o">.</span><span class="n">long</span><span class="p">())</span> - <span class="n">losses</span><span class="p">[</span><span class="n">batch</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">loss</span><span class="o">.</span><span class="n">detach</span><span class="p">()</span><span class="o">.</span><span class="n">numpy</span><span class="p">()</span><span class="o">.</span><span class="n">item</span><span class="p">()</span> - - <span class="c1"># calculate predicted class labels</span> - <span class="n">pred</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> - - <span class="c1"># calculate accuracy on current batch</span> - <span class="n">acc</span> <span class="o">=</span> <span class="n">accuracy_function</span><span class="p">(</span><span class="n">pred</span><span class="p">,</span> <span class="n">labels</span><span class="p">)</span> - <span class="n">accuracies</span><span class="p">[</span><span class="n">batch</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">acc</span> - - <span class="c1"># print progress</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Mini-batch: </span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1">, Accuracy: </span><span class="si">{:.2f}</span><span class="s1">'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">batch</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">valid_dl</span><span class="p">),</span> <span class="n">acc</span><span class="p">))</span> - - <span class="c1"># calculate overall accuracy on the validation/test set</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Epoch: </span><span class="si">{:d}</span><span class="s1">, Mean accuracy: </span><span class="si">{:.2f}</span><span class="s1">%.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">epoch</span><span class="p">,</span> <span class="n">accuracies</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))</span> - - <span class="k">return</span> <span class="n">accuracies</span><span class="p">,</span> <span class="n">losses</span></div> - -<div class="viewcode-block" id="NetworkTrainer.save_state"><a class="viewcode-back" href="../../source/core.html#core.trainer.NetworkTrainer.save_state">[docs]</a> <span class="k">def</span> <span class="nf">save_state</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Save the model state.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="c1"># whether to save the model state</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">save</span><span class="p">:</span> - - <span class="c1"># append the model performance before the checkpoint to the model</span> - <span class="c1"># state, if a checkpoint is passed</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">checkpoint_state</span><span class="p">:</span> - - <span class="c1"># append values from checkpoint to current training state</span> - <span class="n">state</span> <span class="o">=</span> <span class="p">{</span><span class="n">k1</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">([</span><span class="n">v1</span><span class="p">,</span> <span class="n">v2</span><span class="p">])</span> <span class="k">for</span> <span class="p">(</span><span class="n">k1</span><span class="p">,</span> <span class="n">v1</span><span class="p">),</span> <span class="p">(</span><span class="n">k2</span><span class="p">,</span> <span class="n">v2</span><span class="p">)</span> <span class="ow">in</span> - <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">checkpoint_state</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span> - <span class="bp">self</span><span class="o">.</span><span class="n">training_state</span><span class="o">.</span><span class="n">items</span><span class="p">())</span> <span class="k">if</span> <span class="n">k1</span> <span class="o">==</span> <span class="n">k2</span><span class="p">}</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">state</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">training_state</span> - - <span class="c1"># save model state</span> - <span class="n">_</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">save</span><span class="p">(</span> - <span class="bp">self</span><span class="o">.</span><span class="n">state_file</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="p">,</span> - <span class="n">bands</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">use_bands</span><span class="p">,</span> - <span class="n">train_ds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="o">.</span><span class="n">dataset</span><span class="p">,</span> - <span class="n">valid_ds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">valid_dl</span><span class="o">.</span><span class="n">dataset</span><span class="p">,</span> - <span class="n">test_ds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">test_dl</span><span class="o">.</span><span class="n">dataset</span><span class="p">,</span> - <span class="n">state</span><span class="o">=</span><span class="n">state</span><span class="p">,</span> - <span class="p">)</span></div> - - <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Representation of `~pysegcnn.core.trainer.NetworkTrainer`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> fs : `str`</span> -<span class="sd"> Representation string.</span> - -<span class="sd"> """</span> - <span class="c1"># representation string to print</span> - <span class="n">fs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">+</span> <span class="s1">'(</span><span class="se">\n</span><span class="s1">'</span> - - <span class="c1"># dataset</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">' (dataset):</span><span class="se">\n</span><span class="s1"> '</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span> - <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">dataset</span><span class="p">))</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span><span class="p">)</span> - - <span class="c1"># batch size</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> (batch):</span><span class="se">\n</span><span class="s1"> '</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'- batch size: </span><span class="si">{}</span><span class="se">\n</span><span class="s1"> '</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="o">.</span><span class="n">batch_size</span><span class="p">)</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'- mini-batch shape (b, c, h, w): </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="o">.</span><span class="n">batch_size</span><span class="p">,</span> - <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">use_bands</span><span class="p">),</span> - <span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">tile_size</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">tile_size</span><span class="p">)</span> - <span class="p">)</span> - - <span class="c1"># dataset split</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> (split):'</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span> <span class="o">+</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">train_dl</span><span class="o">.</span><span class="n">dataset</span><span class="p">)</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span> <span class="o">+</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">valid_dl</span><span class="o">.</span><span class="n">dataset</span><span class="p">)</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span> <span class="o">+</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">test_dl</span><span class="o">.</span><span class="n">dataset</span><span class="p">)</span> - - <span class="c1"># model</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> (model):</span><span class="se">\n</span><span class="s1"> '</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">))</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span><span class="p">)</span> - - <span class="c1"># optimizer</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> (optimizer):</span><span class="se">\n</span><span class="s1"> '</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="p">))</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span><span class="p">)</span> - - <span class="c1"># early stopping</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> (early stop):</span><span class="se">\n</span><span class="s1"> '</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">es</span><span class="p">))</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span><span class="p">)</span> - - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">)'</span> - <span class="k">return</span> <span class="n">fs</span></div> - - -<div class="viewcode-block" id="EarlyStopping"><a class="viewcode-back" href="../../source/core.html#core.trainer.EarlyStopping">[docs]</a><span class="k">class</span> <span class="nc">EarlyStopping</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> - <span class="sd">"""`Early stopping`_ algorithm.</span> - -<span class="sd"> This implementation of the early stopping algorithm advances a counter each</span> -<span class="sd"> time a metric did not improve over a training epoch. If the metric does not</span> -<span class="sd"> improve over more than ``patience`` epochs, the early stopping criterion is</span> -<span class="sd"> met.</span> - -<span class="sd"> See `pysegcnn.core.trainer.NetworkTrainer.train` for an example</span> -<span class="sd"> implementation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> mode : `str`, optional</span> -<span class="sd"> The mode of the early stopping. Depends on the metric measuring</span> -<span class="sd"> performance. When using model loss as metric, use ``mode`` = 'min',</span> -<span class="sd"> however, when using accuracy as metric, use ``mode`` = 'max'. The</span> -<span class="sd"> default is 'max'.</span> -<span class="sd"> best : `float`, optional</span> -<span class="sd"> Threshold indicating the best metric score. At instanciation, set</span> -<span class="sd"> ``best`` to the worst possible score of the metric. ``best`` will be</span> -<span class="sd"> overwritten during training. The default is 0.</span> -<span class="sd"> min_delta : `float`, optional</span> -<span class="sd"> Minimum change in early stopping metric to be considered as an</span> -<span class="sd"> improvement. The default is 0.</span> -<span class="sd"> patience : `int`, optional</span> -<span class="sd"> The number of epochs to wait for an improvement in the early stopping</span> -<span class="sd"> metric. The default is 10.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> ValueError</span> -<span class="sd"> Raised if ``mode`` is not either 'min' or 'max'.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> .. _Early stopping:</span> -<span class="sd"> https://en.wikipedia.org/wiki/Early_stopping</span> - -<span class="sd"> """</span> - - <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">mode</span><span class="o">=</span><span class="s1">'max'</span><span class="p">,</span> <span class="n">best</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">min_delta</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">patience</span><span class="o">=</span><span class="mi">10</span><span class="p">):</span> - - <span class="c1"># check if mode is correctly specified</span> - <span class="k">if</span> <span class="n">mode</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">]:</span> - <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'Mode "</span><span class="si">{}</span><span class="s1">" not supported. '</span> - <span class="s1">'Mode is either "min" (check whether the metric '</span> - <span class="s1">'decreased, e.g. loss) or "max" (check whether '</span> - <span class="s1">'the metric increased, e.g. accuracy).'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mode</span><span class="p">))</span> - - <span class="c1"># mode to determine if metric improved</span> - <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">=</span> <span class="n">mode</span> - - <span class="c1"># whether to check for an increase or a decrease in a given metric</span> - <span class="bp">self</span><span class="o">.</span><span class="n">is_better</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decreased</span> <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s1">'min'</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">increased</span> - - <span class="c1"># minimum change in metric to be considered as an improvement</span> - <span class="bp">self</span><span class="o">.</span><span class="n">min_delta</span> <span class="o">=</span> <span class="n">min_delta</span> - - <span class="c1"># number of epochs to wait for improvement</span> - <span class="bp">self</span><span class="o">.</span><span class="n">patience</span> <span class="o">=</span> <span class="n">patience</span> - - <span class="c1"># initialize best metric</span> - <span class="bp">self</span><span class="o">.</span><span class="n">best</span> <span class="o">=</span> <span class="n">best</span> - - <span class="c1"># initialize early stopping flag</span> - <span class="bp">self</span><span class="o">.</span><span class="n">early_stop</span> <span class="o">=</span> <span class="kc">False</span> - - <span class="c1"># initialize the early stop counter</span> - <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">=</span> <span class="mi">0</span> - -<div class="viewcode-block" id="EarlyStopping.stop"><a class="viewcode-back" href="../../source/core.html#core.trainer.EarlyStopping.stop">[docs]</a> <span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">metric</span><span class="p">):</span> - <span class="sd">"""Advance early stopping counter.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> metric : `float`</span> -<span class="sd"> The current metric score.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> early_stop : `bool`</span> -<span class="sd"> Whether the early stopping criterion is met.</span> - -<span class="sd"> """</span> - <span class="c1"># if the metric improved, reset the epochs counter, else, advance</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_better</span><span class="p">(</span><span class="n">metric</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">best</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_delta</span><span class="p">):</span> - <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">=</span> <span class="mi">0</span> - <span class="bp">self</span><span class="o">.</span><span class="n">best</span> <span class="o">=</span> <span class="n">metric</span> - <span class="k">else</span><span class="p">:</span> - <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">+=</span> <span class="mi">1</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Early stopping counter: </span><span class="si">{}</span><span class="s1">/</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="bp">self</span><span class="o">.</span><span class="n">counter</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">patience</span><span class="p">))</span> - - <span class="c1"># if the metric did not improve over the last patience epochs,</span> - <span class="c1"># the early stopping criterion is met</span> - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">>=</span> <span class="bp">self</span><span class="o">.</span><span class="n">patience</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Early stopping criterion met, stopping training.'</span><span class="p">)</span> - <span class="bp">self</span><span class="o">.</span><span class="n">early_stop</span> <span class="o">=</span> <span class="kc">True</span> - - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">early_stop</span></div> - -<div class="viewcode-block" id="EarlyStopping.decreased"><a class="viewcode-back" href="../../source/core.html#core.trainer.EarlyStopping.decreased">[docs]</a> <span class="k">def</span> <span class="nf">decreased</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">metric</span><span class="p">,</span> <span class="n">best</span><span class="p">,</span> <span class="n">min_delta</span><span class="p">):</span> - <span class="sd">"""Whether a metric decreased with respect to a best score.</span> - -<span class="sd"> Measure improvement for metrics that are considered as 'better' when</span> -<span class="sd"> they decrease, e.g. model loss, mean squared error, etc.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> metric : `float`</span> -<span class="sd"> The current score.</span> -<span class="sd"> best : `float`</span> -<span class="sd"> The current best score.</span> -<span class="sd"> min_delta : `float`</span> -<span class="sd"> Minimum change to be considered as an improvement.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> `bool`</span> -<span class="sd"> Whether the metric improved.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">metric</span> <span class="o"><</span> <span class="n">best</span> <span class="o">-</span> <span class="n">min_delta</span></div> - -<div class="viewcode-block" id="EarlyStopping.increased"><a class="viewcode-back" href="../../source/core.html#core.trainer.EarlyStopping.increased">[docs]</a> <span class="k">def</span> <span class="nf">increased</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">metric</span><span class="p">,</span> <span class="n">best</span><span class="p">,</span> <span class="n">min_delta</span><span class="p">):</span> - <span class="sd">"""Whether a metric increased with respect to a best score.</span> - -<span class="sd"> Measure improvement for metrics that are considered as 'better' when</span> -<span class="sd"> they increase, e.g. accuracy, precision, recall, etc.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> metric : `float`</span> -<span class="sd"> The current score.</span> -<span class="sd"> best : `float`</span> -<span class="sd"> The current best score.</span> -<span class="sd"> min_delta : `float`</span> -<span class="sd"> Minimum change to be considered as an improvement.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> `bool`</span> -<span class="sd"> Whether the metric improved.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="n">metric</span> <span class="o">></span> <span class="n">best</span> <span class="o">+</span> <span class="n">min_delta</span></div> - - <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Representation of `~pysegcnn.core.trainer.EarlyStopping`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> fs : `str`</span> -<span class="sd"> Representation string.</span> - -<span class="sd"> """</span> - <span class="n">fs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> - <span class="n">fs</span> <span class="o">+=</span> <span class="s1">'(mode=</span><span class="si">{}</span><span class="s1">, best=</span><span class="si">{:.2f}</span><span class="s1">, delta=</span><span class="si">{}</span><span class="s1">, patience=</span><span class="si">{}</span><span class="s1">)'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">best</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_delta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">patience</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">fs</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/transforms.html b/docs/_build/html/_modules/core/transforms.html deleted file mode 100644 index 51ff97a3d4915ed13bf050559143b3c215e6d801..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/transforms.html +++ /dev/null @@ -1,647 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.transforms — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.transforms</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.transforms</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Data augmentation.</span> - -<span class="sd">This module provides classes implementing common image augmentation methods.</span> - -<span class="sd">These methods may be used to artificially increase a dataset.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># externals</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">scipy</span> <span class="kn">import</span> <span class="n">ndimage</span> - - -<div class="viewcode-block" id="Transform"><a class="viewcode-back" href="../../source/core.html#core.transforms.Transform">[docs]</a><span class="k">class</span> <span class="nc">Transform</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> - <span class="sd">"""Base class for an image transformation."""</span> - - <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="k">pass</span> - - <span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image</span><span class="p">):</span> - <span class="sd">"""Apply transformation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> The image to transform.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `~pysegcnn.core.transforms.Transform` is not inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="k">raise</span> <span class="ne">NotImplementedError</span></div> - - -<div class="viewcode-block" id="VariantTransform"><a class="viewcode-back" href="../../source/core.html#core.transforms.VariantTransform">[docs]</a><span class="k">class</span> <span class="nc">VariantTransform</span><span class="p">(</span><span class="n">Transform</span><span class="p">):</span> - <span class="sd">"""Base class for a spatially variant transformation.</span> - -<span class="sd"> Transformation on the ground truth required.</span> -<span class="sd"> """</span> - - <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="c1"># transformation on the ground truth required</span> - <span class="bp">self</span><span class="o">.</span><span class="n">invariant</span> <span class="o">=</span> <span class="kc">False</span></div> - - -<div class="viewcode-block" id="InvariantTransform"><a class="viewcode-back" href="../../source/core.html#core.transforms.InvariantTransform">[docs]</a><span class="k">class</span> <span class="nc">InvariantTransform</span><span class="p">(</span><span class="n">Transform</span><span class="p">):</span> - <span class="sd">"""Base class for a spatially invariant transformation.</span> - -<span class="sd"> Transformation on the ground truth not required.</span> -<span class="sd"> """</span> - - <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="c1"># transformation on the ground truth not required</span> - <span class="bp">self</span><span class="o">.</span><span class="n">invariant</span> <span class="o">=</span> <span class="kc">True</span></div> - - -<div class="viewcode-block" id="FlipLr"><a class="viewcode-back" href="../../source/core.html#core.transforms.FlipLr">[docs]</a><span class="k">class</span> <span class="nc">FlipLr</span><span class="p">(</span><span class="n">VariantTransform</span><span class="p">):</span> - <span class="sd">"""Flip an image horizontally.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> p : `float`, optional</span> -<span class="sd"> The probability to apply the transformation. The default is 0.5.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">p</span><span class="o">=</span><span class="mf">0.5</span><span class="p">):</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - <span class="c1"># the probability to apply the transformation</span> - <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span> - - <span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image</span><span class="p">):</span> - <span class="sd">"""Apply transformation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> The image to transform.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> transform : `numpy.ndarray`</span> -<span class="sd"> The transformed image.</span> - -<span class="sd"> """</span> - <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o"><</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">:</span> - <span class="c1"># transformation applied</span> - <span class="bp">self</span><span class="o">.</span><span class="n">applied</span> <span class="o">=</span> <span class="kc">True</span> - <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)[</span><span class="o">...</span><span class="p">,</span> <span class="p">::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> - - <span class="c1"># transformation not applied</span> - <span class="bp">self</span><span class="o">.</span><span class="n">applied</span> <span class="o">=</span> <span class="kc">False</span> - <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> - - <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Representation of the transformation.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> repr : `str`</span> -<span class="sd"> Representation string.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">+</span> <span class="s1">'(p = </span><span class="si">{}</span><span class="s1">)'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">)</span></div> - - -<div class="viewcode-block" id="FlipUd"><a class="viewcode-back" href="../../source/core.html#core.transforms.FlipUd">[docs]</a><span class="k">class</span> <span class="nc">FlipUd</span><span class="p">(</span><span class="n">VariantTransform</span><span class="p">):</span> - <span class="sd">"""Flip an image vertically.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> p : `float`, optional</span> -<span class="sd"> The probability to apply the transformation. The default is 0.5.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">p</span><span class="o">=</span><span class="mf">0.5</span><span class="p">):</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - <span class="c1"># the probability to apply the transformation</span> - <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span> - - <span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image</span><span class="p">):</span> - <span class="sd">"""Apply transformation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> The image to transform.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> transform : `numpy.ndarray`</span> -<span class="sd"> The transformed image.</span> - -<span class="sd"> """</span> - <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o"><</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">:</span> - <span class="c1"># transformation applied</span> - <span class="bp">self</span><span class="o">.</span><span class="n">applied</span> <span class="o">=</span> <span class="kc">True</span> - <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)[</span><span class="o">...</span><span class="p">,</span> <span class="p">::</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="p">:]</span> - - <span class="c1"># transformation not applied</span> - <span class="bp">self</span><span class="o">.</span><span class="n">applied</span> <span class="o">=</span> <span class="kc">False</span> - <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> - - <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Representation of the transformation.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> repr : `str`</span> -<span class="sd"> Representation string.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">+</span> <span class="s1">'(p = </span><span class="si">{}</span><span class="s1">)'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">)</span></div> - - -<div class="viewcode-block" id="Rotate"><a class="viewcode-back" href="../../source/core.html#core.transforms.Rotate">[docs]</a><span class="k">class</span> <span class="nc">Rotate</span><span class="p">(</span><span class="n">VariantTransform</span><span class="p">):</span> - <span class="sd">"""Rotate an image by ``angle``.</span> - -<span class="sd"> The image is rotated in the spatial plane.</span> - -<span class="sd"> If the input array has more then two dimensions, the spatial dimensions are</span> -<span class="sd"> assumed to be the last two dimensions of the array.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> angle : `float`</span> -<span class="sd"> The rotation angle in degrees.</span> -<span class="sd"> p : `float`, optional</span> -<span class="sd"> The probability to apply the transformation. The default is 0.5.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> -<span class="sd"> """</span> - - <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">angle</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="mf">0.5</span><span class="p">):</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - - <span class="c1"># the rotation angle</span> - <span class="bp">self</span><span class="o">.</span><span class="n">angle</span> <span class="o">=</span> <span class="n">angle</span> - - <span class="c1"># the probability to apply the transformation</span> - <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span> - - <span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image</span><span class="p">):</span> - <span class="sd">"""Apply transformation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> The image to transform.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> transform : `numpy.ndarray`</span> -<span class="sd"> The transformed image.</span> -<span class="sd"> """</span> - <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o"><</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">:</span> - - <span class="c1"># transformation applied</span> - <span class="bp">self</span><span class="o">.</span><span class="n">applied</span> <span class="o">=</span> <span class="kc">True</span> - - <span class="c1"># check dimension of input image</span> - <span class="n">ndim</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)</span><span class="o">.</span><span class="n">ndim</span> - - <span class="c1"># axes defining the rotational plane</span> - <span class="n">rot_axes</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> - <span class="k">if</span> <span class="n">ndim</span> <span class="o">></span> <span class="mi">2</span><span class="p">:</span> - <span class="n">rot_axes</span> <span class="o">=</span> <span class="p">(</span><span class="n">ndim</span> <span class="o">-</span> <span class="mi">2</span><span class="p">,</span> <span class="n">ndim</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">ndimage</span><span class="o">.</span><span class="n">rotate</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle</span><span class="p">,</span> <span class="n">axes</span><span class="o">=</span><span class="n">rot_axes</span><span class="p">,</span> - <span class="n">reshape</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> - - <span class="c1"># transformation not applied</span> - <span class="bp">self</span><span class="o">.</span><span class="n">applied</span> <span class="o">=</span> <span class="kc">False</span> - <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> - - <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Representation of the transformation.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> repr : `str`</span> -<span class="sd"> Representation string.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">+</span> <span class="s1">'(angle = </span><span class="si">{}</span><span class="s1">, p = </span><span class="si">{}</span><span class="s1">)'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span> - <span class="bp">self</span><span class="o">.</span><span class="n">angle</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">)</span></div> - - -<div class="viewcode-block" id="Noise"><a class="viewcode-back" href="../../source/core.html#core.transforms.Noise">[docs]</a><span class="k">class</span> <span class="nc">Noise</span><span class="p">(</span><span class="n">InvariantTransform</span><span class="p">):</span> - <span class="sd">"""Add gaussian noise to an image.</span> - -<span class="sd"> Valid modes are:</span> - -<span class="sd"> 'add': image = image + noise</span> -<span class="sd"> 'speckle' : image = image + image * noise</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> mode : `str`</span> -<span class="sd"> The mode to add the noise.</span> -<span class="sd"> mean : `float`, optional</span> -<span class="sd"> The mean of the gaussian distribution from which the noise is sampled.</span> -<span class="sd"> The default is 0.</span> -<span class="sd"> var : `float`, optional</span> -<span class="sd"> The variance of the gaussian distribution from which the noise is</span> -<span class="sd"> sampled. The default is 0.05.</span> -<span class="sd"> p : `float`, optional</span> -<span class="sd"> The probability to apply the transformation. The default is 0.5.</span> -<span class="sd"> exclude : `list` [`float`] or `list` [`int`], optional</span> -<span class="sd"> Values for which the noise is not added. Useful for pixels resulting</span> -<span class="sd"> from image padding. The default is [].</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> ValueError</span> -<span class="sd"> Raised if ``mode`` is not supported.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <span class="c1"># supported modes</span> - <span class="n">modes</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'add'</span><span class="p">,</span> <span class="s1">'speckle'</span><span class="p">]</span> - - <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">mode</span><span class="p">,</span> <span class="n">mean</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">var</span><span class="o">=</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">[]):</span> - <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> - - <span class="c1"># check which kind of noise to apply</span> - <span class="k">if</span> <span class="n">mode</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">modes</span><span class="p">:</span> - <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'Supported noise types are: </span><span class="si">{}</span><span class="s1">.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">modes</span><span class="p">))</span> - <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">=</span> <span class="n">mode</span> - - <span class="c1"># mean and variance of the gaussian distribution the noise signal is</span> - <span class="c1"># sampled from</span> - <span class="bp">self</span><span class="o">.</span><span class="n">mean</span> <span class="o">=</span> <span class="n">mean</span> - <span class="bp">self</span><span class="o">.</span><span class="n">var</span> <span class="o">=</span> <span class="n">var</span> - - <span class="c1"># the probability to apply the transformation</span> - <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span> - - <span class="c1"># the value in the image that should not be modified by the noise</span> - <span class="bp">self</span><span class="o">.</span><span class="n">exclude</span> <span class="o">=</span> <span class="n">exclude</span> - - <span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image</span><span class="p">):</span> - <span class="sd">"""Apply transformation.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> The image to transform.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> transform : `numpy.ndarray`</span> -<span class="sd"> The transformed image</span> - -<span class="sd"> """</span> - <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o"><</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">:</span> - - <span class="c1"># transformation applied</span> - <span class="bp">self</span><span class="o">.</span><span class="n">applied</span> <span class="o">=</span> <span class="kc">True</span> - - <span class="c1"># generate gaussian noise</span> - <span class="n">noise</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mean</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">var</span><span class="p">,</span> <span class="n">image</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> - - <span class="c1"># check which values should not be modified by adding noise</span> - <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">exclude</span><span class="p">:</span> - <span class="n">noise</span><span class="p">[</span><span class="n">image</span> <span class="o">==</span> <span class="n">val</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span> - - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">==</span> <span class="s1">'gaussian'</span><span class="p">:</span> - <span class="k">return</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> <span class="o">+</span> <span class="n">noise</span><span class="p">)</span><span class="o">.</span><span class="n">clip</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> - - <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">==</span> <span class="s1">'speckle'</span><span class="p">:</span> - <span class="k">return</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> <span class="o">+</span> - <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> <span class="o">*</span> <span class="n">noise</span><span class="p">)</span><span class="o">.</span><span class="n">clip</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> - - <span class="c1"># transformation not applied</span> - <span class="bp">self</span><span class="o">.</span><span class="n">applied</span> <span class="o">=</span> <span class="kc">False</span> - <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> - - <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Representation of the transformation.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> repr : `str`</span> -<span class="sd"> Representation string.</span> - -<span class="sd"> """</span> - <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">+</span> <span class="p">(</span><span class="s1">'(mode = </span><span class="si">{}</span><span class="s1">, mean = </span><span class="si">{}</span><span class="s1">, var = </span><span class="si">{}</span><span class="s1">, '</span> - <span class="s1">'p = </span><span class="si">{}</span><span class="s1">)'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mean</span><span class="p">,</span> - <span class="bp">self</span><span class="o">.</span><span class="n">var</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">))</span></div> - - -<div class="viewcode-block" id="Augment"><a class="viewcode-back" href="../../source/core.html#core.transforms.Augment">[docs]</a><span class="k">class</span> <span class="nc">Augment</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> - <span class="sd">"""Apply a sequence of transformations.</span> - -<span class="sd"> Container class applying each transformation in ``transforms`` in order.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> transforms : `list` or `tuple`</span> -<span class="sd"> A sequence of instances of `pysegcnn.core.transforms.VariantTransform`</span> -<span class="sd"> or `pysegcnn.core.transforms.InvariantTransform`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - - <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">transforms</span><span class="p">):</span> - <span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">transforms</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">))</span> - <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span> <span class="o">=</span> <span class="n">transforms</span> - - <span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image</span><span class="p">,</span> <span class="n">gt</span><span class="p">):</span> - <span class="sd">"""Apply a sequence of transformations to ``image``.</span> - -<span class="sd"> For each spatially variant transformation, the ground truth ``gt`` is</span> -<span class="sd"> transformed respectively.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> The input image.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The corresponding ground truth of ``image``.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> The transformed image.</span> -<span class="sd"> gt : `numpy.ndarray`</span> -<span class="sd"> The transformed ground truth.</span> - -<span class="sd"> """</span> - <span class="c1"># apply transformations to the input image in specified order</span> - <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span><span class="p">:</span> - <span class="n">image</span> <span class="o">=</span> <span class="n">t</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> - - <span class="c1"># check whether the transformations are invariant and if not, apply</span> - <span class="c1"># the transformation also to the ground truth</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">t</span><span class="o">.</span><span class="n">invariant</span> <span class="ow">and</span> <span class="n">t</span><span class="o">.</span><span class="n">applied</span><span class="p">:</span> - <span class="c1"># get the probability with which the transformation is applied</span> - <span class="n">p</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">p</span> - - <span class="c1"># overwrite the probability to 1, to ensure the same</span> - <span class="c1"># transformation is applied on the ground truth</span> - <span class="n">t</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="mi">1</span> - - <span class="c1"># transform ground truth</span> - <span class="n">gt</span> <span class="o">=</span> <span class="n">t</span><span class="p">(</span><span class="n">gt</span><span class="p">)</span> - - <span class="c1"># reset probability to original value</span> - <span class="n">t</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span> - - <span class="k">return</span> <span class="n">image</span><span class="p">,</span> <span class="n">gt</span> - - <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Representation of `~pysegcnn.core.transforms.Augment`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> repr : `str`</span> -<span class="sd"> Representation string.</span> - -<span class="sd"> """</span> - <span class="n">fstring</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">+</span> <span class="s1">'('</span> - <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span><span class="p">:</span> - <span class="n">fstring</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span> - <span class="n">fstring</span> <span class="o">+=</span> <span class="s1">' </span><span class="si">{0}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> - <span class="n">fstring</span> <span class="o">+=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">)'</span> - <span class="k">return</span> <span class="n">fstring</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/core/utils.html b/docs/_build/html/_modules/core/utils.html deleted file mode 100644 index 7b1803b5f45f93da49115c5fcce7191586238e68..0000000000000000000000000000000000000000 --- a/docs/_build/html/_modules/core/utils.html +++ /dev/null @@ -1,1481 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core.utils — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="../../source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../../source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../index.html">Module code</a> »</li> - - <li>core.utils</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - <h1>Source code for core.utils</h1><div class="highlight"><pre> -<span></span><span class="sd">"""Utility functions mainly for image IO and reshaping.</span> - -<span class="sd">License</span> -<span class="sd">-------</span> - -<span class="sd"> Copyright (c) 2020 Daniel Frisinghelli</span> - -<span class="sd"> This source code is licensed under the GNU General Public License v3.</span> - -<span class="sd"> See the LICENSE file in the repository's root directory.</span> - -<span class="sd">"""</span> - -<span class="c1"># !/usr/bin/env python</span> -<span class="c1"># -*- coding: utf-8 -*-</span> - -<span class="c1"># builtins</span> -<span class="kn">import</span> <span class="nn">os</span> -<span class="kn">import</span> <span class="nn">re</span> -<span class="kn">import</span> <span class="nn">shutil</span> -<span class="kn">import</span> <span class="nn">logging</span> -<span class="kn">import</span> <span class="nn">pathlib</span> -<span class="kn">import</span> <span class="nn">tarfile</span> -<span class="kn">import</span> <span class="nn">zipfile</span> -<span class="kn">import</span> <span class="nn">datetime</span> -<span class="kn">import</span> <span class="nn">warnings</span> - -<span class="c1"># externals</span> -<span class="kn">import</span> <span class="nn">gdal</span> -<span class="kn">import</span> <span class="nn">torch</span> -<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> - -<span class="c1"># module level logger</span> -<span class="n">LOGGER</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> - -<span class="c1"># suffixes for radiometrically calibrated scenes</span> -<span class="n">SUFFIXES</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'toa_ref'</span><span class="p">,</span> <span class="s1">'toa_rad'</span><span class="p">,</span> <span class="s1">'toa_brt'</span><span class="p">]</span> - - -<div class="viewcode-block" id="img2np"><a class="viewcode-back" href="../../source/core.html#core.utils.img2np">[docs]</a><span class="k">def</span> <span class="nf">img2np</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">tile</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">cval</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span> - <span class="sd">"""Read an image to a `numpy.ndarray`.</span> - -<span class="sd"> If ``tile_size`` is not `None`, the input image is divided into square</span> -<span class="sd"> tiles of size (``tile_size``, ``tile_size``). If the image is not evenly</span> -<span class="sd"> divisible and ``pad`` = False, a `ValueError` is raised. However, if</span> -<span class="sd"> ``pad`` = True, center padding with constant value ``cval`` is applied.</span> - -<span class="sd"> The tiling works as follows:</span> - -<span class="sd"> (Padded) Input image:</span> - -<span class="sd"> ------------------------------------------------</span> -<span class="sd"> | | | | |</span> -<span class="sd"> | tile_00 | tile_01 | ... | tile_0n |</span> -<span class="sd"> | | | | |</span> -<span class="sd"> |----------------------------------------------|</span> -<span class="sd"> | | | | |</span> -<span class="sd"> | tile_10 | tile_11 | ... | tile_1n |</span> -<span class="sd"> | | | | |</span> -<span class="sd"> |----------------------------------------------|</span> -<span class="sd"> | | | | |</span> -<span class="sd"> | ... | ... | ... | ... |</span> -<span class="sd"> | | | | |</span> -<span class="sd"> |----------------------------------------------|</span> -<span class="sd"> | | | | |</span> -<span class="sd"> | tile_m0 | tile_m1 | ... | tile_mn |</span> -<span class="sd"> | | | | |</span> -<span class="sd"> ------------------------------------------------</span> - -<span class="sd"> where m = n. Each tile has its id, which starts at 0 in the topleft corner</span> -<span class="sd"> of the input image, i.e. tile_00 has id=0, and increases along the width</span> -<span class="sd"> axis, i.e. tile_0n has id=n, tile_10 has id=n+1, ..., tile_mn has</span> -<span class="sd"> id=(m * n) - 1.</span> - -<span class="sd"> If ``tile`` is an integer, only the tile with id = ``tile`` is returned.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> path : `str` or `None` or `numpy.ndarray`</span> -<span class="sd"> The image to read.</span> -<span class="sd"> tile_size : `None` or `int`, optional</span> -<span class="sd"> The size of a tile. The default is None.</span> -<span class="sd"> tile : `int`, optional</span> -<span class="sd"> The tile id. The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. The default is False.</span> -<span class="sd"> cval : `float`, optional</span> -<span class="sd"> The constant padding value. The default is 0.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> FileNotFoundError</span> -<span class="sd"> Raised if ``path`` is a path that does not exist.</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if ``path`` is not `str` or `None` or `numpy.ndarray`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> The image array. The output shape is:</span> - -<span class="sd"> if ``tile_size`` is not `None`:</span> -<span class="sd"> shape=(tiles, bands, tile_size, tile_size)</span> -<span class="sd"> if the image does only have one band:</span> -<span class="sd"> shape=(tiles, tile_size, tile_size)</span> - -<span class="sd"> else:</span> -<span class="sd"> shape=(bands, height, width)</span> -<span class="sd"> if the image does only have one band:</span> -<span class="sd"> shape=(height, width)</span> - -<span class="sd"> """</span> - <span class="c1"># check the type of path</span> - <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> - <span class="k">if</span> <span class="ow">not</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">path</span><span class="p">):</span> - <span class="k">raise</span> <span class="ne">FileNotFoundError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> does not exist.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> - <span class="c1"># the image dataset as returned by gdal</span> - <span class="n">img</span> <span class="o">=</span> <span class="n">gdal</span><span class="o">.</span><span class="n">Open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> - - <span class="c1"># number of bands</span> - <span class="n">bands</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">RasterCount</span> - - <span class="c1"># spatial size</span> - <span class="n">height</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">RasterYSize</span> - <span class="n">width</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">RasterXSize</span> - - <span class="k">elif</span> <span class="n">path</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">'Path is of NoneType, returning.'</span><span class="p">)</span> - <span class="k">return</span> - - <span class="c1"># accept numpy arrays as input</span> - <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span> - <span class="n">img</span> <span class="o">=</span> <span class="n">path</span> - <span class="n">bands</span> <span class="o">=</span> <span class="n">img</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">height</span> <span class="o">=</span> <span class="n">img</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="n">width</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> - - <span class="k">else</span><span class="p">:</span> - <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'Input of type </span><span class="si">{}</span><span class="s1"> not supported'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">img</span><span class="p">)))</span> - - <span class="c1"># check whether to read the image in tiles</span> - <span class="k">if</span> <span class="n">tile_size</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> - - <span class="c1"># number of tiles</span> - <span class="n">ntiles</span> <span class="o">=</span> <span class="mi">1</span> - - <span class="c1"># create empty numpy array to store whole image</span> - <span class="n">image</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">ntiles</span><span class="p">,</span> <span class="n">bands</span><span class="p">,</span> <span class="n">height</span><span class="p">,</span> <span class="n">width</span><span class="p">))</span> - - <span class="c1"># iterate over the bands of the image</span> - <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">bands</span><span class="p">):</span> - - <span class="c1"># read the data of band b</span> - <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">img</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span> - <span class="n">data</span> <span class="o">=</span> <span class="n">img</span><span class="p">[</span><span class="n">b</span><span class="p">,</span> <span class="o">...</span><span class="p">]</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">band</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">GetRasterBand</span><span class="p">(</span><span class="n">b</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> - <span class="n">data</span> <span class="o">=</span> <span class="n">band</span><span class="o">.</span><span class="n">ReadAsArray</span><span class="p">()</span> - - <span class="c1"># append band b to numpy image array</span> - <span class="n">image</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="p">:,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">data</span> - - <span class="k">else</span><span class="p">:</span> - - <span class="c1"># check whether the image is evenly divisible in square tiles</span> - <span class="c1"># of size (tile_size x tile_size)</span> - <span class="n">ntiles</span><span class="p">,</span> <span class="n">padding</span> <span class="o">=</span> <span class="n">is_divisible</span><span class="p">((</span><span class="n">height</span><span class="p">,</span> <span class="n">width</span><span class="p">),</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="p">)</span> - - <span class="c1"># image size after padding</span> - <span class="n">y_size</span> <span class="o">=</span> <span class="n">height</span> <span class="o">+</span> <span class="n">padding</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">padding</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> - <span class="n">x_size</span> <span class="o">=</span> <span class="n">width</span> <span class="o">+</span> <span class="n">padding</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">padding</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> - - <span class="c1"># print progress</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'Image size: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="n">height</span><span class="p">,</span> <span class="n">width</span><span class="p">)))</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'Dividing image into </span><span class="si">{}</span><span class="s1"> tiles of size </span><span class="si">{}</span><span class="s1"> ...'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ntiles</span><span class="p">,</span> <span class="p">(</span><span class="n">tile_size</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">)))</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'Padding image (b, l, t, r): </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="n">padding</span><span class="p">)))</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'Padded image size: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="n">y_size</span><span class="p">,</span> <span class="n">x_size</span><span class="p">)))</span> - - <span class="c1"># get the indices of the top left corner for each tile</span> - <span class="n">topleft</span> <span class="o">=</span> <span class="n">tile_topleft_corner</span><span class="p">((</span><span class="n">y_size</span><span class="p">,</span> <span class="n">x_size</span><span class="p">),</span> <span class="n">tile_size</span><span class="p">)</span> - - <span class="c1"># whether to read all tiles or a single tile</span> - <span class="k">if</span> <span class="n">tile</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - <span class="n">ntiles</span> <span class="o">=</span> <span class="mi">1</span> - - <span class="c1"># create empty numpy array to store the tiles</span> - <span class="n">image</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="n">ntiles</span><span class="p">,</span> <span class="n">bands</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">))</span> <span class="o">*</span> <span class="n">cval</span> - - <span class="c1"># iterate over the topleft corners of the tiles</span> - <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">corner</span> <span class="ow">in</span> <span class="n">topleft</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> - - <span class="c1"># in case a single tile is required, skip the rest of the tiles</span> - <span class="k">if</span> <span class="n">tile</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> - <span class="k">if</span> <span class="n">k</span> <span class="o">!=</span> <span class="n">tile</span><span class="p">:</span> - <span class="k">continue</span> - - <span class="c1"># set the key to 0 for correct array indexing when reading</span> - <span class="c1"># a single tile from the image</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'Processing tile </span><span class="si">{}</span><span class="s1"> ...'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">))</span> - <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'Creating tile </span><span class="si">{}</span><span class="s1"> with top-left corner </span><span class="si">{}</span><span class="s1"> ...'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">corner</span><span class="p">))</span> - - <span class="c1"># calculate shift between padded and original image</span> - <span class="n">row</span> <span class="o">=</span> <span class="n">corner</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">padding</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">if</span> <span class="n">corner</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">></span> <span class="mi">0</span> <span class="k">else</span> <span class="n">corner</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> - <span class="n">col</span> <span class="o">=</span> <span class="n">corner</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">padding</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="n">corner</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">></span> <span class="mi">0</span> <span class="k">else</span> <span class="n">corner</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> - <span class="n">y_tl</span> <span class="o">=</span> <span class="n">row</span> <span class="o">+</span> <span class="n">padding</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">if</span> <span class="n">row</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span> - <span class="n">x_tl</span> <span class="o">=</span> <span class="n">col</span> <span class="o">+</span> <span class="n">padding</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="n">col</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span> - - <span class="c1"># iterate over the bands of the image</span> - <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">bands</span><span class="p">):</span> - - <span class="c1"># check if the current tile extend exists in the image</span> - <span class="n">nrows</span><span class="p">,</span> <span class="n">ncols</span> <span class="o">=</span> <span class="n">check_tile_extend</span><span class="p">(</span> - <span class="p">(</span><span class="n">height</span><span class="p">,</span> <span class="n">width</span><span class="p">),</span> <span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">col</span><span class="p">),</span> <span class="n">tile_size</span><span class="p">)</span> - - <span class="c1"># read the current tile from band b</span> - <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">img</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span> - <span class="n">data</span> <span class="o">=</span> <span class="n">img</span><span class="p">[</span><span class="n">b</span><span class="p">,</span> <span class="n">row</span><span class="p">:</span><span class="n">row</span><span class="o">+</span><span class="n">nrows</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span><span class="n">col</span><span class="o">+</span><span class="n">ncols</span><span class="p">]</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">band</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">GetRasterBand</span><span class="p">(</span><span class="n">b</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> - <span class="n">data</span> <span class="o">=</span> <span class="n">band</span><span class="o">.</span><span class="n">ReadAsArray</span><span class="p">(</span><span class="n">col</span><span class="p">,</span> <span class="n">row</span><span class="p">,</span> <span class="n">ncols</span><span class="p">,</span> <span class="n">nrows</span><span class="p">)</span> - - <span class="c1"># append band b to numpy image array</span> - <span class="n">image</span><span class="p">[</span><span class="n">k</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">y_tl</span><span class="p">:</span><span class="n">nrows</span><span class="p">,</span> <span class="n">x_tl</span><span class="p">:</span><span class="n">ncols</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">:(</span><span class="n">nrows</span> <span class="o">-</span> <span class="n">y_tl</span><span class="p">),</span> - <span class="mi">0</span><span class="p">:(</span><span class="n">ncols</span> <span class="o">-</span> <span class="n">x_tl</span><span class="p">)]</span> - - <span class="c1"># check if there are more than 1 band</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">bands</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> - <span class="n">image</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> - - <span class="c1"># check if there are more than 1 tile</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">ntiles</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> - <span class="n">image</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> - - <span class="c1"># close tif file</span> - <span class="k">del</span> <span class="n">img</span> - - <span class="c1"># return the image</span> - <span class="k">return</span> <span class="n">image</span></div> - - -<div class="viewcode-block" id="is_divisible"><a class="viewcode-back" href="../../source/core.html#core.utils.is_divisible">[docs]</a><span class="k">def</span> <span class="nf">is_divisible</span><span class="p">(</span><span class="n">img_size</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span> - <span class="sd">"""Check whether an image is evenly divisible into square tiles.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> img_size : `tuple`</span> -<span class="sd"> The image size (height, width).</span> -<span class="sd"> tile_size : `int`</span> -<span class="sd"> The size of the tile.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. The default is False.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> ValueError</span> -<span class="sd"> Raised if the image is not evenly divisible and ``pad`` = False.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> ntiles : `int`</span> -<span class="sd"> The number of tiles fitting ``img_size``.</span> -<span class="sd"> padding : `tuple`</span> -<span class="sd"> The amount of padding (bottom, left, top, right).</span> - -<span class="sd"> """</span> - <span class="c1"># calculate number of pixels per tile</span> - <span class="n">pixels_per_tile</span> <span class="o">=</span> <span class="n">tile_size</span> <span class="o">**</span> <span class="mi">2</span> - - <span class="c1"># check whether the image is evenly divisible in square tiles of size</span> - <span class="c1"># (tile_size, tile_size)</span> - <span class="n">ntiles</span> <span class="o">=</span> <span class="p">((</span><span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="n">pixels_per_tile</span><span class="p">)</span> - - <span class="c1"># if it is evenly divisible, no padding is required</span> - <span class="k">if</span> <span class="n">ntiles</span><span class="o">.</span><span class="n">is_integer</span><span class="p">():</span> - <span class="n">padding</span> <span class="o">=</span> <span class="mi">4</span> <span class="o">*</span> <span class="p">(</span><span class="mi">0</span><span class="p">,)</span> - - <span class="k">if</span> <span class="ow">not</span> <span class="n">ntiles</span><span class="o">.</span><span class="n">is_integer</span><span class="p">()</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">pad</span><span class="p">:</span> - <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'Image of size </span><span class="si">{}</span><span class="s1"> not evenly divisible in (</span><span class="si">{}</span><span class="s1">, </span><span class="si">{}</span><span class="s1">) '</span> - <span class="s1">'tiles.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">img_size</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">))</span> - - <span class="k">if</span> <span class="ow">not</span> <span class="n">ntiles</span><span class="o">.</span><span class="n">is_integer</span><span class="p">()</span> <span class="ow">and</span> <span class="n">pad</span><span class="p">:</span> - - <span class="c1"># calculate the desired image size, i.e. the smallest size that is</span> - <span class="c1"># evenly divisible into square tiles of size (tile_size, tile_size)</span> - <span class="n">h_new</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="n">tile_size</span><span class="p">)</span> <span class="o">*</span> <span class="n">tile_size</span><span class="p">)</span> - <span class="n">w_new</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/</span> <span class="n">tile_size</span><span class="p">)</span> <span class="o">*</span> <span class="n">tile_size</span><span class="p">)</span> - - <span class="c1"># calculate center offset</span> - <span class="n">dh</span> <span class="o">=</span> <span class="n">h_new</span> <span class="o">-</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> - <span class="n">dw</span> <span class="o">=</span> <span class="n">w_new</span> <span class="o">-</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> - - <span class="c1"># check whether the center offsets are even or odd</span> - - <span class="c1"># in case both offsets are even, the padding is symmetric on both the</span> - <span class="c1"># bottom/top and left/right</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">dh</span> <span class="o">%</span> <span class="mi">2</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">dw</span> <span class="o">%</span> <span class="mi">2</span><span class="p">:</span> - <span class="n">padding</span> <span class="o">=</span> <span class="p">(</span><span class="n">dh</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dw</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dh</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dw</span> <span class="o">//</span> <span class="mi">2</span><span class="p">)</span> - - <span class="c1"># in case only one offset is even, the padding is symmetric along the</span> - <span class="c1"># even offset and asymmetric along the odd offset</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">dh</span> <span class="o">%</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">dw</span> <span class="o">%</span> <span class="mi">2</span><span class="p">:</span> - <span class="n">padding</span> <span class="o">=</span> <span class="p">(</span><span class="n">dh</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dw</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dh</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dw</span> <span class="o">//</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> - <span class="k">if</span> <span class="n">dh</span> <span class="o">%</span> <span class="mi">2</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">dw</span> <span class="o">%</span> <span class="mi">2</span><span class="p">:</span> - <span class="n">padding</span> <span class="o">=</span> <span class="p">(</span><span class="n">dh</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dw</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dh</span> <span class="o">//</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">dw</span> <span class="o">//</span> <span class="mi">2</span><span class="p">)</span> - - <span class="c1"># in case of offsets are odd, the padding is asymmetric on both the</span> - <span class="c1"># bottom/top and left/right</span> - <span class="k">if</span> <span class="n">dh</span> <span class="o">%</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">dw</span> <span class="o">%</span> <span class="mi">2</span><span class="p">:</span> - <span class="n">padding</span> <span class="o">=</span> <span class="p">(</span><span class="n">dh</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dw</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span> <span class="n">dh</span> <span class="o">//</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">dw</span> <span class="o">//</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> - - <span class="c1"># calculate number of tiles on padded image</span> - <span class="n">ntiles</span> <span class="o">=</span> <span class="p">(</span><span class="n">h_new</span> <span class="o">*</span> <span class="n">w_new</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">tile_size</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span> - - <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">ntiles</span><span class="p">),</span> <span class="n">padding</span></div> - - -<div class="viewcode-block" id="check_tile_extend"><a class="viewcode-back" href="../../source/core.html#core.utils.check_tile_extend">[docs]</a><span class="k">def</span> <span class="nf">check_tile_extend</span><span class="p">(</span><span class="n">img_size</span><span class="p">,</span> <span class="n">topleft</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">):</span> - <span class="sd">"""Check if a tile exceeds the image size.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> img_size : `tuple`</span> -<span class="sd"> The image size (height, width).</span> -<span class="sd"> topleft : `tuple`</span> -<span class="sd"> The topleft corner of the tile (y, x).</span> -<span class="sd"> tile_size : `int`</span> -<span class="sd"> The size of the tile.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> nrows : `int`</span> -<span class="sd"> Number of rows of the tile within the image.</span> -<span class="sd"> ncols : TYPE</span> -<span class="sd"> Number of columns of the tile within the image.</span> - -<span class="sd"> """</span> - <span class="c1"># check if the tile is within both the rows and the columns of the image</span> - <span class="k">if</span> <span class="p">(</span><span class="n">topleft</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span> <span class="o"><</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">and</span> - <span class="n">topleft</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span> <span class="o"><</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span> - - <span class="c1"># both rows and columns can be equal to the tile size</span> - <span class="n">nrows</span><span class="p">,</span> <span class="n">ncols</span> <span class="o">=</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">tile_size</span> - - <span class="c1"># check if the tile exceeds one of rows or columns of the image</span> - <span class="k">if</span> <span class="p">(</span><span class="n">topleft</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span> <span class="o"><</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">and</span> <span class="ow">not</span> - <span class="n">topleft</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span> <span class="o"><</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span> - - <span class="c1"># adjust columns to remaining columns in the original image</span> - <span class="n">nrows</span><span class="p">,</span> <span class="n">ncols</span> <span class="o">=</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">topleft</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> - - <span class="k">if</span> <span class="p">(</span><span class="n">topleft</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span> <span class="o"><</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">and</span> <span class="ow">not</span> - <span class="n">topleft</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span> <span class="o"><</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span> - - <span class="c1"># adjust rows to remaining rows in the original image</span> - <span class="n">nrows</span><span class="p">,</span> <span class="n">ncols</span> <span class="o">=</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">topleft</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">tile_size</span> - - <span class="c1"># check if the tile exceeds both the rows and the columns of the image</span> - <span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="n">topleft</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span> <span class="o"><</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">and</span> <span class="ow">not</span> - <span class="n">topleft</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span> <span class="o"><</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span> - - <span class="c1"># adjust both rows and columns to the remaining ones</span> - <span class="n">nrows</span><span class="p">,</span> <span class="n">ncols</span> <span class="o">=</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">topleft</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">topleft</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> - - <span class="k">return</span> <span class="n">nrows</span><span class="p">,</span> <span class="n">ncols</span></div> - - -<div class="viewcode-block" id="tile_topleft_corner"><a class="viewcode-back" href="../../source/core.html#core.utils.tile_topleft_corner">[docs]</a><span class="k">def</span> <span class="nf">tile_topleft_corner</span><span class="p">(</span><span class="n">img_size</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">):</span> - <span class="sd">"""Return the topleft corners of the tiles in the image.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> img_size : `tuple`</span> -<span class="sd"> The image size (height, width).</span> -<span class="sd"> tile_size : `int`</span> -<span class="sd"> The size of the tile.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> indices : `dict`</span> -<span class="sd"> The keys of ``indices`` are the tile ids (`int`) and the values are the</span> -<span class="sd"> topleft corners (`tuple` = (y, x)) of the tiles.</span> - -<span class="sd"> """</span> - <span class="c1"># check if the image is divisible into square tiles of size</span> - <span class="c1"># (tile_size, tile_size)</span> - <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">is_divisible</span><span class="p">(</span><span class="n">img_size</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> - - <span class="c1"># number of tiles along the width (columns) of the image</span> - <span class="n">ntiles_columns</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">img_size</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/</span> <span class="n">tile_size</span><span class="p">)</span> - - <span class="c1"># number of tiles along the height (rows) of the image</span> - <span class="n">ntiles_rows</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">img_size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="n">tile_size</span><span class="p">)</span> - - <span class="c1"># get the indices of the top left corner for each tile</span> - <span class="n">indices</span> <span class="o">=</span> <span class="p">{}</span> - <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span> - <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ntiles_rows</span><span class="p">):</span> - <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ntiles_columns</span><span class="p">):</span> - <span class="n">indices</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">i</span> <span class="o">*</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">j</span> <span class="o">*</span> <span class="n">tile_size</span><span class="p">)</span> - <span class="n">k</span> <span class="o">+=</span> <span class="mi">1</span> - - <span class="k">return</span> <span class="n">indices</span></div> - - -<div class="viewcode-block" id="reconstruct_scene"><a class="viewcode-back" href="../../source/core.html#core.utils.reconstruct_scene">[docs]</a><span class="k">def</span> <span class="nf">reconstruct_scene</span><span class="p">(</span><span class="n">tiles</span><span class="p">):</span> - <span class="sd">"""Reconstruct a tiled image.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> tiles : `torch.Tensor` or `numpy.ndarray`</span> -<span class="sd"> The tiled image, shape=(tiles, bands, tile_size, tile_size) or</span> -<span class="sd"> shape=(tiles, tile_size, tile_size).</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> image : `numpy.ndarray`</span> -<span class="sd"> The reconstructed image.</span> - -<span class="sd"> """</span> - <span class="c1"># convert to numpy array</span> - <span class="n">tiles</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">tiles</span><span class="p">)</span> - - <span class="c1"># check the size</span> - <span class="k">if</span> <span class="n">tiles</span><span class="o">.</span><span class="n">ndim</span> <span class="o">></span> <span class="mi">3</span><span class="p">:</span> - <span class="n">nbands</span> <span class="o">=</span> <span class="n">tiles</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="n">tile_size</span> <span class="o">=</span> <span class="n">tiles</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">nbands</span> <span class="o">=</span> <span class="mi">1</span> - <span class="n">tile_size</span> <span class="o">=</span> <span class="n">tiles</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="c1"># calculate image size</span> - <span class="n">img_size</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">tiles</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="o">*</span> <span class="n">tile_size</span><span class="p">),)</span> - - <span class="c1"># calculate the topleft corners of the tiles</span> - <span class="n">topleft</span> <span class="o">=</span> <span class="n">tile_topleft_corner</span><span class="p">(</span><span class="n">img_size</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">)</span> - - <span class="c1"># iterate over the tiles</span> - <span class="n">scene</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">shape</span><span class="o">=</span><span class="p">(</span><span class="n">nbands</span><span class="p">,)</span> <span class="o">+</span> <span class="n">img_size</span><span class="p">)</span> - <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">tiles</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">scene</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> - <span class="n">topleft</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="mi">0</span><span class="p">]:</span> <span class="n">topleft</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span><span class="p">,</span> - <span class="n">topleft</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="mi">1</span><span class="p">]:</span> <span class="n">topleft</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">tile_size</span><span class="p">]</span> <span class="o">=</span> <span class="n">tiles</span><span class="p">[</span><span class="n">t</span><span class="p">,</span> <span class="o">...</span><span class="p">]</span> - - <span class="k">return</span> <span class="n">scene</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span></div> - - -<div class="viewcode-block" id="accuracy_function"><a class="viewcode-back" href="../../source/core.html#core.utils.accuracy_function">[docs]</a><span class="k">def</span> <span class="nf">accuracy_function</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="n">labels</span><span class="p">):</span> - <span class="sd">"""Calculate prediction accuracy.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> outputs : `torch.Tensor` or array_like</span> -<span class="sd"> The model prediction.</span> -<span class="sd"> labels : `torch.Tensor` or array_like</span> -<span class="sd"> The ground truth.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> accuracy : `float`</span> -<span class="sd"> Mean prediction accuracy.</span> - -<span class="sd"> """</span> - <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">):</span> - <span class="k">return</span> <span class="p">(</span><span class="n">outputs</span> <span class="o">==</span> <span class="n">labels</span><span class="p">)</span><span class="o">.</span><span class="n">float</span><span class="p">()</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span><span class="o">.</span><span class="n">item</span><span class="p">()</span> - <span class="k">else</span><span class="p">:</span> - <span class="k">return</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">outputs</span><span class="p">)</span> <span class="o">==</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">labels</span><span class="p">))</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span><span class="o">.</span><span class="n">item</span><span class="p">()</span></div> - - -<div class="viewcode-block" id="parse_landsat_scene"><a class="viewcode-back" href="../../source/core.html#core.utils.parse_landsat_scene">[docs]</a><span class="k">def</span> <span class="nf">parse_landsat_scene</span><span class="p">(</span><span class="n">scene_id</span><span class="p">):</span> - <span class="sd">"""Parse a Landsat scene identifier.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> scene_id : `str`</span> -<span class="sd"> A Landsat scene identifier.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scene : `dict` or `None`</span> -<span class="sd"> A dictionary containing scene metadata. If `None`, ``scene_id`` is not</span> -<span class="sd"> a valid Landsat scene identifier.</span> - -<span class="sd"> """</span> - <span class="c1"># Landsat Collection 1 naming convention in regular expression</span> - <span class="n">sensor</span> <span class="o">=</span> <span class="s1">'L[COTEM]0[1-8]_'</span> - <span class="n">level</span> <span class="o">=</span> <span class="s1">'L[0-9][A-Z][A-Z]_'</span> - <span class="n">swath</span> <span class="o">=</span> <span class="s1">'[0-2][0-9]</span><span class="si">{2}</span><span class="s1">[0-1][0-9]</span><span class="si">{2}</span><span class="s1">_'</span> - <span class="n">date</span> <span class="o">=</span> <span class="s1">'[0-9]</span><span class="si">{4}</span><span class="s1">[0-1][0-9][0-3][0-9]_'</span> - <span class="n">doy</span> <span class="o">=</span> <span class="s1">'[0-9]</span><span class="si">{4}</span><span class="s1">[0-3][0-9]</span><span class="si">{2}</span><span class="s1">'</span> - <span class="n">collection</span> <span class="o">=</span> <span class="s1">'0[0-9]_'</span> - <span class="n">category</span> <span class="o">=</span> <span class="s1">'[A-Z]([A-Z]|[0-9])'</span> - - <span class="c1"># Landsat Collection 1 naming</span> - <span class="n">C1</span> <span class="o">=</span> <span class="p">(</span><span class="n">sensor</span> <span class="o">+</span> <span class="n">level</span> <span class="o">+</span> <span class="n">swath</span> <span class="o">+</span> <span class="n">date</span> <span class="o">+</span> <span class="n">date</span> <span class="o">+</span> <span class="n">collection</span> <span class="o">+</span> <span class="n">category</span><span class="p">)</span> - <span class="n">Landsat_C1</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">C1</span><span class="p">)</span> - - <span class="c1"># Landsat naming convention before Collections</span> - <span class="n">C0</span> <span class="o">=</span> <span class="p">(</span><span class="n">sensor</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'_'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'0'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> <span class="o">+</span> <span class="n">swath</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'_'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> <span class="o">+</span> - <span class="n">doy</span> <span class="o">+</span> <span class="s1">'[A-Z]</span><span class="si">{3}</span><span class="s1">'</span> <span class="o">+</span> <span class="s1">'[0-9]</span><span class="si">{2}</span><span class="s1">'</span><span class="p">)</span> - <span class="n">Landsat_C0</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">C0</span><span class="p">)</span> - - <span class="c1"># mapping from sensor id to sensors</span> - <span class="n">lsensors</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'E'</span><span class="p">:</span> <span class="s1">'Enhanced Thematic Mapper Plus'</span><span class="p">,</span> - <span class="s1">'T'</span><span class="p">:</span> <span class="s1">'Thematic Mapper'</span><span class="p">,</span> - <span class="s1">'M'</span><span class="p">:</span> <span class="s1">'Multispectral Scanner'</span><span class="p">}</span> - <span class="n">l8sensors</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'C'</span><span class="p">:</span> <span class="s1">'Operational Land Imager (OLI) & Thermal Infrared Sensor'</span> - <span class="s1">' (TIRS)'</span><span class="p">,</span> - <span class="s1">'O'</span><span class="p">:</span> <span class="s1">'Operational Land Imager (OLI)'</span><span class="p">,</span> - <span class="s1">'T'</span><span class="p">:</span> <span class="s1">'Thermal Infrared Sensor (TIRS)'</span><span class="p">,</span> - <span class="p">}</span> - - <span class="c1"># whether a scene identifier matches the Landsat naming convention</span> - <span class="n">scene</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">if</span> <span class="n">Landsat_C0</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">):</span> - - <span class="c1"># the match of the regular expression</span> - <span class="n">match</span> <span class="o">=</span> <span class="n">Landsat_C0</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> - - <span class="c1"># the metadata of the scene identifier</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="o">=</span> <span class="n">match</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'satellite'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'Landsat </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">match</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> - <span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="n">match</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">></span> <span class="mi">7</span><span class="p">:</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'sensor'</span><span class="p">]</span> <span class="o">=</span> <span class="n">l8sensors</span><span class="p">[</span><span class="n">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'sensor'</span><span class="p">]</span> <span class="o">=</span> <span class="n">lsensors</span><span class="p">[</span><span class="n">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'path'</span><span class="p">]</span> <span class="o">=</span> <span class="n">match</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">6</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'row'</span><span class="p">]</span> <span class="o">=</span> <span class="n">match</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">9</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">doy2date</span><span class="p">(</span><span class="n">match</span><span class="p">[</span><span class="mi">9</span><span class="p">:</span><span class="mi">13</span><span class="p">],</span> <span class="n">match</span><span class="p">[</span><span class="mi">13</span><span class="p">:</span><span class="mi">16</span><span class="p">])</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'gsi'</span><span class="p">]</span> <span class="o">=</span> <span class="n">match</span><span class="p">[</span><span class="mi">16</span><span class="p">:</span><span class="mi">19</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'version'</span><span class="p">]</span> <span class="o">=</span> <span class="n">match</span><span class="p">[</span><span class="mi">19</span><span class="p">:]</span> - - <span class="k">elif</span> <span class="n">Landsat_C1</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">):</span> - - <span class="c1"># the match of the regular expression</span> - <span class="n">match</span> <span class="o">=</span> <span class="n">Landsat_C1</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> - - <span class="c1"># split scene into respective parts</span> - <span class="n">parts</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'_'</span><span class="p">)</span> - - <span class="c1"># the metadata of the scene identifier</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="o">=</span> <span class="n">match</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'satellite'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'Landsat </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">:])</span> - <span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">3</span><span class="p">])</span> <span class="o">></span> <span class="mi">7</span><span class="p">:</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'sensor'</span><span class="p">]</span> <span class="o">=</span> <span class="n">l8sensors</span><span class="p">[</span><span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]]</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'sensor'</span><span class="p">]</span> <span class="o">=</span> <span class="n">lsensors</span><span class="p">[</span><span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'path'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'row'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">3</span><span class="p">:]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">)</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'collection'</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">5</span><span class="p">])</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'version'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">6</span><span class="p">]</span> - - <span class="k">else</span><span class="p">:</span> - <span class="n">scene</span> <span class="o">=</span> <span class="kc">None</span> - - <span class="k">return</span> <span class="n">scene</span></div> - - -<div class="viewcode-block" id="parse_sentinel2_scene"><a class="viewcode-back" href="../../source/core.html#core.utils.parse_sentinel2_scene">[docs]</a><span class="k">def</span> <span class="nf">parse_sentinel2_scene</span><span class="p">(</span><span class="n">scene_id</span><span class="p">):</span> - <span class="sd">"""Parse a Sentinel-2 scene identifier.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> scene_id : `str`</span> -<span class="sd"> A Sentinel-2 scene identifier.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scene : `dict` or `None`</span> -<span class="sd"> A dictionary containing scene metadata. If `None`, ``scene_id`` is not</span> -<span class="sd"> a valid Sentinel-2 scene identifier.</span> - -<span class="sd"> """</span> - <span class="c1"># Sentinel 2 Level-1C products naming convention after 6th December 2016</span> - <span class="n">mission</span> <span class="o">=</span> <span class="s1">'S2[A-B]_'</span> - <span class="n">level</span> <span class="o">=</span> <span class="s1">'MSIL1C_'</span> - <span class="n">date</span> <span class="o">=</span> <span class="s1">'[0-9]</span><span class="si">{4}</span><span class="s1">[0-1][0-9][0-3][0-9]'</span> - <span class="n">time</span> <span class="o">=</span> <span class="s1">'T[0-2][0-9][0-5][0-9][0-5][0-9]_'</span> - <span class="n">processing</span> <span class="o">=</span> <span class="s1">'N[0-9]</span><span class="si">{4}</span><span class="s1">_'</span> - <span class="n">orbit</span> <span class="o">=</span> <span class="s1">'R[0-1][0-9]</span><span class="si">{2}</span><span class="s1">_'</span> - <span class="n">tile</span> <span class="o">=</span> <span class="s1">'T[0-9]</span><span class="si">{2}</span><span class="s1">[A-Z]</span><span class="si">{3}</span><span class="s1">_'</span> - <span class="n">level_1C</span> <span class="o">=</span> <span class="p">(</span><span class="n">mission</span> <span class="o">+</span> <span class="n">level</span> <span class="o">+</span> <span class="n">date</span> <span class="o">+</span> <span class="n">time</span> <span class="o">+</span> <span class="n">processing</span> <span class="o">+</span> - <span class="n">orbit</span> <span class="o">+</span> <span class="n">tile</span> <span class="o">+</span> <span class="n">date</span> <span class="o">+</span> <span class="n">time</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'_'</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> - <span class="n">S2_L1C_New</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">level_1C</span><span class="p">)</span> - - <span class="c1"># Sentinel 2 Level-1C products naming convention before 6th December 2016</span> - <span class="n">file_class</span> <span class="o">=</span> <span class="s1">'[A-Z]</span><span class="si">{4}</span><span class="s1">_'</span> - <span class="n">file_category</span> <span class="o">=</span> <span class="s1">'[A-Z]</span><span class="si">{3}</span><span class="s1">_'</span> - <span class="n">file_semantic</span> <span class="o">=</span> <span class="s1">'L[0-1]([ABC]|_)_[A-Z]</span><span class="si">{2}</span><span class="s1">_'</span> - <span class="n">site</span> <span class="o">=</span> <span class="s1">'[A-Z_]</span><span class="si">{4}</span><span class="s1">_'</span> - <span class="n">aorbit</span> <span class="o">=</span> <span class="s1">'A[0-9]</span><span class="si">{6}</span><span class="s1">_'</span> - <span class="n">S2_L1C_Old</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">mission</span> <span class="o">+</span> <span class="n">file_class</span> <span class="o">+</span> <span class="n">file_category</span> <span class="o">+</span> - <span class="n">file_semantic</span> <span class="o">+</span> <span class="n">site</span> <span class="o">+</span> <span class="s1">'V'</span> <span class="o">+</span> <span class="n">date</span> <span class="o">+</span> <span class="n">time</span> <span class="o">+</span> <span class="n">aorbit</span> <span class="o">+</span> - <span class="n">tile</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'_'</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> - - <span class="c1"># ProSnow project naming convention</span> - <span class="n">ProSnow</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">tile</span> <span class="o">+</span> <span class="n">date</span> <span class="o">+</span> <span class="n">time</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'_'</span><span class="p">,</span> <span class="s1">''</span><span class="p">))</span> - - <span class="c1"># whether a scene identifier matches the Sentinel naming convention</span> - <span class="n">scene</span> <span class="o">=</span> <span class="p">{}</span> - <span class="k">if</span> <span class="n">S2_L1C_Old</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">):</span> - - <span class="c1"># the match of the regular expression</span> - <span class="n">match</span> <span class="o">=</span> <span class="n">S2_L1C_Old</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> - - <span class="c1"># split scene into respective parts</span> - <span class="n">parts</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'_'</span><span class="p">)</span> - - <span class="c1"># the metadata of the scene identifier</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="o">=</span> <span class="n">match</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'satellite'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'Sentinel </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'file class'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'file category'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'file semantic'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'site'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'orbit'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">6</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span> - <span class="n">parts</span><span class="p">[</span><span class="mi">7</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'T'</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'V'</span><span class="p">,</span> <span class="s1">''</span><span class="p">),</span> <span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">)</span> - - <span class="k">elif</span> <span class="n">S2_L1C_New</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">):</span> - - <span class="c1"># the match of the regular expression</span> - <span class="n">match</span> <span class="o">=</span> <span class="n">S2_L1C_New</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> - - <span class="c1"># split scene into respective parts</span> - <span class="n">parts</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'_'</span><span class="p">)</span> - - <span class="c1"># the metadata of the scene identifier</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="o">=</span> <span class="n">match</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'satellite'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'Sentinel </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'product'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'T'</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> - <span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">)</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'baseline'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'orbit'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'tile'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> - - <span class="k">elif</span> <span class="n">ProSnow</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">):</span> - - <span class="c1"># the match of the regular expression</span> - <span class="n">match</span> <span class="o">=</span> <span class="n">ProSnow</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> - - <span class="c1"># split scene into respective parts</span> - <span class="n">parts</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'_'</span><span class="p">)</span> - - <span class="c1"># the metadata of the scene identifier</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> <span class="o">=</span> <span class="n">match</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'satellite'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'Sentinel 2'</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'tile'</span><span class="p">]</span> <span class="o">=</span> <span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> - <span class="n">scene</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'T'</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> - <span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">)</span> - - <span class="k">else</span><span class="p">:</span> - <span class="n">scene</span> <span class="o">=</span> <span class="kc">None</span> - - <span class="k">return</span> <span class="n">scene</span></div> - - -<div class="viewcode-block" id="doy2date"><a class="viewcode-back" href="../../source/core.html#core.utils.doy2date">[docs]</a><span class="k">def</span> <span class="nf">doy2date</span><span class="p">(</span><span class="n">year</span><span class="p">,</span> <span class="n">doy</span><span class="p">):</span> - <span class="sd">"""Convert the (year, day of the year) date format to a datetime object.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> year : `int`</span> -<span class="sd"> The year</span> -<span class="sd"> doy : `int`</span> -<span class="sd"> The day of the year</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> date : `datetime.datetime`</span> -<span class="sd"> The converted date.</span> -<span class="sd"> """</span> - <span class="c1"># convert year/day of year to a datetime object</span> - <span class="n">date</span> <span class="o">=</span> <span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">year</span><span class="p">),</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> - <span class="n">datetime</span><span class="o">.</span><span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">doy</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)))</span> - - <span class="k">return</span> <span class="n">date</span></div> - - -<div class="viewcode-block" id="item_in_enum"><a class="viewcode-back" href="../../source/core.html#core.utils.item_in_enum">[docs]</a><span class="k">def</span> <span class="nf">item_in_enum</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">enum</span><span class="p">):</span> - <span class="sd">"""Check if an item exists in an enumeration.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> name : `str`</span> -<span class="sd"> Name of the item.</span> -<span class="sd"> enum : `enum.Enum`</span> -<span class="sd"> An instance of `enum.Enum`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> ValueError</span> -<span class="sd"> Raised if ``name`` is not in ``enum``.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> value</span> -<span class="sd"> The value of ``name`` in ``enum``.</span> - -<span class="sd"> """</span> - <span class="c1"># check whether the input name exists in the enumeration</span> - <span class="k">if</span> <span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">enum</span><span class="o">.</span><span class="n">__members__</span><span class="p">:</span> - <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> is not in </span><span class="si">{}</span><span class="s1"> enumeration. Valid names are: </span><span class="se">\n</span><span class="s1"> </span><span class="si">{}</span><span class="s1">'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">enum</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> - <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">'- </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> - <span class="n">enum</span><span class="o">.</span><span class="n">__members__</span><span class="p">)))</span> - <span class="k">else</span><span class="p">:</span> - <span class="k">return</span> <span class="n">enum</span><span class="o">.</span><span class="n">__members__</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">value</span></div> - - -<div class="viewcode-block" id="destack_tiff"><a class="viewcode-back" href="../../source/core.html#core.utils.destack_tiff">[docs]</a><span class="k">def</span> <span class="nf">destack_tiff</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">outpath</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">remove</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">suffix</span><span class="o">=</span><span class="s1">''</span><span class="p">):</span> - <span class="sd">"""Destack a TIFF with more than one band into a TIFF file for each band.</span> - -<span class="sd"> Each band in ``image`` is saved to ``outpath`` as distinct TIFF file.</span> -<span class="sd"> The default filenames are: "filename(``image``) + _B(i).tif", where i is</span> -<span class="sd"> the respective number of each band in ``image``.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> image : `str` or `pathlib.Path`</span> -<span class="sd"> The TIFF to destack.</span> -<span class="sd"> outpath : `str`, optional</span> -<span class="sd"> Path to save the output TIFF files. The default is None. If None,</span> -<span class="sd"> ``outpath`` is the path to ``image``.</span> -<span class="sd"> remove : `bool`, optional</span> -<span class="sd"> Whether to remove ``image`` from disk after destacking. The default is</span> -<span class="sd"> False.</span> -<span class="sd"> overwrite : `bool`, optional</span> -<span class="sd"> Whether to overwrite existing TIFF files.</span> -<span class="sd"> suffix : `str`, optional</span> -<span class="sd"> String to append to the filename of ``image``. If specified, the TIFF</span> -<span class="sd"> filenames for each band in ``image`` are, "filename(``image``) +</span> -<span class="sd"> + _B(i)_ + ``suffix``.tif". The default is ''.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> FileNotFoundError</span> -<span class="sd"> Raised if ``image`` does not exist.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="c1"># stop gdal printing warnings and errors to STDERR</span> - <span class="n">gdal</span><span class="o">.</span><span class="n">PushErrorHandler</span><span class="p">(</span><span class="s1">'CPLQuietErrorHandler'</span><span class="p">)</span> - - <span class="c1"># raise Python exceptions for gdal errors</span> - <span class="n">gdal</span><span class="o">.</span><span class="n">UseExceptions</span><span class="p">()</span> - - <span class="c1"># convert to pathlib.Path</span> - <span class="n">image</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">image</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="k">raise</span> <span class="ne">FileNotFoundError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> does not exist.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">image</span><span class="p">))</span> - - <span class="c1"># name of the TIFF</span> - <span class="n">imgname</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">stem</span> - - <span class="c1"># default: output directory is equal to the input directory</span> - <span class="k">if</span> <span class="n">outpath</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> - <span class="n">outpath</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">parent</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">outpath</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">outpath</span><span class="p">)</span> - <span class="c1"># check if output directory exists</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">outpath</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="n">outpath</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - - <span class="c1"># open the TIFF</span> - <span class="n">img</span> <span class="o">=</span> <span class="n">gdal</span><span class="o">.</span><span class="n">Open</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">image</span><span class="p">))</span> - - <span class="c1"># check whether the file was already processed</span> - <span class="n">processed</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">outpath</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">imgname</span> <span class="o">+</span> <span class="s1">'_B*'</span><span class="p">))</span> - <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">processed</span><span class="p">)</span> <span class="o">>=</span> <span class="n">img</span><span class="o">.</span><span class="n">RasterCount</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">overwrite</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> already processed.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">imgname</span><span class="p">))</span> - - <span class="c1"># destack the TIFF</span> - <span class="k">else</span><span class="p">:</span> - <span class="c1"># image driver</span> - <span class="n">driver</span> <span class="o">=</span> <span class="n">gdal</span><span class="o">.</span><span class="n">GetDriverByName</span><span class="p">(</span><span class="s1">'GTiff'</span><span class="p">)</span> - <span class="n">driver</span><span class="o">.</span><span class="n">Register</span><span class="p">()</span> - - <span class="c1"># image size and tiles</span> - <span class="n">cols</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">RasterXSize</span> - <span class="n">rows</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">RasterYSize</span> - <span class="n">bands</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">RasterCount</span> - - <span class="c1"># print progress</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Processing: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">imgname</span><span class="p">))</span> - - <span class="c1"># iterate the bands of the raster</span> - <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">bands</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span> - - <span class="c1"># read the data of band b</span> - <span class="n">band</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">GetRasterBand</span><span class="p">(</span><span class="n">b</span><span class="p">)</span> - <span class="n">data</span> <span class="o">=</span> <span class="n">band</span><span class="o">.</span><span class="n">ReadAsArray</span><span class="p">()</span> - - <span class="c1"># output file: replace for band name</span> - <span class="n">fname</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">outpath</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="n">imgname</span> <span class="o">+</span> <span class="s1">'_B</span><span class="si">{:d}</span><span class="s1">.tif'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">b</span><span class="p">)))</span> - <span class="k">if</span> <span class="n">suffix</span><span class="p">:</span> - <span class="n">fname</span> <span class="o">=</span> <span class="n">fname</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'.tif'</span><span class="p">,</span> <span class="s1">'_</span><span class="si">{}</span><span class="s1">.tif'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">suffix</span><span class="p">))</span> - <span class="n">outDs</span> <span class="o">=</span> <span class="n">driver</span><span class="o">.</span><span class="n">Create</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">cols</span><span class="p">,</span> <span class="n">rows</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">band</span><span class="o">.</span><span class="n">DataType</span><span class="p">)</span> - - <span class="c1"># define output band</span> - <span class="n">outband</span> <span class="o">=</span> <span class="n">outDs</span><span class="o">.</span><span class="n">GetRasterBand</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> - - <span class="c1"># write array to output band</span> - <span class="n">outband</span><span class="o">.</span><span class="n">WriteArray</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> - <span class="n">outband</span><span class="o">.</span><span class="n">FlushCache</span><span class="p">()</span> - - <span class="c1"># Set the geographic information</span> - <span class="n">outDs</span><span class="o">.</span><span class="n">SetProjection</span><span class="p">(</span><span class="n">img</span><span class="o">.</span><span class="n">GetProjection</span><span class="p">())</span> - <span class="n">outDs</span><span class="o">.</span><span class="n">SetGeoTransform</span><span class="p">(</span><span class="n">img</span><span class="o">.</span><span class="n">GetGeoTransform</span><span class="p">())</span> - - <span class="c1"># clear memory</span> - <span class="k">del</span> <span class="n">outband</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">outDs</span> - - <span class="c1"># remove old stacked GeoTIFF</span> - <span class="k">del</span> <span class="n">img</span> - <span class="k">if</span> <span class="n">remove</span><span class="p">:</span> - <span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">image</span><span class="p">)</span> - <span class="k">return</span></div> - - -<div class="viewcode-block" id="standard_eo_structure"><a class="viewcode-back" href="../../source/core.html#core.utils.standard_eo_structure">[docs]</a><span class="k">def</span> <span class="nf">standard_eo_structure</span><span class="p">(</span><span class="n">source_path</span><span class="p">,</span> <span class="n">target_path</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">move</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">parser</span><span class="o">=</span><span class="n">parse_landsat_scene</span><span class="p">):</span> - <span class="sd">"""Modify the directory structure of a remote sensing dataset.</span> - -<span class="sd"> This function assumes that ``source_path`` points to a directory containing</span> -<span class="sd"> remote sensing data, where each file in ``source_path`` and its sub-folders</span> -<span class="sd"> should contain a scene identifier in its filename. The scene identifier is</span> -<span class="sd"> used to restructure the dataset.</span> - -<span class="sd"> Currently, Landsat and Sentinel-2 datasets are supported.</span> - -<span class="sd"> The directory tree in ``source_path`` is modified to the following</span> -<span class="sd"> structure in ``target_path``:</span> - -<span class="sd"> target_path/</span> -<span class="sd"> scene_id_1/</span> -<span class="sd"> files matching scene_id_1</span> -<span class="sd"> scene_id_2/</span> -<span class="sd"> files matching scene_id_2</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> scene_id_n/</span> -<span class="sd"> files matching scene_id_n</span> - - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> source_path : `str` or `pathlib.Path`</span> -<span class="sd"> Path to the remote sensing dataset.</span> -<span class="sd"> target_path : `str` or `pathlib.Path`</span> -<span class="sd"> Path to save the restructured dataset.</span> -<span class="sd"> overwrite : `bool`, optional</span> -<span class="sd"> Whether to overwrite existing files in ``target_path``.</span> -<span class="sd"> The default is True.</span> -<span class="sd"> move : `bool`, optional</span> -<span class="sd"> Whether to move the files from ``source_path`` to ``target_path``. If</span> -<span class="sd"> True, files in ``source_path`` are moved to ``target_path``, if False,</span> -<span class="sd"> files in ``source_path`` are copied to ``target_path``. The default is</span> -<span class="sd"> False.</span> -<span class="sd"> parser : `function`, optional</span> -<span class="sd"> The scene identifier parsing function. Depends on the sensor of the</span> -<span class="sd"> dataset. See e.g., `pysegcnn.core.utils.parse_landsat_scene`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> - <span class="c1"># create a directory for each scene</span> - <span class="k">for</span> <span class="n">dirpath</span><span class="p">,</span> <span class="n">dirnames</span><span class="p">,</span> <span class="n">filenames</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">source_path</span><span class="p">):</span> - - <span class="c1"># check if there are files in the current folder</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">filenames</span><span class="p">:</span> - <span class="k">continue</span> - - <span class="c1"># iterate over the files to modify</span> - <span class="k">for</span> <span class="n">file</span> <span class="ow">in</span> <span class="n">filenames</span><span class="p">:</span> - - <span class="c1"># get the path to the file</span> - <span class="n">old_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="n">dirpath</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span> - - <span class="c1"># get name of the scene</span> - <span class="n">scene</span> <span class="o">=</span> <span class="n">parser</span><span class="p">(</span><span class="n">old_path</span><span class="p">)</span> - <span class="k">if</span> <span class="n">scene</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> - - <span class="c1"># path to copy files not matching a scene identifier</span> - <span class="n">new_path</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">target_path</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'misc'</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span> - - <span class="c1"># file a warning if the file does not match a scene identifier</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> does not match a scene identifier. Copying '</span> - <span class="s1">'to </span><span class="si">{}</span><span class="s1">.'</span><span class="o">.</span><span class="n">format</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">basename</span><span class="p">(</span><span class="n">old_path</span><span class="p">),</span> - <span class="n">new_path</span><span class="o">.</span><span class="n">parent</span><span class="p">))</span> - <span class="k">else</span><span class="p">:</span> - - <span class="c1"># the name of the scene</span> - <span class="n">scene_name</span> <span class="o">=</span> <span class="n">scene</span><span class="p">[</span><span class="s1">'id'</span><span class="p">]</span> - - <span class="c1"># define the new path to the file</span> - <span class="n">new_path</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">target_path</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="n">scene_name</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span> - - <span class="c1"># move files to new directory</span> - <span class="k">if</span> <span class="n">new_path</span><span class="o">.</span><span class="n">is_file</span><span class="p">()</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">overwrite</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> already exists.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">new_path</span><span class="p">))</span> - <span class="k">continue</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">new_path</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - <span class="k">if</span> <span class="n">move</span><span class="p">:</span> - <span class="n">shutil</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">old_path</span><span class="p">,</span> <span class="n">new_path</span><span class="p">)</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'mv </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">new_path</span><span class="p">))</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'cp </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">new_path</span><span class="p">))</span> - <span class="n">shutil</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">old_path</span><span class="p">,</span> <span class="n">new_path</span><span class="p">)</span> - - <span class="c1"># remove old file location</span> - <span class="k">if</span> <span class="n">move</span><span class="p">:</span> - <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">source_path</span><span class="p">)</span></div> - - -<div class="viewcode-block" id="extract_archive"><a class="viewcode-back" href="../../source/core.html#core.utils.extract_archive">[docs]</a><span class="k">def</span> <span class="nf">extract_archive</span><span class="p">(</span><span class="n">inpath</span><span class="p">,</span> <span class="n">outpath</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span> - <span class="sd">"""Extract files from an archive.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> inpath : `str` or `pathlib.Path`</span> -<span class="sd"> Path to an archive.</span> -<span class="sd"> outpath : `str` or `pathlib.Path`</span> -<span class="sd"> Path to save extracted files.</span> -<span class="sd"> overwrite : `bool`, optional</span> -<span class="sd"> Whether to overwrite existing extracted files.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> subdir : str</span> -<span class="sd"> path to the extracted files</span> -<span class="sd"> """</span> - <span class="n">inpath</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">inpath</span><span class="p">)</span> - - <span class="c1"># create the output directory</span> - <span class="n">outpath</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">outpath</span><span class="p">)</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">outpath</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="n">outpath</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - - <span class="c1"># name of the archive</span> - <span class="n">archive</span> <span class="o">=</span> <span class="n">inpath</span><span class="o">.</span><span class="n">stem</span> - - <span class="c1"># path to the extracted files</span> - <span class="n">target</span> <span class="o">=</span> <span class="n">outpath</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="n">archive</span><span class="p">)</span> - <span class="k">if</span> <span class="n">target</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="k">if</span> <span class="n">overwrite</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Overwriting: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">target</span><span class="p">))</span> - <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">target</span><span class="p">)</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Extracted files are located in: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">target</span><span class="p">))</span> - <span class="k">return</span> <span class="n">target</span> - - <span class="c1"># create output directory</span> - <span class="n">target</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - - <span class="c1"># read the archive</span> - <span class="k">if</span> <span class="n">inpath</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">'.tgz'</span><span class="p">)</span> <span class="ow">or</span> <span class="n">inpath</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">'.tar.gz'</span><span class="p">):</span> - <span class="n">tar</span> <span class="o">=</span> <span class="n">tarfile</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">inpath</span><span class="p">,</span> <span class="s2">"r:gz"</span><span class="p">)</span> - <span class="k">elif</span> <span class="n">inpath</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">'.zip'</span><span class="p">):</span> - <span class="n">tar</span> <span class="o">=</span> <span class="n">zipfile</span><span class="o">.</span><span class="n">ZipFile</span><span class="p">(</span><span class="n">inpath</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span> - - <span class="c1"># extract files to the output directory</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Extracting: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">archive</span><span class="p">))</span> - <span class="n">tar</span><span class="o">.</span><span class="n">extractall</span><span class="p">(</span><span class="n">target</span><span class="p">)</span> - - <span class="k">return</span> <span class="n">target</span></div> - - -<div class="viewcode-block" id="read_landsat_metadata"><a class="viewcode-back" href="../../source/core.html#core.utils.read_landsat_metadata">[docs]</a><span class="k">def</span> <span class="nf">read_landsat_metadata</span><span class="p">(</span><span class="n">file</span><span class="p">):</span> - <span class="sd">"""Parse the Landsat metadata *_MTL.txt file.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> file : `str` or `pathlib.Path`</span> -<span class="sd"> Path to a Landsat *_MTL.txt file.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> FileNotFoundError</span> -<span class="sd"> Raised if ``file`` does not exist.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> metadata : `dict`</span> -<span class="sd"> The metadata text file as dictionary, where each line is a (key, value)</span> -<span class="sd"> pair.</span> -<span class="sd"> """</span> - <span class="n">file</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">file</span><span class="p">)</span> - <span class="c1"># check if the metadata file exists</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">file</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="k">raise</span> <span class="ne">FileNotFoundError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> does not exist'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">file</span><span class="p">))</span> - - <span class="c1"># read metadata file</span> - <span class="n">metadata</span> <span class="o">=</span> <span class="p">{}</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Parsing metadata file: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">file</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> - <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span> <span class="k">as</span> <span class="n">metafile</span><span class="p">:</span> - <span class="c1"># iterate over the lines of the metadata file</span> - <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">metafile</span><span class="p">:</span> - <span class="k">try</span><span class="p">:</span> - <span class="c1"># the current line as (key, value pair)</span> - <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'='</span><span class="p">)</span> - - <span class="c1"># store current line in dictionary: skip lines defining the</span> - <span class="c1"># parameter groups</span> - <span class="k">if</span> <span class="s1">'GROUP'</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">key</span><span class="p">:</span> - <span class="n">metadata</span><span class="p">[</span><span class="n">key</span><span class="o">.</span><span class="n">strip</span><span class="p">()]</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> - - <span class="c1"># catch value error of line.split('='), i.e. if there is no '='</span> - <span class="c1"># sign in the current line</span> - <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> - <span class="k">continue</span> - - <span class="k">return</span> <span class="n">metadata</span></div> - - -<div class="viewcode-block" id="get_radiometric_constants"><a class="viewcode-back" href="../../source/core.html#core.utils.get_radiometric_constants">[docs]</a><span class="k">def</span> <span class="nf">get_radiometric_constants</span><span class="p">(</span><span class="n">metadata</span><span class="p">):</span> - <span class="sd">"""Retrieve the radiometric calibration constants.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> metadata : `dict`</span> -<span class="sd"> The dictionary returned by ``read_landsat_metadata``.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> oli : `dict`</span> -<span class="sd"> Radiometric rescaling factors of the OLI sensor.</span> -<span class="sd"> tir : `dict`</span> -<span class="sd"> Thermal conversion constants of the TIRS sensor.</span> -<span class="sd"> """</span> - <span class="c1"># regular expression patterns matching the radiometric rescaling factors</span> - <span class="n">oli_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">'(RADIANCE|REFLECTANCE)_(MULT|ADD)_BAND_</span><span class="se">\\</span><span class="s1">d{1,2}'</span><span class="p">)</span> - <span class="n">tir_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">'K(1|2)_CONSTANT_BAND_</span><span class="se">\\</span><span class="s1">d</span><span class="si">{2}</span><span class="s1">'</span><span class="p">)</span> - - <span class="c1"># rescaling factors to calculate top of atmosphere radiance and reflectance</span> - <span class="n">oli</span> <span class="o">=</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">metadata</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> - <span class="n">oli_pattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">}</span> - - <span class="c1"># rescaling factors to calculate at-satellite temperatures in Kelvin</span> - <span class="n">tir</span> <span class="o">=</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">metadata</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> - <span class="n">tir_pattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">}</span> - - <span class="k">return</span> <span class="n">oli</span><span class="p">,</span> <span class="n">tir</span></div> - - -<div class="viewcode-block" id="landsat_radiometric_calibration"><a class="viewcode-back" href="../../source/core.html#core.utils.landsat_radiometric_calibration">[docs]</a><span class="k">def</span> <span class="nf">landsat_radiometric_calibration</span><span class="p">(</span><span class="n">scene</span><span class="p">,</span> <span class="n">outpath</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">[],</span> - <span class="n">radiance</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> - <span class="n">remove_raw</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span> - <span class="sd">"""Radiometric calibration of Landsat Collection Level 1 scenes.</span> - -<span class="sd"> Convert the Landsat OLI bands to top of atmosphere radiance or reflectance</span> -<span class="sd"> and the TIRS bands to top of atmosphere brightness temperature.</span> - -<span class="sd"> Conversion is performed following the `equations`_ provided by the USGS.</span> - -<span class="sd"> The filename of each band is extended by one of the following suffixes,</span> -<span class="sd"> depending on the type of the radiometric calibration:</span> - -<span class="sd"> 'toa_ref': top of atmosphere reflectance</span> -<span class="sd"> 'toa_rad': top of atmopshere radiance</span> -<span class="sd"> 'toa_brt': top of atmosphere brightness temperature</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> scene : `str` or `pathlib.Path`</span> -<span class="sd"> Path to a Landsat scene in digital number format.</span> -<span class="sd"> outpath : `str` or `pathlib.Path`, optional</span> -<span class="sd"> Path to save the calibrated images. The default is None, which means</span> -<span class="sd"> saving to ``scene``.</span> -<span class="sd"> exclude : `list` [`str`], optional</span> -<span class="sd"> Bands to exclude from the radiometric calibration. The default is [].</span> -<span class="sd"> radiance : `bool`, optional</span> -<span class="sd"> Whether to calculate top of atmosphere radiance. The default is False,</span> -<span class="sd"> which means calculating top of atmopshere reflectance.</span> -<span class="sd"> overwrite : `bool`, optional</span> -<span class="sd"> Whether to overwrite the calibrated images. The default is False.</span> -<span class="sd"> remove_raw : `bool`, optional</span> -<span class="sd"> Whether to remove the raw digitial number images. The default is True.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> FileNotFoundError</span> -<span class="sd"> Raised if ``scene`` does not exist.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> .. _equations:</span> -<span class="sd"> https://www.usgs.gov/land-resources/nli/landsat/using-usgs-landsat-level-1-data-product</span> - -<span class="sd"> """</span> - <span class="n">scene</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">scene</span><span class="p">)</span> - <span class="c1"># check if the input scene exists</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">scene</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="k">raise</span> <span class="ne">FileNotFoundError</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> does not exist.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">scene</span><span class="p">))</span> - - <span class="c1"># default: output directory is equal to the input directory</span> - <span class="k">if</span> <span class="n">outpath</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> - <span class="n">outpath</span> <span class="o">=</span> <span class="n">scene</span> - <span class="k">else</span><span class="p">:</span> - <span class="n">outpath</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">outpath</span><span class="p">)</span> - <span class="c1"># check if output directory exists</span> - <span class="k">if</span> <span class="ow">not</span> <span class="n">outpath</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span> - <span class="n">outpath</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> - - <span class="c1"># the scene metadata file</span> - <span class="k">try</span><span class="p">:</span> - <span class="n">mpattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">'[mMtTlL].txt'</span><span class="p">)</span> - <span class="n">metafile</span> <span class="o">=</span> <span class="p">[</span><span class="n">f</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">scene</span><span class="o">.</span><span class="n">iterdir</span><span class="p">()</span> <span class="k">if</span> <span class="n">mpattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">f</span><span class="p">))]</span> - <span class="n">metadata</span> <span class="o">=</span> <span class="n">read_landsat_metadata</span><span class="p">(</span><span class="n">metafile</span><span class="o">.</span><span class="n">pop</span><span class="p">())</span> - <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">'Can not calibrate scene </span><span class="si">{}</span><span class="s1">: </span><span class="si">{}</span><span class="s1"> does not exist.'</span> - <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">scene</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">scene</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s1">'_MTL.txt'</span><span class="p">))</span> - <span class="k">return</span> - - <span class="c1"># radiometric calibration constants</span> - <span class="n">oli</span><span class="p">,</span> <span class="n">tir</span> <span class="o">=</span> <span class="n">get_radiometric_constants</span><span class="p">(</span><span class="n">metadata</span><span class="p">)</span> - - <span class="c1"># log current Landsat scene ID</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Landsat scene id: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">metadata</span><span class="p">[</span><span class="s1">'LANDSAT_SCENE_ID'</span><span class="p">]))</span> - - <span class="c1"># images to process</span> - <span class="n">ipattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">'B</span><span class="se">\\</span><span class="s1">d{1,2}(.*)</span><span class="se">\\</span><span class="s1">.[tT][iI][fF]'</span><span class="p">)</span> - <span class="n">images</span> <span class="o">=</span> <span class="p">[</span><span class="n">file</span> <span class="k">for</span> <span class="n">file</span> <span class="ow">in</span> <span class="n">scene</span><span class="o">.</span><span class="n">iterdir</span><span class="p">()</span> <span class="k">if</span> <span class="n">ipattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">file</span><span class="p">))]</span> - - <span class="c1"># pattern to match calibrated images</span> - <span class="n">cal_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">'(</span><span class="si">{}</span><span class="s1">|</span><span class="si">{}</span><span class="s1">|</span><span class="si">{}</span><span class="s1">).[tT][iI][fF]'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">*</span><span class="n">SUFFIXES</span><span class="p">))</span> - - <span class="c1"># check if any images were already processe</span> - <span class="n">processed</span> <span class="o">=</span> <span class="p">[</span><span class="n">file</span> <span class="k">for</span> <span class="n">file</span> <span class="ow">in</span> <span class="n">images</span> <span class="k">if</span> <span class="n">cal_pattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">file</span><span class="p">))]</span> - <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">processed</span><span class="p">):</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'The following images have already been processed:'</span><span class="p">)</span> - - <span class="c1"># images that were already processed</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">((</span><span class="s1">'</span><span class="se">\n</span><span class="s1"> '</span> <span class="o">+</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="s1">' '</span><span class="p">)</span><span class="o">.</span><span class="n">join</span><span class="p">(</span> - <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">file</span><span class="o">.</span><span class="n">name</span><span class="p">)</span> <span class="k">for</span> <span class="n">file</span> <span class="ow">in</span> <span class="n">processed</span><span class="p">]))</span> - - <span class="c1"># overwrite: remove processed images and redo calibration</span> - <span class="k">if</span> <span class="n">overwrite</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Preparing to overwrite ...'</span><span class="p">)</span> - - <span class="c1"># remove processed images</span> - <span class="k">for</span> <span class="n">toremove</span> <span class="ow">in</span> <span class="n">processed</span><span class="p">:</span> - <span class="c1"># remove from disk</span> - <span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">toremove</span><span class="p">)</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'rm </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">toremove</span><span class="p">))</span> - - <span class="c1"># remove from list to process</span> - <span class="n">images</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">toremove</span><span class="p">)</span> - - <span class="c1"># not overwriting, terminate calibration</span> - <span class="k">else</span><span class="p">:</span> - <span class="k">return</span> - - <span class="c1"># exclude defined bands from the calibration procedure</span> - <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">images</span><span class="p">:</span> - <span class="n">current_band</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s1">'B</span><span class="se">\\</span><span class="s1">d{1,2}'</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span> - <span class="k">if</span> <span class="n">current_band</span> <span class="ow">in</span> <span class="n">exclude</span><span class="p">:</span> - <span class="n">images</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> - - <span class="c1"># image driver</span> - <span class="n">driver</span> <span class="o">=</span> <span class="n">gdal</span><span class="o">.</span><span class="n">GetDriverByName</span><span class="p">(</span><span class="s1">'GTiff'</span><span class="p">)</span> - <span class="n">driver</span><span class="o">.</span><span class="n">Register</span><span class="p">()</span> - - <span class="c1"># iterate over the different bands</span> - <span class="k">for</span> <span class="n">image</span> <span class="ow">in</span> <span class="n">images</span><span class="p">:</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'Processing: </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> - - <span class="c1"># read the image</span> - <span class="n">img</span> <span class="o">=</span> <span class="n">gdal</span><span class="o">.</span><span class="n">Open</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">image</span><span class="p">))</span> - <span class="n">band</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">GetRasterBand</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> - - <span class="c1"># read data as array</span> - <span class="n">data</span> <span class="o">=</span> <span class="n">band</span><span class="o">.</span><span class="n">ReadAsArray</span><span class="p">()</span> - - <span class="c1"># mask of erroneous values, i.e. mask of values < 0</span> - <span class="n">mask</span> <span class="o">=</span> <span class="n">data</span> <span class="o"><</span> <span class="mi">0</span> - - <span class="c1"># output filename</span> - <span class="n">fname</span> <span class="o">=</span> <span class="n">outpath</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">stem</span><span class="p">)</span> - - <span class="c1"># get the current band</span> - <span class="n">band</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s1">'B</span><span class="se">\\</span><span class="s1">d{1,2}'</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">image</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'B'</span><span class="p">,</span> <span class="s1">'BAND_'</span><span class="p">)</span> - - <span class="c1"># check if the current band is a thermal band</span> - <span class="k">if</span> <span class="n">band</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">'BAND_10'</span><span class="p">,</span> <span class="s1">'BAND_11'</span><span class="p">]:</span> - - <span class="c1"># output file name for TIRS bands</span> - <span class="n">fname</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">fname</span><span class="p">)</span> <span class="o">+</span> <span class="s1">'_toa_brt.tif'</span><span class="p">)</span> - - <span class="c1"># calculate top of atmosphere brightness temperature</span> - <span class="k">with</span> <span class="n">warnings</span><span class="o">.</span><span class="n">catch_warnings</span><span class="p">():</span> - <span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="s2">"ignore"</span><span class="p">,</span> <span class="n">category</span><span class="o">=</span><span class="ne">RuntimeWarning</span><span class="p">)</span> - - <span class="c1"># top of atmosphere radiance</span> - <span class="n">rad</span> <span class="o">=</span> <span class="p">(</span><span class="n">oli</span><span class="p">[</span><span class="s1">'RADIANCE_MULT_</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">band</span><span class="p">)]</span> <span class="o">*</span> <span class="n">data</span> <span class="o">+</span> - <span class="n">oli</span><span class="p">[</span><span class="s1">'RADIANCE_ADD_</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">band</span><span class="p">)])</span> - - <span class="c1"># top of atmosphere brightness temperature</span> - <span class="n">den</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">tir</span><span class="p">[</span><span class="s1">'K1_CONSTANT_</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">band</span><span class="p">)]</span> <span class="o">/</span> <span class="n">rad</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> - <span class="n">toa</span> <span class="o">=</span> <span class="n">tir</span><span class="p">[</span><span class="s1">'K2_CONSTANT_</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">band</span><span class="p">)]</span> <span class="o">/</span> <span class="n">den</span> - - <span class="c1"># clear memory</span> - <span class="k">del</span> <span class="n">den</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">rad</span> - <span class="k">else</span><span class="p">:</span> - - <span class="c1"># whether to calculate top of atmosphere radiance or reflectance</span> - <span class="k">if</span> <span class="n">radiance</span><span class="p">:</span> - - <span class="c1"># output file name for OLI bands: radiance</span> - <span class="n">fname</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">fname</span><span class="p">)</span> <span class="o">+</span> <span class="s1">'_toa_rad.tif'</span><span class="p">)</span> - - <span class="c1"># calculate top of atmosphere radiance</span> - <span class="n">toa</span> <span class="o">=</span> <span class="p">(</span><span class="n">oli</span><span class="p">[</span><span class="s1">'RADIANCE_MULT_</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">band</span><span class="p">)]</span> <span class="o">*</span> <span class="n">data</span> <span class="o">+</span> - <span class="n">oli</span><span class="p">[</span><span class="s1">'RADIANCE_ADD_</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">band</span><span class="p">)])</span> - - <span class="c1"># clear memory</span> - <span class="k">del</span> <span class="n">data</span> - - <span class="k">else</span><span class="p">:</span> - - <span class="c1"># output file name for OLI bands: reflectance</span> - <span class="n">fname</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">fname</span><span class="p">)</span> <span class="o">+</span> <span class="s1">'_toa_ref.tif'</span><span class="p">)</span> - - <span class="c1"># solar zenith angle in radians</span> - <span class="n">zenith</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">radians</span><span class="p">(</span><span class="mi">90</span> <span class="o">-</span> <span class="nb">float</span><span class="p">(</span><span class="n">metadata</span><span class="p">[</span><span class="s1">'SUN_ELEVATION'</span><span class="p">]))</span> - - <span class="c1"># calculate top of the atmosphere reflectance</span> - <span class="n">ref</span> <span class="o">=</span> <span class="p">(</span><span class="n">oli</span><span class="p">[</span><span class="s1">'REFLECTANCE_MULT_</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">band</span><span class="p">)]</span> <span class="o">*</span> <span class="n">data</span> <span class="o">+</span> - <span class="n">oli</span><span class="p">[</span><span class="s1">'REFLECTANCE_ADD_</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">band</span><span class="p">)])</span> - <span class="n">toa</span> <span class="o">=</span> <span class="n">ref</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">zenith</span><span class="p">)</span> - - <span class="c1"># clear memory</span> - <span class="k">del</span> <span class="n">ref</span><span class="p">,</span> <span class="n">data</span> - - <span class="c1"># mask erroneous values</span> - <span class="n">toa</span><span class="p">[</span><span class="n">mask</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span> - - <span class="c1"># output file</span> - <span class="n">outDs</span> <span class="o">=</span> <span class="n">driver</span><span class="o">.</span><span class="n">Create</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">fname</span><span class="p">),</span> <span class="n">img</span><span class="o">.</span><span class="n">RasterXSize</span><span class="p">,</span> <span class="n">img</span><span class="o">.</span><span class="n">RasterYSize</span><span class="p">,</span> - <span class="n">img</span><span class="o">.</span><span class="n">RasterCount</span><span class="p">,</span> <span class="n">gdal</span><span class="o">.</span><span class="n">GDT_Float32</span><span class="p">)</span> - <span class="n">outband</span> <span class="o">=</span> <span class="n">outDs</span><span class="o">.</span><span class="n">GetRasterBand</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> - - <span class="c1"># write array</span> - <span class="n">outband</span><span class="o">.</span><span class="n">WriteArray</span><span class="p">(</span><span class="n">toa</span><span class="p">)</span> - <span class="n">outband</span><span class="o">.</span><span class="n">FlushCache</span><span class="p">()</span> - - <span class="c1"># Set the geographic information</span> - <span class="n">outDs</span><span class="o">.</span><span class="n">SetProjection</span><span class="p">(</span><span class="n">img</span><span class="o">.</span><span class="n">GetProjection</span><span class="p">())</span> - <span class="n">outDs</span><span class="o">.</span><span class="n">SetGeoTransform</span><span class="p">(</span><span class="n">img</span><span class="o">.</span><span class="n">GetGeoTransform</span><span class="p">())</span> - - <span class="c1"># clear memory</span> - <span class="k">del</span> <span class="n">outband</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">img</span><span class="p">,</span> <span class="n">outDs</span><span class="p">,</span> <span class="n">toa</span><span class="p">,</span> <span class="n">mask</span> - - <span class="c1"># check if raw images should be removed</span> - <span class="k">if</span> <span class="n">remove_raw</span><span class="p">:</span> - - <span class="c1"># raw digital number images</span> - <span class="n">_dn</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">scene</span><span class="o">.</span><span class="n">iterdir</span><span class="p">()</span> <span class="k">if</span> <span class="n">ipattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="ow">and</span> - <span class="ow">not</span> <span class="n">cal_pattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">))]</span> - - <span class="c1"># remove raw digital number images</span> - <span class="k">for</span> <span class="n">toremove</span> <span class="ow">in</span> <span class="n">_dn</span><span class="p">:</span> - <span class="c1"># remove from disk</span> - <span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">toremove</span><span class="p">)</span> - <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">'rm </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">toremove</span><span class="p">))</span> - - <span class="k">return</span></div> -</pre></div> - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/_modules/index.html b/docs/_build/html/_modules/index.html index a46b727b17c6ad03036a0edd32edc2729140b51c..51b13136c6474d895db8c6eea1d85c136451a030 100644 --- a/docs/_build/html/_modules/index.html +++ b/docs/_build/html/_modules/index.html @@ -146,21 +146,10 @@ <div itemprop="articleBody"> <h1>All modules for which code is available</h1> -<ul><li><a href="core/cli.html">core.cli</a></li> -<li><a href="core/constants.html">core.constants</a></li> -<li><a href="core/dataset.html">core.dataset</a></li> -<li><a href="core/graphics.html">core.graphics</a></li> -<li><a href="core/layers.html">core.layers</a></li> -<li><a href="core/logging.html">core.logging</a></li> -<li><a href="core/models.html">core.models</a></li> -<li><a href="core/predict.html">core.predict</a></li> -<li><a href="core/split.html">core.split</a></li> -<li><a href="core/trainer.html">core.trainer</a></li> -<li><a href="core/transforms.html">core.transforms</a></li> -<li><a href="core/utils.html">core.utils</a></li> -<li><a href="pysegcnn/core/dataset.html">pysegcnn.core.dataset</a></li> +<ul><li><a href="pysegcnn/core/dataset.html">pysegcnn.core.dataset</a></li> <li><a href="pysegcnn/core/layers.html">pysegcnn.core.layers</a></li> <li><a href="pysegcnn/core/models.html">pysegcnn.core.models</a></li> +<li><a href="pysegcnn/core/transforms.html">pysegcnn.core.transforms</a></li> </ul> </div> diff --git a/docs/_build/html/_modules/pysegcnn/core/dataset.html b/docs/_build/html/_modules/pysegcnn/core/dataset.html index d0811c9a583bd46201ec2b96ddf70cd111ef3e79..d9f8fd6b93a2811c9253779d30b16990a730c43c 100644 --- a/docs/_build/html/_modules/pysegcnn/core/dataset.html +++ b/docs/_build/html/_modules/pysegcnn/core/dataset.html @@ -195,54 +195,54 @@ <div class="viewcode-block" id="ImageDataset"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.dataset.ImageDataset.html#pysegcnn.core.dataset.ImageDataset">[docs]</a><span class="k">class</span> <span class="nc">ImageDataset</span><span class="p">(</span><span class="n">Dataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Base class for multispectral image data.</span> - -<span class="sd"> Inheriting from `torch.utils.data.Dataset` to be compliant to the PyTorch</span> -<span class="sd"> standard. Furthermore, using instances of `torch.utils.data.Dataset`</span> -<span class="sd"> enables the use of the handy `torch.utils.data.DataLoader` class during</span> -<span class="sd"> model training.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention.</span> -<span class="sd"> All directories and subdirectories in ``root_dir`` are searched for</span> -<span class="sd"> files matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> + <span class="sd">"""Base class for multispectral image data.</span> + +<span class="sd"> Inheriting from :py:class:`torch.utils.data.Dataset` to be compliant to the</span> +<span class="sd"> PyTorch standard. This enables the use of the handy</span> +<span class="sd"> :py:class:`torch.utils.data.DataLoader` class during model training.</span> <span class="sd"> """</span> <div class="viewcode-block" id="ImageDataset.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.dataset.ImageDataset.html#pysegcnn.core.dataset.ImageDataset.__init__">[docs]</a> <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> + <span class="sa">r</span><span class="sd">"""Initialize.</span> + +<span class="sd"> Parameters</span> +<span class="sd"> ----------</span> +<span class="sd"> root_dir : `str`</span> +<span class="sd"> The root directory, path to the dataset.</span> +<span class="sd"> use_bands : `list` [`str`], optional</span> +<span class="sd"> A list of the spectral bands to use. The default is `[]`.</span> +<span class="sd"> tile_size : `int` or `None`, optional</span> +<span class="sd"> The size of the tiles. If not `None`, each scene is divided into</span> +<span class="sd"> square tiles of shape ``(tile_size, tile_size)``. The default is</span> +<span class="sd"> `None`.</span> +<span class="sd"> pad : `bool`, optional</span> +<span class="sd"> Whether to center pad the input image. Set ``pad=True``, if the</span> +<span class="sd"> images are not evenly divisible by the ``tile_size``. The image</span> +<span class="sd"> data is padded with a constant padding value of zero. For each</span> +<span class="sd"> image, the corresponding ground truth image is padded with a</span> +<span class="sd"> "no data" label. The default is `False`.</span> +<span class="sd"> gt_pattern : `str`, optional</span> +<span class="sd"> A regural expression to match the ground truth naming convention.</span> +<span class="sd"> All directories and subdirectories in ``root_dir`` are searched for</span> +<span class="sd"> files matching ``gt_pattern``. The default is `(.*)gt\\.tif`.</span> +<span class="sd"> sort : `bool`, optional</span> +<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> +<span class="sd"> data. The default is `False`.</span> +<span class="sd"> seed : `int`, optional</span> +<span class="sd"> The random seed. Used to split the dataset into training,</span> +<span class="sd"> validation and test set. Useful for reproducibility. The default is</span> +<span class="sd"> `0`.</span> +<span class="sd"> transforms : `list`, optional</span> +<span class="sd"> List of :py:class:`pysegcnn.core.transforms.Augment` instances.</span> +<span class="sd"> Each item in ``transforms`` generates a distinct transformed</span> +<span class="sd"> version of the dataset. The total dataset is composed of the</span> +<span class="sd"> original untransformed dataset together with each transformed</span> +<span class="sd"> version of it. If ``transforms=[]``, only the original dataset is</span> +<span class="sd"> used. The default is `[]`.</span> + +<span class="sd"> """</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> <span class="c1"># dataset configuration</span> @@ -642,7 +642,7 @@ <span class="sd"> -------</span> <span class="sd"> stack : `numpy.ndarray`</span> <span class="sd"> The input data of the sample.</span> -<span class="sd"> gt : TYPE</span> +<span class="sd"> gt : `numpy.ndarray`</span> <span class="sd"> The ground truth of the sample.</span> <span class="sd"> """</span> @@ -653,7 +653,7 @@ <span class="k">return</span> <span class="n">stack</span><span class="p">,</span> <span class="n">gt</span> <span class="k">def</span> <span class="nf">to_tensor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="p">):</span> - <span class="sd">"""Convert ``x`` to `torch.Tensor`.</span> + <span class="sd">"""Convert ``x`` to :py:class:`torch.Tensor`.</span> <span class="sd"> Parameters</span> <span class="sd"> ----------</span> @@ -712,86 +712,43 @@ <span class="k">return</span> <span class="n">fs</span></div> -<span class="k">class</span> <span class="nc">StandardEoDataset</span><span class="p">(</span><span class="n">ImageDataset</span><span class="p">):</span> +<div class="viewcode-block" id="StandardEoDataset"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.dataset.StandardEoDataset.html#pysegcnn.core.dataset.StandardEoDataset">[docs]</a><span class="k">class</span> <span class="nc">StandardEoDataset</span><span class="p">(</span><span class="n">ImageDataset</span><span class="p">):</span> <span class="sa">r</span><span class="sd">"""Base class for standard Earth Observation style datasets.</span> -<span class="sd"> `pysegcnn.core.dataset.StandardEoDataset` implements the</span> -<span class="sd"> `~pysegcnn.core.dataset.StandardEoDataset.compose_scenes` method for</span> -<span class="sd"> datasets with the following directory structure:</span> +<span class="sd"> :py:class:`pysegcnn.core.dataset.StandardEoDataset` implements the</span> +<span class="sd"> :py:meth:`~pysegcnn.core.dataset.StandardEoDataset.compose_scenes` method</span> +<span class="sd"> for datasets with the following directory structure:</span> <span class="sd"> root_dir/</span> -<span class="sd"> scene_id_1/</span> -<span class="sd"> scene_id_1_B1.tif</span> -<span class="sd"> scene_id_1_B2.tif</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> scene_id_1_BN.tif</span> -<span class="sd"> scene_id_2/</span> -<span class="sd"> scene_id_2_B1.tif</span> -<span class="sd"> scene_id_2_B2.tif</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> scene_id_2_BN.tif</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> scene_id_N/</span> -<span class="sd"> .</span> -<span class="sd"> .</span> -<span class="sd"> .</span> +<span class="sd"> - scene_id_1/</span> +<span class="sd"> - scene_id_1_B1.tif</span> +<span class="sd"> - scene_id_1_B2.tif</span> +<span class="sd"> - ...</span> +<span class="sd"> - scene_id_1_BN.tif</span> +<span class="sd"> - scene_id_2/</span> +<span class="sd"> - scene_id_2_B1.tif</span> +<span class="sd"> - scene_id_2_B2.tif</span> +<span class="sd"> - ...</span> +<span class="sd"> - scene_id_2_BN.tif</span> +<span class="sd"> - ...</span> +<span class="sd"> - scene_id_N/</span> +<span class="sd"> - ...</span> <span class="sd"> If your dataset shares this directory structure, you can directly inherit</span> -<span class="sd"> `pysegcnn.core.dataset.StandardEoDataset` and implement the remaining</span> -<span class="sd"> methods.</span> - -<span class="sd"> See `pysegcnn.core.dataset.SparcsDataset` for an example.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> +<span class="sd"> :py:class:`pysegcnn.core.dataset.StandardEoDataset` and implement the</span> +<span class="sd"> remaining methods. If not, you can use</span> +<span class="sd"> :py:func:`pysegcnn.core.utils.standard_eo_structure` to transfer your</span> +<span class="sd"> dataset to the above directory structure.</span> + +<span class="sd"> See :py:class:`pysegcnn.core.dataset.SparcsDataset` for an example.</span> <span class="sd"> """</span> - <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> +<div class="viewcode-block" id="StandardEoDataset.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.dataset.StandardEoDataset.html#pysegcnn.core.dataset.StandardEoDataset.__init__">[docs]</a> <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> <span class="c1"># initialize super class ImageDataset</span> <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="p">,</span> <span class="n">tile_size</span><span class="p">,</span> <span class="n">pad</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="p">,</span> - <span class="n">sort</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">transforms</span><span class="p">)</span> + <span class="n">sort</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">transforms</span><span class="p">)</span></div> <span class="k">def</span> <span class="nf">_get_band_number</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span> <span class="sd">"""Return the band number of a scene .tif file.</span> @@ -859,32 +816,7 @@ <span class="k">return</span> <span class="n">scene_data</span> <span class="k">def</span> <span class="nf">compose_scenes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Build the list of samples of the dataset.</span> - -<span class="sd"> Each sample is represented by a dictionary.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scenes : `list` [`dict`]</span> -<span class="sd"> Each item in ``scenes`` is a `dict` with keys:</span> -<span class="sd"> ``'band_name_1'``</span> -<span class="sd"> Path to the file of band_1.</span> -<span class="sd"> ``'band_name_2'``</span> -<span class="sd"> Path to the file of band_2.</span> -<span class="sd"> ``'band_name_n'``</span> -<span class="sd"> Path to the file of band_n.</span> -<span class="sd"> ``'gt'``</span> -<span class="sd"> Path to the ground truth file.</span> -<span class="sd"> ``'date'``</span> -<span class="sd"> The date of the sample.</span> -<span class="sd"> ``'tile'``</span> -<span class="sd"> The tile id of the sample.</span> -<span class="sd"> ``'transform'``</span> -<span class="sd"> The transformation to apply.</span> -<span class="sd"> ``'id'``</span> -<span class="sd"> The scene identifier.</span> - -<span class="sd"> """</span> + <span class="sd">"""Build the list of samples of the dataset."""</span> <span class="c1"># search the root directory</span> <span class="n">scenes</span> <span class="o">=</span> <span class="p">[]</span> <span class="bp">self</span><span class="o">.</span><span class="n">gt</span> <span class="o">=</span> <span class="p">[]</span> @@ -904,7 +836,7 @@ <span class="c1"># list the spectral bands of the scene</span> <span class="n">bands</span> <span class="o">=</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">join</span><span class="p">(</span><span class="n">dirpath</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">files</span> - <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s1">'B</span><span class="se">\\</span><span class="s1">dA|B</span><span class="se">\\</span><span class="s1">d{1,2}'</span><span class="p">,</span> <span class="n">f</span><span class="p">)]</span> + <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s1">'B</span><span class="se">\\</span><span class="s1">dA|B</span><span class="se">\\</span><span class="s1">d{1,2}(.*).tif$'</span><span class="p">,</span> <span class="n">f</span><span class="p">)]</span> <span class="c1"># get the ground truth mask</span> <span class="k">try</span><span class="p">:</span> @@ -946,51 +878,17 @@ <span class="n">scenes</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">k</span><span class="p">:</span> <span class="n">k</span><span class="p">[</span><span class="s1">'date'</span><span class="p">])</span> <span class="bp">self</span><span class="o">.</span><span class="n">gt</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">k</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse_scene_id</span><span class="p">(</span><span class="n">k</span><span class="p">)[</span><span class="s1">'date'</span><span class="p">])</span> - <span class="k">return</span> <span class="n">scenes</span> + <span class="k">return</span> <span class="n">scenes</span></div> <div class="viewcode-block" id="SparcsDataset"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.dataset.SparcsDataset.html#pysegcnn.core.dataset.SparcsDataset">[docs]</a><span class="k">class</span> <span class="nc">SparcsDataset</span><span class="p">(</span><span class="n">StandardEoDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the `Sparcs`_ dataset.</span> + <span class="sd">"""Class for the `Sparcs`_ dataset by `Hughes & Hayes (2014)`_.</span> <span class="sd"> .. _Sparcs:</span> <span class="sd"> https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation</span> -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> +<span class="sd"> .. _Hughes & Hayes (2014):</span> +<span class="sd"> https://www.mdpi.com/2072-4292/6/6/4907</span> <span class="sd"> """</span> @@ -1073,46 +971,7 @@ <span class="k">class</span> <span class="nc">ProSnowDataset</span><span class="p">(</span><span class="n">StandardEoDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the ProSnow datasets.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> + <span class="sd">"""Class for the ProSnow datasets."""</span> <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> @@ -1182,46 +1041,7 @@ <span class="k">class</span> <span class="nc">ProSnowGarmisch</span><span class="p">(</span><span class="n">ProSnowDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the ProSnow Garmisch dataset.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> + <span class="sd">"""Class for the ProSnow Garmisch dataset."""</span> <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> @@ -1242,46 +1062,7 @@ <span class="k">class</span> <span class="nc">ProSnowObergurgl</span><span class="p">(</span><span class="n">ProSnowDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the ProSnow Obergurgl dataset.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> + <span class="sd">"""Class for the ProSnow Obergurgl dataset."""</span> <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">gt_pattern</span><span class="o">=</span><span class="s1">'(.*)gt</span><span class="se">\\</span><span class="s1">.tif'</span><span class="p">,</span> <span class="n">sort</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="p">[]):</span> @@ -1302,50 +1083,13 @@ <div class="viewcode-block" id="Cloud95Dataset"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.dataset.Cloud95Dataset.html#pysegcnn.core.dataset.Cloud95Dataset">[docs]</a><span class="k">class</span> <span class="nc">Cloud95Dataset</span><span class="p">(</span><span class="n">ImageDataset</span><span class="p">):</span> - <span class="sa">r</span><span class="sd">"""Class for the `Cloud-95`_ dataset by `Mohajerani & Saeedi (2020)`_.</span> + <span class="sd">"""Class for the `Cloud-95`_ dataset by `Mohajerani & Saeedi (2020)`_.</span> <span class="sd"> .. _Cloud-95:</span> <span class="sd"> https://github.com/SorourMo/95-Cloud-An-Extension-to-38-Cloud-Dataset</span> <span class="sd"> .. _Mohajerani & Saeedi (2020):</span> <span class="sd"> https://arxiv.org/abs/2001.08768</span> -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> root_dir : `str`</span> -<span class="sd"> The root directory, path to the dataset.</span> -<span class="sd"> use_bands : `list` [`str`], optional</span> -<span class="sd"> A list of the spectral bands to use. The default is [].</span> -<span class="sd"> tile_size : `int` or `None`, optional</span> -<span class="sd"> The size of the tiles. If not `None`, each scene is divided into square</span> -<span class="sd"> tiles of shape (tile_size, tile_size). The default is None.</span> -<span class="sd"> pad : `bool`, optional</span> -<span class="sd"> Whether to center pad the input image. Set ``pad`` = True, if the</span> -<span class="sd"> images are not evenly divisible by the ``tile_size``. The image data is</span> -<span class="sd"> padded with a constant padding value of zero. For each image, the</span> -<span class="sd"> corresponding ground truth image is padded with a "no data" label.</span> -<span class="sd"> The default is False.</span> -<span class="sd"> gt_pattern : `str`, optional</span> -<span class="sd"> A regural expression to match the ground truth naming convention. All</span> -<span class="sd"> directories and subdirectories in ``root_dir`` are searched for files</span> -<span class="sd"> matching ``gt_pattern``. The default is '(.*)gt\\.tif'.</span> -<span class="sd"> sort : `bool`, optional</span> -<span class="sd"> Whether to chronologically sort the samples. Useful for time series</span> -<span class="sd"> data. The default is False.</span> -<span class="sd"> seed : `int`, optional</span> -<span class="sd"> The random seed. Used to split the dataset into training, validation</span> -<span class="sd"> and test set. Useful for reproducibility. The default is 0.</span> -<span class="sd"> transforms : `list` [`pysegcnn.core.split.Augment`], optional</span> -<span class="sd"> List of `pysegcnn.core.split.Augment` instances. Each item in</span> -<span class="sd"> ``transforms`` generates a distinct transformed version of the dataset.</span> -<span class="sd"> The total dataset is composed of the original untransformed dataset</span> -<span class="sd"> together with each transformed version of it.</span> -<span class="sd"> If ``transforms`` = [], only the original dataset is used.</span> -<span class="sd"> The default is [].</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - <span class="sd"> """</span> <div class="viewcode-block" id="Cloud95Dataset.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.dataset.Cloud95Dataset.html#pysegcnn.core.dataset.Cloud95Dataset.__init__">[docs]</a> <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">root_dir</span><span class="p">,</span> <span class="n">use_bands</span><span class="o">=</span><span class="p">[],</span> <span class="n">tile_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> @@ -1435,32 +1179,7 @@ <span class="k">return</span> <span class="n">parse_landsat_scene</span><span class="p">(</span><span class="n">scene_id</span><span class="p">)</span> <span class="k">def</span> <span class="nf">compose_scenes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> - <span class="sd">"""Build the list of samples of the dataset.</span> - -<span class="sd"> Each sample is represented by a dictionary.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> scenes : `list` [`dict`]</span> -<span class="sd"> Each item in ``scenes`` is a `dict` with keys:</span> -<span class="sd"> ``'band_name_1'``</span> -<span class="sd"> Path to the file of band_1.</span> -<span class="sd"> ``'band_name_2'``</span> -<span class="sd"> Path to the file of band_2.</span> -<span class="sd"> ``'band_name_n'``</span> -<span class="sd"> Path to the file of band_n.</span> -<span class="sd"> ``'gt'``</span> -<span class="sd"> Path to the ground truth file.</span> -<span class="sd"> ``'date'``</span> -<span class="sd"> The date of the sample.</span> -<span class="sd"> ``'tile'``</span> -<span class="sd"> The tile id of the sample.</span> -<span class="sd"> ``'transform'``</span> -<span class="sd"> The transformation to apply.</span> -<span class="sd"> ``'id'``</span> -<span class="sd"> The scene identifier.</span> - -<span class="sd"> """</span> + <span class="sd">"""Build the list of samples of the dataset."""</span> <span class="c1"># whether to exclude patches with more than 80% black pixels</span> <span class="n">ipatches</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">exclude</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> diff --git a/docs/_build/html/_modules/pysegcnn/core/layers.html b/docs/_build/html/_modules/pysegcnn/core/layers.html index 1c7ad933a346f350b49e1ade27c8a357ec2d6ef7..b0373e234919b4f1c3c6f900a6fa0d2105cef33e 100644 --- a/docs/_build/html/_modules/pysegcnn/core/layers.html +++ b/docs/_build/html/_modules/pysegcnn/core/layers.html @@ -178,29 +178,30 @@ <span class="sd"> calculated such that the output of the convolution has the same spatial</span> <span class="sd"> dimensions as the input.</span> -<span class="sd"> Parameters</span> +<span class="sd"> Attributes</span> <span class="sd"> ----------</span> -<span class="sd"> *args: `list` [`str`]</span> -<span class="sd"> positional arguments passed to `torch.nn.Conv2d`:</span> -<span class="sd"> ``'in_channels'``: `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> ``'out_channels'``: `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> ``'kernel_size'``: `int` or `tuple` [`int`]</span> -<span class="sd"> Size of the convolving kernel.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional keyword arguments passed to `torch.nn.Conv2d`_.</span> - -<span class="sd"> .. _torch.nn.Conv2d:</span> -<span class="sd"> https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> +<span class="sd"> padding : `tuple` [`int`]</span> +<span class="sd"> The amount of padding, (pad_height, pad_width).</span> <span class="sd"> """</span> <div class="viewcode-block" id="Conv2dSame.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame.__init__">[docs]</a> <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> + <span class="sd">"""Initialize.</span> + +<span class="sd"> Parameters</span> +<span class="sd"> ----------</span> +<span class="sd"> *args: `list` [`str`]</span> +<span class="sd"> positional arguments passed to :py:class:`torch.nn.Conv2d`:</span> +<span class="sd"> ``'in_channels'``: `int`</span> +<span class="sd"> Number of input channels.</span> +<span class="sd"> ``'out_channels'``: `int`</span> +<span class="sd"> Number of output channels.</span> +<span class="sd"> ``'kernel_size'``: `int` or `tuple` [`int`]</span> +<span class="sd"> Size of the convolving kernel.</span> +<span class="sd"> **kwargs: `dict` [`str`]</span> +<span class="sd"> Additional keyword arguments passed to :py:class:`torch.nn.Conv2d`.</span> + +<span class="sd"> """</span> <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> <span class="c1"># define tensorflows "SAME" padding for stride = 1</span> @@ -223,7 +224,7 @@ <span class="sd"> Returns</span> <span class="sd"> -------</span> <span class="sd"> p : `int`</span> -<span class="sd"> the amount of padding.</span> +<span class="sd"> The amount of padding.</span> <span class="sd"> """</span> <span class="c1"># calculates the padding so that the convolution</span> @@ -240,7 +241,7 @@ <span class="sd"> Number of input channels.</span> <span class="sd"> out_channels : `int`</span> <span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> +<span class="sd"> **kwargs: `dict` [`str`]</span> <span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> <span class="sd"> Returns</span> @@ -263,28 +264,39 @@ <div class="viewcode-block" id="Block"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.Block.html#pysegcnn.core.layers.Block">[docs]</a><span class="k">class</span> <span class="nc">Block</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">):</span> <span class="sd">"""Basic convolutional block.</span> -<span class="sd"> Parameters</span> +<span class="sd"> Attributes</span> <span class="sd"> ----------</span> <span class="sd"> in_channels : `int`</span> <span class="sd"> Number of input channels.</span> <span class="sd"> out_channels : `int`</span> <span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Raises</span> -<span class="sd"> ------</span> -<span class="sd"> TypeError</span> -<span class="sd"> Raised if `~pysegcnn.core.layers.Block.layers` method does not return</span> -<span class="sd"> an instance of `torch.nn.Sequential`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> +<span class="sd"> kwargs: `dict` [`str`]</span> +<span class="sd"> Additional arguments passed to</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.Conv2dSame`.</span> +<span class="sd"> conv : :py:class:`torch.nn.Sequential`</span> +<span class="sd"> The convolutional layers of the block.</span> <span class="sd"> """</span> <div class="viewcode-block" id="Block.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.Block.html#pysegcnn.core.layers.Block.__init__">[docs]</a> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> + <span class="sd">"""Initialize.</span> + +<span class="sd"> Parameters</span> +<span class="sd"> ----------</span> +<span class="sd"> in_channels : `int`</span> +<span class="sd"> Number of input channels.</span> +<span class="sd"> out_channels : `int`</span> +<span class="sd"> Number of output channels.</span> +<span class="sd"> **kwargs: `dict` [`str`]</span> +<span class="sd"> Additional arguments passed to</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.Conv2dSame`.</span> + +<span class="sd"> Raises</span> +<span class="sd"> ------</span> +<span class="sd"> TypeError</span> +<span class="sd"> Raised if :py:meth:`~pysegcnn.core.layers.Block.layers` method does</span> +<span class="sd"> not return an instance of :py:class:`torch.nn.Sequential`.</span> +<span class="sd"> """</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> <span class="c1"># number of input and output channels</span> @@ -307,13 +319,13 @@ <span class="sd"> Raises</span> <span class="sd"> ------</span> <span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.layers.Block` is not inherited.</span> +<span class="sd"> Raised if :py:class:`pysegcnn.core.layers.Block` is not inherited.</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> layers : `torch.nn.Sequential` [`torch.nn.Module`]</span> -<span class="sd"> Return an instance of `torch.nn.Sequential` containing a sequence</span> -<span class="sd"> of layer (`torch.nn.Module` ) instances.</span> +<span class="sd"> layers : :py:class:`torch.nn.Sequential` [:py:class:`torch.nn.Module`]</span> +<span class="sd"> Return an instance of :py:class:`torch.nn.Sequential` containing a</span> +<span class="sd"> sequence of layer (:py:class:`torch.nn.Module` ) instances.</span> <span class="sd"> """</span> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Return an instance of </span><span class="si">{}</span><span class="s1">.'</span> @@ -325,33 +337,14 @@ <span class="sd"> Raises</span> <span class="sd"> ------</span> <span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.layers.Block` is not inherited.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> +<span class="sd"> Raised if :py:class:`pysegcnn.core.layers.Block` is not inherited.</span> <span class="sd"> """</span> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Implement the forward pass.'</span><span class="p">)</span></div> <div class="viewcode-block" id="EncoderBlock"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.EncoderBlock.html#pysegcnn.core.layers.EncoderBlock">[docs]</a><span class="k">class</span> <span class="nc">EncoderBlock</span><span class="p">(</span><span class="n">Block</span><span class="p">):</span> - <span class="sd">"""Block of a convolutional encoder.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> + <span class="sd">"""Block of a convolutional encoder."""</span> <div class="viewcode-block" id="EncoderBlock.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.EncoderBlock.html#pysegcnn.core.layers.EncoderBlock.__init__">[docs]</a> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div> @@ -361,21 +354,21 @@ <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`</span> +<span class="sd"> x : :py:class:`torch.Tensor`</span> <span class="sd"> Input tensor, e.g. output of the previous block/layer.</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> y : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> y : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Output of the encoder block.</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Intermediate output before applying downsampling. Useful to</span> <span class="sd"> implement skip connections.</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> +<span class="sd"> indices : :py:class:`torch.Tensor` or `None`</span> <span class="sd"> Optional indices of the downsampling method, e.g. indices of the</span> -<span class="sd"> maxima when using `torch.nn.functional.max_pool2d`. Useful for</span> -<span class="sd"> upsampling later. If no indices are required to upsample, simply</span> -<span class="sd"> return ``indices`` = `None`.</span> +<span class="sd"> maxima when using :py:func:`torch.nn.functional.max_pool2d`. Useful</span> +<span class="sd"> for upsampling later. If no indices are required to upsample,</span> +<span class="sd"> simply return ``indices=None``.</span> <span class="sd"> """</span> <span class="c1"># the forward pass of the layers of the block</span> @@ -389,57 +382,43 @@ <span class="k">def</span> <span class="nf">downsample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span> <span class="sd">"""Define the downsampling method.</span> -<span class="sd"> The `~pysegcnn.core.layers.EncoderBlock.downsample` method should</span> -<span class="sd"> implement the spatial pooling operation.</span> +<span class="sd"> The :py:meth:`~pysegcnn.core.layers.EncoderBlock.downsample` method</span> +<span class="sd"> should implement the spatial pooling operation.</span> <span class="sd"> Use one of the following functions to downsample:</span> -<span class="sd"> - `torch.nn.functional.max_pool2d`</span> -<span class="sd"> - `torch.nn.functional.interpolate`</span> +<span class="sd"> - :py:func:`torch.nn.functional.max_pool2d`</span> +<span class="sd"> - :py:func:`torch.nn.functional.interpolate`</span> -<span class="sd"> See `pysegcnn.core.layers.ConvBnReluMaxPool` for an example</span> +<span class="sd"> See :py:class:`pysegcnn.core.layers.ConvBnReluMaxPool` for an example</span> <span class="sd"> implementation.</span> <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Input tensor, e.g. output of a convolutional block.</span> <span class="sd"> Raises</span> <span class="sd"> ------</span> <span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.layers.EncoderBlock` is not inherited.</span> +<span class="sd"> Raised if :py:class:`pysegcnn.core.layers.EncoderBlock` is not</span> +<span class="sd"> inherited.</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> The spatially downsampled tensor.</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> +<span class="sd"> indices : :py:class:`torch.Tensor` or `None`</span> <span class="sd"> Optional indices of the downsampling method, e.g. indices of the</span> -<span class="sd"> maxima when using `torch.nn.functional.max_pool2d`. Useful for</span> -<span class="sd"> upsampling later. If no indices are required to upsample, simply</span> -<span class="sd"> return ``indices`` = `None`.</span> +<span class="sd"> maxima when using :py:func:`torch.nn.functional.max_pool2d`. Useful</span> +<span class="sd"> for upsampling later. If no indices are required to upsample,</span> +<span class="sd"> simply return ``indices=None``.</span> <span class="sd"> """</span> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">'Implement the downsampling function.'</span><span class="p">)</span></div> <div class="viewcode-block" id="DecoderBlock"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.DecoderBlock.html#pysegcnn.core.layers.DecoderBlock">[docs]</a><span class="k">class</span> <span class="nc">DecoderBlock</span><span class="p">(</span><span class="n">Block</span><span class="p">):</span> - <span class="sd">"""Block of a convolutional decoder.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> + <span class="sd">"""Block of a convolutional decoder."""</span> <div class="viewcode-block" id="DecoderBlock.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.DecoderBlock.html#pysegcnn.core.layers.DecoderBlock.__init__">[docs]</a> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div> @@ -449,21 +428,21 @@ <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Input tensor.</span> -<span class="sd"> feature : `torch.Tensor`, shape=(batch, channel, height, width)</span> -<span class="sd"> Intermediate output of a layer in the encoder.</span> -<span class="sd"> If ``skip`` = True, ``feature`` is concatenated (along the channel</span> -<span class="sd"> axis) to the output of the respective upsampling layer in the</span> -<span class="sd"> decoder (skip connection).</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> +<span class="sd"> feature : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> +<span class="sd"> Intermediate output of a layer in the encoder. If ``skip=True``,</span> +<span class="sd"> ``feature`` is concatenated (along the channel axis) to the output</span> +<span class="sd"> of the respective upsampling layer in the decoder (skip connection)</span> +<span class="sd"> .</span> +<span class="sd"> indices : :py:class:`torch.Tensor` or `None`</span> <span class="sd"> Indices of the encoder downsampling method.</span> <span class="sd"> skip : `bool`</span> <span class="sd"> Whether to apply the skip connection.</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Output of the decoder block.</span> <span class="sd"> """</span> @@ -484,35 +463,36 @@ <span class="k">def</span> <span class="nf">upsample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">feature</span><span class="p">,</span> <span class="n">indices</span><span class="p">):</span> <span class="sd">"""Define the upsampling method.</span> -<span class="sd"> The `~pysegcnn.core.layers.DecoderBlock.upsample` method should</span> -<span class="sd"> implement the spatial upsampling operation.</span> +<span class="sd"> The :py:meth:`~pysegcnn.core.layers.DecoderBlock.upsample` method</span> +<span class="sd"> should implement the spatial upsampling operation.</span> <span class="sd"> Use one of the following functions to upsample:</span> -<span class="sd"> - `torch.nn.functional.max_unpool2d`</span> -<span class="sd"> - `torch.nn.functional.interpolate`</span> +<span class="sd"> - :py:func:`torch.nn.functional.max_unpool2d`</span> +<span class="sd"> - :py:func:`torch.nn.functional.interpolate`</span> -<span class="sd"> See `pysegcnn.core.layers.ConvBnReluMaxUnpool` or</span> -<span class="sd"> `pysegcnn.core.layers.ConvBnReluUpsample` for an example</span> +<span class="sd"> See :py:class:`pysegcnn.core.layers.ConvBnReluMaxUnpool` or</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.ConvBnReluUpsample` for an example</span> <span class="sd"> implementation.</span> <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Input tensor, e.g. output of a convolutional block.</span> -<span class="sd"> feature : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> feature : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Intermediate output of a layer in the encoder. Used to implement</span> <span class="sd"> skip connections.</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> +<span class="sd"> indices : :py:class:`torch.Tensor` or `None`</span> <span class="sd"> Indices of the encoder downsampling method.</span> <span class="sd"> Raises</span> <span class="sd"> ------</span> <span class="sd"> NotImplementedError</span> -<span class="sd"> Raised if `pysegcnn.core.layers.DecoderBlock` is not inherited.</span> +<span class="sd"> Raised if :py:class:`pysegcnn.core.layers.DecoderBlock` is not</span> +<span class="sd"> inherited.</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> The spatially upsampled tensor.</span> <span class="sd"> """</span> @@ -523,31 +503,50 @@ <span class="sd">"""Generic convolutional encoder.</span> <span class="sd"> When instanciating an encoder-decoder architechure, ``filters`` should be</span> -<span class="sd"> the same for `pysegcnn.core.layers.Encoder` and</span> -<span class="sd"> `pysegcnn.core.layers.Decoder`.</span> +<span class="sd"> the same for :py:class:`pysegcnn.core.layers.Encoder` and</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.Decoder`.</span> -<span class="sd"> See `pysegcnn.core.models.UNet` for an example implementation.</span> +<span class="sd"> See :py:class:`pysegcnn.core.models.UNet` for an example implementation.</span> -<span class="sd"> Parameters</span> +<span class="sd"> Attributes</span> <span class="sd"> ----------</span> -<span class="sd"> filters : `list` [`int`]</span> -<span class="sd"> List of input channels to each convolutional block. The length of</span> -<span class="sd"> ``filters`` determines the depth of the encoder. The first element of</span> -<span class="sd"> ``filters`` has to be the number of channels of the input images.</span> -<span class="sd"> block : `pysegcnn.core.layers.EncoderBlock`</span> +<span class="sd"> features : :py:class:`numpy.ndarray`</span> +<span class="sd"> Input channels to each convolutional block, i.e. ``filters``.</span> +<span class="sd"> block : :py:class:`pysegcnn.core.layers.EncoderBlock`</span> <span class="sd"> The convolutional block defining a layer in the encoder.</span> -<span class="sd"> A subclass of `pysegcnn.core.layers.EncoderBlock`, e.g.</span> -<span class="sd"> `pysegcnn.core.layers.ConvBnReluMaxPool`.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> +<span class="sd"> A subclass of :py:class:`pysegcnn.core.layers.EncoderBlock`, e.g.</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.ConvBnReluMaxPool`.</span> +<span class="sd"> layers : :py:class:`torch.nn.ModuleList`</span> +<span class="sd"> List of blocks in the encoder.</span> +<span class="sd"> cache : `dict`</span> +<span class="sd"> Intermediate encoder outputs. Dictionary with keys:</span> +<span class="sd"> ``'feature'``</span> +<span class="sd"> The intermediate encoder outputs (:py:class:`torch.Tensor`).</span> +<span class="sd"> ``'indices'``</span> +<span class="sd"> The indices of the max pooling layer, if required</span> +<span class="sd"> (:py:class:`torch.Tensor`).</span> <span class="sd"> """</span> <div class="viewcode-block" id="Encoder.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.Encoder.html#pysegcnn.core.layers.Encoder.__init__">[docs]</a> <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">filters</span><span class="p">,</span> <span class="n">block</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> + <span class="sd">"""Initialize.</span> + +<span class="sd"> Parameters</span> +<span class="sd"> ----------</span> +<span class="sd"> filters : `list` [`int`]</span> +<span class="sd"> List of input channels to each convolutional block. The length of</span> +<span class="sd"> ``filters`` determines the depth of the encoder. The first element</span> +<span class="sd"> of ``filters`` has to be the number of channels of the input</span> +<span class="sd"> images.</span> +<span class="sd"> block : :py:class:`pysegcnn.core.layers.EncoderBlock`</span> +<span class="sd"> The convolutional block defining a layer in the encoder.</span> +<span class="sd"> A subclass of :py:class:`pysegcnn.core.layers.EncoderBlock`, e.g.</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.ConvBnReluMaxPool`.</span> +<span class="sd"> **kwargs: `dict` [`str`]</span> +<span class="sd"> Additional arguments passed to</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.Conv2dSame`.</span> + +<span class="sd"> """</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> <span class="c1"># the number of filters for each block: the first element of filters</span> @@ -573,22 +572,22 @@ <span class="sd">"""Forward pass of the encoder.</span> <span class="sd"> Stores intermediate outputs in a dictionary. The keys of the dictionary</span> -<span class="sd"> are the number of the network layers and the values are dictionaries</span> +<span class="sd"> are the numbers of the network layers and the values are dictionaries</span> <span class="sd"> with the following (key, value) pairs:</span> -<span class="sd"> ``"feature"``</span> -<span class="sd"> The intermediate encoder outputs (`torch.Tensor`).</span> -<span class="sd"> ``"indices"``</span> +<span class="sd"> ``'feature'``</span> +<span class="sd"> The intermediate encoder outputs (:py:class:`torch.Tensor`).</span> +<span class="sd"> ``'indices'``</span> <span class="sd"> The indices of the max pooling layer, if required</span> -<span class="sd"> (`torch.Tensor`).</span> +<span class="sd"> (:py:class:`torch.Tensor`).</span> <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Input image.</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Output of the encoder.</span> <span class="sd"> """</span> @@ -609,33 +608,47 @@ <span class="sd">"""Generic convolutional decoder.</span> <span class="sd"> When instanciating an encoder-decoder architechure, ``filters`` should be</span> -<span class="sd"> the same for `pysegcnn.core.layers.Encoder` and</span> -<span class="sd"> `pysegcnn.core.layers.Decoder`.</span> +<span class="sd"> the same for :py:class:`pysegcnn.core.layers.Encoder` and</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.Decoder`.</span> -<span class="sd"> See `pysegcnn.core.models.UNet` for an example implementation.</span> +<span class="sd"> See :py:class:`pysegcnn.core.models.UNet` for an example implementation.</span> -<span class="sd"> Parameters</span> +<span class="sd"> Attributes</span> <span class="sd"> ----------</span> -<span class="sd"> filters : `list` [`int`]</span> -<span class="sd"> List of input channels to each convolutional block. The length of</span> -<span class="sd"> ``filters`` determines the depth of the decoder. The first element of</span> -<span class="sd"> ``filters`` has to be the number of channels of the input images.</span> -<span class="sd"> block : `pysegcnn.core.layers.DecoderBlock`</span> +<span class="sd"> features : :py:class:`numpy.ndarray`</span> +<span class="sd"> Input channels to each convolutional block, i.e. ``filters``.</span> +<span class="sd"> block : :py:class:`pysegcnn.core.layers.EncoderBlock`</span> <span class="sd"> The convolutional block defining a layer in the decoder.</span> -<span class="sd"> A subclass of `pysegcnn.core.layers.DecoderBlock`, e.g.</span> -<span class="sd"> `pysegcnn.core.layers.ConvBnReluMaxUnpool`.</span> +<span class="sd"> A subclass of :py:class:`pysegcnn.core.layers.EncoderBlock`, e.g.</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.ConvBnReluMaxPool`.</span> <span class="sd"> skip : `bool`</span> <span class="sd"> Whether to apply skip connections from the encoder to the decoder.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> +<span class="sd"> layers : :py:class:`torch.nn.ModuleList`</span> +<span class="sd"> List of blocks in the decoder.</span> <span class="sd"> """</span> <div class="viewcode-block" id="Decoder.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.Decoder.html#pysegcnn.core.layers.Decoder.__init__">[docs]</a> <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">filters</span><span class="p">,</span> <span class="n">block</span><span class="p">,</span> <span class="n">skip</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> + <span class="sd">"""Initialize.</span> + +<span class="sd"> Parameters</span> +<span class="sd"> ----------</span> +<span class="sd"> filters : `list` [`int`]</span> +<span class="sd"> List of input channels to each convolutional block. The length of</span> +<span class="sd"> ``filters`` determines the depth of the decoder. The first element</span> +<span class="sd"> of ``filters`` has to be the number of channels of the input</span> +<span class="sd"> images.</span> +<span class="sd"> block : :py:class:`pysegcnn.core.layers.DecoderBlock`</span> +<span class="sd"> The convolutional block defining a layer in the decoder.</span> +<span class="sd"> A subclass of :py:class:`pysegcnn.core.layers.DecoderBlock`, e.g.</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.ConvBnReluMaxUnpool`.</span> +<span class="sd"> skip : `bool`, optional</span> +<span class="sd"> Whether to apply skip connections from the encoder to the decoder.</span> +<span class="sd"> **kwargs: `dict` [`str`]</span> +<span class="sd"> Additional arguments passed to</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.Conv2dSame`.</span> + +<span class="sd"> """</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> <span class="c1"># the block of operations defining a layer in the decoder</span> @@ -670,20 +683,22 @@ <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Output of the encoder.</span> <span class="sd"> enc_cache : `dict` [`dict`]</span> <span class="sd"> Cache dictionary. The keys of the dictionary are the number of the</span> <span class="sd"> network layers and the values are dictionaries with the following</span> <span class="sd"> (key, value) pairs:</span> -<span class="sd"> ``"feature"``</span> -<span class="sd"> The intermediate encoder outputs (`torch.Tensor`).</span> -<span class="sd"> ``"indices"``</span> -<span class="sd"> The indices of the max pooling layer (`torch.Tensor`).</span> +<span class="sd"> ``'feature'``</span> +<span class="sd"> The intermediate encoder outputs</span> +<span class="sd"> (:py:class:`torch.Tensor`).</span> +<span class="sd"> ``'indices'``</span> +<span class="sd"> The indices of the max pooling layer</span> +<span class="sd"> (:py:class:`torch.Tensor`).</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Output of the decoder.</span> <span class="sd"> """</span> @@ -702,23 +717,7 @@ <div class="viewcode-block" id="ConvBnReluMaxPool"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.html#pysegcnn.core.layers.ConvBnReluMaxPool">[docs]</a><span class="k">class</span> <span class="nc">ConvBnReluMaxPool</span><span class="p">(</span><span class="n">EncoderBlock</span><span class="p">):</span> - <span class="sd">"""Block of convolution, batchnorm, relu and 2x2 max pool.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional keyword arguments passed to</span> -<span class="sd"> `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> + <span class="sd">"""Block of convolution, batchnorm, relu and 2x2 max pool."""</span> <div class="viewcode-block" id="ConvBnReluMaxPool.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.html#pysegcnn.core.layers.ConvBnReluMaxPool.__init__">[docs]</a> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div> @@ -728,29 +727,30 @@ <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> layers : `torch.nn.Sequential` [`torch.nn.Module`]</span> -<span class="sd"> An instance of `torch.nn.Sequential` containing the sequence</span> -<span class="sd"> of convolution, batchnorm and relu layer (`torch.nn.Module`)</span> -<span class="sd"> instances.</span> +<span class="sd"> layers : :py:class:`torch.nn.Sequential` [:py:class:`torch.nn.Module`]</span> +<span class="sd"> An instance of :py:class:`torch.nn.Sequential` containing the</span> +<span class="sd"> sequence of convolution, batchnorm and relu layer</span> +<span class="sd"> (:py:class:`torch.nn.Module`) instances.</span> <span class="sd"> """</span> <span class="k">return</span> <span class="n">conv_bn_relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">in_channels</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span> <span class="k">def</span> <span class="nf">downsample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span> - <span class="sd">"""2x2 max pooling layer, `torch.nn.functional.max_pool2d`.</span> + <span class="sd">"""2x2 max pooling layer.</span> <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Input tensor.</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height // 2, width // 2)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h // 2, w // 2)</span> <span class="sd"> The 2x2 max pooled tensor.</span> -<span class="sd"> indices : `torch.Tensor` or `None`</span> +<span class="sd"> indices : :py:class:`torch.Tensor` or `None`</span> <span class="sd"> The indices of the maxima. Useful for upsampling with</span> -<span class="sd"> `torch.nn.functional.max_unpool2d`.</span> +<span class="sd"> :py:func:`torch.nn.functional.max_unpool2d`.</span> + <span class="sd"> """</span> <span class="n">x</span><span class="p">,</span> <span class="n">indices</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">max_pool2d</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">kernel_size</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">return_indices</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">return</span> <span class="n">x</span><span class="p">,</span> <span class="n">indices</span> @@ -768,23 +768,7 @@ <div class="viewcode-block" id="ConvBnReluMaxUnpool"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.html#pysegcnn.core.layers.ConvBnReluMaxUnpool">[docs]</a><span class="k">class</span> <span class="nc">ConvBnReluMaxUnpool</span><span class="p">(</span><span class="n">DecoderBlock</span><span class="p">):</span> - <span class="sd">"""Block of convolution, batchnorm, relu and 2x2 max unpool.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional keyword arguments passed to</span> -<span class="sd"> `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> + <span class="sd">"""Block of convolution, batchnorm, relu and 2x2 max unpool."""</span> <div class="viewcode-block" id="ConvBnReluMaxUnpool.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.html#pysegcnn.core.layers.ConvBnReluMaxUnpool.__init__">[docs]</a> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div> @@ -794,10 +778,10 @@ <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> layers : `torch.nn.Sequential` [`torch.nn.Module`]</span> -<span class="sd"> An instance of `torch.nn.Sequential` containing the sequence</span> -<span class="sd"> of convolution, batchnorm and relu layer (`torch.nn.Module`)</span> -<span class="sd"> instances.</span> +<span class="sd"> layers : :py:class:`torch.nn.Sequential` [:py:class:`torch.nn.Module`]</span> +<span class="sd"> An instance of :py:class:`torch.nn.Sequential` containing the</span> +<span class="sd"> sequence of convolution, batchnorm and relu layer</span> +<span class="sd"> (:py:class:`torch.nn.Module`) instances.</span> <span class="sd"> """</span> <span class="k">return</span> <span class="n">conv_bn_relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">in_channels</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span> @@ -807,18 +791,18 @@ <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Input tensor.</span> -<span class="sd"> feature : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> feature : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Intermediate output of a layer in the encoder. Used to determine</span> <span class="sd"> the output shape of the upsampling operation.</span> -<span class="sd"> indices : `torch.Tensor`</span> +<span class="sd"> indices : :py:class:`torch.Tensor`</span> <span class="sd"> The indices of the maxima of the max pooling operation</span> -<span class="sd"> (as returned by `torch.nn.functional.max_pool2d`).</span> +<span class="sd"> (as returned by :py:func:`torch.nn.functional.max_pool2d`).</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height * 2, width * 2)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h * 2, w * 2)</span> <span class="sd"> The 2x2 max unpooled tensor.</span> <span class="sd"> """</span> @@ -838,22 +822,7 @@ <div class="viewcode-block" id="ConvBnReluUpsample"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.ConvBnReluUpsample.html#pysegcnn.core.layers.ConvBnReluUpsample">[docs]</a><span class="k">class</span> <span class="nc">ConvBnReluUpsample</span><span class="p">(</span><span class="n">DecoderBlock</span><span class="p">):</span> - <span class="sd">"""Block of convolution, batchnorm, relu and nearest neighbor upsampling.</span> - -<span class="sd"> Parameters</span> -<span class="sd"> ----------</span> -<span class="sd"> in_channels : `int`</span> -<span class="sd"> Number of input channels.</span> -<span class="sd"> out_channels : `int`</span> -<span class="sd"> Number of output channels</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional arguments passed to `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> - -<span class="sd"> """</span> + <span class="sd">"""Block of convolution, batchnorm, relu and nearest neighbor upsample."""</span> <div class="viewcode-block" id="ConvBnReluUpsample.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.layers.ConvBnReluUpsample.html#pysegcnn.core.layers.ConvBnReluUpsample.__init__">[docs]</a> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <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">in_channels</span><span class="p">,</span> <span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div> @@ -863,10 +832,10 @@ <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> layers : `torch.nn.Sequential` [`torch.nn.Module`]</span> -<span class="sd"> An instance of `torch.nn.Sequential` containing the sequence</span> -<span class="sd"> of convolution, batchnorm and relu layer (`torch.nn.Module`)</span> -<span class="sd"> instances.</span> +<span class="sd"> layers : :py:class:`torch.nn.Sequential` [:py:class:`torch.nn.Module`]</span> +<span class="sd"> An instance of :py:class:`torch.nn.Sequential` containing the</span> +<span class="sd"> sequence of convolution, batchnorm and relu layer</span> +<span class="sd"> (:py:class:`torch.nn.Module`) instances.</span> <span class="sd"> """</span> <span class="k">return</span> <span class="n">conv_bn_relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">in_channels</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">out_channels</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span> @@ -876,19 +845,19 @@ <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Input tensor.</span> -<span class="sd"> feature : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> feature : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> Intermediate output of a layer in the encoder. Used to determine</span> <span class="sd"> the output shape of the upsampling operation.</span> <span class="sd"> indices : `None`, optional</span> <span class="sd"> The indices of the maxima of the max pooling operation</span> -<span class="sd"> (as returned by `torch.nn.functional.max_pool2d`). Not required by</span> -<span class="sd"> this upsampling method.</span> +<span class="sd"> (as returned by :py:func:`torch.nn.functional.max_pool2d`).</span> +<span class="sd"> Not required by this upsampling method.</span> <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> x : `torch.Tensor`, shape=(batch, channel, height, width)</span> +<span class="sd"> x : :py:class:`torch.Tensor`, shape=(b, c, h, w)</span> <span class="sd"> The 2x2 upsampled tensor.</span> <span class="sd"> """</span> diff --git a/docs/_build/html/_modules/pysegcnn/core/models.html b/docs/_build/html/_modules/pysegcnn/core/models.html index ed55a3991df1d9525761ae41aabefb7b395024a7..4e951b1583dc86a5a4d0488d06509f8f46e1c8f6 100644 --- a/docs/_build/html/_modules/pysegcnn/core/models.html +++ b/docs/_build/html/_modules/pysegcnn/core/models.html @@ -187,15 +187,17 @@ <span class="sd">"""Generic Network class.</span> <span class="sd"> The base class for each model. If you want to implement a new model,</span> -<span class="sd"> inherit the ``~pysegcnn.core.models.Network`` class.</span> +<span class="sd"> inherit the :py:class:`pysegcnn.core.models.Network` class.</span> -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> +<span class="sd"> Attributes</span> +<span class="sd"> ----------</span> +<span class="sd"> state_file : `str` or `None` or :py:class:`pathlib.Path`</span> +<span class="sd"> The model state file, where the model parameters are saved.</span> <span class="sd"> """</span> <div class="viewcode-block" id="Network.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.models.Network.html#pysegcnn.core.models.Network.__init__">[docs]</a> <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="sd">"""Initialize."""</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> <span class="c1"># initialize state file</span> @@ -239,9 +241,9 @@ <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> state_file : `str` or `pathlib.Path`</span> +<span class="sd"> state_file : `str` or :py:class:`pathlib.Path`</span> <span class="sd"> Path to save the model state.</span> -<span class="sd"> optimizer : `torch.optim.Optimizer`</span> +<span class="sd"> optimizer : :py:class:`torch.optim.Optimizer`</span> <span class="sd"> The optimizer used to train the model.</span> <span class="sd"> bands : `list` [`str`] or `None`, optional</span> <span class="sd"> List of bands the model is trained with. The default is None.</span> @@ -252,7 +254,7 @@ <span class="sd"> Returns</span> <span class="sd"> -------</span> <span class="sd"> model_state : `dict`</span> -<span class="sd"> A dictionary containing the model and optimizer state</span> +<span class="sd"> A dictionary containing the model and optimizer state.</span> <span class="sd"> """</span> <span class="c1"># check if the output path exists and if not, create it</span> @@ -306,7 +308,7 @@ <span class="sd"> Parameters</span> <span class="sd"> ----------</span> -<span class="sd"> state_file : `str` or `pathlib.Path`</span> +<span class="sd"> state_file : `str` or :py:class:`pathlib.Path`</span> <span class="sd"> The model state file. Model state files are stored in</span> <span class="sd"> pysegcnn/main/_models.</span> @@ -317,13 +319,13 @@ <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> model : `pysegcnn.core.models.Network`</span> +<span class="sd"> model : :py:class:`pysegcnn.core.models.Network`</span> <span class="sd"> The pretrained model.</span> -<span class="sd"> optimizer : `torch.optim.Optimizer`</span> +<span class="sd"> optimizer : :py:class:`torch.optim.Optimizer`</span> <span class="sd"> The optimizer used to train the model.</span> -<span class="sd"> model_state : '`dict`</span> +<span class="sd"> model_state : `dict`</span> <span class="sd"> A dictionary containing the model and optimizer state, as</span> -<span class="sd"> constructed by `~pysegcnn.core.Network.save`.</span> +<span class="sd"> constructed by :py:meth:`~pysegcnn.core.Network.save`.</span> <span class="sd"> """</span> <span class="c1"># load the pretrained model</span> @@ -366,7 +368,7 @@ <span class="sd"> Returns</span> <span class="sd"> -------</span> -<span class="sd"> state_file : `pathlib.Path` or `None`</span> +<span class="sd"> state_file : :py:class:`pathlib.Path` or `None`</span> <span class="sd"> The model state file.</span> <span class="sd"> """</span> @@ -374,36 +376,58 @@ <div class="viewcode-block" id="UNet"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.models.UNet.html#pysegcnn.core.models.UNet">[docs]</a><span class="k">class</span> <span class="nc">UNet</span><span class="p">(</span><span class="n">Network</span><span class="p">):</span> - <span class="sd">"""A PyTorch implementation of `U-Net`_.</span> + <span class="sd">"""A slightly modified implementation of `U-Net`_ in PyTorch.</span> + +<span class="sd"> .. important::</span> -<span class="sd"> Slightly modified version of U-Net:</span> -<span class="sd"> - each convolution is followed by a batch normalization layer</span> -<span class="sd"> - the upsampling is implemented by a 2x2 max unpooling operation</span> +<span class="sd"> - Each convolution is followed by a batch normalization layer</span> +<span class="sd"> - Upsampling is implemented by a 2x2 max unpooling operation</span> <span class="sd"> .. _U-Net:</span> <span class="sd"> https://arxiv.org/abs/1505.04597</span> -<span class="sd"> Parameters</span> +<span class="sd"> Attributes</span> <span class="sd"> ----------</span> <span class="sd"> in_channels : `int`</span> <span class="sd"> Number of channels of the input images.</span> <span class="sd"> nclasses : `int`</span> <span class="sd"> Number of classes.</span> -<span class="sd"> filters : `list` [`int`]</span> +<span class="sd"> kwargs : `dict` [`str`]</span> +<span class="sd"> Additional keyword arguments passed to</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.Conv2dSame`.</span> +<span class="sd"> nfilters : `list` [`int`]</span> <span class="sd"> List of input channels to each convolutional block.</span> <span class="sd"> skip : `bool`</span> <span class="sd"> Whether to apply skip connections from the encoder to the decoder.</span> -<span class="sd"> **kwargs: 'dict' [`str`]</span> -<span class="sd"> Additional keyword arguments passed to</span> -<span class="sd"> `pysegcnn.core.layers.Conv2dSame`.</span> - -<span class="sd"> Returns</span> -<span class="sd"> -------</span> -<span class="sd"> None.</span> +<span class="sd"> epoch : `int`</span> +<span class="sd"> Number of epochs the model was trained.</span> +<span class="sd"> encoder : :py:class:`pysegcnn.core.layers.Encoder`</span> +<span class="sd"> The convolutional encoder.</span> +<span class="sd"> decoder : :py:class:`pysegcnn.core.layers.Decoder`</span> +<span class="sd"> The convolutional decoder.</span> +<span class="sd"> classifier : :py:class:`pysegcnn.core.layers.Conv2dSame`</span> +<span class="sd"> The classification layer, a 1x1 convolution.</span> <span class="sd"> """</span> <div class="viewcode-block" id="UNet.__init__"><a class="viewcode-back" href="../../../source/generated/pysegcnn.core.models.UNet.html#pysegcnn.core.models.UNet.__init__">[docs]</a> <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">in_channels</span><span class="p">,</span> <span class="n">nclasses</span><span class="p">,</span> <span class="n">filters</span><span class="p">,</span> <span class="n">skip</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> + <span class="sd">"""Initialize.</span> + +<span class="sd"> Parameters</span> +<span class="sd"> ----------</span> +<span class="sd"> in_channels : `int`</span> +<span class="sd"> Number of channels of the input images.</span> +<span class="sd"> nclasses : `int`</span> +<span class="sd"> Number of classes.</span> +<span class="sd"> filters : `list` [`int`]</span> +<span class="sd"> List of input channels to each convolutional block.</span> +<span class="sd"> skip : `bool`</span> +<span class="sd"> Whether to apply skip connections from the encoder to the decoder.</span> +<span class="sd"> **kwargs: `dict` [`str`]</span> +<span class="sd"> Additional keyword arguments passed to</span> +<span class="sd"> :py:class:`pysegcnn.core.layers.Conv2dSame`.</span> + +<span class="sd"> """</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span> <span class="c1"># number of input channels</span> diff --git a/docs/_build/html/_sources/modules.rst.txt b/docs/_build/html/_sources/modules.rst.txt deleted file mode 100644 index 383d07e61cdeb0228f6aa0a14dc4a376932a8a66..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/modules.rst.txt +++ /dev/null @@ -1,10 +0,0 @@ -Modules -======= - -.. autosummary:: - :toctree: modules - - pysegcnn.core.cli - pysegcnn.core.constants - pysegcnn.core.dataset - diff --git a/docs/_build/html/_sources/modules/pysegcnn.core.cli.rst.txt b/docs/_build/html/_sources/modules/pysegcnn.core.cli.rst.txt deleted file mode 100644 index 3a5c0e3bb6b6d5c842eb2ea90dadd368efdb5f27..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/modules/pysegcnn.core.cli.rst.txt +++ /dev/null @@ -1,29 +0,0 @@ -pysegcnn.core.cli -================= - -.. automodule:: pysegcnn.core.cli - - - - - - - - .. rubric:: Functions - - .. autosummary:: - - structure_parser - - - - - - - - - - - - - diff --git a/docs/_build/html/_sources/modules/pysegcnn.core.constants.rst.txt b/docs/_build/html/_sources/modules/pysegcnn.core.constants.rst.txt deleted file mode 100644 index abb68f18fa7b316f5dad1bf7a8cfb48937cb9cf3..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/modules/pysegcnn.core.constants.rst.txt +++ /dev/null @@ -1,34 +0,0 @@ -pysegcnn.core.constants -======================= - -.. automodule:: pysegcnn.core.constants - - - - - - - - - - - - .. rubric:: Classes - - .. autosummary:: - - Cloud95Labels - Label - Landsat8 - ProSnowLabels - Sentinel2 - SparcsLabels - - - - - - - - - diff --git a/docs/_build/html/_sources/modules/pysegcnn.core.dataset.rst.txt b/docs/_build/html/_sources/modules/pysegcnn.core.dataset.rst.txt deleted file mode 100644 index 2586d7412cd824ebed8c5cb1137f4b83a3147ef7..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/modules/pysegcnn.core.dataset.rst.txt +++ /dev/null @@ -1,36 +0,0 @@ -pysegcnn.core.dataset -===================== - -.. automodule:: pysegcnn.core.dataset - - - - - - - - - - - - .. rubric:: Classes - - .. autosummary:: - - Cloud95Dataset - ImageDataset - ProSnowDataset - ProSnowGarmisch - ProSnowObergurgl - SparcsDataset - StandardEoDataset - SupportedDatasets - - - - - - - - - diff --git a/docs/_build/html/_sources/readme.rst.txt b/docs/_build/html/_sources/readme.rst.txt deleted file mode 100644 index 35b29b40bef7bea95bc65074292883308f4e6271..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/readme.rst.txt +++ /dev/null @@ -1,4 +0,0 @@ -Test -==== - -.. mdinclude:: ../README.md \ No newline at end of file diff --git a/docs/_build/html/_sources/source/api.rst.txt b/docs/_build/html/_sources/source/api.rst.txt index 4de52de54bd3cdf346bfdf3d35e6bef1ce7643ab..6d2aabc35a3d4889c14b817a6580618244188067 100644 --- a/docs/_build/html/_sources/source/api.rst.txt +++ b/docs/_build/html/_sources/source/api.rst.txt @@ -13,9 +13,9 @@ Dataset Custom dataset classes compliant to the PyTorch `standard <https://pytorch.org/docs/stable/data.html>`_. -Image Dataset -^^^^^^^^^^^^^ -Generic class to implement `custom datasets <https://pytorch.org/tutorials/beginner/data_loading_tutorial.html>`_. +Generic classes +^^^^^^^^^^^^^^^ +Generic class to implement a `custom dataset <https://pytorch.org/tutorials/beginner/data_loading_tutorial.html>`_. .. autosummary:: :toctree: generated/ @@ -23,11 +23,21 @@ Generic class to implement `custom datasets <https://pytorch.org/tutorials/begin core.dataset.ImageDataset -Supported datasets -^^^^^^^^^^^^^^^^^^ +Generic class to implement a custom dataset following a standard directory +structure. + +.. autosummary:: + :toctree: generated/ + :nosignatures: + + core.dataset.StandardEoDataset + -The following open-source spaceborne multispectral image datasets are supported -out-of-the-box: +Specific classes +^^^^^^^^^^^^^^^^ + +Specific classes for some open-source image datasets. Currently, the following +spaceborne multispectral image datasets are supported out-of-the-box: .. autosummary:: :toctree: generated/ @@ -36,7 +46,6 @@ out-of-the-box: core.dataset.SparcsDataset core.dataset.Cloud95Dataset - Models ------ @@ -81,6 +90,9 @@ Neural Networks core.models.UNet +.. + Links: + .. _Sparcs: https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation @@ -92,3 +104,12 @@ Neural Networks .. _U-Net: https://arxiv.org/abs/1505.04597 + +.. _Landsat-8: + https://www.usgs.gov/land-resources/nli/landsat/landsat-8?qt-science_support_page_related_con=0#qt-science_support_page_related_con + +.. _Sentinel-2: + https://sentinel.esa.int/web/sentinel/missions/sentinel-2 + +.. _Hughes & Hayes (2014): + https://www.mdpi.com/2072-4292/6/6/4907 diff --git a/docs/_build/html/_sources/source/core.rst.txt b/docs/_build/html/_sources/source/core.rst.txt deleted file mode 100644 index e57f944a0b43cc53179c8ac6638aebb1a32920a2..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/source/core.rst.txt +++ /dev/null @@ -1,109 +0,0 @@ -core package -============ - -Submodules ----------- - -core.cli module ---------------- - -.. automodule:: core.cli - :members: - :undoc-members: - :show-inheritance: - -core.constants module ---------------------- - -.. automodule:: core.constants - :members: - :undoc-members: - :show-inheritance: - -core.dataset module -------------------- - -.. automodule:: core.dataset - :members: - :undoc-members: - :show-inheritance: - -core.graphics module --------------------- - -.. automodule:: core.graphics - :members: - :undoc-members: - :show-inheritance: - -core.layers module ------------------- - -.. automodule:: core.layers - :members: - :undoc-members: - :show-inheritance: - -core.logging module -------------------- - -.. automodule:: core.logging - :members: - :undoc-members: - :show-inheritance: - -core.models module ------------------- - -.. automodule:: core.models - :members: - :undoc-members: - :show-inheritance: - -core.predict module -------------------- - -.. automodule:: core.predict - :members: - :undoc-members: - :show-inheritance: - -core.split module ------------------ - -.. automodule:: core.split - :members: - :undoc-members: - :show-inheritance: - -core.trainer module -------------------- - -.. automodule:: core.trainer - :members: - :undoc-members: - :show-inheritance: - -core.transforms module ----------------------- - -.. automodule:: core.transforms - :members: - :undoc-members: - :show-inheritance: - -core.utils module ------------------ - -.. automodule:: core.utils - :members: - :undoc-members: - :show-inheritance: - -Module contents ---------------- - -.. automodule:: core - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.Cloud95Dataset.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.Cloud95Dataset.rst.txt index 0b8650621242af8de39fc4bf54f43f371b295a94..a1810656ee6dab330ce851fe7a3320f4396a65d0 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.Cloud95Dataset.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.Cloud95Dataset.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.dataset.Cloud95Dataset +pysegcnn.core.dataset.Cloud95Dataset ==================================== .. currentmodule:: pysegcnn.core.dataset diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.ImageDataset.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.ImageDataset.rst.txt index c04ed1f96ea2d230023e87a20bebeb31c0fe1050..31c36ff73f998226baf6cf9c48daeaea74404f94 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.ImageDataset.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.ImageDataset.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.dataset.ImageDataset +pysegcnn.core.dataset.ImageDataset ================================== .. currentmodule:: pysegcnn.core.dataset diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.SparcsDataset.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.SparcsDataset.rst.txt index d5c9fe46ca1985f87d71a260f0a9168ce193c5c4..cb357b5f003e77960920e99d3fe0ec24ec014b46 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.SparcsDataset.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.dataset.SparcsDataset.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.dataset.SparcsDataset +pysegcnn.core.dataset.SparcsDataset =================================== .. currentmodule:: pysegcnn.core.dataset diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Block.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Block.rst.txt index 3e960b4c77a531221739831ef70e2348e407fd1c..31875348b6f55bb5513dd3785c91d0cddb1a671e 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Block.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Block.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.layers.Block +pysegcnn.core.layers.Block ========================== .. currentmodule:: pysegcnn.core.layers diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Conv2dSame.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Conv2dSame.rst.txt index 7c81180f3dbf6d1b08ea77e608a908975395ddb5..42b472e1ec390a7329cfc9813c4a19efb35fe0ff 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Conv2dSame.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Conv2dSame.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.layers.Conv2dSame +pysegcnn.core.layers.Conv2dSame =============================== .. currentmodule:: pysegcnn.core.layers diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.rst.txt index 7a99902ee622930c6a3ed940f8f2f7e8af705b9d..6260fe50769352e915c3dc3d26ae9b9310ea7c52 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.layers.ConvBnReluMaxPool +pysegcnn.core.layers.ConvBnReluMaxPool ====================================== .. currentmodule:: pysegcnn.core.layers diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.rst.txt index c83252a532e4d66427284193e0ce3bd6233ad52e..386abc1be48bcf7487098b4847c7e6385d849772 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.layers.ConvBnReluMaxUnpool +pysegcnn.core.layers.ConvBnReluMaxUnpool ======================================== .. currentmodule:: pysegcnn.core.layers diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.rst.txt index bac34eecc38456d240d6889d01a7e97b9268dd99..6d4f3e6ac7d591f5aaa1da607b6c5730d099d6d0 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.layers.ConvBnReluUpsample +pysegcnn.core.layers.ConvBnReluUpsample ======================================= .. currentmodule:: pysegcnn.core.layers diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Decoder.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Decoder.rst.txt index 9ca6527d10479cdf03eb3d4213af41da9c295b4a..a5fcf7fd1a0190303deaee9d603008990cc060f5 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Decoder.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Decoder.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.layers.Decoder +pysegcnn.core.layers.Decoder ============================ .. currentmodule:: pysegcnn.core.layers diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.DecoderBlock.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.DecoderBlock.rst.txt index 3acc653c6098b27269e7e171bdc7a9f22ab570e8..d6a87bc7f63568ac82cddf0dc5f4d4653391343c 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.DecoderBlock.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.DecoderBlock.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.layers.DecoderBlock +pysegcnn.core.layers.DecoderBlock ================================= .. currentmodule:: pysegcnn.core.layers diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Encoder.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Encoder.rst.txt index 09aa71ccc1c2f5cf0c5fcf0b84a6e47fde490f4e..fcd00c6bc912c46d3ac641b3d2fdeb5a1fd3295c 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Encoder.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.Encoder.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.layers.Encoder +pysegcnn.core.layers.Encoder ============================ .. currentmodule:: pysegcnn.core.layers diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.EncoderBlock.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.EncoderBlock.rst.txt index 37385b204208ec53e9a247657998a864ad5a0602..454ce4102139d897e53bbad4c61d61bc7b6aeae6 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.EncoderBlock.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.EncoderBlock.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.layers.EncoderBlock +pysegcnn.core.layers.EncoderBlock ================================= .. currentmodule:: pysegcnn.core.layers diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.rst.txt deleted file mode 100644 index 5e2f12505e569b7122b7c49d457efd349481ebfa..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.layers.rst.txt +++ /dev/null @@ -1,43 +0,0 @@ -pysegcnn.core.layers -==================== - -.. automodule:: pysegcnn.core.layers - - - - - - - - .. rubric:: Functions - - .. autosummary:: - - conv_bn_relu - - - - - - .. rubric:: Classes - - .. autosummary:: - - Block - Conv2dSame - ConvBnReluMaxPool - ConvBnReluMaxUnpool - ConvBnReluUpsample - Decoder - DecoderBlock - Encoder - EncoderBlock - - - - - - - - - diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.models.Network.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.models.Network.rst.txt index a5b21f07fee5ee799539ac7daf52a68abd48d617..99819a3608b928852226184cbf9d39f50697a252 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.models.Network.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.models.Network.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.models.Network +pysegcnn.core.models.Network ============================ .. currentmodule:: pysegcnn.core.models diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.models.UNet.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.models.UNet.rst.txt index 933d3fcbccf6d0d26a1c0bee26300e0fa0cae620..92cb118b24485a58a9d65aafbd223aafadf1ce59 100644 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.models.UNet.rst.txt +++ b/docs/_build/html/_sources/source/generated/pysegcnn.core.models.UNet.rst.txt @@ -1,4 +1,4 @@ -pysegcnn.core.models.UNet +pysegcnn.core.models.UNet ========================= .. currentmodule:: pysegcnn.core.models diff --git a/docs/_build/html/_sources/source/generated/pysegcnn.core.models.rst.txt b/docs/_build/html/_sources/source/generated/pysegcnn.core.models.rst.txt deleted file mode 100644 index 3c9f372176cd6078f5561b4a40a331577f0593b9..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/source/generated/pysegcnn.core.models.rst.txt +++ /dev/null @@ -1,33 +0,0 @@ -pysegcnn.core.models -==================== - -.. automodule:: pysegcnn.core.models - - - - - - - - - - - - .. rubric:: Classes - - .. autosummary:: - - Network - SupportedLossFunctions - SupportedModels - SupportedOptimizers - UNet - - - - - - - - - diff --git a/docs/_build/html/_sources/source/install.rst.txt b/docs/_build/html/_sources/source/install.rst.txt deleted file mode 100644 index eb91803d2c6ba64ea68e39a298feb2eaf9ea1254..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/source/install.rst.txt +++ /dev/null @@ -1,77 +0,0 @@ -Installation -============ - -Download ---------- -You can download ``pysegcnn`` from this repository's -`website <https://gitlab.inf.unibz.it/REMSEN/ccisnow/pysegcnn>`_ -or alternatively use ``git`` from terminal: - -.. code-block:: bash - - git clone https://gitlab.inf.unibz.it/REMSEN/ccisnow/pysegcnn.git - -This creates a copy of the repository in your current directory on the file -system. - -Conda ------ - -To install ``pysegcnn``, I recommend to use the ``conda`` package manager. -You can download ``conda`` `here <https://docs.conda.io/en/latest/miniconda.html>`_. -Once successfully installed ``conda``, I recommend to add ``conda-forge`` as -your default channel: - -.. code-block:: bash - - conda config --add channels conda-forge - -Conda environments ------------------- - -To install ``pysegcnn``, I recommend to create a specific ``conda`` -`environment <https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html>`_, -by using the provided ``environment.yml`` file. In a terminal, navigate to the -**cloned git repositories root directory** (``/pysegcnn``) and type: - -.. code-block:: bash - - conda env create -f environment.yml - -This may take a while. The above command creates a conda environment with all -required dependencies except the ``pytorch`` package. The first line in -``environment.yml`` defines the environment name, in this case ``pysegcnn``. -Activate your environment using: - -.. code-block:: bash - - conda activate pysegcnn - -Install PyTorch ---------------- -The installation of ``pytorch`` is heavily dependent on the hardware of your -machine. Therefore, after activating your environment, install the version of -`PyTorch <https://pytorch.org/>`_ that your system supports by following the -official `instructions <https://pytorch.org/get-started/locally/>`_. - -If you have to build ``pytorch`` from source, follow this -`guide <https://github.com/pytorch/pytorch#from-source>`_. - -`Here <https://pytorch.org/get-started/locally/#linux-verification>`_ is how to -check if ``pytorch`` is installed correctly. - -Install PySegCNN ----------------- -To finally install ``pysegcnn`` run the below command **from this repositories -root directory within the activated ``pysegcnn`` conda environment**: - -.. code-block:: bash - - pip install -e . - -If successful, you should be able to import ``pysegcnn`` from any Python -interpreter using: - -.. code-block:: python - - import pysegcnn diff --git a/docs/_build/html/_sources/source/main.rst.txt b/docs/_build/html/_sources/source/main.rst.txt deleted file mode 100644 index 8fd37169d80e63c1a1e29b5dba6e2f67eb27f43b..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/source/main.rst.txt +++ /dev/null @@ -1,37 +0,0 @@ -main package -============ - -Submodules ----------- - -main.config module ------------------- - -.. automodule:: main.config - :members: - :undoc-members: - :show-inheritance: - -main.eval module ----------------- - -.. automodule:: main.eval - :members: - :undoc-members: - :show-inheritance: - -main.train module ------------------ - -.. automodule:: main.train - :members: - :undoc-members: - :show-inheritance: - -Module contents ---------------- - -.. automodule:: main - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/_build/html/_sources/source/modules.rst.txt b/docs/_build/html/_sources/source/modules.rst.txt deleted file mode 100644 index 55e86457961793c751b95f0118225c88718c3100..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/source/modules.rst.txt +++ /dev/null @@ -1,9 +0,0 @@ -pysegcnn -======== - -.. toctree:: - :maxdepth: 4 - - core - main - preprocessing diff --git a/docs/_build/html/_sources/source/preprocessing.rst.txt b/docs/_build/html/_sources/source/preprocessing.rst.txt deleted file mode 100644 index 06afc1c0ea6732e982af1a848fcd9baef6a8503e..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/source/preprocessing.rst.txt +++ /dev/null @@ -1,21 +0,0 @@ -preprocessing package -===================== - -Submodules ----------- - -preprocessing.sparcs module ---------------------------- - -.. automodule:: preprocessing.sparcs - :members: - :undoc-members: - :show-inheritance: - -Module contents ---------------- - -.. automodule:: preprocessing - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/_build/html/_sources/source/readme.rst.txt b/docs/_build/html/_sources/source/readme.rst.txt deleted file mode 100644 index 3f2eb6fc98784afb1aa1a507ef51c1f457ca7689..0000000000000000000000000000000000000000 --- a/docs/_build/html/_sources/source/readme.rst.txt +++ /dev/null @@ -1,4 +0,0 @@ -README -====== - -.. include: ../../README.md \ No newline at end of file diff --git a/docs/_build/html/_static/alabaster.css b/docs/_build/html/_static/alabaster.css deleted file mode 100644 index 0eddaeb07d19bffb50884d7bd7996418b6461a09..0000000000000000000000000000000000000000 --- a/docs/_build/html/_static/alabaster.css +++ /dev/null @@ -1,701 +0,0 @@ -@import url("basic.css"); - -/* -- page layout ----------------------------------------------------------- */ - -body { - font-family: Georgia, serif; - font-size: 17px; - background-color: #fff; - color: #000; - margin: 0; - padding: 0; -} - - -div.document { - width: 940px; - margin: 30px auto 0 auto; -} - -div.documentwrapper { - float: left; - width: 100%; -} - -div.bodywrapper { - margin: 0 0 0 220px; -} - -div.sphinxsidebar { - width: 220px; - font-size: 14px; - line-height: 1.5; -} - -hr { - border: 1px solid #B1B4B6; -} - -div.body { - background-color: #fff; - color: #3E4349; - padding: 0 30px 0 30px; -} - -div.body > .section { - text-align: left; -} - -div.footer { - width: 940px; - margin: 20px auto 30px auto; - font-size: 14px; - color: #888; - text-align: right; -} - -div.footer a { - color: #888; -} - -p.caption { - font-family: inherit; - font-size: inherit; -} - - -div.relations { - display: none; -} - - -div.sphinxsidebar a { - color: #444; - text-decoration: none; - border-bottom: 1px dotted #999; -} - -div.sphinxsidebar a:hover { - border-bottom: 1px solid #999; -} - -div.sphinxsidebarwrapper { - padding: 18px 10px; -} - -div.sphinxsidebarwrapper p.logo { - padding: 0; - margin: -10px 0 0 0px; - text-align: center; -} - -div.sphinxsidebarwrapper h1.logo { - margin-top: -10px; - text-align: center; - margin-bottom: 5px; - text-align: left; -} - -div.sphinxsidebarwrapper h1.logo-name { - margin-top: 0px; -} - -div.sphinxsidebarwrapper p.blurb { - margin-top: 0; - font-style: normal; -} - -div.sphinxsidebar h3, -div.sphinxsidebar h4 { - font-family: Georgia, serif; - color: #444; - font-size: 24px; - font-weight: normal; - margin: 0 0 5px 0; - padding: 0; -} - -div.sphinxsidebar h4 { - font-size: 20px; -} - -div.sphinxsidebar h3 a { - color: #444; -} - -div.sphinxsidebar p.logo a, -div.sphinxsidebar h3 a, -div.sphinxsidebar p.logo a:hover, -div.sphinxsidebar h3 a:hover { - border: none; -} - -div.sphinxsidebar p { - color: #555; - margin: 10px 0; -} - -div.sphinxsidebar ul { - margin: 10px 0; - padding: 0; - color: #000; -} - -div.sphinxsidebar ul li.toctree-l1 > a { - font-size: 120%; -} - -div.sphinxsidebar ul li.toctree-l2 > a { - font-size: 110%; -} - -div.sphinxsidebar input { - border: 1px solid #CCC; - font-family: Georgia, serif; - font-size: 1em; -} - -div.sphinxsidebar hr { - border: none; - height: 1px; - color: #AAA; - background: #AAA; - - text-align: left; - margin-left: 0; - width: 50%; -} - -div.sphinxsidebar .badge { - border-bottom: none; -} - -div.sphinxsidebar .badge:hover { - border-bottom: none; -} - -/* To address an issue with donation coming after search */ -div.sphinxsidebar h3.donation { - margin-top: 10px; -} - -/* -- body styles ----------------------------------------------------------- */ - -a { - color: #004B6B; - text-decoration: underline; -} - -a:hover { - color: #6D4100; - text-decoration: underline; -} - -div.body h1, -div.body h2, -div.body h3, -div.body h4, -div.body h5, -div.body h6 { - font-family: Georgia, serif; - font-weight: normal; - margin: 30px 0px 10px 0px; - padding: 0; -} - -div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } -div.body h2 { font-size: 180%; } -div.body h3 { font-size: 150%; } -div.body h4 { font-size: 130%; } -div.body h5 { font-size: 100%; } -div.body h6 { font-size: 100%; } - -a.headerlink { - color: #DDD; - padding: 0 4px; - text-decoration: none; -} - -a.headerlink:hover { - color: #444; - background: #EAEAEA; -} - -div.body p, div.body dd, div.body li { - line-height: 1.4em; -} - -div.admonition { - margin: 20px 0px; - padding: 10px 30px; - background-color: #EEE; - border: 1px solid #CCC; -} - -div.admonition tt.xref, div.admonition code.xref, div.admonition a tt { - background-color: #FBFBFB; - border-bottom: 1px solid #fafafa; -} - -div.admonition p.admonition-title { - font-family: Georgia, serif; - font-weight: normal; - font-size: 24px; - margin: 0 0 10px 0; - padding: 0; - line-height: 1; -} - -div.admonition p.last { - margin-bottom: 0; -} - -div.highlight { - background-color: #fff; -} - -dt:target, .highlight { - background: #FAF3E8; -} - -div.warning { - background-color: #FCC; - border: 1px solid #FAA; -} - -div.danger { - background-color: #FCC; - border: 1px solid #FAA; - -moz-box-shadow: 2px 2px 4px #D52C2C; - -webkit-box-shadow: 2px 2px 4px #D52C2C; - box-shadow: 2px 2px 4px #D52C2C; -} - -div.error { - background-color: #FCC; - border: 1px solid #FAA; - -moz-box-shadow: 2px 2px 4px #D52C2C; - -webkit-box-shadow: 2px 2px 4px #D52C2C; - box-shadow: 2px 2px 4px #D52C2C; -} - -div.caution { - background-color: #FCC; - border: 1px solid #FAA; -} - -div.attention { - background-color: #FCC; - border: 1px solid #FAA; -} - -div.important { - background-color: #EEE; - border: 1px solid #CCC; -} - -div.note { - background-color: #EEE; - border: 1px solid #CCC; -} - -div.tip { - background-color: #EEE; - border: 1px solid #CCC; -} - -div.hint { - background-color: #EEE; - border: 1px solid #CCC; -} - -div.seealso { - background-color: #EEE; - border: 1px solid #CCC; -} - -div.topic { - background-color: #EEE; -} - -p.admonition-title { - display: inline; -} - -p.admonition-title:after { - content: ":"; -} - -pre, tt, code { - font-family: 'Consolas', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; - font-size: 0.9em; -} - -.hll { - background-color: #FFC; - margin: 0 -12px; - padding: 0 12px; - display: block; -} - -img.screenshot { -} - -tt.descname, tt.descclassname, code.descname, code.descclassname { - font-size: 0.95em; -} - -tt.descname, code.descname { - padding-right: 0.08em; -} - -img.screenshot { - -moz-box-shadow: 2px 2px 4px #EEE; - -webkit-box-shadow: 2px 2px 4px #EEE; - box-shadow: 2px 2px 4px #EEE; -} - -table.docutils { - border: 1px solid #888; - -moz-box-shadow: 2px 2px 4px #EEE; - -webkit-box-shadow: 2px 2px 4px #EEE; - box-shadow: 2px 2px 4px #EEE; -} - -table.docutils td, table.docutils th { - border: 1px solid #888; - padding: 0.25em 0.7em; -} - -table.field-list, table.footnote { - border: none; - -moz-box-shadow: none; - -webkit-box-shadow: none; - box-shadow: none; -} - -table.footnote { - margin: 15px 0; - width: 100%; - border: 1px solid #EEE; - background: #FDFDFD; - font-size: 0.9em; -} - -table.footnote + table.footnote { - margin-top: -15px; - border-top: none; -} - -table.field-list th { - padding: 0 0.8em 0 0; -} - -table.field-list td { - padding: 0; -} - -table.field-list p { - margin-bottom: 0.8em; -} - -/* Cloned from - * https://github.com/sphinx-doc/sphinx/commit/ef60dbfce09286b20b7385333d63a60321784e68 - */ -.field-name { - -moz-hyphens: manual; - -ms-hyphens: manual; - -webkit-hyphens: manual; - hyphens: manual; -} - -table.footnote td.label { - width: .1px; - padding: 0.3em 0 0.3em 0.5em; -} - -table.footnote td { - padding: 0.3em 0.5em; -} - -dl { - margin: 0; - padding: 0; -} - -dl dd { - margin-left: 30px; -} - -blockquote { - margin: 0 0 0 30px; - padding: 0; -} - -ul, ol { - /* Matches the 30px from the narrow-screen "li > ul" selector below */ - margin: 10px 0 10px 30px; - padding: 0; -} - -pre { - background: #EEE; - padding: 7px 30px; - margin: 15px 0px; - line-height: 1.3em; -} - -div.viewcode-block:target { - background: #ffd; -} - -dl pre, blockquote pre, li pre { - margin-left: 0; - padding-left: 30px; -} - -tt, code { - background-color: #ecf0f3; - color: #222; - /* padding: 1px 2px; */ -} - -tt.xref, code.xref, a tt { - background-color: #FBFBFB; - border-bottom: 1px solid #fff; -} - -a.reference { - text-decoration: none; - border-bottom: 1px dotted #004B6B; -} - -/* Don't put an underline on images */ -a.image-reference, a.image-reference:hover { - border-bottom: none; -} - -a.reference:hover { - border-bottom: 1px solid #6D4100; -} - -a.footnote-reference { - text-decoration: none; - font-size: 0.7em; - vertical-align: top; - border-bottom: 1px dotted #004B6B; -} - -a.footnote-reference:hover { - border-bottom: 1px solid #6D4100; -} - -a:hover tt, a:hover code { - background: #EEE; -} - - -@media screen and (max-width: 870px) { - - div.sphinxsidebar { - display: none; - } - - div.document { - width: 100%; - - } - - div.documentwrapper { - margin-left: 0; - margin-top: 0; - margin-right: 0; - margin-bottom: 0; - } - - div.bodywrapper { - margin-top: 0; - margin-right: 0; - margin-bottom: 0; - margin-left: 0; - } - - ul { - margin-left: 0; - } - - li > ul { - /* Matches the 30px from the "ul, ol" selector above */ - margin-left: 30px; - } - - .document { - width: auto; - } - - .footer { - width: auto; - } - - .bodywrapper { - margin: 0; - } - - .footer { - width: auto; - } - - .github { - display: none; - } - - - -} - - - -@media screen and (max-width: 875px) { - - body { - margin: 0; - padding: 20px 30px; - } - - div.documentwrapper { - float: none; - background: #fff; - } - - div.sphinxsidebar { - display: block; - float: none; - width: 102.5%; - margin: 50px -30px -20px -30px; - padding: 10px 20px; - background: #333; - color: #FFF; - } - - div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, - div.sphinxsidebar h3 a { - color: #fff; - } - - div.sphinxsidebar a { - color: #AAA; - } - - div.sphinxsidebar p.logo { - display: none; - } - - div.document { - width: 100%; - margin: 0; - } - - div.footer { - display: none; - } - - div.bodywrapper { - margin: 0; - } - - div.body { - min-height: 0; - padding: 0; - } - - .rtd_doc_footer { - display: none; - } - - .document { - width: auto; - } - - .footer { - width: auto; - } - - .footer { - width: auto; - } - - .github { - display: none; - } -} - - -/* misc. */ - -.revsys-inline { - display: none!important; -} - -/* Make nested-list/multi-paragraph items look better in Releases changelog - * pages. Without this, docutils' magical list fuckery causes inconsistent - * formatting between different release sub-lists. - */ -div#changelog > div.section > ul > li > p:only-child { - margin-bottom: 0; -} - -/* Hide fugly table cell borders in ..bibliography:: directive output */ -table.docutils.citation, table.docutils.citation td, table.docutils.citation th { - border: none; - /* Below needed in some edge cases; if not applied, bottom shadows appear */ - -moz-box-shadow: none; - -webkit-box-shadow: none; - box-shadow: none; -} - - -/* relbar */ - -.related { - line-height: 30px; - width: 100%; - font-size: 0.9rem; -} - -.related.top { - border-bottom: 1px solid #EEE; - margin-bottom: 20px; -} - -.related.bottom { - border-top: 1px solid #EEE; -} - -.related ul { - padding: 0; - margin: 0; - list-style: none; -} - -.related li { - display: inline; -} - -nav#rellinks { - float: right; -} - -nav#rellinks li+li:before { - content: "|"; -} - -nav#breadcrumbs li+li:before { - content: "\00BB"; -} - -/* Hide certain items when printing */ -@media print { - div.related { - display: none; - } -} \ No newline at end of file diff --git a/docs/_build/html/_static/custom.css b/docs/_build/html/_static/custom.css deleted file mode 100644 index 2a924f1d6a8bc930c5296bdb2d5c2d3e39b04a1c..0000000000000000000000000000000000000000 --- a/docs/_build/html/_static/custom.css +++ /dev/null @@ -1 +0,0 @@ -/* This file intentionally left blank. */ diff --git a/docs/_build/html/genindex.html b/docs/_build/html/genindex.html index 7fb412d23cd3e8c8871c22f2206c79156b5bc78b..d44bdbf056114006563185ef8fe370b6fb665423 100644 --- a/docs/_build/html/genindex.html +++ b/docs/_build/html/genindex.html @@ -152,6 +152,7 @@ <div class="genindex-jumpbox"> <a href="#_"><strong>_</strong></a> + | <a href="#A"><strong>A</strong></a> | <a href="#B"><strong>B</strong></a> | <a href="#C"><strong>C</strong></a> | <a href="#D"><strong>D</strong></a> @@ -171,6 +172,8 @@ <li><a href="source/generated/pysegcnn.core.dataset.ImageDataset.html#pysegcnn.core.dataset.ImageDataset.__init__">(pysegcnn.core.dataset.ImageDataset method)</a> </li> <li><a href="source/generated/pysegcnn.core.dataset.SparcsDataset.html#pysegcnn.core.dataset.SparcsDataset.__init__">(pysegcnn.core.dataset.SparcsDataset method)</a> +</li> + <li><a href="source/generated/pysegcnn.core.dataset.StandardEoDataset.html#pysegcnn.core.dataset.StandardEoDataset.__init__">(pysegcnn.core.dataset.StandardEoDataset method)</a> </li> <li><a href="source/generated/pysegcnn.core.layers.Block.html#pysegcnn.core.layers.Block.__init__">(pysegcnn.core.layers.Block method)</a> </li> @@ -193,11 +196,21 @@ <li><a href="source/generated/pysegcnn.core.models.Network.html#pysegcnn.core.models.Network.__init__">(pysegcnn.core.models.Network method)</a> </li> <li><a href="source/generated/pysegcnn.core.models.UNet.html#pysegcnn.core.models.UNet.__init__">(pysegcnn.core.models.UNet method)</a> +</li> + <li><a href="source/generated/pysegcnn.core.transforms.Augment.html#pysegcnn.core.transforms.Augment.__init__">(pysegcnn.core.transforms.Augment method)</a> </li> </ul></li> </ul></td> </tr></table> +<h2 id="A">A</h2> +<table style="width: 100%" class="indextable genindextable"><tr> + <td style="width: 33%; vertical-align: top;"><ul> + <li><a href="source/generated/pysegcnn.core.transforms.Augment.html#pysegcnn.core.transforms.Augment">Augment (class in pysegcnn.core.transforms)</a> +</li> + </ul></td> +</tr></table> + <h2 id="B">B</h2> <table style="width: 100%" class="indextable genindextable"><tr> <td style="width: 33%; vertical-align: top;"><ul> @@ -268,6 +281,10 @@ <table style="width: 100%" class="indextable genindextable"><tr> <td style="width: 33%; vertical-align: top;"><ul> <li><a href="source/generated/pysegcnn.core.dataset.SparcsDataset.html#pysegcnn.core.dataset.SparcsDataset">SparcsDataset (class in pysegcnn.core.dataset)</a> +</li> + </ul></td> + <td style="width: 33%; vertical-align: top;"><ul> + <li><a href="source/generated/pysegcnn.core.dataset.StandardEoDataset.html#pysegcnn.core.dataset.StandardEoDataset">StandardEoDataset (class in pysegcnn.core.dataset)</a> </li> </ul></td> </tr></table> diff --git a/docs/_build/html/modules.html b/docs/_build/html/modules.html deleted file mode 100644 index a1bf15a47e95fddfeda69bf11cd5d32742020290..0000000000000000000000000000000000000000 --- a/docs/_build/html/modules.html +++ /dev/null @@ -1,131 +0,0 @@ - -<!DOCTYPE html> - -<html> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>Modules — PySegCNN documentation</title> - <link rel="stylesheet" href="_static/alabaster.css" type="text/css" /> - <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> - <script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script> - <script src="_static/jquery.js"></script> - <script src="_static/underscore.js"></script> - <script src="_static/doctools.js"></script> - <script src="_static/language_data.js"></script> - <link rel="index" title="Index" href="genindex.html" /> - <link rel="search" title="Search" href="search.html" /> - <link rel="next" title="pysegcnn.core.cli" href="modules/pysegcnn.core.cli.html" /> - <link rel="prev" title="PySegCNN: Image segmentation with convolutional neural networks in Python" href="index.html" /> - - <link rel="stylesheet" href="_static/custom.css" type="text/css" /> - - - <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" /> - - </head><body> - - - <div class="document"> - <div class="documentwrapper"> - <div class="bodywrapper"> - - - <div class="body" role="main"> - - <div class="section" id="modules"> -<h1>Modules<a class="headerlink" href="#modules" title="Permalink to this headline">¶</a></h1> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="modules/pysegcnn.core.cli.html#module-pysegcnn.core.cli" title="pysegcnn.core.cli"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pysegcnn.core.cli</span></code></a></p></td> -<td><p>Command line interface parsers.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="modules/pysegcnn.core.constants.html#module-pysegcnn.core.constants" title="pysegcnn.core.constants"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pysegcnn.core.constants</span></code></a></p></td> -<td><p>A collection of constant values.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="modules/pysegcnn.core.dataset.html#module-pysegcnn.core.dataset" title="pysegcnn.core.dataset"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pysegcnn.core.dataset</span></code></a></p></td> -<td><p>Custom dataset classes compliant to the PyTorch standard.</p></td> -</tr> -</tbody> -</table> -</div> - - - </div> - - </div> - </div> - <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> - <div class="sphinxsidebarwrapper"> -<h1 class="logo"><a href="index.html">PySegCNN</a></h1> - - - - - - - - -<h3>Navigation</h3> -<p class="caption"><span class="caption-text">Table of contents:</span></p> -<ul class="current"> -<li class="toctree-l1 current"><a class="current reference internal" href="#">Modules</a><ul> -<li class="toctree-l2"><a class="reference internal" href="modules/pysegcnn.core.cli.html">pysegcnn.core.cli</a></li> -<li class="toctree-l2"><a class="reference internal" href="modules/pysegcnn.core.constants.html">pysegcnn.core.constants</a></li> -<li class="toctree-l2"><a class="reference internal" href="modules/pysegcnn.core.dataset.html">pysegcnn.core.dataset</a></li> -</ul> -</li> -</ul> - -<div class="relations"> -<h3>Related Topics</h3> -<ul> - <li><a href="index.html">Documentation overview</a><ul> - <li>Previous: <a href="index.html" title="previous chapter">PySegCNN: Image segmentation with convolutional neural networks in Python</a></li> - <li>Next: <a href="modules/pysegcnn.core.cli.html" title="next chapter">pysegcnn.core.cli</a></li> - </ul></li> -</ul> -</div> -<div id="searchbox" style="display: none" role="search"> - <h3 id="searchlabel">Quick search</h3> - <div class="searchformwrapper"> - <form class="search" action="search.html" method="get"> - <input type="text" name="q" aria-labelledby="searchlabel" /> - <input type="submit" value="Go" /> - </form> - </div> -</div> -<script>$('#searchbox').show(0);</script> - - - - - - - - - </div> - </div> - <div class="clearer"></div> - </div> - <div class="footer"> - ©2020, Daniel Frisinghelli. - - | - Powered by <a href="http://sphinx-doc.org/">Sphinx 3.2.1</a> - & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a> - - | - <a href="_sources/modules.rst.txt" - rel="nofollow">Page source</a> - </div> - - - - - </body> -</html> \ No newline at end of file diff --git a/docs/_build/html/modules/pysegcnn.core.cli.html b/docs/_build/html/modules/pysegcnn.core.cli.html deleted file mode 100644 index 9c3e68b4583f7cb1bbb0253ee557bbe44a5b268d..0000000000000000000000000000000000000000 --- a/docs/_build/html/modules/pysegcnn.core.cli.html +++ /dev/null @@ -1,137 +0,0 @@ - -<!DOCTYPE html> - -<html> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>pysegcnn.core.cli — PySegCNN documentation</title> - <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" /> - <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> - <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> - <script src="../_static/jquery.js"></script> - <script src="../_static/underscore.js"></script> - <script src="../_static/doctools.js"></script> - <script src="../_static/language_data.js"></script> - <link rel="index" title="Index" href="../genindex.html" /> - <link rel="search" title="Search" href="../search.html" /> - <link rel="next" title="pysegcnn.core.constants" href="pysegcnn.core.constants.html" /> - <link rel="prev" title="Modules" href="../modules.html" /> - - <link rel="stylesheet" href="../_static/custom.css" type="text/css" /> - - - <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" /> - - </head><body> - - - <div class="document"> - <div class="documentwrapper"> - <div class="bodywrapper"> - - - <div class="body" role="main"> - - <div class="section" id="module-pysegcnn.core.cli"> -<span id="pysegcnn-core-cli"></span><h1>pysegcnn.core.cli<a class="headerlink" href="#module-pysegcnn.core.cli" title="Permalink to this headline">¶</a></h1> -<p>Command line interface parsers.</p> -<div class="section" id="license"> -<h2>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h2> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<p class="rubric">Functions</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">structure_parser</span></code>()</p></td> -<td><p>Command line argument parser to standardize dataset structure.</p></td> -</tr> -</tbody> -</table> -</div> -</div> - - - </div> - - </div> - </div> - <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> - <div class="sphinxsidebarwrapper"> -<h1 class="logo"><a href="../index.html">PySegCNN</a></h1> - - - - - - - - -<h3>Navigation</h3> -<p class="caption"><span class="caption-text">Table of contents:</span></p> -<ul class="current"> -<li class="toctree-l1 current"><a class="reference internal" href="../modules.html">Modules</a><ul class="current"> -<li class="toctree-l2 current"><a class="current reference internal" href="#">pysegcnn.core.cli</a></li> -<li class="toctree-l2"><a class="reference internal" href="pysegcnn.core.constants.html">pysegcnn.core.constants</a></li> -<li class="toctree-l2"><a class="reference internal" href="pysegcnn.core.dataset.html">pysegcnn.core.dataset</a></li> -</ul> -</li> -</ul> - -<div class="relations"> -<h3>Related Topics</h3> -<ul> - <li><a href="../index.html">Documentation overview</a><ul> - <li><a href="../modules.html">Modules</a><ul> - <li>Previous: <a href="../modules.html" title="previous chapter">Modules</a></li> - <li>Next: <a href="pysegcnn.core.constants.html" title="next chapter">pysegcnn.core.constants</a></li> - </ul></li> - </ul></li> -</ul> -</div> -<div id="searchbox" style="display: none" role="search"> - <h3 id="searchlabel">Quick search</h3> - <div class="searchformwrapper"> - <form class="search" action="../search.html" method="get"> - <input type="text" name="q" aria-labelledby="searchlabel" /> - <input type="submit" value="Go" /> - </form> - </div> -</div> -<script>$('#searchbox').show(0);</script> - - - - - - - - - </div> - </div> - <div class="clearer"></div> - </div> - <div class="footer"> - ©2020, Daniel Frisinghelli. - - | - Powered by <a href="http://sphinx-doc.org/">Sphinx 3.2.1</a> - & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a> - - | - <a href="../_sources/modules/pysegcnn.core.cli.rst.txt" - rel="nofollow">Page source</a> - </div> - - - - - </body> -</html> \ No newline at end of file diff --git a/docs/_build/html/modules/pysegcnn.core.constants.html b/docs/_build/html/modules/pysegcnn.core.constants.html deleted file mode 100644 index 84a61dffd38c1cf0da63b66db2a9ff1467bbb52f..0000000000000000000000000000000000000000 --- a/docs/_build/html/modules/pysegcnn.core.constants.html +++ /dev/null @@ -1,152 +0,0 @@ - -<!DOCTYPE html> - -<html> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>pysegcnn.core.constants — PySegCNN documentation</title> - <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" /> - <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> - <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> - <script src="../_static/jquery.js"></script> - <script src="../_static/underscore.js"></script> - <script src="../_static/doctools.js"></script> - <script src="../_static/language_data.js"></script> - <link rel="index" title="Index" href="../genindex.html" /> - <link rel="search" title="Search" href="../search.html" /> - <link rel="next" title="pysegcnn.core.dataset" href="pysegcnn.core.dataset.html" /> - <link rel="prev" title="pysegcnn.core.cli" href="pysegcnn.core.cli.html" /> - - <link rel="stylesheet" href="../_static/custom.css" type="text/css" /> - - - <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" /> - - </head><body> - - - <div class="document"> - <div class="documentwrapper"> - <div class="bodywrapper"> - - - <div class="body" role="main"> - - <div class="section" id="module-pysegcnn.core.constants"> -<span id="pysegcnn-core-constants"></span><h1>pysegcnn.core.constants<a class="headerlink" href="#module-pysegcnn.core.constants" title="Permalink to this headline">¶</a></h1> -<p>A collection of constant values.</p> -<div class="section" id="license"> -<h2>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h2> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<p class="rubric">Classes</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Cloud95Labels</span></code>(value)</p></td> -<td><p>Class labels of the <a href="#id1"><span class="problematic" id="id2">`Cloud-95`_</span></a> dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Label</span></code>(value)</p></td> -<td><p>Generic enumeration for class labels.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Landsat8</span></code>(value)</p></td> -<td><p>The spectral bands of the Landsat 8 sensors.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">ProSnowLabels</span></code>(value)</p></td> -<td><p>Class labels of the ProSnow datasets.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Sentinel2</span></code>(value)</p></td> -<td><p>The spectral bands of the Sentinel-2 MultiSpectral Instrument (MSI).</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">SparcsLabels</span></code>(value)</p></td> -<td><p>Class labels of the <a href="#id3"><span class="problematic" id="id4">`Sparcs`_</span></a> dataset.</p></td> -</tr> -</tbody> -</table> -</div> -</div> - - - </div> - - </div> - </div> - <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> - <div class="sphinxsidebarwrapper"> -<h1 class="logo"><a href="../index.html">PySegCNN</a></h1> - - - - - - - - -<h3>Navigation</h3> -<p class="caption"><span class="caption-text">Table of contents:</span></p> -<ul class="current"> -<li class="toctree-l1 current"><a class="reference internal" href="../modules.html">Modules</a><ul class="current"> -<li class="toctree-l2"><a class="reference internal" href="pysegcnn.core.cli.html">pysegcnn.core.cli</a></li> -<li class="toctree-l2 current"><a class="current reference internal" href="#">pysegcnn.core.constants</a></li> -<li class="toctree-l2"><a class="reference internal" href="pysegcnn.core.dataset.html">pysegcnn.core.dataset</a></li> -</ul> -</li> -</ul> - -<div class="relations"> -<h3>Related Topics</h3> -<ul> - <li><a href="../index.html">Documentation overview</a><ul> - <li><a href="../modules.html">Modules</a><ul> - <li>Previous: <a href="pysegcnn.core.cli.html" title="previous chapter">pysegcnn.core.cli</a></li> - <li>Next: <a href="pysegcnn.core.dataset.html" title="next chapter">pysegcnn.core.dataset</a></li> - </ul></li> - </ul></li> -</ul> -</div> -<div id="searchbox" style="display: none" role="search"> - <h3 id="searchlabel">Quick search</h3> - <div class="searchformwrapper"> - <form class="search" action="../search.html" method="get"> - <input type="text" name="q" aria-labelledby="searchlabel" /> - <input type="submit" value="Go" /> - </form> - </div> -</div> -<script>$('#searchbox').show(0);</script> - - - - - - - - - </div> - </div> - <div class="clearer"></div> - </div> - <div class="footer"> - ©2020, Daniel Frisinghelli. - - | - Powered by <a href="http://sphinx-doc.org/">Sphinx 3.2.1</a> - & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a> - - | - <a href="../_sources/modules/pysegcnn.core.constants.rst.txt" - rel="nofollow">Page source</a> - </div> - - - - - </body> -</html> \ No newline at end of file diff --git a/docs/_build/html/modules/pysegcnn.core.dataset.html b/docs/_build/html/modules/pysegcnn.core.dataset.html deleted file mode 100644 index f80679b0ed647d09a4f947089dc1b62aaebc5c97..0000000000000000000000000000000000000000 --- a/docs/_build/html/modules/pysegcnn.core.dataset.html +++ /dev/null @@ -1,161 +0,0 @@ - -<!DOCTYPE html> - -<html> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>pysegcnn.core.dataset — PySegCNN documentation</title> - <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" /> - <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> - <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> - <script src="../_static/jquery.js"></script> - <script src="../_static/underscore.js"></script> - <script src="../_static/doctools.js"></script> - <script src="../_static/language_data.js"></script> - <link rel="index" title="Index" href="../genindex.html" /> - <link rel="search" title="Search" href="../search.html" /> - <link rel="prev" title="pysegcnn.core.constants" href="pysegcnn.core.constants.html" /> - - <link rel="stylesheet" href="../_static/custom.css" type="text/css" /> - - - <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" /> - - </head><body> - - - <div class="document"> - <div class="documentwrapper"> - <div class="bodywrapper"> - - - <div class="body" role="main"> - - <div class="section" id="module-pysegcnn.core.dataset"> -<span id="pysegcnn-core-dataset"></span><h1>pysegcnn.core.dataset<a class="headerlink" href="#module-pysegcnn.core.dataset" title="Permalink to this headline">¶</a></h1> -<p>Custom dataset classes compliant to the PyTorch standard.</p> -<p>Each custom dataset should inherit from torch.utils.data.Dataset to benefit -from the torch.utils.data.DataLoader class, which implements helpful utilities -during model training.</p> -<p>For any kind of image-like dataset, inherit the ImageDataset class to create -your custom dataset.</p> -<div class="section" id="license"> -<h2>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h2> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<p class="rubric">Classes</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Cloud95Dataset</span></code>(root_dir[, use_bands, …])</p></td> -<td><p>Class for the <a href="#id3"><span class="problematic" id="id4">`Cloud-95`_</span></a> dataset by <a href="#id1"><span class="problematic" id="id2">`</span></a>Mohajerani et al.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">ImageDataset</span></code>(root_dir[, use_bands, …])</p></td> -<td><p>Base class for multispectral image data.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">ProSnowDataset</span></code>(root_dir[, use_bands, …])</p></td> -<td><p>Class for the ProSnow datasets.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">ProSnowGarmisch</span></code>(root_dir[, use_bands, …])</p></td> -<td><p>Class for the ProSnow Garmisch dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">ProSnowObergurgl</span></code>(root_dir[, use_bands, …])</p></td> -<td><p>Class for the ProSnow Obergurgl dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">SparcsDataset</span></code>(root_dir[, use_bands, …])</p></td> -<td><p>Class for the <a href="#id5"><span class="problematic" id="id6">`Sparcs`_</span></a> dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">StandardEoDataset</span></code>(root_dir[, use_bands, …])</p></td> -<td><p>Base class for standard Earth Observation style datasets.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">SupportedDatasets</span></code>(value)</p></td> -<td><p>Names and corresponding classes of the implemented datasets.</p></td> -</tr> -</tbody> -</table> -</div> -</div> - - - </div> - - </div> - </div> - <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> - <div class="sphinxsidebarwrapper"> -<h1 class="logo"><a href="../index.html">PySegCNN</a></h1> - - - - - - - - -<h3>Navigation</h3> -<p class="caption"><span class="caption-text">Table of contents:</span></p> -<ul class="current"> -<li class="toctree-l1 current"><a class="reference internal" href="../modules.html">Modules</a><ul class="current"> -<li class="toctree-l2"><a class="reference internal" href="pysegcnn.core.cli.html">pysegcnn.core.cli</a></li> -<li class="toctree-l2"><a class="reference internal" href="pysegcnn.core.constants.html">pysegcnn.core.constants</a></li> -<li class="toctree-l2 current"><a class="current reference internal" href="#">pysegcnn.core.dataset</a></li> -</ul> -</li> -</ul> - -<div class="relations"> -<h3>Related Topics</h3> -<ul> - <li><a href="../index.html">Documentation overview</a><ul> - <li><a href="../modules.html">Modules</a><ul> - <li>Previous: <a href="pysegcnn.core.constants.html" title="previous chapter">pysegcnn.core.constants</a></li> - </ul></li> - </ul></li> -</ul> -</div> -<div id="searchbox" style="display: none" role="search"> - <h3 id="searchlabel">Quick search</h3> - <div class="searchformwrapper"> - <form class="search" action="../search.html" method="get"> - <input type="text" name="q" aria-labelledby="searchlabel" /> - <input type="submit" value="Go" /> - </form> - </div> -</div> -<script>$('#searchbox').show(0);</script> - - - - - - - - - </div> - </div> - <div class="clearer"></div> - </div> - <div class="footer"> - ©2020, Daniel Frisinghelli. - - | - Powered by <a href="http://sphinx-doc.org/">Sphinx 3.2.1</a> - & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a> - - | - <a href="../_sources/modules/pysegcnn.core.dataset.rst.txt" - rel="nofollow">Page source</a> - </div> - - - - - </body> -</html> \ No newline at end of file diff --git a/docs/_build/html/objects.inv b/docs/_build/html/objects.inv index 3e4fffbf2f1c6de6f65ee83cfcdc7726224a294e..79d2d2a07a6c0f2a6e41a623d9c9a89486f6cb12 100644 Binary files a/docs/_build/html/objects.inv and b/docs/_build/html/objects.inv differ diff --git a/docs/_build/html/py-modindex.html b/docs/_build/html/py-modindex.html deleted file mode 100644 index 856c1bb9aff4d406a37adf59cc90b2e41352dabd..0000000000000000000000000000000000000000 --- a/docs/_build/html/py-modindex.html +++ /dev/null @@ -1,227 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>Python Module Index — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script> - <script src="_static/jquery.js"></script> - <script src="_static/underscore.js"></script> - <script src="_static/doctools.js"></script> - <script src="_static/language_data.js"></script> - - <script type="text/javascript" src="_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="genindex.html" /> - <link rel="search" title="Search" href="search.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" > - - - - <a href="index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul> -<li class="toctree-l1"><a class="reference internal" href="source/requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="source/installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="source/api.html">API Reference</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="index.html" class="icon icon-home"></a> »</li> - - <li>Python Module Index</li> - - - <li class="wy-breadcrumbs-aside"> - - </li> - - </ul> - - - <hr/> -</div> - <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> - <div itemprop="articleBody"> - - - <h1>Python Module Index</h1> - - <div class="modindex-jumpbox"> - <a href="#cap-p"><strong>p</strong></a> - </div> - - <table class="indextable modindextable"> - <tr class="pcap"><td></td><td> </td><td></td></tr> - <tr class="cap" id="cap-p"><td></td><td> - <strong>p</strong></td><td></td></tr> - <tr> - <td><img src="_static/minus.png" class="toggler" - id="toggle-1" style="display: none" alt="-" /></td> - <td> - <code class="xref">pysegcnn</code></td><td> - <em></em></td></tr> - <tr class="cg-1"> - <td></td> - <td>    - <a href="source/generated/pysegcnn.core.layers.html#module-pysegcnn.core.layers"><code class="xref">pysegcnn.core.layers</code></a></td><td> - <em></em></td></tr> - <tr class="cg-1"> - <td></td> - <td>    - <a href="source/generated/pysegcnn.core.models.html#module-pysegcnn.core.models"><code class="xref">pysegcnn.core.models</code></a></td><td> - <em></em></td></tr> - </table> - - - </div> - - </div> - <footer> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/readme.html b/docs/_build/html/readme.html deleted file mode 100644 index 6e6adb7bff4e577fc262f79a0549041d5ea71569..0000000000000000000000000000000000000000 --- a/docs/_build/html/readme.html +++ /dev/null @@ -1,209 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>Test — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script> - <script src="_static/jquery.js"></script> - <script src="_static/underscore.js"></script> - <script src="_static/doctools.js"></script> - <script src="_static/language_data.js"></script> - - <script type="text/javascript" src="_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="genindex.html" /> - <link rel="search" title="Search" href="search.html" /> - <link rel="prev" title="<no title>" href="index.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" > - - - - <a href="index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul class="current"> -<li class="toctree-l1 current"><a class="current reference internal" href="#">Test</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="index.html" class="icon icon-home"></a> »</li> - - <li>Test</li> - - - <li class="wy-breadcrumbs-aside"> - - - <a href="_sources/readme.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"> - - <div class="section" id="test"> -<h1>Test<a class="headerlink" href="#test" title="Permalink to this headline">¶</a></h1> -</div> - - - </div> - - </div> - <footer> - - <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - - - <a href="index.html" class="btn btn-neutral float-left" title="<no title>" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> - - </div> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/searchindex.js b/docs/_build/html/searchindex.js index 9287d508bccdc684e700fd3060e6c75678d7f34d..121f50fd6d65dbf40b337319ced81e981d6a4381 100644 --- a/docs/_build/html/searchindex.js +++ b/docs/_build/html/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["index","source/api","source/generated/pysegcnn.core.dataset.Cloud95Dataset","source/generated/pysegcnn.core.dataset.ImageDataset","source/generated/pysegcnn.core.dataset.SparcsDataset","source/generated/pysegcnn.core.layers.Block","source/generated/pysegcnn.core.layers.Conv2dSame","source/generated/pysegcnn.core.layers.ConvBnReluMaxPool","source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool","source/generated/pysegcnn.core.layers.ConvBnReluUpsample","source/generated/pysegcnn.core.layers.Decoder","source/generated/pysegcnn.core.layers.DecoderBlock","source/generated/pysegcnn.core.layers.Encoder","source/generated/pysegcnn.core.layers.EncoderBlock","source/generated/pysegcnn.core.models.Network","source/generated/pysegcnn.core.models.UNet","source/installation","source/requirements"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":3,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":2,"sphinx.domains.rst":2,"sphinx.domains.std":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["index.rst","source\\api.rst","source\\generated\\pysegcnn.core.dataset.Cloud95Dataset.rst","source\\generated\\pysegcnn.core.dataset.ImageDataset.rst","source\\generated\\pysegcnn.core.dataset.SparcsDataset.rst","source\\generated\\pysegcnn.core.layers.Block.rst","source\\generated\\pysegcnn.core.layers.Conv2dSame.rst","source\\generated\\pysegcnn.core.layers.ConvBnReluMaxPool.rst","source\\generated\\pysegcnn.core.layers.ConvBnReluMaxUnpool.rst","source\\generated\\pysegcnn.core.layers.ConvBnReluUpsample.rst","source\\generated\\pysegcnn.core.layers.Decoder.rst","source\\generated\\pysegcnn.core.layers.DecoderBlock.rst","source\\generated\\pysegcnn.core.layers.Encoder.rst","source\\generated\\pysegcnn.core.layers.EncoderBlock.rst","source\\generated\\pysegcnn.core.models.Network.rst","source\\generated\\pysegcnn.core.models.UNet.rst","source\\installation.rst","source\\requirements.rst"],objects:{"pysegcnn.core.dataset":{Cloud95Dataset:[2,0,1,""],ImageDataset:[3,0,1,""],SparcsDataset:[4,0,1,""]},"pysegcnn.core.dataset.Cloud95Dataset":{__init__:[2,1,1,""]},"pysegcnn.core.dataset.ImageDataset":{__init__:[3,1,1,""]},"pysegcnn.core.dataset.SparcsDataset":{__init__:[4,1,1,""]},"pysegcnn.core.layers":{Block:[5,0,1,""],Conv2dSame:[6,0,1,""],ConvBnReluMaxPool:[7,0,1,""],ConvBnReluMaxUnpool:[8,0,1,""],ConvBnReluUpsample:[9,0,1,""],Decoder:[10,0,1,""],DecoderBlock:[11,0,1,""],Encoder:[12,0,1,""],EncoderBlock:[13,0,1,""]},"pysegcnn.core.layers.Block":{__init__:[5,1,1,""]},"pysegcnn.core.layers.Conv2dSame":{__init__:[6,1,1,""]},"pysegcnn.core.layers.ConvBnReluMaxPool":{__init__:[7,1,1,""]},"pysegcnn.core.layers.ConvBnReluMaxUnpool":{__init__:[8,1,1,""]},"pysegcnn.core.layers.ConvBnReluUpsample":{__init__:[9,1,1,""]},"pysegcnn.core.layers.Decoder":{__init__:[10,1,1,""]},"pysegcnn.core.layers.DecoderBlock":{__init__:[11,1,1,""]},"pysegcnn.core.layers.Encoder":{__init__:[12,1,1,""]},"pysegcnn.core.layers.EncoderBlock":{__init__:[13,1,1,""]},"pysegcnn.core.models":{Network:[14,0,1,""],UNet:[15,0,1,""]},"pysegcnn.core.models.Network":{__init__:[14,1,1,""]},"pysegcnn.core.models.UNet":{__init__:[15,1,1,""]}},objnames:{"0":["py","class","Python class"],"1":["py","method","Python method"]},objtypes:{"0":"py:class","1":"py:method"},terms:{"001":[],"08768":[],"10077":[],"1901":[],"2001":[],"2014":[],"2019":[],"2020":2,"2072":[],"2x2":[7,8,15],"4292":[],"4907":[],"case":16,"class":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"default":[2,3,4,16],"enum":[],"final":16,"float":[],"function":1,"import":16,"int":[2,3,4,5,6,7,8,9,10,11,12,13,15],"new":14,"public":0,"return":[2,3,4,5,6,7,8,9,10,11,12,13,14,15],"static":[],"true":[2,3,4,10],"var":[],"while":[0,16],And:17,For:[0,2,3,4],NOT:[],Not:[],The:[0,1,2,3,4,10,12,14,16],These:[],Use:[],Used:[2,3,4],Useful:[2,3,4],__call__:[5,6,7,8,9,10,11,12,13,14,15],__init__:[2,3,4,5,6,7,8,9,10,11,12,13,14,15],_earli:[],_equat:[],_graphic:[],_model:[],_mtl:[],_sampl:[],_subplot:[],_torch:6,abl:16,about:[],abov:16,abs:[],access:[],accord:[],accur:[2,3,4],accuraci:[],accuracy_funct:[],acknowledg:[],activ:16,adam:[],add:16,added:[],addit:[5,6,7,8,9,10,11,12,13,15],adjust:[],advanc:[],aerosol:[],after:16,algorithm:[],all:[2,3,4,16,17],along:[],alpha:[],also:[],altern:16,among:[],amount:[],angl:[],ani:16,api:0,append:[],appli:[10,15],arbitrari:[],architechur:[10,12],architectur:1,archiv:[],arg:6,argument:[5,6,7,8,9,10,11,12,13,15],arrai:[],array_lik:[],artifici:[],arxiv:[],aspx:[],assertionerror:[],assum:[],atmopsher:[],atmospher:[],attribut:[5,6,7,8,9,10,11,12,13,14,15],augment:[2,3,4],autom:[],avail:1,axes:[],axessubplot:[],axi:[],band:[2,3,4],band_1:[],band_2:[],band_n:[],band_name_1:[],band_name_2:[],band_name_n:[],base:[0,3,14],baseconfig:[],bash:[],basic:5,batch:15,batch_siz:[],batchnorm:[7,8,9],befor:[],beginn:[],belong:[],below:16,benefit:[],best:[],better:[],bia:[],blob:[],block:[7,8,9,10,11,12,13,15],blue:[],bolzano:0,bool:[2,3,4,10,15],both:[5,6,7,8,9,10,11,12,13,14,15,17],bottom:[],box:1,bright:[],build:[0,1,16,17],build_sampl:[],cach:[],calcul:6,calibr:[],call:[],can:[16,17],care:17,ccisnow:16,center:[2,3,4],centimet:[],chang:[],channel:[5,6,7,8,9,10,11,12,13,15,16],check:[],check_tile_extend:[],checkpoint:[],checkpoint_st:[],chronolog:[2,3,4],cirru:[],classif:[],classifi:[],clear:[],cli:[],clone:16,cloud95:[],cloud95dataset:[],cloud95label:[],cloud:2,cmap:[],code:[0,16],collect:[],color:[],colormap:[],column:[],com:0,command:16,common:[],complet:[],compliant:[1,3],compos:[2,3,4],compose_scen:[],composit:[],compsit:[],comput:[],concaten:[],conda:17,conf_mat:[],config:16,configur:[],confus:[],connect:[10,15],consid:[],constant:[2,3,4],constrast:[],construct:[],contact:[],contain:[],content:[],contrast:[],contrast_stretch:[],contributor:[],control:[],conv2d:6,conv2dsam:[5,7,8,9,10,11,12,13,15],conv:[],conv_bn_relu:[],convbnrelumaxpool:12,convbnrelumaxunpool:10,convbnreluupsampl:[],convent:[2,3,4],convers:[],convert:[],convolut:[1,5,6,7,8,9,10,11,12,13,15],convolv:6,copi:16,copyright:[],core:[],corner:[],correctli:[],correspond:[2,3,4],counter:[],cpu:[],creat:16,criterion:[],crossentropi:[],crossentropyloss:[],cuda:[],current:16,custom:1,customsubset:[],cval:[],dai:[],daniel:0,darkblu:[],data:[2,3,4],data_loading_tutori:[],dataclass:[],dataload:3,dataset:[],dataset_config:[],dataset_nam:[],datasetconfig:[],date:[],date_scene_split:[],dateformat:[],datesplit:[],datetim:[],decod:[11,12,15],decoderblock:10,decreas:[],deep:0,defaul:[],defin:[10,12,16],degre:[],delta:[],depend:16,depth:[10,12],descent:[],describ:[],descript:[],design:0,destack:[],destack_tiff:[],detail:[],determin:[10,12],develop:0,dict:[5,6,7,8,9,10,11,12,13,15],dictconfig:[],dictionari:[],did:[],digit:[],digiti:[],dilat:6,dimens:6,directli:[],directori:[2,3,4,16],disabl:[],disjoint:[],disk:[],distinct:[2,3,4],distribut:[],divid:[2,3,4],divis:[2,3,4],doc:6,document:17,doe:5,doi:[],download:[],downsampl:[],doy2dat:[],drop:[],dtype:[],dure:3,each:[2,3,4,10,12,14,15],earli:[],early_stop:[],earlystop:[],earth:0,easili:[],edu:[],either:[],element:[10,12],els:[],empti:[],enabl:3,enc_cach:[],encod:[10,13,15],encoderblock:12,end:[],entir:[],enumer:[],env:16,environ:17,epoch:[],equal:[],equat:[],error:[],etc:[],eurac:0,eval:[],eval_config:[],evalconfig:[],evalu:[],evenli:[2,3,4],exampl:[10,12],exce:[],except:16,exclud:[],exist:[],explicitli:0,express:[2,3,4],extend:[],extens:[],extra:[],extra_repr:[],extract:[],extract_arch:[],factor:[],factori:[],fals:[2,3,4],fcc:[],featur:[],feed:[],fifth:[],fig:[],figsiz:[],figur:[],file:[2,3,4,14,15,16,17],filenam:[],filenotfounderror:[],filter:[10,12,15],first:[10,12,16],fit:[],flip:[],fliplr:[],flipud:[],flood:[],folder:[],follow:[1,15,16],forg:16,format:[],forward:6,found:[],four:[],fraction:[],framework:0,freez:[],frisinghelli:0,from:[3,10,15,16],fulli:0,further:0,furthermor:3,futur:0,garmisch:[],gaussian:[],gdal:17,gener:[0,1,2,3,4,6,10,12,14],get:[],get_label:[],get_num_thread:[],get_radiometric_const:[],get_sensor:[],get_siz:[],git:16,github:[],gitlab:16,given:6,gmail:0,gnu:0,gov:[],gradient:[],graphic:[],greater:[],green:[],grei:[],ground:[2,3,4],group:[],gt_pattern:[2,3,4],guid:16,handi:3,handl:[],hardwar:16,has:[6,10,12],have:16,hay:[],heavili:16,height:[],help:[2,3,4],here:[16,17],horizont:[],host:[],how:[],howev:[],html:6,http:[6,16],hugh:[],idea:0,identifi:[],ids:[],idx:[],imag:[2,3,4,10,12,15],imagedataset:[],imageri:0,img2np:[],img_siz:[],implement:[1,10,12,14,15],improv:[],in_channel:[5,6,7,8,9,11,13,15],includ:[],increas:[],index:[],indic:[],inf:16,infer:[],inform:0,infrar:[],inherit:[3,14],init_dataset:[],init_log:[],init_loss_funct:[],init_model:[],init_optim:[],init_st:[],init_str:[],initi:[2,3,4,5,6,7,8,9,10,11,12,13,14,15],initili:[],inpath:[],input:[2,3,4,5,6,7,8,9,10,11,12,13,15],instal:[0,17],instanc:[2,3,4,5],instanci:[10,12],instead:[],institut:0,instruct:16,instrument:[],integ:[],interfac:[],intermedi:[],intern:[5,6,7,8,9,10,11,12,13,14,15],interpol:[],interpret:16,invari:[],invarianttransform:[],is_divis:[],item:[2,3,4],item_in_enum:[],its:6,kei:[],kernel:6,kernel_s:6,keyword:[6,7,8,15],kind:[],kwarg:[5,6,7,8,9,10,11,12,13,15],label:[2,3,4],land:[],landsat8:[],landsat:[],landsat_radiometric_calibr:[],last:[],later:[],latest:[],launch:[],layer:15,learn:0,left:[],len:[],length:[10,12],level:[],licens:[],lightblu:[],lightgreen:[],like:[],line:16,linear:[],linux:17,list:[1,2,3,4,6,10,12,15,17],load:[],load_checkpoint:[],loader:[],local:[],log:[],log_conf:[],logconfig:[],logfil:[],logging_config:[],loss:[],loss_funct:[],loss_nam:[],machin:[0,16],mai:16,main:[],mainli:[],make:[],manag:[],master:[],match:[2,3,4],matplotlib:17,matrix:[],max:[7,8,15],max_pool2d:[],max_unpool2d:[],maxima:[],maximum:[],mdpi:[],mean:[],measur:[],met:[],metadata:[],method:[2,3,4,5,6,7,8,9,10,11,12,13,14,15],metric:[],min:[],min_delta:[],mini:[],miniconda:[],minimum:[],mode:[],model:[3,10,12],model_config:[],model_dataset_optimizer_splitmode_splitparams_tilesize_batchsize_band:[],model_nam:[],model_st:[],modelconfig:[],modifi:15,modul:[5,6,7,8,9,10,11,12,13,14,15],mohajerani:2,more:[],mountain:[],move:[],msi:[],multispectr:[0,1,3],name:[2,3,4,16],navig:16,nclass:15,ncol:[],ndarrai:[],nearest:9,need:[],neighbor:9,nest:[],net:15,network:[],networktrain:[],neural:[],nir:[],nli:[],nnir:[],nois:[],none:[2,3,4,5,6,7,8,9,10,11,12,13,14,15],norm:[],normal:15,note:[],notimplementederror:[],now:[],nrow:[],nthread:[],ntile:[],number:[5,6,7,8,9,10,11,12,13,15],numpi:17,obergurgl:[],object:[],observ:0,offici:16,oli:[],onc:16,one:[],onli:[2,3,4],open:1,oper:15,optim:[],optim_nam:[],option:[2,3,4],order:[],org:6,origin:[2,3,4],otherwis:0,out:1,out_channel:[5,6,7,8,9,11,13],outpath:[],output:[5,6,7,8,9,11,13],output_pad:[],over:[],overwrit:[],overwritten:[],packag:[0,17],pad:[2,3,4,6],padding_mod:[],page:1,pair:[],pairwis:[],pairwise_disjoint:[],pan:[],paramet:[2,3,4,5,6,7,8,9,10,11,12,13,15],pars:[],parse_landsat_scen:[],parse_scene_id:[],parse_sentinel2_scen:[],parser:[],part:0,pass:[5,6,7,8,9,10,11,12,13,15],path:[2,3,4],pathlib:[],patienc:[],pattern:[],percentil:[],perform:[],pip:16,pixel:[],plane:[],pleas:0,plot:[],plot_band:[],plot_confusion_matrix:[],plot_loss:[],plot_sampl:[],plot_scen:[],point:[],pool:7,posit:6,possibl:[],precis:[],predict:[],predict_sampl:[],predict_scen:[],preprocess:[],preserv:6,pretrain:[],pretrained_model:[],previou:[],primarili:0,print:[],probabl:[],procedur:[],process:[],product:[],project:[],propag:[],properti:[],prosnow:[],prosnowdataset:[],prosnowgarmisch:[],prosnowlabel:[],prosnowobergurgl:[],provid:16,publicli:[],pure:17,pyplot:[],pysegcnn:[1,17],pytest:17,python:[16,17],pytorch:[0,1,3,6,15,17],quit:[],radianc:[],radiometr:[],rais:5,random:[2,3,4],random_scene_split:[],random_tile_split:[],randomli:[],randomscenesplit:[],randomsplit:[],randomsubset:[],randomtilesplit:[],rate:[],ratio:[],raw:[],read:[],read_landsat_metadata:[],read_scen:[],readm:[],recal:[],recommend:16,reconstruct:[],reconstruct_scen:[],rectifi:[],red:[],refer:0,reflect:[],regur:[2,3,4],relu:[7,8,9],remain:[],remot:[],remov:[],remove_raw:[],remsen:16,repositori:[0,16],repres:[],represent:[],reproduc:[2,3,4],requir:[0,16],rescal:[],research:0,reset_paramet:6,reshap:[],resourc:[],respect:[],restructur:[],result:[],resum:[],retriev:[],right:[],root:[2,3,4,16],root_dir:[2,3,4],rotat:[],row:[],run:16,running_mean:[],saeedi:2,same:[6,10,12],same_pad:[],sampl:[2,3,4,16],satellit:0,save:[],save_st:[],scene:[2,3,4],scene_data:[],scene_id:[],scene_id_1:[],scene_id_1_b1:[],scene_id_1_b2:[],scene_id_1_bn:[],scene_id_2:[],scene_id_2_b1:[],scene_id_2_b2:[],scene_id_2_bn:[],scene_id_n:[],scenesubset:[],score:[],scratch:[],script:[],scriptmodul:[5,6,7,8,9,10,11,12,13,14,15],search:[2,3,4],see:[0,2,3,4,10,12,17],seed:[2,3,4],segment:[],self:[2,3,4],semant:0,sens:[],sensor:[],sentinel2:[],sentinel:[],sequenc:[],sequenti:5,seri:[2,3,4],set:[2,3,4],shadow:[],shadow_over_wat:[],shape:[2,3,4,6],share:[5,6,7,8,9,10,11,12,13,14,15],share_memori:[5,6,7,8,9,10,11,12,13,14,15],ship:17,should:[10,12,16],show:[],sienna:[],signatur:[2,3,4],simpli:[],singl:[],size:[2,3,4,6],skip:[10,15],skip_connect:[],skyblu:[],slightli:15,snow:[],snow_fre:[],some:16,sorourmo:[],sort:[2,3,4],sourc:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],source_path:[],spaceborn:1,sparc:4,sparcsdataset:[],sparcslabel:[],spatial:6,specif:16,specifi:[],speckl:[],spectral:[2,3,4],sphinx:17,sphinx_rtd_them:17,split:[2,3,4],split_config:[],split_mod:[],splitconfig:[],squar:[2,3,4],stabl:6,stack:[],standard:[1,3],standard_eo_structur:[],standardeodataset:[],start:[],state:[0,5,6,7,8,9,10,11,12,13,14,15],state_fil:[],stateconfig:[],steelblu:[],step:[],stop:[],store:[],str:[2,3,4,5,6,7,8,9,10,11,12,13,15],stretch:[],stride:6,string:[],strptime:[],structur:[],structure_pars:[],style:[],sub:[],subclass:[10,12],subdir:[],subdirectori:[2,3,4],submodul:[],subset:[],subset_typ:[],success:16,successfulli:16,suffix:[],sum:[],support:16,supporteddataset:[],supportedlossfunct:[],supportedmodel:[],supportedoptim:[],supportedsplit:[],sure:[],swir1:[],swir2:[],system:16,tabl:[],take:[16,17],target_path:[],task:[],temperatur:[],tensor:[],termin:16,test:[2,3,4],test_d:[],test_dl:[],text:[],than:[],thei:[],therefor:16,thermal:[],thi:[0,1,16],thread:[],threshold:[],tif:[2,3,4],tiff:[],tile:[2,3,4],tile_00:[],tile_01:[],tile_0n:[],tile_10:[],tile_11:[],tile_1n:[],tile_m0:[],tile_m1:[],tile_mn:[],tile_s:[2,3,4],tile_topleft_corn:[],time:[2,3,4],tir1:[],tir:[],to_tensor:[],toa_brt:[],toa_rad:[],toa_ref:[],togeth:[2,3,4],top:[],topleft:[],torch:[3,5,6],torch_se:[],total:[2,3,4],train:[2,3,4],train_d:[],train_dl:[],train_val_test_split:[],trainer:[],training_st:[],transfer:[],transfer_model:[],transform:[2,3,4],transpos:[],tree:[],truth:[2,3,4],ttratio:[],tupl:6,tutori:[],tvratio:[],two:[],txt:[],type:[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],typeerror:5,under:0,unet:[10,12],unfreez:[],unibz:16,union:[],unit:[],unpool:[8,15],untransform:[2,3,4],updat:[],upsampl:[9,15],usag:[],use:[2,3,4,16,17],use_band:[2,3,4],used:[2,3,4],useful:[],user:[],usg:[],using:[3,16,17],util:3,valid:[2,3,4],valid_d:[],valid_dl:[],valu:[2,3,4],valueerror:[],vapor:[],varianc:[],variant:[],varianttransform:[],verif:[],verifi:16,version:[2,3,4,15,16],vertic:[],violet:[],vnir1:[],vnir2:[],vnir3:[],wait:[],walkthrough:[],want:[14,17],water:[],websit:16,weight:[],when:[10,12],where:[],whether:[2,3,4,10,15],which:[],white:[],width:[],wiki:[],wikipedia:[],window:17,within:16,work:[0,17],worst:[],wrap:[],wrapper:[],write:[],wrote:0,www:[],y_pred:[],year:[],yellow:[],yml:[16,17],you:[14,16,17],your:16,yyyymmdd:[],zero:[2,3,4]},titles:["PySegCNN: Image segmentation with convolutional neural networks in Python","API Reference","pysegcnn.core.dataset.Cloud95Dataset","pysegcnn.core.dataset.ImageDataset","pysegcnn.core.dataset.SparcsDataset","pysegcnn.core.layers.Block","pysegcnn.core.layers.Conv2dSame","pysegcnn.core.layers.ConvBnReluMaxPool","pysegcnn.core.layers.ConvBnReluMaxUnpool","pysegcnn.core.layers.ConvBnReluUpsample","pysegcnn.core.layers.Decoder","pysegcnn.core.layers.DecoderBlock","pysegcnn.core.layers.Encoder","pysegcnn.core.layers.EncoderBlock","pysegcnn.core.models.Network","pysegcnn.core.models.UNet","Installation","Requirements"],titleterms:{Using:0,acknowledg:0,api:1,architechtur:1,block:5,cli:[],cloud95dataset:2,conda:16,config:[],constant:[],contact:0,content:[],contributor:0,conv2dsam:6,convbnrelumaxpool:7,convbnrelumaxunpool:8,convbnreluupsampl:9,convolut:0,core:[2,3,4,5,6,7,8,9,10,11,12,13,14,15],dataset:[1,2,3,4],decod:[1,10],decoderblock:11,depend:17,document:[],download:16,encod:[1,12],encoderblock:13,environ:16,eval:[],framework:17,graphic:[],imag:[0,1],imagedataset:3,instal:16,layer:[1,5,6,7,8,9,10,11,12,13],learn:17,licens:0,log:[],machin:17,main:[],manag:16,model:[1,14,15],modul:[],network:[0,1,14],neural:[0,1],packag:16,predict:[],preprocess:[],pysegcnn:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],python:0,pytorch:16,raster:17,readm:[],refer:1,requir:17,scipi:17,segment:0,sparc:[],sparcsdataset:4,split:[],stack:17,submodul:[],support:1,test:17,tool:17,train:[],trainer:[],transform:[],unet:15,util:[]}}) \ No newline at end of file +Search.setIndex({docnames:["index","source/api","source/generated/pysegcnn.core.dataset.Cloud95Dataset","source/generated/pysegcnn.core.dataset.ImageDataset","source/generated/pysegcnn.core.dataset.SparcsDataset","source/generated/pysegcnn.core.dataset.StandardEoDataset","source/generated/pysegcnn.core.layers.Block","source/generated/pysegcnn.core.layers.Conv2dSame","source/generated/pysegcnn.core.layers.ConvBnReluMaxPool","source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool","source/generated/pysegcnn.core.layers.ConvBnReluUpsample","source/generated/pysegcnn.core.layers.Decoder","source/generated/pysegcnn.core.layers.DecoderBlock","source/generated/pysegcnn.core.layers.Encoder","source/generated/pysegcnn.core.layers.EncoderBlock","source/generated/pysegcnn.core.models.Network","source/generated/pysegcnn.core.models.UNet","source/generated/pysegcnn.core.transforms.Augment","source/installation","source/requirements"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":3,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":2,"sphinx.domains.rst":2,"sphinx.domains.std":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["index.rst","source\\api.rst","source\\generated\\pysegcnn.core.dataset.Cloud95Dataset.rst","source\\generated\\pysegcnn.core.dataset.ImageDataset.rst","source\\generated\\pysegcnn.core.dataset.SparcsDataset.rst","source\\generated\\pysegcnn.core.dataset.StandardEoDataset.rst","source\\generated\\pysegcnn.core.layers.Block.rst","source\\generated\\pysegcnn.core.layers.Conv2dSame.rst","source\\generated\\pysegcnn.core.layers.ConvBnReluMaxPool.rst","source\\generated\\pysegcnn.core.layers.ConvBnReluMaxUnpool.rst","source\\generated\\pysegcnn.core.layers.ConvBnReluUpsample.rst","source\\generated\\pysegcnn.core.layers.Decoder.rst","source\\generated\\pysegcnn.core.layers.DecoderBlock.rst","source\\generated\\pysegcnn.core.layers.Encoder.rst","source\\generated\\pysegcnn.core.layers.EncoderBlock.rst","source\\generated\\pysegcnn.core.models.Network.rst","source\\generated\\pysegcnn.core.models.UNet.rst","source\\generated\\pysegcnn.core.transforms.Augment.rst","source\\installation.rst","source\\requirements.rst"],objects:{"pysegcnn.core.dataset":{Cloud95Dataset:[2,0,1,""],ImageDataset:[3,0,1,""],SparcsDataset:[4,0,1,""],StandardEoDataset:[5,0,1,""]},"pysegcnn.core.dataset.Cloud95Dataset":{__init__:[2,1,1,""]},"pysegcnn.core.dataset.ImageDataset":{__init__:[3,1,1,""]},"pysegcnn.core.dataset.SparcsDataset":{__init__:[4,1,1,""]},"pysegcnn.core.dataset.StandardEoDataset":{__init__:[5,1,1,""]},"pysegcnn.core.layers":{Block:[6,0,1,""],Conv2dSame:[7,0,1,""],ConvBnReluMaxPool:[8,0,1,""],ConvBnReluMaxUnpool:[9,0,1,""],ConvBnReluUpsample:[10,0,1,""],Decoder:[11,0,1,""],DecoderBlock:[12,0,1,""],Encoder:[13,0,1,""],EncoderBlock:[14,0,1,""]},"pysegcnn.core.layers.Block":{__init__:[6,1,1,""]},"pysegcnn.core.layers.Conv2dSame":{__init__:[7,1,1,""]},"pysegcnn.core.layers.ConvBnReluMaxPool":{__init__:[8,1,1,""]},"pysegcnn.core.layers.ConvBnReluMaxUnpool":{__init__:[9,1,1,""]},"pysegcnn.core.layers.ConvBnReluUpsample":{__init__:[10,1,1,""]},"pysegcnn.core.layers.Decoder":{__init__:[11,1,1,""]},"pysegcnn.core.layers.DecoderBlock":{__init__:[12,1,1,""]},"pysegcnn.core.layers.Encoder":{__init__:[13,1,1,""]},"pysegcnn.core.layers.EncoderBlock":{__init__:[14,1,1,""]},"pysegcnn.core.models":{Network:[15,0,1,""],UNet:[16,0,1,""]},"pysegcnn.core.models.Network":{__init__:[15,1,1,""]},"pysegcnn.core.models.UNet":{__init__:[16,1,1,""]},"pysegcnn.core.transforms":{Augment:[17,0,1,""]},"pysegcnn.core.transforms.Augment":{__init__:[17,1,1,""]}},objnames:{"0":["py","class","Python class"],"1":["py","method","Python method"]},objtypes:{"0":"py:class","1":"py:method"},terms:{"1x1":16,"2014":4,"2020":2,"2x2":[8,9,16],"case":18,"class":[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],"default":[2,3,4,5,18],"final":18,"function":1,"import":18,"int":[2,3,4,5,6,7,8,9,10,11,12,13,14,16],"new":15,"public":0,"return":[6,8,9,10,12,14,17],"true":[2,3,4,5,11],"while":[0,18],And:19,For:[0,2,3,4,5],The:[0,2,3,4,5,6,7,11,13,15,16,18],Used:[2,3,4,5],Useful:[2,3,4,5],__init__:[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],abl:18,abov:[5,18],accur:17,activ:18,add:18,addit:[6,7,8,9,10,11,12,13,14,16],after:18,all:[2,3,4,5,18,19],altern:18,amount:7,ani:18,api:0,appli:[11,16,17],architechur:[11,13],architectur:1,arg:7,argument:[6,7,8,9,10,11,12,13,14,16],attribut:[6,7,8,9,10,11,12,13,14,15,16],augment:[2,3,4,5],avail:1,band:[2,3,4,5],base:[0,3,5,15],basic:6,batch:16,batchnorm:[8,9,10],below:18,block:[8,9,10,11,12,13,14,16],bolzano:0,bool:[2,3,4,5,11,16],both:19,box:1,build:[0,1,18,19],cach:13,calcul:7,can:[5,18,19],care:19,ccisnow:18,center:[2,3,4,5],channel:[6,7,8,9,10,11,12,13,14,16,18],chronolog:[2,3,4,5],classif:16,classifi:16,clone:18,cloud:2,code:[0,18],com:0,command:18,compliant:[1,3],compos:[2,3,4,5],compose_scen:5,conda:19,config:18,connect:[11,16],constant:[2,3,4,5],contain:17,conv2d:7,conv2dsam:[6,8,9,10,11,12,13,14,16],conv:6,convbnrelumaxpool:[11,13],convbnrelumaxunpool:11,convent:[2,3,4,5],convolut:[1,6,7,8,9,10,11,12,13,14,16],convolv:7,copi:18,correspond:[2,3,4,5],creat:18,current:[1,18],custom:1,daniel:0,data:[2,3,4,5],dataload:3,decod:[12,13,16],decoderblock:11,deep:0,defin:[11,13,18],depend:18,depth:[11,13],design:0,determin:[11,13],develop:0,dict:[6,7,8,9,10,11,12,13,14,16],dictionari:13,dilat:7,dimens:7,directli:5,directori:[1,2,3,4,5,18],distinct:[2,3,4,5],divid:[2,3,4,5],divis:[2,3,4,5],document:19,doe:[6,8,9,10,12,14],dure:3,each:[2,3,4,5,11,13,15,16,17],earth:[0,5],element:[11,13],enabl:3,encod:[11,14,16],encoderblock:[11,13],env:18,environ:19,epoch:16,eurac:0,evenli:[2,3,4,5],exampl:[5,11,13],except:18,explicitli:0,express:[2,3,4,5],fals:[2,3,4,5],featur:[11,13],file:[2,3,4,5,15,18,19],filter:[11,13,16],first:[11,13,18],follow:[1,5,16,18],forg:18,framework:0,frisinghelli:0,from:[3,11,16,18],fulli:0,further:0,futur:0,gdal:19,gener:[0,2,3,4,5,11,13,15],git:18,gitlab:18,given:7,gmail:0,gnu:0,ground:[2,3,4,5],gt_pattern:[2,3,4,5],guid:18,handi:3,hardwar:18,has:[7,11,13],have:18,hay:4,heavili:18,help:17,here:[18,19],http:18,hugh:4,idea:0,imag:[1,2,3,4,5,11,13,16],imageri:0,implement:[1,5,11,13,15,16],in_channel:[6,7,8,9,10,12,14,16],indic:13,inf:18,inform:0,inherit:[3,5,15],initi:[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],input:[2,3,4,5,6,7,8,9,10,11,12,13,14,16],instal:[0,19],instanc:[2,3,4,5,6,8,9,10,12,14,17],instanci:[11,13],institut:0,instruct:18,intermedi:13,interpret:18,invarianttransform:17,item:[2,3,4,5],its:7,kei:13,kernel:7,kernel_s:7,keyword:[7,16],kwarg:[6,7,8,9,10,11,12,13,14,16],label:[2,3,4,5],layer:16,learn:0,length:[11,13],line:18,linux:19,list:[1,2,3,4,5,7,11,13,16,17,19],machin:[0,18],mai:18,match:[2,3,4,5],matplotlib:19,max:[8,9,13,16],method:[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],model:[3,11,13],modifi:16,modulelist:[11,13],mohajerani:2,multispectr:[0,1,3],name:[2,3,4,5,18],navig:18,nclass:16,ndarrai:[11,13],nearest:10,neighbor:10,net:16,nfilter:16,none:[2,3,4,5,15,17],normal:16,number:[6,7,8,9,10,11,12,13,14,16],numpi:[11,13,19],observ:[0,5],offici:18,onc:18,onli:[2,3,4,5],open:1,oper:16,option:[2,3,4,5,11],order:17,origin:[2,3,4,5],otherwis:0,out:1,out_channel:[6,7,8,9,10,12,14],output:[6,7,8,9,10,12,13,14],packag:[0,19],pad:[2,3,4,5,7],pad_height:7,pad_width:7,page:1,paramet:[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],part:0,pass:[6,7,8,9,10,11,12,13,14,16],path:[2,3,4,5,15],pathlib:15,pip:18,pleas:0,pool:[8,13],posit:7,preserv:7,primarili:0,provid:18,pure:19,pysegcnn:[1,19],pytest:19,python:[18,19],pytorch:[0,1,3,16,19],rais:[6,8,9,10,12,14],random:[2,3,4,5],recommend:18,refer:0,regur:[2,3,4,5],relu:[8,9,10],remain:5,remsen:18,repositori:[0,18],reproduc:[2,3,4,5],requir:[0,13,18],research:0,root:[2,3,4,5,18],root_dir:[2,3,4,5],run:18,saeedi:2,same:[7,11,13],sampl:[2,3,4,5,18],satellit:0,save:15,scene:[2,3,4,5],scene_id_1:5,scene_id_1_b1:5,scene_id_1_b2:5,scene_id_1_bn:5,scene_id_2:5,scene_id_2_b1:5,scene_id_2_b2:5,scene_id_2_bn:5,scene_id_n:5,search:[2,3,4,5],see:[0,5,11,13,17,19],seed:[2,3,4,5],self:17,semant:0,sequenc:17,sequenti:[6,8,9,10,12,14],seri:[2,3,4,5],set:[2,3,4,5],shape:[2,3,4,5,7],share:5,ship:19,should:[11,13,18],signatur:17,size:[2,3,4,5,7],skip:[11,16],slightli:16,some:[1,18],sort:[2,3,4,5],sourc:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18],spaceborn:1,sparc:4,sparcsdataset:5,spatial:7,specif:18,spectral:[2,3,4,5],sphinx:19,sphinx_rtd_them:19,split:[2,3,4,5],squar:[2,3,4,5],standard:[1,3,5],standard_eo_structur:5,state:[0,15],state_fil:15,str:[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],stride:7,structur:[1,5],style:5,subclass:[11,13],subdirectori:[2,3,4,5],success:18,successfulli:18,support:[1,18],system:18,take:[18,19],tensor:13,termin:18,test:[2,3,4,5],therefor:18,thi:[0,1,3,5,18],tif:[2,3,4,5],tile:[2,3,4,5],tile_s:[2,3,4,5],time:[2,3,4,5],togeth:[2,3,4,5],torch:[3,6,7,8,9,10,11,12,13,14],total:[2,3,4,5],train:[2,3,4,5,16],transfer:5,transform:[2,3,4,5],truth:[2,3,4,5],tupl:[7,17],type:[17,18],typeerror:[6,8,9,10,12,14],under:0,unet:[11,13],unibz:18,unpool:[9,16],untransform:[2,3,4,5],upsampl:[10,16],use:[2,3,4,5,18,19],use_band:[2,3,4,5],used:[2,3,4,5],using:[18,19],util:[3,5],valid:[2,3,4,5],valu:[2,3,4,5],varianttransform:17,verifi:18,version:[2,3,4,5,18],want:[15,19],websit:18,when:[11,13],where:15,whether:[2,3,4,5,11,16],window:19,within:18,work:[0,19],wrote:0,yml:[18,19],you:[5,15,18,19],your:[5,18],zero:[2,3,4,5]},titles:["PySegCNN: Image segmentation with convolutional neural networks in Python","API Reference","pysegcnn.core.dataset.Cloud95Dataset","pysegcnn.core.dataset.ImageDataset","pysegcnn.core.dataset.SparcsDataset","pysegcnn.core.dataset.StandardEoDataset","pysegcnn.core.layers.Block","pysegcnn.core.layers.Conv2dSame","pysegcnn.core.layers.ConvBnReluMaxPool","pysegcnn.core.layers.ConvBnReluMaxUnpool","pysegcnn.core.layers.ConvBnReluUpsample","pysegcnn.core.layers.Decoder","pysegcnn.core.layers.DecoderBlock","pysegcnn.core.layers.Encoder","pysegcnn.core.layers.EncoderBlock","pysegcnn.core.models.Network","pysegcnn.core.models.UNet","pysegcnn.core.transforms.Augment","Installation","Requirements"],titleterms:{"class":1,Using:0,acknowledg:0,api:1,architechtur:1,augment:17,block:6,cloud95dataset:2,conda:18,contact:0,contributor:0,conv2dsam:7,convbnrelumaxpool:8,convbnrelumaxunpool:9,convbnreluupsampl:10,convolut:0,core:[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],dataset:[1,2,3,4,5],decod:[1,11],decoderblock:12,depend:19,download:18,encod:[1,13],encoderblock:14,environ:18,framework:19,gener:1,imag:0,imagedataset:3,instal:18,layer:[1,6,7,8,9,10,11,12,13,14],learn:19,licens:0,machin:19,manag:18,model:[1,15,16],network:[0,1,15],neural:[0,1],packag:18,pysegcnn:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18],python:0,pytorch:18,raster:19,refer:1,requir:19,scipi:19,segment:0,sparcsdataset:4,specif:1,stack:19,standardeodataset:5,test:19,tool:19,transform:17,unet:16}}) \ No newline at end of file diff --git a/docs/_build/html/source/api.html b/docs/_build/html/source/api.html index 8e5f46e9ea6fef9fc109a6c2fd34959e2e453436..67f2d144b6214590aa39d1d875f58112de6ddb81 100644 --- a/docs/_build/html/source/api.html +++ b/docs/_build/html/source/api.html @@ -87,11 +87,12 @@ <li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li> <li class="toctree-l1 current"><a class="current reference internal" href="#">API Reference</a><ul> <li class="toctree-l2"><a class="reference internal" href="#dataset">Dataset</a><ul> -<li class="toctree-l3"><a class="reference internal" href="#image-dataset">Image Dataset</a><ul> +<li class="toctree-l3"><a class="reference internal" href="#generic-classes">Generic classes</a><ul> <li class="toctree-l4"><a class="reference internal" href="generated/pysegcnn.core.dataset.ImageDataset.html">pysegcnn.core.dataset.ImageDataset</a></li> +<li class="toctree-l4"><a class="reference internal" href="generated/pysegcnn.core.dataset.StandardEoDataset.html">pysegcnn.core.dataset.StandardEoDataset</a></li> </ul> </li> -<li class="toctree-l3"><a class="reference internal" href="#supported-datasets">Supported datasets</a><ul> +<li class="toctree-l3"><a class="reference internal" href="#specific-classes">Specific classes</a><ul> <li class="toctree-l4"><a class="reference internal" href="generated/pysegcnn.core.dataset.SparcsDataset.html">pysegcnn.core.dataset.SparcsDataset</a></li> <li class="toctree-l4"><a class="reference internal" href="generated/pysegcnn.core.dataset.Cloud95Dataset.html">pysegcnn.core.dataset.Cloud95Dataset</a></li> </ul> @@ -194,9 +195,9 @@ <div class="section" id="dataset"> <h2>Dataset<a class="headerlink" href="#dataset" title="Permalink to this headline">¶</a></h2> <p>Custom dataset classes compliant to the PyTorch <a class="reference external" href="https://pytorch.org/docs/stable/data.html">standard</a>.</p> -<div class="section" id="image-dataset"> -<h3>Image Dataset<a class="headerlink" href="#image-dataset" title="Permalink to this headline">¶</a></h3> -<p>Generic class to implement <a class="reference external" href="https://pytorch.org/tutorials/beginner/data_loading_tutorial.html">custom datasets</a>.</p> +<div class="section" id="generic-classes"> +<h3>Generic classes<a class="headerlink" href="#generic-classes" title="Permalink to this headline">¶</a></h3> +<p>Generic class to implement a <a class="reference external" href="https://pytorch.org/tutorials/beginner/data_loading_tutorial.html">custom dataset</a>.</p> <table class="longtable docutils align-default"> <colgroup> <col style="width: 10%" /> @@ -208,11 +209,24 @@ </tr> </tbody> </table> +<p>Generic class to implement a custom dataset following a standard directory +structure.</p> +<table class="longtable docutils align-default"> +<colgroup> +<col style="width: 10%" /> +<col style="width: 90%" /> +</colgroup> +<tbody> +<tr class="row-odd"><td><p><a class="reference internal" href="generated/pysegcnn.core.dataset.StandardEoDataset.html#pysegcnn.core.dataset.StandardEoDataset" title="pysegcnn.core.dataset.StandardEoDataset"><code class="xref py py-obj docutils literal notranslate"><span class="pre">core.dataset.StandardEoDataset</span></code></a></p></td> +<td><p>Base class for standard Earth Observation style datasets.</p></td> +</tr> +</tbody> +</table> </div> -<div class="section" id="supported-datasets"> -<h3>Supported datasets<a class="headerlink" href="#supported-datasets" title="Permalink to this headline">¶</a></h3> -<p>The following open-source spaceborne multispectral image datasets are supported -out-of-the-box:</p> +<div class="section" id="specific-classes"> +<h3>Specific classes<a class="headerlink" href="#specific-classes" title="Permalink to this headline">¶</a></h3> +<p>Specific classes for some open-source image datasets. Currently, the following +spaceborne multispectral image datasets are supported out-of-the-box:</p> <table class="longtable docutils align-default"> <colgroup> <col style="width: 10%" /> @@ -220,7 +234,7 @@ out-of-the-box:</p> </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="generated/pysegcnn.core.dataset.SparcsDataset.html#pysegcnn.core.dataset.SparcsDataset" title="pysegcnn.core.dataset.SparcsDataset"><code class="xref py py-obj docutils literal notranslate"><span class="pre">core.dataset.SparcsDataset</span></code></a></p></td> -<td><p>Class for the <a class="reference external" href="https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation">Sparcs</a> dataset.</p></td> +<td><p>Class for the <a class="reference external" href="https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation">Sparcs</a> dataset by <a class="reference external" href="https://www.mdpi.com/2072-4292/6/6/4907">Hughes & Hayes (2014)</a>.</p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="generated/pysegcnn.core.dataset.Cloud95Dataset.html#pysegcnn.core.dataset.Cloud95Dataset" title="pysegcnn.core.dataset.Cloud95Dataset"><code class="xref py py-obj docutils literal notranslate"><span class="pre">core.dataset.Cloud95Dataset</span></code></a></p></td> <td><p>Class for the <a class="reference external" href="https://github.com/SorourMo/95-Cloud-An-Extension-to-38-Cloud-Dataset">Cloud-95</a> dataset by <a class="reference external" href="https://arxiv.org/abs/2001.08768">Mohajerani & Saeedi (2020)</a>.</p></td> @@ -253,7 +267,7 @@ out-of-the-box:</p> <td><p>Block of convolution, batchnorm, relu and 2x2 max unpool.</p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="generated/pysegcnn.core.layers.ConvBnReluUpsample.html#pysegcnn.core.layers.ConvBnReluUpsample" title="pysegcnn.core.layers.ConvBnReluUpsample"><code class="xref py py-obj docutils literal notranslate"><span class="pre">core.layers.ConvBnReluUpsample</span></code></a></p></td> -<td><p>Block of convolution, batchnorm, relu and nearest neighbor upsampling.</p></td> +<td><p>Block of convolution, batchnorm, relu and nearest neighbor upsample.</p></td> </tr> </tbody> </table> @@ -295,7 +309,7 @@ architecture.</p> <td><p>Generic Network class.</p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="generated/pysegcnn.core.models.UNet.html#pysegcnn.core.models.UNet" title="pysegcnn.core.models.UNet"><code class="xref py py-obj docutils literal notranslate"><span class="pre">core.models.UNet</span></code></a></p></td> -<td><p>A PyTorch implementation of <a class="reference external" href="https://arxiv.org/abs/1505.04597">U-Net</a>.</p></td> +<td><p>A slightly modified implementation of <a class="reference external" href="https://arxiv.org/abs/1505.04597">U-Net</a> in PyTorch.</p></td> </tr> </tbody> </table> diff --git a/docs/_build/html/source/core.html b/docs/_build/html/source/core.html deleted file mode 100644 index 18c74c4f435175b42a37e5266a4183e9d99e6034..0000000000000000000000000000000000000000 --- a/docs/_build/html/source/core.html +++ /dev/null @@ -1,6848 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>core package — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> - <script src="../_static/jquery.js"></script> - <script src="../_static/underscore.js"></script> - <script src="../_static/doctools.js"></script> - <script src="../_static/language_data.js"></script> - - <script type="text/javascript" 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="main package" href="main.html" /> - <link rel="prev" title="pysegcnn" href="modules.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" > - - - - <a href="../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul class="current"> -<li class="toctree-l1 current"><a class="reference internal" href="modules.html">pysegcnn</a><ul class="current"> -<li class="toctree-l2 current"><a class="current reference internal" href="#">core package</a><ul> -<li class="toctree-l3"><a class="reference internal" href="#submodules">Submodules</a></li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.cli">core.cli module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#license">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.constants">core.constants module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id1">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.dataset">core.dataset module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id2">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.graphics">core.graphics module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id4">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.layers">core.layers module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id5">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.logging">core.logging module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id6">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.models">core.models module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id7">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.predict">core.predict module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id8">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.split">core.split module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id9">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.trainer">core.trainer module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id10">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.transforms">core.transforms module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id11">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core.utils">core.utils module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id12">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-core">Module contents</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="main.html">main package</a></li> -<li class="toctree-l2"><a class="reference internal" href="preprocessing.html">preprocessing package</a></li> -</ul> -</li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../index.html" class="icon icon-home"></a> »</li> - - <li><a href="modules.html">pysegcnn</a> »</li> - - <li>core package</li> - - - <li class="wy-breadcrumbs-aside"> - - - <a href="../_sources/source/core.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"> - - <div class="section" id="core-package"> -<h1>core package<a class="headerlink" href="#core-package" title="Permalink to this headline">¶</a></h1> -<div class="section" id="submodules"> -<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2> -</div> -<div class="section" id="module-core.cli"> -<span id="core-cli-module"></span><h2>core.cli module<a class="headerlink" href="#module-core.cli" title="Permalink to this headline">¶</a></h2> -<p>Command line interface parsers.</p> -<div class="section" id="license"> -<h3>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py function"> -<dt id="core.cli.structure_parser"> -<code class="sig-prename descclassname">core.cli.</code><code class="sig-name descname">structure_parser</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/cli.html#structure_parser"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.cli.structure_parser" title="Permalink to this definition">¶</a></dt> -<dd><p>Command line argument parser to standardize dataset structure.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> -</dd> -</dl> -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.constants"> -<span id="core-constants-module"></span><h2>core.constants module<a class="headerlink" href="#module-core.constants" title="Permalink to this headline">¶</a></h2> -<p>A collection of constant values.</p> -<div class="section" id="id1"> -<h3>License<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py class"> -<dt id="core.constants.Cloud95Labels"> -<em class="property">class </em><code class="sig-prename descclassname">core.constants.</code><code class="sig-name descname">Cloud95Labels</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/constants.html#Cloud95Labels"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.constants.Cloud95Labels" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.constants.Label" title="core.constants.Label"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.constants.Label</span></code></a></p> -<p>Class labels of the <a class="reference external" href="https://github.com/SorourMo/95-Cloud-An-Extension-to-38-Cloud-Dataset">Cloud-95</a> dataset.</p> -<dl class="py attribute"> -<dt id="core.constants.Cloud95Labels.Clear"> -<code class="sig-name descname">Clear</code><em class="property"> = (0, 'skyblue')</em><a class="headerlink" href="#core.constants.Cloud95Labels.Clear" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Cloud95Labels.Cloud"> -<code class="sig-name descname">Cloud</code><em class="property"> = (1, 'white')</em><a class="headerlink" href="#core.constants.Cloud95Labels.Cloud" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.constants.Label"> -<em class="property">class </em><code class="sig-prename descclassname">core.constants.</code><code class="sig-name descname">Label</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/constants.html#Label"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.constants.Label" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></p> -<p>Generic enumeration for class labels.</p> -<dl class="py method"> -<dt id="core.constants.Label.color"> -<em class="property">property </em><code class="sig-name descname">color</code><a class="headerlink" href="#core.constants.Label.color" title="Permalink to this definition">¶</a></dt> -<dd><p>Return the color to plot a class.</p> -</dd></dl> - -<dl class="py method"> -<dt id="core.constants.Label.id"> -<em class="property">property </em><code class="sig-name descname">id</code><a class="headerlink" href="#core.constants.Label.id" title="Permalink to this definition">¶</a></dt> -<dd><p>Return the value of a class in the ground truth.</p> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.constants.Landsat8"> -<em class="property">class </em><code class="sig-prename descclassname">core.constants.</code><code class="sig-name descname">Landsat8</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/constants.html#Landsat8"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.constants.Landsat8" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></p> -<p>The spectral bands of the Landsat 8 sensors.</p> -<dl class="simple"> -<dt>sensors:</dt><dd><ul class="simple"> -<li><p>Operational Land Imager (OLI), (bands 1-9)</p></li> -<li><p>Thermal Infrared Sensor (TIRS), (bands 10, 11)</p></li> -</ul> -</dd> -</dl> -<dl class="py attribute"> -<dt id="core.constants.Landsat8.blue"> -<code class="sig-name descname">blue</code><em class="property"> = 2</em><a class="headerlink" href="#core.constants.Landsat8.blue" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Landsat8.cirrus"> -<code class="sig-name descname">cirrus</code><em class="property"> = 9</em><a class="headerlink" href="#core.constants.Landsat8.cirrus" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Landsat8.green"> -<code class="sig-name descname">green</code><em class="property"> = 3</em><a class="headerlink" href="#core.constants.Landsat8.green" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Landsat8.nir"> -<code class="sig-name descname">nir</code><em class="property"> = 5</em><a class="headerlink" href="#core.constants.Landsat8.nir" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Landsat8.pan"> -<code class="sig-name descname">pan</code><em class="property"> = 8</em><a class="headerlink" href="#core.constants.Landsat8.pan" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Landsat8.red"> -<code class="sig-name descname">red</code><em class="property"> = 4</em><a class="headerlink" href="#core.constants.Landsat8.red" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Landsat8.swir1"> -<code class="sig-name descname">swir1</code><em class="property"> = 6</em><a class="headerlink" href="#core.constants.Landsat8.swir1" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Landsat8.swir2"> -<code class="sig-name descname">swir2</code><em class="property"> = 7</em><a class="headerlink" href="#core.constants.Landsat8.swir2" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Landsat8.tir1"> -<code class="sig-name descname">tir1</code><em class="property"> = 10</em><a class="headerlink" href="#core.constants.Landsat8.tir1" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Landsat8.violet"> -<code class="sig-name descname">violet</code><em class="property"> = 1</em><a class="headerlink" href="#core.constants.Landsat8.violet" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.constants.ProSnowLabels"> -<em class="property">class </em><code class="sig-prename descclassname">core.constants.</code><code class="sig-name descname">ProSnowLabels</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/constants.html#ProSnowLabels"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.constants.ProSnowLabels" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.constants.Label" title="core.constants.Label"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.constants.Label</span></code></a></p> -<p>Class labels of the ProSnow datasets.</p> -<dl class="py attribute"> -<dt id="core.constants.ProSnowLabels.Cloud"> -<code class="sig-name descname">Cloud</code><em class="property"> = (0, 'white')</em><a class="headerlink" href="#core.constants.ProSnowLabels.Cloud" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.ProSnowLabels.Snow"> -<code class="sig-name descname">Snow</code><em class="property"> = (1, 'lightblue')</em><a class="headerlink" href="#core.constants.ProSnowLabels.Snow" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.ProSnowLabels.Snow_free"> -<code class="sig-name descname">Snow_free</code><em class="property"> = (2, 'sienna')</em><a class="headerlink" href="#core.constants.ProSnowLabels.Snow_free" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.constants.Sentinel2"> -<em class="property">class </em><code class="sig-prename descclassname">core.constants.</code><code class="sig-name descname">Sentinel2</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/constants.html#Sentinel2"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.constants.Sentinel2" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></p> -<p>The spectral bands of the Sentinel-2 MultiSpectral Instrument (MSI).</p> -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.aerosol"> -<code class="sig-name descname">aerosol</code><em class="property"> = 1</em><a class="headerlink" href="#core.constants.Sentinel2.aerosol" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.blue"> -<code class="sig-name descname">blue</code><em class="property"> = 2</em><a class="headerlink" href="#core.constants.Sentinel2.blue" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.cirrus"> -<code class="sig-name descname">cirrus</code><em class="property"> = 10</em><a class="headerlink" href="#core.constants.Sentinel2.cirrus" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.green"> -<code class="sig-name descname">green</code><em class="property"> = 3</em><a class="headerlink" href="#core.constants.Sentinel2.green" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.nir"> -<code class="sig-name descname">nir</code><em class="property"> = 8</em><a class="headerlink" href="#core.constants.Sentinel2.nir" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.nnir"> -<code class="sig-name descname">nnir</code><em class="property"> = '8A'</em><a class="headerlink" href="#core.constants.Sentinel2.nnir" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.red"> -<code class="sig-name descname">red</code><em class="property"> = 4</em><a class="headerlink" href="#core.constants.Sentinel2.red" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.swir1"> -<code class="sig-name descname">swir1</code><em class="property"> = 11</em><a class="headerlink" href="#core.constants.Sentinel2.swir1" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.swir2"> -<code class="sig-name descname">swir2</code><em class="property"> = 12</em><a class="headerlink" href="#core.constants.Sentinel2.swir2" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.vapor"> -<code class="sig-name descname">vapor</code><em class="property"> = 9</em><a class="headerlink" href="#core.constants.Sentinel2.vapor" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.vnir1"> -<code class="sig-name descname">vnir1</code><em class="property"> = 5</em><a class="headerlink" href="#core.constants.Sentinel2.vnir1" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.vnir2"> -<code class="sig-name descname">vnir2</code><em class="property"> = 6</em><a class="headerlink" href="#core.constants.Sentinel2.vnir2" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.Sentinel2.vnir3"> -<code class="sig-name descname">vnir3</code><em class="property"> = 7</em><a class="headerlink" href="#core.constants.Sentinel2.vnir3" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.constants.SparcsLabels"> -<em class="property">class </em><code class="sig-prename descclassname">core.constants.</code><code class="sig-name descname">SparcsLabels</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/constants.html#SparcsLabels"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.constants.SparcsLabels" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.constants.Label" title="core.constants.Label"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.constants.Label</span></code></a></p> -<p>Class labels of the <a class="reference external" href="https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation">Sparcs</a> dataset.</p> -<dl class="py attribute"> -<dt id="core.constants.SparcsLabels.Cloud"> -<code class="sig-name descname">Cloud</code><em class="property"> = (5, 'white')</em><a class="headerlink" href="#core.constants.SparcsLabels.Cloud" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.SparcsLabels.Flooded"> -<code class="sig-name descname">Flooded</code><em class="property"> = (6, 'yellow')</em><a class="headerlink" href="#core.constants.SparcsLabels.Flooded" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.SparcsLabels.Land"> -<code class="sig-name descname">Land</code><em class="property"> = (4, 'sienna')</em><a class="headerlink" href="#core.constants.SparcsLabels.Land" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.SparcsLabels.Shadow"> -<code class="sig-name descname">Shadow</code><em class="property"> = (0, 'grey')</em><a class="headerlink" href="#core.constants.SparcsLabels.Shadow" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.SparcsLabels.Shadow_over_water"> -<code class="sig-name descname">Shadow_over_water</code><em class="property"> = (1, 'darkblue')</em><a class="headerlink" href="#core.constants.SparcsLabels.Shadow_over_water" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.SparcsLabels.Snow"> -<code class="sig-name descname">Snow</code><em class="property"> = (3, 'lightblue')</em><a class="headerlink" href="#core.constants.SparcsLabels.Snow" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.constants.SparcsLabels.Water"> -<code class="sig-name descname">Water</code><em class="property"> = (2, 'blue')</em><a class="headerlink" href="#core.constants.SparcsLabels.Water" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.dataset"> -<span id="core-dataset-module"></span><h2>core.dataset module<a class="headerlink" href="#module-core.dataset" title="Permalink to this headline">¶</a></h2> -<p>Custom dataset classes compliant to the PyTorch standard.</p> -<p>Each custom dataset should inherit from torch.utils.data.Dataset to benefit -from the torch.utils.data.DataLoader class, which implements helpful utilities -during model training.</p> -<p>For any kind of image-like dataset, inherit the ImageDataset class to create -your custom dataset.</p> -<div class="section" id="id2"> -<h3>License<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py class"> -<dt id="core.dataset.Cloud95Dataset"> -<em class="property">class </em><code class="sig-prename descclassname">core.dataset.</code><code class="sig-name descname">Cloud95Dataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#Cloud95Dataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.Cloud95Dataset" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.dataset.ImageDataset" title="core.dataset.ImageDataset"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.dataset.ImageDataset</span></code></a></p> -<p>Class for the <a class="reference external" href="https://github.com/SorourMo/95-Cloud-An-Extension-to-38-Cloud-Dataset">Cloud-95</a> dataset by <a class="reference external" href="https://arxiv.org/abs/2001.08768">Mohajerani et al. (2020)</a>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. All -directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for files -matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.Cloud95Dataset.compose_scenes" title="core.dataset.Cloud95Dataset.compose_scenes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code></a>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.Cloud95Dataset.get_labels" title="core.dataset.Cloud95Dataset.get_labels"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code></a>()</p></td> -<td><p>Class labels of the Cloud-95 dataset.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.Cloud95Dataset.get_sensor" title="core.dataset.Cloud95Dataset.get_sensor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code></a>()</p></td> -<td><p>Landsat 8 bands of the Cloud-95 dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.Cloud95Dataset.get_size" title="core.dataset.Cloud95Dataset.get_size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code></a>()</p></td> -<td><p>Image size of the Cloud-95 dataset.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.Cloud95Dataset.parse_scene_id" title="core.dataset.Cloud95Dataset.parse_scene_id"><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code></a>(scene_id)</p></td> -<td><p>Parse Sparcs scene identifiers (Landsat 8).</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.Cloud95Dataset.preprocess" title="core.dataset.Cloud95Dataset.preprocess"><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code></a>(data, gt)</p></td> -<td><p>Preprocess Cloud-95 dataset images.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.dataset.Cloud95Dataset.compose_scenes"> -<code class="sig-name descname">compose_scenes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#Cloud95Dataset.compose_scenes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.Cloud95Dataset.compose_scenes" title="Permalink to this definition">¶</a></dt> -<dd><p>Build the list of samples of the dataset.</p> -<p>Each sample is represented by a dictionary.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>scenes</strong> –</p> -<dl class="simple"> -<dt>Each item in <code class="docutils literal notranslate"><span class="pre">scenes</span></code> is a <cite>dict</cite> with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_1'</span></code></dt><dd><p>Path to the file of band_1.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_2'</span></code></dt><dd><p>Path to the file of band_2.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_n'</span></code></dt><dd><p>Path to the file of band_n.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'gt'</span></code></dt><dd><p>Path to the ground truth file.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'date'</span></code></dt><dd><p>The date of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'tile'</span></code></dt><dd><p>The tile id of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'transform'</span></code></dt><dd><p>The transformation to apply.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'id'</span></code></dt><dd><p>The scene identifier.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>list</cite> [<cite>dict</cite>]</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.Cloud95Dataset.get_labels"> -<code class="sig-name descname">get_labels</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#Cloud95Dataset.get_labels"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.Cloud95Dataset.get_labels" title="Permalink to this definition">¶</a></dt> -<dd><p>Class labels of the Cloud-95 dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>labels</strong> – The class labels.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>enum.Enum</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.Cloud95Dataset.get_sensor"> -<code class="sig-name descname">get_sensor</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#Cloud95Dataset.get_sensor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.Cloud95Dataset.get_sensor" title="Permalink to this definition">¶</a></dt> -<dd><p>Landsat 8 bands of the Cloud-95 dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>sensor</strong> – An enumeration of the bands of the sensor.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>enum.Enum</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.Cloud95Dataset.get_size"> -<code class="sig-name descname">get_size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#Cloud95Dataset.get_size"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.Cloud95Dataset.get_size" title="Permalink to this definition">¶</a></dt> -<dd><p>Image size of the Cloud-95 dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>size</strong> – The image size (height, width).</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>tuple</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.Cloud95Dataset.parse_scene_id"> -<code class="sig-name descname">parse_scene_id</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">scene_id</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#Cloud95Dataset.parse_scene_id"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.Cloud95Dataset.parse_scene_id" title="Permalink to this definition">¶</a></dt> -<dd><p>Parse Sparcs scene identifiers (Landsat 8).</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>scene_id</strong> (<cite>str</cite>) – A scene identifier.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>scene</strong> – A dictionary containing scene metadata. If <cite>None</cite>, <code class="docutils literal notranslate"><span class="pre">scene_id</span></code> is -not a valid Landsat scene identifier.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>dict</cite> or <cite>None</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.Cloud95Dataset.preprocess"> -<code class="sig-name descname">preprocess</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">gt</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#Cloud95Dataset.preprocess"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.Cloud95Dataset.preprocess" title="Permalink to this definition">¶</a></dt> -<dd><p>Preprocess Cloud-95 dataset images.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>data</strong> (<cite>numpy.ndarray</cite>) – The sample input data.</p></li> -<li><p><strong>gt</strong> (<cite>numpy.ndarray</cite>) – The sample ground truth.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>data</strong> (<cite>numpy.ndarray</cite>) – The preprocessed input data.</p></li> -<li><p><strong>gt</strong> (<cite>numpy.ndarray</cite>) – The preprocessed ground truth data.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.dataset.ImageDataset"> -<em class="property">class </em><code class="sig-prename descclassname">core.dataset.</code><code class="sig-name descname">ImageDataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.utils.data.dataset.Dataset</span></code></p> -<p>Base class for multispectral image data.</p> -<p>Inheriting from <cite>torch.utils.data.Dataset</cite> to be compliant to the PyTorch -standard. Furthermore, using instances of <cite>torch.utils.data.Dataset</cite> -enables the use of the handy <cite>torch.utils.data.DataLoader</cite> class during -model training.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. -All directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for -files matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.ImageDataset.build_samples" title="core.dataset.ImageDataset.build_samples"><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code></a>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.ImageDataset.compose_scenes" title="core.dataset.ImageDataset.compose_scenes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code></a>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.ImageDataset.get_labels" title="core.dataset.ImageDataset.get_labels"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code></a>()</p></td> -<td><p>Return an enumeration of the class labels of the dataset.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.ImageDataset.get_sensor" title="core.dataset.ImageDataset.get_sensor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code></a>()</p></td> -<td><p>Return an enumeration of the bands of the sensor of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.ImageDataset.get_size" title="core.dataset.ImageDataset.get_size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code></a>()</p></td> -<td><p>Return the size of the images in the dataset.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.ImageDataset.parse_scene_id" title="core.dataset.ImageDataset.parse_scene_id"><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code></a>(scene_id)</p></td> -<td><p>Parse the scene identifier.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.ImageDataset.preprocess" title="core.dataset.ImageDataset.preprocess"><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code></a>(data, gt)</p></td> -<td><p>Preprocess a sample before feeding it to a model.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.ImageDataset.read_scene" title="core.dataset.ImageDataset.read_scene"><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code></a>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.ImageDataset.to_tensor" title="core.dataset.ImageDataset.to_tensor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code></a>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.dataset.ImageDataset.build_samples"> -<code class="sig-name descname">build_samples</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">scene</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset.build_samples"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset.build_samples" title="Permalink to this definition">¶</a></dt> -<dd><p>Stack the bands of a sample in a single array.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>scene</strong> (<cite>dict</cite>) – <dl class="simple"> -<dt>The sample data dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_1'</span></code></dt><dd><p>data of band_1 (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_2'</span></code></dt><dd><p>data of band_2 (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_n'</span></code></dt><dd><p>data of band_n (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'gt'</span></code></dt><dd><p>data of the ground truth (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'date'</span></code></dt><dd><p>The date of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'tile'</span></code></dt><dd><p>The tile id of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'transform'</span></code></dt><dd><p>The transformation to apply.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'id'</span></code></dt><dd><p>The scene identifier.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>stack</strong> (<cite>numpy.ndarray</cite>) – The input data of the sample.</p></li> -<li><p><strong>gt</strong> (<em>TYPE</em>) – The ground truth of the sample.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ImageDataset.compose_scenes"> -<code class="sig-name descname">compose_scenes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset.compose_scenes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset.compose_scenes" title="Permalink to this definition">¶</a></dt> -<dd><p>Build the list of samples of the dataset.</p> -<p>Each sample is represented by a dictionary.</p> -<dl class="field-list simple"> -<dt class="field-odd">Raises</dt> -<dd class="field-odd"><p><strong>NotImplementedError</strong> – Raised if the <cite>pysegcnn.core.dataset.ImageDataset</cite> class is not -inherited.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><p><strong>samples</strong> –</p> -<dl class="simple"> -<dt>Each dictionary representing a sample should have keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_1'</span></code></dt><dd><p>Path to the file of band_1.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_2'</span></code></dt><dd><p>Path to the file of band_2.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_n'</span></code></dt><dd><p>Path to the file of band_n.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'gt'</span></code></dt><dd><p>Path to the ground truth file.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'date'</span></code></dt><dd><p>The date of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'tile'</span></code></dt><dd><p>The tile id of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'transform'</span></code></dt><dd><p>The transformation to apply.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'id'</span></code></dt><dd><p>The scene identifier.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>list</cite> [<cite>dict</cite>]</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ImageDataset.get_labels"> -<code class="sig-name descname">get_labels</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset.get_labels"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset.get_labels" title="Permalink to this definition">¶</a></dt> -<dd><p>Return an enumeration of the class labels of the dataset.</p> -<p>Examples can be found in <cite>pysegcnn.core.constants</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Raises</dt> -<dd class="field-odd"><p><strong>NotImplementedError</strong> – Raised if the <cite>pysegcnn.core.dataset.ImageDataset</cite> class is not -inherited.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>labels</strong> – The class labels.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>enum.Enum</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ImageDataset.get_sensor"> -<code class="sig-name descname">get_sensor</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset.get_sensor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset.get_sensor" title="Permalink to this definition">¶</a></dt> -<dd><p>Return an enumeration of the bands of the sensor of the dataset.</p> -<p>Examples can be found in <cite>pysegcnn.core.constants</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Raises</dt> -<dd class="field-odd"><p><strong>NotImplementedError</strong> – Raised if the <cite>pysegcnn.core.dataset.ImageDataset</cite> class is not -inherited.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>sensor</strong> – An enumeration of the bands of the sensor.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>enum.Enum</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ImageDataset.get_size"> -<code class="sig-name descname">get_size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset.get_size"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset.get_size" title="Permalink to this definition">¶</a></dt> -<dd><p>Return the size of the images in the dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Raises</dt> -<dd class="field-odd"><p><strong>NotImplementedError</strong> – Raised if the <cite>pysegcnn.core.dataset.ImageDataset</cite> class is not -inherited.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>size</strong> – The image size (height, width).</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>tuple</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ImageDataset.parse_scene_id"> -<code class="sig-name descname">parse_scene_id</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">scene_id</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset.parse_scene_id"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset.parse_scene_id" title="Permalink to this definition">¶</a></dt> -<dd><p>Parse the scene identifier.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>scene_id</strong> (<cite>str</cite>) – A scene identifier.</p> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>NotImplementedError</strong> – Raised if the <cite>pysegcnn.core.dataset.ImageDataset</cite> class is not -inherited.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>scene</strong> – A dictionary containing scene metadata. If <cite>None</cite>, <code class="docutils literal notranslate"><span class="pre">scene_id</span></code> is -not a valid scene identifier.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>dict</cite> or <cite>None</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ImageDataset.preprocess"> -<code class="sig-name descname">preprocess</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">gt</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset.preprocess"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset.preprocess" title="Permalink to this definition">¶</a></dt> -<dd><p>Preprocess a sample before feeding it to a model.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>data</strong> (<cite>numpy.ndarray</cite>) – The sample input data.</p></li> -<li><p><strong>gt</strong> (<cite>numpy.ndarray</cite>) – The sample ground truth.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>NotImplementedError</strong> – Raised if the <cite>pysegcnn.core.dataset.ImageDataset</cite> class is not -inherited.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul class="simple"> -<li><p><strong>data</strong> (<cite>numpy.ndarray</cite>) – The preprocessed input data.</p></li> -<li><p><strong>gt</strong> (<cite>numpy.ndarray</cite>) – The preprocessed ground truth data.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ImageDataset.read_scene"> -<code class="sig-name descname">read_scene</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">idx</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset.read_scene"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset.read_scene" title="Permalink to this definition">¶</a></dt> -<dd><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>idx</strong> (<cite>int</cite>) – The index of the sample.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><p><strong>scene_data</strong> –</p> -<dl class="simple"> -<dt>The sample data dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_1'</span></code></dt><dd><p>data of band_1 (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_2'</span></code></dt><dd><p>data of band_2 (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_n'</span></code></dt><dd><p>data of band_n (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'gt'</span></code></dt><dd><p>data of the ground truth (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'date'</span></code></dt><dd><p>The date of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'tile'</span></code></dt><dd><p>The tile id of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'transform'</span></code></dt><dd><p>The transformation to apply.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'id'</span></code></dt><dd><p>The scene identifier.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ImageDataset.to_tensor"> -<code class="sig-name descname">to_tensor</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">dtype</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ImageDataset.to_tensor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ImageDataset.to_tensor" title="Permalink to this definition">¶</a></dt> -<dd><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>x</strong> (<em>array_like</em>) – The input data.</p></li> -<li><p><strong>dtype</strong> (<cite>torch.dtype</cite>) – The data type used to convert <code class="docutils literal notranslate"><span class="pre">x</span></code>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>x</strong> – The input data tensor.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>torch.Tensor</cite></p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.dataset.ProSnowDataset"> -<em class="property">class </em><code class="sig-prename descclassname">core.dataset.</code><code class="sig-name descname">ProSnowDataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ProSnowDataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ProSnowDataset" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.dataset.StandardEoDataset" title="core.dataset.StandardEoDataset"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.dataset.StandardEoDataset</span></code></a></p> -<p>Class for the ProSnow datasets.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. All -directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for files -matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.ProSnowDataset.get_labels" title="core.dataset.ProSnowDataset.get_labels"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code></a>()</p></td> -<td><p>Class labels of the ProSnow datasets.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.ProSnowDataset.get_sensor" title="core.dataset.ProSnowDataset.get_sensor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code></a>()</p></td> -<td><p>Sentinel 2 bands of the ProSnow datasets.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code>()</p></td> -<td><p>Return the size of the images in the dataset.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.ProSnowDataset.parse_scene_id" title="core.dataset.ProSnowDataset.parse_scene_id"><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code></a>(scene_id)</p></td> -<td><p>Parse ProSnow scene identifiers (Sentinel 2).</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.ProSnowDataset.preprocess" title="core.dataset.ProSnowDataset.preprocess"><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code></a>(data, gt)</p></td> -<td><p>Preprocess ProSnow dataset images.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.dataset.ProSnowDataset.get_labels"> -<code class="sig-name descname">get_labels</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ProSnowDataset.get_labels"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ProSnowDataset.get_labels" title="Permalink to this definition">¶</a></dt> -<dd><p>Class labels of the ProSnow datasets.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>labels</strong> – The class labels.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>enum.Enum</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ProSnowDataset.get_sensor"> -<code class="sig-name descname">get_sensor</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ProSnowDataset.get_sensor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ProSnowDataset.get_sensor" title="Permalink to this definition">¶</a></dt> -<dd><p>Sentinel 2 bands of the ProSnow datasets.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>sensor</strong> – An enumeration of the bands of the sensor.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>enum.Enum</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ProSnowDataset.parse_scene_id"> -<code class="sig-name descname">parse_scene_id</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">scene_id</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ProSnowDataset.parse_scene_id"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ProSnowDataset.parse_scene_id" title="Permalink to this definition">¶</a></dt> -<dd><p>Parse ProSnow scene identifiers (Sentinel 2).</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>scene_id</strong> (<cite>str</cite>) – A scene identifier.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>scene</strong> – A dictionary containing scene metadata. If <cite>None</cite>, <code class="docutils literal notranslate"><span class="pre">scene_id</span></code> is -not a valid Sentinel-2 scene identifier.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>dict</cite> or <cite>None</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.ProSnowDataset.preprocess"> -<code class="sig-name descname">preprocess</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">gt</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ProSnowDataset.preprocess"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ProSnowDataset.preprocess" title="Permalink to this definition">¶</a></dt> -<dd><p>Preprocess ProSnow dataset images.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>data</strong> (<cite>numpy.ndarray</cite>) – The sample input data.</p></li> -<li><p><strong>gt</strong> (<cite>numpy.ndarray</cite>) – The sample ground truth.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>data</strong> (<cite>numpy.ndarray</cite>) – The preprocessed input data.</p></li> -<li><p><strong>gt</strong> (<cite>numpy.ndarray</cite>) – The preprocessed ground truth data.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.dataset.ProSnowGarmisch"> -<em class="property">class </em><code class="sig-prename descclassname">core.dataset.</code><code class="sig-name descname">ProSnowGarmisch</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ProSnowGarmisch"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ProSnowGarmisch" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.dataset.ProSnowDataset" title="core.dataset.ProSnowDataset"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.dataset.ProSnowDataset</span></code></a></p> -<p>Class for the ProSnow Garmisch dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. All -directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for files -matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code>()</p></td> -<td><p>Class labels of the ProSnow datasets.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code>()</p></td> -<td><p>Sentinel 2 bands of the ProSnow datasets.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.ProSnowGarmisch.get_size" title="core.dataset.ProSnowGarmisch.get_size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code></a>()</p></td> -<td><p>Image size of the ProSnow Garmisch dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code>(scene_id)</p></td> -<td><p>Parse ProSnow scene identifiers (Sentinel 2).</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code>(data, gt)</p></td> -<td><p>Preprocess ProSnow dataset images.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.dataset.ProSnowGarmisch.get_size"> -<code class="sig-name descname">get_size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ProSnowGarmisch.get_size"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ProSnowGarmisch.get_size" title="Permalink to this definition">¶</a></dt> -<dd><p>Image size of the ProSnow Garmisch dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>size</strong> – The image size (height, width).</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>tuple</cite></p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.dataset.ProSnowObergurgl"> -<em class="property">class </em><code class="sig-prename descclassname">core.dataset.</code><code class="sig-name descname">ProSnowObergurgl</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ProSnowObergurgl"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ProSnowObergurgl" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.dataset.ProSnowDataset" title="core.dataset.ProSnowDataset"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.dataset.ProSnowDataset</span></code></a></p> -<p>Class for the ProSnow Obergurgl dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. All -directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for files -matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code>()</p></td> -<td><p>Class labels of the ProSnow datasets.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code>()</p></td> -<td><p>Sentinel 2 bands of the ProSnow datasets.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.ProSnowObergurgl.get_size" title="core.dataset.ProSnowObergurgl.get_size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code></a>()</p></td> -<td><p>Image size of the ProSnow Obergurgl dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code>(scene_id)</p></td> -<td><p>Parse ProSnow scene identifiers (Sentinel 2).</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code>(data, gt)</p></td> -<td><p>Preprocess ProSnow dataset images.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.dataset.ProSnowObergurgl.get_size"> -<code class="sig-name descname">get_size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#ProSnowObergurgl.get_size"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.ProSnowObergurgl.get_size" title="Permalink to this definition">¶</a></dt> -<dd><p>Image size of the ProSnow Obergurgl dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>size</strong> – The image size (height, width).</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>tuple</cite></p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.dataset.SparcsDataset"> -<em class="property">class </em><code class="sig-prename descclassname">core.dataset.</code><code class="sig-name descname">SparcsDataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#SparcsDataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.SparcsDataset" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.dataset.StandardEoDataset" title="core.dataset.StandardEoDataset"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.dataset.StandardEoDataset</span></code></a></p> -<p>Class for the <a class="reference external" href="https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation">Sparcs</a> dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. All -directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for files -matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.SparcsDataset.get_labels" title="core.dataset.SparcsDataset.get_labels"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code></a>()</p></td> -<td><p>Class labels of the Sparcs dataset.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.SparcsDataset.get_sensor" title="core.dataset.SparcsDataset.get_sensor"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code></a>()</p></td> -<td><p>Landsat 8 bands of the Sparcs dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.SparcsDataset.get_size" title="core.dataset.SparcsDataset.get_size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code></a>()</p></td> -<td><p>Image size of the Sparcs dataset.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.SparcsDataset.parse_scene_id" title="core.dataset.SparcsDataset.parse_scene_id"><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code></a>(scene_id)</p></td> -<td><p>Parse Sparcs scene identifiers (Landsat 8).</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.dataset.SparcsDataset.preprocess" title="core.dataset.SparcsDataset.preprocess"><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code></a>(data, gt)</p></td> -<td><p>Preprocess Sparcs dataset images.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.dataset.SparcsDataset.get_labels"> -<code class="sig-name descname">get_labels</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#SparcsDataset.get_labels"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.SparcsDataset.get_labels" title="Permalink to this definition">¶</a></dt> -<dd><p>Class labels of the Sparcs dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>labels</strong> – The class labels.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>enum.Enum</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.SparcsDataset.get_sensor"> -<code class="sig-name descname">get_sensor</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#SparcsDataset.get_sensor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.SparcsDataset.get_sensor" title="Permalink to this definition">¶</a></dt> -<dd><p>Landsat 8 bands of the Sparcs dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>sensor</strong> – An enumeration of the bands of the sensor.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>enum.Enum</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.SparcsDataset.get_size"> -<code class="sig-name descname">get_size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#SparcsDataset.get_size"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.SparcsDataset.get_size" title="Permalink to this definition">¶</a></dt> -<dd><p>Image size of the Sparcs dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>size</strong> – The image size (height, width).</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>tuple</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.SparcsDataset.parse_scene_id"> -<code class="sig-name descname">parse_scene_id</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">scene_id</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#SparcsDataset.parse_scene_id"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.SparcsDataset.parse_scene_id" title="Permalink to this definition">¶</a></dt> -<dd><p>Parse Sparcs scene identifiers (Landsat 8).</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>scene_id</strong> (<cite>str</cite>) – A scene identifier.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>scene</strong> – A dictionary containing scene metadata. If <cite>None</cite>, <code class="docutils literal notranslate"><span class="pre">scene_id</span></code> is -not a valid Landsat scene identifier.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>dict</cite> or <cite>None</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.dataset.SparcsDataset.preprocess"> -<code class="sig-name descname">preprocess</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">gt</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#SparcsDataset.preprocess"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.SparcsDataset.preprocess" title="Permalink to this definition">¶</a></dt> -<dd><p>Preprocess Sparcs dataset images.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>data</strong> (<cite>numpy.ndarray</cite>) – The sample input data.</p></li> -<li><p><strong>gt</strong> (<cite>numpy.ndarray</cite>) – The sample ground truth.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>data</strong> (<cite>numpy.ndarray</cite>) – The preprocessed input data.</p></li> -<li><p><strong>gt</strong> (<cite>numpy.ndarray</cite>) – The preprocessed ground truth data.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.dataset.StandardEoDataset"> -<em class="property">class </em><code class="sig-prename descclassname">core.dataset.</code><code class="sig-name descname">StandardEoDataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#StandardEoDataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.StandardEoDataset" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.dataset.ImageDataset" title="core.dataset.ImageDataset"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.dataset.ImageDataset</span></code></a></p> -<p>Base class for standard Earth Observation style datasets.</p> -<p><cite>pysegcnn.core.dataset.StandardEoDataset</cite> implements the -<cite>~pysegcnn.core.dataset.StandardEoDataset.compose_scenes</cite> method for -datasets with the following directory structure:</p> -<dl> -<dt>root_dir/</dt><dd><dl class="simple"> -<dt>scene_id_1/</dt><dd><p>scene_id_1_B1.tif -scene_id_1_B2.tif -. -. -. -scene_id_1_BN.tif</p> -</dd> -<dt>scene_id_2/</dt><dd><p>scene_id_2_B1.tif -scene_id_2_B2.tif -. -. -. -scene_id_2_BN.tif</p> -</dd> -</dl> -<p>. -scene_id_N/</p> -<blockquote> -<div><p>.</p> -</div></blockquote> -</dd> -</dl> -<p>If your dataset shares this directory structure, you can directly inherit -<cite>pysegcnn.core.dataset.StandardEoDataset</cite> and implement the remaining -methods.</p> -<p>See <cite>pysegcnn.core.dataset.SparcsDataset</cite> for an example.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. All -directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for files -matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.dataset.StandardEoDataset.compose_scenes" title="core.dataset.StandardEoDataset.compose_scenes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code></a>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code>()</p></td> -<td><p>Return an enumeration of the class labels of the dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code>()</p></td> -<td><p>Return an enumeration of the bands of the sensor of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code>()</p></td> -<td><p>Return the size of the images in the dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code>(scene_id)</p></td> -<td><p>Parse the scene identifier.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code>(data, gt)</p></td> -<td><p>Preprocess a sample before feeding it to a model.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.dataset.StandardEoDataset.compose_scenes"> -<code class="sig-name descname">compose_scenes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#StandardEoDataset.compose_scenes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.StandardEoDataset.compose_scenes" title="Permalink to this definition">¶</a></dt> -<dd><p>Build the list of samples of the dataset.</p> -<p>Each sample is represented by a dictionary.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>scenes</strong> –</p> -<dl class="simple"> -<dt>Each item in <code class="docutils literal notranslate"><span class="pre">scenes</span></code> is a <cite>dict</cite> with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_1'</span></code></dt><dd><p>Path to the file of band_1.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_2'</span></code></dt><dd><p>Path to the file of band_2.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'band_name_n'</span></code></dt><dd><p>Path to the file of band_n.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'gt'</span></code></dt><dd><p>Path to the ground truth file.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'date'</span></code></dt><dd><p>The date of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'tile'</span></code></dt><dd><p>The tile id of the sample.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'transform'</span></code></dt><dd><p>The transformation to apply.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'id'</span></code></dt><dd><p>The scene identifier.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>list</cite> [<cite>dict</cite>]</p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.dataset.SupportedDatasets"> -<em class="property">class </em><code class="sig-prename descclassname">core.dataset.</code><code class="sig-name descname">SupportedDatasets</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/dataset.html#SupportedDatasets"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.dataset.SupportedDatasets" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></p> -<p>Names and corresponding classes of the implemented datasets.</p> -<dl class="py attribute"> -<dt id="core.dataset.SupportedDatasets.Cloud95"> -<code class="sig-name descname">Cloud95</code><em class="property"> = <class 'core.dataset.Cloud95Dataset'></em><a class="headerlink" href="#core.dataset.SupportedDatasets.Cloud95" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.dataset.SupportedDatasets.Garmisch"> -<code class="sig-name descname">Garmisch</code><em class="property"> = <class 'core.dataset.ProSnowGarmisch'></em><a class="headerlink" href="#core.dataset.SupportedDatasets.Garmisch" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.dataset.SupportedDatasets.Obergurgl"> -<code class="sig-name descname">Obergurgl</code><em class="property"> = <class 'core.dataset.ProSnowObergurgl'></em><a class="headerlink" href="#core.dataset.SupportedDatasets.Obergurgl" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.dataset.SupportedDatasets.Sparcs"> -<code class="sig-name descname">Sparcs</code><em class="property"> = <class 'core.dataset.SparcsDataset'></em><a class="headerlink" href="#core.dataset.SupportedDatasets.Sparcs" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.graphics"> -<span id="core-graphics-module"></span><h2>core.graphics module<a class="headerlink" href="#module-core.graphics" title="Permalink to this headline">¶</a></h2> -<p>Functions to plot multispectral image data and model output.</p> -<div class="section" id="id4"> -<h3>License<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py function"> -<dt id="core.graphics.contrast_stretching"> -<code class="sig-prename descclassname">core.graphics.</code><code class="sig-name descname">contrast_stretching</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">image</span></em>, <em class="sig-param"><span class="n">alpha</span><span class="o">=</span><span class="default_value">5</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/graphics.html#contrast_stretching"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.graphics.contrast_stretching" title="Permalink to this definition">¶</a></dt> -<dd><p>Apply percentile stretching to an image to increase constrast.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>image</strong> (<cite>numpy.ndarray</cite>) – the input image.</p></li> -<li><p><strong>alpha</strong> (<cite>int</cite>, optional) – The level of the percentiles. The default is 5.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>norm</strong> – the stretched image.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>numpy.ndarray</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.graphics.plot_confusion_matrix"> -<code class="sig-prename descclassname">core.graphics.</code><code class="sig-name descname">plot_confusion_matrix</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">cm</span></em>, <em class="sig-param"><span class="n">labels</span></em>, <em class="sig-param"><span class="n">normalize</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">figsize</span><span class="o">=</span><span class="default_value">10, 10</span></em>, <em class="sig-param"><span class="n">cmap</span><span class="o">=</span><span class="default_value">'Blues'</span></em>, <em class="sig-param"><span class="n">state</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">outpath</span><span class="o">=</span><span class="default_value">'c:\\eurac\\2020\\git\\pysegcnn\\pysegcnn\\main\\_graphics/'</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/graphics.html#plot_confusion_matrix"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.graphics.plot_confusion_matrix" title="Permalink to this definition">¶</a></dt> -<dd><p>Plot the confusion matrix <code class="docutils literal notranslate"><span class="pre">cm</span></code>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>cm</strong> (<cite>numpy.ndarray</cite>) – The confusion matrix.</p></li> -<li><p><strong>labels</strong> (<cite>dict</cite> [<cite>int</cite>, <cite>dict</cite>]) – <p>The label dictionary. The keys are the values of the class labels -in the ground truth <code class="docutils literal notranslate"><span class="pre">y</span></code>. Each nested <cite>dict</cite> should have keys:</p> -<blockquote> -<div><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'color'</span></code></dt><dd><p>A named color (<cite>str</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'label'</span></code></dt><dd><p>The name of the class label (<cite>str</cite>).</p> -</dd> -</dl> -</div></blockquote> -</p></li> -<li><p><strong>normalize</strong> (<cite>bool</cite>, optional) – Whether to normalize the confusion matrix. The default is True.</p></li> -<li><p><strong>figsize</strong> (<cite>tuple</cite>, optional) – The figure size in centimeters. The default is (10, 10).</p></li> -<li><p><strong>cmap</strong> (<cite>str</cite>, optional) – A colormap in <cite>matplotlib.pyplot.colormaps()</cite>. The default is ‘Blues’.</p></li> -<li><p><strong>state</strong> (<cite>str</cite> or <cite>None</cite>, optional) – Filename to save the plot to. <code class="docutils literal notranslate"><span class="pre">state</span></code> should be an existing model -state file ending with ‘.pt’. The default is None, i.e. plot is not -saved to disk.</p></li> -<li><p><strong>outpath</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>, optional) – Output path. The default is ‘pysegcnn/main/_graphics/’.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>fig</strong> (<cite>matplotlib.figure.Figure</cite>) – The figure handle.</p></li> -<li><p><strong>ax</strong> (<cite>matplotlib.axes._subplots.AxesSubplot</cite>) – The axes handle.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.graphics.plot_loss"> -<code class="sig-prename descclassname">core.graphics.</code><code class="sig-name descname">plot_loss</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">state_file</span></em>, <em class="sig-param"><span class="n">figsize</span><span class="o">=</span><span class="default_value">10, 10</span></em>, <em class="sig-param"><span class="n">step</span><span class="o">=</span><span class="default_value">5</span></em>, <em class="sig-param"><span class="n">colors</span><span class="o">=</span><span class="default_value">['lightgreen', 'green', 'skyblue', 'steelblue']</span></em>, <em class="sig-param"><span class="n">outpath</span><span class="o">=</span><span class="default_value">'c:\\eurac\\2020\\git\\pysegcnn\\pysegcnn\\main\\_graphics/'</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/graphics.html#plot_loss"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.graphics.plot_loss" title="Permalink to this definition">¶</a></dt> -<dd><p>Plot the observed loss and accuracy of a model run.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>state_file</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – The model state file. Model state files are stored in -pysegcnn/main/_models.</p></li> -<li><p><strong>figsize</strong> (<cite>tuple</cite>, optional) – The figure size in centimeters. The default is (10, 10).</p></li> -<li><p><strong>step</strong> (<cite>int</cite>, optional) – The step of epochs for the x-axis labels. The default is 5, i.e. label -each fifth epoch.</p></li> -<li><p><strong>colors</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of four named colors supported by <cite>matplotlib</cite>. -The default is [‘lightgreen’, ‘green’, ‘skyblue’, ‘steelblue’].</p></li> -<li><p><strong>outpath</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>, optional) – Output path. The default is ‘pysegcnn/main/_graphics/’.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>fig</strong> – The figure handle.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>matplotlib.figure.Figure</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.graphics.plot_sample"> -<code class="sig-prename descclassname">core.graphics.</code><code class="sig-name descname">plot_sample</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">use_bands</span></em>, <em class="sig-param"><span class="n">labels</span></em>, <em class="sig-param"><span class="n">y</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">y_pred</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">figsize</span><span class="o">=</span><span class="default_value">10, 10</span></em>, <em class="sig-param"><span class="n">bands</span><span class="o">=</span><span class="default_value">['nir', 'red', 'green']</span></em>, <em class="sig-param"><span class="n">state</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">outpath</span><span class="o">=</span><span class="default_value">'c:\\eurac\\2020\\git\\pysegcnn\\pysegcnn\\main\\_samples/'</span></em>, <em class="sig-param"><span class="n">alpha</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/graphics.html#plot_sample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.graphics.plot_sample" title="Permalink to this definition">¶</a></dt> -<dd><p>Plot false color composite (FCC), ground truth and model prediction.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>x</strong> (<cite>numpy.ndarray</cite> or <cite>torch.Tensor</cite>, (b, h, w)) – Array containing the raw data of the tile, shape=(bands, height, width)</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> of <cite>str</cite>) – List describing the order of the bands in <code class="docutils literal notranslate"><span class="pre">x</span></code>.</p></li> -<li><p><strong>labels</strong> (<cite>dict</cite> [<cite>int</cite>, <cite>dict</cite>]) – <p>The label dictionary. The keys are the values of the class labels -in the ground truth <code class="docutils literal notranslate"><span class="pre">y</span></code>. Each nested <cite>dict</cite> should have keys:</p> -<blockquote> -<div><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'color'</span></code></dt><dd><p>A named color (<cite>str</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'label'</span></code></dt><dd><p>The name of the class label (<cite>str</cite>).</p> -</dd> -</dl> -</div></blockquote> -</p></li> -<li><p><strong>y</strong> (<cite>numpy.ndarray</cite> or <cite>torch.Tensor</cite> or <cite>None</cite>, optional) – Array containing the ground truth of tile <code class="docutils literal notranslate"><span class="pre">x</span></code>, shape=(height, width). -The default is None.</p></li> -<li><p><strong>y_pred</strong> (<cite>numpy.ndarray</cite> or <cite>torch.Tensor</cite> or <cite>None</cite>, optional) – Array containing the prediction for tile <code class="docutils literal notranslate"><span class="pre">x</span></code>, shape=(height, width). -The default is None.</p></li> -<li><p><strong>figsize</strong> (<cite>tuple</cite>, optional) – The figure size in centimeters. The default is (10, 10).</p></li> -<li><p><strong>bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – The bands to build the FCC. The default is [‘nir’, ‘red’, ‘green’].</p></li> -<li><p><strong>state</strong> (<cite>str</cite> or <cite>None</cite>, optional) – Filename to save the plot to. <code class="docutils literal notranslate"><span class="pre">state</span></code> should be an existing model -state file ending with ‘.pt’. The default is None, i.e. plot is not -saved to disk.</p></li> -<li><p><strong>outpath</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>, optional) – Output path. The default is ‘pysegcnn/main/_samples’.</p></li> -<li><p><strong>alpha</strong> (<cite>int</cite>, optional) – The level of the percentiles to increase constrast in the FCC. -The default is 0, i.e. no stretching.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>fig</strong> (<cite>matplotlib.figure.Figure</cite>) – The figure handle.</p></li> -<li><p><strong>ax</strong> (<cite>numpy.ndarray</cite> [<cite>matplotlib.axes._subplots.AxesSubplot</cite>]) – An array of the axes handles.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.graphics.running_mean"> -<code class="sig-prename descclassname">core.graphics.</code><code class="sig-name descname">running_mean</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">w</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/graphics.html#running_mean"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.graphics.running_mean" title="Permalink to this definition">¶</a></dt> -<dd><p>Compute a running mean of the input sequence.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>x</strong> (<em>array_like</em>) – The sequence to compute a running mean on.</p></li> -<li><p><strong>w</strong> (<cite>int</cite>) – The window length of the running mean.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>rm</strong> – The running mean of the sequence <code class="docutils literal notranslate"><span class="pre">x</span></code>.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>numpy.ndarray</cite></p> -</dd> -</dl> -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.layers"> -<span id="core-layers-module"></span><h2>core.layers module<a class="headerlink" href="#module-core.layers" title="Permalink to this headline">¶</a></h2> -<p>Layers of a convolutional encoder-decoder network.</p> -<div class="section" id="id5"> -<h3>License<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py class"> -<dt id="core.layers.Block"> -<em class="property">class </em><code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">Block</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#Block"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.Block" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.modules.module.Module</span></code></p> -<p>Basic convolutional block.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>TypeError</strong> – Raised if <cite>~pysegcnn.core.layers.Block.layers</cite> method does not return -an instance of <cite>torch.nn.Sequential</cite>.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.Block.forward" title="core.layers.Block.forward"><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code></a>()</p></td> -<td><p>Forward pass of the block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.Block.layers" title="core.layers.Block.layers"><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code></a>()</p></td> -<td><p>Define the layers of the block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.layers.Block.forward"> -<code class="sig-name descname">forward</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#Block.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.Block.forward" title="Permalink to this definition">¶</a></dt> -<dd><p>Forward pass of the block.</p> -<dl class="field-list simple"> -<dt class="field-odd">Raises</dt> -<dd class="field-odd"><p><strong>NotImplementedError</strong> – Raised if <cite>pysegcnn.core.layers.Block</cite> is not inherited.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.layers.Block.layers"> -<code class="sig-name descname">layers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#Block.layers"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.Block.layers" title="Permalink to this definition">¶</a></dt> -<dd><p>Define the layers of the block.</p> -<dl class="field-list simple"> -<dt class="field-odd">Raises</dt> -<dd class="field-odd"><p><strong>NotImplementedError</strong> – Raised if <cite>pysegcnn.core.layers.Block</cite> is not inherited.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>layers</strong> – Return an instance of <cite>torch.nn.Sequential</cite> containing a sequence -of layer (<cite>torch.nn.Module</cite> ) instances.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>torch.nn.Sequential</cite> [<cite>torch.nn.Module</cite>]</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Block.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.layers.Block.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.layers.Conv2dSame"> -<em class="property">class </em><code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">Conv2dSame</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#Conv2dSame"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.Conv2dSame" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.modules.conv.Conv2d</span></code></p> -<p>A convolution preserving the shape of its input.</p> -<p>Given the kernel size, the dilation and a stride of 1, the padding is -calculated such that the output of the convolution has the same spatial -dimensions as the input.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>*args</strong> (<cite>list</cite> [<cite>str</cite>]) – <dl class="simple"> -<dt>positional arguments passed to <cite>torch.nn.Conv2d</cite>:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'in_channels'</span></code>: <cite>int</cite></dt><dd><p>Number of input channels.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'out_channels'</span></code>: <cite>int</cite></dt><dd><p>Number of output channels.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'kernel_size'</span></code>: <cite>int</cite> or <cite>tuple</cite> [<cite>int</cite>]</dt><dd><p>Size of the convolving kernel.</p> -</dd> -</dl> -</dd> -</dl> -</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional keyword arguments passed to <a href="#id23"><span class="problematic" id="id24">`torch.nn.Conv2d`_</span></a>.</p></li> -<li><p><strong>_torch.nn.Conv2d</strong> (<em>.</em>) – <a class="reference external" href="https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d">https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d</a></p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.Conv2dSame.same_padding" title="core.layers.Conv2dSame.same_padding"><code class="xref py py-obj docutils literal notranslate"><span class="pre">same_padding</span></code></a>(d, k)</p></td> -<td><p>Calculate the amount of padding.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 67%" /> -<col style="width: 33%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>forward</strong></p></td> -<td></td> -</tr> -<tr class="row-odd"><td><p><strong>reset_parameters</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.bias"> -<code class="sig-name descname">bias</code><em class="property">: Optional<span class="p">[</span>torch.Tensor<span class="p">]</span></em><a class="headerlink" href="#core.layers.Conv2dSame.bias" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.dilation"> -<code class="sig-name descname">dilation</code><em class="property">: Tuple<span class="p">[</span>int<span class="p">, </span><span class="p">…</span><span class="p">]</span></em><a class="headerlink" href="#core.layers.Conv2dSame.dilation" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.groups"> -<code class="sig-name descname">groups</code><em class="property">: int</em><a class="headerlink" href="#core.layers.Conv2dSame.groups" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.kernel_size"> -<code class="sig-name descname">kernel_size</code><em class="property">: Tuple<span class="p">[</span>int<span class="p">, </span><span class="p">…</span><span class="p">]</span></em><a class="headerlink" href="#core.layers.Conv2dSame.kernel_size" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.out_channels"> -<code class="sig-name descname">out_channels</code><em class="property">: int</em><a class="headerlink" href="#core.layers.Conv2dSame.out_channels" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.output_padding"> -<code class="sig-name descname">output_padding</code><em class="property">: Tuple<span class="p">[</span>int<span class="p">, </span><span class="p">…</span><span class="p">]</span></em><a class="headerlink" href="#core.layers.Conv2dSame.output_padding" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.padding"> -<code class="sig-name descname">padding</code><em class="property">: Tuple<span class="p">[</span>int<span class="p">, </span><span class="p">…</span><span class="p">]</span></em><a class="headerlink" href="#core.layers.Conv2dSame.padding" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.padding_mode"> -<code class="sig-name descname">padding_mode</code><em class="property">: str</em><a class="headerlink" href="#core.layers.Conv2dSame.padding_mode" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.layers.Conv2dSame.same_padding"> -<em class="property">static </em><code class="sig-name descname">same_padding</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">d</span></em>, <em class="sig-param"><span class="n">k</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#Conv2dSame.same_padding"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.Conv2dSame.same_padding" title="Permalink to this definition">¶</a></dt> -<dd><p>Calculate the amount of padding.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>d</strong> (<cite>int</cite>) – The dilation of the convolution.</p></li> -<li><p><strong>k</strong> (<cite>int</cite>) – The kernel size.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>p</strong> – the amount of padding.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>int</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.stride"> -<code class="sig-name descname">stride</code><em class="property">: Tuple<span class="p">[</span>int<span class="p">, </span><span class="p">…</span><span class="p">]</span></em><a class="headerlink" href="#core.layers.Conv2dSame.stride" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.transposed"> -<code class="sig-name descname">transposed</code><em class="property">: bool</em><a class="headerlink" href="#core.layers.Conv2dSame.transposed" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Conv2dSame.weight"> -<code class="sig-name descname">weight</code><em class="property">: torch.Tensor</em><a class="headerlink" href="#core.layers.Conv2dSame.weight" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.layers.ConvBnReluMaxPool"> -<em class="property">class </em><code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">ConvBnReluMaxPool</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluMaxPool"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluMaxPool" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.layers.EncoderBlock" title="core.layers.EncoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.layers.EncoderBlock</span></code></a></p> -<p>Block of convolution, batchnorm, relu and 2x2 max pool.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional keyword arguments passed to -<cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.layers.ConvBnReluMaxPool.downsample" title="core.layers.ConvBnReluMaxPool.downsample"><code class="xref py py-obj docutils literal notranslate"><span class="pre">downsample</span></code></a>(x)</p></td> -<td><p>2x2 max pooling layer, <cite>torch.nn.functional.max_pool2d</cite>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.layers.ConvBnReluMaxPool.extra_repr" title="core.layers.ConvBnReluMaxPool.extra_repr"><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code></a>()</p></td> -<td><p>Define optional extra information about this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x)</p></td> -<td><p>Forward pass of an encoder block.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.layers.ConvBnReluMaxPool.layers" title="core.layers.ConvBnReluMaxPool.layers"><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code></a>()</p></td> -<td><p>Sequence of convolution, batchnorm and relu layers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.layers.ConvBnReluMaxPool.downsample"> -<code class="sig-name descname">downsample</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluMaxPool.downsample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluMaxPool.downsample" title="Permalink to this definition">¶</a></dt> -<dd><p>2x2 max pooling layer, <cite>torch.nn.functional.max_pool2d</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Input tensor.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height // 2, width // 2)) – The 2x2 max pooled tensor.</p></li> -<li><p><strong>indices</strong> (<cite>torch.Tensor</cite> or <cite>None</cite>) – The indices of the maxima. Useful for upsampling with -<cite>torch.nn.functional.max_unpool2d</cite>.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.layers.ConvBnReluMaxPool.extra_repr"> -<code class="sig-name descname">extra_repr</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluMaxPool.extra_repr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluMaxPool.extra_repr" title="Permalink to this definition">¶</a></dt> -<dd><p>Define optional extra information about this module.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p>Extra representation string.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>str</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.layers.ConvBnReluMaxPool.layers"> -<code class="sig-name descname">layers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluMaxPool.layers"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluMaxPool.layers" title="Permalink to this definition">¶</a></dt> -<dd><p>Sequence of convolution, batchnorm and relu layers.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>layers</strong> – An instance of <cite>torch.nn.Sequential</cite> containing the sequence -of convolution, batchnorm and relu layer (<cite>torch.nn.Module</cite>) -instances.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>torch.nn.Sequential</cite> [<cite>torch.nn.Module</cite>]</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.ConvBnReluMaxPool.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.layers.ConvBnReluMaxPool.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.layers.ConvBnReluMaxUnpool"> -<em class="property">class </em><code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">ConvBnReluMaxUnpool</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluMaxUnpool"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluMaxUnpool" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.layers.DecoderBlock" title="core.layers.DecoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.layers.DecoderBlock</span></code></a></p> -<p>Block of convolution, batchnorm, relu and 2x2 max unpool.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional keyword arguments passed to -<cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.ConvBnReluMaxUnpool.extra_repr" title="core.layers.ConvBnReluMaxUnpool.extra_repr"><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code></a>()</p></td> -<td><p>Define optional extra information about this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x, feature, indices, skip)</p></td> -<td><p>Forward pass of a decoder block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.ConvBnReluMaxUnpool.layers" title="core.layers.ConvBnReluMaxUnpool.layers"><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code></a>()</p></td> -<td><p>Sequence of convolution, batchnorm and relu layers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.ConvBnReluMaxUnpool.upsample" title="core.layers.ConvBnReluMaxUnpool.upsample"><code class="xref py py-obj docutils literal notranslate"><span class="pre">upsample</span></code></a>(x, feature, indices)</p></td> -<td><p>2x2 max unpooling layer.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.layers.ConvBnReluMaxUnpool.extra_repr"> -<code class="sig-name descname">extra_repr</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluMaxUnpool.extra_repr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluMaxUnpool.extra_repr" title="Permalink to this definition">¶</a></dt> -<dd><p>Define optional extra information about this module.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p>Extra representation string.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>str</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.layers.ConvBnReluMaxUnpool.layers"> -<code class="sig-name descname">layers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluMaxUnpool.layers"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluMaxUnpool.layers" title="Permalink to this definition">¶</a></dt> -<dd><p>Sequence of convolution, batchnorm and relu layers.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>layers</strong> – An instance of <cite>torch.nn.Sequential</cite> containing the sequence -of convolution, batchnorm and relu layer (<cite>torch.nn.Module</cite>) -instances.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>torch.nn.Sequential</cite> [<cite>torch.nn.Module</cite>]</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.ConvBnReluMaxUnpool.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.layers.ConvBnReluMaxUnpool.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.layers.ConvBnReluMaxUnpool.upsample"> -<code class="sig-name descname">upsample</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">feature</span></em>, <em class="sig-param"><span class="n">indices</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluMaxUnpool.upsample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluMaxUnpool.upsample" title="Permalink to this definition">¶</a></dt> -<dd><p>2x2 max unpooling layer.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Input tensor.</p></li> -<li><p><strong>feature</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Intermediate output of a layer in the encoder. Used to determine -the output shape of the upsampling operation.</p></li> -<li><p><strong>indices</strong> (<cite>torch.Tensor</cite>) – The indices of the maxima of the max pooling operation -(as returned by <cite>torch.nn.functional.max_pool2d</cite>).</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>x</strong> – The 2x2 max unpooled tensor.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>torch.Tensor</cite>, shape=(batch, channel, height * 2, width * 2)</p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.layers.ConvBnReluUpsample"> -<em class="property">class </em><code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">ConvBnReluUpsample</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluUpsample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluUpsample" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.layers.DecoderBlock" title="core.layers.DecoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.layers.DecoderBlock</span></code></a></p> -<p>Block of convolution, batchnorm, relu and nearest neighbor upsampling.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.ConvBnReluUpsample.extra_repr" title="core.layers.ConvBnReluUpsample.extra_repr"><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code></a>()</p></td> -<td><p>Define optional extra information about this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x, feature, indices, skip)</p></td> -<td><p>Forward pass of a decoder block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.ConvBnReluUpsample.layers" title="core.layers.ConvBnReluUpsample.layers"><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code></a>()</p></td> -<td><p>Sequence of convolution, batchnorm and relu layers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.ConvBnReluUpsample.upsample" title="core.layers.ConvBnReluUpsample.upsample"><code class="xref py py-obj docutils literal notranslate"><span class="pre">upsample</span></code></a>(x, feature[, indices])</p></td> -<td><p>Nearest neighbor upsampling.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.layers.ConvBnReluUpsample.extra_repr"> -<code class="sig-name descname">extra_repr</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluUpsample.extra_repr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluUpsample.extra_repr" title="Permalink to this definition">¶</a></dt> -<dd><p>Define optional extra information about this module.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p>Extra representation string.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>str</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.layers.ConvBnReluUpsample.layers"> -<code class="sig-name descname">layers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluUpsample.layers"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluUpsample.layers" title="Permalink to this definition">¶</a></dt> -<dd><p>Sequence of convolution, batchnorm and relu layers.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>layers</strong> – An instance of <cite>torch.nn.Sequential</cite> containing the sequence -of convolution, batchnorm and relu layer (<cite>torch.nn.Module</cite>) -instances.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>torch.nn.Sequential</cite> [<cite>torch.nn.Module</cite>]</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.ConvBnReluUpsample.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.layers.ConvBnReluUpsample.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.layers.ConvBnReluUpsample.upsample"> -<code class="sig-name descname">upsample</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">feature</span></em>, <em class="sig-param"><span class="n">indices</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#ConvBnReluUpsample.upsample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.ConvBnReluUpsample.upsample" title="Permalink to this definition">¶</a></dt> -<dd><p>Nearest neighbor upsampling.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Input tensor.</p></li> -<li><p><strong>feature</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Intermediate output of a layer in the encoder. Used to determine -the output shape of the upsampling operation.</p></li> -<li><p><strong>indices</strong> (<cite>None</cite>, optional) – The indices of the maxima of the max pooling operation -(as returned by <cite>torch.nn.functional.max_pool2d</cite>). Not required by -this upsampling method.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>x</strong> – The 2x2 upsampled tensor.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>torch.Tensor</cite>, shape=(batch, channel, height, width)</p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.layers.Decoder"> -<em class="property">class </em><code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">Decoder</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">filters</span></em>, <em class="sig-param"><span class="n">block</span></em>, <em class="sig-param"><span class="n">skip</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#Decoder"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.Decoder" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.modules.module.Module</span></code></p> -<p>Generic convolutional decoder.</p> -<p>When instanciating an encoder-decoder architechure, <code class="docutils literal notranslate"><span class="pre">filters</span></code> should be -the same for <cite>pysegcnn.core.layers.Encoder</cite> and -<cite>pysegcnn.core.layers.Decoder</cite>.</p> -<p>See <cite>pysegcnn.core.models.UNet</cite> for an example implementation.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>filters</strong> (<cite>list</cite> [<cite>int</cite>]) – List of input channels to each convolutional block. The length of -<code class="docutils literal notranslate"><span class="pre">filters</span></code> determines the depth of the decoder. The first element of -<code class="docutils literal notranslate"><span class="pre">filters</span></code> has to be the number of channels of the input images.</p></li> -<li><p><strong>block</strong> (<cite>pysegcnn.core.layers.DecoderBlock</cite>) – The convolutional block defining a layer in the decoder. -A subclass of <cite>pysegcnn.core.layers.DecoderBlock</cite>, e.g. -<cite>pysegcnn.core.layers.ConvBnReluMaxUnpool</cite>.</p></li> -<li><p><strong>skip</strong> (<cite>bool</cite>) – Whether to apply skip connections from the encoder to the decoder.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.Decoder.forward" title="core.layers.Decoder.forward"><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code></a>(x, enc_cache)</p></td> -<td><p>Forward pass of the decoder.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.layers.Decoder.forward"> -<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">enc_cache</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#Decoder.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.Decoder.forward" title="Permalink to this definition">¶</a></dt> -<dd><p>Forward pass of the decoder.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Output of the encoder.</p></li> -<li><p><strong>enc_cache</strong> (<cite>dict</cite> [<cite>dict</cite>]) – <p>Cache dictionary. The keys of the dictionary are the number of the -network layers and the values are dictionaries with the following -(key, value) pairs:</p> -<blockquote> -<div><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">"feature"</span></code></dt><dd><p>The intermediate encoder outputs (<cite>torch.Tensor</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">"indices"</span></code></dt><dd><p>The indices of the max pooling layer (<cite>torch.Tensor</cite>).</p> -</dd> -</dl> -</div></blockquote> -</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>x</strong> – Output of the decoder.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>torch.Tensor</cite>, shape=(batch, channel, height, width)</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Decoder.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.layers.Decoder.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.layers.DecoderBlock"> -<em class="property">class </em><code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">DecoderBlock</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#DecoderBlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.DecoderBlock" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.layers.Block" title="core.layers.Block"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.layers.Block</span></code></a></p> -<p>Block of a convolutional decoder.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.DecoderBlock.forward" title="core.layers.DecoderBlock.forward"><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code></a>(x, feature, indices, skip)</p></td> -<td><p>Forward pass of a decoder block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code>()</p></td> -<td><p>Define the layers of the block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.DecoderBlock.upsample" title="core.layers.DecoderBlock.upsample"><code class="xref py py-obj docutils literal notranslate"><span class="pre">upsample</span></code></a>(x, feature, indices)</p></td> -<td><p>Define the upsampling method.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.layers.DecoderBlock.forward"> -<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">feature</span></em>, <em class="sig-param"><span class="n">indices</span></em>, <em class="sig-param"><span class="n">skip</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#DecoderBlock.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.DecoderBlock.forward" title="Permalink to this definition">¶</a></dt> -<dd><p>Forward pass of a decoder block.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Input tensor.</p></li> -<li><p><strong>feature</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Intermediate output of a layer in the encoder. -If <code class="docutils literal notranslate"><span class="pre">skip</span></code> = True, <code class="docutils literal notranslate"><span class="pre">feature</span></code> is concatenated (along the channel -axis) to the output of the respective upsampling layer in the -decoder (skip connection).</p></li> -<li><p><strong>indices</strong> (<cite>torch.Tensor</cite> or <cite>None</cite>) – Indices of the encoder downsampling method.</p></li> -<li><p><strong>skip</strong> (<cite>bool</cite>) – Whether to apply the skip connection.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>x</strong> – Output of the decoder block.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>torch.Tensor</cite>, shape=(batch, channel, height, width)</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.DecoderBlock.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.layers.DecoderBlock.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.layers.DecoderBlock.upsample"> -<code class="sig-name descname">upsample</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">feature</span></em>, <em class="sig-param"><span class="n">indices</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#DecoderBlock.upsample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.DecoderBlock.upsample" title="Permalink to this definition">¶</a></dt> -<dd><p>Define the upsampling method.</p> -<p>The <cite>~pysegcnn.core.layers.DecoderBlock.upsample</cite> method should -implement the spatial upsampling operation.</p> -<dl class="simple"> -<dt>Use one of the following functions to upsample:</dt><dd><ul class="simple"> -<li><p><cite>torch.nn.functional.max_unpool2d</cite></p></li> -<li><p><cite>torch.nn.functional.interpolate</cite></p></li> -</ul> -</dd> -</dl> -<p>See <cite>pysegcnn.core.layers.ConvBnReluMaxUnpool</cite> or -<cite>pysegcnn.core.layers.ConvBnReluUpsample</cite> for an example -implementation.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Input tensor, e.g. output of a convolutional block.</p></li> -<li><p><strong>feature</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Intermediate output of a layer in the encoder. Used to implement -skip connections.</p></li> -<li><p><strong>indices</strong> (<cite>torch.Tensor</cite> or <cite>None</cite>) – Indices of the encoder downsampling method.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>NotImplementedError</strong> – Raised if <cite>pysegcnn.core.layers.DecoderBlock</cite> is not inherited.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>x</strong> – The spatially upsampled tensor.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>torch.Tensor</cite>, shape=(batch, channel, height, width)</p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.layers.Encoder"> -<em class="property">class </em><code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">Encoder</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">filters</span></em>, <em class="sig-param"><span class="n">block</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#Encoder"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.Encoder" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.modules.module.Module</span></code></p> -<p>Generic convolutional encoder.</p> -<p>When instanciating an encoder-decoder architechure, <code class="docutils literal notranslate"><span class="pre">filters</span></code> should be -the same for <cite>pysegcnn.core.layers.Encoder</cite> and -<cite>pysegcnn.core.layers.Decoder</cite>.</p> -<p>See <cite>pysegcnn.core.models.UNet</cite> for an example implementation.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>filters</strong> (<cite>list</cite> [<cite>int</cite>]) – List of input channels to each convolutional block. The length of -<code class="docutils literal notranslate"><span class="pre">filters</span></code> determines the depth of the encoder. The first element of -<code class="docutils literal notranslate"><span class="pre">filters</span></code> has to be the number of channels of the input images.</p></li> -<li><p><strong>block</strong> (<cite>pysegcnn.core.layers.EncoderBlock</cite>) – The convolutional block defining a layer in the encoder. -A subclass of <cite>pysegcnn.core.layers.EncoderBlock</cite>, e.g. -<cite>pysegcnn.core.layers.ConvBnReluMaxPool</cite>.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.layers.Encoder.forward" title="core.layers.Encoder.forward"><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code></a>(x)</p></td> -<td><p>Forward pass of the encoder.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.layers.Encoder.forward"> -<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#Encoder.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.Encoder.forward" title="Permalink to this definition">¶</a></dt> -<dd><p>Forward pass of the encoder.</p> -<p>Stores intermediate outputs in a dictionary. The keys of the dictionary -are the number of the network layers and the values are dictionaries -with the following (key, value) pairs:</p> -<blockquote> -<div><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">"feature"</span></code></dt><dd><p>The intermediate encoder outputs (<cite>torch.Tensor</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">"indices"</span></code></dt><dd><p>The indices of the max pooling layer, if required -(<cite>torch.Tensor</cite>).</p> -</dd> -</dl> -</div></blockquote> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Input image.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>x</strong> – Output of the encoder.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>torch.Tensor</cite>, shape=(batch, channel, height, width)</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.Encoder.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.layers.Encoder.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.layers.EncoderBlock"> -<em class="property">class </em><code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">EncoderBlock</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#EncoderBlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.EncoderBlock" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.layers.Block" title="core.layers.Block"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.layers.Block</span></code></a></p> -<p>Block of a convolutional encoder.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.layers.EncoderBlock.downsample" title="core.layers.EncoderBlock.downsample"><code class="xref py py-obj docutils literal notranslate"><span class="pre">downsample</span></code></a>(x)</p></td> -<td><p>Define the downsampling method.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.layers.EncoderBlock.forward" title="core.layers.EncoderBlock.forward"><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code></a>(x)</p></td> -<td><p>Forward pass of an encoder block.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code>()</p></td> -<td><p>Define the layers of the block.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.layers.EncoderBlock.downsample"> -<code class="sig-name descname">downsample</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#EncoderBlock.downsample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.EncoderBlock.downsample" title="Permalink to this definition">¶</a></dt> -<dd><p>Define the downsampling method.</p> -<p>The <cite>~pysegcnn.core.layers.EncoderBlock.downsample</cite> method should -implement the spatial pooling operation.</p> -<dl class="simple"> -<dt>Use one of the following functions to downsample:</dt><dd><ul class="simple"> -<li><p><cite>torch.nn.functional.max_pool2d</cite></p></li> -<li><p><cite>torch.nn.functional.interpolate</cite></p></li> -</ul> -</dd> -</dl> -<p>See <cite>pysegcnn.core.layers.ConvBnReluMaxPool</cite> for an example -implementation.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Input tensor, e.g. output of a convolutional block.</p> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>NotImplementedError</strong> – Raised if <cite>pysegcnn.core.layers.EncoderBlock</cite> is not inherited.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul class="simple"> -<li><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – The spatially downsampled tensor.</p></li> -<li><p><strong>indices</strong> (<cite>torch.Tensor</cite> or <cite>None</cite>) – Optional indices of the downsampling method, e.g. indices of the -maxima when using <cite>torch.nn.functional.max_pool2d</cite>. Useful for -upsampling later. If no indices are required to upsample, simply -return <code class="docutils literal notranslate"><span class="pre">indices</span></code> = <cite>None</cite>.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.layers.EncoderBlock.forward"> -<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#EncoderBlock.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.EncoderBlock.forward" title="Permalink to this definition">¶</a></dt> -<dd><p>Forward pass of an encoder block.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>x</strong> (<cite>torch.Tensor</cite>) – Input tensor, e.g. output of the previous block/layer.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>y</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Output of the encoder block.</p></li> -<li><p><strong>x</strong> (<cite>torch.Tensor</cite>, shape=(batch, channel, height, width)) – Intermediate output before applying downsampling. Useful to -implement skip connections.</p></li> -<li><p><strong>indices</strong> (<cite>torch.Tensor</cite> or <cite>None</cite>) – Optional indices of the downsampling method, e.g. indices of the -maxima when using <cite>torch.nn.functional.max_pool2d</cite>. Useful for -upsampling later. If no indices are required to upsample, simply -return <code class="docutils literal notranslate"><span class="pre">indices</span></code> = <cite>None</cite>.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.layers.EncoderBlock.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.layers.EncoderBlock.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py function"> -<dt id="core.layers.conv_bn_relu"> -<code class="sig-prename descclassname">core.layers.</code><code class="sig-name descname">conv_bn_relu</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/layers.html#conv_bn_relu"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.layers.conv_bn_relu" title="Permalink to this definition">¶</a></dt> -<dd><p>Block of convolution, batch normalization and rectified linear unit.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>block</strong> – An instance of <cite>torch.nn.Sequential</cite> containing a sequence of -convolution, batch normalization and rectified linear unit layers.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>torch.nn.Sequential</cite> [<cite>torch.nn.Module</cite>]</p> -</dd> -</dl> -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.logging"> -<span id="core-logging-module"></span><h2>core.logging module<a class="headerlink" href="#module-core.logging" title="Permalink to this headline">¶</a></h2> -<p>Logging configuration.</p> -<div class="section" id="id6"> -<h3>License<a class="headerlink" href="#id6" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py function"> -<dt id="core.logging.log_conf"> -<code class="sig-prename descclassname">core.logging.</code><code class="sig-name descname">log_conf</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">logfile</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/logging.html#log_conf"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.logging.log_conf" title="Permalink to this definition">¶</a></dt> -<dd><p>Set basic logging configuration passed to <cite>logging.config.dictConfig</cite>.</p> -<p>See the logging <a class="reference external" href="https://docs.python.org/3/library/logging.config.html#dictionary-schema-details">docs</a> for a detailed description of the configuration -dictionary.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>logfile</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – The file to save the logs to.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>LOGGING_CONFIG</strong> – The logging configuration.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.models"> -<span id="core-models-module"></span><h2>core.models module<a class="headerlink" href="#module-core.models" title="Permalink to this headline">¶</a></h2> -<p>Neural networks for semantic image segmentation.</p> -<div class="section" id="id7"> -<h3>License<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py class"> -<dt id="core.models.Network"> -<em class="property">class </em><code class="sig-prename descclassname">core.models.</code><code class="sig-name descname">Network</code><a class="reference internal" href="../_modules/core/models.html#Network"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.Network" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.modules.module.Module</span></code></p> -<p>Generic Network class.</p> -<p>The base class for each model. If you want to implement a new model, -inherit the <code class="docutils literal notranslate"><span class="pre">~pysegcnn.core.models.Network</span></code> class.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> -</dd> -<dt class="field-odd">Attributes</dt> -<dd class="field-odd"><dl class="simple"> -<dt><a class="reference internal" href="#core.models.Network.state" title="core.models.Network.state"><code class="xref py py-obj docutils literal notranslate"><span class="pre">state</span></code></a></dt><dd><p>Return the model state file.</p> -</dd> -</dl> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(*input)</p></td> -<td><p></p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.models.Network.freeze" title="core.models.Network.freeze"><code class="xref py py-obj docutils literal notranslate"><span class="pre">freeze</span></code></a>()</p></td> -<td><p>Freeze the weights of a model.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.models.Network.load" title="core.models.Network.load"><code class="xref py py-obj docutils literal notranslate"><span class="pre">load</span></code></a>(state_file)</p></td> -<td><p>Load a model state.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.models.Network.save" title="core.models.Network.save"><code class="xref py py-obj docutils literal notranslate"><span class="pre">save</span></code></a>(state_file, optimizer[, bands])</p></td> -<td><p>Save the model state.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.models.Network.unfreeze" title="core.models.Network.unfreeze"><code class="xref py py-obj docutils literal notranslate"><span class="pre">unfreeze</span></code></a>()</p></td> -<td><p>Unfreeze the weights of a model.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.models.Network.freeze"> -<code class="sig-name descname">freeze</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/models.html#Network.freeze"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.Network.freeze" title="Permalink to this definition">¶</a></dt> -<dd><p>Freeze the weights of a model.</p> -<p>Disables gradient computation: useful when using a pretrained model for -inference.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.models.Network.load"> -<em class="property">static </em><code class="sig-name descname">load</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">state_file</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/models.html#Network.load"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.Network.load" title="Permalink to this definition">¶</a></dt> -<dd><p>Load a model state.</p> -<p>Returns the model in <code class="docutils literal notranslate"><span class="pre">state_file</span></code> with the pretrained model and -optimizer weights. Useful when resuming training an existing model.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>state_file</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – The model state file. Model state files are stored in -pysegcnn/main/_models.</p> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>FileNotFoundError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">state_file</span></code> does not exist.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul class="simple"> -<li><p><strong>model</strong> (<cite>pysegcnn.core.models.Network</cite>) – The pretrained model.</p></li> -<li><p><strong>optimizer</strong> (<cite>torch.optim.Optimizer</cite>) – The optimizer used to train the model.</p></li> -<li><p><strong>model_state</strong> (‘<cite>dict</cite>) – A dictionary containing the model and optimizer state, as -constructed by <cite>~pysegcnn.core.Network.save</cite>.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.models.Network.save"> -<code class="sig-name descname">save</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">state_file</span></em>, <em class="sig-param"><span class="n">optimizer</span></em>, <em class="sig-param"><span class="n">bands</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/models.html#Network.save"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.Network.save" title="Permalink to this definition">¶</a></dt> -<dd><p>Save the model state.</p> -<p>Saves the model and optimizer states together with the model -construction parameters, to easily re-instanciate the model.</p> -<p>Optional <code class="docutils literal notranslate"><span class="pre">kwargs</span></code> are also saved.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>state_file</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – Path to save the model state.</p></li> -<li><p><strong>optimizer</strong> (<cite>torch.optim.Optimizer</cite>) – The optimizer used to train the model.</p></li> -<li><p><strong>bands</strong> (<cite>list</cite> [<cite>str</cite>] or <cite>None</cite>, optional) – List of bands the model is trained with. The default is None.</p></li> -<li><p><strong>**kwargs</strong> – Arbitrary keyword arguments. Each keyword argument will be saved -as (key, value) pair in <code class="docutils literal notranslate"><span class="pre">state_file</span></code>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>model_state</strong> – A dictionary containing the model and optimizer state</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.models.Network.state"> -<em class="property">property </em><code class="sig-name descname">state</code><a class="headerlink" href="#core.models.Network.state" title="Permalink to this definition">¶</a></dt> -<dd><p>Return the model state file.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>state_file</strong> – The model state file.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>pathlib.Path</cite> or <cite>None</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.models.Network.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.models.Network.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.models.Network.unfreeze"> -<code class="sig-name descname">unfreeze</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/models.html#Network.unfreeze"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.Network.unfreeze" title="Permalink to this definition">¶</a></dt> -<dd><p>Unfreeze the weights of a model.</p> -<p>Enables gradient computation: useful when adjusting a pretrained model -to a new dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.models.SupportedLossFunctions"> -<em class="property">class </em><code class="sig-prename descclassname">core.models.</code><code class="sig-name descname">SupportedLossFunctions</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/models.html#SupportedLossFunctions"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.SupportedLossFunctions" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></p> -<p>Names and corresponding classes of the tested loss functions.</p> -<dl class="py attribute"> -<dt id="core.models.SupportedLossFunctions.CrossEntropy"> -<code class="sig-name descname">CrossEntropy</code><em class="property"> = <class 'torch.nn.modules.loss.CrossEntropyLoss'></em><a class="headerlink" href="#core.models.SupportedLossFunctions.CrossEntropy" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.models.SupportedModels"> -<em class="property">class </em><code class="sig-prename descclassname">core.models.</code><code class="sig-name descname">SupportedModels</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/models.html#SupportedModels"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.SupportedModels" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></p> -<p>Names and corresponding classes of the implemented models.</p> -<dl class="py attribute"> -<dt id="core.models.SupportedModels.Unet"> -<code class="sig-name descname">Unet</code><em class="property"> = <class 'core.models.UNet'></em><a class="headerlink" href="#core.models.SupportedModels.Unet" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.models.SupportedOptimizers"> -<em class="property">class </em><code class="sig-prename descclassname">core.models.</code><code class="sig-name descname">SupportedOptimizers</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/models.html#SupportedOptimizers"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.SupportedOptimizers" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></p> -<p>Names and corresponding classes of the tested optimizers.</p> -<dl class="py attribute"> -<dt id="core.models.SupportedOptimizers.Adam"> -<code class="sig-name descname">Adam</code><em class="property"> = <class 'torch.optim.adam.Adam'></em><a class="headerlink" href="#core.models.SupportedOptimizers.Adam" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.models.UNet"> -<em class="property">class </em><code class="sig-prename descclassname">core.models.</code><code class="sig-name descname">UNet</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">nclasses</span></em>, <em class="sig-param"><span class="n">filters</span></em>, <em class="sig-param"><span class="n">skip</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/models.html#UNet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.UNet" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.models.Network" title="core.models.Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.models.Network</span></code></a></p> -<p>A PyTorch implementation of <a class="reference external" href="https://arxiv.org/abs/1505.04597">U-Net</a>.</p> -<dl class="simple"> -<dt>Slightly modified version of U-Net:</dt><dd><ul class="simple"> -<li><p>each convolution is followed by a batch normalization layer</p></li> -<li><p>the upsampling is implemented by a 2x2 max unpooling operation</p></li> -</ul> -</dd> -</dl> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of channels of the input images.</p></li> -<li><p><strong>nclasses</strong> (<cite>int</cite>) – Number of classes.</p></li> -<li><p><strong>filters</strong> (<cite>list</cite> [<cite>int</cite>]) – List of input channels to each convolutional block.</p></li> -<li><p><strong>skip</strong> (<cite>bool</cite>) – Whether to apply skip connections from the encoder to the decoder.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional keyword arguments passed to -<cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -<dt class="field-even">Attributes</dt> -<dd class="field-even"><dl class="simple"> -<dt><code class="xref py py-obj docutils literal notranslate"><span class="pre">state</span></code></dt><dd><p>Return the model state file.</p> -</dd> -</dl> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.models.UNet.forward" title="core.models.UNet.forward"><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code></a>(x)</p></td> -<td><p>Forward propagation of U-Net.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">freeze</span></code>()</p></td> -<td><p>Freeze the weights of a model.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load</span></code>(state_file)</p></td> -<td><p>Load a model state.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">save</span></code>(state_file, optimizer[, bands])</p></td> -<td><p>Save the model state.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">unfreeze</span></code>()</p></td> -<td><p>Unfreeze the weights of a model.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.models.UNet.forward"> -<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/models.html#UNet.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.models.UNet.forward" title="Permalink to this definition">¶</a></dt> -<dd><p>Forward propagation of U-Net.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>x</strong> (<cite>torch.Tensor</cite>) – The input image, shape=(batch_size, channels, height, width).</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>y</strong> – The classified image, shape=(batch_size, height, width).</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>‘torch.tensor’</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.models.UNet.training"> -<code class="sig-name descname">training</code><em class="property">: bool</em><a class="headerlink" href="#core.models.UNet.training" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.predict"> -<span id="core-predict-module"></span><h2>core.predict module<a class="headerlink" href="#module-core.predict" title="Permalink to this headline">¶</a></h2> -<p>Functions for model inference.</p> -<div class="section" id="id8"> -<h3>License<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py function"> -<dt id="core.predict.predict_samples"> -<code class="sig-prename descclassname">core.predict.</code><code class="sig-name descname">predict_samples</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">cm</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">plot</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/predict.html#predict_samples"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.predict.predict_samples" title="Permalink to this definition">¶</a></dt> -<dd><p>Classify each sample in <code class="docutils literal notranslate"><span class="pre">ds</span></code> with model <code class="docutils literal notranslate"><span class="pre">model</span></code>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.split.RandomSubset</cite> or) – </p></li> -<li><p><strong>pysegcnn.core.split.SceneSubset</strong> – An instance of <cite>~pysegcnn.core.split.RandomSubset</cite> or -<cite>~pysegcnn.core.split.SceneSubset</cite>.</p></li> -<li><p><strong>model</strong> (<cite>pysegcnn.core.models.Network</cite>) – An instance of <cite>~pysegcnn.core.models.Network</cite>.</p></li> -<li><p><strong>cm</strong> (<cite>bool</cite>, optional) – Whether to compute the confusion matrix. The default is False.</p></li> -<li><p><strong>plot</strong> (<cite>bool</cite>, optional) – Whether to plot a false color composite, ground truth and model -prediction for each sample. The default is False.</p></li> -<li><p><strong>**kwargs</strong> – Additional keyword arguments passed to -<cite>pysegcnn.core.graphics.plot_sample</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>TypeError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">ds</span></code> is not an instance of -<cite>~pysegcnn.core.split.RandomSubset</cite> or -<cite>~pysegcnn.core.split.SceneSubset</cite>.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul> -<li><p><strong>output</strong> (<cite>dict</cite>) –</p> -<dl class="simple"> -<dt>Output dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'input'</span></code></dt><dd><p>Model input data</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'labels'</span></code></dt><dd><p>The ground truth</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'prediction'</span></code></dt><dd><p>Model prediction</p> -</dd> -</dl> -</dd> -</dl> -</li> -<li><p><strong>conf_mat</strong> (<cite>numpy.ndarray</cite>) – The confusion matrix. Note that the confusion matrix <code class="docutils literal notranslate"><span class="pre">conf_mat</span></code> is -only computed if <code class="docutils literal notranslate"><span class="pre">cm</span></code> = True.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.predict.predict_scenes"> -<code class="sig-prename descclassname">core.predict.</code><code class="sig-name descname">predict_scenes</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">scene_id</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">cm</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">plot</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/predict.html#predict_scenes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.predict.predict_scenes" title="Permalink to this definition">¶</a></dt> -<dd><p>Classify each scene in <code class="docutils literal notranslate"><span class="pre">ds</span></code> with model <code class="docutils literal notranslate"><span class="pre">model</span></code>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.split.SceneSubset</cite>) – An instance of <cite>~pysegcnn.core.split.SceneSubset</cite>.</p></li> -<li><p><strong>model</strong> (<cite>pysegcnn.core.models.Network</cite>) – An instance of <cite>~pysegcnn.core.models.Network</cite>.</p></li> -<li><p><strong>scene_id</strong> (<cite>str</cite> or <cite>None</cite>) – A valid scene identifier.</p></li> -<li><p><strong>cm</strong> (<cite>bool</cite>, optional) – Whether to compute the confusion matrix. The default is False.</p></li> -<li><p><strong>plot</strong> (<cite>bool</cite>, optional) – Whether to plot a false color composite, ground truth and model -prediction for each scene. The default is False.</p></li> -<li><p><strong>**kwargs</strong> – Additional keyword arguments passed to -<cite>pysegcnn.core.graphics.plot_sample</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>TypeError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">ds</span></code> is not an instance of -<cite>~pysegcnn.core.split.SceneSubset</cite>.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul> -<li><p><strong>output</strong> (<cite>dict</cite>) –</p> -<dl class="simple"> -<dt>Output dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'input'</span></code></dt><dd><p>Model input data</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'labels'</span></code></dt><dd><p>The ground truth</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'prediction'</span></code></dt><dd><p>Model prediction</p> -</dd> -</dl> -</dd> -</dl> -</li> -<li><p><strong>conf_mat</strong> (<cite>numpy.ndarray</cite>) – The confusion matrix. Note that the confusion matrix <code class="docutils literal notranslate"><span class="pre">conf_mat</span></code> is -only computed if <code class="docutils literal notranslate"><span class="pre">cm</span></code> = True.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.split"> -<span id="core-split-module"></span><h2>core.split module<a class="headerlink" href="#module-core.split" title="Permalink to this headline">¶</a></h2> -<p>Split the dataset into training, validation and test set.</p> -<div class="section" id="id9"> -<h3>License<a class="headerlink" href="#id9" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py class"> -<dt id="core.split.CustomSubset"> -<em class="property">class </em><code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">CustomSubset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="n">indices</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#CustomSubset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.CustomSubset" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.utils.data.dataset.Subset</span></code></p> -<p>Custom subset inheriting <cite>torch.utils.data.Subset</cite>.</p> -</dd></dl> - -<dl class="py class"> -<dt id="core.split.DateSplit"> -<em class="property">class </em><code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">DateSplit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">date</span></em>, <em class="sig-param"><span class="n">dateformat</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#DateSplit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.DateSplit" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.split.Split" title="core.split.Split"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.split.Split</span></code></a></p> -<p>Split the dataset based on a date.</p> -<p>Class wrapper for <cite>pysegcnn.core.split.Split.date_scene_split</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>date</strong> (<em>'str'</em>) – A date.</p></li> -<li><p><strong>dateformat</strong> (<em>'str'</em><em>, </em><em>optional</em>) – The format of <code class="docutils literal notranslate"><span class="pre">date</span></code>. <code class="docutils literal notranslate"><span class="pre">dateformat</span></code> is used by -<cite>datetime.datetime.strptime’ to parse ``date`</cite> to a <cite>datetime.datetime</cite> -object. The default is ‘%Y%m%d’.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">split</span></code>()</p></td> -<td><p>Split dataset into training, validation and test set.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.split.DateSplit.subset_type" title="core.split.DateSplit.subset_type"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subset_type</span></code></a>()</p></td> -<td><p>Wrap <cite>pysegcnn.core.split.SceneSubset</cite>.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.split.DateSplit.subsets" title="core.split.DateSplit.subsets"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subsets</span></code></a>()</p></td> -<td><p>Wrap <cite>pysegcnn.core.split.Split.date_scene_split</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.split.DateSplit.subset_type"> -<code class="sig-name descname">subset_type</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#DateSplit.subset_type"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.DateSplit.subset_type" title="Permalink to this definition">¶</a></dt> -<dd><p>Wrap <cite>pysegcnn.core.split.SceneSubset</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>SceneSubset</strong> – The subset type.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>pysegcnn.core.split.SceneSubset</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.split.DateSplit.subsets"> -<code class="sig-name descname">subsets</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#DateSplit.subsets"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.DateSplit.subsets" title="Permalink to this definition">¶</a></dt> -<dd><p>Wrap <cite>pysegcnn.core.split.Split.date_scene_split</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>subsets</strong> –</p> -<dl class="simple"> -<dt>Subset dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'train'</span></code></dt><dd><p>dictionary containing the training scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'valid'</span></code></dt><dd><p>dictionary containing the validation scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'test'</span></code></dt><dd><p>dictionary containing the test scenes, empty.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.split.RandomSceneSplit"> -<em class="property">class </em><code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">RandomSceneSplit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">ttratio</span></em>, <em class="sig-param"><span class="n">tvratio</span></em>, <em class="sig-param"><span class="n">seed</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#RandomSceneSplit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.RandomSceneSplit" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.split.RandomSplit" title="core.split.RandomSplit"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.split.RandomSplit</span></code></a></p> -<p>Randomly split the dataset.</p> -<p>For each scene, all the tiles of the scene are included in either the -training, validation or test set, respectively.</p> -<p>Class wrapper for <cite>pysegcnn.core.split.Split.random_scene_split</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>tvratio</strong> (<cite>float</cite>) – The ratio of training data to validation data, e.g. <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> = 0.8 -means 80% training, 20% validation.</p></li> -<li><p><strong>ttratio</strong> (<cite>float</cite>, optional) – The ratio of training and validation data to test data, e.g. -<code class="docutils literal notranslate"><span class="pre">ttratio</span></code> = 0.6 means 60% for training and validation, 40% for -testing. The default is 1.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed for reproducibility. The default is 0.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">split</span></code>()</p></td> -<td><p>Split dataset into training, validation and test set.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.split.RandomSceneSplit.subset_type" title="core.split.RandomSceneSplit.subset_type"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subset_type</span></code></a>()</p></td> -<td><p>Wrap <cite>pysegcnn.core.split.SceneSubset</cite>.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.split.RandomSceneSplit.subsets" title="core.split.RandomSceneSplit.subsets"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subsets</span></code></a>()</p></td> -<td><p>Wrap <cite>pysegcnn.core.split.Split.random_scene_split</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.split.RandomSceneSplit.subset_type"> -<code class="sig-name descname">subset_type</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#RandomSceneSplit.subset_type"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.RandomSceneSplit.subset_type" title="Permalink to this definition">¶</a></dt> -<dd><p>Wrap <cite>pysegcnn.core.split.SceneSubset</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>SceneSubset</strong> – The subset type.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>pysegcnn.core.split.SceneSubset</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.split.RandomSceneSplit.subsets"> -<code class="sig-name descname">subsets</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#RandomSceneSplit.subsets"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.RandomSceneSplit.subsets" title="Permalink to this definition">¶</a></dt> -<dd><p>Wrap <cite>pysegcnn.core.split.Split.random_scene_split</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>subsets</strong> –</p> -<dl class="simple"> -<dt>Subset dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'train'</span></code></dt><dd><p>dictionary containing the training scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'valid'</span></code></dt><dd><p>dictionary containing the validation scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'test'</span></code></dt><dd><p>dictionary containing the test scenes, empty.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.split.RandomSplit"> -<em class="property">class </em><code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">RandomSplit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">ttratio</span></em>, <em class="sig-param"><span class="n">tvratio</span></em>, <em class="sig-param"><span class="n">seed</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#RandomSplit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.RandomSplit" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.split.Split" title="core.split.Split"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.split.Split</span></code></a></p> -<p>Randomly split the dataset.</p> -<p>Generic class for random dataset splits.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>tvratio</strong> (<cite>float</cite>) – The ratio of training data to validation data, e.g. <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> = 0.8 -means 80% training, 20% validation.</p></li> -<li><p><strong>ttratio</strong> (<cite>float</cite>, optional) – The ratio of training and validation data to test data, e.g. -<code class="docutils literal notranslate"><span class="pre">ttratio</span></code> = 0.6 means 60% for training and validation, 40% for -testing. The default is 1.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed for reproducibility. The default is 0.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">split</span></code>()</p></td> -<td><p>Split dataset into training, validation and test set.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">subset_type</span></code>()</p></td> -<td><p>Define the type of each subset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">subsets</span></code>()</p></td> -<td><p>Define training, validation and test sets.</p></td> -</tr> -</tbody> -</table> -</dd></dl> - -<dl class="py class"> -<dt id="core.split.RandomSubset"> -<em class="property">class </em><code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">RandomSubset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">indices</span></em>, <em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="n">scenes</span></em>, <em class="sig-param"><span class="n">scene_ids</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#RandomSubset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.RandomSubset" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.split.CustomSubset" title="core.split.CustomSubset"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.split.CustomSubset</span></code></a></p> -<p>A custom subset for random dataset splits.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>indices</strong> (<cite>list</cite> [<cite>int</cite>]) – List of the subset indices to access <code class="docutils literal notranslate"><span class="pre">ds</span></code>.</p></li> -<li><p><strong>name</strong> (<cite>str</cite>) – Name of the subset.</p></li> -<li><p><strong>scenes</strong> (<cite>list</cite> [<cite>dict</cite>]) – List of the subset tiles.</p></li> -<li><p><strong>scene_ids</strong> (<cite>list</cite> or <cite>numpy.ndarray</cite>) – Container of the scene ids.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -</dd></dl> - -<dl class="py class"> -<dt id="core.split.RandomTileSplit"> -<em class="property">class </em><code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">RandomTileSplit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">ttratio</span></em>, <em class="sig-param"><span class="n">tvratio</span></em>, <em class="sig-param"><span class="n">seed</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#RandomTileSplit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.RandomTileSplit" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.split.RandomSplit" title="core.split.RandomSplit"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.split.RandomSplit</span></code></a></p> -<p>Randomly split the dataset.</p> -<p>For each scene, the tiles of the scene can be distributed among the -training, validation and test set.</p> -<p>Class wrapper for <cite>pysegcnn.core.split.Split.random_tile_split</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>tvratio</strong> (<cite>float</cite>) – The ratio of training data to validation data, e.g. <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> = 0.8 -means 80% training, 20% validation.</p></li> -<li><p><strong>ttratio</strong> (<cite>float</cite>, optional) – The ratio of training and validation data to test data, e.g. -<code class="docutils literal notranslate"><span class="pre">ttratio</span></code> = 0.6 means 60% for training and validation, 40% for -testing. The default is 1.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed for reproducibility. The default is 0.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">split</span></code>()</p></td> -<td><p>Split dataset into training, validation and test set.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.split.RandomTileSplit.subset_type" title="core.split.RandomTileSplit.subset_type"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subset_type</span></code></a>()</p></td> -<td><p>Wrap <cite>pysegcnn.core.split.RandomSubset</cite>.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.split.RandomTileSplit.subsets" title="core.split.RandomTileSplit.subsets"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subsets</span></code></a>()</p></td> -<td><p>Wrap <cite>pysegcnn.core.split.Split.random_tile_split</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.split.RandomTileSplit.subset_type"> -<code class="sig-name descname">subset_type</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#RandomTileSplit.subset_type"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.RandomTileSplit.subset_type" title="Permalink to this definition">¶</a></dt> -<dd><p>Wrap <cite>pysegcnn.core.split.RandomSubset</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>SceneSubset</strong> – The subset type.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>pysegcnn.core.split.RandomSubset</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.split.RandomTileSplit.subsets"> -<code class="sig-name descname">subsets</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#RandomTileSplit.subsets"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.RandomTileSplit.subsets" title="Permalink to this definition">¶</a></dt> -<dd><p>Wrap <cite>pysegcnn.core.split.Split.random_tile_split</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>subsets</strong> –</p> -<dl class="simple"> -<dt>Subset dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'train'</span></code></dt><dd><p>dictionary containing the training scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'valid'</span></code></dt><dd><p>dictionary containing the validation scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'test'</span></code></dt><dd><p>dictionary containing the test scenes, empty.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.split.SceneSubset"> -<em class="property">class </em><code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">SceneSubset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">indices</span></em>, <em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="n">scenes</span></em>, <em class="sig-param"><span class="n">scene_ids</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#SceneSubset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.SceneSubset" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.split.CustomSubset" title="core.split.CustomSubset"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.split.CustomSubset</span></code></a></p> -<p>A custom subset for dataset splits where the scenes are preserved.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>indices</strong> (<cite>list</cite> [<cite>int</cite>]) – List of the subset indices to access <code class="docutils literal notranslate"><span class="pre">ds</span></code>.</p></li> -<li><p><strong>name</strong> (<cite>str</cite>) – Name of the subset.</p></li> -<li><p><strong>scenes</strong> (<cite>list</cite> [<cite>dict</cite>]) – List of the subset tiles.</p></li> -<li><p><strong>scene_ids</strong> (<cite>list</cite> or <cite>numpy.ndarray</cite>) – Container of the scene ids.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -</dd></dl> - -<dl class="py class"> -<dt id="core.split.Split"> -<em class="property">class </em><code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">Split</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#Split"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.Split" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p> -<p>Generic class handling how <code class="docutils literal notranslate"><span class="pre">ds</span></code> is split.</p> -<p>Inherit <cite>~pysegcnn.core.split.Split</cite> and implement the -<cite>~pysegcnn.core.split.Split.subsets</cite> and -<cite>~pysegcnn.core.split.Split.subset_type</cite> method.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.split.Split.split" title="core.split.Split.split"><code class="xref py py-obj docutils literal notranslate"><span class="pre">split</span></code></a>()</p></td> -<td><p>Split dataset into training, validation and test set.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.split.Split.subset_type" title="core.split.Split.subset_type"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subset_type</span></code></a>()</p></td> -<td><p>Define the type of each subset.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.split.Split.subsets" title="core.split.Split.subsets"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subsets</span></code></a>()</p></td> -<td><p>Define training, validation and test sets.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.split.Split.split"> -<code class="sig-name descname">split</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#Split.split"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.Split.split" title="Permalink to this definition">¶</a></dt> -<dd><p>Split dataset into training, validation and test set.</p> -<p><cite>~pysegcnn.core.split.Split.split</cite> works only if -<cite>~pysegcnn.core.split.Split.subsets</cite> and -<cite>~pysegcnn.core.split.Split.subset_type</cite> are implemented.</p> -</dd></dl> - -<dl class="py method"> -<dt id="core.split.Split.subset_type"> -<code class="sig-name descname">subset_type</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#Split.subset_type"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.Split.subset_type" title="Permalink to this definition">¶</a></dt> -<dd><p>Define the type of each subset.</p> -<p>Wrapper method for -<cite>pysegcnn.core.split.RandomSubset</cite> or -<cite>pysegcnn.core.split.SceneSubset</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Raises</dt> -<dd class="field-odd"><p><strong>NotImplementedError</strong> – Raised if <cite>pysegcnn.core.split.Split</cite> is not inherited.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.split.Split.subsets"> -<code class="sig-name descname">subsets</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#Split.subsets"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.Split.subsets" title="Permalink to this definition">¶</a></dt> -<dd><p>Define training, validation and test sets.</p> -<p>Wrapper method for -<cite>pysegcnn.core.split.Split.random_tile_split</cite>, -<cite>pysegcnn.core.split.Split.random_scene_split</cite> or -<cite>pysegcnn.core.split.Split.date_scene_split</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Raises</dt> -<dd class="field-odd"><p><strong>NotImplementedError</strong> – Raised if <cite>pysegcnn.core.split.Split</cite> is not inherited.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.split.SupportedSplits"> -<em class="property">class </em><code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">SupportedSplits</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#SupportedSplits"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.SupportedSplits" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></p> -<p>Names and corresponding classes of the implemented split modes.</p> -<dl class="py attribute"> -<dt id="core.split.SupportedSplits.date"> -<code class="sig-name descname">date</code><em class="property"> = <class 'core.split.DateSplit'></em><a class="headerlink" href="#core.split.SupportedSplits.date" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.split.SupportedSplits.random"> -<code class="sig-name descname">random</code><em class="property"> = <class 'core.split.RandomTileSplit'></em><a class="headerlink" href="#core.split.SupportedSplits.random" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.split.SupportedSplits.scene"> -<code class="sig-name descname">scene</code><em class="property"> = <class 'core.split.RandomSceneSplit'></em><a class="headerlink" href="#core.split.SupportedSplits.scene" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py function"> -<dt id="core.split.date_scene_split"> -<code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">date_scene_split</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">date</span></em>, <em class="sig-param"><span class="n">dateformat</span><span class="o">=</span><span class="default_value">'%Y%m%d'</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#date_scene_split"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.date_scene_split" title="Permalink to this definition">¶</a></dt> -<dd><p>Split the dataset based on a date.</p> -<p>Scenes before <code class="docutils literal notranslate"><span class="pre">date</span></code> build the training set, scenes after <code class="docutils literal notranslate"><span class="pre">date</span></code> build -the validation set, the test set is empty.</p> -<p>Useful for time series data.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>date</strong> (<cite>str</cite>) – A date.</p></li> -<li><p><strong>dateformat</strong> (<cite>str</cite>, optional) – The format of <code class="docutils literal notranslate"><span class="pre">date</span></code>. <code class="docutils literal notranslate"><span class="pre">dateformat</span></code> is used by -<cite>datetime.datetime.strptime’ to parse ``date`</cite> to a <cite>datetime.datetime</cite> -object. The default is ‘%Y%m%d’.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>AssertionError</strong> – Raised if the splits are not pairwise disjoint.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>subsets</strong> –</p> -<dl class="simple"> -<dt>Subset dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'train'</span></code></dt><dd><p>dictionary containing the training scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'valid'</span></code></dt><dd><p>dictionary containing the validation scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'test'</span></code></dt><dd><p>dictionary containing the test scenes, empty.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.split.pairwise_disjoint"> -<code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">pairwise_disjoint</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">sets</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#pairwise_disjoint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.pairwise_disjoint" title="Permalink to this definition">¶</a></dt> -<dd><p>Check if <code class="docutils literal notranslate"><span class="pre">sets</span></code> are pairwise disjoint.</p> -<p>Sets are pairwise disjoint if the length of their union equals the sum of -their lengths.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>sets</strong> (<cite>list</cite> [<cite>collections.Sized</cite>]) – A list of sized objects.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>disjoint</strong> – Whether the sets are pairwise disjoint.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>bool</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.split.random_scene_split"> -<code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">random_scene_split</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">tvratio</span></em>, <em class="sig-param"><span class="n">ttratio</span><span class="o">=</span><span class="default_value">1</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#random_scene_split"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.random_scene_split" title="Permalink to this definition">¶</a></dt> -<dd><p>Randomly split the tiles of a dataset.</p> -<p>For each scene, all the tiles of the scene are included in either the -training, validation or test set, respectively.</p> -<p>The parameters <code class="docutils literal notranslate"><span class="pre">ttratio</span></code> and <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> control the size of the -training, validation and test datasets.</p> -<p>Test dataset size : (1 - <code class="docutils literal notranslate"><span class="pre">ttratio</span></code>) * len(<code class="docutils literal notranslate"><span class="pre">ds</span></code>) -Train dataset size : <code class="docutils literal notranslate"><span class="pre">ttratio</span></code> * <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> * len(<code class="docutils literal notranslate"><span class="pre">ds</span></code>) -Validation dataset size: <code class="docutils literal notranslate"><span class="pre">ttratio</span></code> * (1 - <code class="docutils literal notranslate"><span class="pre">tvratio</span></code>) * len(<code class="docutils literal notranslate"><span class="pre">ds</span></code>)</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>tvratio</strong> (<cite>float</cite>) – The ratio of training data to validation data, e.g. <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> = 0.8 -means 80% training, 20% validation.</p></li> -<li><p><strong>ttratio</strong> (<cite>float</cite>, optional) – The ratio of training and validation data to test data, e.g. -<code class="docutils literal notranslate"><span class="pre">ttratio</span></code> = 0.6 means 60% for training and validation, 40% for -testing. The default is 1.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed for reproducibility. The default is 0.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>AssertionError</strong> – Raised if the splits are not pairwise disjoint.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>subsets</strong> –</p> -<dl class="simple"> -<dt>Subset dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'train'</span></code></dt><dd><p>dictionary containing the training scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'valid'</span></code></dt><dd><p>dictionary containing the validation scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'test'</span></code></dt><dd><p>dictionary containing the test scenes.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.split.random_tile_split"> -<code class="sig-prename descclassname">core.split.</code><code class="sig-name descname">random_tile_split</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">tvratio</span></em>, <em class="sig-param"><span class="n">ttratio</span><span class="o">=</span><span class="default_value">1</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/split.html#random_tile_split"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.split.random_tile_split" title="Permalink to this definition">¶</a></dt> -<dd><p>Randomly split the tiles of a dataset.</p> -<p>For each scene, the tiles of the scene can be distributed among the -training, validation and test set.</p> -<p>The parameters <code class="docutils literal notranslate"><span class="pre">ttratio</span></code> and <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> control the size of the -training, validation and test datasets.</p> -<p>Test dataset size : (1 - <code class="docutils literal notranslate"><span class="pre">ttratio</span></code>) * len(<code class="docutils literal notranslate"><span class="pre">ds</span></code>) -Train dataset size : <code class="docutils literal notranslate"><span class="pre">ttratio</span></code> * <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> * len(<code class="docutils literal notranslate"><span class="pre">ds</span></code>) -Validation dataset size: <code class="docutils literal notranslate"><span class="pre">ttratio</span></code> * (1 - <code class="docutils literal notranslate"><span class="pre">tvratio</span></code>) * len(<code class="docutils literal notranslate"><span class="pre">ds</span></code>)</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>~pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>tvratio</strong> (<cite>float</cite>) – The ratio of training data to validation data, e.g. <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> = 0.8 -means 80% training, 20% validation.</p></li> -<li><p><strong>ttratio</strong> (<cite>float</cite>, optional) – The ratio of training and validation data to test data, e.g. -<code class="docutils literal notranslate"><span class="pre">ttratio</span></code> = 0.6 means 60% for training and validation, 40% for -testing. The default is 1.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed for reproducibility. The default is 0.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>AssertionError</strong> – Raised if the splits are not pairwise disjoint.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>subsets</strong> –</p> -<dl class="simple"> -<dt>Subset dictionary with keys:</dt><dd><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'train'</span></code></dt><dd><p>dictionary containing the training scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'valid'</span></code></dt><dd><p>dictionary containing the validation scenes.</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'test'</span></code></dt><dd><p>dictionary containing the test scenes.</p> -</dd> -</dl> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.trainer"> -<span id="core-trainer-module"></span><h2>core.trainer module<a class="headerlink" href="#module-core.trainer" title="Permalink to this headline">¶</a></h2> -<p>Model configuration and training.</p> -<p>This module provides an end-to-end framework of dataclasses designed to train -segmentation models on image datasets.</p> -<p>See pysegcnn/main/train.py for a complete walkthrough.</p> -<div class="section" id="id10"> -<h3>License<a class="headerlink" href="#id10" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py class"> -<dt id="core.trainer.BaseConfig"> -<em class="property">class </em><code class="sig-prename descclassname">core.trainer.</code><code class="sig-name descname">BaseConfig</code><a class="reference internal" href="../_modules/core/trainer.html#BaseConfig"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.BaseConfig" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p> -<p>Base <cite>dataclasses.dataclass</cite> for each configuration.</p> -</dd></dl> - -<dl class="py class"> -<dt id="core.trainer.DatasetConfig"> -<em class="property">class </em><code class="sig-prename descclassname">core.trainer.</code><code class="sig-name descname">DatasetConfig</code><span class="sig-paren">(</span><em class="sig-param">dataset_name: str</em>, <em class="sig-param">root_dir: pathlib.Path</em>, <em class="sig-param">bands: list</em>, <em class="sig-param">tile_size: int</em>, <em class="sig-param">gt_pattern: str</em>, <em class="sig-param">seed: int</em>, <em class="sig-param">sort: bool = False</em>, <em class="sig-param">transforms: list = <factory></em>, <em class="sig-param">pad: bool = False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#DatasetConfig"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.DatasetConfig" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.trainer.BaseConfig" title="core.trainer.BaseConfig"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.trainer.BaseConfig</span></code></a></p> -<p>Dataset configuration class.</p> -<p>Instanciate a dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>dataset_name</strong> (<cite>str</cite>) – The name of the dataset.</p></li> -<li><p><strong>root_dir</strong> (<cite>pathlib.Path</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>bands</strong> (<cite>list</cite> [<cite>str</cite>]) – A list of the spectral bands to use.</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite>) – The size of the tiles. Each scene is divided into square tiles of shape -(tile_size, tile_size).</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>) – A pattern to match the ground truth naming convention. All directories -and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for files matching -<code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.DatasetConfig.init_dataset" title="core.trainer.DatasetConfig.init_dataset"><code class="xref py py-obj docutils literal notranslate"><span class="pre">init_dataset</span></code></a>()</p></td> -<td><p>Instanciate the dataset.</p></td> -</tr> -</tbody> -</table> -<dl class="py attribute"> -<dt id="core.trainer.DatasetConfig.bands"> -<code class="sig-name descname">bands</code><em class="property">: list</em><a class="headerlink" href="#core.trainer.DatasetConfig.bands" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.DatasetConfig.dataset_name"> -<code class="sig-name descname">dataset_name</code><em class="property">: str</em><a class="headerlink" href="#core.trainer.DatasetConfig.dataset_name" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.DatasetConfig.gt_pattern"> -<code class="sig-name descname">gt_pattern</code><em class="property">: str</em><a class="headerlink" href="#core.trainer.DatasetConfig.gt_pattern" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.trainer.DatasetConfig.init_dataset"> -<code class="sig-name descname">init_dataset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#DatasetConfig.init_dataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.DatasetConfig.init_dataset" title="Permalink to this definition">¶</a></dt> -<dd><p>Instanciate the dataset.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>dataset</strong> – An instance of <cite>pysegcnn.core.dataset.ImageDataset</cite>.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>pysegcnn.core.dataset.ImageDataset</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.DatasetConfig.pad"> -<code class="sig-name descname">pad</code><em class="property">: bool</em><em class="property"> = False</em><a class="headerlink" href="#core.trainer.DatasetConfig.pad" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.DatasetConfig.root_dir"> -<code class="sig-name descname">root_dir</code><em class="property">: pathlib.Path</em><a class="headerlink" href="#core.trainer.DatasetConfig.root_dir" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.DatasetConfig.seed"> -<code class="sig-name descname">seed</code><em class="property">: int</em><a class="headerlink" href="#core.trainer.DatasetConfig.seed" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.DatasetConfig.sort"> -<code class="sig-name descname">sort</code><em class="property">: bool</em><em class="property"> = False</em><a class="headerlink" href="#core.trainer.DatasetConfig.sort" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.DatasetConfig.tile_size"> -<code class="sig-name descname">tile_size</code><em class="property">: int</em><a class="headerlink" href="#core.trainer.DatasetConfig.tile_size" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.DatasetConfig.transforms"> -<code class="sig-name descname">transforms</code><em class="property">: list</em><a class="headerlink" href="#core.trainer.DatasetConfig.transforms" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.trainer.EarlyStopping"> -<em class="property">class </em><code class="sig-prename descclassname">core.trainer.</code><code class="sig-name descname">EarlyStopping</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">mode</span><span class="o">=</span><span class="default_value">'max'</span></em>, <em class="sig-param"><span class="n">best</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_delta</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">patience</span><span class="o">=</span><span class="default_value">10</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#EarlyStopping"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.EarlyStopping" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p> -<p><a href="#id25"><span class="problematic" id="id26">`Early stopping`_</span></a> algorithm.</p> -<p>This implementation of the early stopping algorithm advances a counter each -time a metric did not improve over a training epoch. If the metric does not -improve over more than <code class="docutils literal notranslate"><span class="pre">patience</span></code> epochs, the early stopping criterion is -met.</p> -<p>See <cite>pysegcnn.core.trainer.NetworkTrainer.train</cite> for an example -implementation.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>mode</strong> (<cite>str</cite>, optional) – The mode of the early stopping. Depends on the metric measuring -performance. When using model loss as metric, use <code class="docutils literal notranslate"><span class="pre">mode</span></code> = ‘min’, -however, when using accuracy as metric, use <code class="docutils literal notranslate"><span class="pre">mode</span></code> = ‘max’. The -default is ‘max’.</p></li> -<li><p><strong>best</strong> (<cite>float</cite>, optional) – Threshold indicating the best metric score. At instanciation, set -<code class="docutils literal notranslate"><span class="pre">best</span></code> to the worst possible score of the metric. <code class="docutils literal notranslate"><span class="pre">best</span></code> will be -overwritten during training. The default is 0.</p></li> -<li><p><strong>min_delta</strong> (<cite>float</cite>, optional) – Minimum change in early stopping metric to be considered as an -improvement. The default is 0.</p></li> -<li><p><strong>patience</strong> (<cite>int</cite>, optional) – The number of epochs to wait for an improvement in the early stopping -metric. The default is 10.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>ValueError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">mode</span></code> is not either ‘min’ or ‘max’.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul class="simple"> -<li><p><em>None.</em></p></li> -<li><p><em>.. _Early stopping</em> – <a class="reference external" href="https://en.wikipedia.org/wiki/Early_stopping">https://en.wikipedia.org/wiki/Early_stopping</a></p></li> -</ul> -</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.EarlyStopping.decreased" title="core.trainer.EarlyStopping.decreased"><code class="xref py py-obj docutils literal notranslate"><span class="pre">decreased</span></code></a>(metric, best, min_delta)</p></td> -<td><p>Whether a metric decreased with respect to a best score.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.trainer.EarlyStopping.increased" title="core.trainer.EarlyStopping.increased"><code class="xref py py-obj docutils literal notranslate"><span class="pre">increased</span></code></a>(metric, best, min_delta)</p></td> -<td><p>Whether a metric increased with respect to a best score.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.EarlyStopping.stop" title="core.trainer.EarlyStopping.stop"><code class="xref py py-obj docutils literal notranslate"><span class="pre">stop</span></code></a>(metric)</p></td> -<td><p>Advance early stopping counter.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.trainer.EarlyStopping.decreased"> -<code class="sig-name descname">decreased</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">metric</span></em>, <em class="sig-param"><span class="n">best</span></em>, <em class="sig-param"><span class="n">min_delta</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#EarlyStopping.decreased"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.EarlyStopping.decreased" title="Permalink to this definition">¶</a></dt> -<dd><p>Whether a metric decreased with respect to a best score.</p> -<p>Measure improvement for metrics that are considered as ‘better’ when -they decrease, e.g. model loss, mean squared error, etc.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>metric</strong> (<cite>float</cite>) – The current score.</p></li> -<li><p><strong>best</strong> (<cite>float</cite>) – The current best score.</p></li> -<li><p><strong>min_delta</strong> (<cite>float</cite>) – Minimum change to be considered as an improvement.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p>Whether the metric improved.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>bool</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.trainer.EarlyStopping.increased"> -<code class="sig-name descname">increased</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">metric</span></em>, <em class="sig-param"><span class="n">best</span></em>, <em class="sig-param"><span class="n">min_delta</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#EarlyStopping.increased"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.EarlyStopping.increased" title="Permalink to this definition">¶</a></dt> -<dd><p>Whether a metric increased with respect to a best score.</p> -<p>Measure improvement for metrics that are considered as ‘better’ when -they increase, e.g. accuracy, precision, recall, etc.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>metric</strong> (<cite>float</cite>) – The current score.</p></li> -<li><p><strong>best</strong> (<cite>float</cite>) – The current best score.</p></li> -<li><p><strong>min_delta</strong> (<cite>float</cite>) – Minimum change to be considered as an improvement.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p>Whether the metric improved.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>bool</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.trainer.EarlyStopping.stop"> -<code class="sig-name descname">stop</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">metric</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#EarlyStopping.stop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.EarlyStopping.stop" title="Permalink to this definition">¶</a></dt> -<dd><p>Advance early stopping counter.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>metric</strong> (<cite>float</cite>) – The current metric score.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>early_stop</strong> – Whether the early stopping criterion is met.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>bool</cite></p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.trainer.EvalConfig"> -<em class="property">class </em><code class="sig-prename descclassname">core.trainer.</code><code class="sig-name descname">EvalConfig</code><span class="sig-paren">(</span><em class="sig-param">state_file: pathlib.Path</em>, <em class="sig-param">test: object</em>, <em class="sig-param">predict_scene: bool = False</em>, <em class="sig-param">plot_samples: bool = False</em>, <em class="sig-param">plot_scenes: bool = False</em>, <em class="sig-param">plot_bands: list = <factory></em>, <em class="sig-param">cm: bool = True</em>, <em class="sig-param">figsize: tuple = (10</em>, <em class="sig-param">10)</em>, <em class="sig-param">alpha: int = 5</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#EvalConfig"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.EvalConfig" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.trainer.BaseConfig" title="core.trainer.BaseConfig"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.trainer.BaseConfig</span></code></a></p> -<p>Model inference configuration.</p> -<p>Evaluate a model.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>state_file</strong> (<cite>pathlib.Path</cite>) – Path to the model to evaluate.</p></li> -<li><p><strong>test</strong> (<cite>bool</cite> or <cite>None</cite>) – Whether to evaluate the model on the training(<code class="docutils literal notranslate"><span class="pre">test</span></code> = <cite>None</cite>), the -validation (<code class="docutils literal notranslate"><span class="pre">test</span></code> = False) or the test set (<code class="docutils literal notranslate"><span class="pre">test</span></code> = True).</p></li> -<li><p><strong>predict_scene</strong> (<cite>bool</cite>, optional) – The model prediction order. If False, the samples (tiles) of a dataset -are predicted in any order and the scenes are not reconstructed. -If True, the samples (tiles) are ordered according to the scene they -belong to and a model prediction for each entire reconstructed scene is -returned. The default is False.</p></li> -<li><p><strong>plot_samples</strong> (<cite>bool</cite>, optional) – Whether to save a plot of false color composite, ground truth and model -prediction for each sample (tile). Only used if <code class="docutils literal notranslate"><span class="pre">predict_scene</span></code> = -False. The default is False.</p></li> -<li><p><strong>plot_scenes</strong> (<cite>bool</cite>, optional) – Whether to save a plot of false color composite, ground truth and model -prediction for each entire scene. Only used if <code class="docutils literal notranslate"><span class="pre">predict_scene</span></code> = -True. The default is False.</p></li> -<li><p><strong>plot_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – The bands to build the false color composite. The default is -[‘nir’, ‘red’, ‘green’].</p></li> -<li><p><strong>cm</strong> (<cite>bool</cite>, optional) – Whether to compute and plot the confusion matrix. The default is True.</p></li> -<li><p><strong>figsize</strong> (<cite>tuple</cite>, optional) – The figure size in centimeters. The default is (10, 10).</p></li> -<li><p><strong>alpha</strong> (<cite>int</cite>, optional) – The level of the percentiles for contrast stretching of the false color -compsite. The default is 0, i.e. no stretching.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<dl class="py attribute"> -<dt id="core.trainer.EvalConfig.alpha"> -<code class="sig-name descname">alpha</code><em class="property">: int</em><em class="property"> = 5</em><a class="headerlink" href="#core.trainer.EvalConfig.alpha" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.EvalConfig.cm"> -<code class="sig-name descname">cm</code><em class="property">: bool</em><em class="property"> = True</em><a class="headerlink" href="#core.trainer.EvalConfig.cm" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.EvalConfig.figsize"> -<code class="sig-name descname">figsize</code><em class="property">: tuple</em><em class="property"> = (10, 10)</em><a class="headerlink" href="#core.trainer.EvalConfig.figsize" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.EvalConfig.plot_bands"> -<code class="sig-name descname">plot_bands</code><em class="property">: list</em><a class="headerlink" href="#core.trainer.EvalConfig.plot_bands" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.EvalConfig.plot_samples"> -<code class="sig-name descname">plot_samples</code><em class="property">: bool</em><em class="property"> = False</em><a class="headerlink" href="#core.trainer.EvalConfig.plot_samples" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.EvalConfig.plot_scenes"> -<code class="sig-name descname">plot_scenes</code><em class="property">: bool</em><em class="property"> = False</em><a class="headerlink" href="#core.trainer.EvalConfig.plot_scenes" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.EvalConfig.predict_scene"> -<code class="sig-name descname">predict_scene</code><em class="property">: bool</em><em class="property"> = False</em><a class="headerlink" href="#core.trainer.EvalConfig.predict_scene" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.EvalConfig.state_file"> -<code class="sig-name descname">state_file</code><em class="property">: pathlib.Path</em><a class="headerlink" href="#core.trainer.EvalConfig.state_file" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.EvalConfig.test"> -<code class="sig-name descname">test</code><em class="property">: object</em><a class="headerlink" href="#core.trainer.EvalConfig.test" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.trainer.LogConfig"> -<em class="property">class </em><code class="sig-prename descclassname">core.trainer.</code><code class="sig-name descname">LogConfig</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">state_file</span><span class="p">:</span> <span class="n">pathlib.Path</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#LogConfig"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.LogConfig" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.trainer.BaseConfig" title="core.trainer.BaseConfig"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.trainer.BaseConfig</span></code></a></p> -<p>Logging configuration class.</p> -<p>Generate the model log file.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>state_file</strong> (<cite>pathlib.Path</cite>) – Path to a model state file.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.LogConfig.init_log" title="core.trainer.LogConfig.init_log"><code class="xref py py-obj docutils literal notranslate"><span class="pre">init_log</span></code></a>(init_str)</p></td> -<td><p>Generate a string to identify a new model run.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.trainer.LogConfig.now" title="core.trainer.LogConfig.now"><code class="xref py py-obj docutils literal notranslate"><span class="pre">now</span></code></a>()</p></td> -<td><p>Return the current date and time.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.trainer.LogConfig.init_log"> -<em class="property">static </em><code class="sig-name descname">init_log</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">init_str</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#LogConfig.init_log"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.LogConfig.init_log" title="Permalink to this definition">¶</a></dt> -<dd><p>Generate a string to identify a new model run.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>init_str</strong> (<cite>str</cite>) – The string to write to the model log file.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.trainer.LogConfig.now"> -<em class="property">static </em><code class="sig-name descname">now</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#LogConfig.now"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.LogConfig.now" title="Permalink to this definition">¶</a></dt> -<dd><p>Return the current date and time.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>date</strong> – The current date and time.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>datetime.datetime</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.LogConfig.state_file"> -<code class="sig-name descname">state_file</code><em class="property">: pathlib.Path</em><a class="headerlink" href="#core.trainer.LogConfig.state_file" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.trainer.ModelConfig"> -<em class="property">class </em><code class="sig-prename descclassname">core.trainer.</code><code class="sig-name descname">ModelConfig</code><span class="sig-paren">(</span><em class="sig-param">model_name: str</em>, <em class="sig-param">filters: list</em>, <em class="sig-param">torch_seed: int</em>, <em class="sig-param">optim_name: str</em>, <em class="sig-param">loss_name: str</em>, <em class="sig-param">skip_connection: bool = True</em>, <em class="sig-param">kwargs: dict = <factory></em>, <em class="sig-param">batch_size: int = 64</em>, <em class="sig-param">checkpoint: bool = False</em>, <em class="sig-param">transfer: bool = False</em>, <em class="sig-param">pretrained_model: str = ''</em>, <em class="sig-param">lr: float = 0.001</em>, <em class="sig-param">early_stop: bool = False</em>, <em class="sig-param">mode: str = 'max'</em>, <em class="sig-param">delta: float = 0</em>, <em class="sig-param">patience: int = 10</em>, <em class="sig-param">epochs: int = 50</em>, <em class="sig-param">nthreads: int = 2</em>, <em class="sig-param">save: bool = True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#ModelConfig"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.ModelConfig" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.trainer.BaseConfig" title="core.trainer.BaseConfig"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.trainer.BaseConfig</span></code></a></p> -<p>Model configuration class.</p> -<p>Instanciate a (pretrained) model.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>model_name</strong> (<cite>str</cite>) – The name of the model.</p></li> -<li><p><strong>filters</strong> (<cite>list</cite> [<cite>int</cite>]) – List of input channels to the convolutional layers.</p></li> -<li><p><strong>torch_seed</strong> (<cite>int</cite>) – The random seed to initialize the model weights. -Useful for reproducibility.</p></li> -<li><p><strong>optim_name</strong> (<cite>str</cite>) – The name of the optimizer to update the model weights.</p></li> -<li><p><strong>loss_name</strong> (<cite>str</cite>) – The name of the loss function measuring the model error.</p></li> -<li><p><strong>skip_connection</strong> (<cite>bool</cite>, optional) – Whether to apply skip connections. The defaul is True.</p></li> -<li><p><strong>kwargs</strong> (<cite>dict</cite>, optional) – The configuration for each convolution in the model. The default is -{‘kernel_size’: 3, ‘stride’: 1, ‘dilation’: 1}.</p></li> -<li><p><strong>batch_size</strong> (<cite>int</cite>, optional) – The model batch size. Determines the number of samples to process -before updating the model weights. The default is 64.</p></li> -<li><p><strong>checkpoint</strong> (<cite>bool</cite>, optional) – Whether to resume training from an existing model checkpoint. The -default is False.</p></li> -<li><p><strong>transfer</strong> (<cite>bool</cite>, optional) – Whether to use a model for transfer learning on a new dataset. If True, -the model architecture of <code class="docutils literal notranslate"><span class="pre">pretrained_model</span></code> is adjusted to a new -dataset. The default is False.</p></li> -<li><p><strong>pretrained_model</strong> (<cite>str</cite>, optional) – The name of the pretrained model to use for transfer learning. -The default is ‘’.</p></li> -<li><p><strong>lr</strong> (<cite>float</cite>, optional) – The learning rate used by the gradient descent algorithm. -The default is 0.001.</p></li> -<li><p><strong>early_stop</strong> (<cite>bool</cite>, optional) – Whether to apply <a href="#id27"><span class="problematic" id="id28">`early stopping`_</span></a>. The default is False.</p></li> -<li><p><strong>mode</strong> (<cite>str</cite>, optional) – The mode of the early stopping. Depends on the metric measuring -performance. When using model loss as metric, use <code class="docutils literal notranslate"><span class="pre">mode</span></code> = ‘min’, -however, when using accuracy as metric, use <code class="docutils literal notranslate"><span class="pre">mode</span></code> = ‘max’. For now, -only <code class="docutils literal notranslate"><span class="pre">mode</span></code> = ‘max’ is supported. Only used if <code class="docutils literal notranslate"><span class="pre">early_stop</span></code> = True. -The default is ‘max’.</p></li> -<li><p><strong>delta</strong> (<cite>float</cite>, optional) – Minimum change in early stopping metric to be considered as an -improvement. Only used if <code class="docutils literal notranslate"><span class="pre">early_stop</span></code> = True. The default is 0.</p></li> -<li><p><strong>patience</strong> (<cite>int</cite>, optional) – The number of epochs to wait for an improvement in the early stopping -metric. If the model does not improve over more than <code class="docutils literal notranslate"><span class="pre">patience</span></code> -epochs, quit training. Only used if <code class="docutils literal notranslate"><span class="pre">early_stop</span></code> = True. -The default is 10.</p></li> -<li><p><strong>epochs</strong> (<cite>int</cite>, optional) – The maximum number of epochs to train. The default is 50.</p></li> -<li><p><strong>nthreads</strong> (<cite>int</cite>, optional) – The number of cpu threads to use during training. The default is -torch.get_num_threads().</p></li> -<li><p><strong>save</strong> (<cite>bool</cite>, optional) – Whether to save the model state to disk. Model states are saved in -pysegcnn/main/_models. The default is True.</p></li> -<li><p><strong>_early stopping</strong> (<em>.</em>) – <a class="reference external" href="https://en.wikipedia.org/wiki/Early_stopping">https://en.wikipedia.org/wiki/Early_stopping</a></p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.ModelConfig.init_loss_function" title="core.trainer.ModelConfig.init_loss_function"><code class="xref py py-obj docutils literal notranslate"><span class="pre">init_loss_function</span></code></a>()</p></td> -<td><p>Instanciate the loss function.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.trainer.ModelConfig.init_model" title="core.trainer.ModelConfig.init_model"><code class="xref py py-obj docutils literal notranslate"><span class="pre">init_model</span></code></a>(ds, state_file)</p></td> -<td><p>Instanciate the model and the optimizer.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.ModelConfig.init_optimizer" title="core.trainer.ModelConfig.init_optimizer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">init_optimizer</span></code></a>(model)</p></td> -<td><p>Instanciate the optimizer.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.trainer.ModelConfig.load_checkpoint" title="core.trainer.ModelConfig.load_checkpoint"><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_checkpoint</span></code></a>(model, optimizer, state_file)</p></td> -<td><p>Load an existing model checkpoint.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.ModelConfig.transfer_model" title="core.trainer.ModelConfig.transfer_model"><code class="xref py py-obj docutils literal notranslate"><span class="pre">transfer_model</span></code></a>(state_file, ds)</p></td> -<td><p>Adjust a pretrained model to a new dataset.</p></td> -</tr> -</tbody> -</table> -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.batch_size"> -<code class="sig-name descname">batch_size</code><em class="property">: int</em><em class="property"> = 64</em><a class="headerlink" href="#core.trainer.ModelConfig.batch_size" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.checkpoint"> -<code class="sig-name descname">checkpoint</code><em class="property">: bool</em><em class="property"> = False</em><a class="headerlink" href="#core.trainer.ModelConfig.checkpoint" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.delta"> -<code class="sig-name descname">delta</code><em class="property">: float</em><em class="property"> = 0</em><a class="headerlink" href="#core.trainer.ModelConfig.delta" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.early_stop"> -<code class="sig-name descname">early_stop</code><em class="property">: bool</em><em class="property"> = False</em><a class="headerlink" href="#core.trainer.ModelConfig.early_stop" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.epochs"> -<code class="sig-name descname">epochs</code><em class="property">: int</em><em class="property"> = 50</em><a class="headerlink" href="#core.trainer.ModelConfig.epochs" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.filters"> -<code class="sig-name descname">filters</code><em class="property">: list</em><a class="headerlink" href="#core.trainer.ModelConfig.filters" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.trainer.ModelConfig.init_loss_function"> -<code class="sig-name descname">init_loss_function</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#ModelConfig.init_loss_function"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.ModelConfig.init_loss_function" title="Permalink to this definition">¶</a></dt> -<dd><p>Instanciate the loss function.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>loss_function</strong> – An instance of <cite>torch.nn.Module</cite>.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>torch.nn.Module</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.trainer.ModelConfig.init_model"> -<code class="sig-name descname">init_model</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em>, <em class="sig-param"><span class="n">state_file</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#ModelConfig.init_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.ModelConfig.init_model" title="Permalink to this definition">¶</a></dt> -<dd><p>Instanciate the model and the optimizer.</p> -<p>If the model checkpoint <code class="docutils literal notranslate"><span class="pre">state_file</span></code> exists, the pretrained model and -optimizer states are loaded, otherwise the model and the optimizer are -initialized from scratch.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>state_file</strong> (<cite>pathlib.Path</cite>) – Path to a model checkpoint.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul> -<li><p><strong>model</strong> (<cite>pysegcnn.core.models.Network</cite>) – An instance of <cite>pysegcnn.core.models.Network</cite>.</p></li> -<li><p><strong>optimizer</strong> (<cite>torch.optim.Optimizer</cite>) – An instance of <cite>torch.optim.Optimizer</cite>.</p></li> -<li><p><strong>checkpoint_state</strong> (<cite>dict</cite> [<cite>str</cite>, <cite>numpy.ndarray</cite>]) – If the model checkpoint <code class="docutils literal notranslate"><span class="pre">state_file</span></code> exists, <code class="docutils literal notranslate"><span class="pre">checkpoint_state</span></code> -has keys:</p> -<blockquote> -<div><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'ta'</span></code></dt><dd><p>The accuracy on the training set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'tl'</span></code></dt><dd><p>The loss on the training set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'va'</span></code></dt><dd><p>The accuracy on the validation set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'vl'</span></code></dt><dd><p>The loss on the validation set (<cite>numpy.ndarray</cite>).</p> -</dd> -</dl> -</div></blockquote> -</li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py method"> -<dt id="core.trainer.ModelConfig.init_optimizer"> -<code class="sig-name descname">init_optimizer</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#ModelConfig.init_optimizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.ModelConfig.init_optimizer" title="Permalink to this definition">¶</a></dt> -<dd><p>Instanciate the optimizer.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>model</strong> (<cite>torch.nn.Module</cite>) – An instance of <cite>torch.nn.Module</cite>.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>optimizer</strong> – An instance of <cite>torch.optim.Optimizer</cite>.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>torch.optim.Optimizer</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.kwargs"> -<code class="sig-name descname">kwargs</code><em class="property">: dict</em><a class="headerlink" href="#core.trainer.ModelConfig.kwargs" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.trainer.ModelConfig.load_checkpoint"> -<em class="property">static </em><code class="sig-name descname">load_checkpoint</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">model</span></em>, <em class="sig-param"><span class="n">optimizer</span></em>, <em class="sig-param"><span class="n">state_file</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#ModelConfig.load_checkpoint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.ModelConfig.load_checkpoint" title="Permalink to this definition">¶</a></dt> -<dd><p>Load an existing model checkpoint.</p> -<p>If the model checkpoint <code class="docutils literal notranslate"><span class="pre">state_file</span></code> exists, the pretrained model and -optimizer states are loaded.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>model</strong> (<cite>pysegcnn.core.models.Network</cite>) – An instance of <cite>pysegcnn.core.models.Network</cite>.</p></li> -<li><p><strong>optimizer</strong> (<cite>torch.optim.Optimizer</cite>) – An instance of <cite>torch.optim.Optimizer</cite>.</p></li> -<li><p><strong>state_file</strong> (<cite>pathlib.Path</cite>) – Path to the model checkpoint.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul> -<li><p><strong>model</strong> (<cite>pysegcnn.core.models.Network</cite>) – An instance of <cite>pysegcnn.core.models.Network</cite>.</p></li> -<li><p><strong>optimizer</strong> (<cite>torch.optim.Optimizer</cite>) – An instance of <cite>torch.optim.Optimizer</cite>.</p></li> -<li><p><strong>checkpoint_state</strong> (<cite>dict</cite> [<cite>str</cite>, <cite>numpy.ndarray</cite>]) – If the model checkpoint <code class="docutils literal notranslate"><span class="pre">state_file</span></code> exists, <code class="docutils literal notranslate"><span class="pre">checkpoint_state</span></code> -has keys:</p> -<blockquote> -<div><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'ta'</span></code></dt><dd><p>The accuracy on the training set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'tl'</span></code></dt><dd><p>The loss on the training set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'va'</span></code></dt><dd><p>The accuracy on the validation set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'vl'</span></code></dt><dd><p>The loss on the validation set (<cite>numpy.ndarray</cite>).</p> -</dd> -</dl> -</div></blockquote> -</li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.loss_name"> -<code class="sig-name descname">loss_name</code><em class="property">: str</em><a class="headerlink" href="#core.trainer.ModelConfig.loss_name" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.lr"> -<code class="sig-name descname">lr</code><em class="property">: float</em><em class="property"> = 0.001</em><a class="headerlink" href="#core.trainer.ModelConfig.lr" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.mode"> -<code class="sig-name descname">mode</code><em class="property">: str</em><em class="property"> = 'max'</em><a class="headerlink" href="#core.trainer.ModelConfig.mode" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.model_name"> -<code class="sig-name descname">model_name</code><em class="property">: str</em><a class="headerlink" href="#core.trainer.ModelConfig.model_name" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.nthreads"> -<code class="sig-name descname">nthreads</code><em class="property">: int</em><em class="property"> = 2</em><a class="headerlink" href="#core.trainer.ModelConfig.nthreads" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.optim_name"> -<code class="sig-name descname">optim_name</code><em class="property">: str</em><a class="headerlink" href="#core.trainer.ModelConfig.optim_name" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.patience"> -<code class="sig-name descname">patience</code><em class="property">: int</em><em class="property"> = 10</em><a class="headerlink" href="#core.trainer.ModelConfig.patience" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.pretrained_model"> -<code class="sig-name descname">pretrained_model</code><em class="property">: str</em><em class="property"> = ''</em><a class="headerlink" href="#core.trainer.ModelConfig.pretrained_model" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.save"> -<code class="sig-name descname">save</code><em class="property">: bool</em><em class="property"> = True</em><a class="headerlink" href="#core.trainer.ModelConfig.save" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.skip_connection"> -<code class="sig-name descname">skip_connection</code><em class="property">: bool</em><em class="property"> = True</em><a class="headerlink" href="#core.trainer.ModelConfig.skip_connection" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.torch_seed"> -<code class="sig-name descname">torch_seed</code><em class="property">: int</em><a class="headerlink" href="#core.trainer.ModelConfig.torch_seed" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.ModelConfig.transfer"> -<code class="sig-name descname">transfer</code><em class="property">: bool</em><em class="property"> = False</em><a class="headerlink" href="#core.trainer.ModelConfig.transfer" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.trainer.ModelConfig.transfer_model"> -<em class="property">static </em><code class="sig-name descname">transfer_model</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">state_file</span></em>, <em class="sig-param"><span class="n">ds</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#ModelConfig.transfer_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.ModelConfig.transfer_model" title="Permalink to this definition">¶</a></dt> -<dd><p>Adjust a pretrained model to a new dataset.</p> -<p>The classification layer of the pretrained model in <code class="docutils literal notranslate"><span class="pre">state_file</span></code> is -initilialized from scratch with the classes of the new dataset <code class="docutils literal notranslate"><span class="pre">ds</span></code>.</p> -<p>The remaining model weights are preserved.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>state_file</strong> (<cite>pathlib.Path</cite>) – Path to a pretrained model.</p></li> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><ul class="simple"> -<li><p><strong>TypeError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">ds</span></code> is not an instance of -<cite>pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>ValueError</strong> – Raised if the bands of <code class="docutils literal notranslate"><span class="pre">ds</span></code> do not match the bands of the dataset -the pretrained model was trained with.</p></li> -</ul> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>model</strong> – An instance of <cite>pysegcnn.core.models.Network</cite>. The pretrained model -adjusted to the new dataset.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>pysegcnn.core.models.Network</cite></p> -</dd> -</dl> -</dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.trainer.NetworkTrainer"> -<em class="property">class </em><code class="sig-prename descclassname">core.trainer.</code><code class="sig-name descname">NetworkTrainer</code><span class="sig-paren">(</span><em class="sig-param">model: pysegcnn.core.models.Network</em>, <em class="sig-param">optimizer: torch.optim.optimizer.Optimizer</em>, <em class="sig-param">loss_function: torch.nn.modules.module.Module</em>, <em class="sig-param">train_dl: torch.utils.data.dataloader.DataLoader</em>, <em class="sig-param">valid_dl: torch.utils.data.dataloader.DataLoader</em>, <em class="sig-param">test_dl: torch.utils.data.dataloader.DataLoader</em>, <em class="sig-param">state_file: pathlib.Path</em>, <em class="sig-param">epochs: int = 1</em>, <em class="sig-param">nthreads: int = 2</em>, <em class="sig-param">early_stop: bool = False</em>, <em class="sig-param">mode: str = 'max'</em>, <em class="sig-param">delta: float = 0</em>, <em class="sig-param">patience: int = 10</em>, <em class="sig-param">checkpoint_state: dict = <factory></em>, <em class="sig-param">save: bool = True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#NetworkTrainer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.NetworkTrainer" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.trainer.BaseConfig" title="core.trainer.BaseConfig"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.trainer.BaseConfig</span></code></a></p> -<p>Model training class.</p> -<p>Generic class to train an instance of <cite>pysegcnn.core.models.Network</cite> on -a dataset of type <cite>pysegcnn.core.dataset.ImageDataset</cite>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>model</strong> (<cite>pysegcnn.core.models.Network</cite>) – The model to train. An instance of <cite>pysegcnn.core.models.Network</cite>.</p></li> -<li><p><strong>optimizer</strong> (<cite>torch.optim.Optimizer</cite>) – The optimizer to update the model weights. An instance of -<cite>torch.optim.Optimizer</cite>.</p></li> -<li><p><strong>loss_function</strong> (<cite>torch.nn.Module</cite>) – The loss function to compute the model error. An instance of -<cite>torch.nn.Module</cite>.</p></li> -<li><p><strong>train_dl</strong> (<cite>torch.utils.data.DataLoader</cite>) – The training <cite>torch.utils.data.DataLoader</cite> instance.</p></li> -<li><p><strong>valid_dl</strong> (<cite>torch.utils.data.DataLoader</cite>) – The validation <cite>torch.utils.data.DataLoader</cite> instance.</p></li> -<li><p><strong>test_dl</strong> (<cite>torch.utils.data.DataLoader</cite>) – The test <cite>torch.utils.data.DataLoader</cite> instance.</p></li> -<li><p><strong>state_file</strong> (<cite>pathlib.Path</cite>) – Path to save the model state.</p></li> -<li><p><strong>epochs</strong> (<cite>int</cite>, optional) – The maximum number of epochs to train. The default is 1.</p></li> -<li><p><strong>nthreads</strong> (<cite>int</cite>, optional) – The number of cpu threads to use during training. The default is -torch.get_num_threads().</p></li> -<li><p><strong>early_stop</strong> (<cite>bool</cite>, optional) – Whether to apply <a href="#id29"><span class="problematic" id="id30">`early stopping`_</span></a>. The default is False.</p></li> -<li><p><strong>mode</strong> (<cite>str</cite>, optional) – The mode of the early stopping. Depends on the metric measuring -performance. When using model loss as metric, use <code class="docutils literal notranslate"><span class="pre">mode</span></code> = ‘min’, -however, when using accuracy as metric, use <code class="docutils literal notranslate"><span class="pre">mode</span></code> = ‘max’. For now, -only <code class="docutils literal notranslate"><span class="pre">mode</span></code> = ‘max’ is supported. Only used if <code class="docutils literal notranslate"><span class="pre">early_stop</span></code> = True. -The default is ‘max’.</p></li> -<li><p><strong>delta</strong> (<cite>float</cite>, optional) – Minimum change in early stopping metric to be considered as an -improvement. Only used if <code class="docutils literal notranslate"><span class="pre">early_stop</span></code> = True. The default is 0.</p></li> -<li><p><strong>patience</strong> (<cite>int</cite>, optional) – The number of epochs to wait for an improvement in the early stopping -metric. If the model does not improve over more than <code class="docutils literal notranslate"><span class="pre">patience</span></code> -epochs, quit training. Only used if <code class="docutils literal notranslate"><span class="pre">early_stop</span></code> = True. -The default is 10.</p></li> -<li><p><strong>checkpoint_state</strong> (<cite>dict</cite> [<cite>str</cite>, <cite>numpy.ndarray</cite>], optional) – <p>A model checkpoint for <code class="docutils literal notranslate"><span class="pre">model</span></code>. If specified, <code class="docutils literal notranslate"><span class="pre">checkpoint_state</span></code> -should be a dictionary with keys:</p> -<blockquote> -<div><dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'ta'</span></code></dt><dd><p>The accuracy on the training set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'tl'</span></code></dt><dd><p>The loss on the training set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'va'</span></code></dt><dd><p>The accuracy on the validation set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'vl'</span></code></dt><dd><p>The loss on the validation set (<cite>numpy.ndarray</cite>).</p> -</dd> -</dl> -</div></blockquote> -<p>The default is {}.</p> -</p></li> -<li><p><strong>save</strong> (<cite>bool</cite>, optional) – Whether to save the model state to <code class="docutils literal notranslate"><span class="pre">state_file</span></code>. The default is True.</p></li> -<li><p><strong>_early stopping</strong> (<em>.</em>) – <a class="reference external" href="https://en.wikipedia.org/wiki/Early_stopping">https://en.wikipedia.org/wiki/Early_stopping</a></p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.NetworkTrainer.predict" title="core.trainer.NetworkTrainer.predict"><code class="xref py py-obj docutils literal notranslate"><span class="pre">predict</span></code></a>()</p></td> -<td><p>Model inference at training time.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.trainer.NetworkTrainer.save_state" title="core.trainer.NetworkTrainer.save_state"><code class="xref py py-obj docutils literal notranslate"><span class="pre">save_state</span></code></a>()</p></td> -<td><p>Save the model state.</p></td> -</tr> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.NetworkTrainer.train" title="core.trainer.NetworkTrainer.train"><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code></a>()</p></td> -<td><p>Train the model.</p></td> -</tr> -</tbody> -</table> -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.checkpoint_state"> -<code class="sig-name descname">checkpoint_state</code><em class="property">: dict</em><a class="headerlink" href="#core.trainer.NetworkTrainer.checkpoint_state" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.delta"> -<code class="sig-name descname">delta</code><em class="property">: float</em><em class="property"> = 0</em><a class="headerlink" href="#core.trainer.NetworkTrainer.delta" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.early_stop"> -<code class="sig-name descname">early_stop</code><em class="property">: bool</em><em class="property"> = False</em><a class="headerlink" href="#core.trainer.NetworkTrainer.early_stop" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.epochs"> -<code class="sig-name descname">epochs</code><em class="property">: int</em><em class="property"> = 1</em><a class="headerlink" href="#core.trainer.NetworkTrainer.epochs" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.loss_function"> -<code class="sig-name descname">loss_function</code><em class="property">: torch.nn.modules.module.Module</em><a class="headerlink" href="#core.trainer.NetworkTrainer.loss_function" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.mode"> -<code class="sig-name descname">mode</code><em class="property">: str</em><em class="property"> = 'max'</em><a class="headerlink" href="#core.trainer.NetworkTrainer.mode" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.model"> -<code class="sig-name descname">model</code><em class="property">: pysegcnn.core.models.Network</em><a class="headerlink" href="#core.trainer.NetworkTrainer.model" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.nthreads"> -<code class="sig-name descname">nthreads</code><em class="property">: int</em><em class="property"> = 2</em><a class="headerlink" href="#core.trainer.NetworkTrainer.nthreads" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.optimizer"> -<code class="sig-name descname">optimizer</code><em class="property">: torch.optim.optimizer.Optimizer</em><a class="headerlink" href="#core.trainer.NetworkTrainer.optimizer" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.patience"> -<code class="sig-name descname">patience</code><em class="property">: int</em><em class="property"> = 10</em><a class="headerlink" href="#core.trainer.NetworkTrainer.patience" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.trainer.NetworkTrainer.predict"> -<code class="sig-name descname">predict</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#NetworkTrainer.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.NetworkTrainer.predict" title="Permalink to this definition">¶</a></dt> -<dd><p>Model inference at training time.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul class="simple"> -<li><p><strong>accuracies</strong> (<cite>numpy.ndarray</cite>) – The mean model prediction accuracy on each mini-batch in the -validation set.</p></li> -<li><p><strong>losses</strong> (<cite>numpy.ndarray</cite>) – The model loss for each mini-batch in the validation set.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.save"> -<code class="sig-name descname">save</code><em class="property">: bool</em><em class="property"> = True</em><a class="headerlink" href="#core.trainer.NetworkTrainer.save" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.trainer.NetworkTrainer.save_state"> -<code class="sig-name descname">save_state</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#NetworkTrainer.save_state"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.NetworkTrainer.save_state" title="Permalink to this definition">¶</a></dt> -<dd><p>Save the model state.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.state_file"> -<code class="sig-name descname">state_file</code><em class="property">: pathlib.Path</em><a class="headerlink" href="#core.trainer.NetworkTrainer.state_file" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.test_dl"> -<code class="sig-name descname">test_dl</code><em class="property">: torch.utils.data.dataloader.DataLoader</em><a class="headerlink" href="#core.trainer.NetworkTrainer.test_dl" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.trainer.NetworkTrainer.train"> -<code class="sig-name descname">train</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#NetworkTrainer.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.NetworkTrainer.train" title="Permalink to this definition">¶</a></dt> -<dd><p>Train the model.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>training_state</strong> – The training state dictionary with keys: -<code class="docutils literal notranslate"><span class="pre">'ta'</span></code></p> -<blockquote> -<div><p>The accuracy on the training set (<cite>numpy.ndarray</cite>).</p> -</div></blockquote> -<dl class="simple"> -<dt><code class="docutils literal notranslate"><span class="pre">'tl'</span></code></dt><dd><p>The loss on the training set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'va'</span></code></dt><dd><p>The accuracy on the validation set (<cite>numpy.ndarray</cite>).</p> -</dd> -<dt><code class="docutils literal notranslate"><span class="pre">'vl'</span></code></dt><dd><p>The loss on the validation set (<cite>numpy.ndarray</cite>).</p> -</dd> -</dl> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>dict</cite> [<cite>str</cite>, <cite>numpy.ndarray</cite>]</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.train_dl"> -<code class="sig-name descname">train_dl</code><em class="property">: torch.utils.data.dataloader.DataLoader</em><a class="headerlink" href="#core.trainer.NetworkTrainer.train_dl" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.NetworkTrainer.valid_dl"> -<code class="sig-name descname">valid_dl</code><em class="property">: torch.utils.data.dataloader.DataLoader</em><a class="headerlink" href="#core.trainer.NetworkTrainer.valid_dl" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.trainer.SplitConfig"> -<em class="property">class </em><code class="sig-prename descclassname">core.trainer.</code><code class="sig-name descname">SplitConfig</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">split_mode</span><span class="p">:</span> <span class="n">str</span></em>, <em class="sig-param"><span class="n">ttratio</span><span class="p">:</span> <span class="n">float</span></em>, <em class="sig-param"><span class="n">tvratio</span><span class="p">:</span> <span class="n">float</span></em>, <em class="sig-param"><span class="n">date</span><span class="p">:</span> <span class="n">str</span> <span class="o">=</span> <span class="default_value">'yyyymmdd'</span></em>, <em class="sig-param"><span class="n">dateformat</span><span class="p">:</span> <span class="n">str</span> <span class="o">=</span> <span class="default_value">'%Y%m%d'</span></em>, <em class="sig-param"><span class="n">drop</span><span class="p">:</span> <span class="n">float</span> <span class="o">=</span> <span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#SplitConfig"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.SplitConfig" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.trainer.BaseConfig" title="core.trainer.BaseConfig"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.trainer.BaseConfig</span></code></a></p> -<p>Dataset split configuration class.</p> -<p>Split a dataset into training, validation and test set.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>split_mode</strong> (<cite>str</cite>) – The mode to split the dataset.</p></li> -<li><p><strong>ttratio</strong> (<cite>float</cite>) – The ratio of training and validation data to test data, e.g. -<code class="docutils literal notranslate"><span class="pre">ttratio</span></code> = 0.6 means 60% for training and validation, 40% for -testing.</p></li> -<li><p><strong>tvratio</strong> (<cite>float</cite>) – The ratio of training data to validation data, e.g. <code class="docutils literal notranslate"><span class="pre">tvratio</span></code> = 0.8 -means 80% training, 20% validation.</p></li> -<li><p><strong>date</strong> (<cite>str</cite>, optional) – A date. Used if <code class="docutils literal notranslate"><span class="pre">split_mode</span></code> = ‘date’. The default is ‘yyyymmdd’.</p></li> -<li><p><strong>dateformat</strong> (<cite>str</cite>, optional) – The format of <code class="docutils literal notranslate"><span class="pre">date</span></code>. <code class="docutils literal notranslate"><span class="pre">dateformat</span></code> is used by -<cite>datetime.datetime.strptime’ to parse ``date`</cite> to a <cite>datetime.datetime</cite> -object. The default is ‘%Y%m%d’.</p></li> -<li><p><strong>drop</strong> (<cite>float</cite>, optional) – Whether to drop samples (during training only) with a fraction of -pixels equal to the constant padding value >= <code class="docutils literal notranslate"><span class="pre">drop</span></code>. <code class="docutils literal notranslate"><span class="pre">drop</span></code> = 0 -means, do not drop any samples. The default is 0.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.SplitConfig.dataloaders" title="core.trainer.SplitConfig.dataloaders"><code class="xref py py-obj docutils literal notranslate"><span class="pre">dataloaders</span></code></a>(*args, **kwargs)</p></td> -<td><p>Build <cite>torch.utils.data.DataLoader</cite> instances.</p></td> -</tr> -<tr class="row-even"><td><p><a class="reference internal" href="#core.trainer.SplitConfig.train_val_test_split" title="core.trainer.SplitConfig.train_val_test_split"><code class="xref py py-obj docutils literal notranslate"><span class="pre">train_val_test_split</span></code></a>(ds)</p></td> -<td><p>Split <code class="docutils literal notranslate"><span class="pre">ds</span></code> into training, validation and test set.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="core.trainer.SplitConfig.dataloaders"> -<em class="property">static </em><code class="sig-name descname">dataloaders</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#SplitConfig.dataloaders"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.SplitConfig.dataloaders" title="Permalink to this definition">¶</a></dt> -<dd><p>Build <cite>torch.utils.data.DataLoader</cite> instances.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>*args</strong> (<cite>list</cite> [<cite>torch.utils.data.Dataset</cite>]) – List of instances of <cite>torch.utils.data.Dataset</cite>.</p></li> -<li><p><strong>**kwargs</strong> – Additional keyword arguments passed to -<cite>torch.utils.data.DataLoader</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>TypeError</strong> – Raised if not each item in <code class="docutils literal notranslate"><span class="pre">args</span></code> is an instance of -<cite>torch.utils.data.Dataset</cite>.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>loaders</strong> – List of instances of <cite>torch.utils.data.DataLoader</cite>. If an instance -of <cite>torch.utils.data.Dataset</cite> in <code class="docutils literal notranslate"><span class="pre">args</span></code> is empty, <cite>None</cite> is -appended to <code class="docutils literal notranslate"><span class="pre">loaders</span></code> instead of an instance of -<cite>torch.utils.data.DataLoader</cite>.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>list</cite> [<cite>torch.utils.data.DataLoader</cite>]</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.SplitConfig.date"> -<code class="sig-name descname">date</code><em class="property">: str</em><em class="property"> = 'yyyymmdd'</em><a class="headerlink" href="#core.trainer.SplitConfig.date" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.SplitConfig.dateformat"> -<code class="sig-name descname">dateformat</code><em class="property">: str</em><em class="property"> = '%Y%m%d'</em><a class="headerlink" href="#core.trainer.SplitConfig.dateformat" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.SplitConfig.drop"> -<code class="sig-name descname">drop</code><em class="property">: float</em><em class="property"> = 0</em><a class="headerlink" href="#core.trainer.SplitConfig.drop" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.SplitConfig.split_mode"> -<code class="sig-name descname">split_mode</code><em class="property">: str</em><a class="headerlink" href="#core.trainer.SplitConfig.split_mode" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.trainer.SplitConfig.train_val_test_split"> -<code class="sig-name descname">train_val_test_split</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#SplitConfig.train_val_test_split"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.SplitConfig.train_val_test_split" title="Permalink to this definition">¶</a></dt> -<dd><p>Split <code class="docutils literal notranslate"><span class="pre">ds</span></code> into training, validation and test set.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>pysegcnn.core.dataset.ImageDataset</cite>.</p> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>TypeError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">ds</span></code> is not an instance of -<cite>pysegcnn.core.dataset.ImageDataset</cite>.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul class="simple"> -<li><p><strong>train_ds</strong> (<cite>pysegcnn.core.split.RandomSubset</cite> or)</p></li> -<li><p><cite>pysegcnn.core.split.SceneSubset</cite>. – The training set.</p></li> -<li><p><strong>valid_ds</strong> (<cite>pysegcnn.core.split.RandomSubset</cite> or)</p></li> -<li><p><cite>pysegcnn.core.split.SceneSubset</cite>. – The validation set.</p></li> -<li><p><strong>test_ds</strong> (<cite>pysegcnn.core.split.RandomSubset</cite> or)</p></li> -<li><p><cite>pysegcnn.core.split.SceneSubset</cite>. – The test set.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.SplitConfig.ttratio"> -<code class="sig-name descname">ttratio</code><em class="property">: float</em><a class="headerlink" href="#core.trainer.SplitConfig.ttratio" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.SplitConfig.tvratio"> -<code class="sig-name descname">tvratio</code><em class="property">: float</em><a class="headerlink" href="#core.trainer.SplitConfig.tvratio" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.trainer.StateConfig"> -<em class="property">class </em><code class="sig-prename descclassname">core.trainer.</code><code class="sig-name descname">StateConfig</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ds</span><span class="p">:</span> <span class="n">pysegcnn.core.dataset.ImageDataset</span></em>, <em class="sig-param"><span class="n">sc</span><span class="p">:</span> <span class="n"><a class="reference internal" href="#core.trainer.SplitConfig" title="core.trainer.SplitConfig">core.trainer.SplitConfig</a></span></em>, <em class="sig-param"><span class="n">mc</span><span class="p">:</span> <span class="n"><a class="reference internal" href="#core.trainer.ModelConfig" title="core.trainer.ModelConfig">core.trainer.ModelConfig</a></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#StateConfig"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.StateConfig" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.trainer.BaseConfig" title="core.trainer.BaseConfig"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.trainer.BaseConfig</span></code></a></p> -<p>Model state configuration class.</p> -<p>Generate the model state filename according to the following naming -convention:</p> -<p>model_dataset_optimizer_splitmode_splitparams_tilesize_batchsize_bands.pt</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>ds</strong> (<cite>pysegcnn.core.dataset.ImageDataset</cite>) – An instance of <cite>pysegcnn.core.dataset.ImageDataset</cite>.</p></li> -<li><p><strong>sc</strong> (<cite>pysegcnn.core.trainer.SplitConfig</cite>) – An instance of <cite>pysegcnn.core.trainer.SplitConfig</cite>.</p></li> -<li><p><strong>mc</strong> (<cite>pysegcnn.core.trainer.ModelConfig</cite>) – An instance of <cite>pysegcnn.core.trainer.SplitConfig</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><a class="reference internal" href="#core.trainer.StateConfig.init_state" title="core.trainer.StateConfig.init_state"><code class="xref py py-obj docutils literal notranslate"><span class="pre">init_state</span></code></a>()</p></td> -<td><p>Generate the model state filename.</p></td> -</tr> -</tbody> -</table> -<dl class="py attribute"> -<dt id="core.trainer.StateConfig.ds"> -<code class="sig-name descname">ds</code><em class="property">: pysegcnn.core.dataset.ImageDataset</em><a class="headerlink" href="#core.trainer.StateConfig.ds" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py method"> -<dt id="core.trainer.StateConfig.init_state"> -<code class="sig-name descname">init_state</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/trainer.html#StateConfig.init_state"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.trainer.StateConfig.init_state" title="Permalink to this definition">¶</a></dt> -<dd><p>Generate the model state filename.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>state</strong> – The path to the model state file.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>pathlib.Path</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.StateConfig.mc"> -<code class="sig-name descname">mc</code><em class="property">: <a class="reference internal" href="#core.trainer.ModelConfig" title="core.trainer.ModelConfig">core.trainer.ModelConfig</a></em><a class="headerlink" href="#core.trainer.StateConfig.mc" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -<dl class="py attribute"> -<dt id="core.trainer.StateConfig.sc"> -<code class="sig-name descname">sc</code><em class="property">: <a class="reference internal" href="#core.trainer.SplitConfig" title="core.trainer.SplitConfig">core.trainer.SplitConfig</a></em><a class="headerlink" href="#core.trainer.StateConfig.sc" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.transforms"> -<span id="core-transforms-module"></span><h2>core.transforms module<a class="headerlink" href="#module-core.transforms" title="Permalink to this headline">¶</a></h2> -<p>Data augmentation.</p> -<p>This module provides classes implementing common image augmentation methods.</p> -<p>These methods may be used to artificially increase a dataset.</p> -<div class="section" id="id11"> -<h3>License<a class="headerlink" href="#id11" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py class"> -<dt id="core.transforms.Augment"> -<em class="property">class </em><code class="sig-prename descclassname">core.transforms.</code><code class="sig-name descname">Augment</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">transforms</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/transforms.html#Augment"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.transforms.Augment" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p> -<p>Apply a sequence of transformations.</p> -<p>Container class applying each transformation in <code class="docutils literal notranslate"><span class="pre">transforms</span></code> in order.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>transforms</strong> (<cite>list</cite> or <cite>tuple</cite>) – A sequence of instances of <cite>pysegcnn.core.transforms.VariantTransform</cite> -or <cite>pysegcnn.core.transforms.InvariantTransform</cite>.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">__call__</span></code>(image, gt)</p></td> -<td><p>Apply a sequence of transformations to <code class="docutils literal notranslate"><span class="pre">image</span></code>.</p></td> -</tr> -</tbody> -</table> -</dd></dl> - -<dl class="py class"> -<dt id="core.transforms.FlipLr"> -<em class="property">class </em><code class="sig-prename descclassname">core.transforms.</code><code class="sig-name descname">FlipLr</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">p</span><span class="o">=</span><span class="default_value">0.5</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/transforms.html#FlipLr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.transforms.FlipLr" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.transforms.VariantTransform" title="core.transforms.VariantTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.transforms.VariantTransform</span></code></a></p> -<p>Flip an image horizontally.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>p</strong> (<cite>float</cite>, optional) – The probability to apply the transformation. The default is 0.5.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">__call__</span></code>(image)</p></td> -<td><p>Apply transformation.</p></td> -</tr> -</tbody> -</table> -</dd></dl> - -<dl class="py class"> -<dt id="core.transforms.FlipUd"> -<em class="property">class </em><code class="sig-prename descclassname">core.transforms.</code><code class="sig-name descname">FlipUd</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">p</span><span class="o">=</span><span class="default_value">0.5</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/transforms.html#FlipUd"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.transforms.FlipUd" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.transforms.VariantTransform" title="core.transforms.VariantTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.transforms.VariantTransform</span></code></a></p> -<p>Flip an image vertically.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>p</strong> (<cite>float</cite>, optional) – The probability to apply the transformation. The default is 0.5.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">__call__</span></code>(image)</p></td> -<td><p>Apply transformation.</p></td> -</tr> -</tbody> -</table> -</dd></dl> - -<dl class="py class"> -<dt id="core.transforms.InvariantTransform"> -<em class="property">class </em><code class="sig-prename descclassname">core.transforms.</code><code class="sig-name descname">InvariantTransform</code><a class="reference internal" href="../_modules/core/transforms.html#InvariantTransform"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.transforms.InvariantTransform" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.transforms.Transform" title="core.transforms.Transform"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.transforms.Transform</span></code></a></p> -<p>Base class for a spatially invariant transformation.</p> -<p>Transformation on the ground truth not required.</p> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">__call__</span></code>(image)</p></td> -<td><p>Apply transformation.</p></td> -</tr> -</tbody> -</table> -</dd></dl> - -<dl class="py class"> -<dt id="core.transforms.Noise"> -<em class="property">class </em><code class="sig-prename descclassname">core.transforms.</code><code class="sig-name descname">Noise</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">mode</span></em>, <em class="sig-param"><span class="n">mean</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">var</span><span class="o">=</span><span class="default_value">0.05</span></em>, <em class="sig-param"><span class="n">p</span><span class="o">=</span><span class="default_value">0.5</span></em>, <em class="sig-param"><span class="n">exclude</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/transforms.html#Noise"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.transforms.Noise" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.transforms.InvariantTransform" title="core.transforms.InvariantTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.transforms.InvariantTransform</span></code></a></p> -<p>Add gaussian noise to an image.</p> -<p>Valid modes are:</p> -<blockquote> -<div><p>‘add’: image = image + noise -‘speckle’ : image = image + image * noise</p> -</div></blockquote> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>mode</strong> (<cite>str</cite>) – The mode to add the noise.</p></li> -<li><p><strong>mean</strong> (<cite>float</cite>, optional) – The mean of the gaussian distribution from which the noise is sampled. -The default is 0.</p></li> -<li><p><strong>var</strong> (<cite>float</cite>, optional) – The variance of the gaussian distribution from which the noise is -sampled. The default is 0.05.</p></li> -<li><p><strong>p</strong> (<cite>float</cite>, optional) – The probability to apply the transformation. The default is 0.5.</p></li> -<li><p><strong>exclude</strong> (<cite>list</cite> [<cite>float</cite>] or <cite>list</cite> [<cite>int</cite>], optional) – Values for which the noise is not added. Useful for pixels resulting -from image padding. The default is [].</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>ValueError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">mode</span></code> is not supported.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">__call__</span></code>(image)</p></td> -<td><p>Apply transformation.</p></td> -</tr> -</tbody> -</table> -<dl class="py attribute"> -<dt id="core.transforms.Noise.modes"> -<code class="sig-name descname">modes</code><em class="property"> = ['add', 'speckle']</em><a class="headerlink" href="#core.transforms.Noise.modes" title="Permalink to this definition">¶</a></dt> -<dd></dd></dl> - -</dd></dl> - -<dl class="py class"> -<dt id="core.transforms.Rotate"> -<em class="property">class </em><code class="sig-prename descclassname">core.transforms.</code><code class="sig-name descname">Rotate</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">angle</span></em>, <em class="sig-param"><span class="n">p</span><span class="o">=</span><span class="default_value">0.5</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/transforms.html#Rotate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.transforms.Rotate" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.transforms.VariantTransform" title="core.transforms.VariantTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.transforms.VariantTransform</span></code></a></p> -<p>Rotate an image by <code class="docutils literal notranslate"><span class="pre">angle</span></code>.</p> -<p>The image is rotated in the spatial plane.</p> -<p>If the input array has more then two dimensions, the spatial dimensions are -assumed to be the last two dimensions of the array.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>angle</strong> (<cite>float</cite>) – The rotation angle in degrees.</p></li> -<li><p><strong>p</strong> (<cite>float</cite>, optional) – The probability to apply the transformation. The default is 0.5.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">__call__</span></code>(image)</p></td> -<td><p>Apply transformation.</p></td> -</tr> -</tbody> -</table> -</dd></dl> - -<dl class="py class"> -<dt id="core.transforms.Transform"> -<em class="property">class </em><code class="sig-prename descclassname">core.transforms.</code><code class="sig-name descname">Transform</code><a class="reference internal" href="../_modules/core/transforms.html#Transform"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.transforms.Transform" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p> -<p>Base class for an image transformation.</p> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">__call__</span></code>(image)</p></td> -<td><p>Apply transformation.</p></td> -</tr> -</tbody> -</table> -</dd></dl> - -<dl class="py class"> -<dt id="core.transforms.VariantTransform"> -<em class="property">class </em><code class="sig-prename descclassname">core.transforms.</code><code class="sig-name descname">VariantTransform</code><a class="reference internal" href="../_modules/core/transforms.html#VariantTransform"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.transforms.VariantTransform" title="Permalink to this definition">¶</a></dt> -<dd><p>Bases: <a class="reference internal" href="#core.transforms.Transform" title="core.transforms.Transform"><code class="xref py py-class docutils literal notranslate"><span class="pre">core.transforms.Transform</span></code></a></p> -<p>Base class for a spatially variant transformation.</p> -<p>Transformation on the ground truth required.</p> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">__call__</span></code>(image)</p></td> -<td><p>Apply transformation.</p></td> -</tr> -</tbody> -</table> -</dd></dl> - -</div> -</div> -<div class="section" id="module-core.utils"> -<span id="core-utils-module"></span><h2>core.utils module<a class="headerlink" href="#module-core.utils" title="Permalink to this headline">¶</a></h2> -<p>Utility functions mainly for image IO and reshaping.</p> -<div class="section" id="id12"> -<h3>License<a class="headerlink" href="#id12" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<dl class="py function"> -<dt id="core.utils.accuracy_function"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">accuracy_function</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">outputs</span></em>, <em class="sig-param"><span class="n">labels</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#accuracy_function"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.accuracy_function" title="Permalink to this definition">¶</a></dt> -<dd><p>Calculate prediction accuracy.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>outputs</strong> (<cite>torch.Tensor</cite> or array_like) – The model prediction.</p></li> -<li><p><strong>labels</strong> (<cite>torch.Tensor</cite> or array_like) – The ground truth.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>accuracy</strong> – Mean prediction accuracy.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>float</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.check_tile_extend"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">check_tile_extend</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">img_size</span></em>, <em class="sig-param"><span class="n">topleft</span></em>, <em class="sig-param"><span class="n">tile_size</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#check_tile_extend"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.check_tile_extend" title="Permalink to this definition">¶</a></dt> -<dd><p>Check if a tile exceeds the image size.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>img_size</strong> (<cite>tuple</cite>) – The image size (height, width).</p></li> -<li><p><strong>topleft</strong> (<cite>tuple</cite>) – The topleft corner of the tile (y, x).</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite>) – The size of the tile.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>nrows</strong> (<cite>int</cite>) – Number of rows of the tile within the image.</p></li> -<li><p><strong>ncols</strong> (<em>TYPE</em>) – Number of columns of the tile within the image.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.destack_tiff"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">destack_tiff</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">image</span></em>, <em class="sig-param"><span class="n">outpath</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">overwrite</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">remove</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">suffix</span><span class="o">=</span><span class="default_value">''</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#destack_tiff"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.destack_tiff" title="Permalink to this definition">¶</a></dt> -<dd><p>Destack a TIFF with more than one band into a TIFF file for each band.</p> -<p>Each band in <code class="docutils literal notranslate"><span class="pre">image</span></code> is saved to <code class="docutils literal notranslate"><span class="pre">outpath</span></code> as distinct TIFF file. -The default filenames are: “filename(<code class="docutils literal notranslate"><span class="pre">image</span></code>) + _B(i).tifâ€, where i is -the respective number of each band in <code class="docutils literal notranslate"><span class="pre">image</span></code>.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>image</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – The TIFF to destack.</p></li> -<li><p><strong>outpath</strong> (<cite>str</cite>, optional) – Path to save the output TIFF files. The default is None. If None, -<code class="docutils literal notranslate"><span class="pre">outpath</span></code> is the path to <code class="docutils literal notranslate"><span class="pre">image</span></code>.</p></li> -<li><p><strong>remove</strong> (<cite>bool</cite>, optional) – Whether to remove <code class="docutils literal notranslate"><span class="pre">image</span></code> from disk after destacking. The default is -False.</p></li> -<li><p><strong>overwrite</strong> (<cite>bool</cite>, optional) – Whether to overwrite existing TIFF files.</p></li> -<li><p><strong>suffix</strong> (<cite>str</cite>, optional) – String to append to the filename of <code class="docutils literal notranslate"><span class="pre">image</span></code>. If specified, the TIFF -filenames for each band in <code class="docutils literal notranslate"><span class="pre">image</span></code> are, “filename(<code class="docutils literal notranslate"><span class="pre">image</span></code>) + -+ _B(i)_ + <code class="docutils literal notranslate"><span class="pre">suffix</span></code>.tifâ€. The default is ‘’.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>FileNotFoundError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">image</span></code> does not exist.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.doy2date"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">doy2date</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">year</span></em>, <em class="sig-param"><span class="n">doy</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#doy2date"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.doy2date" title="Permalink to this definition">¶</a></dt> -<dd><p>Convert the (year, day of the year) date format to a datetime object.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>year</strong> (<cite>int</cite>) – The year</p></li> -<li><p><strong>doy</strong> (<cite>int</cite>) – The day of the year</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>date</strong> – The converted date.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>datetime.datetime</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.extract_archive"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">extract_archive</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">inpath</span></em>, <em class="sig-param"><span class="n">outpath</span></em>, <em class="sig-param"><span class="n">overwrite</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#extract_archive"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.extract_archive" title="Permalink to this definition">¶</a></dt> -<dd><p>Extract files from an archive.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>inpath</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – Path to an archive.</p></li> -<li><p><strong>outpath</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – Path to save extracted files.</p></li> -<li><p><strong>overwrite</strong> (<cite>bool</cite>, optional) – Whether to overwrite existing extracted files.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>subdir</strong> – path to the extracted files</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>str</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.get_radiometric_constants"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">get_radiometric_constants</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">metadata</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#get_radiometric_constants"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.get_radiometric_constants" title="Permalink to this definition">¶</a></dt> -<dd><p>Retrieve the radiometric calibration constants.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>metadata</strong> (<cite>dict</cite>) – The dictionary returned by <code class="docutils literal notranslate"><span class="pre">read_landsat_metadata</span></code>.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><ul class="simple"> -<li><p><strong>oli</strong> (<cite>dict</cite>) – Radiometric rescaling factors of the OLI sensor.</p></li> -<li><p><strong>tir</strong> (<cite>dict</cite>) – Thermal conversion constants of the TIRS sensor.</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.img2np"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">img2np</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">path</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">tile</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">cval</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#img2np"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.img2np" title="Permalink to this definition">¶</a></dt> -<dd><p>Read an image to a <cite>numpy.ndarray</cite>.</p> -<p>If <code class="docutils literal notranslate"><span class="pre">tile_size</span></code> is not <cite>None</cite>, the input image is divided into square -tiles of size (<code class="docutils literal notranslate"><span class="pre">tile_size</span></code>, <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>). If the image is not evenly -divisible and <code class="docutils literal notranslate"><span class="pre">pad</span></code> = False, a <cite>ValueError</cite> is raised. However, if -<code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, center padding with constant value <code class="docutils literal notranslate"><span class="pre">cval</span></code> is applied.</p> -<p>The tiling works as follows:</p> -<blockquote> -<div><p>(Padded) Input image:</p> -<div class="line-block"> -<div class="line-block"> -<div class="line">| | | |</div> -</div> -<div class="line">tile_00 | tile_01 | … | tile_0n |</div> -<div class="line-block"> -<div class="line">| | | |</div> -</div> -</div> -<p><a href="#id17"><span class="problematic" id="id18">|----------------------------------------------|</span></a> -| | | | | -| tile_10 | tile_11 | … | tile_1n | -| | | | | -<a href="#id19"><span class="problematic" id="id20">|----------------------------------------------|</span></a> -| | | | | -| … | … | … | … | -| | | | | -<a href="#id21"><span class="problematic" id="id22">|----------------------------------------------|</span></a> -| | | | | -| tile_m0 | tile_m1 | … | tile_mn | -| | | | | -————————————————</p> -</div></blockquote> -<p>where m = n. Each tile has its id, which starts at 0 in the topleft corner -of the input image, i.e. tile_00 has id=0, and increases along the width -axis, i.e. tile_0n has id=n, tile_10 has id=n+1, …, tile_mn has -id=(m * n) - 1.</p> -<p>If <code class="docutils literal notranslate"><span class="pre">tile</span></code> is an integer, only the tile with id = <code class="docutils literal notranslate"><span class="pre">tile</span></code> is returned.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>path</strong> (<cite>str</cite> or <cite>None</cite> or <cite>numpy.ndarray</cite>) – The image to read.</p></li> -<li><p><strong>tile_size</strong> (<cite>None</cite> or <cite>int</cite>, optional) – The size of a tile. The default is None.</p></li> -<li><p><strong>tile</strong> (<cite>int</cite>, optional) – The tile id. The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. The default is False.</p></li> -<li><p><strong>cval</strong> (<cite>float</cite>, optional) – The constant padding value. The default is 0.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><ul class="simple"> -<li><p><strong>FileNotFoundError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">path</span></code> is a path that does not exist.</p></li> -<li><p><strong>TypeError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">path</span></code> is not <cite>str</cite> or <cite>None</cite> or <cite>numpy.ndarray</cite>.</p></li> -</ul> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><p><strong>image</strong> –</p> -<p>The image array. The output shape is:</p> -<blockquote> -<div><dl> -<dt>if <code class="docutils literal notranslate"><span class="pre">tile_size</span></code> is not <cite>None</cite>:</dt><dd><p>shape=(tiles, bands, tile_size, tile_size) -if the image does only have one band:</p> -<blockquote> -<div><p>shape=(tiles, tile_size, tile_size)</p> -</div></blockquote> -</dd> -<dt>else:</dt><dd><p>shape=(bands, height, width) -if the image does only have one band:</p> -<blockquote> -<div><p>shape=(height, width)</p> -</div></blockquote> -</dd> -</dl> -</div></blockquote> -</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>numpy.ndarray</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.is_divisible"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">is_divisible</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">img_size</span></em>, <em class="sig-param"><span class="n">tile_size</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#is_divisible"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.is_divisible" title="Permalink to this definition">¶</a></dt> -<dd><p>Check whether an image is evenly divisible into square tiles.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>img_size</strong> (<cite>tuple</cite>) – The image size (height, width).</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite>) – The size of the tile.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. The default is False.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>ValueError</strong> – Raised if the image is not evenly divisible and <code class="docutils literal notranslate"><span class="pre">pad</span></code> = False.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul class="simple"> -<li><p><strong>ntiles</strong> (<cite>int</cite>) – The number of tiles fitting <code class="docutils literal notranslate"><span class="pre">img_size</span></code>.</p></li> -<li><p><strong>padding</strong> (<cite>tuple</cite>) – The amount of padding (bottom, left, top, right).</p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.item_in_enum"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">item_in_enum</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="n">enum</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#item_in_enum"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.item_in_enum" title="Permalink to this definition">¶</a></dt> -<dd><p>Check if an item exists in an enumeration.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>name</strong> (<cite>str</cite>) – Name of the item.</p></li> -<li><p><strong>enum</strong> (<cite>enum.Enum</cite>) – An instance of <cite>enum.Enum</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>ValueError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">name</span></code> is not in <code class="docutils literal notranslate"><span class="pre">enum</span></code>.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p>The value of <code class="docutils literal notranslate"><span class="pre">name</span></code> in <code class="docutils literal notranslate"><span class="pre">enum</span></code>.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>value</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.landsat_radiometric_calibration"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">landsat_radiometric_calibration</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">scene</span></em>, <em class="sig-param"><span class="n">outpath</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">exclude</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">radiance</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">overwrite</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">remove_raw</span><span class="o">=</span><span class="default_value">True</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#landsat_radiometric_calibration"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.landsat_radiometric_calibration" title="Permalink to this definition">¶</a></dt> -<dd><p>Radiometric calibration of Landsat Collection Level 1 scenes.</p> -<p>Convert the Landsat OLI bands to top of atmosphere radiance or reflectance -and the TIRS bands to top of atmosphere brightness temperature.</p> -<p>Conversion is performed following the <a href="#id31"><span class="problematic" id="id32">`equations`_</span></a> provided by the USGS.</p> -<p>The filename of each band is extended by one of the following suffixes, -depending on the type of the radiometric calibration:</p> -<blockquote> -<div><p>‘toa_ref’: top of atmosphere reflectance -‘toa_rad’: top of atmopshere radiance -‘toa_brt’: top of atmosphere brightness temperature</p> -</div></blockquote> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>scene</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – Path to a Landsat scene in digital number format.</p></li> -<li><p><strong>outpath</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>, optional) – Path to save the calibrated images. The default is None, which means -saving to <code class="docutils literal notranslate"><span class="pre">scene</span></code>.</p></li> -<li><p><strong>exclude</strong> (<cite>list</cite> [<cite>str</cite>], optional) – Bands to exclude from the radiometric calibration. The default is [].</p></li> -<li><p><strong>radiance</strong> (<cite>bool</cite>, optional) – Whether to calculate top of atmosphere radiance. The default is False, -which means calculating top of atmopshere reflectance.</p></li> -<li><p><strong>overwrite</strong> (<cite>bool</cite>, optional) – Whether to overwrite the calibrated images. The default is False.</p></li> -<li><p><strong>remove_raw</strong> (<cite>bool</cite>, optional) – Whether to remove the raw digitial number images. The default is True.</p></li> -</ul> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>FileNotFoundError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">scene</span></code> does not exist.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><ul class="simple"> -<li><p><em>None.</em></p></li> -<li><p><em>.. _equations</em> – <a class="reference external" href="https://www.usgs.gov/land-resources/nli/landsat/using-usgs-landsat-level-1-data-product">https://www.usgs.gov/land-resources/nli/landsat/using-usgs-landsat-level-1-data-product</a></p></li> -</ul> -</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.parse_landsat_scene"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">parse_landsat_scene</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">scene_id</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#parse_landsat_scene"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.parse_landsat_scene" title="Permalink to this definition">¶</a></dt> -<dd><p>Parse a Landsat scene identifier.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>scene_id</strong> (<cite>str</cite>) – A Landsat scene identifier.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>scene</strong> – A dictionary containing scene metadata. If <cite>None</cite>, <code class="docutils literal notranslate"><span class="pre">scene_id</span></code> is not -a valid Landsat scene identifier.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>dict</cite> or <cite>None</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.parse_sentinel2_scene"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">parse_sentinel2_scene</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">scene_id</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#parse_sentinel2_scene"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.parse_sentinel2_scene" title="Permalink to this definition">¶</a></dt> -<dd><p>Parse a Sentinel-2 scene identifier.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>scene_id</strong> (<cite>str</cite>) – A Sentinel-2 scene identifier.</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>scene</strong> – A dictionary containing scene metadata. If <cite>None</cite>, <code class="docutils literal notranslate"><span class="pre">scene_id</span></code> is not -a valid Sentinel-2 scene identifier.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>dict</cite> or <cite>None</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.read_landsat_metadata"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">read_landsat_metadata</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">file</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#read_landsat_metadata"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.read_landsat_metadata" title="Permalink to this definition">¶</a></dt> -<dd><p>Parse the Landsat metadata <a href="#id13"><span class="problematic" id="id14">*</span></a>_MTL.txt file.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>file</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – Path to a Landsat <a href="#id15"><span class="problematic" id="id16">*</span></a>_MTL.txt file.</p> -</dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>FileNotFoundError</strong> – Raised if <code class="docutils literal notranslate"><span class="pre">file</span></code> does not exist.</p> -</dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p><strong>metadata</strong> – The metadata text file as dictionary, where each line is a (key, value) -pair.</p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.reconstruct_scene"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">reconstruct_scene</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">tiles</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#reconstruct_scene"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.reconstruct_scene" title="Permalink to this definition">¶</a></dt> -<dd><p>Reconstruct a tiled image.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><p><strong>tiles</strong> (<cite>torch.Tensor</cite> or <cite>numpy.ndarray</cite>) – The tiled image, shape=(tiles, bands, tile_size, tile_size) or -shape=(tiles, tile_size, tile_size).</p> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>image</strong> – The reconstructed image.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>numpy.ndarray</cite></p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.standard_eo_structure"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">standard_eo_structure</code><span class="sig-paren">(</span><em class="sig-param">source_path</em>, <em class="sig-param">target_path</em>, <em class="sig-param">overwrite=False</em>, <em class="sig-param">move=False</em>, <em class="sig-param">parser=<function parse_landsat_scene></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#standard_eo_structure"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.standard_eo_structure" title="Permalink to this definition">¶</a></dt> -<dd><p>Modify the directory structure of a remote sensing dataset.</p> -<p>This function assumes that <code class="docutils literal notranslate"><span class="pre">source_path</span></code> points to a directory containing -remote sensing data, where each file in <code class="docutils literal notranslate"><span class="pre">source_path</span></code> and its sub-folders -should contain a scene identifier in its filename. The scene identifier is -used to restructure the dataset.</p> -<p>Currently, Landsat and Sentinel-2 datasets are supported.</p> -<p>The directory tree in <code class="docutils literal notranslate"><span class="pre">source_path</span></code> is modified to the following -structure in <code class="docutils literal notranslate"><span class="pre">target_path</span></code>:</p> -<blockquote> -<div><dl> -<dt>target_path/</dt><dd><dl class="simple"> -<dt>scene_id_1/</dt><dd><p>files matching scene_id_1</p> -</dd> -<dt>scene_id_2/</dt><dd><p>files matching scene_id_2</p> -</dd> -</dl> -<p>. -scene_id_n/</p> -<blockquote> -<div><p>files matching scene_id_n</p> -</div></blockquote> -</dd> -</dl> -</div></blockquote> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>source_path</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – Path to the remote sensing dataset.</p></li> -<li><p><strong>target_path</strong> (<cite>str</cite> or <cite>pathlib.Path</cite>) – Path to save the restructured dataset.</p></li> -<li><p><strong>overwrite</strong> (<cite>bool</cite>, optional) – Whether to overwrite existing files in <code class="docutils literal notranslate"><span class="pre">target_path</span></code>. -The default is True.</p></li> -<li><p><strong>move</strong> (<cite>bool</cite>, optional) – Whether to move the files from <code class="docutils literal notranslate"><span class="pre">source_path</span></code> to <code class="docutils literal notranslate"><span class="pre">target_path</span></code>. If -True, files in <code class="docutils literal notranslate"><span class="pre">source_path</span></code> are moved to <code class="docutils literal notranslate"><span class="pre">target_path</span></code>, if False, -files in <code class="docutils literal notranslate"><span class="pre">source_path</span></code> are copied to <code class="docutils literal notranslate"><span class="pre">target_path</span></code>. The default is -False.</p></li> -<li><p><strong>parser</strong> (<cite>function</cite>, optional) – The scene identifier parsing function. Depends on the sensor of the -dataset. See e.g., <cite>pysegcnn.core.utils.parse_landsat_scene</cite>.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> -</dd> -</dl> -</dd></dl> - -<dl class="py function"> -<dt id="core.utils.tile_topleft_corner"> -<code class="sig-prename descclassname">core.utils.</code><code class="sig-name descname">tile_topleft_corner</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">img_size</span></em>, <em class="sig-param"><span class="n">tile_size</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/core/utils.html#tile_topleft_corner"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#core.utils.tile_topleft_corner" title="Permalink to this definition">¶</a></dt> -<dd><p>Return the topleft corners of the tiles in the image.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>img_size</strong> (<cite>tuple</cite>) – The image size (height, width).</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite>) – The size of the tile.</p></li> -</ul> -</dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p><strong>indices</strong> – The keys of <code class="docutils literal notranslate"><span class="pre">indices</span></code> are the tile ids (<cite>int</cite>) and the values are the -topleft corners (<cite>tuple</cite> = (y, x)) of the tiles.</p> -</dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p><cite>dict</cite></p> -</dd> -</dl> -</dd></dl> - -</div> -</div> -<div class="section" id="module-core"> -<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-core" title="Permalink to this headline">¶</a></h2> -</div> -</div> - - - </div> - - </div> - <footer> - - <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - - <a href="main.html" class="btn btn-neutral float-right" title="main package" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> - - - <a href="modules.html" class="btn btn-neutral float-left" title="pysegcnn" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> - - </div> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/source/generated/pysegcnn.core.dataset.Cloud95Dataset.html b/docs/_build/html/source/generated/pysegcnn.core.dataset.Cloud95Dataset.html index 71193ba899ffa348b9a91465bd75b0563c14462b..78fe3ebf4be34eb40a674e610a52ff4928fa76dc 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.dataset.Cloud95Dataset.html +++ b/docs/_build/html/source/generated/pysegcnn.core.dataset.Cloud95Dataset.html @@ -87,8 +87,8 @@ <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> <li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> <li class="toctree-l2 current"><a class="reference internal" href="../api.html#dataset">Dataset</a><ul class="current"> -<li class="toctree-l3"><a class="reference internal" href="pysegcnn.core.dataset.ImageDataset.html">pysegcnn.core.dataset.ImageDataset</a></li> -<li class="toctree-l3 current"><a class="reference internal" href="../api.html#supported-datasets">Supported datasets</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="../api.html#generic-classes">Generic classes</a></li> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#specific-classes">Specific classes</a><ul class="current"> <li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.dataset.SparcsDataset.html">pysegcnn.core.dataset.SparcsDataset</a></li> <li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.dataset.Cloud95Dataset</a></li> </ul> @@ -171,80 +171,48 @@ <dt id="pysegcnn.core.dataset.Cloud95Dataset"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.dataset.</code><code class="sig-name descname">Cloud95Dataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/dataset.html#Cloud95Dataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.dataset.Cloud95Dataset" title="Permalink to this definition">¶</a></dt> <dd><p>Class for the <a class="reference external" href="https://github.com/SorourMo/95-Cloud-An-Extension-to-38-Cloud-Dataset">Cloud-95</a> dataset by <a class="reference external" href="https://arxiv.org/abs/2001.08768">Mohajerani & Saeedi (2020)</a>.</p> -<dl class="field-list simple"> +<dl class="py method"> +<dt id="pysegcnn.core.dataset.Cloud95Dataset.__init__"> +<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/dataset.html#Cloud95Dataset.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.dataset.Cloud95Dataset.__init__" title="Permalink to this definition">¶</a></dt> +<dd><p>Initialize.</p> +<dl class="field-list"> <dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. All -directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for files -matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> +<dd class="field-odd"><dl> +<dt><strong>root_dir</strong><span class="classifier"><cite>str</cite></span></dt><dd><p>The root directory, path to the dataset.</p> +</dd> +<dt><strong>use_bands</strong><span class="classifier"><cite>list</cite> [<cite>str</cite>], optional</span></dt><dd><p>A list of the spectral bands to use. The default is <cite>[]</cite>.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>tile_size</strong><span class="classifier"><cite>int</cite> or <cite>None</cite>, optional</span></dt><dd><p>The size of the tiles. If not <cite>None</cite>, each scene is divided into +square tiles of shape <code class="docutils literal notranslate"><span class="pre">(tile_size,</span> <span class="pre">tile_size)</span></code>. The default is +<cite>None</cite>.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>pad</strong><span class="classifier"><cite>bool</cite>, optional</span></dt><dd><p>Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad=True</span></code>, if the +images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image +data is padded with a constant padding value of zero. For each +image, the corresponding ground truth image is padded with a +“no data†label. The default is <cite>False</cite>.</p> +</dd> +<dt><strong>gt_pattern</strong><span class="classifier"><cite>str</cite>, optional</span></dt><dd><p>A regural expression to match the ground truth naming convention. +All directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for +files matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is <cite>(.*)gt\.tif</cite>.</p> +</dd> +<dt><strong>sort</strong><span class="classifier"><cite>bool</cite>, optional</span></dt><dd><p>Whether to chronologically sort the samples. Useful for time series +data. The default is <cite>False</cite>.</p> +</dd> +<dt><strong>seed</strong><span class="classifier"><cite>int</cite>, optional</span></dt><dd><p>The random seed. Used to split the dataset into training, +validation and test set. Useful for reproducibility. The default is +<cite>0</cite>.</p> +</dd> +<dt><strong>transforms</strong><span class="classifier"><cite>list</cite>, optional</span></dt><dd><p>List of <a class="reference internal" href="pysegcnn.core.transforms.Augment.html#pysegcnn.core.transforms.Augment" title="pysegcnn.core.transforms.Augment"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.transforms.Augment</span></code></a> instances. +Each item in <code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed +version of the dataset. The total dataset is composed of the +original untransformed dataset together with each transformed +version of it. If <code class="docutils literal notranslate"><span class="pre">transforms=[]</span></code>, only the original dataset is +used. The default is <cite>[]</cite>.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code>()</p></td> -<td><p>Class labels of the Cloud-95 dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code>()</p></td> -<td><p>Landsat 8 bands of the Cloud-95 dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code>()</p></td> -<td><p>Image size of the Cloud-95 dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code>(scene_id)</p></td> -<td><p>Parse Sparcs scene identifiers (Landsat 8).</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code>(data, gt)</p></td> -<td><p>Preprocess Cloud-95 dataset images.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="pysegcnn.core.dataset.Cloud95Dataset.__init__"> -<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/dataset.html#Cloud95Dataset.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.dataset.Cloud95Dataset.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initialize self. See help(type(self)) for accurate signature.</p> </dd></dl> <p class="rubric">Methods</p> @@ -255,7 +223,7 @@ The default is [].</p></li> </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.dataset.Cloud95Dataset.__init__" title="pysegcnn.core.dataset.Cloud95Dataset.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(root_dir[, use_bands, tile_size, …])</p></td> -<td><p>Initialize self.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> <td><p>Stack the bands of a sample in a single array.</p></td> @@ -282,7 +250,7 @@ The default is [].</p></li> <td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> +<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.Tensor</span></code>.</p></td> </tr> </tbody> </table> diff --git a/docs/_build/html/source/generated/pysegcnn.core.dataset.ImageDataset.html b/docs/_build/html/source/generated/pysegcnn.core.dataset.ImageDataset.html index 31e363c90e798c8ed4afc43b8acb2964faf25e18..6ee1bfb83bd7c91b22ac749927f6d6ab8c58c8b4 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.dataset.ImageDataset.html +++ b/docs/_build/html/source/generated/pysegcnn.core.dataset.ImageDataset.html @@ -36,7 +36,7 @@ <link rel="index" title="Index" href="../../genindex.html" /> <link rel="search" title="Search" href="../../search.html" /> - <link rel="next" title="pysegcnn.core.dataset.SparcsDataset" href="pysegcnn.core.dataset.SparcsDataset.html" /> + <link rel="next" title="pysegcnn.core.dataset.StandardEoDataset" href="pysegcnn.core.dataset.StandardEoDataset.html" /> <link rel="prev" title="API Reference" href="../api.html" /> </head> @@ -87,8 +87,12 @@ <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> <li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> <li class="toctree-l2 current"><a class="reference internal" href="../api.html#dataset">Dataset</a><ul class="current"> -<li class="toctree-l3 current"><a class="current reference internal" href="#">pysegcnn.core.dataset.ImageDataset</a></li> -<li class="toctree-l3"><a class="reference internal" href="../api.html#supported-datasets">Supported datasets</a></li> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#generic-classes">Generic classes</a><ul class="current"> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.dataset.ImageDataset</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.dataset.StandardEoDataset.html">pysegcnn.core.dataset.StandardEoDataset</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#specific-classes">Specific classes</a></li> </ul> </li> <li class="toctree-l2"><a class="reference internal" href="../api.html#models">Models</a></li> @@ -167,84 +171,51 @@ <dt id="pysegcnn.core.dataset.ImageDataset"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.dataset.</code><code class="sig-name descname">ImageDataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/dataset.html#ImageDataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.dataset.ImageDataset" title="Permalink to this definition">¶</a></dt> <dd><p>Base class for multispectral image data.</p> -<p>Inheriting from <cite>torch.utils.data.Dataset</cite> to be compliant to the PyTorch -standard. Furthermore, using instances of <cite>torch.utils.data.Dataset</cite> -enables the use of the handy <cite>torch.utils.data.DataLoader</cite> class during -model training.</p> -<dl class="field-list simple"> +<p>Inheriting from <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.utils.data.Dataset</span></code> to be compliant to the +PyTorch standard. This enables the use of the handy +<code class="xref py py-class docutils literal notranslate"><span class="pre">torch.utils.data.DataLoader</span></code> class during model training.</p> +<dl class="py method"> +<dt id="pysegcnn.core.dataset.ImageDataset.__init__"> +<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/dataset.html#ImageDataset.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.dataset.ImageDataset.__init__" title="Permalink to this definition">¶</a></dt> +<dd><p>Initialize.</p> +<dl class="field-list"> <dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. +<dd class="field-odd"><dl> +<dt><strong>root_dir</strong><span class="classifier"><cite>str</cite></span></dt><dd><p>The root directory, path to the dataset.</p> +</dd> +<dt><strong>use_bands</strong><span class="classifier"><cite>list</cite> [<cite>str</cite>], optional</span></dt><dd><p>A list of the spectral bands to use. The default is <cite>[]</cite>.</p> +</dd> +<dt><strong>tile_size</strong><span class="classifier"><cite>int</cite> or <cite>None</cite>, optional</span></dt><dd><p>The size of the tiles. If not <cite>None</cite>, each scene is divided into +square tiles of shape <code class="docutils literal notranslate"><span class="pre">(tile_size,</span> <span class="pre">tile_size)</span></code>. The default is +<cite>None</cite>.</p> +</dd> +<dt><strong>pad</strong><span class="classifier"><cite>bool</cite>, optional</span></dt><dd><p>Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad=True</span></code>, if the +images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image +data is padded with a constant padding value of zero. For each +image, the corresponding ground truth image is padded with a +“no data†label. The default is <cite>False</cite>.</p> +</dd> +<dt><strong>gt_pattern</strong><span class="classifier"><cite>str</cite>, optional</span></dt><dd><p>A regural expression to match the ground truth naming convention. All directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for -files matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> +files matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is <cite>(.*)gt\.tif</cite>.</p> +</dd> +<dt><strong>sort</strong><span class="classifier"><cite>bool</cite>, optional</span></dt><dd><p>Whether to chronologically sort the samples. Useful for time series +data. The default is <cite>False</cite>.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>seed</strong><span class="classifier"><cite>int</cite>, optional</span></dt><dd><p>The random seed. Used to split the dataset into training, +validation and test set. Useful for reproducibility. The default is +<cite>0</cite>.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>transforms</strong><span class="classifier"><cite>list</cite>, optional</span></dt><dd><p>List of <a class="reference internal" href="pysegcnn.core.transforms.Augment.html#pysegcnn.core.transforms.Augment" title="pysegcnn.core.transforms.Augment"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.transforms.Augment</span></code></a> instances. +Each item in <code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed +version of the dataset. The total dataset is composed of the +original untransformed dataset together with each transformed +version of it. If <code class="docutils literal notranslate"><span class="pre">transforms=[]</span></code>, only the original dataset is +used. The default is <cite>[]</cite>.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code>()</p></td> -<td><p>Return an enumeration of the class labels of the dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code>()</p></td> -<td><p>Return an enumeration of the bands of the sensor of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code>()</p></td> -<td><p>Return the size of the images in the dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code>(scene_id)</p></td> -<td><p>Parse the scene identifier.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code>(data, gt)</p></td> -<td><p>Preprocess a sample before feeding it to a model.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="pysegcnn.core.dataset.ImageDataset.__init__"> -<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/dataset.html#ImageDataset.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.dataset.ImageDataset.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initialize self. See help(type(self)) for accurate signature.</p> </dd></dl> <p class="rubric">Methods</p> @@ -255,7 +226,7 @@ The default is [].</p></li> </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.dataset.ImageDataset.__init__" title="pysegcnn.core.dataset.ImageDataset.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(root_dir[, use_bands, tile_size, …])</p></td> -<td><p>Initialize self.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> <td><p>Stack the bands of a sample in a single array.</p></td> @@ -282,7 +253,7 @@ The default is [].</p></li> <td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> +<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.Tensor</span></code>.</p></td> </tr> </tbody> </table> @@ -298,7 +269,7 @@ The default is [].</p></li> <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - <a href="pysegcnn.core.dataset.SparcsDataset.html" class="btn btn-neutral float-right" title="pysegcnn.core.dataset.SparcsDataset" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + <a href="pysegcnn.core.dataset.StandardEoDataset.html" class="btn btn-neutral float-right" title="pysegcnn.core.dataset.StandardEoDataset" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> <a href="../api.html" class="btn btn-neutral float-left" title="API Reference" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> diff --git a/docs/_build/html/source/generated/pysegcnn.core.dataset.SparcsDataset.html b/docs/_build/html/source/generated/pysegcnn.core.dataset.SparcsDataset.html index 9aa65a8dd2f76b40cc0f1f8117cd184ec1677b6f..37b1630b6319393e6c0e06e9c93ee29ba373a3af 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.dataset.SparcsDataset.html +++ b/docs/_build/html/source/generated/pysegcnn.core.dataset.SparcsDataset.html @@ -37,7 +37,7 @@ <link rel="index" title="Index" href="../../genindex.html" /> <link rel="search" title="Search" href="../../search.html" /> <link rel="next" title="pysegcnn.core.dataset.Cloud95Dataset" href="pysegcnn.core.dataset.Cloud95Dataset.html" /> - <link rel="prev" title="pysegcnn.core.dataset.ImageDataset" href="pysegcnn.core.dataset.ImageDataset.html" /> + <link rel="prev" title="pysegcnn.core.dataset.StandardEoDataset" href="pysegcnn.core.dataset.StandardEoDataset.html" /> </head> <body class="wy-body-for-nav"> @@ -87,8 +87,8 @@ <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> <li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> <li class="toctree-l2 current"><a class="reference internal" href="../api.html#dataset">Dataset</a><ul class="current"> -<li class="toctree-l3"><a class="reference internal" href="pysegcnn.core.dataset.ImageDataset.html">pysegcnn.core.dataset.ImageDataset</a></li> -<li class="toctree-l3 current"><a class="reference internal" href="../api.html#supported-datasets">Supported datasets</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="../api.html#generic-classes">Generic classes</a></li> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#specific-classes">Specific classes</a><ul class="current"> <li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.dataset.SparcsDataset</a></li> <li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.dataset.Cloud95Dataset.html">pysegcnn.core.dataset.Cloud95Dataset</a></li> </ul> @@ -170,81 +170,49 @@ <dl class="py class"> <dt id="pysegcnn.core.dataset.SparcsDataset"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.dataset.</code><code class="sig-name descname">SparcsDataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/dataset.html#SparcsDataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.dataset.SparcsDataset" title="Permalink to this definition">¶</a></dt> -<dd><p>Class for the <a class="reference external" href="https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation">Sparcs</a> dataset.</p> -<dl class="field-list simple"> +<dd><p>Class for the <a class="reference external" href="https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation">Sparcs</a> dataset by <a class="reference external" href="https://www.mdpi.com/2072-4292/6/6/4907">Hughes & Hayes (2014)</a>.</p> +<dl class="py method"> +<dt id="pysegcnn.core.dataset.SparcsDataset.__init__"> +<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/dataset.html#SparcsDataset.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.dataset.SparcsDataset.__init__" title="Permalink to this definition">¶</a></dt> +<dd><p>Initialize.</p> +<dl class="field-list"> <dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>root_dir</strong> (<cite>str</cite>) – The root directory, path to the dataset.</p></li> -<li><p><strong>use_bands</strong> (<cite>list</cite> [<cite>str</cite>], optional) – A list of the spectral bands to use. The default is [].</p></li> -<li><p><strong>tile_size</strong> (<cite>int</cite> or <cite>None</cite>, optional) – The size of the tiles. If not <cite>None</cite>, each scene is divided into square -tiles of shape (tile_size, tile_size). The default is None.</p></li> -<li><p><strong>pad</strong> (<cite>bool</cite>, optional) – Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad</span></code> = True, if the -images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image data is -padded with a constant padding value of zero. For each image, the -corresponding ground truth image is padded with a “no data†label. -The default is False.</p></li> -<li><p><strong>gt_pattern</strong> (<cite>str</cite>, optional) – A regural expression to match the ground truth naming convention. All -directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for files -matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is ‘(.*)gt\.tif’.</p></li> -<li><p><strong>sort</strong> (<cite>bool</cite>, optional) – Whether to chronologically sort the samples. Useful for time series -data. The default is False.</p></li> -<li><p><strong>seed</strong> (<cite>int</cite>, optional) – The random seed. Used to split the dataset into training, validation -and test set. Useful for reproducibility. The default is 0.</p></li> -<li><p><strong>transforms</strong> (<cite>list</cite> [<cite>pysegcnn.core.split.Augment</cite>], optional) – List of <cite>pysegcnn.core.split.Augment</cite> instances. Each item in -<code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed version of the dataset. -The total dataset is composed of the original untransformed dataset -together with each transformed version of it. -If <code class="docutils literal notranslate"><span class="pre">transforms</span></code> = [], only the original dataset is used. -The default is [].</p></li> -</ul> +<dd class="field-odd"><dl> +<dt><strong>root_dir</strong><span class="classifier"><cite>str</cite></span></dt><dd><p>The root directory, path to the dataset.</p> +</dd> +<dt><strong>use_bands</strong><span class="classifier"><cite>list</cite> [<cite>str</cite>], optional</span></dt><dd><p>A list of the spectral bands to use. The default is <cite>[]</cite>.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>tile_size</strong><span class="classifier"><cite>int</cite> or <cite>None</cite>, optional</span></dt><dd><p>The size of the tiles. If not <cite>None</cite>, each scene is divided into +square tiles of shape <code class="docutils literal notranslate"><span class="pre">(tile_size,</span> <span class="pre">tile_size)</span></code>. The default is +<cite>None</cite>.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>pad</strong><span class="classifier"><cite>bool</cite>, optional</span></dt><dd><p>Whether to center pad the input image. Set <code class="docutils literal notranslate"><span class="pre">pad=True</span></code>, if the +images are not evenly divisible by the <code class="docutils literal notranslate"><span class="pre">tile_size</span></code>. The image +data is padded with a constant padding value of zero. For each +image, the corresponding ground truth image is padded with a +“no data†label. The default is <cite>False</cite>.</p> +</dd> +<dt><strong>gt_pattern</strong><span class="classifier"><cite>str</cite>, optional</span></dt><dd><p>A regural expression to match the ground truth naming convention. +All directories and subdirectories in <code class="docutils literal notranslate"><span class="pre">root_dir</span></code> are searched for +files matching <code class="docutils literal notranslate"><span class="pre">gt_pattern</span></code>. The default is <cite>(.*)gt\.tif</cite>.</p> +</dd> +<dt><strong>sort</strong><span class="classifier"><cite>bool</cite>, optional</span></dt><dd><p>Whether to chronologically sort the samples. Useful for time series +data. The default is <cite>False</cite>.</p> +</dd> +<dt><strong>seed</strong><span class="classifier"><cite>int</cite>, optional</span></dt><dd><p>The random seed. Used to split the dataset into training, +validation and test set. Useful for reproducibility. The default is +<cite>0</cite>.</p> +</dd> +<dt><strong>transforms</strong><span class="classifier"><cite>list</cite>, optional</span></dt><dd><p>List of <a class="reference internal" href="pysegcnn.core.transforms.Augment.html#pysegcnn.core.transforms.Augment" title="pysegcnn.core.transforms.Augment"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.transforms.Augment</span></code></a> instances. +Each item in <code class="docutils literal notranslate"><span class="pre">transforms</span></code> generates a distinct transformed +version of the dataset. The total dataset is composed of the +original untransformed dataset together with each transformed +version of it. If <code class="docutils literal notranslate"><span class="pre">transforms=[]</span></code>, only the original dataset is +used. The default is <cite>[]</cite>.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> -<td><p>Stack the bands of a sample in a single array.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">compose_scenes</span></code>()</p></td> -<td><p>Build the list of samples of the dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_labels</span></code>()</p></td> -<td><p>Class labels of the Sparcs dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_sensor</span></code>()</p></td> -<td><p>Landsat 8 bands of the Sparcs dataset.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_size</span></code>()</p></td> -<td><p>Image size of the Sparcs dataset.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parse_scene_id</span></code>(scene_id)</p></td> -<td><p>Parse Sparcs scene identifiers (Landsat 8).</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">preprocess</span></code>(data, gt)</p></td> -<td><p>Preprocess Sparcs dataset images.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">read_scene</span></code>(idx)</p></td> -<td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="pysegcnn.core.dataset.SparcsDataset.__init__"> -<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">root_dir</span></em>, <em class="sig-param"><span class="n">use_bands</span><span class="o">=</span><span class="default_value">[]</span></em>, <em class="sig-param"><span class="n">tile_size</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pad</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">gt_pattern</span><span class="o">=</span><span class="default_value">'(.*)gt\\.tif'</span></em>, <em class="sig-param"><span class="n">sort</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">transforms</span><span class="o">=</span><span class="default_value">[]</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/dataset.html#SparcsDataset.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.dataset.SparcsDataset.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initialize self. See help(type(self)) for accurate signature.</p> </dd></dl> <p class="rubric">Methods</p> @@ -255,7 +223,7 @@ The default is [].</p></li> </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.dataset.SparcsDataset.__init__" title="pysegcnn.core.dataset.SparcsDataset.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(root_dir[, use_bands, tile_size, …])</p></td> -<td><p>Initialize self.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">build_samples</span></code>(scene)</p></td> <td><p>Stack the bands of a sample in a single array.</p></td> @@ -282,7 +250,7 @@ The default is [].</p></li> <td><p>Read the data of the sample with index <code class="docutils literal notranslate"><span class="pre">idx</span></code>.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tensor</span></code>(x, dtype)</p></td> -<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <cite>torch.Tensor</cite>.</p></td> +<td><p>Convert <code class="docutils literal notranslate"><span class="pre">x</span></code> to <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.Tensor</span></code>.</p></td> </tr> </tbody> </table> @@ -301,7 +269,7 @@ The default is [].</p></li> <a href="pysegcnn.core.dataset.Cloud95Dataset.html" class="btn btn-neutral float-right" title="pysegcnn.core.dataset.Cloud95Dataset" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> - <a href="pysegcnn.core.dataset.ImageDataset.html" class="btn btn-neutral float-left" title="pysegcnn.core.dataset.ImageDataset" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + <a href="pysegcnn.core.dataset.StandardEoDataset.html" class="btn btn-neutral float-left" title="pysegcnn.core.dataset.StandardEoDataset" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> </div> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.Block.html b/docs/_build/html/source/generated/pysegcnn.core.layers.Block.html index aca8887c887829393ef959bdc9a865f0fae8f672..a0aa79226b3ef4f428d355717407f42f2a3fa9e6 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.Block.html +++ b/docs/_build/html/source/generated/pysegcnn.core.layers.Block.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.layers.Conv2dSame" href="pysegcnn.core.layers.Conv2dSame.html" /> + <link rel="prev" title="pysegcnn.core.dataset.Cloud95Dataset" href="pysegcnn.core.dataset.Cloud95Dataset.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,26 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#layers">Layers</a><ul class="current"> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.layers.Block</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html">pysegcnn.core.layers.Conv2dSame</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxPool.html">pysegcnn.core.layers.ConvBnReluMaxPool</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxUnpool.html">pysegcnn.core.layers.ConvBnReluMaxUnpool</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluUpsample.html">pysegcnn.core.layers.ConvBnReluUpsample</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a></li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a></li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +148,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.layers.Block</li> @@ -155,148 +175,45 @@ <dt id="pysegcnn.core.layers.Block"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.layers.</code><code class="sig-name descname">Block</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#Block"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.Block" title="Permalink to this definition">¶</a></dt> <dd><p>Basic convolutional block.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> +<dl class="field-list"> +<dt class="field-odd">Attributes</dt> +<dd class="field-odd"><dl> +<dt><strong>in_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of input channels.</p> </dd> -<dt class="field-even">Raises</dt> -<dd class="field-even"><p><strong>TypeError</strong> – Raised if <cite>~pysegcnn.core.layers.Block.layers</cite> method does not return -an instance of <cite>torch.nn.Sequential</cite>.</p> +<dt><strong>out_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of output channels.</p> </dd> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> +<dt><strong>kwargs: `dict` [`str`]</strong></dt><dd><p>Additional arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> </dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> +<dt><strong>conv</strong><span class="classifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code></span></dt><dd><p>The convolutional layers of the block.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>()</p></td> -<td><p>Forward pass of the block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code>()</p></td> -<td><p>Define the layers of the block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> <dl class="py method"> <dt id="pysegcnn.core.layers.Block.__init__"> <code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#Block.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.Block.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> +<dd><p>Initialize.</p> +<dl class="field-list"> +<dt class="field-odd">Parameters</dt> +<dd class="field-odd"><dl> +<dt><strong>in_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of input channels.</p> +</dd> +<dt><strong>out_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of output channels.</p> +</dd> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> +</dd> +</dl> +</dd> +<dt class="field-even">Raises</dt> +<dd class="field-even"><dl class="simple"> +<dt>TypeError</dt><dd><p>Raised if <code class="xref py py-meth docutils literal notranslate"><span class="pre">layers()</span></code> method does +not return an instance of <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code>.</p> +</dd> +</dl> +</dd> +</dl> </dd></dl> <p class="rubric">Methods</p> @@ -307,7 +224,7 @@ an instance of <cite>torch.nn.Sequential</cite>.</p> </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.layers.Block.__init__" title="pysegcnn.core.layers.Block.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -435,6 +352,15 @@ an instance of <cite>torch.nn.Sequential</cite>.</p> </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.layers.Conv2dSame.html" class="btn btn-neutral float-right" title="pysegcnn.core.layers.Conv2dSame" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.dataset.Cloud95Dataset.html" class="btn btn-neutral float-left" title="pysegcnn.core.dataset.Cloud95Dataset" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.Conv2dSame.html b/docs/_build/html/source/generated/pysegcnn.core.layers.Conv2dSame.html index 48ec4f834446ecb9f1d19c8ddfb1941d4c13446c..52f526271b86e8c2c7c460b71b31d2d7a7e717d7 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.Conv2dSame.html +++ b/docs/_build/html/source/generated/pysegcnn.core.layers.Conv2dSame.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.layers.ConvBnReluMaxPool" href="pysegcnn.core.layers.ConvBnReluMaxPool.html" /> + <link rel="prev" title="pysegcnn.core.layers.Block" href="pysegcnn.core.layers.Block.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,26 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#layers">Layers</a><ul class="current"> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Block.html">pysegcnn.core.layers.Block</a></li> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.layers.Conv2dSame</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxPool.html">pysegcnn.core.layers.ConvBnReluMaxPool</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxUnpool.html">pysegcnn.core.layers.ConvBnReluMaxUnpool</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluUpsample.html">pysegcnn.core.layers.ConvBnReluUpsample</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a></li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a></li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +148,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.layers.Conv2dSame</li> @@ -158,11 +178,23 @@ <p>Given the kernel size, the dilation and a stride of 1, the padding is calculated such that the output of the convolution has the same spatial dimensions as the input.</p> +<dl class="field-list"> +<dt class="field-odd">Attributes</dt> +<dd class="field-odd"><dl> +<dt><strong>padding</strong><span class="classifier"><cite>tuple</cite> [<cite>int</cite>]</span></dt><dd><p>The amount of padding, (pad_height, pad_width).</p> +</dd> +</dl> +</dd> +</dl> +<dl class="py method"> +<dt id="pysegcnn.core.layers.Conv2dSame.__init__"> +<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#Conv2dSame.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.Conv2dSame.__init__" title="Permalink to this definition">¶</a></dt> +<dd><p>Initialize.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>*args</strong> (<cite>list</cite> [<cite>str</cite>]) – <dl class="simple"> -<dt>positional arguments passed to <cite>torch.nn.Conv2d</cite>:</dt><dd><dl class="simple"> +<dd class="field-odd"><dl class="simple"> +<dt><strong>*args: `list` [`str`]</strong></dt><dd><dl class="simple"> +<dt>positional arguments passed to <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Conv2d</span></code>:</dt><dd><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">'in_channels'</span></code>: <cite>int</cite></dt><dd><p>Number of input channels.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">'out_channels'</span></code>: <cite>int</cite></dt><dd><p>Number of output channels.</p> @@ -172,144 +204,12 @@ dimensions as the input.</p> </dl> </dd> </dl> -</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional keyword arguments passed to <a href="#id1"><span class="problematic" id="id2">`torch.nn.Conv2d`_</span></a>.</p></li> -<li><p><strong>_torch.nn.Conv2d</strong> (<em>.</em>) – <a class="reference external" href="https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d">https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d</a></p></li> -</ul> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional keyword arguments passed to <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Conv2d</span></code>.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">same_padding</span></code>(d, k)</p></td> -<td><p>Calculate the amount of padding.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 67%" /> -<col style="width: 33%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>forward</strong></p></td> -<td></td> -</tr> -<tr class="row-odd"><td><p><strong>reset_parameters</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="pysegcnn.core.layers.Conv2dSame.__init__"> -<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#Conv2dSame.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.Conv2dSame.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> </dd></dl> <p class="rubric">Methods</p> @@ -320,7 +220,7 @@ dimensions as the input.</p> </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.layers.Conv2dSame.__init__" title="pysegcnn.core.layers.Conv2dSame.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(*args, **kwargs)</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -451,6 +351,15 @@ dimensions as the input.</p> </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.layers.ConvBnReluMaxPool.html" class="btn btn-neutral float-right" title="pysegcnn.core.layers.ConvBnReluMaxPool" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.layers.Block.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers.Block" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.html b/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.html index 09c844e7b508d31111dc76a285696ca8092e3944..f037442d93026acc61b2876591af974b12ce80b9 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.html +++ b/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.layers.ConvBnReluMaxUnpool" href="pysegcnn.core.layers.ConvBnReluMaxUnpool.html" /> + <link rel="prev" title="pysegcnn.core.layers.Conv2dSame" href="pysegcnn.core.layers.Conv2dSame.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,26 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#layers">Layers</a><ul class="current"> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Block.html">pysegcnn.core.layers.Block</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html">pysegcnn.core.layers.Conv2dSame</a></li> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.layers.ConvBnReluMaxPool</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxUnpool.html">pysegcnn.core.layers.ConvBnReluMaxUnpool</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluUpsample.html">pysegcnn.core.layers.ConvBnReluUpsample</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a></li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a></li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +148,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.layers.ConvBnReluMaxPool</li> @@ -155,148 +175,30 @@ <dt id="pysegcnn.core.layers.ConvBnReluMaxPool"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.layers.</code><code class="sig-name descname">ConvBnReluMaxPool</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#ConvBnReluMaxPool"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.ConvBnReluMaxPool" title="Permalink to this definition">¶</a></dt> <dd><p>Block of convolution, batchnorm, relu and 2x2 max pool.</p> -<dl class="field-list simple"> +<dl class="py method"> +<dt id="pysegcnn.core.layers.ConvBnReluMaxPool.__init__"> +<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#ConvBnReluMaxPool.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.ConvBnReluMaxPool.__init__" title="Permalink to this definition">¶</a></dt> +<dd><p>Initialize.</p> +<dl class="field-list"> <dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional keyword arguments passed to -<cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> +<dd class="field-odd"><dl> +<dt><strong>in_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of input channels.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>out_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of output channels.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> +</dd> +</dl> +</dd> +<dt class="field-even">Raises</dt> +<dd class="field-even"><dl class="simple"> +<dt>TypeError</dt><dd><p>Raised if <code class="xref py py-meth docutils literal notranslate"><span class="pre">layers()</span></code> method does +not return an instance of <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code>.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">downsample</span></code>(x)</p></td> -<td><p>2x2 max pooling layer, <cite>torch.nn.functional.max_pool2d</cite>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Define optional extra information about this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x)</p></td> -<td><p>Forward pass of an encoder block.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code>()</p></td> -<td><p>Sequence of convolution, batchnorm and relu layers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="pysegcnn.core.layers.ConvBnReluMaxPool.__init__"> -<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#ConvBnReluMaxPool.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.ConvBnReluMaxPool.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> </dd></dl> <p class="rubric">Methods</p> @@ -307,7 +209,7 @@ </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.layers.ConvBnReluMaxPool.__init__" title="pysegcnn.core.layers.ConvBnReluMaxPool.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -334,7 +236,7 @@ <td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">downsample</span></code>(x)</p></td> -<td><p>2x2 max pooling layer, <cite>torch.nn.functional.max_pool2d</cite>.</p></td> +<td><p>2x2 max pooling layer.</p></td> </tr> <tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> <td><p>Sets the module in evaluation mode.</p></td> @@ -438,6 +340,15 @@ </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.layers.ConvBnReluMaxUnpool.html" class="btn btn-neutral float-right" title="pysegcnn.core.layers.ConvBnReluMaxUnpool" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.layers.Conv2dSame.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers.Conv2dSame" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.html b/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.html index f694846b4861e74dbf7e2ae1eb15393389854a2b..3cbf3dc9ca97b3b3700b877bf31d5caeadbea5d2 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.html +++ b/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.layers.ConvBnReluUpsample" href="pysegcnn.core.layers.ConvBnReluUpsample.html" /> + <link rel="prev" title="pysegcnn.core.layers.ConvBnReluMaxPool" href="pysegcnn.core.layers.ConvBnReluMaxPool.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,26 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#layers">Layers</a><ul class="current"> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Block.html">pysegcnn.core.layers.Block</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html">pysegcnn.core.layers.Conv2dSame</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxPool.html">pysegcnn.core.layers.ConvBnReluMaxPool</a></li> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.layers.ConvBnReluMaxUnpool</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluUpsample.html">pysegcnn.core.layers.ConvBnReluUpsample</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a></li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a></li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +148,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.layers.ConvBnReluMaxUnpool</li> @@ -155,148 +175,30 @@ <dt id="pysegcnn.core.layers.ConvBnReluMaxUnpool"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.layers.</code><code class="sig-name descname">ConvBnReluMaxUnpool</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#ConvBnReluMaxUnpool"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.ConvBnReluMaxUnpool" title="Permalink to this definition">¶</a></dt> <dd><p>Block of convolution, batchnorm, relu and 2x2 max unpool.</p> -<dl class="field-list simple"> +<dl class="py method"> +<dt id="pysegcnn.core.layers.ConvBnReluMaxUnpool.__init__"> +<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#ConvBnReluMaxUnpool.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.ConvBnReluMaxUnpool.__init__" title="Permalink to this definition">¶</a></dt> +<dd><p>Initialize.</p> +<dl class="field-list"> <dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional keyword arguments passed to -<cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> +<dd class="field-odd"><dl> +<dt><strong>in_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of input channels.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>out_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of output channels.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> +</dd> +</dl> +</dd> +<dt class="field-even">Raises</dt> +<dd class="field-even"><dl class="simple"> +<dt>TypeError</dt><dd><p>Raised if <code class="xref py py-meth docutils literal notranslate"><span class="pre">layers()</span></code> method does +not return an instance of <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code>.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Define optional extra information about this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x, feature, indices, skip)</p></td> -<td><p>Forward pass of a decoder block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code>()</p></td> -<td><p>Sequence of convolution, batchnorm and relu layers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">upsample</span></code>(x, feature, indices)</p></td> -<td><p>2x2 max unpooling layer.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="pysegcnn.core.layers.ConvBnReluMaxUnpool.__init__"> -<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#ConvBnReluMaxUnpool.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.ConvBnReluMaxUnpool.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> </dd></dl> <p class="rubric">Methods</p> @@ -307,7 +209,7 @@ </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.layers.ConvBnReluMaxUnpool.__init__" title="pysegcnn.core.layers.ConvBnReluMaxUnpool.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -438,6 +340,15 @@ </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.layers.ConvBnReluUpsample.html" class="btn btn-neutral float-right" title="pysegcnn.core.layers.ConvBnReluUpsample" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.layers.ConvBnReluMaxPool.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers.ConvBnReluMaxPool" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.html b/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.html index f5ebbff95d8836755c94d745ec89d9f14911f37a..c504ad0ca50329c93cc7f67fb37d631317c30688 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.html +++ b/docs/_build/html/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.layers.EncoderBlock" href="pysegcnn.core.layers.EncoderBlock.html" /> + <link rel="prev" title="pysegcnn.core.layers.ConvBnReluMaxUnpool" href="pysegcnn.core.layers.ConvBnReluMaxUnpool.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,26 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#layers">Layers</a><ul class="current"> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Block.html">pysegcnn.core.layers.Block</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html">pysegcnn.core.layers.Conv2dSame</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxPool.html">pysegcnn.core.layers.ConvBnReluMaxPool</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxUnpool.html">pysegcnn.core.layers.ConvBnReluMaxUnpool</a></li> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.layers.ConvBnReluUpsample</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a></li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a></li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +148,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.layers.ConvBnReluUpsample</li> @@ -154,148 +174,31 @@ <dl class="py class"> <dt id="pysegcnn.core.layers.ConvBnReluUpsample"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.layers.</code><code class="sig-name descname">ConvBnReluUpsample</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#ConvBnReluUpsample"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.ConvBnReluUpsample" title="Permalink to this definition">¶</a></dt> -<dd><p>Block of convolution, batchnorm, relu and nearest neighbor upsampling.</p> -<dl class="field-list simple"> +<dd><p>Block of convolution, batchnorm, relu and nearest neighbor upsample.</p> +<dl class="py method"> +<dt id="pysegcnn.core.layers.ConvBnReluUpsample.__init__"> +<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#ConvBnReluUpsample.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.ConvBnReluUpsample.__init__" title="Permalink to this definition">¶</a></dt> +<dd><p>Initialize.</p> +<dl class="field-list"> <dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> +<dd class="field-odd"><dl> +<dt><strong>in_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of input channels.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>out_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of output channels.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> +</dd> +</dl> +</dd> +<dt class="field-even">Raises</dt> +<dd class="field-even"><dl class="simple"> +<dt>TypeError</dt><dd><p>Raised if <code class="xref py py-meth docutils literal notranslate"><span class="pre">layers()</span></code> method does +not return an instance of <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code>.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Define optional extra information about this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x, feature, indices, skip)</p></td> -<td><p>Forward pass of a decoder block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code>()</p></td> -<td><p>Sequence of convolution, batchnorm and relu layers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">upsample</span></code>(x, feature[, indices])</p></td> -<td><p>Nearest neighbor upsampling.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="pysegcnn.core.layers.ConvBnReluUpsample.__init__"> -<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#ConvBnReluUpsample.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.ConvBnReluUpsample.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> </dd></dl> <p class="rubric">Methods</p> @@ -306,7 +209,7 @@ </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.layers.ConvBnReluUpsample.__init__" title="pysegcnn.core.layers.ConvBnReluUpsample.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -437,6 +340,15 @@ </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.layers.EncoderBlock.html" class="btn btn-neutral float-right" title="pysegcnn.core.layers.EncoderBlock" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.layers.ConvBnReluMaxUnpool.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers.ConvBnReluMaxUnpool" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.Decoder.html b/docs/_build/html/source/generated/pysegcnn.core.layers.Decoder.html index 286b5ca0d9a0c8c74b1253e1459deb7168a39357..761c49f489f68b8851138a325bc468bbf796e155 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.Decoder.html +++ b/docs/_build/html/source/generated/pysegcnn.core.layers.Decoder.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.models.Network" href="pysegcnn.core.models.Network.html" /> + <link rel="prev" title="pysegcnn.core.layers.Encoder" href="pysegcnn.core.layers.Encoder.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,25 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="../api.html#layers">Layers</a></li> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a><ul class="current"> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.EncoderBlock.html">pysegcnn.core.layers.EncoderBlock</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.DecoderBlock.html">pysegcnn.core.layers.DecoderBlock</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Encoder.html">pysegcnn.core.layers.Encoder</a></li> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.layers.Decoder</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a></li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +147,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.layers.Decoder</li> @@ -156,149 +175,49 @@ <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.layers.</code><code class="sig-name descname">Decoder</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">filters</span></em>, <em class="sig-param"><span class="n">block</span></em>, <em class="sig-param"><span class="n">skip</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#Decoder"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.Decoder" title="Permalink to this definition">¶</a></dt> <dd><p>Generic convolutional decoder.</p> <p>When instanciating an encoder-decoder architechure, <code class="docutils literal notranslate"><span class="pre">filters</span></code> should be -the same for <cite>pysegcnn.core.layers.Encoder</cite> and -<cite>pysegcnn.core.layers.Decoder</cite>.</p> -<p>See <cite>pysegcnn.core.models.UNet</cite> for an example implementation.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>filters</strong> (<cite>list</cite> [<cite>int</cite>]) – List of input channels to each convolutional block. The length of -<code class="docutils literal notranslate"><span class="pre">filters</span></code> determines the depth of the decoder. The first element of -<code class="docutils literal notranslate"><span class="pre">filters</span></code> has to be the number of channels of the input images.</p></li> -<li><p><strong>block</strong> (<cite>pysegcnn.core.layers.DecoderBlock</cite>) – The convolutional block defining a layer in the decoder. -A subclass of <cite>pysegcnn.core.layers.DecoderBlock</cite>, e.g. -<cite>pysegcnn.core.layers.ConvBnReluMaxUnpool</cite>.</p></li> -<li><p><strong>skip</strong> (<cite>bool</cite>) – Whether to apply skip connections from the encoder to the decoder.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> +the same for <a class="reference internal" href="pysegcnn.core.layers.Encoder.html#pysegcnn.core.layers.Encoder" title="pysegcnn.core.layers.Encoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Encoder</span></code></a> and +<a class="reference internal" href="#pysegcnn.core.layers.Decoder" title="pysegcnn.core.layers.Decoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Decoder</span></code></a>.</p> +<p>See <a class="reference internal" href="pysegcnn.core.models.UNet.html#pysegcnn.core.models.UNet" title="pysegcnn.core.models.UNet"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.models.UNet</span></code></a> for an example implementation.</p> +<dl class="field-list"> +<dt class="field-odd">Attributes</dt> +<dd class="field-odd"><dl> +<dt><strong>features</strong><span class="classifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">numpy.ndarray</span></code></span></dt><dd><p>Input channels to each convolutional block, i.e. <code class="docutils literal notranslate"><span class="pre">filters</span></code>.</p> +</dd> +<dt><strong>block</strong><span class="classifier"><a class="reference internal" href="pysegcnn.core.layers.EncoderBlock.html#pysegcnn.core.layers.EncoderBlock" title="pysegcnn.core.layers.EncoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.EncoderBlock</span></code></a></span></dt><dd><p>The convolutional block defining a layer in the decoder. +A subclass of <a class="reference internal" href="pysegcnn.core.layers.EncoderBlock.html#pysegcnn.core.layers.EncoderBlock" title="pysegcnn.core.layers.EncoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.EncoderBlock</span></code></a>, e.g. +<a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxPool.html#pysegcnn.core.layers.ConvBnReluMaxPool" title="pysegcnn.core.layers.ConvBnReluMaxPool"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.ConvBnReluMaxPool</span></code></a>.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>skip</strong><span class="classifier"><cite>bool</cite></span></dt><dd><p>Whether to apply skip connections from the encoder to the decoder.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>layers</strong><span class="classifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.ModuleList</span></code></span></dt><dd><p>List of blocks in the decoder.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x, enc_cache)</p></td> -<td><p>Forward pass of the decoder.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> <dl class="py method"> <dt id="pysegcnn.core.layers.Decoder.__init__"> <code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">filters</span></em>, <em class="sig-param"><span class="n">block</span></em>, <em class="sig-param"><span class="n">skip</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#Decoder.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.Decoder.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> +<dd><p>Initialize.</p> +<dl class="field-list"> +<dt class="field-odd">Parameters</dt> +<dd class="field-odd"><dl> +<dt><strong>filters</strong><span class="classifier"><cite>list</cite> [<cite>int</cite>]</span></dt><dd><p>List of input channels to each convolutional block. The length of +<code class="docutils literal notranslate"><span class="pre">filters</span></code> determines the depth of the decoder. The first element +of <code class="docutils literal notranslate"><span class="pre">filters</span></code> has to be the number of channels of the input +images.</p> +</dd> +<dt><strong>block</strong><span class="classifier"><a class="reference internal" href="pysegcnn.core.layers.DecoderBlock.html#pysegcnn.core.layers.DecoderBlock" title="pysegcnn.core.layers.DecoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.DecoderBlock</span></code></a></span></dt><dd><p>The convolutional block defining a layer in the decoder. +A subclass of <a class="reference internal" href="pysegcnn.core.layers.DecoderBlock.html#pysegcnn.core.layers.DecoderBlock" title="pysegcnn.core.layers.DecoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.DecoderBlock</span></code></a>, e.g. +<a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxUnpool.html#pysegcnn.core.layers.ConvBnReluMaxUnpool" title="pysegcnn.core.layers.ConvBnReluMaxUnpool"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.ConvBnReluMaxUnpool</span></code></a>.</p> +</dd> +<dt><strong>skip</strong><span class="classifier"><cite>bool</cite>, optional</span></dt><dd><p>Whether to apply skip connections from the encoder to the decoder.</p> +</dd> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> +</dd> +</dl> +</dd> +</dl> </dd></dl> <p class="rubric">Methods</p> @@ -309,7 +228,7 @@ A subclass of <cite>pysegcnn.core.layers.DecoderBlock</cite>, e.g. </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.layers.Decoder.__init__" title="pysegcnn.core.layers.Decoder.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(filters, block[, skip])</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -434,6 +353,15 @@ A subclass of <cite>pysegcnn.core.layers.DecoderBlock</cite>, e.g. </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.models.Network.html" class="btn btn-neutral float-right" title="pysegcnn.core.models.Network" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.layers.Encoder.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers.Encoder" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.DecoderBlock.html b/docs/_build/html/source/generated/pysegcnn.core.layers.DecoderBlock.html index fa52e72eda7a7c3c46a1c65fc80776da7ca8b856..830aa5d909d6cc11ac9149025e5c0fe5750c5a6b 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.DecoderBlock.html +++ b/docs/_build/html/source/generated/pysegcnn.core.layers.DecoderBlock.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.layers.Encoder" href="pysegcnn.core.layers.Encoder.html" /> + <link rel="prev" title="pysegcnn.core.layers.EncoderBlock" href="pysegcnn.core.layers.EncoderBlock.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,25 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="../api.html#layers">Layers</a></li> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a><ul class="current"> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.EncoderBlock.html">pysegcnn.core.layers.EncoderBlock</a></li> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.layers.DecoderBlock</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Encoder.html">pysegcnn.core.layers.Encoder</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Decoder.html">pysegcnn.core.layers.Decoder</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a></li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +147,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.layers.DecoderBlock</li> @@ -155,147 +174,30 @@ <dt id="pysegcnn.core.layers.DecoderBlock"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.layers.</code><code class="sig-name descname">DecoderBlock</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#DecoderBlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.DecoderBlock" title="Permalink to this definition">¶</a></dt> <dd><p>Block of a convolutional decoder.</p> -<dl class="field-list simple"> +<dl class="py method"> +<dt id="pysegcnn.core.layers.DecoderBlock.__init__"> +<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#DecoderBlock.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.DecoderBlock.__init__" title="Permalink to this definition">¶</a></dt> +<dd><p>Initialize.</p> +<dl class="field-list"> <dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> +<dd class="field-odd"><dl> +<dt><strong>in_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of input channels.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>out_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of output channels.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> +</dd> +</dl> +</dd> +<dt class="field-even">Raises</dt> +<dd class="field-even"><dl class="simple"> +<dt>TypeError</dt><dd><p>Raised if <code class="xref py py-meth docutils literal notranslate"><span class="pre">layers()</span></code> method does +not return an instance of <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code>.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x, feature, indices, skip)</p></td> -<td><p>Forward pass of a decoder block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code>()</p></td> -<td><p>Define the layers of the block.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">upsample</span></code>(x, feature, indices)</p></td> -<td><p>Define the upsampling method.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="pysegcnn.core.layers.DecoderBlock.__init__"> -<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#DecoderBlock.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.DecoderBlock.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> </dd></dl> <p class="rubric">Methods</p> @@ -306,7 +208,7 @@ </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.layers.DecoderBlock.__init__" title="pysegcnn.core.layers.DecoderBlock.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -437,6 +339,15 @@ </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.layers.Encoder.html" class="btn btn-neutral float-right" title="pysegcnn.core.layers.Encoder" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.layers.EncoderBlock.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers.EncoderBlock" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.Encoder.html b/docs/_build/html/source/generated/pysegcnn.core.layers.Encoder.html index fbc6521dd990ec09f97450ecf577d3c43672e8ce..ebc77d2b75706b774a48d7e646c2ba557eed174b 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.Encoder.html +++ b/docs/_build/html/source/generated/pysegcnn.core.layers.Encoder.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.layers.Decoder" href="pysegcnn.core.layers.Decoder.html" /> + <link rel="prev" title="pysegcnn.core.layers.DecoderBlock" href="pysegcnn.core.layers.DecoderBlock.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,25 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="../api.html#layers">Layers</a></li> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a><ul class="current"> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.EncoderBlock.html">pysegcnn.core.layers.EncoderBlock</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.DecoderBlock.html">pysegcnn.core.layers.DecoderBlock</a></li> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.layers.Encoder</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Decoder.html">pysegcnn.core.layers.Decoder</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a></li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +147,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.layers.Encoder</li> @@ -156,148 +175,56 @@ <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.layers.</code><code class="sig-name descname">Encoder</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">filters</span></em>, <em class="sig-param"><span class="n">block</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#Encoder"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.Encoder" title="Permalink to this definition">¶</a></dt> <dd><p>Generic convolutional encoder.</p> <p>When instanciating an encoder-decoder architechure, <code class="docutils literal notranslate"><span class="pre">filters</span></code> should be -the same for <cite>pysegcnn.core.layers.Encoder</cite> and -<cite>pysegcnn.core.layers.Decoder</cite>.</p> -<p>See <cite>pysegcnn.core.models.UNet</cite> for an example implementation.</p> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>filters</strong> (<cite>list</cite> [<cite>int</cite>]) – List of input channels to each convolutional block. The length of -<code class="docutils literal notranslate"><span class="pre">filters</span></code> determines the depth of the encoder. The first element of -<code class="docutils literal notranslate"><span class="pre">filters</span></code> has to be the number of channels of the input images.</p></li> -<li><p><strong>block</strong> (<cite>pysegcnn.core.layers.EncoderBlock</cite>) – The convolutional block defining a layer in the encoder. -A subclass of <cite>pysegcnn.core.layers.EncoderBlock</cite>, e.g. -<cite>pysegcnn.core.layers.ConvBnReluMaxPool</cite>.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> +the same for <a class="reference internal" href="#pysegcnn.core.layers.Encoder" title="pysegcnn.core.layers.Encoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Encoder</span></code></a> and +<a class="reference internal" href="pysegcnn.core.layers.Decoder.html#pysegcnn.core.layers.Decoder" title="pysegcnn.core.layers.Decoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Decoder</span></code></a>.</p> +<p>See <a class="reference internal" href="pysegcnn.core.models.UNet.html#pysegcnn.core.models.UNet" title="pysegcnn.core.models.UNet"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.models.UNet</span></code></a> for an example implementation.</p> +<dl class="field-list"> +<dt class="field-odd">Attributes</dt> +<dd class="field-odd"><dl> +<dt><strong>features</strong><span class="classifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">numpy.ndarray</span></code></span></dt><dd><p>Input channels to each convolutional block, i.e. <code class="docutils literal notranslate"><span class="pre">filters</span></code>.</p> +</dd> +<dt><strong>block</strong><span class="classifier"><a class="reference internal" href="pysegcnn.core.layers.EncoderBlock.html#pysegcnn.core.layers.EncoderBlock" title="pysegcnn.core.layers.EncoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.EncoderBlock</span></code></a></span></dt><dd><p>The convolutional block defining a layer in the encoder. +A subclass of <a class="reference internal" href="pysegcnn.core.layers.EncoderBlock.html#pysegcnn.core.layers.EncoderBlock" title="pysegcnn.core.layers.EncoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.EncoderBlock</span></code></a>, e.g. +<a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxPool.html#pysegcnn.core.layers.ConvBnReluMaxPool" title="pysegcnn.core.layers.ConvBnReluMaxPool"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.ConvBnReluMaxPool</span></code></a>.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>layers</strong><span class="classifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.ModuleList</span></code></span></dt><dd><p>List of blocks in the encoder.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>cache</strong><span class="classifier"><cite>dict</cite></span></dt><dd><dl class="simple"> +<dt>Intermediate encoder outputs. Dictionary with keys:</dt><dd><dl class="simple"> +<dt><code class="docutils literal notranslate"><span class="pre">'feature'</span></code></dt><dd><p>The intermediate encoder outputs (<code class="xref py py-class docutils literal notranslate"><span class="pre">torch.Tensor</span></code>).</p> +</dd> +<dt><code class="docutils literal notranslate"><span class="pre">'indices'</span></code></dt><dd><p>The indices of the max pooling layer, if required +(<code class="xref py py-class docutils literal notranslate"><span class="pre">torch.Tensor</span></code>).</p> +</dd> +</dl> +</dd> +</dl> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x)</p></td> -<td><p>Forward pass of the encoder.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> <dl class="py method"> <dt id="pysegcnn.core.layers.Encoder.__init__"> <code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">filters</span></em>, <em class="sig-param"><span class="n">block</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#Encoder.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.Encoder.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> +<dd><p>Initialize.</p> +<dl class="field-list"> +<dt class="field-odd">Parameters</dt> +<dd class="field-odd"><dl> +<dt><strong>filters</strong><span class="classifier"><cite>list</cite> [<cite>int</cite>]</span></dt><dd><p>List of input channels to each convolutional block. The length of +<code class="docutils literal notranslate"><span class="pre">filters</span></code> determines the depth of the encoder. The first element +of <code class="docutils literal notranslate"><span class="pre">filters</span></code> has to be the number of channels of the input +images.</p> +</dd> +<dt><strong>block</strong><span class="classifier"><a class="reference internal" href="pysegcnn.core.layers.EncoderBlock.html#pysegcnn.core.layers.EncoderBlock" title="pysegcnn.core.layers.EncoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.EncoderBlock</span></code></a></span></dt><dd><p>The convolutional block defining a layer in the encoder. +A subclass of <a class="reference internal" href="pysegcnn.core.layers.EncoderBlock.html#pysegcnn.core.layers.EncoderBlock" title="pysegcnn.core.layers.EncoderBlock"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.EncoderBlock</span></code></a>, e.g. +<a class="reference internal" href="pysegcnn.core.layers.ConvBnReluMaxPool.html#pysegcnn.core.layers.ConvBnReluMaxPool" title="pysegcnn.core.layers.ConvBnReluMaxPool"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.ConvBnReluMaxPool</span></code></a>.</p> +</dd> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> +</dd> +</dl> +</dd> +</dl> </dd></dl> <p class="rubric">Methods</p> @@ -308,7 +235,7 @@ A subclass of <cite>pysegcnn.core.layers.EncoderBlock</cite>, e.g. </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.layers.Encoder.__init__" title="pysegcnn.core.layers.Encoder.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(filters, block, **kwargs)</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -433,6 +360,15 @@ A subclass of <cite>pysegcnn.core.layers.EncoderBlock</cite>, e.g. </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.layers.Decoder.html" class="btn btn-neutral float-right" title="pysegcnn.core.layers.Decoder" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.layers.DecoderBlock.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers.DecoderBlock" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.EncoderBlock.html b/docs/_build/html/source/generated/pysegcnn.core.layers.EncoderBlock.html index c41607a518f10ae7ad99df71739fae5a3efd3c27..8fb1f3d14550274f6d6d625211b6ced37438a236 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.EncoderBlock.html +++ b/docs/_build/html/source/generated/pysegcnn.core.layers.EncoderBlock.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.layers.DecoderBlock" href="pysegcnn.core.layers.DecoderBlock.html" /> + <link rel="prev" title="pysegcnn.core.layers.ConvBnReluUpsample" href="pysegcnn.core.layers.ConvBnReluUpsample.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,25 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="../api.html#layers">Layers</a></li> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a><ul class="current"> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.layers.EncoderBlock</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.DecoderBlock.html">pysegcnn.core.layers.DecoderBlock</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Encoder.html">pysegcnn.core.layers.Encoder</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.layers.Decoder.html">pysegcnn.core.layers.Decoder</a></li> +</ul> +</li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a></li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +147,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.layers.EncoderBlock</li> @@ -155,147 +174,30 @@ <dt id="pysegcnn.core.layers.EncoderBlock"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.layers.</code><code class="sig-name descname">EncoderBlock</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#EncoderBlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.EncoderBlock" title="Permalink to this definition">¶</a></dt> <dd><p>Block of a convolutional encoder.</p> -<dl class="field-list simple"> +<dl class="py method"> +<dt id="pysegcnn.core.layers.EncoderBlock.__init__"> +<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#EncoderBlock.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.EncoderBlock.__init__" title="Permalink to this definition">¶</a></dt> +<dd><p>Initialize.</p> +<dl class="field-list"> <dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of input channels.</p></li> -<li><p><strong>out_channels</strong> (<cite>int</cite>) – Number of output channels.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional arguments passed to <cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> +<dd class="field-odd"><dl> +<dt><strong>in_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of input channels.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>out_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of output channels.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> +</dd> +</dl> +</dd> +<dt class="field-even">Raises</dt> +<dd class="field-even"><dl class="simple"> +<dt>TypeError</dt><dd><p>Raised if <code class="xref py py-meth docutils literal notranslate"><span class="pre">layers()</span></code> method does +not return an instance of <code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code>.</p> +</dd> +</dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">downsample</span></code>(x)</p></td> -<td><p>Define the downsampling method.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x)</p></td> -<td><p>Forward pass of an encoder block.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">layers</span></code>()</p></td> -<td><p>Define the layers of the block.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> -<dl class="py method"> -<dt id="pysegcnn.core.layers.EncoderBlock.__init__"> -<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">out_channels</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/layers.html#EncoderBlock.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.layers.EncoderBlock.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> </dd></dl> <p class="rubric">Methods</p> @@ -306,7 +208,7 @@ </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.layers.EncoderBlock.__init__" title="pysegcnn.core.layers.EncoderBlock.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -437,6 +339,15 @@ </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.layers.DecoderBlock.html" class="btn btn-neutral float-right" title="pysegcnn.core.layers.DecoderBlock" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.layers.ConvBnReluUpsample.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers.ConvBnReluUpsample" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.layers.html b/docs/_build/html/source/generated/pysegcnn.core.layers.html deleted file mode 100644 index 5f954e54df2408834d52277904eab6e20c00ff52..0000000000000000000000000000000000000000 --- a/docs/_build/html/source/generated/pysegcnn.core.layers.html +++ /dev/null @@ -1,283 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>pysegcnn.core.layers — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" 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="pysegcnn.core.models" href="pysegcnn.core.models.html" /> - <link rel="prev" title="API Reference" href="../api.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul class="current"> -<li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> -<li class="toctree-l2 current"><a class="reference internal" href="../api.html#layers-and-models">Layers and Models</a><ul class="current"> -<li class="toctree-l3 current"><a class="current reference internal" href="#">pysegcnn.core.layers</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#license">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="pysegcnn.core.models.html">pysegcnn.core.models</a></li> -</ul> -</li> -</ul> -</li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../api.html">API Reference</a> »</li> - - <li>pysegcnn.core.layers</li> - - - <li class="wy-breadcrumbs-aside"> - - - <a href="../../_sources/source/generated/pysegcnn.core.layers.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"> - - <div class="section" id="module-pysegcnn.core.layers"> -<span id="pysegcnn-core-layers"></span><h1>pysegcnn.core.layers<a class="headerlink" href="#module-pysegcnn.core.layers" title="Permalink to this headline">¶</a></h1> -<p>Layers of a convolutional encoder-decoder network.</p> -<div class="section" id="license"> -<h2>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h2> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<p class="rubric">Functions</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">conv_bn_relu</span></code>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Block of convolution, batch normalization and rectified linear unit.</p></td> -</tr> -</tbody> -</table> -<p class="rubric">Classes</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Block</span></code>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Basic convolutional block.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Conv2dSame</span></code>(*args, **kwargs)</p></td> -<td><p>A convolution preserving the shape of its input.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">ConvBnReluMaxPool</span></code>(in_channels, out_channels, …)</p></td> -<td><p>Block of convolution, batchnorm, relu and 2x2 max pool.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">ConvBnReluMaxUnpool</span></code>(in_channels, …)</p></td> -<td><p>Block of convolution, batchnorm, relu and 2x2 max unpool.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">ConvBnReluUpsample</span></code>(in_channels, …)</p></td> -<td><p>Block of convolution, batchnorm, relu and nearest neighbor upsampling.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Decoder</span></code>(filters, block[, skip])</p></td> -<td><p>Generic convolutional decoder.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">DecoderBlock</span></code>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Block of a convolutional decoder.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Encoder</span></code>(filters, block, **kwargs)</p></td> -<td><p>Generic convolutional encoder.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">EncoderBlock</span></code>(in_channels, out_channels, **kwargs)</p></td> -<td><p>Block of a convolutional encoder.</p></td> -</tr> -</tbody> -</table> -</div> -</div> - - - </div> - - </div> - <footer> - - <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - - <a href="pysegcnn.core.models.html" class="btn btn-neutral float-right" title="pysegcnn.core.models" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> - - - <a href="../api.html" class="btn btn-neutral float-left" title="API Reference" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> - - </div> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/source/generated/pysegcnn.core.models.Network.html b/docs/_build/html/source/generated/pysegcnn.core.models.Network.html index 1147eae92a395b1a5d42f77e52f5004efe4ac674..d5fb8006a7f6568df408341c98e6817d356a4dbf 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.models.Network.html +++ b/docs/_build/html/source/generated/pysegcnn.core.models.Network.html @@ -35,7 +35,9 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="next" title="pysegcnn.core.models.UNet" href="pysegcnn.core.models.UNet.html" /> + <link rel="prev" title="pysegcnn.core.layers.Decoder" href="pysegcnn.core.layers.Decoder.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +82,23 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="../api.html#layers">Layers</a></li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a></li> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a><ul class="current"> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.models.Network</a></li> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.models.UNet.html">pysegcnn.core.models.UNet</a></li> +</ul> +</li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +145,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.models.Network</li> @@ -156,153 +173,19 @@ <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.models.</code><code class="sig-name descname">Network</code><a class="reference internal" href="../../_modules/pysegcnn/core/models.html#Network"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.models.Network" title="Permalink to this definition">¶</a></dt> <dd><p>Generic Network class.</p> <p>The base class for each model. If you want to implement a new model, -inherit the <code class="docutils literal notranslate"><span class="pre">~pysegcnn.core.models.Network</span></code> class.</p> -<dl class="field-list simple"> -<dt class="field-odd">Returns</dt> -<dd class="field-odd"><p></p> -</dd> -<dt class="field-even">Return type</dt> -<dd class="field-even"><p>None.</p> -</dd> +inherit the <a class="reference internal" href="#pysegcnn.core.models.Network" title="pysegcnn.core.models.Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.models.Network</span></code></a> class.</p> +<dl class="field-list"> <dt class="field-odd">Attributes</dt> -<dd class="field-odd"><dl class="simple"> -<dt><code class="xref py py-obj docutils literal notranslate"><span class="pre">state</span></code></dt><dd><p>Return the model state file.</p> +<dd class="field-odd"><dl> +<dt><strong>state_file</strong><span class="classifier"><cite>str</cite> or <cite>None</cite> or <code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></span></dt><dd><p>The model state file, where the model parameters are saved.</p> </dd> </dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(*input)</p></td> -<td><p></p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">freeze</span></code>()</p></td> -<td><p>Freeze the weights of a model.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load</span></code>(state_file)</p></td> -<td><p>Load a model state.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">save</span></code>(state_file, optimizer[, bands])</p></td> -<td><p>Save the model state.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">unfreeze</span></code>()</p></td> -<td><p>Unfreeze the weights of a model.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> <dl class="py method"> <dt id="pysegcnn.core.models.Network.__init__"> <code class="sig-name descname">__init__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/models.html#Network.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.models.Network.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> +<dd><p>Initialize.</p> </dd></dl> <p class="rubric">Methods</p> @@ -313,7 +196,7 @@ inherit the <code class="docutils literal notranslate"><span class="pre">~pysegc </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.models.Network.__init__" title="pysegcnn.core.models.Network.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>()</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -453,6 +336,15 @@ inherit the <code class="docutils literal notranslate"><span class="pre">~pysegc </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + <a href="pysegcnn.core.models.UNet.html" class="btn btn-neutral float-right" title="pysegcnn.core.models.UNet" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + + + <a href="pysegcnn.core.layers.Decoder.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers.Decoder" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.models.UNet.html b/docs/_build/html/source/generated/pysegcnn.core.models.UNet.html index b276d7b9a83f8b8fa17bf0168951c86df3fb5a31..2a81325512b299c21c9b09a50b54c815b6461aa9 100644 --- a/docs/_build/html/source/generated/pysegcnn.core.models.UNet.html +++ b/docs/_build/html/source/generated/pysegcnn.core.models.UNet.html @@ -35,7 +35,8 @@ <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="prev" title="pysegcnn.core.models.Network" href="pysegcnn.core.models.Network.html" /> </head> <body class="wy-body-for-nav"> @@ -80,10 +81,23 @@ - <ul> + <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="../api.html#dataset">Dataset</a></li> +<li class="toctree-l2 current"><a class="reference internal" href="../api.html#models">Models</a><ul class="current"> +<li class="toctree-l3"><a class="reference internal" href="../api.html#layers">Layers</a></li> +<li class="toctree-l3"><a class="reference internal" href="../api.html#encoder-decoder-architechture">Encoder-Decoder architechture</a></li> +<li class="toctree-l3 current"><a class="reference internal" href="../api.html#neural-networks">Neural Networks</a><ul class="current"> +<li class="toctree-l4"><a class="reference internal" href="pysegcnn.core.models.Network.html">pysegcnn.core.models.Network</a></li> +<li class="toctree-l4 current"><a class="current reference internal" href="#">pysegcnn.core.models.UNet</a></li> +</ul> +</li> +</ul> +</li> +</ul> +</li> </ul> @@ -130,6 +144,8 @@ <li><a href="../../index.html" class="icon icon-home"></a> »</li> + <li><a href="../api.html">API Reference</a> »</li> + <li>pysegcnn.core.models.UNet</li> @@ -154,170 +170,60 @@ <dl class="py class"> <dt id="pysegcnn.core.models.UNet"> <em class="property">class </em><code class="sig-prename descclassname">pysegcnn.core.models.</code><code class="sig-name descname">UNet</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">nclasses</span></em>, <em class="sig-param"><span class="n">filters</span></em>, <em class="sig-param"><span class="n">skip</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/models.html#UNet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.models.UNet" title="Permalink to this definition">¶</a></dt> -<dd><p>A PyTorch implementation of <a class="reference external" href="https://arxiv.org/abs/1505.04597">U-Net</a>.</p> -<dl class="simple"> -<dt>Slightly modified version of U-Net:</dt><dd><ul class="simple"> -<li><p>each convolution is followed by a batch normalization layer</p></li> -<li><p>the upsampling is implemented by a 2x2 max unpooling operation</p></li> +<dd><p>A slightly modified implementation of <a class="reference external" href="https://arxiv.org/abs/1505.04597">U-Net</a> in PyTorch.</p> +<div class="admonition important"> +<p class="admonition-title">Important</p> +<ul class="simple"> +<li><p>Each convolution is followed by a batch normalization layer</p></li> +<li><p>Upsampling is implemented by a 2x2 max unpooling operation</p></li> </ul> +</div> +<dl class="field-list"> +<dt class="field-odd">Attributes</dt> +<dd class="field-odd"><dl> +<dt><strong>in_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of channels of the input images.</p> </dd> -</dl> -<dl class="field-list simple"> -<dt class="field-odd">Parameters</dt> -<dd class="field-odd"><ul class="simple"> -<li><p><strong>in_channels</strong> (<cite>int</cite>) – Number of channels of the input images.</p></li> -<li><p><strong>nclasses</strong> (<cite>int</cite>) – Number of classes.</p></li> -<li><p><strong>filters</strong> (<cite>list</cite> [<cite>int</cite>]) – List of input channels to each convolutional block.</p></li> -<li><p><strong>skip</strong> (<cite>bool</cite>) – Whether to apply skip connections from the encoder to the decoder.</p></li> -<li><p><strong>**kwargs</strong> (‘dict’ [<cite>str</cite>]) – Additional keyword arguments passed to -<cite>pysegcnn.core.layers.Conv2dSame</cite>.</p></li> -</ul> +<dt><strong>nclasses</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of classes.</p> </dd> -<dt class="field-even">Returns</dt> -<dd class="field-even"><p></p> +<dt><strong>kwargs</strong><span class="classifier"><cite>dict</cite> [<cite>str</cite>]</span></dt><dd><p>Additional keyword arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> </dd> -<dt class="field-odd">Return type</dt> -<dd class="field-odd"><p>None.</p> +<dt><strong>nfilters</strong><span class="classifier"><cite>list</cite> [<cite>int</cite>]</span></dt><dd><p>List of input channels to each convolutional block.</p> </dd> -<dt class="field-even">Attributes</dt> -<dd class="field-even"><dl class="simple"> -<dt><code class="xref py py-obj docutils literal notranslate"><span class="pre">state</span></code></dt><dd><p>Return the model state file.</p> +<dt><strong>skip</strong><span class="classifier"><cite>bool</cite></span></dt><dd><p>Whether to apply skip connections from the encoder to the decoder.</p> +</dd> +<dt><strong>epoch</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of epochs the model was trained.</p> +</dd> +<dt><strong>encoder</strong><span class="classifier"><a class="reference internal" href="pysegcnn.core.layers.Encoder.html#pysegcnn.core.layers.Encoder" title="pysegcnn.core.layers.Encoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Encoder</span></code></a></span></dt><dd><p>The convolutional encoder.</p> +</dd> +<dt><strong>decoder</strong><span class="classifier"><a class="reference internal" href="pysegcnn.core.layers.Decoder.html#pysegcnn.core.layers.Decoder" title="pysegcnn.core.layers.Decoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Decoder</span></code></a></span></dt><dd><p>The convolutional decoder.</p> +</dd> +<dt><strong>classifier</strong><span class="classifier"><a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a></span></dt><dd><p>The classification layer, a 1x1 convolution.</p> </dd> </dl> </dd> </dl> -<p class="rubric">Methods</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> -<td><p>Adds a child module to the current module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">apply</span></code>(fn)</p></td> -<td><p>Applies <code class="docutils literal notranslate"><span class="pre">fn</span></code> recursively to every submodule (as returned by <code class="docutils literal notranslate"><span class="pre">.children()</span></code>) as well as self.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">bfloat16</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">bfloat16</span></code> datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">buffers</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module buffers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cpu</span></code>()</p></td> -<td><p>Moves all model parameters and buffers to the CPU.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">cuda</span></code>([device])</p></td> -<td><p>Moves all model parameters and buffers to the GPU.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">double</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">double</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">eval</span></code>()</p></td> -<td><p>Sets the module in evaluation mode.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">extra_repr</span></code>()</p></td> -<td><p>Set the extra representation of the module</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to float datatype.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">forward</span></code>(x)</p></td> -<td><p>Forward propagation of U-Net.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">freeze</span></code>()</p></td> -<td><p>Freeze the weights of a model.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">half</span></code>()</p></td> -<td><p>Casts all floating point parameters and buffers to <code class="docutils literal notranslate"><span class="pre">half</span></code> datatype.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load</span></code>(state_file)</p></td> -<td><p>Load a model state.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">load_state_dict</span></code>(state_dict[, strict])</p></td> -<td><p>Copies parameters and buffers from <code class="xref py py-attr docutils literal notranslate"><span class="pre">state_dict</span></code> into this module and its descendants.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">modules</span></code>()</p></td> -<td><p>Returns an iterator over all modules in the network.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_buffers</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_children</span></code>()</p></td> -<td><p>Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_modules</span></code>([memo, prefix])</p></td> -<td><p>Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">named_parameters</span></code>([prefix, recurse])</p></td> -<td><p>Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">parameters</span></code>([recurse])</p></td> -<td><p>Returns an iterator over module parameters.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_backward_hook</span></code>(hook)</p></td> -<td><p>Registers a backward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_buffer</span></code>(name, tensor[, persistent])</p></td> -<td><p>Adds a buffer to the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_hook</span></code>(hook)</p></td> -<td><p>Registers a forward hook on the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_forward_pre_hook</span></code>(hook)</p></td> -<td><p>Registers a forward pre-hook on the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">register_parameter</span></code>(name, param)</p></td> -<td><p>Adds a parameter to the module.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">requires_grad_</span></code>([requires_grad])</p></td> -<td><p>Change if autograd should record operations on parameters in this module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">save</span></code>(state_file, optimizer[, bands])</p></td> -<td><p>Save the model state.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">state_dict</span></code>([destination, prefix, keep_vars])</p></td> -<td><p>Returns a dictionary containing a whole state of the module.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">to</span></code>(*args, **kwargs)</p></td> -<td><p>Moves and/or casts the parameters and buffers.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">train</span></code>([mode])</p></td> -<td><p>Sets the module in training mode.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code>(dst_type)</p></td> -<td><p>Casts all parameters and buffers to <code class="xref py py-attr docutils literal notranslate"><span class="pre">dst_type</span></code>.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">unfreeze</span></code>()</p></td> -<td><p>Unfreeze the weights of a model.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">zero_grad</span></code>()</p></td> -<td><p>Sets gradients of all model parameters to zero.</p></td> -</tr> -</tbody> -</table> -<table class="docutils align-default"> -<colgroup> -<col style="width: 62%" /> -<col style="width: 38%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><strong>__call__</strong></p></td> -<td></td> -</tr> -<tr class="row-even"><td><p><strong>share_memory</strong></p></td> -<td></td> -</tr> -</tbody> -</table> <dl class="py method"> <dt id="pysegcnn.core.models.UNet.__init__"> <code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">in_channels</span></em>, <em class="sig-param"><span class="n">nclasses</span></em>, <em class="sig-param"><span class="n">filters</span></em>, <em class="sig-param"><span class="n">skip</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pysegcnn/core/models.html#UNet.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pysegcnn.core.models.UNet.__init__" title="Permalink to this definition">¶</a></dt> -<dd><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p> +<dd><p>Initialize.</p> +<dl class="field-list"> +<dt class="field-odd">Parameters</dt> +<dd class="field-odd"><dl> +<dt><strong>in_channels</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of channels of the input images.</p> +</dd> +<dt><strong>nclasses</strong><span class="classifier"><cite>int</cite></span></dt><dd><p>Number of classes.</p> +</dd> +<dt><strong>filters</strong><span class="classifier"><cite>list</cite> [<cite>int</cite>]</span></dt><dd><p>List of input channels to each convolutional block.</p> +</dd> +<dt><strong>skip</strong><span class="classifier"><cite>bool</cite></span></dt><dd><p>Whether to apply skip connections from the encoder to the decoder.</p> +</dd> +<dt><strong>**kwargs: `dict` [`str`]</strong></dt><dd><p>Additional keyword arguments passed to +<a class="reference internal" href="pysegcnn.core.layers.Conv2dSame.html#pysegcnn.core.layers.Conv2dSame" title="pysegcnn.core.layers.Conv2dSame"><code class="xref py py-class docutils literal notranslate"><span class="pre">pysegcnn.core.layers.Conv2dSame</span></code></a>.</p> +</dd> +</dl> +</dd> +</dl> </dd></dl> <p class="rubric">Methods</p> @@ -328,7 +234,7 @@ </colgroup> <tbody> <tr class="row-odd"><td><p><a class="reference internal" href="#pysegcnn.core.models.UNet.__init__" title="pysegcnn.core.models.UNet.__init__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__init__</span></code></a>(in_channels, nclasses, filters, …)</p></td> -<td><p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></td> +<td><p>Initialize.</p></td> </tr> <tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_module</span></code>(name, module)</p></td> <td><p>Adds a child module to the current module.</p></td> @@ -468,6 +374,13 @@ </div> <footer> + <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + + + <a href="pysegcnn.core.models.Network.html" class="btn btn-neutral float-left" title="pysegcnn.core.models.Network" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> + + </div> + <hr/> diff --git a/docs/_build/html/source/generated/pysegcnn.core.models.html b/docs/_build/html/source/generated/pysegcnn.core.models.html deleted file mode 100644 index 0c44e06266cbcbee8bbd512adf0045d4685ae8b1..0000000000000000000000000000000000000000 --- a/docs/_build/html/source/generated/pysegcnn.core.models.html +++ /dev/null @@ -1,256 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>pysegcnn.core.models — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> - <script src="../../_static/jquery.js"></script> - <script src="../../_static/underscore.js"></script> - <script src="../../_static/doctools.js"></script> - <script src="../../_static/language_data.js"></script> - - <script type="text/javascript" src="../../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../../genindex.html" /> - <link rel="search" title="Search" href="../../search.html" /> - <link rel="prev" title="pysegcnn.core.layers" href="pysegcnn.core.layers.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" > - - - - <a href="../../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul class="current"> -<li class="toctree-l1"><a class="reference internal" href="../requirements.html">Requirements</a></li> -<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> -<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current"> -<li class="toctree-l2 current"><a class="reference internal" href="../api.html#layers-and-models">Layers and Models</a><ul class="current"> -<li class="toctree-l3"><a class="reference internal" href="pysegcnn.core.layers.html">pysegcnn.core.layers</a></li> -<li class="toctree-l3 current"><a class="current reference internal" href="#">pysegcnn.core.models</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#license">License</a></li> -</ul> -</li> -</ul> -</li> -</ul> -</li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../../index.html" class="icon icon-home"></a> »</li> - - <li><a href="../api.html">API Reference</a> »</li> - - <li>pysegcnn.core.models</li> - - - <li class="wy-breadcrumbs-aside"> - - - <a href="../../_sources/source/generated/pysegcnn.core.models.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"> - - <div class="section" id="module-pysegcnn.core.models"> -<span id="pysegcnn-core-models"></span><h1>pysegcnn.core.models<a class="headerlink" href="#module-pysegcnn.core.models" title="Permalink to this headline">¶</a></h1> -<p>Neural networks for semantic image segmentation.</p> -<div class="section" id="license"> -<h2>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h2> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -<p class="rubric">Classes</p> -<table class="longtable docutils align-default"> -<colgroup> -<col style="width: 10%" /> -<col style="width: 90%" /> -</colgroup> -<tbody> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">Network</span></code>()</p></td> -<td><p>Generic Network class.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">SupportedLossFunctions</span></code>(value)</p></td> -<td><p>Names and corresponding classes of the tested loss functions.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">SupportedModels</span></code>(value)</p></td> -<td><p>Names and corresponding classes of the implemented models.</p></td> -</tr> -<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">SupportedOptimizers</span></code>(value)</p></td> -<td><p>Names and corresponding classes of the tested optimizers.</p></td> -</tr> -<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">UNet</span></code>(in_channels, nclasses, filters, skip, …)</p></td> -<td><p>A PyTorch implementation of <a href="#id1"><span class="problematic" id="id2">`U-Net`_</span></a>.</p></td> -</tr> -</tbody> -</table> -</div> -</div> - - - </div> - - </div> - <footer> - - <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - - - <a href="pysegcnn.core.layers.html" class="btn btn-neutral float-left" title="pysegcnn.core.layers" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> - - </div> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/source/install.html b/docs/_build/html/source/install.html deleted file mode 100644 index 51ec939aa1bdad0857ae4c7ba63521003d8da231..0000000000000000000000000000000000000000 --- a/docs/_build/html/source/install.html +++ /dev/null @@ -1,278 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>Installation — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> - <script src="../_static/jquery.js"></script> - <script src="../_static/underscore.js"></script> - <script src="../_static/doctools.js"></script> - <script src="../_static/language_data.js"></script> - - <script type="text/javascript" src="../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../genindex.html" /> - <link rel="search" title="Search" href="../search.html" /> - <link rel="prev" title="PySegCNN: Image segmentation with convolutional neural networks in Python" href="../index.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" > - - - - <a href="../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul class="current"> -<li class="toctree-l1 current"><a class="current reference internal" href="#">Installation</a><ul> -<li class="toctree-l2"><a class="reference internal" href="#download">Download</a></li> -<li class="toctree-l2"><a class="reference internal" href="#conda">Conda</a></li> -<li class="toctree-l2"><a class="reference internal" href="#conda-environments">Conda environments</a></li> -<li class="toctree-l2"><a class="reference internal" href="#install-pytorch">Install PyTorch</a></li> -<li class="toctree-l2"><a class="reference internal" href="#install-pysegcnn">Install PySegCNN</a></li> -</ul> -</li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../index.html" class="icon icon-home"></a> »</li> - - <li>Installation</li> - - - <li class="wy-breadcrumbs-aside"> - - - <a href="../_sources/source/install.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"> - - <div class="section" id="installation"> -<h1>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h1> -<div class="section" id="download"> -<h2>Download<a class="headerlink" href="#download" title="Permalink to this headline">¶</a></h2> -<p>You can download <code class="docutils literal notranslate"><span class="pre">pysegcnn</span></code> from this repository’s -<a class="reference external" href="https://gitlab.inf.unibz.it/REMSEN/ccisnow/pysegcnn">website</a> -or alternatively use <code class="docutils literal notranslate"><span class="pre">git</span></code> from terminal:</p> -<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>git clone https://gitlab.inf.unibz.it/REMSEN/ccisnow/pysegcnn.git -</pre></div> -</div> -<p>This creates a copy of the repository in your current directory on the file -system.</p> -</div> -<div class="section" id="conda"> -<h2>Conda<a class="headerlink" href="#conda" title="Permalink to this headline">¶</a></h2> -<p>To install <code class="docutils literal notranslate"><span class="pre">pysegcnn</span></code>, I recommend to use the <code class="docutils literal notranslate"><span class="pre">conda</span></code> package manager. -You can download <code class="docutils literal notranslate"><span class="pre">conda</span></code> <a class="reference external" href="https://docs.conda.io/en/latest/miniconda.html">here</a>. -Once successfully installed <code class="docutils literal notranslate"><span class="pre">conda</span></code>, I recommend to add <code class="docutils literal notranslate"><span class="pre">conda-forge</span></code> as -your default channel:</p> -<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>conda config --add channels conda-forge -</pre></div> -</div> -</div> -<div class="section" id="conda-environments"> -<h2>Conda environments<a class="headerlink" href="#conda-environments" title="Permalink to this headline">¶</a></h2> -<p>To install <code class="docutils literal notranslate"><span class="pre">pysegcnn</span></code>, I recommend to create a specific <code class="docutils literal notranslate"><span class="pre">conda</span></code> -<a class="reference external" href="https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html">environment</a>, -by using the provided <code class="docutils literal notranslate"><span class="pre">environment.yml</span></code> file. In a terminal, navigate to the -<strong>cloned git repositories root directory</strong> (<code class="docutils literal notranslate"><span class="pre">/pysegcnn</span></code>) and type:</p> -<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>conda env create -f environment.yml -</pre></div> -</div> -<p>This may take a while. The above command creates a conda environment with all -required dependencies except the <code class="docutils literal notranslate"><span class="pre">pytorch</span></code> package. The first line in -<code class="docutils literal notranslate"><span class="pre">environment.yml</span></code> defines the environment name, in this case <code class="docutils literal notranslate"><span class="pre">pysegcnn</span></code>. -Activate your environment using:</p> -<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>conda activate pysegcnn -</pre></div> -</div> -</div> -<div class="section" id="install-pytorch"> -<h2>Install PyTorch<a class="headerlink" href="#install-pytorch" title="Permalink to this headline">¶</a></h2> -<p>The installation of <code class="docutils literal notranslate"><span class="pre">pytorch</span></code> is heavily dependent on the hardware of your -machine. Therefore, after activating your environment, install the version of -<a class="reference external" href="https://pytorch.org/">PyTorch</a> that your system supports by following the -official <a class="reference external" href="https://pytorch.org/get-started/locally/">instructions</a>.</p> -<p>If you have to build <code class="docutils literal notranslate"><span class="pre">pytorch</span></code> from source, follow this -<a class="reference external" href="https://github.com/pytorch/pytorch#from-source">guide</a>.</p> -<p><a class="reference external" href="https://pytorch.org/get-started/locally/#linux-verification">Here</a> is how to -check if <code class="docutils literal notranslate"><span class="pre">pytorch</span></code> is installed correctly.</p> -</div> -<div class="section" id="install-pysegcnn"> -<h2>Install PySegCNN<a class="headerlink" href="#install-pysegcnn" title="Permalink to this headline">¶</a></h2> -<p>To finally install <code class="docutils literal notranslate"><span class="pre">pysegcnn</span></code> run the below command <strong>from this repositories -root directory within the activated ``pysegcnn`` conda environment</strong>:</p> -<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>pip install -e . -</pre></div> -</div> -<p>If successful, you should be able to import <code class="docutils literal notranslate"><span class="pre">pysegcnn</span></code> from any Python -interpreter using:</p> -<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pysegcnn</span> -</pre></div> -</div> -</div> -</div> - - - </div> - - </div> - <footer> - - <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - - - <a href="../index.html" class="btn btn-neutral float-left" title="PySegCNN: Image segmentation with convolutional neural networks in Python" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> - - </div> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/source/installation.html b/docs/_build/html/source/installation.html index 5fb964c0a318f45dcc8d1f48e40ea536541c4678..422e882caa3279a88eb1d2a138bb6ddfec8b1289 100644 --- a/docs/_build/html/source/installation.html +++ b/docs/_build/html/source/installation.html @@ -36,6 +36,7 @@ <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> + <link rel="next" title="API Reference" href="api.html" /> <link rel="prev" title="Requirements" href="requirements.html" /> </head> @@ -91,6 +92,7 @@ <li class="toctree-l2"><a class="reference internal" href="#install-pysegcnn">Install PySegCNN</a></li> </ul> </li> +<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a></li> </ul> @@ -230,6 +232,8 @@ interpreter using:</p> <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> + <a href="api.html" class="btn btn-neutral float-right" title="API Reference" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> + <a href="requirements.html" class="btn btn-neutral float-left" title="Requirements" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> diff --git a/docs/_build/html/source/main.html b/docs/_build/html/source/main.html deleted file mode 100644 index d25c64c84a9589ba1a65c9dc349ad910cb737b7c..0000000000000000000000000000000000000000 --- a/docs/_build/html/source/main.html +++ /dev/null @@ -1,300 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>main package — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> - <script src="../_static/jquery.js"></script> - <script src="../_static/underscore.js"></script> - <script src="../_static/doctools.js"></script> - <script src="../_static/language_data.js"></script> - - <script type="text/javascript" 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="preprocessing package" href="preprocessing.html" /> - <link rel="prev" title="core package" href="core.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" > - - - - <a href="../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul class="current"> -<li class="toctree-l1 current"><a class="reference internal" href="modules.html">pysegcnn</a><ul class="current"> -<li class="toctree-l2"><a class="reference internal" href="core.html">core package</a></li> -<li class="toctree-l2 current"><a class="current reference internal" href="#">main package</a><ul> -<li class="toctree-l3"><a class="reference internal" href="#submodules">Submodules</a></li> -<li class="toctree-l3"><a class="reference internal" href="#module-main.config">main.config module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#license">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-main.eval">main.eval module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id1">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-main.train">main.train module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#id2">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-main">Module contents</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="preprocessing.html">preprocessing package</a></li> -</ul> -</li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../index.html" class="icon icon-home"></a> »</li> - - <li><a href="modules.html">pysegcnn</a> »</li> - - <li>main package</li> - - - <li class="wy-breadcrumbs-aside"> - - - <a href="../_sources/source/main.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"> - - <div class="section" id="main-package"> -<h1>main package<a class="headerlink" href="#main-package" title="Permalink to this headline">¶</a></h1> -<div class="section" id="submodules"> -<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2> -</div> -<div class="section" id="module-main.config"> -<span id="main-config-module"></span><h2>main.config module<a class="headerlink" href="#module-main.config" title="Permalink to this headline">¶</a></h2> -<p>The configuration file to train and evaluate a model.</p> -<p>The configuration is handled by the configuration dictionaries.</p> -<p>Modify the values to your needs, but DO NOT modify the keys.</p> -<div class="section" id="license"> -<h3>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -</div> -</div> -<div class="section" id="module-main.eval"> -<span id="main-eval-module"></span><h2>main.eval module<a class="headerlink" href="#module-main.eval" title="Permalink to this headline">¶</a></h2> -<p>Main script to evaluate a model.</p> -<p>Steps to run a model evaluation:</p> -<blockquote> -<div><ol class="arabic simple"> -<li><p>Configure the dictionary ‘eval_config’ in pysegcnn/main/config.py</p></li> -<li><p>Save pysegcnn/main/config.py</p></li> -<li><p>In a terminal, navigate to the repository’s root directory</p></li> -<li><p>run “python pysegcnn/main/eval.pyâ€</p></li> -</ol> -</div></blockquote> -<div class="section" id="id1"> -<h3>License<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -</div> -</div> -<div class="section" id="module-main.train"> -<span id="main-train-module"></span><h2>main.train module<a class="headerlink" href="#module-main.train" title="Permalink to this headline">¶</a></h2> -<p>Main script to train a model.</p> -<p>Steps to launch a model run:</p> -<blockquote> -<div><ol class="arabic simple"> -<li><p>Configure the model run in pysegcnn/main/config.py -(i) configure the dataset : dictionary ‘dataset_config’ -(j) configure the dataset split: dictionary ‘split_config’ -(k) configure the model : dictionary ‘model_config’</p></li> -<li><p>Save pysegcnn/main/config.py</p></li> -<li><p>In a terminal, navigate to the repository’s root directory</p></li> -<li><p>run “python pysegcnn/main/train.pyâ€</p></li> -</ol> -</div></blockquote> -<div class="section" id="id2"> -<h3>License<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -</div> -</div> -<div class="section" id="module-main"> -<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-main" title="Permalink to this headline">¶</a></h2> -</div> -</div> - - - </div> - - </div> - <footer> - - <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - - <a href="preprocessing.html" class="btn btn-neutral float-right" title="preprocessing package" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> - - - <a href="core.html" class="btn btn-neutral float-left" title="core package" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> - - </div> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/source/modules.html b/docs/_build/html/source/modules.html deleted file mode 100644 index abe9a8d8ae74a8997a507131c881b262dae29b43..0000000000000000000000000000000000000000 --- a/docs/_build/html/source/modules.html +++ /dev/null @@ -1,300 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>pysegcnn — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> - <script src="../_static/jquery.js"></script> - <script src="../_static/underscore.js"></script> - <script src="../_static/doctools.js"></script> - <script src="../_static/language_data.js"></script> - - <script type="text/javascript" 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="core package" href="core.html" /> - <link rel="prev" title="<no title>" href="../index.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" > - - - - <a href="../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul class="current"> -<li class="toctree-l1 current"><a class="current reference internal" href="#">pysegcnn</a><ul> -<li class="toctree-l2"><a class="reference internal" href="core.html">core package</a></li> -<li class="toctree-l2"><a class="reference internal" href="main.html">main package</a></li> -<li class="toctree-l2"><a class="reference internal" href="preprocessing.html">preprocessing package</a></li> -</ul> -</li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../index.html" class="icon icon-home"></a> »</li> - - <li>pysegcnn</li> - - - <li class="wy-breadcrumbs-aside"> - - - <a href="../_sources/source/modules.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"> - - <div class="section" id="pysegcnn"> -<h1>pysegcnn<a class="headerlink" href="#pysegcnn" title="Permalink to this headline">¶</a></h1> -<div class="toctree-wrapper compound"> -<ul> -<li class="toctree-l1"><a class="reference internal" href="core.html">core package</a><ul> -<li class="toctree-l2"><a class="reference internal" href="core.html#submodules">Submodules</a></li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.cli">core.cli module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#license">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.constants">core.constants module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id1">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.dataset">core.dataset module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id2">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.graphics">core.graphics module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id4">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.layers">core.layers module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id5">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.logging">core.logging module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id6">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.models">core.models module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id7">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.predict">core.predict module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id8">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.split">core.split module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id9">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.trainer">core.trainer module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id10">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.transforms">core.transforms module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id11">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core.utils">core.utils module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="core.html#id12">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="core.html#module-core">Module contents</a></li> -</ul> -</li> -<li class="toctree-l1"><a class="reference internal" href="main.html">main package</a><ul> -<li class="toctree-l2"><a class="reference internal" href="main.html#submodules">Submodules</a></li> -<li class="toctree-l2"><a class="reference internal" href="main.html#module-main.config">main.config module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="main.html#license">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="main.html#module-main.eval">main.eval module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="main.html#id1">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="main.html#module-main.train">main.train module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="main.html#id2">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="main.html#module-main">Module contents</a></li> -</ul> -</li> -<li class="toctree-l1"><a class="reference internal" href="preprocessing.html">preprocessing package</a><ul> -<li class="toctree-l2"><a class="reference internal" href="preprocessing.html#submodules">Submodules</a></li> -<li class="toctree-l2"><a class="reference internal" href="preprocessing.html#module-preprocessing.sparcs">preprocessing.sparcs module</a><ul> -<li class="toctree-l3"><a class="reference internal" href="preprocessing.html#license">License</a></li> -</ul> -</li> -<li class="toctree-l2"><a class="reference internal" href="preprocessing.html#module-preprocessing">Module contents</a></li> -</ul> -</li> -</ul> -</div> -</div> - - - </div> - - </div> - <footer> - - <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - - <a href="core.html" class="btn btn-neutral float-right" title="core package" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> - - - <a href="../index.html" class="btn btn-neutral float-left" title="<no title>" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> - - </div> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/source/preprocessing.html b/docs/_build/html/source/preprocessing.html deleted file mode 100644 index 9621025cb91bbd53068b23cbc577d6e7ff9953d6..0000000000000000000000000000000000000000 --- a/docs/_build/html/source/preprocessing.html +++ /dev/null @@ -1,247 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>preprocessing package — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> - <script src="../_static/jquery.js"></script> - <script src="../_static/underscore.js"></script> - <script src="../_static/doctools.js"></script> - <script src="../_static/language_data.js"></script> - - <script type="text/javascript" src="../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../genindex.html" /> - <link rel="search" title="Search" href="../search.html" /> - <link rel="prev" title="main package" href="main.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" > - - - - <a href="../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul class="current"> -<li class="toctree-l1 current"><a class="reference internal" href="modules.html">pysegcnn</a><ul class="current"> -<li class="toctree-l2"><a class="reference internal" href="core.html">core package</a></li> -<li class="toctree-l2"><a class="reference internal" href="main.html">main package</a></li> -<li class="toctree-l2 current"><a class="current reference internal" href="#">preprocessing package</a><ul> -<li class="toctree-l3"><a class="reference internal" href="#submodules">Submodules</a></li> -<li class="toctree-l3"><a class="reference internal" href="#module-preprocessing.sparcs">preprocessing.sparcs module</a><ul> -<li class="toctree-l4"><a class="reference internal" href="#license">License</a></li> -</ul> -</li> -<li class="toctree-l3"><a class="reference internal" href="#module-preprocessing">Module contents</a></li> -</ul> -</li> -</ul> -</li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../index.html" class="icon icon-home"></a> »</li> - - <li><a href="modules.html">pysegcnn</a> »</li> - - <li>preprocessing package</li> - - - <li class="wy-breadcrumbs-aside"> - - - <a href="../_sources/source/preprocessing.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"> - - <div class="section" id="preprocessing-package"> -<h1>preprocessing package<a class="headerlink" href="#preprocessing-package" title="Permalink to this headline">¶</a></h1> -<div class="section" id="submodules"> -<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2> -</div> -<div class="section" id="module-preprocessing.sparcs"> -<span id="preprocessing-sparcs-module"></span><h2>preprocessing.sparcs module<a class="headerlink" href="#module-preprocessing.sparcs" title="Permalink to this headline">¶</a></h2> -<p>Command line script to preprocess the Sparcs dataset.</p> -<p>After downloading the Sparcs dataset, from the repository’s root directory run:</p> -<blockquote> -<div><p>python pysegcnn/preprocessing/sparcs.py</p> -</div></blockquote> -<p>The above command will print the usage of the script.</p> -<div class="section" id="license"> -<h3>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h3> -<blockquote> -<div><p>Copyright (c) 2020 Daniel Frisinghelli</p> -<p>This source code is licensed under the GNU General Public License v3.</p> -<p>See the LICENSE file in the repository’s root directory.</p> -</div></blockquote> -</div> -</div> -<div class="section" id="module-preprocessing"> -<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-preprocessing" title="Permalink to this headline">¶</a></h2> -</div> -</div> - - - </div> - - </div> - <footer> - - <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - - - <a href="main.html" class="btn btn-neutral float-left" title="main package" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> - - </div> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/source/readme.html b/docs/_build/html/source/readme.html deleted file mode 100644 index 32d5d7f0abb36bc9083d5cfceb7b0c6d5d407d9f..0000000000000000000000000000000000000000 --- a/docs/_build/html/source/readme.html +++ /dev/null @@ -1,210 +0,0 @@ - - -<!DOCTYPE html> -<html class="writer-html5" lang="en" > -<head> - <meta charset="utf-8"> - - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - - <title>README — PySegCNN documentation</title> - - - - <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" /> - <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> - - - - - - - - <!--[if lt IE 9]> - <script src="../_static/js/html5shiv.min.js"></script> - <![endif]--> - - - <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> - <script src="../_static/jquery.js"></script> - <script src="../_static/underscore.js"></script> - <script src="../_static/doctools.js"></script> - <script src="../_static/language_data.js"></script> - - <script type="text/javascript" src="../_static/js/theme.js"></script> - - - <link rel="index" title="Index" href="../genindex.html" /> - <link rel="search" title="Search" href="../search.html" /> - <link rel="prev" title="preprocessing package" href="preprocessing.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" > - - - - <a href="../index.html" class="icon icon-home" alt="Documentation Home"> PySegCNN - - - - </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" /> - <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="main navigation"> - - - - - - - <ul class="current"> -<li class="toctree-l1"><a class="reference internal" href="modules.html">pysegcnn</a></li> -<li class="toctree-l1 current"><a class="current reference internal" href="#">README</a></li> -</ul> - - - - </div> - - </div> - </nav> - - <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> - - - <nav class="wy-nav-top" aria-label="top navigation"> - - <i data-toggle="wy-nav-top" class="fa fa-bars"></i> - <a href="../index.html">PySegCNN</a> - - </nav> - - - <div class="wy-nav-content"> - - <div class="rst-content"> - - - - - - - - - - - - - - - - - -<div role="navigation" aria-label="breadcrumbs navigation"> - - <ul class="wy-breadcrumbs"> - - <li><a href="../index.html" class="icon icon-home"></a> »</li> - - <li>README</li> - - - <li class="wy-breadcrumbs-aside"> - - - <a href="../_sources/source/readme.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"> - - <div class="section" id="readme"> -<h1>README<a class="headerlink" href="#readme" title="Permalink to this headline">¶</a></h1> -</div> - - - </div> - - </div> - <footer> - - <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> - - - <a href="preprocessing.html" class="btn btn-neutral float-left" title="preprocessing package" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> - - </div> - - - <hr/> - - <div role="contentinfo"> - <p> - - © Copyright 2020, Daniel Frisinghelli - - </p> - </div> - - - - Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a - - <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> - - provided by <a href="https://readthedocs.org">Read the Docs</a>. - -</footer> - - </div> - </div> - - </section> - - </div> - - - <script type="text/javascript"> - jQuery(function () { - SphinxRtdTheme.Navigation.enable(true); - }); - </script> - - - - - - -</body> -</html> \ No newline at end of file diff --git a/docs/_build/html/source/requirements.html b/docs/_build/html/source/requirements.html index 6360808703ea68989479d2ad31c0f56b73534813..aaceee5fc90ef2aaabacc36c5084a30698421544 100644 --- a/docs/_build/html/source/requirements.html +++ b/docs/_build/html/source/requirements.html @@ -92,6 +92,7 @@ </ul> </li> <li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li> +<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a></li> </ul> diff --git a/docs/conf.py b/docs/conf.py index 40c453ea0210443b06710df6915585055cda4523..c3ffaec690db1aad2cec9bdc03662c2f87fa6b5f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -32,15 +32,17 @@ author = 'Daniel Frisinghelli' # ones. extensions = [ 'sphinx.ext.autodoc', + 'sphinx.ext.autosummary', 'sphinx.ext.viewcode', - 'sphinx.ext.napoleon', - 'recommonmark', - 'numpydoc' + 'numpydoc', ] -# napoleon options -napoleon_google_docstring = False +# numpydoc options +numpydoc_show_class_members = False +numpydoc_show_inherited_class_members = False +# autosummary options +autosummary_generate = True # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/docs/source/api.rst b/docs/source/api.rst index 4de52de54bd3cdf346bfdf3d35e6bef1ce7643ab..6d2aabc35a3d4889c14b817a6580618244188067 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -13,9 +13,9 @@ Dataset Custom dataset classes compliant to the PyTorch `standard <https://pytorch.org/docs/stable/data.html>`_. -Image Dataset -^^^^^^^^^^^^^ -Generic class to implement `custom datasets <https://pytorch.org/tutorials/beginner/data_loading_tutorial.html>`_. +Generic classes +^^^^^^^^^^^^^^^ +Generic class to implement a `custom dataset <https://pytorch.org/tutorials/beginner/data_loading_tutorial.html>`_. .. autosummary:: :toctree: generated/ @@ -23,11 +23,21 @@ Generic class to implement `custom datasets <https://pytorch.org/tutorials/begin core.dataset.ImageDataset -Supported datasets -^^^^^^^^^^^^^^^^^^ +Generic class to implement a custom dataset following a standard directory +structure. + +.. autosummary:: + :toctree: generated/ + :nosignatures: + + core.dataset.StandardEoDataset + -The following open-source spaceborne multispectral image datasets are supported -out-of-the-box: +Specific classes +^^^^^^^^^^^^^^^^ + +Specific classes for some open-source image datasets. Currently, the following +spaceborne multispectral image datasets are supported out-of-the-box: .. autosummary:: :toctree: generated/ @@ -36,7 +46,6 @@ out-of-the-box: core.dataset.SparcsDataset core.dataset.Cloud95Dataset - Models ------ @@ -81,6 +90,9 @@ Neural Networks core.models.UNet +.. + Links: + .. _Sparcs: https://www.usgs.gov/land-resources/nli/landsat/spatial-procedures-automated-removal-cloud-and-shadow-sparcs-validation @@ -92,3 +104,12 @@ Neural Networks .. _U-Net: https://arxiv.org/abs/1505.04597 + +.. _Landsat-8: + https://www.usgs.gov/land-resources/nli/landsat/landsat-8?qt-science_support_page_related_con=0#qt-science_support_page_related_con + +.. _Sentinel-2: + https://sentinel.esa.int/web/sentinel/missions/sentinel-2 + +.. _Hughes & Hayes (2014): + https://www.mdpi.com/2072-4292/6/6/4907 diff --git a/docs/source/generated/pysegcnn.core.dataset.Cloud95Dataset.rst b/docs/source/generated/pysegcnn.core.dataset.Cloud95Dataset.rst index 0b8650621242af8de39fc4bf54f43f371b295a94..a1810656ee6dab330ce851fe7a3320f4396a65d0 100644 --- a/docs/source/generated/pysegcnn.core.dataset.Cloud95Dataset.rst +++ b/docs/source/generated/pysegcnn.core.dataset.Cloud95Dataset.rst @@ -1,4 +1,4 @@ -pysegcnn.core.dataset.Cloud95Dataset +pysegcnn.core.dataset.Cloud95Dataset ==================================== .. currentmodule:: pysegcnn.core.dataset diff --git a/docs/source/generated/pysegcnn.core.dataset.ImageDataset.rst b/docs/source/generated/pysegcnn.core.dataset.ImageDataset.rst index c04ed1f96ea2d230023e87a20bebeb31c0fe1050..31c36ff73f998226baf6cf9c48daeaea74404f94 100644 --- a/docs/source/generated/pysegcnn.core.dataset.ImageDataset.rst +++ b/docs/source/generated/pysegcnn.core.dataset.ImageDataset.rst @@ -1,4 +1,4 @@ -pysegcnn.core.dataset.ImageDataset +pysegcnn.core.dataset.ImageDataset ================================== .. currentmodule:: pysegcnn.core.dataset diff --git a/docs/source/generated/pysegcnn.core.dataset.SparcsDataset.rst b/docs/source/generated/pysegcnn.core.dataset.SparcsDataset.rst index d5c9fe46ca1985f87d71a260f0a9168ce193c5c4..cb357b5f003e77960920e99d3fe0ec24ec014b46 100644 --- a/docs/source/generated/pysegcnn.core.dataset.SparcsDataset.rst +++ b/docs/source/generated/pysegcnn.core.dataset.SparcsDataset.rst @@ -1,4 +1,4 @@ -pysegcnn.core.dataset.SparcsDataset +pysegcnn.core.dataset.SparcsDataset =================================== .. currentmodule:: pysegcnn.core.dataset diff --git a/docs/source/generated/pysegcnn.core.layers.Block.rst b/docs/source/generated/pysegcnn.core.layers.Block.rst index 3e960b4c77a531221739831ef70e2348e407fd1c..31875348b6f55bb5513dd3785c91d0cddb1a671e 100644 --- a/docs/source/generated/pysegcnn.core.layers.Block.rst +++ b/docs/source/generated/pysegcnn.core.layers.Block.rst @@ -1,4 +1,4 @@ -pysegcnn.core.layers.Block +pysegcnn.core.layers.Block ========================== .. currentmodule:: pysegcnn.core.layers diff --git a/docs/source/generated/pysegcnn.core.layers.Conv2dSame.rst b/docs/source/generated/pysegcnn.core.layers.Conv2dSame.rst index 7c81180f3dbf6d1b08ea77e608a908975395ddb5..42b472e1ec390a7329cfc9813c4a19efb35fe0ff 100644 --- a/docs/source/generated/pysegcnn.core.layers.Conv2dSame.rst +++ b/docs/source/generated/pysegcnn.core.layers.Conv2dSame.rst @@ -1,4 +1,4 @@ -pysegcnn.core.layers.Conv2dSame +pysegcnn.core.layers.Conv2dSame =============================== .. currentmodule:: pysegcnn.core.layers diff --git a/docs/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.rst b/docs/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.rst index 7a99902ee622930c6a3ed940f8f2f7e8af705b9d..6260fe50769352e915c3dc3d26ae9b9310ea7c52 100644 --- a/docs/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.rst +++ b/docs/source/generated/pysegcnn.core.layers.ConvBnReluMaxPool.rst @@ -1,4 +1,4 @@ -pysegcnn.core.layers.ConvBnReluMaxPool +pysegcnn.core.layers.ConvBnReluMaxPool ====================================== .. currentmodule:: pysegcnn.core.layers diff --git a/docs/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.rst b/docs/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.rst index c83252a532e4d66427284193e0ce3bd6233ad52e..386abc1be48bcf7487098b4847c7e6385d849772 100644 --- a/docs/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.rst +++ b/docs/source/generated/pysegcnn.core.layers.ConvBnReluMaxUnpool.rst @@ -1,4 +1,4 @@ -pysegcnn.core.layers.ConvBnReluMaxUnpool +pysegcnn.core.layers.ConvBnReluMaxUnpool ======================================== .. currentmodule:: pysegcnn.core.layers diff --git a/docs/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.rst b/docs/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.rst index bac34eecc38456d240d6889d01a7e97b9268dd99..6d4f3e6ac7d591f5aaa1da607b6c5730d099d6d0 100644 --- a/docs/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.rst +++ b/docs/source/generated/pysegcnn.core.layers.ConvBnReluUpsample.rst @@ -1,4 +1,4 @@ -pysegcnn.core.layers.ConvBnReluUpsample +pysegcnn.core.layers.ConvBnReluUpsample ======================================= .. currentmodule:: pysegcnn.core.layers diff --git a/docs/source/generated/pysegcnn.core.layers.Decoder.rst b/docs/source/generated/pysegcnn.core.layers.Decoder.rst index 9ca6527d10479cdf03eb3d4213af41da9c295b4a..a5fcf7fd1a0190303deaee9d603008990cc060f5 100644 --- a/docs/source/generated/pysegcnn.core.layers.Decoder.rst +++ b/docs/source/generated/pysegcnn.core.layers.Decoder.rst @@ -1,4 +1,4 @@ -pysegcnn.core.layers.Decoder +pysegcnn.core.layers.Decoder ============================ .. currentmodule:: pysegcnn.core.layers diff --git a/docs/source/generated/pysegcnn.core.layers.DecoderBlock.rst b/docs/source/generated/pysegcnn.core.layers.DecoderBlock.rst index 3acc653c6098b27269e7e171bdc7a9f22ab570e8..d6a87bc7f63568ac82cddf0dc5f4d4653391343c 100644 --- a/docs/source/generated/pysegcnn.core.layers.DecoderBlock.rst +++ b/docs/source/generated/pysegcnn.core.layers.DecoderBlock.rst @@ -1,4 +1,4 @@ -pysegcnn.core.layers.DecoderBlock +pysegcnn.core.layers.DecoderBlock ================================= .. currentmodule:: pysegcnn.core.layers diff --git a/docs/source/generated/pysegcnn.core.layers.Encoder.rst b/docs/source/generated/pysegcnn.core.layers.Encoder.rst index 09aa71ccc1c2f5cf0c5fcf0b84a6e47fde490f4e..fcd00c6bc912c46d3ac641b3d2fdeb5a1fd3295c 100644 --- a/docs/source/generated/pysegcnn.core.layers.Encoder.rst +++ b/docs/source/generated/pysegcnn.core.layers.Encoder.rst @@ -1,4 +1,4 @@ -pysegcnn.core.layers.Encoder +pysegcnn.core.layers.Encoder ============================ .. currentmodule:: pysegcnn.core.layers diff --git a/docs/source/generated/pysegcnn.core.layers.EncoderBlock.rst b/docs/source/generated/pysegcnn.core.layers.EncoderBlock.rst index 37385b204208ec53e9a247657998a864ad5a0602..454ce4102139d897e53bbad4c61d61bc7b6aeae6 100644 --- a/docs/source/generated/pysegcnn.core.layers.EncoderBlock.rst +++ b/docs/source/generated/pysegcnn.core.layers.EncoderBlock.rst @@ -1,4 +1,4 @@ -pysegcnn.core.layers.EncoderBlock +pysegcnn.core.layers.EncoderBlock ================================= .. currentmodule:: pysegcnn.core.layers diff --git a/docs/source/generated/pysegcnn.core.models.Network.rst b/docs/source/generated/pysegcnn.core.models.Network.rst index a5b21f07fee5ee799539ac7daf52a68abd48d617..99819a3608b928852226184cbf9d39f50697a252 100644 --- a/docs/source/generated/pysegcnn.core.models.Network.rst +++ b/docs/source/generated/pysegcnn.core.models.Network.rst @@ -1,4 +1,4 @@ -pysegcnn.core.models.Network +pysegcnn.core.models.Network ============================ .. currentmodule:: pysegcnn.core.models diff --git a/docs/source/generated/pysegcnn.core.models.UNet.rst b/docs/source/generated/pysegcnn.core.models.UNet.rst index 933d3fcbccf6d0d26a1c0bee26300e0fa0cae620..92cb118b24485a58a9d65aafbd223aafadf1ce59 100644 --- a/docs/source/generated/pysegcnn.core.models.UNet.rst +++ b/docs/source/generated/pysegcnn.core.models.UNet.rst @@ -1,4 +1,4 @@ -pysegcnn.core.models.UNet +pysegcnn.core.models.UNet ========================= .. currentmodule:: pysegcnn.core.models