| <!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"/> |
| <meta content="Module API" property="og:title"> |
| <meta content="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/og-logo.png" property="og:image"> |
| <meta content="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/og-logo.png" property="og:image:secure_url"> |
| <meta content="Module API" property="og:description"/> |
| <title>Module API — 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: '.txt' |
| }; |
| </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("/versions/1.4.1/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://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> --> |
| <!-- --> |
| <link href="../../../genindex.html" rel="index" title="Index"> |
| <link href="../../../search.html" rel="search" title="Search"/> |
| <link href="../index.html" rel="up" title="MXNet - Python API"/> |
| <link href="../executor/executor.html" rel="next" title="Executor and Executor Manager"/> |
| <link href="../metric/metric.html" rel="prev" title="Evaluation Metric API"/> |
| <link href="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-icon.png" rel="icon" type="image/png"/> |
| </link></link></link></meta></meta></meta></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="/versions/1.4.1/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="/versions/1.4.1/tutorials/gluon/gluon.html">About</a></li> |
| <li><a class="main-nav-link" href="https://www.d2l.ai/">Dive into Deep Learning</a></li> |
| <li><a class="main-nav-link" href="https://gluon-cv.mxnet.io">GluonCV Toolkit</a></li> |
| <li><a class="main-nav-link" href="https://gluon-nlp.mxnet.io/">GluonNLP Toolkit</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="/versions/1.4.1/api/python/index.html">Python</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/c++/index.html">C++</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/clojure/index.html">Clojure</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/java/index.html">Java</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/julia/index.html">Julia</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/perl/index.html">Perl</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/r/index.html">R</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/scala/index.html">Scala</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="/versions/1.4.1/faq/index.html">FAQ</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/tutorials/index.html">Tutorials</a> |
| <li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/1.4.1/example">Examples</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/architecture/index.html">Architecture</a></li> |
| <li><a class="main-nav-link" href="https://cwiki.apache.org/confluence/display/MXNET/Apache+MXNet+Home">Developer Wiki</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/model_zoo/index.html">Model Zoo</a></li> |
| <li><a class="main-nav-link" href="https://github.com/onnx/onnx-mxnet">ONNX</a></li> |
| </li></ul> |
| </span> |
| <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="http://discuss.mxnet.io">Forum</a></li> |
| <li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/1.4.1">Github</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/community/contribute.html">Contribute</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/community/ecosystem.html">Ecosystem</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/community/powered_by.html">Powered By</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">1.4.1<span class="caret"></span></a><ul id="package-dropdown-menu" class="dropdown-menu"><li><a href="/">master</a></li><li><a href="/versions/1.7.0/">1.7.0</a></li><li><a href=/versions/1.6.0/>1.6.0</a></li><li><a href=/versions/1.5.0/>1.5.0</a></li><li><a href=/versions/1.4.1/>1.4.1</a></li><li><a href=/versions/1.3.1/>1.3.1</a></li><li><a href=/versions/1.2.1/>1.2.1</a></li><li><a href=/versions/1.1.0/>1.1.0</a></li><li><a href=/versions/1.0.0/>1.0.0</a></li><li><a href=/versions/0.12.1/>0.12.1</a></li><li><a href=/versions/0.11.0/>0.11.0</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="/versions/1.4.1/install/index.html">Install</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/tutorials/index.html">Tutorials</a></li> |
| <li class="dropdown-submenu dropdown"> |
| <a aria-expanded="true" aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" tabindex="-1">Gluon</a> |
| <ul class="dropdown-menu navbar-menu" id="package-dropdown-menu"> |
| <li><a class="main-nav-link" href="/versions/1.4.1/tutorials/gluon/gluon.html">About</a></li> |
| <li><a class="main-nav-link" href="http://gluon.mxnet.io">The Straight Dope (Tutorials)</a></li> |
| <li><a class="main-nav-link" href="https://gluon-cv.mxnet.io">GluonCV Toolkit</a></li> |
| <li><a class="main-nav-link" href="https://gluon-nlp.mxnet.io/">GluonNLP Toolkit</a></li> |
| </ul> |
| </li> |
| <li class="dropdown-submenu"> |
| <a aria-expanded="true" aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" tabindex="-1">API</a> |
| <ul class="dropdown-menu"> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/python/index.html">Python</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/c++/index.html">C++</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/clojure/index.html">Clojure</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/java/index.html">Java</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/julia/index.html">Julia</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/perl/index.html">Perl</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/r/index.html">R</a></li> |
| <li><a class="main-nav-link" href="/versions/1.4.1/api/scala/index.html">Scala</a></li> |
| </ul> |
| </li> |
| <li class="dropdown-submenu"> |
| <a aria-expanded="true" aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" tabindex="-1">Docs</a> |
| <ul class="dropdown-menu"> |
| <li><a href="/versions/1.4.1/faq/index.html" tabindex="-1">FAQ</a></li> |
| <li><a href="/versions/1.4.1/tutorials/index.html" tabindex="-1">Tutorials</a></li> |
| <li><a href="https://github.com/apache/incubator-mxnet/tree/1.4.1/example" tabindex="-1">Examples</a></li> |
| <li><a href="/versions/1.4.1/architecture/index.html" tabindex="-1">Architecture</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/MXNET/Apache+MXNet+Home" tabindex="-1">Developer Wiki</a></li> |
| <li><a href="/versions/1.4.1/model_zoo/index.html" tabindex="-1">Gluon Model Zoo</a></li> |
| <li><a href="https://github.com/onnx/onnx-mxnet" tabindex="-1">ONNX</a></li> |
| </ul> |
| </li> |
| <li class="dropdown-submenu dropdown"> |
| <a aria-haspopup="true" class="dropdown-toggle burger-link" data-toggle="dropdown" href="#" role="button" tabindex="-1">Community</a> |
| <ul class="dropdown-menu"> |
| <li><a href="http://discuss.mxnet.io" tabindex="-1">Forum</a></li> |
| <li><a href="https://github.com/apache/incubator-mxnet/tree/1.4.1" tabindex="-1">Github</a></li> |
| <li><a href="/versions/1.4.1/community/contribute.html" tabindex="-1">Contribute</a></li> |
| <li><a href="/versions/1.4.1/community/ecosystem.html" tabindex="-1">Ecosystem</a></li> |
| <li><a href="/versions/1.4.1/community/powered_by.html" tabindex="-1">Powered By</a></li> |
| </ul> |
| </li> |
| <li id="dropdown-menu-position-anchor-version-mobile" class="dropdown-submenu" style="position: relative"><a href="#" tabindex="-1">1.4.1</a><ul class="dropdown-menu"><li><a tabindex="-1" href=/>master</a></li><li><a tabindex="-1" href=/versions/1.6.0/>1.6.0</a></li><li><a tabindex="-1" href=/versions/1.5.0/>1.5.0</a></li><li><a tabindex="-1" href=/versions/1.4.1/>1.4.1</a></li><li><a tabindex="-1" href=/versions/1.3.1/>1.3.1</a></li><li><a tabindex="-1" href=/versions/1.2.1/>1.2.1</a></li><li><a tabindex="-1" href=/versions/1.1.0/>1.1.0</a></li><li><a tabindex="-1" href=/versions/1.0.0/>1.0.0</a></li><li><a tabindex="-1" href=/versions/0.12.1/>0.12.1</a></li><li><a tabindex="-1" href=/versions/0.11.0/>0.11.0</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">MXNet APIs</a><ul class="current"> |
| <li class="toctree-l2"><a class="reference internal" href="../../c++/index.html">MXNet - C++ API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../clojure/index.html">MXNet - Clojure API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../julia/index.html">MXNet - Julia API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../perl/index.html">MXNet - Perl API</a></li> |
| <li class="toctree-l2 current"><a class="reference internal" href="../index.html">MXNet - Python API</a><ul class="current"> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#autograd-api">Autograd API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#callback-api">Callback API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#contrib-package">Contrib Package</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#gluon-api">Gluon API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#image-api">Image API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#io-api">IO API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#kv-store-api">KV Store API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#metric-api">Metric API</a></li> |
| <li class="toctree-l3 current"><a class="reference internal" href="../index.html#module-api">Module API</a><ul class="current"> |
| <li class="toctree-l4 current"><a class="current reference internal" href="#">Module API</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../executor/executor.html">Executor and Executor Manager</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#ndarray-api">NDArray API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#optimization-api">Optimization API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#profiler-api">Profiler API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#run-time-compilation-api">Run-Time Compilation API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#symbol-api">Symbol API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#symbol-in-pictures-api">Symbol in Pictures API</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../index.html#tools">Tools</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l2"><a class="reference internal" href="../../r/index.html">MXNet - R API</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../scala/index.html">MXNet - Scala API</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../architecture/index.html">MXNet Architecture</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../community/index.html">MXNet Community</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../faq/index.html">MXNet FAQ</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../gluon/index.html">About Gluon</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../install/index.html">Installing MXNet</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../install/index.html#nvidia-jetson-tx-family">Nvidia Jetson TX family</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../install/index.html#source-download">Source Download</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../model_zoo/index.html">MXNet Model Zoo</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../tutorials/index.html">Tutorials</a></li> |
| </ul> |
| </div> |
| </div> |
| <div class="content"> |
| <div class="page-tracker"></div> |
| <!--- Licensed to the Apache Software Foundation (ASF) under one --> |
| <!--- or more contributor license agreements. See the NOTICE file --> |
| <!--- distributed with this work for additional information --> |
| <!--- regarding copyright ownership. The ASF licenses this file --> |
| <!--- to you under the Apache License, Version 2.0 (the --> |
| <!--- "License"); you may not use this file except in compliance --> |
| <!--- with the License. You may obtain a copy of the License at --><!--- http://www.apache.org/licenses/LICENSE-2.0 --><!--- Unless required by applicable law or agreed to in writing, --> |
| <!--- software distributed under the License is distributed on an --> |
| <!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY --> |
| <!--- KIND, either express or implied. See the License for the --> |
| <!--- specific language governing permissions and limitations --> |
| <!--- under the License. --><div class="section" id="module-api"> |
| <span id="module-api"></span><h1>Module API<a class="headerlink" href="#module-api" title="Permalink to this headline">¶</a></h1> |
| <div class="section" id="overview"> |
| <span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2> |
| <p>The module API, defined in the <code class="docutils literal"><span class="pre">module</span></code> (or simply <code class="docutils literal"><span class="pre">mod</span></code>) package, provides an |
| intermediate and high-level interface for performing computation with a |
| <code class="docutils literal"><span class="pre">Symbol</span></code>. One can roughly think a module is a machine which can execute a |
| program defined by a <code class="docutils literal"><span class="pre">Symbol</span></code>.</p> |
| <p>The <code class="docutils literal"><span class="pre">module.Module</span></code> accepts a <code class="docutils literal"><span class="pre">Symbol</span></code> as the input.</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">data</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">Variable</span><span class="p">(</span><span class="s1">'data'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">fc1</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">FullyConnected</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'fc1'</span><span class="p">,</span> <span class="n">num_hidden</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">act1</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">Activation</span><span class="p">(</span><span class="n">fc1</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'relu1'</span><span class="p">,</span> <span class="n">act_type</span><span class="o">=</span><span class="s2">"relu"</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">fc2</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">FullyConnected</span><span class="p">(</span><span class="n">act1</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'fc2'</span><span class="p">,</span> <span class="n">num_hidden</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">out</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">SoftmaxOutput</span><span class="p">(</span><span class="n">fc2</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">'softmax'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">mod</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">mod</span><span class="o">.</span><span class="n">Module</span><span class="p">(</span><span class="n">out</span><span class="p">)</span> <span class="c1"># create a module by given a Symbol</span> |
| </pre></div> |
| </div> |
| <p>Assume there is a valid MXNet data iterator <code class="docutils literal"><span class="pre">nd_iter</span></code>. We can initialize the |
| module:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">data_shapes</span><span class="o">=</span><span class="n">nd_iter</span><span class="o">.</span><span class="n">provide_data</span><span class="p">,</span> |
| <span class="gp">>>> </span> <span class="n">label_shapes</span><span class="o">=</span><span class="n">nd_iter</span><span class="o">.</span><span class="n">provide_label</span><span class="p">)</span> <span class="c1"># create memory by given input shapes</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">init_params</span><span class="p">()</span> <span class="c1"># initial parameters with the default random initializer</span> |
| </pre></div> |
| </div> |
| <p>Now the module is able to compute. We can call high-level API to train and |
| predict:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">nd_iter</span><span class="p">,</span> <span class="n">num_epoch</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="o">...</span><span class="p">)</span> <span class="c1"># train</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">new_nd_iter</span><span class="p">)</span> <span class="c1"># predict on new data</span> |
| </pre></div> |
| </div> |
| <p>or use intermediate APIs to perform step-by-step computations</p> |
| <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">data_batch</span><span class="p">)</span> <span class="c1"># forward on the provided data batch</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">backward</span><span class="p">()</span> <span class="c1"># backward to calculate the gradients</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">update</span><span class="p">()</span> <span class="c1"># update parameters using the default optimizer</span> |
| </pre></div> |
| </div> |
| <p>A detailed tutorial is available at |
| <a class="reference external" href="/versions/1.4.1/tutorials/basic/module.html">Module - Neural network training and inference</a>.</p> |
| <p>The <code class="docutils literal"><span class="pre">module</span></code> package provides several modules:</p> |
| <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.module.BaseModule" title="mxnet.module.BaseModule"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule</span></code></a></td> |
| <td>The base class of a module.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.Module" title="mxnet.module.Module"><code class="xref py py-obj docutils literal"><span class="pre">Module</span></code></a></td> |
| <td>Module is a basic module that wrap a <cite>Symbol</cite>.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.SequentialModule" title="mxnet.module.SequentialModule"><code class="xref py py-obj docutils literal"><span class="pre">SequentialModule</span></code></a></td> |
| <td>A SequentialModule is a container module that can chain multiple modules together.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BucketingModule" title="mxnet.module.BucketingModule"><code class="xref py py-obj docutils literal"><span class="pre">BucketingModule</span></code></a></td> |
| <td>This module helps to deal efficiently with varying-length inputs.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.PythonModule" title="mxnet.module.PythonModule"><code class="xref py py-obj docutils literal"><span class="pre">PythonModule</span></code></a></td> |
| <td>A convenient module class that implements many of the module APIs as empty functions.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.PythonLossModule" title="mxnet.module.PythonLossModule"><code class="xref py py-obj docutils literal"><span class="pre">PythonLossModule</span></code></a></td> |
| <td>A convenient module class that implements many of the module APIs as empty functions.</td> |
| </tr> |
| </tbody> |
| </table> |
| <p>We summarize the interface for each class in the following sections.</p> |
| </div> |
| <div class="section" id="the-basemodule-class"> |
| <span id="the-basemodule-class"></span><h2>The <code class="docutils literal"><span class="pre">BaseModule</span></code> class<a class="headerlink" href="#the-basemodule-class" title="Permalink to this headline">¶</a></h2> |
| <p>The <code class="docutils literal"><span class="pre">BaseModule</span></code> is the base class for all other module classes. It defines the |
| interface each module class should provide.</p> |
| <div class="section" id="initialize-memory"> |
| <span id="initialize-memory"></span><h3>Initialize memory<a class="headerlink" href="#initialize-memory" title="Permalink to this headline">¶</a></h3> |
| <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.module.BaseModule.bind" title="mxnet.module.BaseModule.bind"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.bind</span></code></a></td> |
| <td>Binds the symbols to construct executors.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="get-and-set-parameters"> |
| <span id="get-and-set-parameters"></span><h3>Get and set parameters<a class="headerlink" href="#get-and-set-parameters" title="Permalink to this headline">¶</a></h3> |
| <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.module.BaseModule.init_params" title="mxnet.module.BaseModule.init_params"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.init_params</span></code></a></td> |
| <td>Initializes the parameters and auxiliary states.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.set_params" title="mxnet.module.BaseModule.set_params"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.set_params</span></code></a></td> |
| <td>Assigns parameter and aux state values.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.BaseModule.get_params" title="mxnet.module.BaseModule.get_params"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.get_params</span></code></a></td> |
| <td>Gets parameters, those are potentially copies of the the actual parameters used to do computation on the device.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.save_params" title="mxnet.module.BaseModule.save_params"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.save_params</span></code></a></td> |
| <td>Saves model parameters to file.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.BaseModule.load_params" title="mxnet.module.BaseModule.load_params"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.load_params</span></code></a></td> |
| <td>Loads model parameters from file.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="train-and-predict"> |
| <span id="train-and-predict"></span><h3>Train and predict<a class="headerlink" href="#train-and-predict" title="Permalink to this headline">¶</a></h3> |
| <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.module.BaseModule.fit" title="mxnet.module.BaseModule.fit"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.fit</span></code></a></td> |
| <td>Trains the module parameters.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.score" title="mxnet.module.BaseModule.score"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.score</span></code></a></td> |
| <td>Runs prediction on <code class="docutils literal"><span class="pre">eval_data</span></code> and evaluates the performance according to the given <code class="docutils literal"><span class="pre">eval_metric</span></code>.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.BaseModule.iter_predict" title="mxnet.module.BaseModule.iter_predict"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.iter_predict</span></code></a></td> |
| <td>Iterates over predictions.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.predict" title="mxnet.module.BaseModule.predict"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.predict</span></code></a></td> |
| <td>Runs prediction and collects the outputs.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="forward-and-backward"> |
| <span id="forward-and-backward"></span><h3>Forward and backward<a class="headerlink" href="#forward-and-backward" title="Permalink to this headline">¶</a></h3> |
| <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.module.BaseModule.forward" title="mxnet.module.BaseModule.forward"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.forward</span></code></a></td> |
| <td>Forward computation.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.backward" title="mxnet.module.BaseModule.backward"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.backward</span></code></a></td> |
| <td>Backward computation.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.BaseModule.forward_backward" title="mxnet.module.BaseModule.forward_backward"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.forward_backward</span></code></a></td> |
| <td>A convenient function that calls both <code class="docutils literal"><span class="pre">forward</span></code> and <code class="docutils literal"><span class="pre">backward</span></code>.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="update-parameters"> |
| <span id="update-parameters"></span><h3>Update parameters<a class="headerlink" href="#update-parameters" title="Permalink to this headline">¶</a></h3> |
| <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.module.BaseModule.init_optimizer" title="mxnet.module.BaseModule.init_optimizer"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.init_optimizer</span></code></a></td> |
| <td>Installs and initializes optimizers, as well as initialize kvstore for</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.update" title="mxnet.module.BaseModule.update"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.update</span></code></a></td> |
| <td>Updates parameters according to the installed optimizer and the gradients computed in the previous forward-backward batch.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.BaseModule.update_metric" title="mxnet.module.BaseModule.update_metric"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.update_metric</span></code></a></td> |
| <td>Evaluates and accumulates evaluation metric on outputs of the last forward computation.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="input-and-output"> |
| <span id="input-and-output"></span><h3>Input and output<a class="headerlink" href="#input-and-output" title="Permalink to this headline">¶</a></h3> |
| <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.module.BaseModule.data_names" title="mxnet.module.BaseModule.data_names"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.data_names</span></code></a></td> |
| <td>A list of names for data required by this module.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.output_names" title="mxnet.module.BaseModule.output_names"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.output_names</span></code></a></td> |
| <td>A list of names for the outputs of this module.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.BaseModule.data_shapes" title="mxnet.module.BaseModule.data_shapes"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.data_shapes</span></code></a></td> |
| <td>A list of (name, shape) pairs specifying the data inputs to this module.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.label_shapes" title="mxnet.module.BaseModule.label_shapes"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.label_shapes</span></code></a></td> |
| <td>A list of (name, shape) pairs specifying the label inputs to this module.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.BaseModule.output_shapes" title="mxnet.module.BaseModule.output_shapes"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.output_shapes</span></code></a></td> |
| <td>A list of (name, shape) pairs specifying the outputs of this module.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.get_outputs" title="mxnet.module.BaseModule.get_outputs"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.get_outputs</span></code></a></td> |
| <td>Gets outputs of the previous forward computation.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.BaseModule.get_input_grads" title="mxnet.module.BaseModule.get_input_grads"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.get_input_grads</span></code></a></td> |
| <td>Gets the gradients to the inputs, computed in the previous backward computation.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="others"> |
| <span id="others"></span><h3>Others<a class="headerlink" href="#others" title="Permalink to this headline">¶</a></h3> |
| <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.module.BaseModule.get_states" title="mxnet.module.BaseModule.get_states"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.get_states</span></code></a></td> |
| <td>Gets states from all devices</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.set_states" title="mxnet.module.BaseModule.set_states"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.set_states</span></code></a></td> |
| <td>Sets value for states.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.BaseModule.install_monitor" title="mxnet.module.BaseModule.install_monitor"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.install_monitor</span></code></a></td> |
| <td>Installs monitor on all executors.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.BaseModule.symbol" title="mxnet.module.BaseModule.symbol"><code class="xref py py-obj docutils literal"><span class="pre">BaseModule.symbol</span></code></a></td> |
| <td>Gets the symbol associated with this module.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| <div class="section" id="other-build-in-modules"> |
| <span id="other-build-in-modules"></span><h2>Other build-in modules<a class="headerlink" href="#other-build-in-modules" title="Permalink to this headline">¶</a></h2> |
| <p>Besides the basic interface defined in <code class="docutils literal"><span class="pre">BaseModule</span></code>, each module class supports |
| additional functionality. We summarize them in this section.</p> |
| <div class="section" id="class-module"> |
| <span id="class-module"></span><h3>Class <code class="docutils literal"><span class="pre">Module</span></code><a class="headerlink" href="#class-module" title="Permalink to this headline">¶</a></h3> |
| <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.module.Module.load" title="mxnet.module.Module.load"><code class="xref py py-obj docutils literal"><span class="pre">Module.load</span></code></a></td> |
| <td>Creates a model from previously saved checkpoint.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.Module.save_checkpoint" title="mxnet.module.Module.save_checkpoint"><code class="xref py py-obj docutils literal"><span class="pre">Module.save_checkpoint</span></code></a></td> |
| <td>Saves current progress to checkpoint.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.Module.reshape" title="mxnet.module.Module.reshape"><code class="xref py py-obj docutils literal"><span class="pre">Module.reshape</span></code></a></td> |
| <td>Reshapes the module for new input shapes.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.Module.borrow_optimizer" title="mxnet.module.Module.borrow_optimizer"><code class="xref py py-obj docutils literal"><span class="pre">Module.borrow_optimizer</span></code></a></td> |
| <td>Borrows optimizer from a shared module.</td> |
| </tr> |
| <tr class="row-odd"><td><a class="reference internal" href="#mxnet.module.Module.save_optimizer_states" title="mxnet.module.Module.save_optimizer_states"><code class="xref py py-obj docutils literal"><span class="pre">Module.save_optimizer_states</span></code></a></td> |
| <td>Saves optimizer (updater) state to a file.</td> |
| </tr> |
| <tr class="row-even"><td><a class="reference internal" href="#mxnet.module.Module.load_optimizer_states" title="mxnet.module.Module.load_optimizer_states"><code class="xref py py-obj docutils literal"><span class="pre">Module.load_optimizer_states</span></code></a></td> |
| <td>Loads optimizer (updater) state from a file.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="class-bucketmodule"> |
| <span id="class-bucketmodule"></span><h3>Class <code class="docutils literal"><span class="pre">BucketModule</span></code><a class="headerlink" href="#class-bucketmodule" title="Permalink to this headline">¶</a></h3> |
| <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.module.BucketingModule.switch_bucket" title="mxnet.module.BucketingModule.switch_bucket"><code class="xref py py-obj docutils literal"><span class="pre">BucketingModule.switch_bucket</span></code></a></td> |
| <td>Switches to a different bucket.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="class-sequentialmodule"> |
| <span id="class-sequentialmodule"></span><h3>Class <code class="docutils literal"><span class="pre">SequentialModule</span></code><a class="headerlink" href="#class-sequentialmodule" title="Permalink to this headline">¶</a></h3> |
| <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.module.SequentialModule.add" title="mxnet.module.SequentialModule.add"><code class="xref py py-obj docutils literal"><span class="pre">SequentialModule.add</span></code></a></td> |
| <td>Add a module to the chain.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </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><dl class="class"> |
| <dt id="mxnet.module.BaseModule"> |
| <em class="property">class </em><code class="descclassname">mxnet.module.</code><code class="descname">BaseModule</code><span class="sig-paren">(</span><em>logger=<module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'></em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule" title="Permalink to this definition">¶</a></dt> |
| <dd><p>The base class of a module.</p> |
| <p>A module represents a computation component. One can think of module as a computation machine. |
| A module can execute forward and backward passes and update parameters in a model. |
| We aim to make the APIs easy to use, especially in the case when we need to use the imperative |
| API to work with multiple modules (e.g. stochastic depth network).</p> |
| <p>A module has several states:</p> |
| <ul class="simple"> |
| <li>Initial state: Memory is not allocated yet, so the module is not ready for computation yet.</li> |
| <li>Binded: Shapes for inputs, outputs, and parameters are all known, memory has been allocated, |
| and the module is ready for computation.</li> |
| <li>Parameters are initialized: For modules with parameters, doing computation before |
| initializing the parameters might result in undefined outputs.</li> |
| <li>Optimizer is installed: An optimizer can be installed to a module. After this, the parameters |
| of the module can be updated according to the optimizer after gradients are computed |
| (forward-backward).</li> |
| </ul> |
| <p>In order for a module to interact with others, it must be able to report the |
| following information in its initial state (before binding):</p> |
| <ul class="simple"> |
| <li><cite>data_names</cite>: list of type string indicating the names of the required input data.</li> |
| <li><cite>output_names</cite>: list of type string indicating the names of the required outputs.</li> |
| </ul> |
| <p>After binding, a module should be able to report the following richer information:</p> |
| <ul class="simple"> |
| <li><dl class="first docutils"> |
| <dt>state information</dt> |
| <dd><ul class="first last"> |
| <li><cite>binded</cite>: <cite>bool</cite>, indicates whether the memory buffers needed for computation |
| have been allocated.</li> |
| <li><cite>for_training</cite>: whether the module is bound for training.</li> |
| <li><cite>params_initialized</cite>: <cite>bool</cite>, indicates whether the parameters of this module |
| have been initialized.</li> |
| <li><cite>optimizer_initialized</cite>: <cite>bool</cite>, indicates whether an optimizer is defined |
| and initialized.</li> |
| <li><cite>inputs_need_grad</cite>: <cite>bool</cite>, indicates whether gradients with respect to the |
| input data are needed. Might be useful when implementing composition of modules.</li> |
| </ul> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>input/output information</dt> |
| <dd><ul class="first last"> |
| <li><cite>data_shapes</cite>: a list of <cite>(name, shape)</cite>. In theory, since the memory is allocated, |
| we could directly provide the data arrays. But in the case of data parallelism, |
| the data arrays might not be of the same shape as viewed from the external world.</li> |
| <li><cite>label_shapes</cite>: a list of <cite>(name, shape)</cite>. This might be <cite>[]</cite> if the module does |
| not need labels (e.g. it does not contains a loss function at the top), or a module |
| is not bound for training.</li> |
| <li><cite>output_shapes</cite>: a list of <cite>(name, shape)</cite> for outputs of the module.</li> |
| </ul> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>parameters (for modules with parameters)</dt> |
| <dd><ul class="first last"> |
| <li><cite>get_params()</cite>: return a tuple <cite>(arg_params, aux_params)</cite>. Each of those |
| is a dictionary of name to <code class="docutils literal"><span class="pre">NDArray</span></code> mapping. Those <cite>NDArray</cite> always lives on |
| CPU. The actual parameters used for computing might live on other devices (GPUs), |
| this function will retrieve (a copy of) the latest parameters.</li> |
| <li><code class="docutils literal"><span class="pre">set_params(arg_params,</span> <span class="pre">aux_params)</span></code>: assign parameters to the devices |
| doing the computation.</li> |
| <li><code class="docutils literal"><span class="pre">init_params(...)</span></code>: a more flexible interface to assign or initialize the parameters.</li> |
| </ul> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>setup</dt> |
| <dd><ul class="first last"> |
| <li><cite>bind()</cite>: prepare environment for computation.</li> |
| <li><cite>init_optimizer()</cite>: install optimizer for parameter updating.</li> |
| <li><cite>prepare()</cite>: prepare the module based on the current data batch.</li> |
| </ul> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>computation</dt> |
| <dd><ul class="first last"> |
| <li><cite>forward(data_batch)</cite>: forward operation.</li> |
| <li><cite>backward(out_grads=None)</cite>: backward operation.</li> |
| <li><cite>update()</cite>: update parameters according to installed optimizer.</li> |
| <li><cite>get_outputs()</cite>: get outputs of the previous forward operation.</li> |
| <li><cite>get_input_grads()</cite>: get the gradients with respect to the inputs computed |
| in the previous backward operation.</li> |
| <li><cite>update_metric(metric, labels, pre_sliced=False)</cite>: update performance metric |
| for the previous forward |
| computed results.</li> |
| </ul> |
| </dd> |
| </dl> |
| </li> |
| <li><dl class="first docutils"> |
| <dt>other properties (mostly for backward compatibility)</dt> |
| <dd><ul class="first last"> |
| <li><cite>symbol</cite>: the underlying symbolic graph for this module (if any) |
| This property is not necessarily constant. For example, for <cite>BucketingModule</cite>, |
| this property is simply the <em>current</em> symbol being used. For other modules, |
| this value might not be well defined.</li> |
| </ul> |
| </dd> |
| </dl> |
| </li> |
| </ul> |
| <p>When those intermediate-level API are implemented properly, the following |
| high-level API will be automatically available for a module:</p> |
| <ul class="simple"> |
| <li><cite>fit</cite>: train the module parameters on a data set.</li> |
| <li><cite>predict</cite>: run prediction on a data set and collect outputs.</li> |
| <li><cite>score</cite>: run prediction on a data set and evaluate performance.</li> |
| </ul> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of creating a mxnet module.</span> |
| <span class="gp">>>> </span><span class="kn">import</span> <span class="nn">mxnet</span> <span class="k">as</span> <span class="nn">mx</span> |
| <span class="gp">>>> </span><span class="n">data</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="s1">'data'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">fc1</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">FullyConnected</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'fc1'</span><span class="p">,</span> <span class="n">num_hidden</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">act1</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">Activation</span><span class="p">(</span><span class="n">fc1</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'relu1'</span><span class="p">,</span> <span class="n">act_type</span><span class="o">=</span><span class="s2">"relu"</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">fc2</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">FullyConnected</span><span class="p">(</span><span class="n">act1</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">'fc2'</span><span class="p">,</span> <span class="n">num_hidden</span> <span class="o">=</span> <span class="mi">64</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">act2</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">Activation</span><span class="p">(</span><span class="n">fc2</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'relu2'</span><span class="p">,</span> <span class="n">act_type</span><span class="o">=</span><span class="s2">"relu"</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">fc3</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">FullyConnected</span><span class="p">(</span><span class="n">act2</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'fc3'</span><span class="p">,</span> <span class="n">num_hidden</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">out</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">SoftmaxOutput</span><span class="p">(</span><span class="n">fc3</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">'softmax'</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">mod</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">mod</span><span class="o">.</span><span class="n">Module</span><span class="p">(</span><span class="n">out</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.forward_backward"> |
| <code class="descname">forward_backward</code><span class="sig-paren">(</span><em>data_batch</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.forward_backward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.forward_backward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A convenient function that calls both <code class="docutils literal"><span class="pre">forward</span></code> and <code class="docutils literal"><span class="pre">backward</span></code>.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.score"> |
| <code class="descname">score</code><span class="sig-paren">(</span><em>eval_data</em>, <em>eval_metric</em>, <em>num_batch=None</em>, <em>batch_end_callback=None</em>, <em>score_end_callback=None</em>, <em>reset=True</em>, <em>epoch=0</em>, <em>sparse_row_id_fn=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.score"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.score" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Runs prediction on <code class="docutils literal"><span class="pre">eval_data</span></code> and evaluates the performance according to |
| the given <code class="docutils literal"><span class="pre">eval_metric</span></code>.</p> |
| <p>Checkout <a class="reference external" href="/versions/1.4.1/tutorials/basic/module.html">Module Tutorial</a> to see |
| a end-to-end use-case.</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>eval_data</strong> (<em>DataIter</em>) – Evaluation data to run prediction on.</li> |
| <li><strong>eval_metric</strong> (<a class="reference internal" href="../metric/metric.html#mxnet.metric.EvalMetric" title="mxnet.metric.EvalMetric"><em>EvalMetric</em></a><em> or </em><em>list of EvalMetrics</em>) – Evaluation metric to use.</li> |
| <li><strong>num_batch</strong> (<em>int</em>) – Number of batches to run. Defaults to <code class="docutils literal"><span class="pre">None</span></code>, indicating run until the <cite>DataIter</cite> |
| finishes.</li> |
| <li><strong>batch_end_callback</strong> (<em>function</em>) – Could also be a list of functions.</li> |
| <li><strong>reset</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">True</span></code>. Indicates whether we should reset <cite>eval_data</cite> before starting |
| evaluating.</li> |
| <li><strong>epoch</strong> (<em>int</em>) – Defaults to 0. For compatibility, this will be passed to callbacks (if any). |
| During training, this will correspond to the training epoch number.</li> |
| <li><strong>sparse_row_id_fn</strong> (<em>A callback function</em>) – The function takes <cite>data_batch</cite> as an input and returns a dict of |
| str -> NDArray. The resulting dict is used for pulling row_sparse |
| parameters from the kvstore, where the str key is the name of the param, |
| and the value is the row id of the param to pull.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of using score for prediction.</span> |
| <span class="gp">>>> </span><span class="c1"># Evaluate accuracy on val_dataiter</span> |
| <span class="gp">>>> </span><span class="n">metric</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">Accuracy</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">val_dataiter</span><span class="p">,</span> <span class="n">metric</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">val_dataiter</span><span class="p">,</span> <span class="p">[</span><span class="s1">'mse'</span><span class="p">,</span> <span class="s1">'acc'</span><span class="p">])</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.iter_predict"> |
| <code class="descname">iter_predict</code><span class="sig-paren">(</span><em>eval_data</em>, <em>num_batch=None</em>, <em>reset=True</em>, <em>sparse_row_id_fn=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.iter_predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.iter_predict" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Iterates over predictions.</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">pred</span><span class="p">,</span> <span class="n">i_batch</span><span class="p">,</span> <span class="n">batch</span> <span class="ow">in</span> <span class="n">module</span><span class="o">.</span><span class="n">iter_predict</span><span class="p">(</span><span class="n">eval_data</span><span class="p">):</span> |
| <span class="gp">... </span> <span class="c1"># pred is a list of outputs from the module</span> |
| <span class="gp">... </span> <span class="c1"># i_batch is a integer</span> |
| <span class="gp">... </span> <span class="c1"># batch is the data batch from the data iterator</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>eval_data</strong> (<em>DataIter</em>) – Evaluation data to run prediction on.</li> |
| <li><strong>num_batch</strong> (<em>int</em>) – Default is <code class="docutils literal"><span class="pre">None</span></code>, indicating running all the batches in the data iterator.</li> |
| <li><strong>reset</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>, indicating whether we should reset the data iter before start |
| doing prediction.</li> |
| <li><strong>sparse_row_id_fn</strong> (<em>A callback function</em>) – The function takes <cite>data_batch</cite> as an input and returns a dict of |
| str -> NDArray. The resulting dict is used for pulling row_sparse |
| parameters from the kvstore, where the str key is the name of the param, |
| and the value is the row id of the param to pull.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.predict"> |
| <code class="descname">predict</code><span class="sig-paren">(</span><em>eval_data</em>, <em>num_batch=None</em>, <em>merge_batches=True</em>, <em>reset=True</em>, <em>always_output_list=False</em>, <em>sparse_row_id_fn=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.predict" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Runs prediction and collects the outputs.</p> |
| <p>When <cite>merge_batches</cite> is <code class="docutils literal"><span class="pre">True</span></code> (by default), the return value will be a list |
| <code class="docutils literal"><span class="pre">[out1,</span> <span class="pre">out2,</span> <span class="pre">out3]</span></code>, where each element is formed by concatenating the outputs for |
| all the mini-batches. When <cite>always_output_list</cite> is <code class="docutils literal"><span class="pre">False</span></code> (as by default), |
| then in the case of a single output, <cite>out1</cite> is returned instead of <code class="docutils literal"><span class="pre">[out1]</span></code>.</p> |
| <p>When <cite>merge_batches</cite> is <code class="docutils literal"><span class="pre">False</span></code>, the return value will be a nested list like |
| <code class="docutils literal"><span class="pre">[[out1_batch1,</span> <span class="pre">out2_batch1],</span> <span class="pre">[out1_batch2],</span> <span class="pre">...]</span></code>. This mode is useful because |
| in some cases (e.g. bucketing), the module does not necessarily produce the same |
| number of outputs.</p> |
| <p>The objects in the results have type <cite>NDArray</cite>. If you need to work with a numpy array, |
| just call <code class="docutils literal"><span class="pre">.asnumpy()</span></code> on each <cite>NDArray</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>eval_data</strong> (<em>DataIter</em><em> or </em><a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a><em> or </em><em>numpy array</em>) – Evaluation data to run prediction on.</li> |
| <li><strong>num_batch</strong> (<em>int</em>) – Defaults to <code class="docutils literal"><span class="pre">None</span></code>, indicates running all the batches in the data iterator.</li> |
| <li><strong>merge_batches</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">True</span></code>, see above for return values.</li> |
| <li><strong>reset</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">True</span></code>, indicates whether we should reset the data iter before |
| doing prediction.</li> |
| <li><strong>always_output_list</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">False</span></code>, see above for return values.</li> |
| <li><strong>sparse_row_id_fn</strong> (<em>A callback function</em>) – The function takes <cite>data_batch</cite> as an input and returns a dict of |
| str -> NDArray. The resulting dict is used for pulling row_sparse |
| parameters from the kvstore, where the str key is the name of the param, |
| and the value is the row id of the param to pull.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Prediction results.</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 or list of list of NDArray</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of using `predict` for prediction.</span> |
| <span class="gp">>>> </span><span class="c1"># Predict on the first 10 batches of val_dataiter</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">eval_data</span><span class="o">=</span><span class="n">val_dataiter</span><span class="p">,</span> <span class="n">num_batch</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.fit"> |
| <code class="descname">fit</code><span class="sig-paren">(</span><em>train_data</em>, <em>eval_data=None</em>, <em>eval_metric='acc'</em>, <em>epoch_end_callback=None</em>, <em>batch_end_callback=None</em>, <em>kvstore='local'</em>, <em>optimizer='sgd'</em>, <em>optimizer_params=(('learning_rate'</em>, <em>0.01)</em>, <em>)</em>, <em>eval_end_callback=None</em>, <em>eval_batch_end_callback=None</em>, <em>initializer=<mxnet.initializer.Uniform object></em>, <em>arg_params=None</em>, <em>aux_params=None</em>, <em>allow_missing=False</em>, <em>force_rebind=False</em>, <em>force_init=False</em>, <em>begin_epoch=0</em>, <em>num_epoch=None</em>, <em>validation_metric=None</em>, <em>monitor=None</em>, <em>sparse_row_id_fn=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.fit" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Trains the module parameters.</p> |
| <p>Checkout <a class="reference external" href="/versions/1.4.1/tutorials/basic/module.html">Module Tutorial</a> to see |
| a end-to-end use-case.</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>train_data</strong> (<em>DataIter</em>) – Train DataIter.</li> |
| <li><strong>eval_data</strong> (<em>DataIter</em>) – If not <code class="docutils literal"><span class="pre">None</span></code>, will be used as validation set and the performance |
| after each epoch will be evaluated.</li> |
| <li><strong>eval_metric</strong> (<em>str</em><em> or </em><a class="reference internal" href="../metric/metric.html#mxnet.metric.EvalMetric" title="mxnet.metric.EvalMetric"><em>EvalMetric</em></a>) – Defaults to ‘accuracy’. The performance measure used to display during training. |
| Other possible predefined metrics are: |
| ‘ce’ (CrossEntropy), ‘f1’, ‘mae’, ‘mse’, ‘rmse’, ‘top_k_accuracy’.</li> |
| <li><strong>epoch_end_callback</strong> (<em>function</em><em> or </em><em>list of functions</em>) – Each callback will be called with the current <cite>epoch</cite>, <cite>symbol</cite>, <cite>arg_params</cite> |
| and <cite>aux_params</cite>.</li> |
| <li><strong>batch_end_callback</strong> (<em>function</em><em> or </em><em>list of function</em>) – Each callback will be called with a <cite>BatchEndParam</cite>.</li> |
| <li><strong>kvstore</strong> (<em>str</em><em> or </em><a class="reference internal" href="../kvstore/kvstore.html#mxnet.kvstore.KVStore" title="mxnet.kvstore.KVStore"><em>KVStore</em></a>) – Defaults to ‘local’.</li> |
| <li><strong>optimizer</strong> (<em>str</em><em> or </em><a class="reference internal" href="../optimization/optimization.html#mxnet.optimizer.Optimizer" title="mxnet.optimizer.Optimizer"><em>Optimizer</em></a>) – Defaults to ‘sgd’.</li> |
| <li><strong>optimizer_params</strong> (<em>dict</em>) – Defaults to <code class="docutils literal"><span class="pre">(('learning_rate',</span> <span class="pre">0.01),)</span></code>. The parameters for |
| the optimizer constructor. |
| The default value is not a dict, just to avoid pylint warning on dangerous |
| default values.</li> |
| <li><strong>eval_end_callback</strong> (<em>function</em><em> or </em><em>list of function</em>) – These will be called at the end of each full evaluation, with the metrics over |
| the entire evaluation set.</li> |
| <li><strong>eval_batch_end_callback</strong> (<em>function</em><em> or </em><em>list of function</em>) – These will be called at the end of each mini-batch during evaluation.</li> |
| <li><strong>initializer</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – The initializer is called to initialize the module parameters when they are |
| not already initialized.</li> |
| <li><strong>arg_params</strong> (<em>dict</em>) – Defaults to <code class="docutils literal"><span class="pre">None</span></code>, if not <code class="docutils literal"><span class="pre">None</span></code>, should be existing parameters from a trained |
| model or loaded from a checkpoint (previously saved model). In this case, |
| the value here will be used to initialize the module parameters, unless they |
| are already initialized by the user via a call to <cite>init_params</cite> or <cite>fit</cite>. |
| <cite>arg_params</cite> has a higher priority than <cite>initializer</cite>.</li> |
| <li><strong>aux_params</strong> (<em>dict</em>) – Defaults to <code class="docutils literal"><span class="pre">None</span></code>. Similar to <cite>arg_params</cite>, except for auxiliary states.</li> |
| <li><strong>allow_missing</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">False</span></code>. Indicates whether to allow missing parameters when <cite>arg_params</cite> |
| and <cite>aux_params</cite> are not <code class="docutils literal"><span class="pre">None</span></code>. If this is <code class="docutils literal"><span class="pre">True</span></code>, then the missing parameters |
| will be initialized via the <cite>initializer</cite>.</li> |
| <li><strong>force_rebind</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">False</span></code>. Whether to force rebinding the executors if already bound.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">False</span></code>. Indicates whether to force initialization even if the |
| parameters are already initialized.</li> |
| <li><strong>begin_epoch</strong> (<em>int</em>) – Defaults to 0. Indicates the starting epoch. Usually, if resumed from a |
| checkpoint saved at a previous training phase at epoch N, then this value should be |
| N+1.</li> |
| <li><strong>num_epoch</strong> (<em>int</em>) – Number of epochs for training.</li> |
| <li><strong>sparse_row_id_fn</strong> (<em>A callback function</em>) – The function takes <cite>data_batch</cite> as an input and returns a dict of |
| str -> NDArray. The resulting dict is used for pulling row_sparse |
| parameters from the kvstore, where the str key is the name of the param, |
| and the value is the row id of the param to pull.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of using fit for training.</span> |
| <span class="gp">>>> </span><span class="c1"># Assume training dataIter and validation dataIter are ready</span> |
| <span class="gp">>>> </span><span class="c1"># Assume loading a previously checkpointed model</span> |
| <span class="gp">>>> </span><span class="n">sym</span><span class="p">,</span> <span class="n">arg_params</span><span class="p">,</span> <span class="n">aux_params</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">load_checkpoint</span><span class="p">(</span><span class="n">model_prefix</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">train_data</span><span class="o">=</span><span class="n">train_dataiter</span><span class="p">,</span> <span class="n">eval_data</span><span class="o">=</span><span class="n">val_dataiter</span><span class="p">,</span> <span class="n">optimizer</span><span class="o">=</span><span class="s1">'sgd'</span><span class="p">,</span> |
| <span class="gp">... </span> <span class="n">optimizer_params</span><span class="o">=</span><span class="p">{</span><span class="s1">'learning_rate'</span><span class="p">:</span><span class="mf">0.01</span><span class="p">,</span> <span class="s1">'momentum'</span><span class="p">:</span> <span class="mf">0.9</span><span class="p">},</span> |
| <span class="gp">... </span> <span class="n">arg_params</span><span class="o">=</span><span class="n">arg_params</span><span class="p">,</span> <span class="n">aux_params</span><span class="o">=</span><span class="n">aux_params</span><span class="p">,</span> |
| <span class="gp">... </span> <span class="n">eval_metric</span><span class="o">=</span><span class="s1">'acc'</span><span class="p">,</span> <span class="n">num_epoch</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">begin_epoch</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BaseModule.data_names"> |
| <code class="descname">data_names</code><a class="headerlink" href="#mxnet.module.BaseModule.data_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for data required by this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BaseModule.output_names"> |
| <code class="descname">output_names</code><a class="headerlink" href="#mxnet.module.BaseModule.output_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for the outputs of this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BaseModule.data_shapes"> |
| <code class="descname">data_shapes</code><a class="headerlink" href="#mxnet.module.BaseModule.data_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of (name, shape) pairs specifying the data inputs to this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BaseModule.label_shapes"> |
| <code class="descname">label_shapes</code><a class="headerlink" href="#mxnet.module.BaseModule.label_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of (name, shape) pairs specifying the label inputs to this module. |
| If this module does not accept labels – either it is a module without loss |
| function, or it is not bound for training, then this should return an empty |
| list <code class="docutils literal"><span class="pre">[]</span></code>.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BaseModule.output_shapes"> |
| <code class="descname">output_shapes</code><a class="headerlink" href="#mxnet.module.BaseModule.output_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of (name, shape) pairs specifying the outputs of this module.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.get_params"> |
| <code class="descname">get_params</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.get_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.get_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets parameters, those are potentially copies of the the actual parameters used |
| to do computation on the device.</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">Returns:</th><td class="field-body">A pair of dictionaries each mapping parameter names to NDArray values.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><code class="docutils literal"><span class="pre">(arg_params,</span> <span class="pre">aux_params)</span></code></td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of getting module parameters.</span> |
| <span class="gp">>>> </span><span class="nb">print</span> <span class="n">mod</span><span class="o">.</span><span class="n">get_params</span><span class="p">()</span> |
| <span class="go">({'fc2_weight': <NDArray 64x128 @cpu(0)>, 'fc1_weight': <NDArray 128x100 @cpu(0)>,</span> |
| <span class="go">'fc3_bias': <NDArray 10 @cpu(0)>, 'fc3_weight': <NDArray 10x64 @cpu(0)>,</span> |
| <span class="go">'fc2_bias': <NDArray 64 @cpu(0)>, 'fc1_bias': <NDArray 128 @cpu(0)>}, {})</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.init_params"> |
| <code class="descname">init_params</code><span class="sig-paren">(</span><em>initializer=<mxnet.initializer.Uniform object></em>, <em>arg_params=None</em>, <em>aux_params=None</em>, <em>allow_missing=False</em>, <em>force_init=False</em>, <em>allow_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.init_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.init_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Initializes the parameters and auxiliary states.</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>initializer</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – Called to initialize parameters if needed.</li> |
| <li><strong>arg_params</strong> (<em>dict</em>) – If not <code class="docutils literal"><span class="pre">None</span></code>, should be a dictionary of existing <cite>arg_params</cite>. Initialization |
| will be copied from that.</li> |
| <li><strong>aux_params</strong> (<em>dict</em>) – If not <code class="docutils literal"><span class="pre">None</span></code>, should be a dictionary of existing <cite>aux_params</cite>. Initialization |
| will be copied from that.</li> |
| <li><strong>allow_missing</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, params could contain missing values, and the initializer will be |
| called to fill those missing params.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, <cite>force_init</cite> will force re-initialize even if already initialized.</li> |
| <li><strong>allow_extra</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Whether allow extra parameters that are not needed by symbol. |
| If this is True, no error will be thrown when arg_params or aux_params |
| contain extra parameters that is not needed by the executor.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of initializing module parameters.</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">init_params</span><span class="p">()</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.set_params"> |
| <code class="descname">set_params</code><span class="sig-paren">(</span><em>arg_params</em>, <em>aux_params</em>, <em>allow_missing=False</em>, <em>force_init=True</em>, <em>allow_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.set_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.set_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Assigns parameter and aux state values.</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>arg_params</strong> (<em>dict</em>) – Dictionary of name to value (<cite>NDArray</cite>) mapping.</li> |
| <li><strong>aux_params</strong> (<em>dict</em>) – Dictionary of name to value (<cite>NDArray</cite>) mapping.</li> |
| <li><strong>allow_missing</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, params could contain missing values, and the initializer will be |
| called to fill those missing params.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, will force re-initialize even if already initialized.</li> |
| <li><strong>allow_extra</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Whether allow extra parameters that are not needed by symbol. |
| If this is True, no error will be thrown when arg_params or aux_params |
| contain extra parameters that is not needed by the executor.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of setting module parameters.</span> |
| <span class="gp">>>> </span><span class="n">sym</span><span class="p">,</span> <span class="n">arg_params</span><span class="p">,</span> <span class="n">aux_params</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">load_checkpoint</span><span class="p">(</span><span class="n">model_prefix</span><span class="p">,</span> <span class="n">n_epoch_load</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">set_params</span><span class="p">(</span><span class="n">arg_params</span><span class="o">=</span><span class="n">arg_params</span><span class="p">,</span> <span class="n">aux_params</span><span class="o">=</span><span class="n">aux_params</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.save_params"> |
| <code class="descname">save_params</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.save_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.save_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Saves model parameters to 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 param file.</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of saving module parameters.</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">save_params</span><span class="p">(</span><span class="s1">'myfile'</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.load_params"> |
| <code class="descname">load_params</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.load_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.load_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Loads model parameters from 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 param file.</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of loading module parameters.</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">load_params</span><span class="p">(</span><span class="s1">'myfile'</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.get_states"> |
| <code class="descname">get_states</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.get_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.get_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets states from all devices</p> |
| <p>If <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">True</span></code>, returns output of form <code class="docutils literal"><span class="pre">[out1,</span> <span class="pre">out2]</span></code>. |
| Otherwise, it returns output of the form |
| <code class="docutils literal"><span class="pre">[[out1_dev1,</span> <span class="pre">out1_dev2],</span> <span class="pre">[out2_dev1,</span> <span class="pre">out2_dev2]]</span></code>. |
| All output elements are <cite>NDArray</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"><strong>merge_multi_context</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the states |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicates that we |
| should merge the collected results so that they look like from a single |
| executor.</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">A list of <code class="docutils literal"><span class="pre">NDArray</span></code> or a list of list of <code class="docutils literal"><span class="pre">NDArray</span></code>.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.set_states"> |
| <code class="descname">set_states</code><span class="sig-paren">(</span><em>states=None</em>, <em>value=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.set_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.set_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Sets value for states. Only one of states & value can be specified.</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>states</strong> (<em>list of list of NDArray</em>) – Source states arrays formatted like |
| <code class="docutils literal"><span class="pre">[[state1_dev1,</span> <span class="pre">state1_dev2],</span> <span class="pre">[state2_dev1,</span> <span class="pre">state2_dev2]]</span></code>.</li> |
| <li><strong>value</strong> (<em>number</em>) – A single scalar value for all state arrays.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.install_monitor"> |
| <code class="descname">install_monitor</code><span class="sig-paren">(</span><em>mon</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.install_monitor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.install_monitor" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Installs monitor on all executors.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.prepare"> |
| <code class="descname">prepare</code><span class="sig-paren">(</span><em>data_batch</em>, <em>sparse_row_id_fn=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.prepare"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.prepare" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Prepares the module for processing a data batch.</p> |
| <p>Usually involves switching bucket and reshaping. |
| For modules that contain <cite>row_sparse</cite> parameters in KVStore, |
| it prepares the <cite>row_sparse</cite> parameters based on the sparse_row_id_fn.</p> |
| <p>When KVStore is used to update parameters for multi-device or multi-machine training, |
| a copy of the parameters are stored in KVStore. Note that for <cite>row_sparse</cite> parameters, |
| the <cite>update()</cite> updates the copy of parameters in KVStore, but doesn’t broadcast |
| the updated parameters to all devices / machines. The <cite>prepare</cite> function is used to |
| broadcast <cite>row_sparse</cite> parameters with the next batch of data.</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>data_batch</strong> (<em>DataBatch</em>) – The current batch of data for forward computation.</li> |
| <li><strong>sparse_row_id_fn</strong> (<em>A callback function</em>) – The function takes <cite>data_batch</cite> as an input and returns a dict of |
| str -> NDArray. The resulting dict is used for pulling row_sparse |
| parameters from the kvstore, where the str key is the name of the param, |
| and the value is the row id of the param to pull.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.forward"> |
| <code class="descname">forward</code><span class="sig-paren">(</span><em>data_batch</em>, <em>is_train=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.forward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Forward computation. It supports data batches with different shapes, such as |
| different batch sizes or different image sizes. |
| If reshaping of data batch relates to modification of symbol or module, such as |
| changing image layout ordering or switching from training to predicting, module |
| rebinding is required.</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>data_batch</strong> (<em>DataBatch</em>) – Could be anything with similar API implemented.</li> |
| <li><strong>is_train</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">None</span></code>, which means <cite>is_train</cite> takes the value of <code class="docutils literal"><span class="pre">self.for_training</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">mxnet</span> <span class="k">as</span> <span class="nn">mx</span> |
| <span class="gp">>>> </span><span class="kn">from</span> <span class="nn">collections</span> <span class="k">import</span> <span class="n">namedtuple</span> |
| <span class="gp">>>> </span><span class="n">Batch</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s1">'Batch'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'data'</span><span class="p">])</span> |
| <span class="gp">>>> </span><span class="n">data</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">Variable</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">data</span> <span class="o">*</span> <span class="mi">2</span> |
| <span class="gp">>>> </span><span class="n">mod</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">mod</span><span class="o">.</span><span class="n">Module</span><span class="p">(</span><span class="n">symbol</span><span class="o">=</span><span class="n">out</span><span class="p">,</span> <span class="n">label_names</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">data_shapes</span><span class="o">=</span><span class="p">[(</span><span class="s1">'data'</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">))])</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">init_params</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="n">data1</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">))]</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">Batch</span><span class="p">(</span><span class="n">data1</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="nb">print</span> <span class="n">mod</span><span class="o">.</span><span class="n">get_outputs</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">[[ 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]]</span> |
| <span class="gp">>>> </span><span class="c1"># Forward with data batch of different shape</span> |
| <span class="gp">>>> </span><span class="n">data2</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">))]</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">Batch</span><span class="p">(</span><span class="n">data2</span><span class="p">))</span> |
| <span class="gp">>>> </span><span class="nb">print</span> <span class="n">mod</span><span class="o">.</span><span class="n">get_outputs</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">[[ 2. 2. 2. 2. 2.]</span> |
| <span class="go"> [ 2. 2. 2. 2. 2.]</span> |
| <span class="go"> [ 2. 2. 2. 2. 2.]]</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.backward"> |
| <code class="descname">backward</code><span class="sig-paren">(</span><em>out_grads=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.backward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.backward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Backward computation.</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>out_grads</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a><em> or </em><em>list of NDArray</em><em>, </em><em>optional</em>) – Gradient on the outputs to be propagated back. |
| This parameter is only needed when bind is called |
| on outputs that are not a loss function.</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of backward computation.</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">backward</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="nb">print</span> <span class="n">mod</span><span class="o">.</span><span class="n">get_input_grads</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">[[[ 1.10182791e-05 5.12257748e-06 4.01927764e-06 8.32566820e-06</span> |
| <span class="go"> -1.59775993e-06 7.24269375e-06 7.28067835e-06 -1.65902311e-05</span> |
| <span class="go"> 5.46342608e-06 8.44196393e-07]</span> |
| <span class="go"> ...]]</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.get_outputs"> |
| <code class="descname">get_outputs</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.get_outputs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.get_outputs" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets outputs of the previous forward computation.</p> |
| <p>If <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[out1,</span> <span class="pre">out2]</span></code>. Otherwise, |
| it returns out put of form <code class="docutils literal"><span class="pre">[[out1_dev1,</span> <span class="pre">out1_dev2],</span> <span class="pre">[out2_dev1,</span> <span class="pre">out2_dev2]]</span></code>. |
| All the output elements have type <cite>NDArray</cite>. When <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">False</span></code>, |
| those <cite>NDArray</cite> instances might live on different devices.</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>merge_multi_context</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the outputs |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicates that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of <cite>NDArray</cite> or list of list of <cite>NDArray</cite>.</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of getting forward output.</span> |
| <span class="gp">>>> </span><span class="nb">print</span> <span class="n">mod</span><span class="o">.</span><span class="n">get_outputs</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">[[ 0.09999977 0.10000153 0.10000716 0.10000195 0.09999853 0.09999743</span> |
| <span class="go"> 0.10000272 0.10000113 0.09999088 0.09999888]]</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.get_input_grads"> |
| <code class="descname">get_input_grads</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.get_input_grads"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.get_input_grads" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets the gradients to the inputs, computed in the previous backward computation.</p> |
| <p>If <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[grad1,</span> <span class="pre">grad2]</span></code>. Otherwise, it |
| is like <code class="docutils literal"><span class="pre">[[grad1_dev1,</span> <span class="pre">grad1_dev2],</span> <span class="pre">[grad2_dev1,</span> <span class="pre">grad2_dev2]]</span></code>. All the output |
| elements have type <cite>NDArray</cite>. When <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">False</span></code>, those <cite>NDArray</cite> |
| instances might live on different devices.</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>merge_multi_context</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the gradients |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicates that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Input gradients.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of NDArray or list of list of NDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of getting input gradients.</span> |
| <span class="gp">>>> </span><span class="nb">print</span> <span class="n">mod</span><span class="o">.</span><span class="n">get_input_grads</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">[[[ 1.10182791e-05 5.12257748e-06 4.01927764e-06 8.32566820e-06</span> |
| <span class="go"> -1.59775993e-06 7.24269375e-06 7.28067835e-06 -1.65902311e-05</span> |
| <span class="go"> 5.46342608e-06 8.44196393e-07]</span> |
| <span class="go"> ...]]</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.update"> |
| <code class="descname">update</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.update"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.update" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Updates parameters according to the installed optimizer and the gradients computed |
| in the previous forward-backward batch.</p> |
| <p>When KVStore is used to update parameters for multi-device or multi-machine training, |
| a copy of the parameters are stored in KVStore. Note that for <cite>row_sparse</cite> parameters, |
| this function does update the copy of parameters in KVStore, but doesn’t broadcast the |
| updated parameters to all devices / machines. Please call <cite>prepare</cite> to broadcast |
| <cite>row_sparse</cite> parameters with the next batch of data.</p> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of updating module parameters.</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">init_optimizer</span><span class="p">(</span><span class="n">kvstore</span><span class="o">=</span><span class="s1">'local'</span><span class="p">,</span> <span class="n">optimizer</span><span class="o">=</span><span class="s1">'sgd'</span><span class="p">,</span> |
| <span class="gp">... </span> <span class="n">optimizer_params</span><span class="o">=</span><span class="p">((</span><span class="s1">'learning_rate'</span><span class="p">,</span> <span class="mf">0.01</span><span class="p">),</span> <span class="p">))</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">backward</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">update</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="nb">print</span> <span class="n">mod</span><span class="o">.</span><span class="n">get_params</span><span class="p">()[</span><span class="mi">0</span><span class="p">][</span><span class="s1">'fc3_weight'</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span> |
| <span class="go">[[ 5.86930104e-03 5.28078526e-03 -8.88729654e-03 -1.08308345e-03</span> |
| <span class="go"> 6.13054074e-03 4.27560415e-03 1.53817423e-03 4.62131854e-03</span> |
| <span class="go"> 4.69872449e-03 -2.42400169e-03 9.94111411e-04 1.12386420e-03</span> |
| <span class="go"> ...]]</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.update_metric"> |
| <code class="descname">update_metric</code><span class="sig-paren">(</span><em>eval_metric</em>, <em>labels</em>, <em>pre_sliced=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.update_metric"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.update_metric" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Evaluates and accumulates evaluation metric on outputs of the last forward |
| computation.</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>eval_metric</strong> (<a class="reference internal" href="../metric/metric.html#mxnet.metric.EvalMetric" title="mxnet.metric.EvalMetric"><em>EvalMetric</em></a>) – Evaluation metric to use.</li> |
| <li><strong>labels</strong> (list of NDArray if <cite>pre_sliced</cite> parameter is set to <cite>False</cite>,) – list of lists of NDArray otherwise. Typically <cite>data_batch.label</cite>.</li> |
| <li><strong>pre_sliced</strong> (<em>bool</em>) – Whether the labels are already sliced per device (default: False).</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of updating evaluation metric.</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">data_batch</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">update_metric</span><span class="p">(</span><span class="n">metric</span><span class="p">,</span> <span class="n">data_batch</span><span class="o">.</span><span class="n">label</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.bind"> |
| <code class="descname">bind</code><span class="sig-paren">(</span><em>data_shapes</em>, <em>label_shapes=None</em>, <em>for_training=True</em>, <em>inputs_need_grad=False</em>, <em>force_rebind=False</em>, <em>shared_module=None</em>, <em>grad_req='write'</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.bind"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.bind" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Binds the symbols to construct executors. This is necessary before one |
| can perform computation with the module.</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>data_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>) or </em><em>DataDesc objects</em>) – Typically is <code class="docutils literal"><span class="pre">data_iter.provide_data</span></code>. Can also be a list of |
| (data name, data shape).</li> |
| <li><strong>label_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>) or </em><em>DataDesc objects</em>) – Typically is <code class="docutils literal"><span class="pre">data_iter.provide_label</span></code>. Can also be a list of |
| (label name, label shape).</li> |
| <li><strong>for_training</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>. Whether the executors should be bind for training.</li> |
| <li><strong>inputs_need_grad</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>. Whether the gradients to the input data need to be computed. |
| Typically this is not needed. But this might be needed when implementing composition |
| of modules.</li> |
| <li><strong>force_rebind</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>. This function does nothing if the executors are already |
| bound. But with this <code class="docutils literal"><span class="pre">True</span></code>, the executors will be forced to rebind.</li> |
| <li><strong>shared_module</strong> (<a class="reference internal" href="#mxnet.module.Module" title="mxnet.module.Module"><em>Module</em></a>) – Default is <code class="docutils literal"><span class="pre">None</span></code>. This is used in bucketing. When not <code class="docutils literal"><span class="pre">None</span></code>, the shared module |
| essentially corresponds to a different bucket – a module with different symbol |
| but with the same sets of parameters (e.g. unrolled RNNs with different lengths).</li> |
| <li><strong>grad_req</strong> (<em>str</em><em>, </em><em>list of str</em><em>, </em><em>dict of str to str</em>) – Requirement for gradient accumulation. Can be ‘write’, ‘add’, or ‘null’ |
| (default to ‘write’). |
| Can be specified globally (str) or for each argument (list, dict).</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of binding symbols.</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">data_shapes</span><span class="o">=</span><span class="p">[(</span><span class="s1">'data'</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</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="gp">>>> </span><span class="c1"># Assume train_iter is already created.</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">data_shapes</span><span class="o">=</span><span class="n">train_iter</span><span class="o">.</span><span class="n">provide_data</span><span class="p">,</span> <span class="n">label_shapes</span><span class="o">=</span><span class="n">train_iter</span><span class="o">.</span><span class="n">provide_label</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BaseModule.init_optimizer"> |
| <code class="descname">init_optimizer</code><span class="sig-paren">(</span><em>kvstore='local'</em>, <em>optimizer='sgd'</em>, <em>optimizer_params=(('learning_rate'</em>, <em>0.01)</em>, <em>)</em>, <em>force_init=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/base_module.html#BaseModule.init_optimizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BaseModule.init_optimizer" title="Permalink to this definition">¶</a></dt> |
| <dd><dl class="docutils"> |
| <dt>Installs and initializes optimizers, as well as initialize kvstore for</dt> |
| <dd>distributed training</dd> |
| </dl> |
| <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>kvstore</strong> (<em>str</em><em> or </em><a class="reference internal" href="../kvstore/kvstore.html#mxnet.kvstore.KVStore" title="mxnet.kvstore.KVStore"><em>KVStore</em></a>) – Defaults to <cite>‘local’</cite>.</li> |
| <li><strong>optimizer</strong> (<em>str</em><em> or </em><a class="reference internal" href="../optimization/optimization.html#mxnet.optimizer.Optimizer" title="mxnet.optimizer.Optimizer"><em>Optimizer</em></a>) – Defaults to <cite>‘sgd’</cite>.</li> |
| <li><strong>optimizer_params</strong> (<em>dict</em>) – Defaults to <code class="docutils literal"><span class="pre">(('learning_rate',</span> <span class="pre">0.01),)</span></code>. The default value is not a dictionary, |
| just to avoid pylint warning of dangerous default values.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">False</span></code>, indicates whether to force re-initializing an optimizer |
| if it is already installed.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of initializing optimizer.</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">init_optimizer</span><span class="p">(</span><span class="n">optimizer</span><span class="o">=</span><span class="s1">'sgd'</span><span class="p">,</span> <span class="n">optimizer_params</span><span class="o">=</span><span class="p">((</span><span class="s1">'learning_rate'</span><span class="p">,</span> <span class="mf">0.005</span><span class="p">),))</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BaseModule.symbol"> |
| <code class="descname">symbol</code><a class="headerlink" href="#mxnet.module.BaseModule.symbol" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets the symbol associated with this module.</p> |
| <p>Except for <cite>Module</cite>, for other types of modules (e.g. <cite>BucketingModule</cite>), this |
| property might not be a constant throughout its life time. Some modules might |
| not even be associated with any symbols.</p> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.module.Module"> |
| <em class="property">class </em><code class="descclassname">mxnet.module.</code><code class="descname">Module</code><span class="sig-paren">(</span><em>symbol</em>, <em>data_names=('data'</em>, <em>)</em>, <em>label_names=('softmax_label'</em>, <em>)</em>, <em>logger=<module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'></em>, <em>context=cpu(0)</em>, <em>work_load_list=None</em>, <em>fixed_param_names=None</em>, <em>state_names=None</em>, <em>group2ctxs=None</em>, <em>compression_params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Module is a basic module that wrap a <cite>Symbol</cite>. It is functionally the same |
| as the <cite>FeedForward</cite> model, except under the module 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>symbol</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol" title="mxnet.symbol.Symbol"><em>Symbol</em></a>) – </li> |
| <li><strong>data_names</strong> (<em>list of str</em>) – Defaults to <cite>(‘data’)</cite> for a typical model used in image classification.</li> |
| <li><strong>label_names</strong> (<em>list of str</em>) – Defaults to <cite>(‘softmax_label’)</cite> for a typical model used in image |
| classification.</li> |
| <li><strong>logger</strong> (<em>Logger</em>) – Defaults to <cite>logging</cite>.</li> |
| <li><strong>context</strong> (<em>Context</em><em> or </em><em>list of Context</em>) – Defaults to <code class="docutils literal"><span class="pre">mx.cpu()</span></code>.</li> |
| <li><strong>work_load_list</strong> (<em>list of number</em>) – Default <code class="docutils literal"><span class="pre">None</span></code>, indicating uniform workload.</li> |
| <li><strong>fixed_param_names</strong> (<em>list of str</em>) – Default <code class="docutils literal"><span class="pre">None</span></code>, indicating no network parameters are fixed.</li> |
| <li><strong>state_names</strong> (<em>list of str</em>) – states are similar to data and label, but not provided by data iterator. |
| Instead they are initialized to 0 and can be set by <cite>set_states()</cite>.</li> |
| <li><strong>group2ctxs</strong> (<em>dict of str to context</em><em> or </em><em>list of context</em><em>,</em>) – or list of dict of str to context |
| Default is <cite>None</cite>. Mapping the <cite>ctx_group</cite> attribute to the context assignment.</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> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <dl class="staticmethod"> |
| <dt id="mxnet.module.Module.load"> |
| <em class="property">static </em><code class="descname">load</code><span class="sig-paren">(</span><em>prefix</em>, <em>epoch</em>, <em>load_optimizer_states=False</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.load"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.load" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Creates a model from previously saved checkpoint.</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>) – path prefix of saved model files. You should have |
| “prefix-symbol.json”, “prefix-xxxx.params”, and |
| optionally “prefix-xxxx.states”, where xxxx is the |
| epoch number.</li> |
| <li><strong>epoch</strong> (<em>int</em>) – epoch to load.</li> |
| <li><strong>load_optimizer_states</strong> (<em>bool</em>) – whether to load optimizer states. Checkpoint needs |
| to have been made with save_optimizer_states=True.</li> |
| <li><strong>data_names</strong> (<em>list of str</em>) – Default is <cite>(‘data’)</cite> for a typical model used in image classification.</li> |
| <li><strong>label_names</strong> (<em>list of str</em>) – Default is <cite>(‘softmax_label’)</cite> for a typical model used in image |
| classification.</li> |
| <li><strong>logger</strong> (<em>Logger</em>) – Default is <cite>logging</cite>.</li> |
| <li><strong>context</strong> (<em>Context</em><em> or </em><em>list of Context</em>) – Default is <code class="docutils literal"><span class="pre">cpu()</span></code>.</li> |
| <li><strong>work_load_list</strong> (<em>list of number</em>) – Default <code class="docutils literal"><span class="pre">None</span></code>, indicating uniform workload.</li> |
| <li><strong>fixed_param_names</strong> (<em>list of str</em>) – Default <code class="docutils literal"><span class="pre">None</span></code>, indicating no network parameters are fixed.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.save_checkpoint"> |
| <code class="descname">save_checkpoint</code><span class="sig-paren">(</span><em>prefix</em>, <em>epoch</em>, <em>save_optimizer_states=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.save_checkpoint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.save_checkpoint" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Saves current progress to checkpoint. |
| Use <cite>mx.callback.module_checkpoint</cite> as <cite>epoch_end_callback</cite> to save during training.</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>) – The file prefix to checkpoint to.</li> |
| <li><strong>epoch</strong> (<em>int</em>) – The current epoch number.</li> |
| <li><strong>save_optimizer_states</strong> (<em>bool</em>) – Whether to save optimizer states to continue training.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.Module.data_names"> |
| <code class="descname">data_names</code><a class="headerlink" href="#mxnet.module.Module.data_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for data required by this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.Module.label_names"> |
| <code class="descname">label_names</code><a class="headerlink" href="#mxnet.module.Module.label_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for labels required by this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.Module.output_names"> |
| <code class="descname">output_names</code><a class="headerlink" href="#mxnet.module.Module.output_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for the outputs of this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.Module.data_shapes"> |
| <code class="descname">data_shapes</code><a class="headerlink" href="#mxnet.module.Module.data_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets data shapes.</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">Returns:</th><td class="field-body"></td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">A list of <cite>(name, shape)</cite> pairs.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.Module.label_shapes"> |
| <code class="descname">label_shapes</code><a class="headerlink" href="#mxnet.module.Module.label_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets label shapes.</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">Returns:</th><td class="field-body">The return value could be <code class="docutils literal"><span class="pre">None</span></code> if |
| the module does not need labels, or if the module is not bound for |
| training (in this case, label information is not available).</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">A list of <cite>(name, shape)</cite> pairs.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.Module.output_shapes"> |
| <code class="descname">output_shapes</code><a class="headerlink" href="#mxnet.module.Module.output_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets output shapes.</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">Returns:</th><td class="field-body"></td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">A list of <cite>(name, shape)</cite> pairs.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.get_params"> |
| <code class="descname">get_params</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.get_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.get_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets current 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">Returns:</th><td class="field-body">A pair of dictionaries each mapping parameter names to NDArray values.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><cite>(arg_params, aux_params)</cite></td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.init_params"> |
| <code class="descname">init_params</code><span class="sig-paren">(</span><em>initializer=<mxnet.initializer.Uniform object></em>, <em>arg_params=None</em>, <em>aux_params=None</em>, <em>allow_missing=False</em>, <em>force_init=False</em>, <em>allow_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.init_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.init_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Initializes the parameters and auxiliary states.</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>initializer</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – Called to initialize parameters if needed.</li> |
| <li><strong>arg_params</strong> (<em>dict</em>) – If not <code class="docutils literal"><span class="pre">None</span></code>, should be a dictionary of existing arg_params. Initialization |
| will be copied from that.</li> |
| <li><strong>aux_params</strong> (<em>dict</em>) – If not <code class="docutils literal"><span class="pre">None</span></code>, should be a dictionary of existing aux_params. Initialization |
| will be copied from that.</li> |
| <li><strong>allow_missing</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, params could contain missing values, and the initializer will be |
| called to fill those missing params.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, will force re-initialize even if already initialized.</li> |
| <li><strong>allow_extra</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Whether allow extra parameters that are not needed by symbol. |
| If this is True, no error will be thrown when arg_params or aux_params |
| contain extra parameters that is not needed by the executor.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.set_params"> |
| <code class="descname">set_params</code><span class="sig-paren">(</span><em>arg_params</em>, <em>aux_params</em>, <em>allow_missing=False</em>, <em>force_init=True</em>, <em>allow_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.set_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.set_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Assigns parameter and aux state values.</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>arg_params</strong> (<em>dict</em>) – Dictionary of name to <cite>NDArray</cite>.</li> |
| <li><strong>aux_params</strong> (<em>dict</em>) – Dictionary of name to <cite>NDArray</cite>.</li> |
| <li><strong>allow_missing</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, params could contain missing values, and the initializer will be |
| called to fill those missing params.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, will force re-initialize even if already initialized.</li> |
| <li><strong>allow_extra</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Whether allow extra parameters that are not needed by symbol. |
| If this is True, no error will be thrown when arg_params or aux_params |
| contain extra parameters that is not needed by the executor.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of setting module parameters.</span> |
| <span class="gp">>>> </span><span class="n">sym</span><span class="p">,</span> <span class="n">arg_params</span><span class="p">,</span> <span class="n">aux_params</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">load_checkpoint</span><span class="p">(</span><span class="n">model_prefix</span><span class="p">,</span> <span class="n">n_epoch_load</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">set_params</span><span class="p">(</span><span class="n">arg_params</span><span class="o">=</span><span class="n">arg_params</span><span class="p">,</span> <span class="n">aux_params</span><span class="o">=</span><span class="n">aux_params</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.bind"> |
| <code class="descname">bind</code><span class="sig-paren">(</span><em>data_shapes</em>, <em>label_shapes=None</em>, <em>for_training=True</em>, <em>inputs_need_grad=False</em>, <em>force_rebind=False</em>, <em>shared_module=None</em>, <em>grad_req='write'</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.bind"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.bind" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Binds the symbols to construct executors. This is necessary before one |
| can perform computation with the module.</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>data_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically is <code class="docutils literal"><span class="pre">data_iter.provide_data</span></code>.</li> |
| <li><strong>label_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically is <code class="docutils literal"><span class="pre">data_iter.provide_label</span></code>.</li> |
| <li><strong>for_training</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>. Whether the executors should be bound for training.</li> |
| <li><strong>inputs_need_grad</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>. Whether the gradients to the input data need to be computed. |
| Typically this is not needed. But this might be needed when implementing composition |
| of modules.</li> |
| <li><strong>force_rebind</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>. This function does nothing if the executors are already |
| bound. But with this <code class="docutils literal"><span class="pre">True</span></code>, the executors will be forced to rebind.</li> |
| <li><strong>shared_module</strong> (<a class="reference internal" href="#mxnet.module.Module" title="mxnet.module.Module"><em>Module</em></a>) – Default is <code class="docutils literal"><span class="pre">None</span></code>. This is used in bucketing. When not <code class="docutils literal"><span class="pre">None</span></code>, the shared module |
| essentially corresponds to a different bucket – a module with different symbol |
| but with the same sets of parameters (e.g. unrolled RNNs with different lengths).</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.reshape"> |
| <code class="descname">reshape</code><span class="sig-paren">(</span><em>data_shapes</em>, <em>label_shapes=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.reshape"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.reshape" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Reshapes the module for new input shapes.</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>data_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically is <code class="docutils literal"><span class="pre">data_iter.provide_data</span></code>.</li> |
| <li><strong>label_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically is <code class="docutils literal"><span class="pre">data_iter.provide_label</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.init_optimizer"> |
| <code class="descname">init_optimizer</code><span class="sig-paren">(</span><em>kvstore='local'</em>, <em>optimizer='sgd'</em>, <em>optimizer_params=(('learning_rate'</em>, <em>0.01)</em>, <em>)</em>, <em>force_init=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.init_optimizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.init_optimizer" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Installs and initializes optimizers.</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>kvstore</strong> (<em>str</em><em> or </em><a class="reference internal" href="../kvstore/kvstore.html#mxnet.kvstore.KVStore" title="mxnet.kvstore.KVStore"><em>KVStore</em></a>) – Default <cite>‘local’</cite>.</li> |
| <li><strong>optimizer</strong> (<em>str</em><em> or </em><a class="reference internal" href="../optimization/optimization.html#mxnet.optimizer.Optimizer" title="mxnet.optimizer.Optimizer"><em>Optimizer</em></a>) – Default <cite>‘sgd’</cite></li> |
| <li><strong>optimizer_params</strong> (<em>dict</em>) – Default <cite>((‘learning_rate’, 0.01),)</cite>. The default value is not a dictionary, |
| just to avoid pylint warning of dangerous default values.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – Default <code class="docutils literal"><span class="pre">False</span></code>, indicating whether we should force re-initializing the |
| optimizer in the case an optimizer is already installed.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.borrow_optimizer"> |
| <code class="descname">borrow_optimizer</code><span class="sig-paren">(</span><em>shared_module</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.borrow_optimizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.borrow_optimizer" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Borrows optimizer from a shared module. Used in bucketing, where exactly the same |
| optimizer (esp. kvstore) is used.</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>shared_module</strong> (<a class="reference internal" href="#mxnet.module.Module" title="mxnet.module.Module"><em>Module</em></a>) – </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.forward"> |
| <code class="descname">forward</code><span class="sig-paren">(</span><em>data_batch</em>, <em>is_train=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.forward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Forward computation. It supports data batches with different shapes, such as |
| different batch sizes or different image sizes. |
| If reshaping of data batch relates to modification of symbol or module, such as |
| changing image layout ordering or switching from training to predicting, module |
| rebinding is required.</p> |
| <div class="admonition seealso"> |
| <p class="first admonition-title">See also</p> |
| <p class="last"><a class="reference internal" href="#mxnet.module.BaseModule.forward" title="mxnet.module.BaseModule.forward"><code class="xref py py-meth docutils literal"><span class="pre">BaseModule.forward()</span></code></a></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>data_batch</strong> (<em>DataBatch</em>) – Could be anything with similar API implemented.</li> |
| <li><strong>is_train</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">None</span></code>, which means <code class="docutils literal"><span class="pre">is_train</span></code> takes the value of <code class="docutils literal"><span class="pre">self.for_training</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.backward"> |
| <code class="descname">backward</code><span class="sig-paren">(</span><em>out_grads=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.backward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.backward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Backward computation.</p> |
| <div class="admonition seealso"> |
| <p class="first admonition-title">See also</p> |
| <p class="last"><a class="reference internal" href="#mxnet.module.BaseModule.backward" title="mxnet.module.BaseModule.backward"><code class="xref py py-meth docutils literal"><span class="pre">BaseModule.backward()</span></code></a></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"><strong>out_grads</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a><em> or </em><em>list of NDArray</em><em>, </em><em>optional</em>) – Gradient on the outputs to be propagated back. |
| This parameter is only needed when bind is called |
| on outputs that are not a loss function.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.update"> |
| <code class="descname">update</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.update"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.update" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Updates parameters according to the installed optimizer and the gradients computed |
| in the previous forward-backward batch.</p> |
| <p>When KVStore is used to update parameters for multi-device or multi-machine training, |
| a copy of the parameters are stored in KVStore. Note that for <cite>row_sparse</cite> parameters, |
| this function does update the copy of parameters in KVStore, but doesn’t broadcast the |
| updated parameters to all devices / machines. Please call <cite>prepare</cite> to broadcast |
| <cite>row_sparse</cite> parameters with the next batch of data.</p> |
| <div class="admonition seealso"> |
| <p class="first admonition-title">See also</p> |
| <p class="last"><a class="reference internal" href="#mxnet.module.BaseModule.update" title="mxnet.module.BaseModule.update"><code class="xref py py-meth docutils literal"><span class="pre">BaseModule.update()</span></code></a></p> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.get_outputs"> |
| <code class="descname">get_outputs</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.get_outputs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.get_outputs" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets outputs of the previous forward computation.</p> |
| <p>If <code class="docutils literal"><span class="pre">merge_multi_context</span></code> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[out1,</span> <span class="pre">out2]</span></code>. Otherwise, it |
| is like <code class="docutils literal"><span class="pre">[[out1_dev1,</span> <span class="pre">out1_dev2],</span> <span class="pre">[out2_dev1,</span> <span class="pre">out2_dev2]]</span></code>. All the output |
| elements are <cite>NDArray</cite>. When <cite>merge_multi_context</cite> is <cite>False</cite>, those <cite>NDArray</cite> |
| might live on different devices.</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>merge_multi_context</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the outputs |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicate that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of NDArray or list of list of NDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.get_input_grads"> |
| <code class="descname">get_input_grads</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.get_input_grads"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.get_input_grads" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets the gradients with respect to the inputs of the module.</p> |
| <p>If <code class="docutils literal"><span class="pre">merge_multi_context</span></code> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[grad1,</span> <span class="pre">grad2]</span></code>. Otherwise, it |
| is like <code class="docutils literal"><span class="pre">[[grad1_dev1,</span> <span class="pre">grad1_dev2],</span> <span class="pre">[grad2_dev1,</span> <span class="pre">grad2_dev2]]</span></code>. All the output |
| elements are <cite>NDArray</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"><strong>merge_multi_context</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the outputs |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicate that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Input gradients</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of NDArray or list of list of NDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.get_states"> |
| <code class="descname">get_states</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.get_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.get_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets states from all devices.</p> |
| <p>If <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[out1,</span> <span class="pre">out2]</span></code>. Otherwise, it |
| is like <code class="docutils literal"><span class="pre">[[out1_dev1,</span> <span class="pre">out1_dev2],</span> <span class="pre">[out2_dev1,</span> <span class="pre">out2_dev2]]</span></code>. All the output |
| elements are <cite>NDArray</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"><strong>merge_multi_context</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the states |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicate that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">States</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of NDArray or list of list of NDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.set_states"> |
| <code class="descname">set_states</code><span class="sig-paren">(</span><em>states=None</em>, <em>value=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.set_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.set_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Sets value for states. Only one of the states & value can be specified.</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>states</strong> (<em>list of list of NDArrays</em>) – source states arrays formatted like <code class="docutils literal"><span class="pre">[[state1_dev1,</span> <span class="pre">state1_dev2],</span> |
| <span class="pre">[state2_dev1,</span> <span class="pre">state2_dev2]]</span></code>.</li> |
| <li><strong>value</strong> (<em>number</em>) – a single scalar value for all state arrays.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.update_metric"> |
| <code class="descname">update_metric</code><span class="sig-paren">(</span><em>eval_metric</em>, <em>labels</em>, <em>pre_sliced=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.update_metric"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.update_metric" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Evaluates and accumulates evaluation metric on outputs of the last forward computation.</p> |
| <div class="admonition seealso"> |
| <p class="first admonition-title">See also</p> |
| <p class="last"><a class="reference internal" href="#mxnet.module.BaseModule.update_metric" title="mxnet.module.BaseModule.update_metric"><code class="xref py py-meth docutils literal"><span class="pre">BaseModule.update_metric()</span></code></a></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>eval_metric</strong> (<a class="reference internal" href="../metric/metric.html#mxnet.metric.EvalMetric" title="mxnet.metric.EvalMetric"><em>EvalMetric</em></a>) – Evaluation metric to use.</li> |
| <li><strong>labels</strong> (list of NDArray if <cite>pre_sliced</cite> parameter is set to <cite>False</cite>,) – list of lists of NDArray otherwise. Typically <cite>data_batch.label</cite>.</li> |
| <li><strong>pre_sliced</strong> (<em>bool</em>) – Whether the labels are already sliced per device (default: False).</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.save_optimizer_states"> |
| <code class="descname">save_optimizer_states</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.save_optimizer_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.save_optimizer_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Saves optimizer (updater) state 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.module.Module.load_optimizer_states"> |
| <code class="descname">load_optimizer_states</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.load_optimizer_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.load_optimizer_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Loads optimizer (updater) state 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.module.Module.install_monitor"> |
| <code class="descname">install_monitor</code><span class="sig-paren">(</span><em>mon</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.install_monitor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.install_monitor" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Installs monitor on all executors.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.Module.prepare"> |
| <code class="descname">prepare</code><span class="sig-paren">(</span><em>data_batch</em>, <em>sparse_row_id_fn=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/module.html#Module.prepare"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.Module.prepare" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Prepares the module for processing a data batch.</p> |
| <p>Usually involves switching bucket and reshaping. |
| For modules that contain <cite>row_sparse</cite> parameters in KVStore, |
| it prepares the <cite>row_sparse</cite> parameters based on the sparse_row_id_fn.</p> |
| <p>When KVStore is used to update parameters for multi-device or multi-machine training, |
| a copy of the parameters are stored in KVStore. Note that for <cite>row_sparse</cite> parameters, |
| the <cite>update()</cite> updates the copy of parameters in KVStore, but doesn’t broadcast |
| the updated parameters to all devices / machines. The <cite>prepare</cite> function is used to |
| broadcast <cite>row_sparse</cite> parameters with the next batch of data.</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>data_batch</strong> (<em>DataBatch</em>) – The current batch of data for forward computation.</li> |
| <li><strong>sparse_row_id_fn</strong> (<em>A callback function</em>) – The function takes <cite>data_batch</cite> as an input and returns a dict of |
| str -> NDArray. The resulting dict is used for pulling row_sparse |
| parameters from the kvstore, where the str key is the name of the param, |
| and the value is the row id of the param to pull.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.module.BucketingModule"> |
| <em class="property">class </em><code class="descclassname">mxnet.module.</code><code class="descname">BucketingModule</code><span class="sig-paren">(</span><em>sym_gen</em>, <em>default_bucket_key=None</em>, <em>logger=<module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'></em>, <em>context=cpu(0)</em>, <em>work_load_list=None</em>, <em>fixed_param_names=None</em>, <em>state_names=None</em>, <em>group2ctxs=None</em>, <em>compression_params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule" title="Permalink to this definition">¶</a></dt> |
| <dd><p>This module helps to deal efficiently with varying-length inputs.</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>sym_gen</strong> (<em>function</em>) – A function when called with a bucket key, returns a triple |
| <code class="docutils literal"><span class="pre">(symbol,</span> <span class="pre">data_names,</span> <span class="pre">label_names)</span></code>.</li> |
| <li><strong>default_bucket_key</strong> (<em>str</em><em> (or </em><em>any python object</em><em>)</em>) – The key for the default bucket.</li> |
| <li><strong>logger</strong> (<em>Logger</em>) – </li> |
| <li><strong>context</strong> (<em>Context</em><em> or </em><em>list of Context</em>) – Defaults to <code class="docutils literal"><span class="pre">mx.cpu()</span></code></li> |
| <li><strong>work_load_list</strong> (<em>list of number</em>) – Defaults to <code class="docutils literal"><span class="pre">None</span></code>, indicating uniform workload.</li> |
| <li><strong>fixed_param_names</strong> (<em>list of str</em>) – Defaults to <code class="docutils literal"><span class="pre">None</span></code>, indicating no network parameters are fixed.</li> |
| <li><strong>state_names</strong> (<em>list of str</em>) – States are similar to data and label, but not provided by data iterator. |
| Instead they are initialized to 0 and can be set by set_states()</li> |
| <li><strong>group2ctxs</strong> (<em>dict of str to context</em><em> or </em><em>list of context</em><em>,</em>) – or list of dict of str to context |
| Default is <cite>None</cite>. Mapping the <cite>ctx_group</cite> attribute to the context assignment.</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> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BucketingModule.data_names"> |
| <code class="descname">data_names</code><a class="headerlink" href="#mxnet.module.BucketingModule.data_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for data required by this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BucketingModule.output_names"> |
| <code class="descname">output_names</code><a class="headerlink" href="#mxnet.module.BucketingModule.output_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for the outputs of this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BucketingModule.data_shapes"> |
| <code class="descname">data_shapes</code><a class="headerlink" href="#mxnet.module.BucketingModule.data_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Get data shapes.</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">Returns:</th><td class="field-body"></td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">A list of <cite>(name, shape)</cite> pairs.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BucketingModule.label_shapes"> |
| <code class="descname">label_shapes</code><a class="headerlink" href="#mxnet.module.BucketingModule.label_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Get label shapes.</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">Returns:</th><td class="field-body">The return value could be <code class="docutils literal"><span class="pre">None</span></code> if the module does not need labels, |
| or if the module is not bound for training (in this case, label information |
| is not available).</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">A list of <cite>(name, shape)</cite> pairs.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BucketingModule.output_shapes"> |
| <code class="descname">output_shapes</code><a class="headerlink" href="#mxnet.module.BucketingModule.output_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets output shapes.</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">Returns:</th><td class="field-body"></td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">A list of <cite>(name, shape)</cite> pairs.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.get_params"> |
| <code class="descname">get_params</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.get_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.get_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets current 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">Returns:</th><td class="field-body">A pair of dictionaries each mapping parameter names to NDArray values.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><cite>(arg_params, aux_params)</cite></td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.set_params"> |
| <code class="descname">set_params</code><span class="sig-paren">(</span><em>arg_params</em>, <em>aux_params</em>, <em>allow_missing=False</em>, <em>force_init=True</em>, <em>allow_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.set_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.set_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Assigns parameters and aux state values.</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>arg_params</strong> (<em>dict</em>) – Dictionary of name to value (<cite>NDArray</cite>) mapping.</li> |
| <li><strong>aux_params</strong> (<em>dict</em>) – Dictionary of name to value (<cite>NDArray</cite>) mapping.</li> |
| <li><strong>allow_missing</strong> (<em>bool</em>) – If true, params could contain missing values, and the initializer will be |
| called to fill those missing params.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – If true, will force re-initialize even if already initialized.</li> |
| <li><strong>allow_extra</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Whether allow extra parameters that are not needed by symbol. |
| If this is True, no error will be thrown when arg_params or aux_params |
| contain extra parameters that is not needed by the executor.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of setting module parameters.</span> |
| <span class="gp">>>> </span><span class="n">sym</span><span class="p">,</span> <span class="n">arg_params</span><span class="p">,</span> <span class="n">aux_params</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">load_checkpoint</span><span class="p">(</span><span class="n">model_prefix</span><span class="p">,</span> <span class="n">n_epoch_load</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">set_params</span><span class="p">(</span><span class="n">arg_params</span><span class="o">=</span><span class="n">arg_params</span><span class="p">,</span> <span class="n">aux_params</span><span class="o">=</span><span class="n">aux_params</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.init_params"> |
| <code class="descname">init_params</code><span class="sig-paren">(</span><em>initializer=<mxnet.initializer.Uniform object></em>, <em>arg_params=None</em>, <em>aux_params=None</em>, <em>allow_missing=False</em>, <em>force_init=False</em>, <em>allow_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.init_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.init_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Initializes 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>initializer</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – </li> |
| <li><strong>arg_params</strong> (<em>dict</em>) – Defaults to <code class="docutils literal"><span class="pre">None</span></code>. Existing parameters. This has higher priority |
| than <cite>initializer</cite>.</li> |
| <li><strong>aux_params</strong> (<em>dict</em>) – Defaults to <code class="docutils literal"><span class="pre">None</span></code>. Existing auxiliary states. This has higher priority |
| than <cite>initializer</cite>.</li> |
| <li><strong>allow_missing</strong> (<em>bool</em>) – Allow missing values in <cite>arg_params</cite> and <cite>aux_params</cite> (if not <code class="docutils literal"><span class="pre">None</span></code>). |
| In this case, missing values will be filled with <cite>initializer</cite>.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">False</span></code>.</li> |
| <li><strong>allow_extra</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Whether allow extra parameters that are not needed by symbol. |
| If this is True, no error will be thrown when arg_params or aux_params |
| contain extra parameters that is not needed by the executor.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.get_states"> |
| <code class="descname">get_states</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.get_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.get_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets states from all devices.</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>merge_multi_context</strong> (<em>bool</em>) – Default is <cite>True</cite>. In the case when data-parallelism is used, the states |
| will be collected from multiple devices. A <cite>True</cite> value indicate that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">If <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[out1,</span> <span class="pre">out2]</span></code>. Otherwise, it |
| is like <code class="docutils literal"><span class="pre">[[out1_dev1,</span> <span class="pre">out1_dev2],</span> <span class="pre">[out2_dev1,</span> <span class="pre">out2_dev2]]</span></code>. All the output |
| elements are <cite>NDArray</cite>.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of NDArrays or list of list of NDArrays</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.set_states"> |
| <code class="descname">set_states</code><span class="sig-paren">(</span><em>states=None</em>, <em>value=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.set_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.set_states" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Sets value for states. Only one of states & values can be specified.</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>states</strong> (<em>list of list of NDArrays</em>) – Source states arrays formatted like <code class="docutils literal"><span class="pre">[[state1_dev1,</span> <span class="pre">state1_dev2],</span> |
| <span class="pre">[state2_dev1,</span> <span class="pre">state2_dev2]]</span></code>.</li> |
| <li><strong>value</strong> (<em>number</em>) – A single scalar value for all state arrays.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.bind"> |
| <code class="descname">bind</code><span class="sig-paren">(</span><em>data_shapes</em>, <em>label_shapes=None</em>, <em>for_training=True</em>, <em>inputs_need_grad=False</em>, <em>force_rebind=False</em>, <em>shared_module=None</em>, <em>grad_req='write'</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.bind"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.bind" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Binding for a <cite>BucketingModule</cite> means setting up the buckets and binding the |
| executor for the default bucket key. Executors corresponding to other keys are |
| bound afterwards with <cite>switch_bucket</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>data_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – This should correspond to the symbol for the default bucket.</li> |
| <li><strong>label_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – This should correspond to the symbol for the default bucket.</li> |
| <li><strong>for_training</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>.</li> |
| <li><strong>inputs_need_grad</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>.</li> |
| <li><strong>force_rebind</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>.</li> |
| <li><strong>shared_module</strong> (<a class="reference internal" href="#mxnet.module.BucketingModule" title="mxnet.module.BucketingModule"><em>BucketingModule</em></a>) – Default is <code class="docutils literal"><span class="pre">None</span></code>. This value is currently not used.</li> |
| <li><strong>grad_req</strong> (<em>str</em><em>, </em><em>list of str</em><em>, </em><em>dict of str to str</em>) – Requirement for gradient accumulation. Can be ‘write’, ‘add’, or ‘null’ |
| (default to ‘write’). |
| Can be specified globally (str) or for each argument (list, dict).</li> |
| <li><strong>bucket_key</strong> (<em>str</em><em> (or </em><em>any python object</em><em>)</em>) – bucket key for binding. by default use the default_bucket_key</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.switch_bucket"> |
| <code class="descname">switch_bucket</code><span class="sig-paren">(</span><em>bucket_key</em>, <em>data_shapes</em>, <em>label_shapes=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.switch_bucket"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.switch_bucket" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Switches to a different bucket. This will change <code class="docutils literal"><span class="pre">self.curr_module</span></code>.</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>bucket_key</strong> (<em>str</em><em> (or </em><em>any python object</em><em>)</em>) – The key of the target bucket.</li> |
| <li><strong>data_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically <code class="docutils literal"><span class="pre">data_batch.provide_data</span></code>.</li> |
| <li><strong>label_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically <code class="docutils literal"><span class="pre">data_batch.provide_label</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.init_optimizer"> |
| <code class="descname">init_optimizer</code><span class="sig-paren">(</span><em>kvstore='local'</em>, <em>optimizer='sgd'</em>, <em>optimizer_params=(('learning_rate'</em>, <em>0.01)</em>, <em>)</em>, <em>force_init=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.init_optimizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.init_optimizer" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Installs and initializes optimizers.</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>kvstore</strong> (<em>str</em><em> or </em><a class="reference internal" href="../kvstore/kvstore.html#mxnet.kvstore.KVStore" title="mxnet.kvstore.KVStore"><em>KVStore</em></a>) – Defaults to <cite>‘local’</cite>.</li> |
| <li><strong>optimizer</strong> (<em>str</em><em> or </em><a class="reference internal" href="../optimization/optimization.html#mxnet.optimizer.Optimizer" title="mxnet.optimizer.Optimizer"><em>Optimizer</em></a>) – Defaults to <cite>‘sgd’</cite></li> |
| <li><strong>optimizer_params</strong> (<em>dict</em>) – Defaults to <cite>((‘learning_rate’, 0.01),)</cite>. The default value is not a dictionary, |
| just to avoid pylint warning of dangerous default values.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">False</span></code>, indicating whether we should force re-initializing the |
| optimizer in the case an optimizer is already installed.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.prepare"> |
| <code class="descname">prepare</code><span class="sig-paren">(</span><em>data_batch</em>, <em>sparse_row_id_fn=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.prepare"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.prepare" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Prepares the module for processing a data batch.</p> |
| <p>Usually involves switching bucket and reshaping. |
| For modules that contain <cite>row_sparse</cite> parameters in KVStore, |
| it prepares the <cite>row_sparse</cite> parameters based on the sparse_row_id_fn.</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>data_batch</strong> (<em>DataBatch</em>) – The current batch of data for forward computation.</li> |
| <li><strong>sparse_row_id_fn</strong> (<em>A callback function</em>) – The function takes <cite>data_batch</cite> as an input and returns a dict of |
| str -> NDArray. The resulting dict is used for pulling row_sparse |
| parameters from the kvstore, where the str key is the name of the param, |
| and the value is the row id of the param to pull.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.forward"> |
| <code class="descname">forward</code><span class="sig-paren">(</span><em>data_batch</em>, <em>is_train=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.forward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Forward computation.</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>data_batch</strong> (<em>DataBatch</em>) – </li> |
| <li><strong>is_train</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">None</span></code>, in which case <cite>is_train</cite> is take as <code class="docutils literal"><span class="pre">self.for_training</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.backward"> |
| <code class="descname">backward</code><span class="sig-paren">(</span><em>out_grads=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.backward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.backward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Backward computation.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.update"> |
| <code class="descname">update</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.update"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.update" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Updates parameters according to installed optimizer and the gradient computed |
| in the previous forward-backward cycle.</p> |
| <p>When KVStore is used to update parameters for multi-device or multi-machine training, |
| a copy of the parameters are stored in KVStore. Note that for <cite>row_sparse</cite> parameters, |
| this function does update the copy of parameters in KVStore, but doesn’t broadcast the |
| updated parameters to all devices / machines. Please call <cite>prepare</cite> to broadcast |
| <cite>row_sparse</cite> parameters with the next batch of data.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.get_outputs"> |
| <code class="descname">get_outputs</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.get_outputs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.get_outputs" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets outputs from a previous forward computation.</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>merge_multi_context</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the outputs |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicate that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">If <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[out1,</span> <span class="pre">out2]</span></code>. Otherwise, it |
| is like <code class="docutils literal"><span class="pre">[[out1_dev1,</span> <span class="pre">out1_dev2],</span> <span class="pre">[out2_dev1,</span> <span class="pre">out2_dev2]]</span></code>. All the output |
| elements are numpy arrays.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of numpy arrays or list of list of numpy arrays</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.get_input_grads"> |
| <code class="descname">get_input_grads</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.get_input_grads"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.get_input_grads" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets the gradients with respect to the inputs of the module.</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>merge_multi_context</strong> (<em>bool</em>) – Defaults to <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the outputs |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicate that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">If <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[grad1,</span> <span class="pre">grad2]</span></code>. Otherwise, it |
| is like <code class="docutils literal"><span class="pre">[[grad1_dev1,</span> <span class="pre">grad1_dev2],</span> <span class="pre">[grad2_dev1,</span> <span class="pre">grad2_dev2]]</span></code>. All the output |
| elements are <cite>NDArray</cite>.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of NDArrays or list of list of NDArrays</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.update_metric"> |
| <code class="descname">update_metric</code><span class="sig-paren">(</span><em>eval_metric</em>, <em>labels</em>, <em>pre_sliced=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.update_metric"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.update_metric" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Evaluates and accumulates evaluation metric on outputs of the last forward computation.</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>eval_metric</strong> (<a class="reference internal" href="../metric/metric.html#mxnet.metric.EvalMetric" title="mxnet.metric.EvalMetric"><em>EvalMetric</em></a>) – </li> |
| <li><strong>labels</strong> (<em>list of NDArray</em>) – Typically <code class="docutils literal"><span class="pre">data_batch.label</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.BucketingModule.symbol"> |
| <code class="descname">symbol</code><a class="headerlink" href="#mxnet.module.BucketingModule.symbol" title="Permalink to this definition">¶</a></dt> |
| <dd><p>The symbol of the current bucket being used.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.BucketingModule.install_monitor"> |
| <code class="descname">install_monitor</code><span class="sig-paren">(</span><em>mon</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/bucketing_module.html#BucketingModule.install_monitor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.BucketingModule.install_monitor" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Installs monitor on all executors</p> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.module.SequentialModule"> |
| <em class="property">class </em><code class="descclassname">mxnet.module.</code><code class="descname">SequentialModule</code><span class="sig-paren">(</span><em>logger=<module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'></em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A SequentialModule is a container module that can chain multiple modules together.</p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">Building a computation graph with this kind of imperative container is less |
| flexible and less efficient than the symbolic graph. So, this should be only used as a |
| handy utility.</p> |
| </div> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.add"> |
| <code class="descname">add</code><span class="sig-paren">(</span><em>module</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.add"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.add" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Add a module to the chain.</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>module</strong> (<a class="reference internal" href="#mxnet.module.BaseModule" title="mxnet.module.BaseModule"><em>BaseModule</em></a>) – The new module to add.</li> |
| <li><strong>kwargs</strong> (<code class="docutils literal"><span class="pre">**keywords</span></code>) – <p>All the keyword arguments are saved as meta information |
| for the added module. The currently known meta includes</p> |
| <ul> |
| <li><dl class="first docutils"> |
| <dt><cite>take_labels</cite>: indicating whether the module expect to</dt> |
| <dd>take labels when doing computation. Note any module in |
| the chain can take labels (not necessarily only the top |
| most one), and they all take the same labels passed |
| from the original data batch for the <cite>SequentialModule</cite>.</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">This function returns <cite>self</cite> to allow us to easily chain a |
| series of <cite>add</cite> calls.</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">self</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p class="rubric">Examples</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># An example of addinging two modules to a chain.</span> |
| <span class="gp">>>> </span><span class="n">seq_mod</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">mod</span><span class="o">.</span><span class="n">SequentialModule</span><span class="p">()</span> |
| <span class="gp">>>> </span><span class="n">seq_mod</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">mod1</span><span class="p">)</span> |
| <span class="gp">>>> </span><span class="n">seq_mod</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">mod2</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.SequentialModule.data_names"> |
| <code class="descname">data_names</code><a class="headerlink" href="#mxnet.module.SequentialModule.data_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for data required by this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.SequentialModule.output_names"> |
| <code class="descname">output_names</code><a class="headerlink" href="#mxnet.module.SequentialModule.output_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for the outputs of this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.SequentialModule.data_shapes"> |
| <code class="descname">data_shapes</code><a class="headerlink" href="#mxnet.module.SequentialModule.data_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets data shapes.</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">Returns:</th><td class="field-body">A list of <cite>(name, shape)</cite> pairs. The data shapes of the first module |
| is the data shape of a <cite>SequentialModule</cite>.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">list</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.SequentialModule.label_shapes"> |
| <code class="descname">label_shapes</code><a class="headerlink" href="#mxnet.module.SequentialModule.label_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets label shapes.</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">Returns:</th><td class="field-body">A list of <cite>(name, shape)</cite> pairs. The return value could be <cite>None</cite> if |
| the module does not need labels, or if the module is not bound for |
| training (in this case, label information is not available).</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">list</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.SequentialModule.output_shapes"> |
| <code class="descname">output_shapes</code><a class="headerlink" href="#mxnet.module.SequentialModule.output_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets output shapes.</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">Returns:</th><td class="field-body">A list of <cite>(name, shape)</cite> pairs. The output shapes of the last |
| module is the output shape of a <cite>SequentialModule</cite>.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">list</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.get_params"> |
| <code class="descname">get_params</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.get_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.get_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets current 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">Returns:</th><td class="field-body">A pair of dictionaries each mapping parameter names to NDArray values. This |
| is a merged dictionary of all the parameters in the modules.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">(arg_params, aux_params)</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.init_params"> |
| <code class="descname">init_params</code><span class="sig-paren">(</span><em>initializer=<mxnet.initializer.Uniform object></em>, <em>arg_params=None</em>, <em>aux_params=None</em>, <em>allow_missing=False</em>, <em>force_init=False</em>, <em>allow_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.init_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.init_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Initializes 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>initializer</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – </li> |
| <li><strong>arg_params</strong> (<em>dict</em>) – Default <code class="docutils literal"><span class="pre">None</span></code>. Existing parameters. This has higher priority |
| than <cite>initializer</cite>.</li> |
| <li><strong>aux_params</strong> (<em>dict</em>) – Default <code class="docutils literal"><span class="pre">None</span></code>. Existing auxiliary states. This has higher priority |
| than <cite>initializer</cite>.</li> |
| <li><strong>allow_missing</strong> (<em>bool</em>) – Allow missing values in <cite>arg_params</cite> and <cite>aux_params</cite> (if not <code class="docutils literal"><span class="pre">None</span></code>). |
| In this case, missing values will be filled with <cite>initializer</cite>.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – Default <code class="docutils literal"><span class="pre">False</span></code>.</li> |
| <li><strong>allow_extra</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Whether allow extra parameters that are not needed by symbol. |
| If this is True, no error will be thrown when arg_params or aux_params |
| contain extra parameters that is not needed by the executor.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.bind"> |
| <code class="descname">bind</code><span class="sig-paren">(</span><em>data_shapes</em>, <em>label_shapes=None</em>, <em>for_training=True</em>, <em>inputs_need_grad=False</em>, <em>force_rebind=False</em>, <em>shared_module=None</em>, <em>grad_req='write'</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.bind"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.bind" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Binds the symbols to construct executors. This is necessary before one |
| can perform computation with the module.</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>data_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically is <cite>data_iter.provide_data</cite>.</li> |
| <li><strong>label_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically is <cite>data_iter.provide_label</cite>.</li> |
| <li><strong>for_training</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>. Whether the executors should be bind for training.</li> |
| <li><strong>inputs_need_grad</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>. Whether the gradients to the input data need to be computed. |
| Typically this is not needed. But this might be needed when implementing composition |
| of modules.</li> |
| <li><strong>force_rebind</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>. This function does nothing if the executors are already |
| bound. But with this <code class="docutils literal"><span class="pre">True</span></code>, the executors will be forced to rebind.</li> |
| <li><strong>shared_module</strong> (<a class="reference internal" href="#mxnet.module.Module" title="mxnet.module.Module"><em>Module</em></a>) – Default is <code class="docutils literal"><span class="pre">None</span></code>. Currently shared module is not supported for <cite>SequentialModule</cite>.</li> |
| <li><strong>grad_req</strong> (<em>str</em><em>, </em><em>list of str</em><em>, </em><em>dict of str to str</em>) – Requirement for gradient accumulation. Can be ‘write’, ‘add’, or ‘null’ |
| (default to ‘write’). |
| Can be specified globally (str) or for each argument (list, dict).</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.init_optimizer"> |
| <code class="descname">init_optimizer</code><span class="sig-paren">(</span><em>kvstore='local'</em>, <em>optimizer='sgd'</em>, <em>optimizer_params=(('learning_rate'</em>, <em>0.01)</em>, <em>)</em>, <em>force_init=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.init_optimizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.init_optimizer" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Installs and initializes optimizers.</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>kvstore</strong> (<em>str</em><em> or </em><a class="reference internal" href="../kvstore/kvstore.html#mxnet.kvstore.KVStore" title="mxnet.kvstore.KVStore"><em>KVStore</em></a>) – Default <cite>‘local’</cite>.</li> |
| <li><strong>optimizer</strong> (<em>str</em><em> or </em><a class="reference internal" href="../optimization/optimization.html#mxnet.optimizer.Optimizer" title="mxnet.optimizer.Optimizer"><em>Optimizer</em></a>) – Default <cite>‘sgd’</cite></li> |
| <li><strong>optimizer_params</strong> (<em>dict</em>) – Default <code class="docutils literal"><span class="pre">(('learning_rate',</span> <span class="pre">0.01),)</span></code>. The default value is not a dictionary, |
| just to avoid pylint warning of dangerous default values.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – Default <code class="docutils literal"><span class="pre">False</span></code>, indicating whether we should force re-initializing the |
| optimizer in the case an optimizer is already installed.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.forward"> |
| <code class="descname">forward</code><span class="sig-paren">(</span><em>data_batch</em>, <em>is_train=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.forward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Forward computation.</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>data_batch</strong> (<em>DataBatch</em>) – </li> |
| <li><strong>is_train</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">None</span></code>, in which case <cite>is_train</cite> is take as <code class="docutils literal"><span class="pre">self.for_training</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.backward"> |
| <code class="descname">backward</code><span class="sig-paren">(</span><em>out_grads=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.backward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.backward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Backward computation.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.update"> |
| <code class="descname">update</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.update"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.update" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Updates parameters according to installed optimizer and the gradient computed |
| in the previous forward-backward cycle.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.get_outputs"> |
| <code class="descname">get_outputs</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.get_outputs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.get_outputs" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets outputs from a previous forward computation.</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>merge_multi_context</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the outputs |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicate that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">If <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[out1,</span> |
| <span class="pre">out2]</span></code>. Otherwise, it is like <code class="docutils literal"><span class="pre">[[out1_dev1,</span> <span class="pre">out1_dev2],</span> <span class="pre">[out2_dev1,</span> |
| <span class="pre">out2_dev2]]</span></code>. All the output elements are numpy arrays.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of NDArray or list of list of NDArray</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.get_input_grads"> |
| <code class="descname">get_input_grads</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.get_input_grads"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.get_input_grads" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets the gradients with respect to the inputs of the module.</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>merge_multi_context</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>. In the case when data-parallelism is used, the outputs |
| will be collected from multiple devices. A <code class="docutils literal"><span class="pre">True</span></code> value indicate that we |
| should merge the collected results so that they look like from a single |
| executor.</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">If <cite>merge_multi_context</cite> is <code class="docutils literal"><span class="pre">True</span></code>, it is like <code class="docutils literal"><span class="pre">[grad1,</span> <span class="pre">grad2]</span></code>. Otherwise, it |
| is like <code class="docutils literal"><span class="pre">[[grad1_dev1,</span> <span class="pre">grad1_dev2],</span> <span class="pre">[grad2_dev1,</span> <span class="pre">grad2_dev2]]</span></code>. All the output |
| elements are <cite>NDArray</cite>.</td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list of NDArrays or list of list of NDArrays</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.update_metric"> |
| <code class="descname">update_metric</code><span class="sig-paren">(</span><em>eval_metric</em>, <em>labels</em>, <em>pre_sliced=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.update_metric"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.update_metric" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Evaluates and accumulates evaluation metric on outputs of the last forward computation.</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>eval_metric</strong> (<a class="reference internal" href="../metric/metric.html#mxnet.metric.EvalMetric" title="mxnet.metric.EvalMetric"><em>EvalMetric</em></a>) – </li> |
| <li><strong>labels</strong> (<em>list of NDArray</em>) – Typically <code class="docutils literal"><span class="pre">data_batch.label</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.SequentialModule.install_monitor"> |
| <code class="descname">install_monitor</code><span class="sig-paren">(</span><em>mon</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/sequential_module.html#SequentialModule.install_monitor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.SequentialModule.install_monitor" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Installs monitor on all executors.</p> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.module.PythonModule"> |
| <em class="property">class </em><code class="descclassname">mxnet.module.</code><code class="descname">PythonModule</code><span class="sig-paren">(</span><em>data_names</em>, <em>label_names</em>, <em>output_names</em>, <em>logger=<module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'></em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonModule"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonModule" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A convenient module class that implements many of the module APIs as |
| empty functions.</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>data_names</strong> (<em>list of str</em>) – Names of the data expected by the module.</li> |
| <li><strong>label_names</strong> (<em>list of str</em>) – Names of the labels expected by the module. Could be <code class="docutils literal"><span class="pre">None</span></code> if the |
| module does not need labels.</li> |
| <li><strong>output_names</strong> (<em>list of str</em>) – Names of the outputs.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <dl class="attribute"> |
| <dt id="mxnet.module.PythonModule.data_names"> |
| <code class="descname">data_names</code><a class="headerlink" href="#mxnet.module.PythonModule.data_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for data required by this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.PythonModule.output_names"> |
| <code class="descname">output_names</code><a class="headerlink" href="#mxnet.module.PythonModule.output_names" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of names for the outputs of this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.PythonModule.data_shapes"> |
| <code class="descname">data_shapes</code><a class="headerlink" href="#mxnet.module.PythonModule.data_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of (name, shape) pairs specifying the data inputs to this module.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.PythonModule.label_shapes"> |
| <code class="descname">label_shapes</code><a class="headerlink" href="#mxnet.module.PythonModule.label_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of (name, shape) pairs specifying the label inputs to this module. |
| If this module does not accept labels – either it is a module without loss |
| function, or it is not bound for training, then this should return an empty |
| list <code class="docutils literal"><span class="pre">[]`</span></code>.</p> |
| </dd></dl> |
| <dl class="attribute"> |
| <dt id="mxnet.module.PythonModule.output_shapes"> |
| <code class="descname">output_shapes</code><a class="headerlink" href="#mxnet.module.PythonModule.output_shapes" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A list of (name, shape) pairs specifying the outputs of this module.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonModule.get_params"> |
| <code class="descname">get_params</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonModule.get_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonModule.get_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets parameters, those are potentially copies of the the actual parameters used |
| to do computation on the device. Subclass should override this method if contains |
| 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">Returns:</th><td class="field-body"></td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><code class="docutils literal"><span class="pre">({},</span> <span class="pre">{})</span></code>, a pair of empty dict.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonModule.init_params"> |
| <code class="descname">init_params</code><span class="sig-paren">(</span><em>initializer=<mxnet.initializer.Uniform object></em>, <em>arg_params=None</em>, <em>aux_params=None</em>, <em>allow_missing=False</em>, <em>force_init=False</em>, <em>allow_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonModule.init_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonModule.init_params" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Initializes the parameters and auxiliary states. By default this function |
| does nothing. Subclass should override this method if contains 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>initializer</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – Called to initialize parameters if needed.</li> |
| <li><strong>arg_params</strong> (<em>dict</em>) – If not <code class="docutils literal"><span class="pre">None</span></code>, should be a dictionary of existing <cite>arg_params</cite>. Initialization |
| will be copied from that.</li> |
| <li><strong>aux_params</strong> (<em>dict</em>) – If not <code class="docutils literal"><span class="pre">None</span></code>, should be a dictionary of existing <cite>aux_params</cite>. Initialization |
| will be copied from that.</li> |
| <li><strong>allow_missing</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, params could contain missing values, and the initializer will be |
| called to fill those missing params.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – If <code class="docutils literal"><span class="pre">True</span></code>, will force re-initialize even if already initialized.</li> |
| <li><strong>allow_extra</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Whether allow extra parameters that are not needed by symbol. |
| If this is True, no error will be thrown when arg_params or aux_params |
| contain extra parameters that is not needed by the executor.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonModule.update"> |
| <code class="descname">update</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonModule.update"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonModule.update" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Updates parameters according to the installed optimizer and the gradients computed |
| in the previous forward-backward batch. Currently we do nothing here. Subclass should |
| override this method if contains parameters.</p> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonModule.update_metric"> |
| <code class="descname">update_metric</code><span class="sig-paren">(</span><em>eval_metric</em>, <em>labels</em>, <em>pre_sliced=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonModule.update_metric"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonModule.update_metric" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Evaluates and accumulates evaluation metric on outputs of the last forward computation. |
| Subclass should override this method if needed.</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>eval_metric</strong> (<a class="reference internal" href="../metric/metric.html#mxnet.metric.EvalMetric" title="mxnet.metric.EvalMetric"><em>EvalMetric</em></a>) – </li> |
| <li><strong>labels</strong> (<em>list of NDArray</em>) – Typically <code class="docutils literal"><span class="pre">data_batch.label</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonModule.bind"> |
| <code class="descname">bind</code><span class="sig-paren">(</span><em>data_shapes</em>, <em>label_shapes=None</em>, <em>for_training=True</em>, <em>inputs_need_grad=False</em>, <em>force_rebind=False</em>, <em>shared_module=None</em>, <em>grad_req='write'</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonModule.bind"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonModule.bind" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Binds the symbols to construct executors. This is necessary before one |
| can perform computation with the module.</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>data_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically is <code class="docutils literal"><span class="pre">data_iter.provide_data</span></code>.</li> |
| <li><strong>label_shapes</strong> (<em>list of</em><em> (</em><em>str</em><em>, </em><em>tuple</em><em>)</em>) – Typically is <code class="docutils literal"><span class="pre">data_iter.provide_label</span></code>.</li> |
| <li><strong>for_training</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">True</span></code>. Whether the executors should be bind for training.</li> |
| <li><strong>inputs_need_grad</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>. Whether the gradients to the input data need to be computed. |
| Typically this is not needed. But this might be needed when implementing composition |
| of modules.</li> |
| <li><strong>force_rebind</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">False</span></code>. This function does nothing if the executors are already |
| bound. But with this <code class="docutils literal"><span class="pre">True</span></code>, the executors will be forced to rebind.</li> |
| <li><strong>shared_module</strong> (<a class="reference internal" href="#mxnet.module.Module" title="mxnet.module.Module"><em>Module</em></a>) – Default is <code class="docutils literal"><span class="pre">None</span></code>. This is used in bucketing. When not <code class="docutils literal"><span class="pre">None</span></code>, the shared module |
| essentially corresponds to a different bucket – a module with different symbol |
| but with the same sets of parameters (e.g. unrolled RNNs with different lengths).</li> |
| <li><strong>grad_req</strong> (<em>str</em><em>, </em><em>list of str</em><em>, </em><em>dict of str to str</em>) – Requirement for gradient accumulation. Can be ‘write’, ‘add’, or ‘null’ |
| (default to ‘write’). |
| Can be specified globally (str) or for each argument (list, dict).</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonModule.init_optimizer"> |
| <code class="descname">init_optimizer</code><span class="sig-paren">(</span><em>kvstore='local'</em>, <em>optimizer='sgd'</em>, <em>optimizer_params=(('learning_rate'</em>, <em>0.01)</em>, <em>)</em>, <em>force_init=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonModule.init_optimizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonModule.init_optimizer" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Installs and initializes optimizers. By default we do nothing. Subclass should |
| override this method if needed.</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>kvstore</strong> (<em>str</em><em> or </em><a class="reference internal" href="../kvstore/kvstore.html#mxnet.kvstore.KVStore" title="mxnet.kvstore.KVStore"><em>KVStore</em></a>) – Default <cite>‘local’</cite>.</li> |
| <li><strong>optimizer</strong> (<em>str</em><em> or </em><a class="reference internal" href="../optimization/optimization.html#mxnet.optimizer.Optimizer" title="mxnet.optimizer.Optimizer"><em>Optimizer</em></a>) – Default <cite>‘sgd’</cite></li> |
| <li><strong>optimizer_params</strong> (<em>dict</em>) – Default <cite>((‘learning_rate’, 0.01),)</cite>. The default value is not a dictionary, |
| just to avoid pylint warning of dangerous default values.</li> |
| <li><strong>force_init</strong> (<em>bool</em>) – Default <cite>False</cite>, indicating whether we should force re-initializing the |
| optimizer in the case an optimizer is already installed.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| </dd></dl> |
| <dl class="class"> |
| <dt id="mxnet.module.PythonLossModule"> |
| <em class="property">class </em><code class="descclassname">mxnet.module.</code><code class="descname">PythonLossModule</code><span class="sig-paren">(</span><em>name='pyloss'</em>, <em>data_names=('data'</em>, <em>)</em>, <em>label_names=('softmax_label'</em>, <em>)</em>, <em>logger=<module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'></em>, <em>grad_func=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonLossModule"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonLossModule" title="Permalink to this definition">¶</a></dt> |
| <dd><p>A convenient module class that implements many of the module APIs as |
| empty functions.</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>name</strong> (<em>str</em>) – Names of the module. The outputs will be named <cite>[name + ‘_output’]</cite>.</li> |
| <li><strong>data_names</strong> (<em>list of str</em>) – Defaults to <code class="docutils literal"><span class="pre">['data']</span></code>. Names of the data expected by this module. |
| Should be a list of only one name.</li> |
| <li><strong>label_names</strong> (<em>list of str</em>) – Default <code class="docutils literal"><span class="pre">['softmax_label']</span></code>. Names of the labels expected by the module. |
| Should be a list of only one name.</li> |
| <li><strong>grad_func</strong> (<em>function</em>) – Optional. If not <code class="docutils literal"><span class="pre">None</span></code>, should be a function that takes <cite>scores</cite> |
| and <cite>labels</cite>, both of type <cite>NDArray</cite>, and return the gradients with |
| respect to the scores according to this loss function. The return |
| value could be a numpy array or an <cite>NDArray</cite>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonLossModule.forward"> |
| <code class="descname">forward</code><span class="sig-paren">(</span><em>data_batch</em>, <em>is_train=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonLossModule.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonLossModule.forward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Forward computation. Here we do nothing but to keep a reference to |
| the scores and the labels so that we can do backward computation.</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>data_batch</strong> (<em>DataBatch</em>) – Could be anything with similar API implemented.</li> |
| <li><strong>is_train</strong> (<em>bool</em>) – Default is <code class="docutils literal"><span class="pre">None</span></code>, which means <cite>is_train</cite> takes the value of <code class="docutils literal"><span class="pre">self.for_training</span></code>.</li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonLossModule.get_outputs"> |
| <code class="descname">get_outputs</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonLossModule.get_outputs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonLossModule.get_outputs" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets outputs of the previous forward computation. As a output loss module, |
| we treat the inputs to this module as scores, and simply return them.</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>merge_multi_context</strong> (<em>bool</em>) – Should always be <code class="docutils literal"><span class="pre">True</span></code>, because we do not use multiple contexts for computing.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonLossModule.backward"> |
| <code class="descname">backward</code><span class="sig-paren">(</span><em>out_grads=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonLossModule.backward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonLossModule.backward" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Backward computation.</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>out_grads</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a><em> or </em><em>list of NDArray</em><em>, </em><em>optional</em>) – Gradient on the outputs to be propagated back. |
| This parameter is only needed when bind is called |
| on outputs that are not a loss function.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonLossModule.get_input_grads"> |
| <code class="descname">get_input_grads</code><span class="sig-paren">(</span><em>merge_multi_context=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonLossModule.get_input_grads"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonLossModule.get_input_grads" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Gets the gradients to the inputs, computed in the previous backward computation.</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>merge_multi_context</strong> (<em>bool</em>) – Should always be <code class="docutils literal"><span class="pre">True</span></code> because we do not use multiple context for computation.</td> |
| </tr> |
| </tbody> |
| </table> |
| </dd></dl> |
| <dl class="method"> |
| <dt id="mxnet.module.PythonLossModule.install_monitor"> |
| <code class="descname">install_monitor</code><span class="sig-paren">(</span><em>mon</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/module/python_module.html#PythonLossModule.install_monitor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.module.PythonLossModule.install_monitor" title="Permalink to this definition">¶</a></dt> |
| <dd><p>Installs monitor on all executors.</p> |
| </dd></dl> |
| </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="#">Module API</a><ul> |
| <li><a class="reference internal" href="#overview">Overview</a></li> |
| <li><a class="reference internal" href="#the-basemodule-class">The <code class="docutils literal"><span class="pre">BaseModule</span></code> class</a><ul> |
| <li><a class="reference internal" href="#initialize-memory">Initialize memory</a></li> |
| <li><a class="reference internal" href="#get-and-set-parameters">Get and set parameters</a></li> |
| <li><a class="reference internal" href="#train-and-predict">Train and predict</a></li> |
| <li><a class="reference internal" href="#forward-and-backward">Forward and backward</a></li> |
| <li><a class="reference internal" href="#update-parameters">Update parameters</a></li> |
| <li><a class="reference internal" href="#input-and-output">Input and output</a></li> |
| <li><a class="reference internal" href="#others">Others</a></li> |
| </ul> |
| </li> |
| <li><a class="reference internal" href="#other-build-in-modules">Other build-in modules</a><ul> |
| <li><a class="reference internal" href="#class-module">Class <code class="docutils literal"><span class="pre">Module</span></code></a></li> |
| <li><a class="reference internal" href="#class-bucketmodule">Class <code class="docutils literal"><span class="pre">BucketModule</span></code></a></li> |
| <li><a class="reference internal" href="#class-sequentialmodule">Class <code class="docutils literal"><span class="pre">SequentialModule</span></code></a></li> |
| </ul> |
| </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 src="../../../_static/js/docversion.js" type="text/javascript"></script> |
| <script type="text/javascript"> |
| $('body').ready(function () { |
| $('body').css('visibility', 'visible'); |
| }); |
| </script> |
| </body> |
| </html> |