| <!DOCTYPE html> |
| |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"/> |
| <meta content="IE=edge" http-equiv="X-UA-Compatible"/> |
| <meta content="width=device-width, initial-scale=1" name="viewport"/> |
| <title>Gluon Package — mxnet documentation</title> |
| <link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" rel="stylesheet"/> |
| <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/> |
| <link href="../../../_static/basic.css" rel="stylesheet" type="text/css"> |
| <link href="../../../_static/pygments.css" rel="stylesheet" type="text/css"> |
| <link href="../../../_static/mxnet.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT: '../../../', |
| VERSION: '', |
| COLLAPSE_INDEX: false, |
| FILE_SUFFIX: '.html', |
| HAS_SOURCE: true, |
| SOURCELINK_SUFFIX: '' |
| }; |
| </script> |
| <script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script> |
| <script src="../../../_static/underscore.js" type="text/javascript"></script> |
| <script src="../../../_static/searchtools_custom.js" type="text/javascript"></script> |
| <script src="../../../_static/doctools.js" type="text/javascript"></script> |
| <script src="../../../_static/selectlang.js" type="text/javascript"></script> |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script> |
| <script type="text/javascript"> jQuery(function() { Search.loadIndex("/searchindex.js"); Search.init();}); </script> |
| <script> |
| (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
| (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new |
| Date();a=s.createElement(o), |
| m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
| })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); |
| |
| ga('create', 'UA-96378503-1', 'auto'); |
| ga('send', 'pageview'); |
| |
| </script> |
| <!-- --> |
| <!-- <script type="text/javascript" src="../../../_static/jquery.js"></script> --> |
| <!-- --> |
| <!-- <script type="text/javascript" src="../../../_static/underscore.js"></script> --> |
| <!-- --> |
| <!-- <script type="text/javascript" src="../../../_static/doctools.js"></script> --> |
| <!-- --> |
| <!-- <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> --> |
| <!-- --> |
| <link href="../index.html" rel="up" title="MXNet - Python API"> |
| <link href="nn.html" rel="next" title="Gluon Neural Network Layers"/> |
| <link href="../autograd/autograd.html" rel="prev" title="Autograd Package"/> |
| <link href="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-icon.png" rel="icon" type="image/png"/> |
| </link></link></link></head> |
| <body background="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-background-compressed.jpeg" role="document"> |
| <div class="content-block"><div class="navbar navbar-fixed-top"> |
| <div class="container" id="navContainer"> |
| <div class="innder" id="header-inner"> |
| <h1 id="logo-wrap"> |
| <a href="../../../" id="logo"><img src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet_logo.png"/></a> |
| </h1> |
| <nav class="nav-bar" id="main-nav"> |
| <a class="main-nav-link" href="../../../install/index.html">Install</a> |
| <span id="dropdown-menu-position-anchor"> |
| <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Gluon <span class="caret"></span></a> |
| <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu"> |
| <li><a class="main-nav-link" href="../../../gluon/index.html">About</a></li> |
| <li><a class="main-nav-link" href="http://gluon.mxnet.io">Tutorials</a></li> |
| </ul> |
| </span> |
| <span id="dropdown-menu-position-anchor"> |
| <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">API <span class="caret"></span></a> |
| <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu"> |
| <li><a class="main-nav-link" href="../../../api/python/index.html">Python</a></li> |
| <li><a class="main-nav-link" href="../../../api/scala/index.html">Scala</a></li> |
| <li><a class="main-nav-link" href="../../../api/r/index.html">R</a></li> |
| <li><a class="main-nav-link" href="../../../api/julia/index.html">Julia</a></li> |
| <li><a class="main-nav-link" href="../../../api/c++/index.html">C++</a></li> |
| <li><a class="main-nav-link" href="../../../api/perl/index.html">Perl</a></li> |
| </ul> |
| </span> |
| <span id="dropdown-menu-position-anchor-docs"> |
| <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Docs <span class="caret"></span></a> |
| <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu-docs"> |
| <li><a class="main-nav-link" href="../../../tutorials/index.html">Tutorials</a> |
| <li><a class="main-nav-link" href="../../../faq/index.html">FAQ</a></li> |
| <li><a class="main-nav-link" href="../../../architecture/index.html">Architecture</a></li> |
| <li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/master/example">Examples</a></li> |
| <li><a class="main-nav-link" href="../../../model_zoo/index.html">Model Zoo</a></li> |
| </li></ul> |
| </span> |
| <a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a> |
| <span id="dropdown-menu-position-anchor-community"> |
| <a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">Community <span class="caret"></span></a> |
| <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu-community"> |
| <li><a class="main-nav-link" href="../../../community/index.html">Community</a></li> |
| <li><a class="main-nav-link" href="../../../community/contribute.html">Contribute</a></li> |
| <li><a class="main-nav-link" href="../../../community/powered_by.html">Powered By</a></li> |
| <li><a class="main-nav-link" href="http://discuss.mxnet.io">Discuss</a></li> |
| </ul> |
| </span> |
| <span id="dropdown-menu-position-anchor-version" style="position: relative"><a href="#" class="main-nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Versions(master)<span class="caret"></span></a><ul id="package-dropdown-menu" class="dropdown-menu"><li><a class="main-nav-link" href=https://mxnet.incubator.apache.org/>1.0.0</a></li><li><a class="main-nav-link" href=https://mxnet.incubator.apache.org/versions/0.12.1/index.html>0.12.1</a></li><li><a class="main-nav-link" href=https://mxnet.incubator.apache.org/versions/0.12.0/index.html>0.12.0</a></li><li><a class="main-nav-link" href=https://mxnet.incubator.apache.org/versions/0.11.0/index.html>0.11.0</a></li><li><a class="main-nav-link" href=https://mxnet.incubator.apache.org/versions/master/index.html>master</a></li></ul></span></nav> |
| <script> function getRootPath(){ return "../../../" } </script> |
| <div class="burgerIcon dropdown"> |
| <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button">☰</a> |
| <ul class="dropdown-menu" id="burgerMenu"> |
| <li><a href="../../../install/index.html">Install</a></li> |
| <li><a class="main-nav-link" href="../../../tutorials/index.html">Tutorials</a></li> |
| <li class="dropdown-submenu"> |
| <a href="#" tabindex="-1">Community</a> |
| <ul class="dropdown-menu"> |
| <li><a href="../../../community/index.html" tabindex="-1">Community</a></li> |
| <li><a href="../../../community/contribute.html" tabindex="-1">Contribute</a></li> |
| <li><a href="../../../community/powered_by.html" tabindex="-1">Powered By</a></li> |
| </ul> |
| </li> |
| <li class="dropdown-submenu"> |
| <a href="#" tabindex="-1">API</a> |
| <ul class="dropdown-menu"> |
| <li><a href="../../../api/python/index.html" tabindex="-1">Python</a> |
| </li> |
| <li><a href="../../../api/scala/index.html" tabindex="-1">Scala</a> |
| </li> |
| <li><a href="../../../api/r/index.html" tabindex="-1">R</a> |
| </li> |
| <li><a href="../../../api/julia/index.html" tabindex="-1">Julia</a> |
| </li> |
| <li><a href="../../../api/c++/index.html" tabindex="-1">C++</a> |
| </li> |
| <li><a href="../../../api/perl/index.html" tabindex="-1">Perl</a> |
| </li> |
| </ul> |
| </li> |
| <li class="dropdown-submenu"> |
| <a href="#" tabindex="-1">Docs</a> |
| <ul class="dropdown-menu"> |
| <li><a href="../../../tutorials/index.html" tabindex="-1">Tutorials</a></li> |
| <li><a href="../../../faq/index.html" tabindex="-1">FAQ</a></li> |
| <li><a href="../../../architecture/index.html" tabindex="-1">Architecture</a></li> |
| <li><a href="https://github.com/apache/incubator-mxnet/tree/master/example" tabindex="-1">Examples</a></li> |
| <li><a href="../../../model_zoo/index.html" tabindex="-1">Model Zoo</a></li> |
| </ul> |
| </li> |
| <li><a href="../../../architecture/index.html">Architecture</a></li> |
| <li><a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a></li> |
| <li id="dropdown-menu-position-anchor-version-mobile" class="dropdown-submenu" style="position: relative"><a href="#" tabindex="-1">Versions(master)</a><ul class="dropdown-menu"><li><a tabindex="-1" href=https://mxnet.incubator.apache.org/>1.0.0</a></li><li><a tabindex="-1" href=https://mxnet.incubator.apache.org/versions/0.12.1/index.html>0.12.1</a></li><li><a tabindex="-1" href=https://mxnet.incubator.apache.org/versions/0.12.0/index.html>0.12.0</a></li><li><a tabindex="-1" href=https://mxnet.incubator.apache.org/versions/0.11.0/index.html>0.11.0</a></li><li><a tabindex="-1" href=https://mxnet.incubator.apache.org/versions/master/index.html>master</a></li></ul></li></ul> |
| </div> |
| <div class="plusIcon dropdown"> |
| <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"><span aria-hidden="true" class="glyphicon glyphicon-plus"></span></a> |
| <ul class="dropdown-menu dropdown-menu-right" id="plusMenu"></ul> |
| </div> |
| <div id="search-input-wrap"> |
| <form action="../../../search.html" autocomplete="off" class="" method="get" role="search"> |
| <div class="form-group inner-addon left-addon"> |
| <i class="glyphicon glyphicon-search"></i> |
| <input class="form-control" name="q" placeholder="Search" type="text"/> |
| </div> |
| <input name="check_keywords" type="hidden" value="yes"> |
| <input name="area" type="hidden" value="default"/> |
| </input></form> |
| <div id="search-preview"></div> |
| </div> |
| <div id="searchIcon"> |
| <span aria-hidden="true" class="glyphicon glyphicon-search"></span> |
| </div> |
| <!-- <div id="lang-select-wrap"> --> |
| <!-- <label id="lang-select-label"> --> |
| <!-- <\!-- <i class="fa fa-globe"></i> -\-> --> |
| <!-- <span></span> --> |
| <!-- </label> --> |
| <!-- <select id="lang-select"> --> |
| <!-- <option value="en">Eng</option> --> |
| <!-- <option value="zh">中文</option> --> |
| <!-- </select> --> |
| <!-- </div> --> |
| <!-- <a id="mobile-nav-toggle"> |
| <span class="mobile-nav-toggle-bar"></span> |
| <span class="mobile-nav-toggle-bar"></span> |
| <span class="mobile-nav-toggle-bar"></span> |
| </a> --> |
| </div> |
| </div> |
| </div> |
| <script type="text/javascript"> |
| $('body').css('background', 'white'); |
| </script> |
| <div class="container"> |
| <div class="row"> |
| <div aria-label="main navigation" class="sphinxsidebar leftsidebar" role="navigation"> |
| <div class="sphinxsidebarwrapper"> |
| <ul class="current"> |
| <li class="toctree-l1 current"><a class="reference internal" href="../index.html">Python Documents</a><ul class="current"> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#ndarray-api">NDArray API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#symbol-api">Symbol API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#module-api">Module API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#autograd-api">Autograd API</a></li> |
| <li class="toctree-l2 current"><a class="reference internal" href="../index.html#gluon-api">Gluon API</a><ul class="current"> |
| <li class="toctree-l3 current"><a class="current reference internal" href="">Gluon Package</a><ul> |
| <li class="toctree-l4"><a class="reference internal" href="#overview">Overview</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#parameter">Parameter</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#containers">Containers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#trainer">Trainer</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#utilities">Utilities</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="#api-reference">API Reference</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l3"><a class="reference internal" href="nn.html">Gluon Neural Network Layers</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="rnn.html">Gluon Recurrent Neural Network API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="loss.html">Gluon Loss API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="data.html">Gluon Data API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="model_zoo.html">Gluon Model Zoo</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="contrib.html">Gluon Contrib API</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#kvstore-api">KVStore API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#io-api">IO API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#image-api">Image API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#optimization-api">Optimization API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#callback-api">Callback API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#metric-api">Metric API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#run-time-compilation-api">Run-Time Compilation API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../index.html#contrib-package">Contrib Package</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="../../r/index.html">R Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../julia/index.html">Julia Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../c++/index.html">C++ Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../scala/index.html">Scala Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../perl/index.html">Perl Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../faq/index.html">HowTo Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../architecture/index.html">System Documents</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../tutorials/index.html">Tutorials</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../community/index.html">Community</a></li> |
| </ul> |
| </div> |
| </div> |
| <div class="content"> |
| <div class="page-tracker"></div> |
| <div class="section" id="gluon-package"> |
| <span id="gluon-package"></span><h1>Gluon Package<a class="headerlink" href="#gluon-package" title="Permalink to this headline">¶</a></h1> |
| <script src="../../_static/js/auto_module_index.js" type="text/javascript"></script><div class="section" id="overview"> |
| <span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2> |
| <p>Gluon package is a high-level interface for MXNet designed to be easy to use while |
| keeping most of the flexibility of low level API. Gluon supports both imperative |
| and symbolic programming, making it easy to train complex models imperatively |
| in Python and then deploy with symbolic graph in C++ and Scala.</p> |
| <div class="toctree-wrapper compound"> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="nn.html">Gluon Neural Network Layers</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="rnn.html">Gluon Recurrent Neural Network API</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="loss.html">Gluon Loss API</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="data.html">Gluon Data API</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="model_zoo.html">Gluon Model Zoo</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="contrib.html">Gluon Contrib API</a></li> |
| </ul> |
| </div> |
| </div> |
| <div class="section" id="parameter"> |
| <span id="parameter"></span><h2>Parameter<a class="headerlink" href="#parameter" title="Permalink to this headline">¶</a></h2> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-obj docutils literal"><span class="pre">Parameter</span></code></a></td> |
| <td>A Container holding parameters (weights) of Blocks.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-obj docutils literal"><span class="pre">ParameterDict</span></code></a></td> |
| <td>A dictionary managing a set of parameters.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="containers"> |
| <span id="containers"></span><h2>Containers<a class="headerlink" href="#containers" title="Permalink to this headline">¶</a></h2> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-obj docutils literal"><span class="pre">Block</span></code></a></td> |
| <td>Base class for all neural network layers and models.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-obj docutils literal"><span class="pre">HybridBlock</span></code></a></td> |
| <td><cite>HybridBlock</cite> supports forwarding with both Symbol and NDArray.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.SymbolBlock" title="mxnet.gluon.SymbolBlock"><code class="xref py py-obj docutils literal"><span class="pre">SymbolBlock</span></code></a></td> |
| <td>Construct block from symbol.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.gluon.nn.Sequential" title="mxnet.gluon.nn.Sequential"><code class="xref py py-obj docutils literal"><span class="pre">nn.Sequential</span></code></a></td> |
| <td>Stacks Blocks sequentially.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.nn.HybridSequential" title="mxnet.gluon.nn.HybridSequential"><code class="xref py py-obj docutils literal"><span class="pre">nn.HybridSequential</span></code></a></td> |
| <td>Stacks HybridBlocks sequentially.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="trainer"> |
| <span id="trainer"></span><h2>Trainer<a class="headerlink" href="#trainer" title="Permalink to this headline">¶</a></h2> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.Trainer" title="mxnet.gluon.Trainer"><code class="xref py py-obj docutils literal"><span class="pre">Trainer</span></code></a></td> |
| <td>Applies an <cite>Optimizer</cite> on a set of Parameters.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="utilities"> |
| <span id="utilities"></span><h2>Utilities<a class="headerlink" href="#utilities" title="Permalink to this headline">¶</a></h2> |
| <table border="1" class="longtable docutils"> |
| <colgroup> |
| <col width="10%"/> |
| <col width="90%"/> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.utils.split_data" title="mxnet.gluon.utils.split_data"><code class="xref py py-obj docutils literal"><span class="pre">split_data</span></code></a></td> |
| <td>Splits an NDArray into <cite>num_slice</cite> slices along <cite>batch_axis</cite>.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.gluon.utils.split_and_load" title="mxnet.gluon.utils.split_and_load"><code class="xref py py-obj docutils literal"><span class="pre">split_and_load</span></code></a></td> |
| <td>Splits an NDArray into <cite>len(ctx_list)</cite> slices along <cite>batch_axis</cite> and loads each slice to one context in <cite>ctx_list</cite>.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.utils.clip_global_norm" title="mxnet.gluon.utils.clip_global_norm"><code class="xref py py-obj docutils literal"><span class="pre">clip_global_norm</span></code></a></td> |
| <td>Rescales NDArrays so that the sum of their 2-norm is smaller than <cite>max_norm</cite>.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="api-reference"> |
| <span id="api-reference"></span><h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h2> |
| <script src="../../_static/js/auto_module_index.js" type="text/javascript"></script><span class="target" id="module-mxnet.gluon"></span><p>Neural network module.</p> |
| <dl class="class"> |
| <dt id="mxnet.gluon.Block"> |
| <em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">Block</code><span class="sig-paren">(</span><em>prefix=None</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Base class for all neural network layers and models. Your models should |
| subclass this class.</p> |
| <p><a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> can be nested recursively in a tree structure. You can create and |
| assign child <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> as regular attributes:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mxnet.gluon</span> <span class="kn">import</span> <span class="n">Block</span><span class="p">,</span> <span class="n">nn</span> |
| <span class="kn">from</span> <span class="nn">mxnet</span> <span class="kn">import</span> <span class="n">ndarray</span> <span class="k">as</span> <span class="n">F</span> |
| |
| <span class="k">class</span> <span class="nc">Model</span><span class="p">(</span><span class="n">Block</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="o">**</span><span class="n">kwargs</span><span class="p">):</span> |
| <span class="nb">super</span><span class="p">(</span><span class="n">Model</span><span class="p">,</span> <span class="bp">self</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">kwargs</span><span class="p">)</span> |
| <span class="c1"># use name_scope to give child Blocks appropriate names.</span> |
| <span class="c1"># It also allows sharing Parameters between Blocks recursively.</span> |
| <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span> |
| <span class="bp">self</span><span class="o">.</span><span class="n">dense0</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span> |
| <span class="bp">self</span><span class="o">.</span><span class="n">dense1</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span> |
| |
| <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">x</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dense0</span><span class="p">(</span><span class="n">x</span><span class="p">))</span> |
| <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dense1</span><span class="p">(</span><span class="n">x</span><span class="p">))</span> |
| |
| <span class="n">model</span> <span class="o">=</span> <span class="n">Model</span><span class="p">()</span> |
| <span class="n">model</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> |
| <span class="n">model</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">zeros</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">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">)))</span> |
| </pre></div> |
| </div> |
| <p>Child <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> assigned this way will be registered and <a class="reference internal" href="#mxnet.gluon.Block.collect_params" title="mxnet.gluon.Block.collect_params"><code class="xref py py-meth docutils literal"><span class="pre">collect_params()</span></code></a> |
| will collect their Parameters recursively.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>prefix</strong> (<em>str</em>) – Prefix acts like a name space. It will be prepended to the names of all |
| Parameters and child <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> s in this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> ‘s |
| <a class="reference internal" href="#mxnet.gluon.Block.name_scope" title="mxnet.gluon.Block.name_scope"><code class="xref py py-meth docutils literal"><span class="pre">name_scope()</span></code></a> . |
| Prefix should be unique within one model to prevent name collisions.</li> |
| <li><strong>params</strong> (<em>ParameterDict or None</em>) – <p><a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-class docutils literal"><span class="pre">ParameterDict</span></code></a> for sharing weights with the new <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>. For example, |
| if you want <code class="docutils literal"><span class="pre">dense1</span></code> to share <code class="docutils literal"><span class="pre">dense0</span></code>‘s weights, you can do:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">dense0</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span> |
| <span class="n">dense1</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">dense0</span><span class="o">.</span><span class="n">collect_params</span><span class="p">())</span> |
| </pre></div> |
| </div> |
| </li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.__call__"> |
| <code class="descname">__call__</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.__call__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.__call__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Calls forward. Only accepts positional arguments.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.__setattr__"> |
| <code class="descname">__setattr__</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.__setattr__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.__setattr__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Registers parameters.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.Block.__weakref__"> |
| <code class="descname">__weakref__</code><a class="headerlink" href="#mxnet.gluon.Block.__weakref__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>list of weak references to the object (if defined)</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.cast"> |
| <code class="descname">cast</code><span class="sig-paren">(</span><em>dtype</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.cast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.cast" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Cast this Block to use another data type.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>dtype</strong> (<em>str or numpy.dtype</em>) – The new data type.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.collect_params"> |
| <code class="descname">collect_params</code><span class="sig-paren">(</span><em>select=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.collect_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.collect_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a <a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-class docutils literal"><span class="pre">ParameterDict</span></code></a> containing this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> and all of its |
| children’s Parameters(default), also can returns the select <a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-class docutils literal"><span class="pre">ParameterDict</span></code></a> |
| which match some given regular expressions.</p> |
| <p>For example, collect the specified parameter in [‘conv1_weight’, ‘conv1_bias’, ‘fc_weight’, |
| ‘fc_bias’]:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">model</span><span class="o">.</span><span class="n">collect_params</span><span class="p">(</span><span class="s1">'conv1_weight|conv1_bias|fc_weight|fc_bias'</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>or collect all paramters which their name ends with ‘weight’ or ‘bias’, this can be done |
| using regular expressions:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">model</span><span class="o">.</span><span class="n">collect_params</span><span class="p">(</span><span class="s1">'.*weight|.*bias'</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>select</strong> (<em>str</em>) – regular expressions</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">The selected <a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-class docutils literal"><span class="pre">ParameterDict</span></code></a></td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.forward"> |
| <code class="descname">forward</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.forward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Overrides to implement forward computation using <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code>. Only |
| accepts positional arguments.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>*args</strong> – <p>Input tensors.</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.hybridize"> |
| <code class="descname">hybridize</code><span class="sig-paren">(</span><em>active=True</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.hybridize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.hybridize" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Activates or deactivates <a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-class docutils literal"><span class="pre">HybridBlock</span></code></a> s recursively. Has no effect on |
| non-hybrid children.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>active</strong> (<em>bool, default True</em>) – Whether to turn hybrid on or off.</li> |
| <li><strong>**kwargs</strong> – <p>Additional flags for hybridized operator.</p> |
| </li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.initialize"> |
| <code class="descname">initialize</code><span class="sig-paren">(</span><em>init=<mxnet.initializer.Uniform object></em>, <em>ctx=None</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.initialize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.initialize" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Initializes <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a> s of this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> and its children.</p> |
| <p>Equivalent to <code class="docutils literal"><span class="pre">block.collect_params().initialize(...)</span></code></p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.load_params"> |
| <code class="descname">load_params</code><span class="sig-paren">(</span><em>filename</em>, <em>ctx</em>, <em>allow_missing=False</em>, <em>ignore_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.load_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.load_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Load parameters from file.</p> |
| <dl class="docutils"> |
| <dt>filename <span class="classifier-delimiter">:</span> <span class="classifier">str</span></dt> |
| <dd>Path to parameter file.</dd> |
| <dt>ctx <span class="classifier-delimiter">:</span> <span class="classifier">Context or list of Context</span></dt> |
| <dd>Context(s) initialize loaded parameters on.</dd> |
| <dt>allow_missing <span class="classifier-delimiter">:</span> <span class="classifier">bool, default False</span></dt> |
| <dd>Whether to silently skip loading parameters not represents in the file.</dd> |
| <dt>ignore_extra <span class="classifier-delimiter">:</span> <span class="classifier">bool, default False</span></dt> |
| <dd>Whether to silently ignore parameters from the file that are not |
| present in this Block.</dd> |
| </dl> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.Block.name"> |
| <code class="descname">name</code><a class="headerlink" href="#mxnet.gluon.Block.name" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Name of this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>, without ‘_’ in the end.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.name_scope"> |
| <code class="descname">name_scope</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.name_scope"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.name_scope" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a name space object managing a child <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> and parameter |
| names. Should be used within a <code class="docutils literal"><span class="pre">with</span></code> statement:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span> |
| <span class="bp">self</span><span class="o">.</span><span class="n">dense</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.Block.params"> |
| <code class="descname">params</code><a class="headerlink" href="#mxnet.gluon.Block.params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>‘s parameter dictionary (does not include its |
| children’s parameters).</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.Block.prefix"> |
| <code class="descname">prefix</code><a class="headerlink" href="#mxnet.gluon.Block.prefix" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Prefix of this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.register_child"> |
| <code class="descname">register_child</code><span class="sig-paren">(</span><em>block</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.register_child"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.register_child" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Registers block as a child of self. <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> s assigned to self as |
| attributes will be registered automatically.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Block.save_params"> |
| <code class="descname">save_params</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.save_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.save_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Save parameters to file.</p> |
| <dl class="docutils"> |
| <dt>filename <span class="classifier-delimiter">:</span> <span class="classifier">str</span></dt> |
| <dd>Path to file.</dd> |
| </dl> |
| </dd></dl> |
| </dd></dl> |
| <dl class="exception"> |
| <dt id="mxnet.gluon.DeferredInitializationError"> |
| <em class="property">exception </em><code class="descclassname">mxnet.gluon.</code><code class="descname">DeferredInitializationError</code><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#DeferredInitializationError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.DeferredInitializationError" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Error for unfinished deferred initialization.</p> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.gluon.HybridBlock"> |
| <em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">HybridBlock</code><span class="sig-paren">(</span><em>prefix=None</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock" title="Permalink to this definition">¶</a></dt> |
| <dd><p><cite>HybridBlock</cite> supports forwarding with both Symbol and NDArray.</p> |
| <p>Forward computation in <a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-class docutils literal"><span class="pre">HybridBlock</span></code></a> must be static to work with <code class="xref py py-class docutils literal"><span class="pre">Symbol</span></code> s, |
| i.e. you cannot call <code class="xref py py-meth docutils literal"><span class="pre">NDArray.asnumpy()</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">NDArray.shape</span></code>, |
| <code class="xref py py-attr docutils literal"><span class="pre">NDArray.dtype</span></code>, etc on tensors. |
| Also, you cannot use branching or loop logic that bases on non-constant |
| expressions like random numbers or intermediate results, since they change |
| the graph structure for each iteration.</p> |
| <p>Before activating with <code class="xref py py-meth docutils literal"><span class="pre">hybridize()</span></code>, <a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-class docutils literal"><span class="pre">HybridBlock</span></code></a> works just like normal |
| <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>. After activation, <a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-class docutils literal"><span class="pre">HybridBlock</span></code></a> will create a symbolic graph |
| representing the forward computation and cache it. On subsequent forwards, |
| the cached graph will be used instead of <a class="reference internal" href="#mxnet.gluon.HybridBlock.hybrid_forward" title="mxnet.gluon.HybridBlock.hybrid_forward"><code class="xref py py-meth docutils literal"><span class="pre">hybrid_forward()</span></code></a>.</p> |
| <p>Refer <a class="reference external" href="https://mxnet.incubator.apache.org/versions/master/tutorials/gluon/hybrid.html">Hybrid tutorial</a> to see |
| the end-to-end usage.</p> |
| <dl class="method"> |
| <dt id="mxnet.gluon.HybridBlock.__setattr__"> |
| <code class="descname">__setattr__</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.__setattr__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.__setattr__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Registers parameters.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.HybridBlock.export"> |
| <code class="descname">export</code><span class="sig-paren">(</span><em>path</em>, <em>epoch=0</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.export"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.export" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Export HybridBlock to json format that can be loaded by <cite>mxnet.mod.Module</cite> |
| or the C++ interface.</p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">When there are only one input, it will have name <cite>data</cite>. When there |
| Are more than one inputs, they will be named as <cite>data0</cite>, <cite>data1</cite>, etc.</p> |
| </div> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>path</strong> (<em>str</em>) – Path to save model. Two files <cite>path-symbol.json</cite> and <cite>path-xxxx.params</cite> |
| will be created, where xxxx is the 4 digits epoch number.</li> |
| <li><strong>epoch</strong> (<em>int</em>) – Epoch number of saved model.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.HybridBlock.forward"> |
| <code class="descname">forward</code><span class="sig-paren">(</span><em>x</em>, <em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.forward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Defines the forward computation. Arguments can be either |
| <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code> or <code class="xref py py-class docutils literal"><span class="pre">Symbol</span></code>.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.HybridBlock.hybrid_forward"> |
| <code class="descname">hybrid_forward</code><span class="sig-paren">(</span><em>F</em>, <em>x</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.hybrid_forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.hybrid_forward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Overrides to construct symbolic graph for this <cite>Block</cite>.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>x</strong> (<em>Symbol or NDArray</em>) – The first input tensor.</li> |
| <li><strong>*args</strong> – <p>Additional input tensors.</p> |
| </li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.HybridBlock.infer_shape"> |
| <code class="descname">infer_shape</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.infer_shape"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.infer_shape" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Infers shape of Parameters from inputs.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.HybridBlock.infer_type"> |
| <code class="descname">infer_type</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.infer_type"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.infer_type" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Infers data type of Parameters from inputs.</p> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.gluon.Parameter"> |
| <em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">Parameter</code><span class="sig-paren">(</span><em>name</em>, <em>grad_req='write'</em>, <em>shape=None</em>, <em>dtype=<type 'numpy.float32'></em>, <em>lr_mult=1.0</em>, <em>wd_mult=1.0</em>, <em>init=None</em>, <em>allow_deferred_init=False</em>, <em>differentiable=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A Container holding parameters (weights) of Blocks.</p> |
| <p><a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a> holds a copy of the parameter on each <code class="xref py py-class docutils literal"><span class="pre">Context</span></code> after |
| it is initialized with <code class="docutils literal"><span class="pre">Parameter.initialize(...)</span></code>. If <a class="reference internal" href="#mxnet.gluon.Parameter.grad_req" title="mxnet.gluon.Parameter.grad_req"><code class="xref py py-attr docutils literal"><span class="pre">grad_req</span></code></a> is |
| not <code class="docutils literal"><span class="pre">'null'</span></code>, it will also hold a gradient array on each <code class="xref py py-class docutils literal"><span class="pre">Context</span></code>:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> |
| <span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">16</span><span class="p">,</span> <span class="mi">100</span><span class="p">),</span> <span class="n">ctx</span><span class="o">=</span><span class="n">ctx</span><span class="p">)</span> |
| <span class="n">w</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">gluon</span><span class="o">.</span><span class="n">Parameter</span><span class="p">(</span><span class="s1">'fc_weight'</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">64</span><span class="p">,</span> <span class="mi">100</span><span class="p">),</span> <span class="n">init</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">init</span><span class="o">.</span><span class="n">Xavier</span><span class="p">())</span> |
| <span class="n">b</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">gluon</span><span class="o">.</span><span class="n">Parameter</span><span class="p">(</span><span class="s1">'fc_bias'</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">64</span><span class="p">,),</span> <span class="n">init</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">init</span><span class="o">.</span><span class="n">Zero</span><span class="p">())</span> |
| <span class="n">w</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="n">ctx</span><span class="p">)</span> |
| <span class="n">b</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="n">ctx</span><span class="p">)</span> |
| <span class="n">out</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">FullyConnected</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">w</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">ctx</span><span class="p">),</span> <span class="n">b</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">ctx</span><span class="p">),</span> <span class="n">num_hidden</span><span class="o">=</span><span class="mi">64</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>name</strong> (<em>str</em>) – Name of this parameter.</li> |
| <li><strong>grad_req</strong> (<em>{'write', 'add', 'null'}, default 'write'</em>) – <p>Specifies how to update gradient to grad arrays.</p> |
| <ul> |
| <li><code class="docutils literal"><span class="pre">'write'</span></code> means everytime gradient is written to grad <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code>.</li> |
| <li><code class="docutils literal"><span class="pre">'add'</span></code> means everytime gradient is added to the grad <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code>. You need |
| to manually call <code class="docutils literal"><span class="pre">zero_grad()</span></code> to clear the gradient buffer before each |
| iteration when using this option.</li> |
| <li>‘null’ means gradient is not requested for this parameter. gradient arrays |
| will not be allocated.</li> |
| </ul> |
| </li> |
| <li><strong>shape</strong> (<em>tuple of int, default None</em>) – Shape of this parameter. By default shape is not specified. Parameter with |
| unknown shape can be used for <code class="xref py py-class docutils literal"><span class="pre">Symbol</span></code> API, but <code class="docutils literal"><span class="pre">init</span></code> will throw an error |
| when using <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code> API.</li> |
| <li><strong>dtype</strong> (<em>numpy.dtype or str, default 'float32'</em>) – Data type of this parameter. For example, <code class="docutils literal"><span class="pre">numpy.float32</span></code> or <code class="docutils literal"><span class="pre">'float32'</span></code>.</li> |
| <li><strong>lr_mult</strong> (<em>float, default 1.0</em>) – Learning rate multiplier. Learning rate will be multiplied by lr_mult |
| when updating this parameter with optimizer.</li> |
| <li><strong>wd_mult</strong> (<em>float, default 1.0</em>) – Weight decay multiplier (L2 regularizer coefficient). Works similar to lr_mult.</li> |
| <li><strong>init</strong> (<em>Initializer, default None</em>) – Initializer of this parameter. Will use the global initializer by default.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.Parameter.grad_req"> |
| <code class="descname">grad_req</code><a class="headerlink" href="#mxnet.gluon.Parameter.grad_req" title="Permalink to this definition">¶</a></dt> |
| <dd><p><em>{‘write’, ‘add’, ‘null’}</em></p> |
| <p>This can be set before or after initialization. Setting <code class="docutils literal"><span class="pre">grad_req</span></code> to <code class="docutils literal"><span class="pre">'null'</span></code> |
| with <code class="docutils literal"><span class="pre">x.grad_req</span> <span class="pre">=</span> <span class="pre">'null'</span></code> saves memory and computation when you don’t |
| need gradient w.r.t x.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.Parameter.lr_mult"> |
| <code class="descname">lr_mult</code><a class="headerlink" href="#mxnet.gluon.Parameter.lr_mult" title="Permalink to this definition">¶</a></dt> |
| <dd><p><em>float</em></p> |
| <p>Local learning rate multiplier for this Parameter. The actual learning rate |
| is calculated with <code class="docutils literal"><span class="pre">learning_rate</span> <span class="pre">*</span> <span class="pre">lr_mult</span></code>. You can set it with |
| <code class="docutils literal"><span class="pre">param.lr_mult</span> <span class="pre">=</span> <span class="pre">2.0</span></code></p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.Parameter.wd_mult"> |
| <code class="descname">wd_mult</code><a class="headerlink" href="#mxnet.gluon.Parameter.wd_mult" title="Permalink to this definition">¶</a></dt> |
| <dd><p><em>float</em></p> |
| <p>Local weight decay multiplier for this Parameter.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.Parameter.__weakref__"> |
| <code class="descname">__weakref__</code><a class="headerlink" href="#mxnet.gluon.Parameter.__weakref__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>list of weak references to the object (if defined)</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.cast"> |
| <code class="descname">cast</code><span class="sig-paren">(</span><em>dtype</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.cast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.cast" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Cast data and gradient of this Parameter to a new data type.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>dtype</strong> (<em>str or numpy.dtype</em>) – The new data type.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.data"> |
| <code class="descname">data</code><span class="sig-paren">(</span><em>ctx=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.data" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a copy of this parameter on one context. Must have been |
| initialized on this context before.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ctx</strong> (<em>Context</em>) – Desired context.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">NDArray on ctx</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.grad"> |
| <code class="descname">grad</code><span class="sig-paren">(</span><em>ctx=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.grad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.grad" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a gradient buffer for this parameter on one context.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ctx</strong> (<em>Context</em>) – Desired context.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.initialize"> |
| <code class="descname">initialize</code><span class="sig-paren">(</span><em>init=None</em>, <em>ctx=None</em>, <em>default_init=<mxnet.initializer.Uniform object></em>, <em>force_reinit=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.initialize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.initialize" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Initializes parameter and gradient arrays. Only used for <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code> API.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>init</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – The initializer to use. Overrides <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> and default_init.</li> |
| <li><strong>ctx</strong> (Context or list of Context, defaults to <code class="xref py py-meth docutils literal"><span class="pre">context.current_context()</span></code>.) – <p>Initialize Parameter on given context. If ctx is a list of Context, a |
| copy will be made for each context.</p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">Copies are independent arrays. User is responsible for keeping |
| their values consistent when updating. |
| Normally <code class="xref py py-class docutils literal"><span class="pre">gluon.Trainer</span></code> does this for you.</p> |
| </div> |
| </li> |
| <li><strong>default_init</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – Default initializer is used when both <code class="xref py py-func docutils literal"><span class="pre">init()</span></code> |
| and <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> are <code class="docutils literal"><span class="pre">None</span></code>.</li> |
| <li><strong>force_reinit</strong> (<em>bool, default False</em>) – Whether to force re-initialization if parameter is already initialized.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">weight</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">gluon</span><span class="o">.</span><span class="n">Parameter</span><span class="p">(</span><span class="s1">'weight'</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">data</span><span class="p">()</span> |
| <span class="go">[[-0.01068833 0.01729892]</span> |
| <span class="go"> [ 0.02042518 -0.01618656]]</span> |
| <span class="go"><NDArray 2x2 @cpu(0)></span> |
| <span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">grad</span><span class="p">()</span> |
| <span class="go">[[ 0. 0.]</span> |
| <span class="go"> [ 0. 0.]]</span> |
| <span class="go"><NDArray 2x2 @cpu(0)></span> |
| <span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">1</span><span class="p">)])</span> |
| <span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> |
| <span class="go">[[-0.00873779 -0.02834515]</span> |
| <span class="go"> [ 0.05484822 -0.06206018]]</span> |
| <span class="go"><NDArray 2x2 @gpu(0)></span> |
| <span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> |
| <span class="go">[[-0.00873779 -0.02834515]</span> |
| <span class="go"> [ 0.05484822 -0.06206018]]</span> |
| <span class="go"><NDArray 2x2 @gpu(1)></span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.list_ctx"> |
| <code class="descname">list_ctx</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.list_ctx"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.list_ctx" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a list of contexts this parameter is initialized on.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.list_data"> |
| <code class="descname">list_data</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.list_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.list_data" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns copies of this parameter on all contexts, in the same order |
| as creation.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.list_grad"> |
| <code class="descname">list_grad</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.list_grad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.list_grad" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns gradient buffers on all contexts, in the same order |
| as <code class="xref py py-meth docutils literal"><span class="pre">values()</span></code>.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.reset_ctx"> |
| <code class="descname">reset_ctx</code><span class="sig-paren">(</span><em>ctx</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.reset_ctx"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.reset_ctx" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Re-assign Parameter to other contexts.</p> |
| <dl class="docutils"> |
| <dt>ctx <span class="classifier-delimiter">:</span> <span class="classifier">Context or list of Context, default <code class="docutils literal"><span class="pre">context.current_context()</span></code>.</span></dt> |
| <dd>Assign Parameter to given context. If ctx is a list of Context, a |
| copy will be made for each context.</dd> |
| </dl> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.set_data"> |
| <code class="descname">set_data</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.set_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.set_data" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Sets this parameter’s value on all contexts.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.var"> |
| <code class="descname">var</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.var"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.var" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Returns a symbol representing this parameter.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Parameter.zero_grad"> |
| <code class="descname">zero_grad</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.zero_grad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.zero_grad" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Sets gradient buffer on all contexts to 0. No action is taken if |
| parameter is uninitialized or doesn’t require gradient.</p> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.gluon.ParameterDict"> |
| <em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">ParameterDict</code><span class="sig-paren">(</span><em>prefix=''</em>, <em>shared=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A dictionary managing a set of parameters.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>prefix</strong> (str, default <code class="docutils literal"><span class="pre">''</span></code>) – The prefix to be prepended to all Parameters’ names created by this dict.</li> |
| <li><strong>shared</strong> (<em>ParameterDict or None</em>) – If not <code class="docutils literal"><span class="pre">None</span></code>, when this dict’s <a class="reference internal" href="#mxnet.gluon.ParameterDict.get" title="mxnet.gluon.ParameterDict.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a> method creates a new parameter, will |
| first try to retrieve it from “shared” dict. Usually used for sharing |
| parameters with another Block.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.ParameterDict.__weakref__"> |
| <code class="descname">__weakref__</code><a class="headerlink" href="#mxnet.gluon.ParameterDict.__weakref__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>list of weak references to the object (if defined)</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.ParameterDict.get"> |
| <code class="descname">get</code><span class="sig-paren">(</span><em>name</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.get"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.get" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Retrieves a <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a> with name <code class="docutils literal"><span class="pre">self.prefix+name</span></code>. If not found, |
| <a class="reference internal" href="#mxnet.gluon.ParameterDict.get" title="mxnet.gluon.ParameterDict.get"><code class="xref py py-func docutils literal"><span class="pre">get()</span></code></a> will first try to retrieve it from “shared” dict. If still not |
| found, <a class="reference internal" href="#mxnet.gluon.ParameterDict.get" title="mxnet.gluon.ParameterDict.get"><code class="xref py py-func docutils literal"><span class="pre">get()</span></code></a> will create a new <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a> with key-word arguments and |
| insert it to self.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>name</strong> (<em>str</em>) – Name of the desired Parameter. It will be prepended with this dictionary’s |
| prefix.</li> |
| <li><strong>**kwargs</strong> – <p>The rest of key-word arguments for the created <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a>.</p> |
| </li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The created or retrieved <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a>.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter">Parameter</a></p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.ParameterDict.initialize"> |
| <code class="descname">initialize</code><span class="sig-paren">(</span><em>init=<mxnet.initializer.Uniform object></em>, <em>ctx=None</em>, <em>verbose=False</em>, <em>force_reinit=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.initialize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.initialize" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Initializes all Parameters managed by this dictionary to be used for <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code> |
| API. It has no effect when using <code class="xref py py-class docutils literal"><span class="pre">Symbol</span></code> API.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>init</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – Global default Initializer to be used when <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> is <code class="docutils literal"><span class="pre">None</span></code>. |
| Otherwise, <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> takes precedence.</li> |
| <li><strong>ctx</strong> (<em>Context or list of Context</em>) – Keeps a copy of Parameters on one or many context(s).</li> |
| <li><strong>force_reinit</strong> (<em>bool, default False</em>) – Whether to force re-initialization if parameter is already initialized.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.ParameterDict.load"> |
| <code class="descname">load</code><span class="sig-paren">(</span><em>filename</em>, <em>ctx</em>, <em>allow_missing=False</em>, <em>ignore_extra=False</em>, <em>restore_prefix=''</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.load"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.load" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Load parameters from file.</p> |
| <dl class="docutils"> |
| <dt>filename <span class="classifier-delimiter">:</span> <span class="classifier">str</span></dt> |
| <dd>Path to parameter file.</dd> |
| <dt>ctx <span class="classifier-delimiter">:</span> <span class="classifier">Context or list of Context</span></dt> |
| <dd>Context(s) initialize loaded parameters on.</dd> |
| <dt>allow_missing <span class="classifier-delimiter">:</span> <span class="classifier">bool, default False</span></dt> |
| <dd>Whether to silently skip loading parameters not represents in the file.</dd> |
| <dt>ignore_extra <span class="classifier-delimiter">:</span> <span class="classifier">bool, default False</span></dt> |
| <dd>Whether to silently ignore parameters from the file that are not |
| present in this ParameterDict.</dd> |
| <dt>restore_prefix <span class="classifier-delimiter">:</span> <span class="classifier">str, default ‘’</span></dt> |
| <dd>prepend prefix to names of stored parameters before loading.</dd> |
| </dl> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.ParameterDict.prefix"> |
| <code class="descname">prefix</code><a class="headerlink" href="#mxnet.gluon.ParameterDict.prefix" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Prefix of this dict. It will be prepended to <code class="xref py py-class docutils literal"><span class="pre">Parameter`s'</span> <span class="pre">name</span> <span class="pre">created</span> |
| <span class="pre">with</span> <span class="pre">:py:func:`get</span></code>.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.ParameterDict.reset_ctx"> |
| <code class="descname">reset_ctx</code><span class="sig-paren">(</span><em>ctx</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.reset_ctx"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.reset_ctx" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Re-assign all Parameters to other contexts.</p> |
| <dl class="docutils"> |
| <dt>ctx <span class="classifier-delimiter">:</span> <span class="classifier">Context or list of Context, default <code class="xref py py-meth docutils literal"><span class="pre">context.current_context()</span></code>.</span></dt> |
| <dd>Assign Parameter to given context. If ctx is a list of Context, a |
| copy will be made for each context.</dd> |
| </dl> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.ParameterDict.save"> |
| <code class="descname">save</code><span class="sig-paren">(</span><em>filename</em>, <em>strip_prefix=''</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.save"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.save" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Save parameters to file.</p> |
| <dl class="docutils"> |
| <dt>filename <span class="classifier-delimiter">:</span> <span class="classifier">str</span></dt> |
| <dd>Path to parameter file.</dd> |
| <dt>strip_prefix <span class="classifier-delimiter">:</span> <span class="classifier">str, default ‘’</span></dt> |
| <dd>Strip prefix from parameter names before saving.</dd> |
| </dl> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.ParameterDict.setattr"> |
| <code class="descname">setattr</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.setattr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.setattr" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Set an attribute to a new value for all Parameters.</p> |
| <p>For example, set grad_req to null if you don’t need gradient w.r.t a |
| model’s Parameters:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">model</span><span class="o">.</span><span class="n">collect_params</span><span class="p">()</span><span class="o">.</span><span class="n">setattr</span><span class="p">(</span><span class="s1">'grad_req'</span><span class="p">,</span> <span class="s1">'null'</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>or change the learning rate multiplier:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">model</span><span class="o">.</span><span class="n">collect_params</span><span class="p">()</span><span class="o">.</span><span class="n">setattr</span><span class="p">(</span><span class="s1">'lr_mult'</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>name</strong> (<em>str</em>) – Name of the attribute.</li> |
| <li><strong>value</strong> (<em>valid type for attribute name</em>) – The new value for the attribute.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.ParameterDict.update"> |
| <code class="descname">update</code><span class="sig-paren">(</span><em>other</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.update"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.update" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Copies all Parameters in <code class="docutils literal"><span class="pre">other</span></code> to self.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.ParameterDict.zero_grad"> |
| <code class="descname">zero_grad</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.zero_grad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.zero_grad" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Sets all Parameters’ gradient buffer to 0.</p> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.gluon.SymbolBlock"> |
| <em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">SymbolBlock</code><span class="sig-paren">(</span><em>outputs</em>, <em>inputs</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#SymbolBlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.SymbolBlock" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Construct block from symbol. This is useful for using pre-trained models |
| as feature extractors. For example, you may want to extract get the output |
| from fc2 layer in AlexNet.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>outputs</strong> (<em>Symbol or list of Symbol</em>) – The desired output for SymbolBlock.</li> |
| <li><strong>inputs</strong> (<em>Symbol or list of Symbol</em>) – The Variables in output’s argument that should be used as inputs.</li> |
| <li><strong>params</strong> (<a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><em>ParameterDict</em></a>) – Parameter dictionary for arguments and auxililary states of outputs |
| that are not inputs.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># To extract the feature from fc1 and fc2 layers of AlexNet:</span> |
| <span class="gp">>>> </span><span class="n">alexnet</span> <span class="o">=</span> <span class="n">gluon</span><span class="o">.</span><span class="n">model_zoo</span><span class="o">.</span><span class="n">vision</span><span class="o">.</span><span class="n">alexnet</span><span class="p">(</span><span class="n">pretrained</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(),</span> |
| <span class="go"> prefix='model_')</span> |
| <span class="gp">>>> </span><span class="n">inputs</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">sym</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s1">'data'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">out</span> <span class="o">=</span> <span class="n">alexnet</span><span class="p">(</span><span class="n">inputs</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">internals</span> <span class="o">=</span> <span class="n">out</span><span class="o">.</span><span class="n">get_internals</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">internals</span><span class="o">.</span><span class="n">list_outputs</span><span class="p">())</span> |
| <span class="go">['data', ..., 'model_dense0_relu_fwd_output', ..., 'model_dense1_relu_fwd_output', ...]</span> |
| <span class="gp">>>> </span><span class="n">outputs</span> <span class="o">=</span> <span class="p">[</span><span class="n">internals</span><span class="p">[</span><span class="s1">'model_dense0_relu_fwd_output'</span><span class="p">],</span> |
| <span class="go"> internals['model_dense1_relu_fwd_output']]</span> |
| <span class="gp">>>> </span><span class="c1"># Create SymbolBlock that shares parameters with alexnet</span> |
| <span class="gp">>>> </span><span class="n">feat_model</span> <span class="o">=</span> <span class="n">gluon</span><span class="o">.</span><span class="n">SymbolBlock</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">alexnet</span><span class="o">.</span><span class="n">collect_params</span><span class="p">())</span> |
| <span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</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="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">16</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">224</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">feat_model</span><span class="p">(</span><span class="n">x</span><span class="p">))</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.gluon.Trainer"> |
| <em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">Trainer</code><span class="sig-paren">(</span><em>params</em>, <em>optimizer</em>, <em>optimizer_params=None</em>, <em>kvstore='device'</em>, <em>compression_params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Applies an <cite>Optimizer</cite> on a set of Parameters. Trainer should |
| be used together with <cite>autograd</cite>.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>params</strong> (<a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><em>ParameterDict</em></a>) – The set of parameters to optimize.</li> |
| <li><strong>optimizer</strong> (<em>str or Optimizer</em>) – The optimizer to use. See |
| <a class="reference external" href="https://mxnet.incubator.apache.org/versions/master/api/python/optimization.html#the-mxnet-optimizer-package">help</a> |
| on Optimizer for a list of available optimizers.</li> |
| <li><strong>optimizer_params</strong> (<em>dict</em>) – Key-word arguments to be passed to optimizer constructor. For example, |
| <cite>{‘learning_rate’: 0.1}</cite>. All optimizers accept learning_rate, wd (weight decay), |
| clip_gradient, and lr_scheduler. See each optimizer’s |
| constructor for a list of additional supported arguments.</li> |
| <li><strong>kvstore</strong> (<em>str or KVStore</em>) – kvstore type for multi-gpu and distributed training. See help on |
| <a class="reference internal" href="../kvstore/kvstore.html#mxnet.kvstore.create" title="mxnet.kvstore.create"><code class="xref any py py-func docutils literal"><span class="pre">mxnet.kvstore.create</span></code></a> for more information.</li> |
| <li><strong>compression_params</strong> (<em>dict</em>) – Specifies type of gradient compression and additional arguments depending |
| on the type of compression being used. For example, 2bit compression requires a threshold. |
| Arguments would then be {‘type’:‘2bit’, ‘threshold’:0.5} |
| See mxnet.KVStore.set_gradient_compression method for more details on gradient compression.</li> |
| <li><strong>Properties</strong> – </li> |
| <li><strong>----------</strong> – </li> |
| <li><strong>learning_rate</strong> (<em>float</em>) – The current learning rate of the optimizer. Given an Optimizer object |
| optimizer, its learning rate can be accessed as optimizer.learning_rate.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <dl class="attribute"> |
| <dt id="mxnet.gluon.Trainer.__weakref__"> |
| <code class="descname">__weakref__</code><a class="headerlink" href="#mxnet.gluon.Trainer.__weakref__" title="Permalink to this definition">¶</a></dt> |
| <dd><p>list of weak references to the object (if defined)</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Trainer.load_states"> |
| <code class="descname">load_states</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.load_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.load_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Loads trainer states (e.g. optimizer, momentum) from a file.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fname</strong> (<em>str</em>) – Path to input states file.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Trainer.save_states"> |
| <code class="descname">save_states</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.save_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.save_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Saves trainer states (e.g. optimizer, momentum) to a file.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fname</strong> (<em>str</em>) – Path to output states file.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Trainer.set_learning_rate"> |
| <code class="descname">set_learning_rate</code><span class="sig-paren">(</span><em>lr</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.set_learning_rate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.set_learning_rate" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Sets a new learning rate of the optimizer.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>lr</strong> (<em>float</em>) – The new learning rate of the optimizer.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.Trainer.step"> |
| <code class="descname">step</code><span class="sig-paren">(</span><em>batch_size</em>, <em>ignore_stale_grad=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.step"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.step" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Makes one step of parameter update. Should be called after |
| <cite>autograd.compute_gradient</cite> and outside of <cite>record()</cite> scope.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>batch_size</strong> (<em>int</em>) – Batch size of data processed. Gradient will be normalized by <cite>1/batch_size</cite>. |
| Set this to 1 if you normalized loss manually with <cite>loss = mean(loss)</cite>.</li> |
| <li><strong>ignore_stale_grad</strong> (<em>bool, optional, default=False</em>) – If true, ignores Parameters with stale gradient (gradient that has not |
| been updated by <cite>backward</cite> after last step) and skip update.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.gluon.nn.Sequential"> |
| <em class="property">class </em><code class="descclassname">mxnet.gluon.nn.</code><code class="descname">Sequential</code><span class="sig-paren">(</span><em>prefix=None</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#Sequential"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.Sequential" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Stacks Blocks sequentially.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">net</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Sequential</span><span class="p">()</span> |
| <span class="c1"># use net's name_scope to give child Blocks appropriate names.</span> |
| <span class="k">with</span> <span class="n">net</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span> |
| <span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">activation</span><span class="o">=</span><span class="s1">'relu'</span><span class="p">))</span> |
| <span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">))</span> |
| </pre></div> |
| </div> |
| <dl class="method"> |
| <dt id="mxnet.gluon.nn.Sequential.add"> |
| <code class="descname">add</code><span class="sig-paren">(</span><em>*blocks</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#Sequential.add"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.Sequential.add" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Adds block on top of the stack.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.gluon.nn.Sequential.hybridize"> |
| <code class="descname">hybridize</code><span class="sig-paren">(</span><em>active=True</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#Sequential.hybridize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.Sequential.hybridize" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Activates or deactivates <a href="#id17"><span class="problematic" id="id18">`</span></a>HybridBlock`s recursively. Has no effect on |
| non-hybrid children.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> |
| <li><strong>active</strong> (<em>bool, default True</em>) – Whether to turn hybrid on or off.</li> |
| <li><strong>**kwargs</strong> – <p>Additional flags for hybridized operator.</p> |
| </li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.gluon.nn.HybridSequential"> |
| <em class="property">class </em><code class="descclassname">mxnet.gluon.nn.</code><code class="descname">HybridSequential</code><span class="sig-paren">(</span><em>prefix=None</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#HybridSequential"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.HybridSequential" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Stacks HybridBlocks sequentially.</p> |
| <p>Example:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">net</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">HybridSequential</span><span class="p">()</span> |
| <span class="c1"># use net's name_scope to give child Blocks appropriate names.</span> |
| <span class="k">with</span> <span class="n">net</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span> |
| <span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">activation</span><span class="o">=</span><span class="s1">'relu'</span><span class="p">))</span> |
| <span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">))</span> |
| <span class="n">net</span><span class="o">.</span><span class="n">hybridize</span><span class="p">()</span> |
| </pre></div> |
| </div> |
| <dl class="method"> |
| <dt id="mxnet.gluon.nn.HybridSequential.add"> |
| <code class="descname">add</code><span class="sig-paren">(</span><em>*blocks</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#HybridSequential.add"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.HybridSequential.add" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Adds block on top of the stack.</p> |
| </dd></dl> |
| </dd></dl> |
| <span class="target" id="module-mxnet.gluon.utils"></span><p>Parallelization utility optimizer.</p> |
| <dl class="function"> |
| <dt id="mxnet.gluon.utils.split_data"> |
| <code class="descclassname">mxnet.gluon.utils.</code><code class="descname">split_data</code><span class="sig-paren">(</span><em>data</em>, <em>num_slice</em>, <em>batch_axis=0</em>, <em>even_split=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#split_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.split_data" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Splits an NDArray into <cite>num_slice</cite> slices along <cite>batch_axis</cite>. |
| Usually used for data parallelism where each slices is sent |
| to one device (i.e. GPU).</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – A batch of data.</li> |
| <li><strong>num_slice</strong> (<em>int</em>) – Number of desired slices.</li> |
| <li><strong>batch_axis</strong> (<em>int, default 0</em>) – The axis along which to slice.</li> |
| <li><strong>even_split</strong> (<em>bool, default True</em>) – Whether to force all slices to have the same number of elements. |
| If <cite>True</cite>, an error will be raised when <cite>num_slice</cite> does not evenly |
| divide <cite>data.shape[batch_axis]</cite>.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Return value is a list even if <cite>num_slice</cite> is 1.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list of NDArray</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.gluon.utils.split_and_load"> |
| <code class="descclassname">mxnet.gluon.utils.</code><code class="descname">split_and_load</code><span class="sig-paren">(</span><em>data</em>, <em>ctx_list</em>, <em>batch_axis=0</em>, <em>even_split=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#split_and_load"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.split_and_load" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Splits an NDArray into <cite>len(ctx_list)</cite> slices along <cite>batch_axis</cite> and loads |
| each slice to one context in <cite>ctx_list</cite>.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>data</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – A batch of data.</li> |
| <li><strong>ctx_list</strong> (<em>list of Context</em>) – A list of Contexts.</li> |
| <li><strong>batch_axis</strong> (<em>int, default 0</em>) – The axis along which to slice.</li> |
| <li><strong>even_split</strong> (<em>bool, default True</em>) – Whether to force all slices to have the same number of elements.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Each corresponds to a context in <cite>ctx_list</cite>.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list of NDArray</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.gluon.utils.clip_global_norm"> |
| <code class="descclassname">mxnet.gluon.utils.</code><code class="descname">clip_global_norm</code><span class="sig-paren">(</span><em>arrays</em>, <em>max_norm</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#clip_global_norm"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.clip_global_norm" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Rescales NDArrays so that the sum of their 2-norm is smaller than <cite>max_norm</cite>.</p> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.gluon.utils.check_sha1"> |
| <code class="descclassname">mxnet.gluon.utils.</code><code class="descname">check_sha1</code><span class="sig-paren">(</span><em>filename</em>, <em>sha1_hash</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#check_sha1"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.check_sha1" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Check whether the sha1 hash of the file content matches the expected hash.</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>filename</strong> (<em>str</em>) – Path to the file.</li> |
| <li><strong>sha1_hash</strong> (<em>str</em>) – Expected sha1 hash in hexadecimal digits.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Whether the file content matches the expected hash.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="function"> |
| <dt id="mxnet.gluon.utils.download"> |
| <code class="descclassname">mxnet.gluon.utils.</code><code class="descname">download</code><span class="sig-paren">(</span><em>url</em>, <em>path=None</em>, <em>overwrite=False</em>, <em>sha1_hash=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#download"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.download" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Download an given URL</p> |
| <table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name"/> |
| <col class="field-body"/> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>url</strong> (<em>str</em>) – URL to download</li> |
| <li><strong>path</strong> (<em>str, optional</em>) – Destination path to store downloaded file. By default stores to the |
| current directory with same name as in url.</li> |
| <li><strong>overwrite</strong> (<em>bool, optional</em>) – Whether to overwrite destination file if already exists.</li> |
| <li><strong>sha1_hash</strong> (<em>str, optional</em>) – Expected sha1 hash in hexadecimal digits. Will ignore existing file when hash is specified |
| but doesn’t match.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The file path of the downloaded file.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <script>auto_index("api-reference");</script></div> |
| </div> |
| </div> |
| </div> |
| <div aria-label="main navigation" class="sphinxsidebar rightsidebar" role="navigation"> |
| <div class="sphinxsidebarwrapper"> |
| <h3><a href="../../../index.html">Table Of Contents</a></h3> |
| <ul> |
| <li><a class="reference internal" href="#">Gluon Package</a><ul> |
| <li><a class="reference internal" href="#overview">Overview</a></li> |
| <li><a class="reference internal" href="#parameter">Parameter</a></li> |
| <li><a class="reference internal" href="#containers">Containers</a></li> |
| <li><a class="reference internal" href="#trainer">Trainer</a></li> |
| <li><a class="reference internal" href="#utilities">Utilities</a></li> |
| <li><a class="reference internal" href="#api-reference">API Reference</a></li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </div><div class="footer"> |
| <div class="section-disclaimer"> |
| <div class="container"> |
| <div> |
| <img height="60" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/apache_incubator_logo.png"/> |
| <p> |
| Apache MXNet is an effort undergoing incubation at The Apache Software Foundation (ASF), <strong>sponsored by the <i>Apache Incubator</i></strong>. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF. |
| </p> |
| <p> |
| "Copyright © 2017-2018, The Apache Software Foundation |
| Apache MXNet, MXNet, Apache, the Apache feather, and the Apache MXNet project logo are either registered trademarks or trademarks of the Apache Software Foundation." |
| </p> |
| </div> |
| </div> |
| </div> |
| </div> <!-- pagename != index --> |
| </div> |
| <script crossorigin="anonymous" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> |
| <script src="../../../_static/js/sidebar.js" type="text/javascript"></script> |
| <script src="../../../_static/js/search.js" type="text/javascript"></script> |
| <script src="../../../_static/js/navbar.js" type="text/javascript"></script> |
| <script src="../../../_static/js/clipboard.min.js" type="text/javascript"></script> |
| <script src="../../../_static/js/copycode.js" type="text/javascript"></script> |
| <script src="../../../_static/js/page.js" type="text/javascript"></script> |
| <script type="text/javascript"> |
| $('body').ready(function () { |
| $('body').css('visibility', 'visible'); |
| }); |
| </script> |
| </body> |
| </html> |