versions/1.5.0/api/python/gluon/gluon.html (1,775 lines of code) (raw):
<!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="Gluon Package" 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="Gluon Package" property="og:description"/>
<title>Gluon Package — mxnet documentation</title>
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="../../../_static/basic.css" rel="stylesheet" type="text/css">
<link href="../../../_static/pygments.css" rel="stylesheet" type="text/css">
<link href="../../../_static/mxnet.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../../',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.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.5.0/searchindex.js"); Search.init();}); </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="nn.html" rel="next" title="Gluon Neural Network Layers"/>
<link href="../contrib/svrg_optimization.html" rel="prev" title="SVRG Optimization in Python Module 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.5.0/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.5.0/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.5.0/api/python/index.html">Python</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/c++/index.html">C++</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/clojure/index.html">Clojure</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/java/index.html">Java</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/julia/index.html">Julia</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/perl/index.html">Perl</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/r/index.html">R</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/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.5.0/faq/index.html">FAQ</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/tutorials/index.html">Tutorials</a>
<li><a class="main-nav-link" href="https://github.com/apache/incubator-mxnet/tree/1.5.0/example">Examples</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/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.5.0/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.5.0">Github</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/community/contribute.html">Contribute</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/community/ecosystem.html">Ecosystem</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/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.5.0<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.5.0/install/index.html">Install</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/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.5.0/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.5.0/api/python/index.html">Python</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/c++/index.html">C++</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/clojure/index.html">Clojure</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/java/index.html">Java</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/julia/index.html">Julia</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/perl/index.html">Perl</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/api/r/index.html">R</a></li>
<li><a class="main-nav-link" href="/versions/1.5.0/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.5.0/faq/index.html" tabindex="-1">FAQ</a></li>
<li><a href="/versions/1.5.0/tutorials/index.html" tabindex="-1">Tutorials</a></li>
<li><a href="https://github.com/apache/incubator-mxnet/tree/1.5.0/example" tabindex="-1">Examples</a></li>
<li><a href="/versions/1.5.0/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.5.0/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.5.0" tabindex="-1">Github</a></li>
<li><a href="/versions/1.5.0/community/contribute.html" tabindex="-1">Contribute</a></li>
<li><a href="/versions/1.5.0/community/ecosystem.html" tabindex="-1">Ecosystem</a></li>
<li><a href="/versions/1.5.0/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.5.0</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>
<li class="toctree-l1"><a class="reference internal" href="../../index.html">MXNet APIs</a></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="gluon-package">
<span id="gluon-package"></span><h1>Gluon Package<a class="headerlink" href="#gluon-package" title="Permalink to this headline">¶</a></h1>
<script src="../../../_static/js/auto_module_index.js" type="text/javascript"></script><div class="section" id="overview">
<span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>The Gluon package is a high-level interface for MXNet designed to be easy to use, while keeping most of the flexibility of a low level API. Gluon supports both imperative and symbolic programming, making it easy to train complex models imperatively in Python and then deploy with a symbolic graph in C++ and Scala.</p>
<p>Based on the the <a class="reference external" href="https://github.com/gluon-api/gluon-api">Gluon API specification</a>, the Gluon API in Apache MXNet provides a clear, concise, and simple API for deep learning. It makes it easy to prototype, build, and train deep learning models without sacrificing training speed.</p>
<p><strong>Advantages</strong></p>
<ol class="simple">
<li>Simple, Easy-to-Understand Code: Gluon offers a full set of plug-and-play neural network building blocks, including predefined layers, optimizers, and initializers.</li>
<li>Flexible, Imperative Structure: Gluon does not require the neural network model to be rigidly defined, but rather brings the training algorithm and model closer together to provide flexibility in the development process.</li>
<li>Dynamic Graphs: Gluon enables developers to define neural network models that are dynamic, meaning they can be built on the fly, with any structure, and using any of Python’s native control flow.</li>
<li>High Performance: Gluon provides all of the above benefits without impacting the training speed that the underlying engine provides.</li>
</ol>
<p><strong>Examples</strong></p>
<p><em>Simple, Easy-to-Understand Code</em></p>
<p>Use plug-and-play neural network building blocks, including predefined layers, optimizers, and initializers:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">net</span> <span class="o">=</span> <span class="n">gluon</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">Sequential</span><span class="p">()</span>
<span class="c1"># When instantiated, Sequential stores a chain of neural network layers. </span>
<span class="c1"># Once presented with data, Sequential executes each layer in turn, using </span>
<span class="c1"># the output of one layer as the input for the next</span>
<span class="k">with</span> <span class="n">net</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">gluon</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">256</span><span class="p">,</span> <span class="n">activation</span><span class="o">=</span><span class="s2">"relu"</span><span class="p">))</span> <span class="c1"># 1st layer (256 nodes)</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">gluon</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">256</span><span class="p">,</span> <span class="n">activation</span><span class="o">=</span><span class="s2">"relu"</span><span class="p">))</span> <span class="c1"># 2nd hidden layer</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">gluon</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="n">num_outputs</span><span class="p">))</span>
</pre></div>
</div>
<p><em>Flexible, Imperative Structure</em></p>
<p>Prototype, build, and train neural networks in fully imperative manner using the MXNet autograd package and the Gluon trainer method:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">epochs</span> <span class="o">=</span> <span class="mi">10</span>
<span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">epochs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">train_data</span><span class="p">):</span>
<span class="k">with</span> <span class="n">autograd</span><span class="o">.</span><span class="n">record</span><span class="p">():</span>
<span class="n">output</span> <span class="o">=</span> <span class="n">net</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="c1"># the forward iteration</span>
<span class="n">loss</span> <span class="o">=</span> <span class="n">softmax_cross_entropy</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>
<span class="n">loss</span><span class="o">.</span><span class="n">backward</span><span class="p">()</span>
<span class="n">trainer</span><span class="o">.</span><span class="n">step</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
</pre></div>
</div>
<p><em>Dynamic Graphs</em></p>
<p>Build neural networks on the fly for use cases where neural networks must change in size and shape during model training:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">F</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">tree</span><span class="p">):</span>
<span class="n">children_outputs</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">F</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">child</span><span class="p">)</span>
<span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">tree</span><span class="o">.</span><span class="n">children</span><span class="p">]</span>
<span class="c1">#Recursively builds the neural network based on each input sentence’s</span>
<span class="c1">#syntactic structure during the model definition and training process</span>
<span class="o">...</span>
</pre></div>
</div>
<p><em>High Performance</em></p>
<p>Easily cache the neural network to achieve high performance by defining your neural network with <em>HybridSequential</em> and calling the <em>hybridize</em> method:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">net</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">HybridSequential</span><span class="p">()</span>
<span class="k">with</span> <span class="n">net</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">256</span><span class="p">,</span> <span class="n">activation</span><span class="o">=</span><span class="s2">"relu"</span><span class="p">))</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">128</span><span class="p">,</span> <span class="n">activation</span><span class="o">=</span><span class="s2">"relu"</span><span class="p">))</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
<span class="n">net</span><span class="o">.</span><span class="n">hybridize</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="contents">
<span id="contents"></span><h2>Contents<a class="headerlink" href="#contents" title="Permalink to this headline">¶</a></h2>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="nn.html">Gluon Neural Network Layers</a></li>
<li class="toctree-l1"><a class="reference internal" href="rnn.html">Gluon Recurrent Neural Network API</a></li>
<li class="toctree-l1"><a class="reference internal" href="loss.html">Gluon Loss API</a></li>
<li class="toctree-l1"><a class="reference internal" href="data.html">Gluon Data API</a></li>
<li class="toctree-l1"><a class="reference internal" href="model_zoo.html">Gluon Model Zoo</a></li>
<li class="toctree-l1"><a class="reference internal" href="contrib.html">Gluon Contrib API</a></li>
</ul>
</div>
</div>
<div class="section" id="parameter">
<span id="parameter"></span><h2>Parameter<a class="headerlink" href="#parameter" title="Permalink to this headline">¶</a></h2>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-obj docutils literal"><span class="pre">Parameter</span></code></a></td>
<td>A Container holding parameters (weights) of Blocks.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.gluon.Constant" title="mxnet.gluon.Constant"><code class="xref py py-obj docutils literal"><span class="pre">Constant</span></code></a></td>
<td>A constant parameter for holding immutable tensors.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-obj docutils literal"><span class="pre">ParameterDict</span></code></a></td>
<td>A dictionary managing a set of parameters.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="containers">
<span id="containers"></span><h2>Containers<a class="headerlink" href="#containers" title="Permalink to this headline">¶</a></h2>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-obj docutils literal"><span class="pre">Block</span></code></a></td>
<td>Base class for all neural network layers and models.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-obj docutils literal"><span class="pre">HybridBlock</span></code></a></td>
<td><cite>HybridBlock</cite> supports forwarding with both Symbol and NDArray.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.SymbolBlock" title="mxnet.gluon.SymbolBlock"><code class="xref py py-obj docutils literal"><span class="pre">SymbolBlock</span></code></a></td>
<td>Construct block from symbol.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.gluon.nn.Sequential" title="mxnet.gluon.nn.Sequential"><code class="xref py py-obj docutils literal"><span class="pre">nn.Sequential</span></code></a></td>
<td>Stacks Blocks sequentially.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.nn.HybridSequential" title="mxnet.gluon.nn.HybridSequential"><code class="xref py py-obj docutils literal"><span class="pre">nn.HybridSequential</span></code></a></td>
<td>Stacks HybridBlocks sequentially.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="trainer">
<span id="trainer"></span><h2>Trainer<a class="headerlink" href="#trainer" title="Permalink to this headline">¶</a></h2>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.Trainer" title="mxnet.gluon.Trainer"><code class="xref py py-obj docutils literal"><span class="pre">Trainer</span></code></a></td>
<td>Applies an <cite>Optimizer</cite> on a set of Parameters.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="utilities">
<span id="utilities"></span><h2>Utilities<a class="headerlink" href="#utilities" title="Permalink to this headline">¶</a></h2>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.utils.split_data" title="mxnet.gluon.utils.split_data"><code class="xref py py-obj docutils literal"><span class="pre">split_data</span></code></a></td>
<td>Splits an NDArray into <cite>num_slice</cite> slices along <cite>batch_axis</cite>.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.gluon.utils.split_and_load" title="mxnet.gluon.utils.split_and_load"><code class="xref py py-obj docutils literal"><span class="pre">split_and_load</span></code></a></td>
<td>Splits an NDArray into <cite>len(ctx_list)</cite> slices along <cite>batch_axis</cite> and loads each slice to one context in <cite>ctx_list</cite>.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.gluon.utils.clip_global_norm" title="mxnet.gluon.utils.clip_global_norm"><code class="xref py py-obj docutils literal"><span class="pre">clip_global_norm</span></code></a></td>
<td>Rescales NDArrays so that the sum of their 2-norm is smaller than <cite>max_norm</cite>.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="api-reference">
<span id="api-reference"></span><h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h2>
<script src="../../../_static/js/auto_module_index.js" type="text/javascript"></script><span class="target" id="module-mxnet.gluon"></span><p>Neural network module.</p>
<dl class="class">
<dt id="mxnet.gluon.Block">
<em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">Block</code><span class="sig-paren">(</span><em>prefix=None</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for all neural network layers and models. Your models should
subclass this class.</p>
<p><a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> can be nested recursively in a tree structure. You can create and
assign child <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> as regular attributes:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mxnet.gluon</span> <span class="k">import</span> <span class="n">Block</span><span class="p">,</span> <span class="n">nn</span>
<span class="kn">from</span> <span class="nn">mxnet</span> <span class="k">import</span> <span class="n">ndarray</span> <span class="k">as</span> <span class="n">F</span>
<span class="k">class</span> <span class="nc">Model</span><span class="p">(</span><span class="n">Block</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">Model</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="c1"># use name_scope to give child Blocks appropriate names.</span>
<span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dense0</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dense1</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dense0</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dense1</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">Model</span><span class="p">()</span>
<span class="n">model</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
<span class="n">model</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">)))</span>
</pre></div>
</div>
<p>Child <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> assigned this way will be registered and <a class="reference internal" href="#mxnet.gluon.Block.collect_params" title="mxnet.gluon.Block.collect_params"><code class="xref py py-meth docutils literal"><span class="pre">collect_params()</span></code></a>
will collect their Parameters recursively. You can also manually register
child blocks with <a class="reference internal" href="#mxnet.gluon.Block.register_child" title="mxnet.gluon.Block.register_child"><code class="xref py py-meth docutils literal"><span class="pre">register_child()</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>prefix</strong> (<em>str</em>) – Prefix acts like a name space. All children blocks created in parent block’s
<a class="reference internal" href="#mxnet.gluon.Block.name_scope" title="mxnet.gluon.Block.name_scope"><code class="xref py py-meth docutils literal"><span class="pre">name_scope()</span></code></a> will have parent block’s prefix in their name.
Please refer to
<a class="reference external" href="/versions/1.5.0/tutorials/gluon/naming.html">naming tutorial</a>
for more info on prefix and naming.</li>
<li><strong>params</strong> (<a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><em>ParameterDict</em></a><em> or </em><em>None</em>) – <p><a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-class docutils literal"><span class="pre">ParameterDict</span></code></a> for sharing weights with the new <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>. For example,
if you want <code class="docutils literal"><span class="pre">dense1</span></code> to share <code class="docutils literal"><span class="pre">dense0</span></code>‘s weights, you can do:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">dense0</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="n">dense1</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">dense0</span><span class="o">.</span><span class="n">collect_params</span><span class="p">())</span>
</pre></div>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mxnet.gluon.Block.__call__">
<code class="descname">__call__</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.__call__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.__call__" title="Permalink to this definition">¶</a></dt>
<dd><p>Calls forward. Only accepts positional arguments.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.__setattr__">
<code class="descname">__setattr__</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.__setattr__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.__setattr__" title="Permalink to this definition">¶</a></dt>
<dd><p>Registers parameters.</p>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.Block.__weakref__">
<code class="descname">__weakref__</code><a class="headerlink" href="#mxnet.gluon.Block.__weakref__" title="Permalink to this definition">¶</a></dt>
<dd><p>list of weak references to the object (if defined)</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.apply">
<code class="descname">apply</code><span class="sig-paren">(</span><em>fn</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.apply"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.apply" title="Permalink to this definition">¶</a></dt>
<dd><p>Applies <code class="docutils literal"><span class="pre">fn</span></code> recursively to every child block as well as self.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fn</strong> (<em>callable</em>) – Function to be applied to each submodule, of form <cite>fn(block)</cite>.</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">this block</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.cast">
<code class="descname">cast</code><span class="sig-paren">(</span><em>dtype</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.cast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.cast" title="Permalink to this definition">¶</a></dt>
<dd><p>Cast this Block to use another data type.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>dtype</strong> (<em>str</em><em> or </em><em>numpy.dtype</em>) – The new data type.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.collect_params">
<code class="descname">collect_params</code><span class="sig-paren">(</span><em>select=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.collect_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.collect_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a <a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-class docutils literal"><span class="pre">ParameterDict</span></code></a> containing this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> and all of its
children’s Parameters(default), also can returns the select <a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-class docutils literal"><span class="pre">ParameterDict</span></code></a>
which match some given regular expressions.</p>
<p>For example, collect the specified parameters in [‘conv1_weight’, ‘conv1_bias’, ‘fc_weight’,
‘fc_bias’]:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">model</span><span class="o">.</span><span class="n">collect_params</span><span class="p">(</span><span class="s1">'conv1_weight|conv1_bias|fc_weight|fc_bias'</span><span class="p">)</span>
</pre></div>
</div>
<p>or collect all parameters whose names end with ‘weight’ or ‘bias’, this can be done
using regular expressions:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">model</span><span class="o">.</span><span class="n">collect_params</span><span class="p">(</span><span class="s1">'.*weight|.*bias'</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>select</strong> (<em>str</em>) – regular expressions</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">The selected <a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><code class="xref py py-class docutils literal"><span class="pre">ParameterDict</span></code></a></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.forward">
<code class="descname">forward</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.forward" title="Permalink to this definition">¶</a></dt>
<dd><p>Overrides to implement forward computation using <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code>. Only
accepts positional arguments.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>*args</strong> (<em>list of NDArray</em>) – Input tensors.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.hybridize">
<code class="descname">hybridize</code><span class="sig-paren">(</span><em>active=True</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.hybridize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.hybridize" title="Permalink to this definition">¶</a></dt>
<dd><p>Activates or deactivates <a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-class docutils literal"><span class="pre">HybridBlock</span></code></a> s recursively. Has no effect on
non-hybrid children.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>active</strong> (<em>bool</em><em>, </em><em>default True</em>) – Whether to turn hybrid on or off.</li>
<li><strong>static_alloc</strong> (<em>bool</em><em>, </em><em>default False</em>) – Statically allocate memory to improve speed. Memory usage may increase.</li>
<li><strong>static_shape</strong> (<em>bool</em><em>, </em><em>default False</em>) – Optimize for invariant input shapes between iterations. Must also
set static_alloc to True. Change of input shapes is still allowed
but slower.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.initialize">
<code class="descname">initialize</code><span class="sig-paren">(</span><em>init=<mxnet.initializer.Uniform object></em>, <em>ctx=None</em>, <em>verbose=False</em>, <em>force_reinit=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.initialize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.initialize" title="Permalink to this definition">¶</a></dt>
<dd><p>Initializes <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a> s of this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> and its children.
Equivalent to <code class="docutils literal"><span class="pre">block.collect_params().initialize(...)</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>init</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – Global default Initializer to be used when <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> is <code class="docutils literal"><span class="pre">None</span></code>.
Otherwise, <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> takes precedence.</li>
<li><strong>ctx</strong> (<em>Context</em><em> or </em><em>list of Context</em>) – Keeps a copy of Parameters on one or many context(s).</li>
<li><strong>verbose</strong> (<em>bool</em><em>, </em><em>default False</em>) – Whether to verbosely print out details on initialization.</li>
<li><strong>force_reinit</strong> (<em>bool</em><em>, </em><em>default False</em>) – Whether to force re-initialization if parameter is already initialized.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.load_parameters">
<code class="descname">load_parameters</code><span class="sig-paren">(</span><em>filename</em>, <em>ctx=None</em>, <em>allow_missing=False</em>, <em>ignore_extra=False</em>, <em>cast_dtype=False</em>, <em>dtype_source='current'</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.load_parameters"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.load_parameters" title="Permalink to this definition">¶</a></dt>
<dd><p>Load parameters from file previously saved by <cite>save_parameters</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>filename</strong> (<em>str</em>) – Path to parameter file.</li>
<li><strong>ctx</strong> (<em>Context</em><em> or </em><em>list of Context</em><em>, </em><em>default cpu</em><em>(</em><em>)</em>) – Context(s) to initialize loaded parameters on.</li>
<li><strong>allow_missing</strong> (<em>bool</em><em>, </em><em>default False</em>) – Whether to silently skip loading parameters not represents in the file.</li>
<li><strong>ignore_extra</strong> (<em>bool</em><em>, </em><em>default False</em>) – Whether to silently ignore parameters from the file that are not
present in this Block.</li>
<li><strong>cast_dtype</strong> (<em>bool</em><em>, </em><em>default False</em>) – Cast the data type of the NDArray loaded from the checkpoint to the dtype
provided by the Parameter if any.</li>
<li><strong>dtype_source</strong> (<em>str</em><em>, </em><em>default 'current'</em>) – must be in {‘current’, ‘saved’}
Only valid if cast_dtype=True, specify the source of the dtype for casting
the parameters</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">References</p>
<p><a class="reference external" href="/versions/1.5.0/tutorials/gluon/save_load_params.html">Saving and Loading Gluon Models</a></p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.load_params">
<code class="descname">load_params</code><span class="sig-paren">(</span><em>filename</em>, <em>ctx=None</em>, <em>allow_missing=False</em>, <em>ignore_extra=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.load_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.load_params" title="Permalink to this definition">¶</a></dt>
<dd><p>[Deprecated] Please use load_parameters.</p>
<p>Load parameters from file.</p>
<dl class="docutils">
<dt>filename <span class="classifier-delimiter">:</span> <span class="classifier">str</span></dt>
<dd>Path to parameter file.</dd>
<dt>ctx <span class="classifier-delimiter">:</span> <span class="classifier">Context or list of Context, default cpu()</span></dt>
<dd>Context(s) to initialize loaded parameters on.</dd>
<dt>allow_missing <span class="classifier-delimiter">:</span> <span class="classifier">bool, default False</span></dt>
<dd>Whether to silently skip loading parameters not represents in the file.</dd>
<dt>ignore_extra <span class="classifier-delimiter">:</span> <span class="classifier">bool, default False</span></dt>
<dd>Whether to silently ignore parameters from the file that are not
present in this Block.</dd>
</dl>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.Block.name">
<code class="descname">name</code><a class="headerlink" href="#mxnet.gluon.Block.name" title="Permalink to this definition">¶</a></dt>
<dd><p>Name of this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>, without ‘_’ in the end.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.name_scope">
<code class="descname">name_scope</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.name_scope"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.name_scope" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a name space object managing a child <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> and parameter
names. Should be used within a <code class="docutils literal"><span class="pre">with</span></code> statement:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dense</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
</pre></div>
</div>
<p>Please refer to
<a class="reference external" href="/versions/1.5.0/tutorials/gluon/naming.html">naming tutorial</a>
for more info on prefix and naming.</p>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.Block.params">
<code class="descname">params</code><a class="headerlink" href="#mxnet.gluon.Block.params" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>‘s parameter dictionary (does not include its
children’s parameters).</p>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.Block.prefix">
<code class="descname">prefix</code><a class="headerlink" href="#mxnet.gluon.Block.prefix" title="Permalink to this definition">¶</a></dt>
<dd><p>Prefix of this <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.register_child">
<code class="descname">register_child</code><span class="sig-paren">(</span><em>block</em>, <em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.register_child"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.register_child" title="Permalink to this definition">¶</a></dt>
<dd><p>Registers block as a child of self. <a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a> s assigned to self as
attributes will be registered automatically.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.register_forward_hook">
<code class="descname">register_forward_hook</code><span class="sig-paren">(</span><em>hook</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.register_forward_hook"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.register_forward_hook" title="Permalink to this definition">¶</a></dt>
<dd><p>Registers a forward hook on the block.</p>
<p>The hook function is called immediately after <a class="reference internal" href="#mxnet.gluon.Block.forward" title="mxnet.gluon.Block.forward"><code class="xref py py-func docutils literal"><span class="pre">forward()</span></code></a>.
It should not modify the input or output.</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>hook</strong> (<em>callable</em>) – The forward hook function of form <cite>hook(block, input, output) -> None</cite>.</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"><code class="xref py py-class docutils literal"><span class="pre">mxnet.gluon.utils.HookHandle</span></code></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.register_forward_pre_hook">
<code class="descname">register_forward_pre_hook</code><span class="sig-paren">(</span><em>hook</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.register_forward_pre_hook"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.register_forward_pre_hook" title="Permalink to this definition">¶</a></dt>
<dd><p>Registers a forward pre-hook on the block.</p>
<p>The hook function is called immediately before <a class="reference internal" href="#mxnet.gluon.Block.forward" title="mxnet.gluon.Block.forward"><code class="xref py py-func docutils literal"><span class="pre">forward()</span></code></a>.
It should not modify the input or output.</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>hook</strong> (<em>callable</em>) – The forward hook function of form <cite>hook(block, input) -> None</cite>.</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"><code class="xref py py-class docutils literal"><span class="pre">mxnet.gluon.utils.HookHandle</span></code></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.save_parameters">
<code class="descname">save_parameters</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.save_parameters"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.save_parameters" title="Permalink to this definition">¶</a></dt>
<dd><p>Save parameters to file.</p>
<p>Saved parameters can only be loaded with <cite>load_parameters</cite>. Note that this
method only saves parameters, not model structure. If you want to save
model structures, please use <a class="reference internal" href="#mxnet.gluon.HybridBlock.export" title="mxnet.gluon.HybridBlock.export"><code class="xref py py-meth docutils literal"><span class="pre">HybridBlock.export()</span></code></a>.</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>filename</strong> (<em>str</em>) – Path to file.</td>
</tr>
</tbody>
</table>
<p class="rubric">References</p>
<p><a class="reference external" href="/versions/1.5.0/tutorials/gluon/save_load_params.html">Saving and Loading Gluon Models</a></p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.save_params">
<code class="descname">save_params</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.save_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.save_params" title="Permalink to this definition">¶</a></dt>
<dd><p>[Deprecated] Please use save_parameters. Note that if you want load
from SymbolBlock later, please use export instead.</p>
<p>Save parameters to file.</p>
<dl class="docutils">
<dt>filename <span class="classifier-delimiter">:</span> <span class="classifier">str</span></dt>
<dd>Path to file.</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Block.summary">
<code class="descname">summary</code><span class="sig-paren">(</span><em>*inputs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#Block.summary"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Block.summary" title="Permalink to this definition">¶</a></dt>
<dd><p>Print the summary of the model’s output and parameters.</p>
<p>The network must have been initialized, and must not have been hybridized.</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>inputs</strong> (<em>object</em>) – Any input that the model supports. For any tensor in the input, only
<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><code class="xref py py-class docutils literal"><span class="pre">mxnet.ndarray.NDArray</span></code></a> is supported.</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.gluon.Constant">
<em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">Constant</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Constant"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Constant" title="Permalink to this definition">¶</a></dt>
<dd><p>A constant parameter for holding immutable tensors.
<cite>Constant`s are ignored by `autograd</cite> and <cite>Trainer</cite>, thus their values
will not change during training. But you can still update their values
manually with the <cite>set_data</cite> method.</p>
<p><cite>Constant</cite> s can be created with either:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">const</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">gluon</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span><span class="s1">'const'</span><span class="p">,</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">],[</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">]])</span>
</pre></div>
</div>
<p>or:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Block</span><span class="p">(</span><span class="n">gluon</span><span class="o">.</span><span class="n">Block</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">Block</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">const</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get_constant</span><span class="p">(</span><span class="s1">'const'</span><span class="p">,</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">],[</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">]])</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) – Name of the parameter.</li>
<li><strong>value</strong> (<em>array-like</em>) – Initial value for the constant.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="exception">
<dt id="mxnet.gluon.DeferredInitializationError">
<em class="property">exception </em><code class="descclassname">mxnet.gluon.</code><code class="descname">DeferredInitializationError</code><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#DeferredInitializationError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.DeferredInitializationError" title="Permalink to this definition">¶</a></dt>
<dd><p>Error for unfinished deferred initialization.</p>
</dd></dl>
<dl class="class">
<dt id="mxnet.gluon.HybridBlock">
<em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">HybridBlock</code><span class="sig-paren">(</span><em>prefix=None</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock" title="Permalink to this definition">¶</a></dt>
<dd><p><cite>HybridBlock</cite> supports forwarding with both Symbol and NDArray.</p>
<p><cite>HybridBlock</cite> is similar to <cite>Block</cite>, with a few differences:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">mxnet</span> <span class="k">as</span> <span class="nn">mx</span>
<span class="kn">from</span> <span class="nn">mxnet.gluon</span> <span class="k">import</span> <span class="n">HybridBlock</span><span class="p">,</span> <span class="n">nn</span>
<span class="k">class</span> <span class="nc">Model</span><span class="p">(</span><span class="n">HybridBlock</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">Model</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="c1"># use name_scope to give child Blocks appropriate names.</span>
<span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dense0</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dense1</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">hybrid_forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">F</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dense0</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dense1</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">Model</span><span class="p">()</span>
<span class="n">model</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
<span class="n">model</span><span class="o">.</span><span class="n">hybridize</span><span class="p">()</span>
<span class="n">model</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">zeros</span><span class="p">((</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">)))</span>
</pre></div>
</div>
<p>Forward computation in <a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-class docutils literal"><span class="pre">HybridBlock</span></code></a> must be static to work with <code class="xref py py-class docutils literal"><span class="pre">Symbol</span></code> s,
i.e. you cannot call <code class="xref py py-meth docutils literal"><span class="pre">NDArray.asnumpy()</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">NDArray.shape</span></code>,
<code class="xref py py-attr docutils literal"><span class="pre">NDArray.dtype</span></code>, <cite>NDArray</cite> indexing (<cite>x[i]</cite>) etc on tensors.
Also, you cannot use branching or loop logic that bases on non-constant
expressions like random numbers or intermediate results, since they change
the graph structure for each iteration.</p>
<p>Before activating with <code class="xref py py-meth docutils literal"><span class="pre">hybridize()</span></code>, <a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-class docutils literal"><span class="pre">HybridBlock</span></code></a> works just like normal
<a class="reference internal" href="#mxnet.gluon.Block" title="mxnet.gluon.Block"><code class="xref py py-class docutils literal"><span class="pre">Block</span></code></a>. After activation, <a class="reference internal" href="#mxnet.gluon.HybridBlock" title="mxnet.gluon.HybridBlock"><code class="xref py py-class docutils literal"><span class="pre">HybridBlock</span></code></a> will create a symbolic graph
representing the forward computation and cache it. On subsequent forwards,
the cached graph will be used instead of <a class="reference internal" href="#mxnet.gluon.HybridBlock.hybrid_forward" title="mxnet.gluon.HybridBlock.hybrid_forward"><code class="xref py py-meth docutils literal"><span class="pre">hybrid_forward()</span></code></a>.</p>
<p>Please see references for detailed tutorial.</p>
<p class="rubric">References</p>
<p><a class="reference external" href="/versions/1.5.0/tutorials/gluon/hybrid.html">Hybrid - Faster training and easy deployment</a></p>
<dl class="method">
<dt id="mxnet.gluon.HybridBlock.__setattr__">
<code class="descname">__setattr__</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.__setattr__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.__setattr__" title="Permalink to this definition">¶</a></dt>
<dd><p>Registers parameters.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.HybridBlock.export">
<code class="descname">export</code><span class="sig-paren">(</span><em>path</em>, <em>epoch=0</em>, <em>remove_amp_cast=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.export"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.export" title="Permalink to this definition">¶</a></dt>
<dd><p>Export HybridBlock to json format that can be loaded by
<cite>SymbolBlock.imports</cite>, <cite>mxnet.mod.Module</cite> or the C++ interface.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">When there are only one input, it will have name <cite>data</cite>. When there
Are more than one inputs, they will be named as <cite>data0</cite>, <cite>data1</cite>, etc.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>path</strong> (<em>str</em>) – Path to save model. Two files <cite>path-symbol.json</cite> and <cite>path-xxxx.params</cite>
will be created, where xxxx is the 4 digits epoch number.</li>
<li><strong>epoch</strong> (<em>int</em>) – Epoch number of saved model.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.HybridBlock.forward">
<code class="descname">forward</code><span class="sig-paren">(</span><em>x</em>, <em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.forward" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines the forward computation. Arguments can be either
<code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code> or <code class="xref py py-class docutils literal"><span class="pre">Symbol</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.HybridBlock.hybrid_forward">
<code class="descname">hybrid_forward</code><span class="sig-paren">(</span><em>F</em>, <em>x</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.hybrid_forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.hybrid_forward" title="Permalink to this definition">¶</a></dt>
<dd><p>Overrides to construct symbolic graph for this <cite>Block</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>x</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol" title="mxnet.symbol.Symbol"><em>Symbol</em></a><em> or </em><a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The first input tensor.</li>
<li><strong>*args</strong> (<em>list of Symbol</em><em> or </em><em>list of NDArray</em>) – Additional input tensors.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.HybridBlock.infer_shape">
<code class="descname">infer_shape</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.infer_shape"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.infer_shape" title="Permalink to this definition">¶</a></dt>
<dd><p>Infers shape of Parameters from inputs.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.HybridBlock.infer_type">
<code class="descname">infer_type</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#HybridBlock.infer_type"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.HybridBlock.infer_type" title="Permalink to this definition">¶</a></dt>
<dd><p>Infers data type of Parameters from inputs.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.gluon.Parameter">
<em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">Parameter</code><span class="sig-paren">(</span><em>name</em>, <em>grad_req='write'</em>, <em>shape=None</em>, <em>dtype=<type 'numpy.float32'></em>, <em>lr_mult=1.0</em>, <em>wd_mult=1.0</em>, <em>init=None</em>, <em>allow_deferred_init=False</em>, <em>differentiable=True</em>, <em>stype='default'</em>, <em>grad_stype='default'</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter" title="Permalink to this definition">¶</a></dt>
<dd><p>A Container holding parameters (weights) of Blocks.</p>
<p><a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a> holds a copy of the parameter on each <code class="xref py py-class docutils literal"><span class="pre">Context</span></code> after
it is initialized with <code class="docutils literal"><span class="pre">Parameter.initialize(...)</span></code>. If <a class="reference internal" href="#mxnet.gluon.Parameter.grad_req" title="mxnet.gluon.Parameter.grad_req"><code class="xref py py-attr docutils literal"><span class="pre">grad_req</span></code></a> is
not <code class="docutils literal"><span class="pre">'null'</span></code>, it will also hold a gradient array on each <code class="xref py py-class docutils literal"><span class="pre">Context</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">16</span><span class="p">,</span> <span class="mi">100</span><span class="p">),</span> <span class="n">ctx</span><span class="o">=</span><span class="n">ctx</span><span class="p">)</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">gluon</span><span class="o">.</span><span class="n">Parameter</span><span class="p">(</span><span class="s1">'fc_weight'</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">64</span><span class="p">,</span> <span class="mi">100</span><span class="p">),</span> <span class="n">init</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">init</span><span class="o">.</span><span class="n">Xavier</span><span class="p">())</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">gluon</span><span class="o">.</span><span class="n">Parameter</span><span class="p">(</span><span class="s1">'fc_bias'</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">64</span><span class="p">,),</span> <span class="n">init</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">init</span><span class="o">.</span><span class="n">Zero</span><span class="p">())</span>
<span class="n">w</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="n">ctx</span><span class="p">)</span>
<span class="n">b</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="n">ctx</span><span class="p">)</span>
<span class="n">out</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">FullyConnected</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">w</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">ctx</span><span class="p">),</span> <span class="n">b</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">ctx</span><span class="p">),</span> <span class="n">num_hidden</span><span class="o">=</span><span class="mi">64</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) – Name of this parameter.</li>
<li><strong>grad_req</strong> (<em>{'write'</em><em>, </em><em>'add'</em><em>, </em><em>'null'}</em><em>, </em><em>default 'write'</em>) – <p>Specifies how to update gradient to grad arrays.</p>
<ul>
<li><code class="docutils literal"><span class="pre">'write'</span></code> means everytime gradient is written to grad <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code>.</li>
<li><code class="docutils literal"><span class="pre">'add'</span></code> means everytime gradient is added to the grad <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code>. You need
to manually call <code class="docutils literal"><span class="pre">zero_grad()</span></code> to clear the gradient buffer before each
iteration when using this option.</li>
<li>‘null’ means gradient is not requested for this parameter. gradient arrays
will not be allocated.</li>
</ul>
</li>
<li><strong>shape</strong> (<em>int</em><em> or </em><em>tuple of int</em><em>, </em><em>default None</em>) – Shape of this parameter. By default shape is not specified. Parameter with
unknown shape can be used for <code class="xref py py-class docutils literal"><span class="pre">Symbol</span></code> API, but <code class="docutils literal"><span class="pre">init</span></code> will throw an error
when using <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code> API.</li>
<li><strong>dtype</strong> (<em>numpy.dtype</em><em> or </em><em>str</em><em>, </em><em>default 'float32'</em>) – Data type of this parameter. For example, <code class="docutils literal"><span class="pre">numpy.float32</span></code> or <code class="docutils literal"><span class="pre">'float32'</span></code>.</li>
<li><strong>lr_mult</strong> (<em>float</em><em>, </em><em>default 1.0</em>) – Learning rate multiplier. Learning rate will be multiplied by lr_mult
when updating this parameter with optimizer.</li>
<li><strong>wd_mult</strong> (<em>float</em><em>, </em><em>default 1.0</em>) – Weight decay multiplier (L2 regularizer coefficient). Works similar to lr_mult.</li>
<li><strong>init</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a><em>, </em><em>default None</em>) – Initializer of this parameter. Will use the global initializer by default.</li>
<li><strong>stype</strong> (<em>{'default'</em><em>, </em><em>'row_sparse'</em><em>, </em><em>'csr'}</em><em>, </em><em>defaults to 'default'.</em>) – The storage type of the parameter.</li>
<li><strong>grad_stype</strong> (<em>{'default'</em><em>, </em><em>'row_sparse'</em><em>, </em><em>'csr'}</em><em>, </em><em>defaults to 'default'.</em>) – The storage type of the parameter’s gradient.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="mxnet.gluon.Parameter.grad_req">
<code class="descname">grad_req</code><a class="headerlink" href="#mxnet.gluon.Parameter.grad_req" title="Permalink to this definition">¶</a></dt>
<dd><p><em>{‘write’, ‘add’, ‘null’}</em> – This can be set before or after initialization. Setting <code class="docutils literal"><span class="pre">grad_req</span></code> to <code class="docutils literal"><span class="pre">'null'</span></code>
with <code class="docutils literal"><span class="pre">x.grad_req</span> <span class="pre">=</span> <span class="pre">'null'</span></code> saves memory and computation when you don’t
need gradient w.r.t x.</p>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.Parameter.lr_mult">
<code class="descname">lr_mult</code><a class="headerlink" href="#mxnet.gluon.Parameter.lr_mult" title="Permalink to this definition">¶</a></dt>
<dd><p><em>float</em> – Local learning rate multiplier for this Parameter. The actual learning rate
is calculated with <code class="docutils literal"><span class="pre">learning_rate</span> <span class="pre">*</span> <span class="pre">lr_mult</span></code>. You can set it with
<code class="docutils literal"><span class="pre">param.lr_mult</span> <span class="pre">=</span> <span class="pre">2.0</span></code></p>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.Parameter.wd_mult">
<code class="descname">wd_mult</code><a class="headerlink" href="#mxnet.gluon.Parameter.wd_mult" title="Permalink to this definition">¶</a></dt>
<dd><p><em>float</em> – Local weight decay multiplier for this Parameter.</p>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.Parameter.__weakref__">
<code class="descname">__weakref__</code><a class="headerlink" href="#mxnet.gluon.Parameter.__weakref__" title="Permalink to this definition">¶</a></dt>
<dd><p>list of weak references to the object (if defined)</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.cast">
<code class="descname">cast</code><span class="sig-paren">(</span><em>dtype</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.cast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.cast" title="Permalink to this definition">¶</a></dt>
<dd><p>Cast data and gradient of this Parameter to a new data type.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>dtype</strong> (<em>str</em><em> or </em><em>numpy.dtype</em>) – The new data type.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.data">
<code class="descname">data</code><span class="sig-paren">(</span><em>ctx=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.data" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of this parameter on one context. Must have been
initialized on this context before. For sparse parameters, use
<a class="reference internal" href="#mxnet.gluon.Parameter.row_sparse_data" title="mxnet.gluon.Parameter.row_sparse_data"><code class="xref py py-meth docutils literal"><span class="pre">Parameter.row_sparse_data()</span></code></a> instead.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ctx</strong> (<em>Context</em>) – Desired context.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">NDArray on ctx</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.Parameter.dtype">
<code class="descname">dtype</code><a class="headerlink" href="#mxnet.gluon.Parameter.dtype" title="Permalink to this definition">¶</a></dt>
<dd><p>The type of the parameter.</p>
<p>Setting the dtype value is equivalent to casting the value of the parameter</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.grad">
<code class="descname">grad</code><span class="sig-paren">(</span><em>ctx=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.grad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.grad" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a gradient buffer for this parameter on one context.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ctx</strong> (<em>Context</em>) – Desired context.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.initialize">
<code class="descname">initialize</code><span class="sig-paren">(</span><em>init=None</em>, <em>ctx=None</em>, <em>default_init=<mxnet.initializer.Uniform object></em>, <em>force_reinit=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.initialize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.initialize" title="Permalink to this definition">¶</a></dt>
<dd><p>Initializes parameter and gradient arrays. Only used for <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code> API.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>init</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – The initializer to use. Overrides <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> and default_init.</li>
<li><strong>ctx</strong> (Context or list of Context, defaults to <code class="xref py py-meth docutils literal"><span class="pre">context.current_context()</span></code>.) – <p>Initialize Parameter on given context. If ctx is a list of Context, a
copy will be made for each context.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Copies are independent arrays. User is responsible for keeping
their values consistent when updating.
Normally <code class="xref py py-class docutils literal"><span class="pre">gluon.Trainer</span></code> does this for you.</p>
</div>
</li>
<li><strong>default_init</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – Default initializer is used when both <code class="xref py py-func docutils literal"><span class="pre">init()</span></code>
and <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> are <code class="docutils literal"><span class="pre">None</span></code>.</li>
<li><strong>force_reinit</strong> (<em>bool</em><em>, </em><em>default False</em>) – Whether to force re-initialization if parameter is already initialized.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">weight</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">gluon</span><span class="o">.</span><span class="n">Parameter</span><span class="p">(</span><span class="s1">'weight'</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">data</span><span class="p">()</span>
<span class="go">[[-0.01068833 0.01729892]</span>
<span class="go"> [ 0.02042518 -0.01618656]]</span>
<span class="go"><NDArray 2x2 @cpu(0)></span>
<span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">grad</span><span class="p">()</span>
<span class="go">[[ 0. 0.]</span>
<span class="go"> [ 0. 0.]]</span>
<span class="go"><NDArray 2x2 @cpu(0)></span>
<span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">initialize</span><span class="p">(</span><span class="n">ctx</span><span class="o">=</span><span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">1</span><span class="p">)])</span>
<span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
<span class="go">[[-0.00873779 -0.02834515]</span>
<span class="go"> [ 0.05484822 -0.06206018]]</span>
<span class="go"><NDArray 2x2 @gpu(0)></span>
<span class="gp">>>> </span><span class="n">weight</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">gpu</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
<span class="go">[[-0.00873779 -0.02834515]</span>
<span class="go"> [ 0.05484822 -0.06206018]]</span>
<span class="go"><NDArray 2x2 @gpu(1)></span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.list_ctx">
<code class="descname">list_ctx</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.list_ctx"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.list_ctx" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of contexts this parameter is initialized on.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.list_data">
<code class="descname">list_data</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.list_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.list_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns copies of this parameter on all contexts, in the same order
as creation. For sparse parameters, use <a class="reference internal" href="#mxnet.gluon.Parameter.list_row_sparse_data" title="mxnet.gluon.Parameter.list_row_sparse_data"><code class="xref py py-meth docutils literal"><span class="pre">Parameter.list_row_sparse_data()</span></code></a>
instead.</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">list of NDArrays</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.list_grad">
<code class="descname">list_grad</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.list_grad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.list_grad" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns gradient buffers on all contexts, in the same order
as <code class="xref py py-meth docutils literal"><span class="pre">values()</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.list_row_sparse_data">
<code class="descname">list_row_sparse_data</code><span class="sig-paren">(</span><em>row_id</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.list_row_sparse_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.list_row_sparse_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns copies of the ‘row_sparse’ parameter on all contexts, in the same order
as creation. The copy only retains rows whose ids occur in provided row ids.
The parameter must have been initialized before.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>row_id</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – Row ids to retain for the ‘row_sparse’ parameter.</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">list of NDArrays</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.reset_ctx">
<code class="descname">reset_ctx</code><span class="sig-paren">(</span><em>ctx</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.reset_ctx"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.reset_ctx" title="Permalink to this definition">¶</a></dt>
<dd><p>Re-assign Parameter to other contexts.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ctx</strong> (Context or list of Context, default <code class="docutils literal"><span class="pre">context.current_context()</span></code>.) – Assign Parameter to given context. If ctx is a list of Context, a
copy will be made for each context.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.row_sparse_data">
<code class="descname">row_sparse_data</code><span class="sig-paren">(</span><em>row_id</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.row_sparse_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.row_sparse_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of the ‘row_sparse’ parameter on the same context as row_id’s.
The copy only retains rows whose ids occur in provided row ids.
The parameter must have been initialized on this context before.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>row_id</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – Row ids to retain for the ‘row_sparse’ parameter.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">NDArray on row_id’s context</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.set_data">
<code class="descname">set_data</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.set_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.set_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets this parameter’s value on all contexts.</p>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.Parameter.shape">
<code class="descname">shape</code><a class="headerlink" href="#mxnet.gluon.Parameter.shape" title="Permalink to this definition">¶</a></dt>
<dd><p>The shape of the parameter.</p>
<p>By default, an unknown dimension size is 0. However, when the NumPy semantic
is turned on, unknown dimension size is -1.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.var">
<code class="descname">var</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.var"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.var" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a symbol representing this parameter.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Parameter.zero_grad">
<code class="descname">zero_grad</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#Parameter.zero_grad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Parameter.zero_grad" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets gradient buffer on all contexts to 0. No action is taken if
parameter is uninitialized or doesn’t require gradient.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.gluon.ParameterDict">
<em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">ParameterDict</code><span class="sig-paren">(</span><em>prefix=''</em>, <em>shared=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict" title="Permalink to this definition">¶</a></dt>
<dd><p>A dictionary managing a set of parameters.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>prefix</strong> (str, default <code class="docutils literal"><span class="pre">''</span></code>) – The prefix to be prepended to all Parameters’ names created by this dict.</li>
<li><strong>shared</strong> (<a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><em>ParameterDict</em></a><em> or </em><em>None</em>) – If not <code class="docutils literal"><span class="pre">None</span></code>, when this dict’s <a class="reference internal" href="#mxnet.gluon.ParameterDict.get" title="mxnet.gluon.ParameterDict.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a> method creates a new parameter, will
first try to retrieve it from “shared” dict. Usually used for sharing
parameters with another Block.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="mxnet.gluon.ParameterDict.__weakref__">
<code class="descname">__weakref__</code><a class="headerlink" href="#mxnet.gluon.ParameterDict.__weakref__" title="Permalink to this definition">¶</a></dt>
<dd><p>list of weak references to the object (if defined)</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.ParameterDict.get">
<code class="descname">get</code><span class="sig-paren">(</span><em>name</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.get"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.get" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieves a <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a> with name <code class="docutils literal"><span class="pre">self.prefix+name</span></code>. If not found,
<a class="reference internal" href="#mxnet.gluon.ParameterDict.get" title="mxnet.gluon.ParameterDict.get"><code class="xref py py-func docutils literal"><span class="pre">get()</span></code></a> will first try to retrieve it from “shared” dict. If still not
found, <a class="reference internal" href="#mxnet.gluon.ParameterDict.get" title="mxnet.gluon.ParameterDict.get"><code class="xref py py-func docutils literal"><span class="pre">get()</span></code></a> will create a new <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a> with key-word arguments and
insert it to self.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>str</em>) – Name of the desired Parameter. It will be prepended with this dictionary’s
prefix.</li>
<li><strong>**kwargs</strong> (<em>dict</em>) – The rest of key-word arguments for the created <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The created or retrieved <a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter"><code class="xref py py-class docutils literal"><span class="pre">Parameter</span></code></a>.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><a class="reference internal" href="#mxnet.gluon.Parameter" title="mxnet.gluon.Parameter">Parameter</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.ParameterDict.get_constant">
<code class="descname">get_constant</code><span class="sig-paren">(</span><em>name</em>, <em>value=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.get_constant"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.get_constant" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieves a <a class="reference internal" href="#mxnet.gluon.Constant" title="mxnet.gluon.Constant"><code class="xref py py-class docutils literal"><span class="pre">Constant</span></code></a> with name <code class="docutils literal"><span class="pre">self.prefix+name</span></code>. If not found,
<a class="reference internal" href="#mxnet.gluon.ParameterDict.get" title="mxnet.gluon.ParameterDict.get"><code class="xref py py-func docutils literal"><span class="pre">get()</span></code></a> will first try to retrieve it from “shared” dict. If still not
found, <a class="reference internal" href="#mxnet.gluon.ParameterDict.get" title="mxnet.gluon.ParameterDict.get"><code class="xref py py-func docutils literal"><span class="pre">get()</span></code></a> will create a new <a class="reference internal" href="#mxnet.gluon.Constant" title="mxnet.gluon.Constant"><code class="xref py py-class docutils literal"><span class="pre">Constant</span></code></a> with key-word
arguments and insert it to self.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>str</em>) – Name of the desired Constant. It will be prepended with this dictionary’s
prefix.</li>
<li><strong>value</strong> (<em>array-like</em>) – Initial value of constant.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The created or retrieved <a class="reference internal" href="#mxnet.gluon.Constant" title="mxnet.gluon.Constant"><code class="xref py py-class docutils literal"><span class="pre">Constant</span></code></a>.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><a class="reference internal" href="#mxnet.gluon.Constant" title="mxnet.gluon.Constant"><code class="xref py py-class docutils literal"><span class="pre">Constant</span></code></a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.ParameterDict.initialize">
<code class="descname">initialize</code><span class="sig-paren">(</span><em>init=<mxnet.initializer.Uniform object></em>, <em>ctx=None</em>, <em>verbose=False</em>, <em>force_reinit=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.initialize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.initialize" title="Permalink to this definition">¶</a></dt>
<dd><p>Initializes all Parameters managed by this dictionary to be used for <code class="xref py py-class docutils literal"><span class="pre">NDArray</span></code>
API. It has no effect when using <code class="xref py py-class docutils literal"><span class="pre">Symbol</span></code> API.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>init</strong> (<a class="reference internal" href="../optimization/optimization.html#mxnet.initializer.Initializer" title="mxnet.initializer.Initializer"><em>Initializer</em></a>) – Global default Initializer to be used when <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> is <code class="docutils literal"><span class="pre">None</span></code>.
Otherwise, <code class="xref py py-meth docutils literal"><span class="pre">Parameter.init()</span></code> takes precedence.</li>
<li><strong>ctx</strong> (<em>Context</em><em> or </em><em>list of Context</em>) – Keeps a copy of Parameters on one or many context(s).</li>
<li><strong>verbose</strong> (<em>bool</em><em>, </em><em>default False</em>) – Whether to verbosely print out details on initialization.</li>
<li><strong>force_reinit</strong> (<em>bool</em><em>, </em><em>default False</em>) – Whether to force re-initialization if parameter is already initialized.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.ParameterDict.load">
<code class="descname">load</code><span class="sig-paren">(</span><em>filename</em>, <em>ctx=None</em>, <em>allow_missing=False</em>, <em>ignore_extra=False</em>, <em>restore_prefix=''</em>, <em>cast_dtype=False</em>, <em>dtype_source='current'</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.load"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.load" title="Permalink to this definition">¶</a></dt>
<dd><p>Load parameters from file.</p>
<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>filename</strong> (<em>str</em>) – Path to parameter file.</li>
<li><strong>ctx</strong> (<em>Context</em><em> or </em><em>list of Context</em>) – Context(s) initialize loaded parameters on.</li>
<li><strong>allow_missing</strong> (<em>bool</em><em>, </em><em>default False</em>) – Whether to silently skip loading parameters not represents in the file.</li>
<li><strong>ignore_extra</strong> (<em>bool</em><em>, </em><em>default False</em>) – Whether to silently ignore parameters from the file that are not
present in this ParameterDict.</li>
<li><strong>restore_prefix</strong> (<em>str</em><em>, </em><em>default ''</em>) – prepend prefix to names of stored parameters before loading.</li>
<li><strong>cast_dtype</strong> (<em>bool</em><em>, </em><em>default False</em>) – Cast the data type of the parameter</li>
<li><strong>dtype_source</strong> (<em>str</em><em>, </em><em>default 'current'</em>) – must be in {‘current’, ‘saved’}
Only valid if cast_dtype=True, specify the source of the dtype for casting
the parameters</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.gluon.ParameterDict.prefix">
<code class="descname">prefix</code><a class="headerlink" href="#mxnet.gluon.ParameterDict.prefix" title="Permalink to this definition">¶</a></dt>
<dd><p>Prefix of this dict. It will be prepended to <code class="xref py py-class docutils literal"><span class="pre">Parameter`s'</span> <span class="pre">name</span> <span class="pre">created</span>
<span class="pre">with</span> <span class="pre">:py:func:`get</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.ParameterDict.reset_ctx">
<code class="descname">reset_ctx</code><span class="sig-paren">(</span><em>ctx</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.reset_ctx"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.reset_ctx" title="Permalink to this definition">¶</a></dt>
<dd><p>Re-assign all Parameters to other contexts.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ctx</strong> (Context or list of Context, default <code class="xref py py-meth docutils literal"><span class="pre">context.current_context()</span></code>.) – Assign Parameter to given context. If ctx is a list of Context, a
copy will be made for each context.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.ParameterDict.save">
<code class="descname">save</code><span class="sig-paren">(</span><em>filename</em>, <em>strip_prefix=''</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.save"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.save" title="Permalink to this definition">¶</a></dt>
<dd><p>Save parameters to file.</p>
<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>filename</strong> (<em>str</em>) – Path to parameter file.</li>
<li><strong>strip_prefix</strong> (<em>str</em><em>, </em><em>default ''</em>) – Strip prefix from parameter names before saving.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.ParameterDict.setattr">
<code class="descname">setattr</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.setattr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.setattr" title="Permalink to this definition">¶</a></dt>
<dd><p>Set an attribute to a new value for all Parameters.</p>
<p>For example, set grad_req to null if you don’t need gradient w.r.t a
model’s Parameters:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">model</span><span class="o">.</span><span class="n">collect_params</span><span class="p">()</span><span class="o">.</span><span class="n">setattr</span><span class="p">(</span><span class="s1">'grad_req'</span><span class="p">,</span> <span class="s1">'null'</span><span class="p">)</span>
</pre></div>
</div>
<p>or change the learning rate multiplier:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">model</span><span class="o">.</span><span class="n">collect_params</span><span class="p">()</span><span class="o">.</span><span class="n">setattr</span><span class="p">(</span><span class="s1">'lr_mult'</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) – Name of the attribute.</li>
<li><strong>value</strong> (<em>valid type for attribute name</em>) – The new value for the attribute.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.ParameterDict.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>other</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.update"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.update" title="Permalink to this definition">¶</a></dt>
<dd><p>Copies all Parameters in <code class="docutils literal"><span class="pre">other</span></code> to self.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.ParameterDict.zero_grad">
<code class="descname">zero_grad</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/parameter.html#ParameterDict.zero_grad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.ParameterDict.zero_grad" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets all Parameters’ gradient buffer to 0.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.gluon.SymbolBlock">
<em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">SymbolBlock</code><span class="sig-paren">(</span><em>outputs</em>, <em>inputs</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#SymbolBlock"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.SymbolBlock" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct block from symbol. This is useful for using pre-trained models
as feature extractors. For example, you may want to extract the output
from fc2 layer in AlexNet.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>outputs</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol" title="mxnet.symbol.Symbol"><em>Symbol</em></a><em> or </em><em>list of Symbol</em>) – The desired output for SymbolBlock.</li>
<li><strong>inputs</strong> (<a class="reference internal" href="../symbol/symbol.html#mxnet.symbol.Symbol" title="mxnet.symbol.Symbol"><em>Symbol</em></a><em> or </em><em>list of Symbol</em>) – The Variables in output’s argument that should be used as inputs.</li>
<li><strong>params</strong> (<a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><em>ParameterDict</em></a>) – Parameter dictionary for arguments and auxililary states of outputs
that are not inputs.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># To extract the feature from fc1 and fc2 layers of AlexNet:</span>
<span class="gp">>>> </span><span class="n">alexnet</span> <span class="o">=</span> <span class="n">gluon</span><span class="o">.</span><span class="n">model_zoo</span><span class="o">.</span><span class="n">vision</span><span class="o">.</span><span class="n">alexnet</span><span class="p">(</span><span class="n">pretrained</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">ctx</span><span class="o">=</span><span class="n">mx</span><span class="o">.</span><span class="n">cpu</span><span class="p">(),</span>
<span class="go"> prefix='model_')</span>
<span class="gp">>>> </span><span class="n">inputs</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">sym</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s1">'data'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">out</span> <span class="o">=</span> <span class="n">alexnet</span><span class="p">(</span><span class="n">inputs</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">internals</span> <span class="o">=</span> <span class="n">out</span><span class="o">.</span><span class="n">get_internals</span><span class="p">()</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">internals</span><span class="o">.</span><span class="n">list_outputs</span><span class="p">())</span>
<span class="go">['data', ..., 'model_dense0_relu_fwd_output', ..., 'model_dense1_relu_fwd_output', ...]</span>
<span class="gp">>>> </span><span class="n">outputs</span> <span class="o">=</span> <span class="p">[</span><span class="n">internals</span><span class="p">[</span><span class="s1">'model_dense0_relu_fwd_output'</span><span class="p">],</span>
<span class="go"> internals['model_dense1_relu_fwd_output']]</span>
<span class="gp">>>> </span><span class="c1"># Create SymbolBlock that shares parameters with alexnet</span>
<span class="gp">>>> </span><span class="n">feat_model</span> <span class="o">=</span> <span class="n">gluon</span><span class="o">.</span><span class="n">SymbolBlock</span><span class="p">(</span><span class="n">outputs</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">alexnet</span><span class="o">.</span><span class="n">collect_params</span><span class="p">())</span>
<span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">16</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">224</span><span class="p">))</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">feat_model</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
</pre></div>
</div>
<dl class="staticmethod">
<dt id="mxnet.gluon.SymbolBlock.imports">
<em class="property">static </em><code class="descname">imports</code><span class="sig-paren">(</span><em>symbol_file</em>, <em>input_names</em>, <em>param_file=None</em>, <em>ctx=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/block.html#SymbolBlock.imports"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.SymbolBlock.imports" title="Permalink to this definition">¶</a></dt>
<dd><p>Import model previously saved by <cite>HybridBlock.export</cite> or
<cite>Module.save_checkpoint</cite> as a SymbolBlock for use in Gluon.</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>symbol_file</strong> (<em>str</em>) – Path to symbol file.</li>
<li><strong>input_names</strong> (<em>list of str</em>) – List of input variable names</li>
<li><strong>param_file</strong> (<em>str</em><em>, </em><em>optional</em>) – Path to parameter file.</li>
<li><strong>ctx</strong> (<em>Context</em><em>, </em><em>default None</em>) – The context to initialize SymbolBlock on.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">SymbolBlock loaded from symbol and parameter files.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><a class="reference internal" href="#mxnet.gluon.SymbolBlock" title="mxnet.gluon.SymbolBlock">SymbolBlock</a></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="n">net1</span> <span class="o">=</span> <span class="n">gluon</span><span class="o">.</span><span class="n">model_zoo</span><span class="o">.</span><span class="n">vision</span><span class="o">.</span><span class="n">resnet18_v1</span><span class="p">(</span>
<span class="gp">... </span> <span class="n">prefix</span><span class="o">=</span><span class="s1">'resnet'</span><span class="p">,</span> <span class="n">pretrained</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">net1</span><span class="o">.</span><span class="n">hybridize</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">out1</span> <span class="o">=</span> <span class="n">net1</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">net1</span><span class="o">.</span><span class="n">export</span><span class="p">(</span><span class="s1">'net1'</span><span class="p">,</span> <span class="n">epoch</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">>>></span>
<span class="gp">>>> </span><span class="n">net2</span> <span class="o">=</span> <span class="n">gluon</span><span class="o">.</span><span class="n">SymbolBlock</span><span class="o">.</span><span class="n">imports</span><span class="p">(</span>
<span class="gp">... </span> <span class="s1">'net1-symbol.json'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'data'</span><span class="p">],</span> <span class="s1">'net1-0001.params'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">out2</span> <span class="o">=</span> <span class="n">net2</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.gluon.Trainer">
<em class="property">class </em><code class="descclassname">mxnet.gluon.</code><code class="descname">Trainer</code><span class="sig-paren">(</span><em>params</em>, <em>optimizer</em>, <em>optimizer_params=None</em>, <em>kvstore='device'</em>, <em>compression_params=None</em>, <em>update_on_kvstore=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer" title="Permalink to this definition">¶</a></dt>
<dd><p>Applies an <cite>Optimizer</cite> on a set of Parameters. Trainer should
be used together with <cite>autograd</cite>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>For the following cases, updates will always happen on kvstore,
i.e., you cannot set update_on_kvstore=False.</p>
<ul class="last simple">
<li>dist kvstore with sparse weights or sparse gradients</li>
<li>dist async kvstore</li>
<li><cite>optimizer.lr_scheduler</cite> is not None</li>
</ul>
</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>params</strong> (<a class="reference internal" href="#mxnet.gluon.ParameterDict" title="mxnet.gluon.ParameterDict"><em>ParameterDict</em></a>) – The set of parameters to optimize.</li>
<li><strong>optimizer</strong> (<em>str</em><em> or </em><a class="reference internal" href="../optimization/optimization.html#mxnet.optimizer.Optimizer" title="mxnet.optimizer.Optimizer"><em>Optimizer</em></a>) – The optimizer to use. See
<a class="reference external" href="/api/python/optimization/optimization.html#the-mxnet-optimizer-package">help</a>
on Optimizer for a list of available optimizers.</li>
<li><strong>optimizer_params</strong> (<em>dict</em>) – Key-word arguments to be passed to optimizer constructor. For example,
<cite>{‘learning_rate’: 0.1}</cite>. All optimizers accept learning_rate, wd (weight decay),
clip_gradient, and lr_scheduler. See each optimizer’s
constructor for a list of additional supported arguments.</li>
<li><strong>kvstore</strong> (<em>str</em><em> or </em><a class="reference internal" href="../kvstore/kvstore.html#mxnet.kvstore.KVStore" title="mxnet.kvstore.KVStore"><em>KVStore</em></a>) – kvstore type for multi-gpu and distributed training. See help on
<a class="reference internal" href="../kvstore/kvstore.html#mxnet.kvstore.create" title="mxnet.kvstore.create"><code class="xref any py py-func docutils literal"><span class="pre">mxnet.kvstore.create</span></code></a> for more information.</li>
<li><strong>compression_params</strong> (<em>dict</em>) – Specifies type of gradient compression and additional arguments depending
on the type of compression being used. For example, 2bit compression requires a threshold.
Arguments would then be {‘type’:‘2bit’, ‘threshold’:0.5}
See mxnet.KVStore.set_gradient_compression method for more details on gradient compression.</li>
<li><strong>update_on_kvstore</strong> (<em>bool</em><em>, </em><em>default None</em>) – Whether to perform parameter updates on kvstore. If None, then trainer will choose the more
suitable option depending on the type of kvstore. If the <cite>update_on_kvstore</cite> argument is
provided, environment variable <cite>MXNET_UPDATE_ON_KVSTORE</cite> will be ignored.</li>
<li><strong>Properties</strong> – </li>
<li><strong>----------</strong> – </li>
<li><strong>learning_rate</strong> (<em>float</em>) – The current learning rate of the optimizer. Given an Optimizer object
optimizer, its learning rate can be accessed as optimizer.learning_rate.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="mxnet.gluon.Trainer.__weakref__">
<code class="descname">__weakref__</code><a class="headerlink" href="#mxnet.gluon.Trainer.__weakref__" title="Permalink to this definition">¶</a></dt>
<dd><p>list of weak references to the object (if defined)</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Trainer.allreduce_grads">
<code class="descname">allreduce_grads</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.allreduce_grads"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.allreduce_grads" title="Permalink to this definition">¶</a></dt>
<dd><p>For each parameter, reduce the gradients from different contexts.</p>
<p>Should be called after <cite>autograd.backward()</cite>, outside of <cite>record()</cite> scope,
and before <cite>trainer.update()</cite>.</p>
<p>For normal parameter updates, <cite>step()</cite> should be used, which internally calls
<cite>allreduce_grads()</cite> and then <cite>update()</cite>. However, if you need to get the reduced
gradients to perform certain transformation, such as in gradient clipping, then
you may want to manually call <cite>allreduce_grads()</cite> and <cite>update()</cite> separately.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Trainer.load_states">
<code class="descname">load_states</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.load_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.load_states" title="Permalink to this definition">¶</a></dt>
<dd><p>Loads trainer states (e.g. optimizer, momentum) from a file.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fname</strong> (<em>str</em>) – Path to input states file.</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><cite>optimizer.param_dict</cite>, which contains Parameter information (such as
<cite>lr_mult</cite> and <cite>wd_mult</cite>) will not be loaded from the file, but rather set
based on current Trainer’s parameters.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Trainer.save_states">
<code class="descname">save_states</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.save_states"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.save_states" title="Permalink to this definition">¶</a></dt>
<dd><p>Saves trainer states (e.g. optimizer, momentum) to a file.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fname</strong> (<em>str</em>) – Path to output states file.</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><cite>optimizer.param_dict</cite>, which contains Parameter information (such as
<cite>lr_mult</cite> and <cite>wd_mult</cite>) will not be saved.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Trainer.set_learning_rate">
<code class="descname">set_learning_rate</code><span class="sig-paren">(</span><em>lr</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.set_learning_rate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.set_learning_rate" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets a new learning rate of the optimizer.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>lr</strong> (<em>float</em>) – The new learning rate of the optimizer.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Trainer.step">
<code class="descname">step</code><span class="sig-paren">(</span><em>batch_size</em>, <em>ignore_stale_grad=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.step"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.step" title="Permalink to this definition">¶</a></dt>
<dd><p>Makes one step of parameter update. Should be called after
<cite>autograd.backward()</cite> and outside of <cite>record()</cite> scope.</p>
<p>For normal parameter updates, <cite>step()</cite> should be used, which internally calls
<cite>allreduce_grads()</cite> and then <cite>update()</cite>. However, if you need to get the reduced
gradients to perform certain transformation, such as in gradient clipping, then
you may want to manually call <cite>allreduce_grads()</cite> and <cite>update()</cite> separately.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>batch_size</strong> (<em>int</em>) – Batch size of data processed. Gradient will be normalized by <cite>1/batch_size</cite>.
Set this to 1 if you normalized loss manually with <cite>loss = mean(loss)</cite>.</li>
<li><strong>ignore_stale_grad</strong> (<em>bool</em><em>, </em><em>optional</em><em>, </em><em>default=False</em>) – If true, ignores Parameters with stale gradient (gradient that has not
been updated by <cite>backward</cite> after last step) and skip update.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.Trainer.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>batch_size</em>, <em>ignore_stale_grad=False</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/trainer.html#Trainer.update"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.Trainer.update" title="Permalink to this definition">¶</a></dt>
<dd><p>Makes one step of parameter update.</p>
<p>Should be called after <cite>autograd.backward()</cite> and outside of <cite>record()</cite> scope,
and after <cite>trainer.update()</cite>.</p>
<p>For normal parameter updates, <cite>step()</cite> should be used, which internally calls
<cite>allreduce_grads()</cite> and then <cite>update()</cite>. However, if you need to get the reduced
gradients to perform certain transformation, such as in gradient clipping, then
you may want to manually call <cite>allreduce_grads()</cite> and <cite>update()</cite> separately.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>batch_size</strong> (<em>int</em>) – Batch size of data processed. Gradient will be normalized by <cite>1/batch_size</cite>.
Set this to 1 if you normalized loss manually with <cite>loss = mean(loss)</cite>.</li>
<li><strong>ignore_stale_grad</strong> (<em>bool</em><em>, </em><em>optional</em><em>, </em><em>default=False</em>) – If true, ignores Parameters with stale gradient (gradient that has not
been updated by <cite>backward</cite> after last step) and skip update.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.gluon.nn.Sequential">
<em class="property">class </em><code class="descclassname">mxnet.gluon.nn.</code><code class="descname">Sequential</code><span class="sig-paren">(</span><em>prefix=None</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#Sequential"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.Sequential" title="Permalink to this definition">¶</a></dt>
<dd><p>Stacks Blocks sequentially.</p>
<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">net</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Sequential</span><span class="p">()</span>
<span class="c1"># use net's name_scope to give child Blocks appropriate names.</span>
<span class="k">with</span> <span class="n">net</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">activation</span><span class="o">=</span><span class="s1">'relu'</span><span class="p">))</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">))</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.gluon.nn.Sequential.add">
<code class="descname">add</code><span class="sig-paren">(</span><em>*blocks</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#Sequential.add"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.Sequential.add" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds block on top of the stack.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.gluon.nn.Sequential.hybridize">
<code class="descname">hybridize</code><span class="sig-paren">(</span><em>active=True</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#Sequential.hybridize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.Sequential.hybridize" title="Permalink to this definition">¶</a></dt>
<dd><p>Activates or deactivates <cite>HybridBlock</cite> s recursively. Has no effect on
non-hybrid children.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>active</strong> (<em>bool</em><em>, </em><em>default True</em>) – Whether to turn hybrid on or off.</li>
<li><strong>**kwargs</strong> (<em>string</em>) – Additional flags for hybridized operator.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.gluon.nn.HybridSequential">
<em class="property">class </em><code class="descclassname">mxnet.gluon.nn.</code><code class="descname">HybridSequential</code><span class="sig-paren">(</span><em>prefix=None</em>, <em>params=None</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#HybridSequential"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.HybridSequential" title="Permalink to this definition">¶</a></dt>
<dd><p>Stacks HybridBlocks sequentially.</p>
<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">net</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">HybridSequential</span><span class="p">()</span>
<span class="c1"># use net's name_scope to give child Blocks appropriate names.</span>
<span class="k">with</span> <span class="n">net</span><span class="o">.</span><span class="n">name_scope</span><span class="p">():</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">activation</span><span class="o">=</span><span class="s1">'relu'</span><span class="p">))</span>
<span class="n">net</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Dense</span><span class="p">(</span><span class="mi">20</span><span class="p">))</span>
<span class="n">net</span><span class="o">.</span><span class="n">hybridize</span><span class="p">()</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.gluon.nn.HybridSequential.add">
<code class="descname">add</code><span class="sig-paren">(</span><em>*blocks</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/nn/basic_layers.html#HybridSequential.add"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.nn.HybridSequential.add" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds block on top of the stack.</p>
</dd></dl>
</dd></dl>
<span class="target" id="module-mxnet.gluon.utils"></span><p>Parallelization utility optimizer.</p>
<dl class="function">
<dt id="mxnet.gluon.utils.split_data">
<code class="descclassname">mxnet.gluon.utils.</code><code class="descname">split_data</code><span class="sig-paren">(</span><em>data</em>, <em>num_slice</em>, <em>batch_axis=0</em>, <em>even_split=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#split_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.split_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Splits an NDArray into <cite>num_slice</cite> slices along <cite>batch_axis</cite>.
Usually used for data parallelism where each slices is sent
to one device (i.e. GPU).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>data</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – A batch of data.</li>
<li><strong>num_slice</strong> (<em>int</em>) – Number of desired slices.</li>
<li><strong>batch_axis</strong> (<em>int</em><em>, </em><em>default 0</em>) – The axis along which to slice.</li>
<li><strong>even_split</strong> (<em>bool</em><em>, </em><em>default True</em>) – Whether to force all slices to have the same number of elements.
If <cite>True</cite>, an error will be raised when <cite>num_slice</cite> does not evenly
divide <cite>data.shape[batch_axis]</cite>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Return value is a list even if <cite>num_slice</cite> is 1.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list of NDArray</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.gluon.utils.split_and_load">
<code class="descclassname">mxnet.gluon.utils.</code><code class="descname">split_and_load</code><span class="sig-paren">(</span><em>data</em>, <em>ctx_list</em>, <em>batch_axis=0</em>, <em>even_split=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#split_and_load"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.split_and_load" title="Permalink to this definition">¶</a></dt>
<dd><p>Splits an NDArray into <cite>len(ctx_list)</cite> slices along <cite>batch_axis</cite> and loads
each slice to one context in <cite>ctx_list</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>data</strong> (<a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – A batch of data.</li>
<li><strong>ctx_list</strong> (<em>list of Context</em>) – A list of Contexts.</li>
<li><strong>batch_axis</strong> (<em>int</em><em>, </em><em>default 0</em>) – The axis along which to slice.</li>
<li><strong>even_split</strong> (<em>bool</em><em>, </em><em>default True</em>) – Whether to force all slices to have the same number of elements.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Each corresponds to a context in <cite>ctx_list</cite>.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list of NDArray</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.gluon.utils.clip_global_norm">
<code class="descclassname">mxnet.gluon.utils.</code><code class="descname">clip_global_norm</code><span class="sig-paren">(</span><em>arrays</em>, <em>max_norm</em>, <em>check_isfinite=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#clip_global_norm"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.clip_global_norm" title="Permalink to this definition">¶</a></dt>
<dd><p>Rescales NDArrays so that the sum of their 2-norm is smaller than <cite>max_norm</cite>.</p>
<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>arrays</strong> (<em>list of NDArray</em>) – </li>
<li><strong>max_norm</strong> (<em>float</em>) – </li>
<li><strong>check_isfinite</strong> (<em>bool</em><em>, </em><em>default True</em>) – If True, check that the total_norm is finite (not nan or inf). This
requires a blocking .asscalar() call.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Total norm. Return type is NDArray of shape (1,) if check_isfinite is
False. Otherwise a float is returned.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><a class="reference internal" href="../ndarray/ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray">NDArray</a> or float</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.gluon.utils.check_sha1">
<code class="descclassname">mxnet.gluon.utils.</code><code class="descname">check_sha1</code><span class="sig-paren">(</span><em>filename</em>, <em>sha1_hash</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#check_sha1"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.check_sha1" title="Permalink to this definition">¶</a></dt>
<dd><p>Check whether the sha1 hash of the file content matches the expected hash.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>filename</strong> (<em>str</em>) – Path to the file.</li>
<li><strong>sha1_hash</strong> (<em>str</em>) – Expected sha1 hash in hexadecimal digits.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Whether the file content matches the expected hash.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.gluon.utils.download">
<code class="descclassname">mxnet.gluon.utils.</code><code class="descname">download</code><span class="sig-paren">(</span><em>url</em>, <em>path=None</em>, <em>overwrite=False</em>, <em>sha1_hash=None</em>, <em>retries=5</em>, <em>verify_ssl=True</em><span class="sig-paren">)</span><a class="reference internal" href="../../../_modules/mxnet/gluon/utils.html#download"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mxnet.gluon.utils.download" title="Permalink to this definition">¶</a></dt>
<dd><p>Download an given URL</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>url</strong> (<em>str</em>) – URL to download</li>
<li><strong>path</strong> (<em>str</em><em>, </em><em>optional</em>) – Destination path to store downloaded file. By default stores to the
current directory with same name as in url.</li>
<li><strong>overwrite</strong> (<em>bool</em><em>, </em><em>optional</em>) – Whether to overwrite destination file if already exists.</li>
<li><strong>sha1_hash</strong> (<em>str</em><em>, </em><em>optional</em>) – Expected sha1 hash in hexadecimal digits. Will ignore existing file when hash is specified
but doesn’t match.</li>
<li><strong>retries</strong> (<em>integer</em><em>, </em><em>default 5</em>) – The number of times to attempt the download in case of failure or non 200 return codes</li>
<li><strong>verify_ssl</strong> (<em>bool</em><em>, </em><em>default True</em>) – Verify SSL certificates.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The file path of the downloaded file.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<script>auto_index("api-reference");</script></div>
</div>
</div>
</div>
<div aria-label="main navigation" class="sphinxsidebar rightsidebar" role="navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../../../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Gluon Package</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#contents">Contents</a></li>
<li><a class="reference internal" href="#parameter">Parameter</a></li>
<li><a class="reference internal" href="#containers">Containers</a></li>
<li><a class="reference internal" href="#trainer">Trainer</a></li>
<li><a class="reference internal" href="#utilities">Utilities</a></li>
<li><a class="reference internal" href="#api-reference">API Reference</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div><div class="footer">
<div class="section-disclaimer">
<div class="container">
<div>
<img height="60" src="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/apache_incubator_logo.png"/>
<p>
Apache MXNet is an effort undergoing incubation at The Apache Software Foundation (ASF), <strong>sponsored by the <i>Apache Incubator</i></strong>. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
</p>
<p>
"Copyright © 2017-2018, The Apache Software Foundation
Apache MXNet, MXNet, Apache, the Apache feather, and the Apache MXNet project logo are either registered trademarks or trademarks of the Apache Software Foundation."
</p>
</div>
</div>
</div>
</div> <!-- pagename != index -->
</div>
<script crossorigin="anonymous" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="../../../_static/js/sidebar.js" type="text/javascript"></script>
<script src="../../../_static/js/search.js" type="text/javascript"></script>
<script src="../../../_static/js/navbar.js" type="text/javascript"></script>
<script src="../../../_static/js/clipboard.min.js" type="text/javascript"></script>
<script src="../../../_static/js/copycode.js" type="text/javascript"></script>
<script src="../../../_static/js/page.js" type="text/javascript"></script>
<script src="../../../_static/js/docversion.js" type="text/javascript"></script>
<script type="text/javascript">
$('body').ready(function () {
$('body').css('visibility', 'visible');
});
</script>
</body>
</html>