blob: 1becc27632826b3cba027652a398fb6f255e32ab [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<title>Data Loading API — mxnet documentation</title>
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="../../_static/basic.css" rel="stylesheet" type="text/css">
<link href="../../_static/pygments.css" rel="stylesheet" type="text/css">
<link href="../../_static/mxnet.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: ''
};
</script>
<script src="../../_static/jquery-1.11.1.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://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
<script type="text/javascript"> jQuery(function() { Search.loadIndex("/searchindex.js"); Search.init();}); </script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-96378503-1', 'auto');
ga('send', 'pageview');
</script>
<!-- -->
<!-- <script type="text/javascript" src="../../_static/jquery.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="../../_static/underscore.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="../../_static/doctools.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> -->
<!-- -->
<link href="index.html" rel="up" title="MXNet - Python API">
<link href="optimization.html" rel="next" title="Optimization: initialize and update weights"/>
<link href="kvstore.html" rel="prev" title="KVStore API"/>
<link href="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-icon.png" rel="icon" type="image/png"/>
</link></link></link></head>
<body role="document"><!-- Previous Navbar Layout
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="../../" class="navbar-brand">
<img src="http://data.mxnet.io/theme/mxnet.png">
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul id="navbar" class="navbar navbar-left">
<li> <a href="../../get_started/index.html">Get Started</a> </li>
<li> <a href="../../tutorials/index.html">Tutorials</a> </li>
<li> <a href="../../how_to/index.html">How To</a> </li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Packages <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="../../packages/python/index.html">
Python
</a></li>
<li><a href="../../packages/r/index.html">
R
</a></li>
<li><a href="../../packages/julia/index.html">
Julia
</a></li>
<li><a href="../../packages/c++/index.html">
C++
</a></li>
<li><a href="../../packages/scala/index.html">
Scala
</a></li>
<li><a href="../../packages/perl/index.html">
Perl
</a></li>
</ul>
</li>
<li> <a href="../../system/index.html">System</a> </li>
<li>
<form class="" role="search" action="../../search.html" method="get" autocomplete="off">
<div class="form-group inner-addon left-addon">
<i class="glyphicon glyphicon-search"></i>
<input type="text" name="q" class="form-control" placeholder="Search">
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form> </li>
</ul>
<ul id="navbar" class="navbar navbar-right">
<li> <a href="../../index.html"><span class="flag-icon flag-icon-us"></span></a> </li>
<li> <a href="../..//zh/index.html"><span class="flag-icon flag-icon-cn"></span></a> </li>
</ul>
</div>
</div>
</div>
Previous Navbar Layout End -->
<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="http://data.mxnet.io/theme/mxnet.png"/></a>
</h1>
<nav class="nav-bar" id="main-nav">
<a class="main-nav-link" href="../../get_started/install.html">Install</a>
<a class="main-nav-link" href="../../tutorials/index.html">Tutorials</a>
<a class="main-nav-link" href="../../how_to/index.html">How To</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">API <span class="caret"></span></a>
<ul class="dropdown-menu" id="package-dropdown-menu">
<li><a class="main-nav-link" href="../../api/python/index.html">Python</a></li>
<li><a class="main-nav-link" href="../../api/scala/index.html">Scala</a></li>
<li><a class="main-nav-link" href="../../api/r/index.html">R</a></li>
<li><a class="main-nav-link" href="../../api/julia/index.html">Julia</a></li>
<li><a class="main-nav-link" href="../../api/c++/index.html">C++</a></li>
<li><a class="main-nav-link" href="../../api/perl/index.html">Perl</a></li>
</ul>
</span>
<a class="main-nav-link" href="../../architecture/index.html">Architecture</a>
<!-- <a class="main-nav-link" href="../../community/index.html">Community</a> -->
<a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a>
<span id="dropdown-menu-position-anchor-version" style="position: relative"><a href="#" class="main-nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Versions(master)<span class="caret"></span></a><ul id="package-dropdown-menu" class="dropdown-menu"><li><a class="main-nav-link" href=http://mxnet.incubator.apache.org/test/>v0.10.14</a></li><li><a class="main-nav-link" href=http://mxnet.incubator.apache.org/test/versions/0.10/index.html>0.10</a></li><li><a class="main-nav-link" href=http://mxnet.incubator.apache.org/test/versions/master/index.html>master</a></li></ul></span></nav>
<script> function getRootPath(){ return "../../" } </script>
<div class="burgerIcon dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"></a>
<ul class="dropdown-menu dropdown-menu-right" id="burgerMenu">
<li><a href="../../get_started/install.html">Install</a></li>
<li><a href="../../tutorials/index.html">Tutorials</a></li>
<li><a href="../../how_to/index.html">How To</a></li>
<li class="dropdown-submenu">
<a href="#" tabindex="-1">API</a>
<ul class="dropdown-menu">
<li><a href="../../api/python/index.html" tabindex="-1">Python</a>
</li>
<li><a href="../../api/scala/index.html" tabindex="-1">Scala</a>
</li>
<li><a href="../../api/r/index.html" tabindex="-1">R</a>
</li>
<li><a href="../../api/julia/index.html" tabindex="-1">Julia</a>
</li>
<li><a href="../../api/c++/index.html" tabindex="-1">C++</a>
</li>
<li><a href="../../api/perl/index.html" tabindex="-1">Perl</a>
</li>
</ul>
</li>
<li><a href="../../architecture/index.html">Architecture</a></li>
<li><a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a></li>
<li id="dropdown-menu-position-anchor-version-mobile" class="dropdown-submenu" style="position: relative"><a href="#" tabindex="-1">Versions(master)</a><ul class="dropdown-menu"><li><a tabindex="-1" href=http://mxnet.incubator.apache.org/test/>v0.10.14</a></li><li><a tabindex="-1" href=http://mxnet.incubator.apache.org/test/versions/0.10/index.html>0.10</a></li><li><a tabindex="-1" href=http://mxnet.incubator.apache.org/test/versions/master/index.html>master</a></li></ul></li></ul>
</div>
<div class="plusIcon dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"><span aria-hidden="true" class="glyphicon glyphicon-plus"></span></a>
<ul class="dropdown-menu dropdown-menu-right" id="plusMenu"></ul>
</div>
<div id="search-input-wrap">
<form action="../../search.html" autocomplete="off" class="" method="get" role="search">
<div class="form-group inner-addon left-addon">
<i class="glyphicon glyphicon-search"></i>
<input class="form-control" name="q" placeholder="Search" type="text"/>
</div>
<input name="check_keywords" type="hidden" value="yes">
<input name="area" type="hidden" value="default"/>
</input></form>
<div id="search-preview"></div>
</div>
<div id="searchIcon">
<span aria-hidden="true" class="glyphicon glyphicon-search"></span>
</div>
<!-- <div id="lang-select-wrap"> -->
<!-- <label id="lang-select-label"> -->
<!-- <\!-- <i class="fa fa-globe"></i> -\-> -->
<!-- <span></span> -->
<!-- </label> -->
<!-- <select id="lang-select"> -->
<!-- <option value="en">Eng</option> -->
<!-- <option value="zh">中文</option> -->
<!-- </select> -->
<!-- </div> -->
<!-- <a id="mobile-nav-toggle">
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
</a> -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div aria-label="main navigation" class="sphinxsidebar leftsidebar" role="navigation">
<div class="sphinxsidebarwrapper">
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Python Documents</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="index.html#table-of-contents">Table of contents</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="ndarray.html">NDArray API</a></li>
<li class="toctree-l3"><a class="reference internal" href="symbol.html">Symbol API</a></li>
<li class="toctree-l3"><a class="reference internal" href="module.html">Module API</a></li>
<li class="toctree-l3"><a class="reference internal" href="rnn.html">RNN Cell API</a></li>
<li class="toctree-l3"><a class="reference internal" href="kvstore.html">KVStore API</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="">Data Loading API</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#overview">Overview</a></li>
<li class="toctree-l4"><a class="reference internal" href="#data-iterators">Data iterators</a></li>
<li class="toctree-l4"><a class="reference internal" href="#helper-classes-and-functions">Helper classes and functions</a></li>
<li class="toctree-l4"><a class="reference internal" href="#develop-a-new-iterator">Develop a new iterator</a></li>
<li class="toctree-l4"><a class="reference internal" href="#api-reference">API Reference</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="optimization.html">Optimization: initialize and update weights</a></li>
<li class="toctree-l3"><a class="reference internal" href="callback.html">Callback API</a></li>
<li class="toctree-l3"><a class="reference internal" href="metric.html">Evaluation Metric API</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../r/index.html">R Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../julia/index.html">Julia Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../c++/index.html">C++ Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../scala/index.html">Scala Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../perl/index.html">Perl Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../how_to/index.html">HowTo Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/index.html">System Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tutorials/index.html">Tutorials</a></li>
</ul>
</div>
</div>
<div class="content">
<div class="section" id="data-loading-api">
<span id="data-loading-api"></span><h1>Data Loading API<a class="headerlink" href="#data-loading-api" title="Permalink to this headline"></a></h1>
<div class="section" id="overview">
<span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline"></a></h2>
<p>This document summarizes supported data formats and iterator APIs to read the
data including</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#module-mxnet.io" title="mxnet.io"><code class="xref py py-obj docutils literal"><span class="pre">mxnet.io</span></code></a></td>
<td>Data iterators for common data formats.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#module-mxnet.recordio" title="mxnet.recordio"><code class="xref py py-obj docutils literal"><span class="pre">mxnet.recordio</span></code></a></td>
<td>Read and write for the RecordIO data format.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#module-mxnet.image" title="mxnet.image"><code class="xref py py-obj docutils literal"><span class="pre">mxnet.image</span></code></a></td>
<td>Read individual image files and perform augmentations.</td>
</tr>
</tbody>
</table>
<p>First, let’s see how to write an iterator for a new data format.
The following iterator can be used to train a symbol whose input data variable has
name <code class="docutils literal"><span class="pre">data</span></code> and input label variable has name <code class="docutils literal"><span class="pre">softmax_label</span></code>.
The iterator also provides information about the batch, including the
shapes and name.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">nd_iter</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">NDArrayIter</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">{</span><span class="s1">'data'</span><span class="p">:</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">100</span><span class="p">,</span><span class="mi">10</span><span class="p">))},</span>
<span class="gp">... </span> <span class="n">label</span><span class="o">=</span><span class="p">{</span><span class="s1">'softmax_label'</span><span class="p">:</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">100</span><span class="p">,))},</span>
<span class="gp">... </span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">25</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">nd_iter</span><span class="o">.</span><span class="n">provide_data</span><span class="p">)</span>
<span class="go">[DataDesc[data,(25, 10L),<type 'numpy.float32'>,NCHW]]</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">nd_iter</span><span class="o">.</span><span class="n">provide_label</span><span class="p">)</span>
<span class="go">[DataDesc[softmax_label,(25,),<type 'numpy.float32'>,NCHW]]</span>
</pre></div>
</div>
<p>Let’s see a complete example of how to use data iterator in model training.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">data</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">sym</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="s1">'data'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">label</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">sym</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="s1">'softmax_label'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">fullc</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">sym</span><span class="o">.</span><span class="n">FullyConnected</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">num_hidden</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">loss</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">sym</span><span class="o">.</span><span class="n">SoftmaxOutput</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">mod</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">mod</span><span class="o">.</span><span class="n">Module</span><span class="p">(</span><span class="n">loss</span><span class="p">,</span> <span class="n">data_names</span><span class="o">=</span><span class="p">[</span><span class="s1">'data'</span><span class="p">],</span> <span class="n">label_names</span><span class="o">=</span><span class="p">[</span><span class="s1">'softmax_label'</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="n">data_shapes</span><span class="o">=</span><span class="n">nd_iter</span><span class="o">.</span><span class="n">provide_data</span><span class="p">,</span> <span class="n">label_shapes</span><span class="o">=</span><span class="n">nd_iter</span><span class="o">.</span><span class="n">provide_label</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">mod</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">nd_iter</span><span class="p">,</span> <span class="n">num_epoch</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<p>A detailed tutorial is available at
<a class="reference external" href="http://mxnet.io/tutorials/basic/data.html">Iterators - Loading data</a>.</p>
</div>
<div class="section" id="data-iterators">
<span id="data-iterators"></span><h2>Data iterators<a class="headerlink" href="#data-iterators" 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.io.NDArrayIter" title="mxnet.io.NDArrayIter"><code class="xref py py-obj docutils literal"><span class="pre">io.NDArrayIter</span></code></a></td>
<td>Returns an iterator for <code class="docutils literal"><span class="pre">mx.nd.NDArray</span></code> or <code class="docutils literal"><span class="pre">numpy.ndarray</span></code>.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.io.CSVIter" title="mxnet.io.CSVIter"><code class="xref py py-obj docutils literal"><span class="pre">io.CSVIter</span></code></a></td>
<td>Returns the CSV file iterator.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.io.ImageRecordIter" title="mxnet.io.ImageRecordIter"><code class="xref py py-obj docutils literal"><span class="pre">io.ImageRecordIter</span></code></a></td>
<td>Iterates on image RecordIO files</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.io.ImageRecordUInt8Iter" title="mxnet.io.ImageRecordUInt8Iter"><code class="xref py py-obj docutils literal"><span class="pre">io.ImageRecordUInt8Iter</span></code></a></td>
<td>Iterating on image RecordIO files</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.io.MNISTIter" title="mxnet.io.MNISTIter"><code class="xref py py-obj docutils literal"><span class="pre">io.MNISTIter</span></code></a></td>
<td>Iterating on the MNIST dataset.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.recordio.MXRecordIO" title="mxnet.recordio.MXRecordIO"><code class="xref py py-obj docutils literal"><span class="pre">recordio.MXRecordIO</span></code></a></td>
<td>Reads/writes <cite>RecordIO</cite> data format, supporting sequential read and write.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.recordio.MXIndexedRecordIO" title="mxnet.recordio.MXIndexedRecordIO"><code class="xref py py-obj docutils literal"><span class="pre">recordio.MXIndexedRecordIO</span></code></a></td>
<td>Reads/writes <cite>RecordIO</cite> data format, supporting random access.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.ImageIter" title="mxnet.image.ImageIter"><code class="xref py py-obj docutils literal"><span class="pre">image.ImageIter</span></code></a></td>
<td>Image data iterator with a large number of augmentation choices.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="helper-classes-and-functions">
<span id="helper-classes-and-functions"></span><h2>Helper classes and functions<a class="headerlink" href="#helper-classes-and-functions" title="Permalink to this headline"></a></h2>
<p>Data structures and other iterators provided in the <code class="docutils literal"><span class="pre">mxnet.io</span></code> packages.</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.io.DataDesc" title="mxnet.io.DataDesc"><code class="xref py py-obj docutils literal"><span class="pre">io.DataDesc</span></code></a></td>
<td>DataDesc is used to store name, shape, type and layout information of the data or the label.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.io.DataBatch" title="mxnet.io.DataBatch"><code class="xref py py-obj docutils literal"><span class="pre">io.DataBatch</span></code></a></td>
<td>A data batch.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.io.DataIter" title="mxnet.io.DataIter"><code class="xref py py-obj docutils literal"><span class="pre">io.DataIter</span></code></a></td>
<td>The base class for an MXNet data iterator.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.io.ResizeIter" title="mxnet.io.ResizeIter"><code class="xref py py-obj docutils literal"><span class="pre">io.ResizeIter</span></code></a></td>
<td>Resize a data iterator to a given number of batches.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.io.PrefetchingIter" title="mxnet.io.PrefetchingIter"><code class="xref py py-obj docutils literal"><span class="pre">io.PrefetchingIter</span></code></a></td>
<td>Performs pre-fetch for other data iterators.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.io.MXDataIter" title="mxnet.io.MXDataIter"><code class="xref py py-obj docutils literal"><span class="pre">io.MXDataIter</span></code></a></td>
<td>A python wrapper a C++ data iterator.</td>
</tr>
</tbody>
</table>
<p>A list of image modification functions provided by <code class="docutils literal"><span class="pre">mxnet.image</span></code>.</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.imdecode" title="mxnet.image.imdecode"><code class="xref py py-obj docutils literal"><span class="pre">image.imdecode</span></code></a></td>
<td>Decode an image to an NDArray.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.scale_down" title="mxnet.image.scale_down"><code class="xref py py-obj docutils literal"><span class="pre">image.scale_down</span></code></a></td>
<td>Scales down crop size if it’s larger than image size.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.resize_short" title="mxnet.image.resize_short"><code class="xref py py-obj docutils literal"><span class="pre">image.resize_short</span></code></a></td>
<td>Resizes shorter edge to size.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.fixed_crop" title="mxnet.image.fixed_crop"><code class="xref py py-obj docutils literal"><span class="pre">image.fixed_crop</span></code></a></td>
<td>Crop src at fixed location, and (optionally) resize it to size.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.random_crop" title="mxnet.image.random_crop"><code class="xref py py-obj docutils literal"><span class="pre">image.random_crop</span></code></a></td>
<td>Randomly crop <cite>src</cite> with <cite>size</cite> (width, height).</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.center_crop" title="mxnet.image.center_crop"><code class="xref py py-obj docutils literal"><span class="pre">image.center_crop</span></code></a></td>
<td>Crops the image <cite>src</cite> to the given <cite>size</cite> by trimming on all four sides and preserving the center of the image.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.color_normalize" title="mxnet.image.color_normalize"><code class="xref py py-obj docutils literal"><span class="pre">image.color_normalize</span></code></a></td>
<td>Normalize src with mean and std.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.random_size_crop" title="mxnet.image.random_size_crop"><code class="xref py py-obj docutils literal"><span class="pre">image.random_size_crop</span></code></a></td>
<td>Randomly crop src with size.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.ResizeAug" title="mxnet.image.ResizeAug"><code class="xref py py-obj docutils literal"><span class="pre">image.ResizeAug</span></code></a></td>
<td>Make resize shorter edge to size augmenter.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.RandomCropAug" title="mxnet.image.RandomCropAug"><code class="xref py py-obj docutils literal"><span class="pre">image.RandomCropAug</span></code></a></td>
<td>Make random crop augmenter</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.RandomSizedCropAug" title="mxnet.image.RandomSizedCropAug"><code class="xref py py-obj docutils literal"><span class="pre">image.RandomSizedCropAug</span></code></a></td>
<td>Make random crop with random resizing and random aspect ratio jitter augmenter.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.CenterCropAug" title="mxnet.image.CenterCropAug"><code class="xref py py-obj docutils literal"><span class="pre">image.CenterCropAug</span></code></a></td>
<td>Make center crop augmenter.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.RandomOrderAug" title="mxnet.image.RandomOrderAug"><code class="xref py py-obj docutils literal"><span class="pre">image.RandomOrderAug</span></code></a></td>
<td>Apply list of augmenters in random order</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.ColorJitterAug" title="mxnet.image.ColorJitterAug"><code class="xref py py-obj docutils literal"><span class="pre">image.ColorJitterAug</span></code></a></td>
<td>Apply random brightness, contrast and saturation jitter in random order.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.LightingAug" title="mxnet.image.LightingAug"><code class="xref py py-obj docutils literal"><span class="pre">image.LightingAug</span></code></a></td>
<td>Add PCA based noise.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.ColorNormalizeAug" title="mxnet.image.ColorNormalizeAug"><code class="xref py py-obj docutils literal"><span class="pre">image.ColorNormalizeAug</span></code></a></td>
<td>Mean and std normalization.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.HorizontalFlipAug" title="mxnet.image.HorizontalFlipAug"><code class="xref py py-obj docutils literal"><span class="pre">image.HorizontalFlipAug</span></code></a></td>
<td>Random horizontal flipping.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.image.CastAug" title="mxnet.image.CastAug"><code class="xref py py-obj docutils literal"><span class="pre">image.CastAug</span></code></a></td>
<td>Cast to float32</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.image.CreateAugmenter" title="mxnet.image.CreateAugmenter"><code class="xref py py-obj docutils literal"><span class="pre">image.CreateAugmenter</span></code></a></td>
<td>Creates an augmenter list.</td>
</tr>
</tbody>
</table>
<p>Functions to read and write RecordIO files.</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.recordio.pack" title="mxnet.recordio.pack"><code class="xref py py-obj docutils literal"><span class="pre">recordio.pack</span></code></a></td>
<td>Pack a string into MXImageRecord.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.recordio.unpack" title="mxnet.recordio.unpack"><code class="xref py py-obj docutils literal"><span class="pre">recordio.unpack</span></code></a></td>
<td>Unpack a MXImageRecord to string.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#mxnet.recordio.unpack_img" title="mxnet.recordio.unpack_img"><code class="xref py py-obj docutils literal"><span class="pre">recordio.unpack_img</span></code></a></td>
<td>Unpack a MXImageRecord to image.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#mxnet.recordio.pack_img" title="mxnet.recordio.pack_img"><code class="xref py py-obj docutils literal"><span class="pre">recordio.pack_img</span></code></a></td>
<td>Pack an image into <code class="docutils literal"><span class="pre">MXImageRecord</span></code>.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="develop-a-new-iterator">
<span id="develop-a-new-iterator"></span><h2>Develop a new iterator<a class="headerlink" href="#develop-a-new-iterator" title="Permalink to this headline"></a></h2>
<p>Writing a new data iterator in Python is straightforward. Most MXNet
training/inference programs accept an iterable object with <code class="docutils literal"><span class="pre">provide_data</span></code>
and <code class="docutils literal"><span class="pre">provide_label</span></code> properties.
This <a class="reference external" href="http://mxnet.io/tutorials/basic/data.html">tutorial</a> explains how to
write an iterator from scratch.</p>
<p>The following example demonstrates how to combine
multiple data iterators into a single one. It can be used for multiple
modality training such as image captioning, in which images are read by
<code class="docutils literal"><span class="pre">ImageRecordIter</span></code> while documents are read by <code class="docutils literal"><span class="pre">CSVIter</span></code></p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MultiIter</span><span class="p">:</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iter_list</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">iters</span> <span class="o">=</span> <span class="n">iter_list</span>
<span class="k">def</span> <span class="nf">next</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">batches</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">iters</span><span class="p">]</span>
<span class="k">return</span> <span class="n">DataBatch</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="o">*</span><span class="n">b</span><span class="o">.</span><span class="n">data</span> <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">batches</span><span class="p">],</span>
<span class="n">label</span><span class="o">=</span><span class="p">[</span><span class="o">*</span><span class="n">b</span><span class="o">.</span><span class="n">label</span> <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">batches</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">iters</span><span class="p">:</span>
<span class="n">i</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">provide_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="p">[</span><span class="o">*</span><span class="n">i</span><span class="o">.</span><span class="n">provide_data</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">iters</span><span class="p">]</span>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">provide_label</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="p">[</span><span class="o">*</span><span class="n">i</span><span class="o">.</span><span class="n">provide_label</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">iters</span><span class="p">]</span>
<span class="nb">iter</span> <span class="o">=</span> <span class="n">MultiIter</span><span class="p">([</span><span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">ImageRecordIter</span><span class="p">(</span><span class="s1">'image.rec'</span><span class="p">),</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">CSVIter</span><span class="p">(</span><span class="s1">'txt.csv'</span><span class="p">)])</span>
</pre></div>
</div>
<p>Parsing and performing another pre-processing such as augmentation may be expensive.
If performance is critical, we can implement a data iterator in C++. Refer to
<a class="reference external" href="https://github.com/dmlc/mxnet/tree/master/src/io">src/io</a> for examples.</p>
<div class="section" id="change-batch-layout">
<span id="change-batch-layout"></span><h3>Change batch layout<a class="headerlink" href="#change-batch-layout" title="Permalink to this headline"></a></h3>
<p>By default, the backend engine treats the first dimension of each data and label variable in data
iterators as the batch size (i.e. <code class="docutils literal"><span class="pre">NCHW</span></code> or <code class="docutils literal"><span class="pre">NT</span></code> layout). In order to override the axis for batch size,
the <code class="docutils literal"><span class="pre">provide_data</span></code> (and <code class="docutils literal"><span class="pre">provide_label</span></code> if there is label) properties should include the layouts. This
is especially useful in RNN since <code class="docutils literal"><span class="pre">TNC</span></code> layouts are often more efficient. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="nd">@property</span>
<span class="k">def</span> <span class="nf">provide_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="p">[</span><span class="n">DataDesc</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">'seq_var'</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">seq_length</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">),</span> <span class="n">layout</span><span class="o">=</span><span class="s1">'TN'</span><span class="p">)]</span>
</pre></div>
</div>
<p>The backend engine will recognize the index of <code class="docutils literal"><span class="pre">N</span></code> in the <code class="docutils literal"><span class="pre">layout</span></code> as the axis for batch size.</p>
</div>
</div>
<div class="section" id="api-reference">
<span id="api-reference"></span><h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline"></a></h2>
<script src="../../_static/js/auto_module_index.js" type="text/javascript"></script><span class="target" id="module-mxnet.io"></span><p>Data iterators for common data formats.</p>
<dl class="class">
<dt id="mxnet.io.DataDesc">
<em class="property">class </em><code class="descclassname">mxnet.io.</code><code class="descname">DataDesc</code><a class="headerlink" href="#mxnet.io.DataDesc" title="Permalink to this definition"></a></dt>
<dd><p>DataDesc is used to store name, shape, type and layout
information of the data or the label.</p>
<p>The <cite>layout</cite> describes how the axes in <cite>shape</cite> should be interpreted,
for example for image data setting <cite>layout=NCHW</cite> indicates
that the first axis is number of examples in the batch(N),
C is number of channels, H is the height and W is the width of the image.</p>
<p>For sequential data, by default <cite>layout</cite> is set to <code class="docutils literal"><span class="pre">NTC</span></code>, where
N is number of examples in the batch, T the temporal axis representing time
and C is the number of channels.</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>cls</strong> (<a class="reference internal" href="#mxnet.io.DataDesc" title="mxnet.io.DataDesc"><em>DataDesc</em></a>) – The class.</li>
<li><strong>name</strong> (<em>str</em>) – Data name.</li>
<li><strong>shape</strong> (<em>tuple of int</em>) – Data shape.</li>
<li><strong>dtype</strong> (<em>np.dtype, optional</em>) – Data type.</li>
<li><strong>layout</strong> (<em>str, optional</em>) – Data layout.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="staticmethod">
<dt id="mxnet.io.DataDesc.get_batch_axis">
<em class="property">static </em><code class="descname">get_batch_axis</code><span class="sig-paren">(</span><em>layout</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataDesc.get_batch_axis" title="Permalink to this definition"></a></dt>
<dd><p>Get the dimension that corresponds to the batch size.</p>
<p>When data parallelism is used, the data will be automatically split and
concatenated along the batch-size dimension. Axis can be -1, which means
the whole array will be copied for each data-parallelism device.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>layout</strong> (<em>str</em>) – layout string. For example, “NCHW”.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">An axis indicating the batch_size dimension.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="staticmethod">
<dt id="mxnet.io.DataDesc.get_list">
<em class="property">static </em><code class="descname">get_list</code><span class="sig-paren">(</span><em>shapes</em>, <em>types</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataDesc.get_list" title="Permalink to this definition"></a></dt>
<dd><p>Get DataDesc list from attribute lists.</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>shapes</strong> (<em>a tuple of (name, shape)</em>) – </li>
<li><strong>types</strong> (<em>a tuple of (name, type)</em>) – </li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.io.DataBatch">
<em class="property">class </em><code class="descclassname">mxnet.io.</code><code class="descname">DataBatch</code><span class="sig-paren">(</span><em>data</em>, <em>label=None</em>, <em>pad=None</em>, <em>index=None</em>, <em>bucket_key=None</em>, <em>provide_data=None</em>, <em>provide_label=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataBatch" title="Permalink to this definition"></a></dt>
<dd><p>A data batch.</p>
<p>MXNet’s data iterator returns a batch of data for each <cite>next</cite> call.
This data contains <cite>batch_size</cite> number of examples.</p>
<p>If the input data consists of images, then shape of these images depend on
the <cite>layout</cite> attribute of <cite>DataDesc</cite> object in <cite>provide_data</cite> parameter.</p>
<p>If <cite>layout</cite> is set to ‘NCHW’ then, images should be stored in a 4-D matrix
of shape <code class="docutils literal"><span class="pre">(batch_size,</span> <span class="pre">num_channel,</span> <span class="pre">height,</span> <span class="pre">width)</span></code>.
If <cite>layout</cite> is set to ‘NHWC’ then, images should be stored in a 4-D matrix
of shape <code class="docutils literal"><span class="pre">(batch_size,</span> <span class="pre">height,</span> <span class="pre">width,</span> <span class="pre">num_channel)</span></code>.
The channels are often in RGB order.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>data</strong> (list of <cite>NDArray</cite>, each array containing <cite>batch_size</cite> examples.) – A list of input data.</li>
<li><strong>label</strong> (list of <cite>NDArray</cite>, each array often containing a 1-dimensional array. optional) – A list of input labels.</li>
<li><strong>pad</strong> (<em>int, optional</em>) – The number of examples padded at the end of a batch. It is used when the
total number of examples read is not divisible by the <cite>batch_size</cite>.
These extra padded examples are ignored in prediction.</li>
<li><strong>index</strong> (<em>numpy.array, optional</em>) – The example indices in this batch.</li>
<li><strong>bucket_key</strong> (<em>int, optional</em>) – The bucket key, used for bucketing module.</li>
<li><strong>provide_data</strong> (list of <cite>DataDesc</cite>, optional) – A list of <cite>DataDesc</cite> objects. <cite>DataDesc</cite> is used to store
name, shape, type and layout information of the data.
The <em>i</em>-th element describes the name and shape of <code class="docutils literal"><span class="pre">data[i]</span></code>.</li>
<li><strong>provide_label</strong> (list of <cite>DataDesc</cite>, optional) – A list of <cite>DataDesc</cite> objects. <cite>DataDesc</cite> is used to store
name, shape, type and layout information of the label.
The <em>i</em>-th element describes the name and shape of <code class="docutils literal"><span class="pre">label[i]</span></code>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="class">
<dt id="mxnet.io.DataIter">
<em class="property">class </em><code class="descclassname">mxnet.io.</code><code class="descname">DataIter</code><span class="sig-paren">(</span><em>batch_size=0</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataIter" title="Permalink to this definition"></a></dt>
<dd><p>The base class for an MXNet data iterator.</p>
<p>All I/O in MXNet is handled by specializations of this class. Data iterators
in MXNet are similar to standard-iterators in Python. On each call to <cite>next</cite>
they return a <cite>DataBatch</cite> which represents the next batch of data. When
there is no more data to return, it raises a <cite>StopIteration</cite> exception.</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>batch_size</strong> (<em>int, optional</em>) – The batch size, namely the number of items in the batch.</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#mxnet.io.NDArrayIter" title="mxnet.io.NDArrayIter"><code class="xref py py-class docutils literal"><span class="pre">NDArrayIter</span></code></a></dt>
<dd>Data-iterator for MXNet NDArray or numpy-ndarray objects.</dd>
<dt><a class="reference internal" href="#mxnet.io.CSVIter" title="mxnet.io.CSVIter"><code class="xref py py-class docutils literal"><span class="pre">CSVIter</span></code></a></dt>
<dd>Data-iterator for csv data.</dd>
<dt><code class="xref py py-class docutils literal"><span class="pre">ImageIter</span></code></dt>
<dd>Data-iterator for images.</dd>
</dl>
</div>
<dl class="method">
<dt id="mxnet.io.DataIter.reset">
<code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataIter.reset" title="Permalink to this definition"></a></dt>
<dd><p>Reset the iterator to the begin of the data.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.io.DataIter.next">
<code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataIter.next" title="Permalink to this definition"></a></dt>
<dd><p>Get next data batch from iterator.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The data of next batch.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference internal" href="#mxnet.io.DataBatch" title="mxnet.io.DataBatch">DataBatch</a></td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><code class="xref py py-exc docutils literal"><span class="pre">StopIteration</span></code>
If the end of the data is reached.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.io.DataIter.iter_next">
<code class="descname">iter_next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataIter.iter_next" title="Permalink to this definition"></a></dt>
<dd><p>Move to the next batch.</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">Whether the move is successful.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">boolean</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.io.DataIter.getdata">
<code class="descname">getdata</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataIter.getdata" title="Permalink to this definition"></a></dt>
<dd><p>Get data of current batch.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The data of the current batch.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">list of NDArray</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.io.DataIter.getlabel">
<code class="descname">getlabel</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataIter.getlabel" title="Permalink to this definition"></a></dt>
<dd><p>Get label of the current batch.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The label of the current batch.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">list of NDArray</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.io.DataIter.getindex">
<code class="descname">getindex</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataIter.getindex" title="Permalink to this definition"></a></dt>
<dd><p>Get index of the current batch.</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"><strong>index</strong>
The indices of examples in the current batch.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">numpy.array</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.io.DataIter.getpad">
<code class="descname">getpad</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.DataIter.getpad" title="Permalink to this definition"></a></dt>
<dd><p>Get the number of padding examples in the current batch.</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">Number of padding examples in the current batch.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.io.ResizeIter">
<em class="property">class </em><code class="descclassname">mxnet.io.</code><code class="descname">ResizeIter</code><span class="sig-paren">(</span><em>data_iter</em>, <em>size</em>, <em>reset_internal=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.ResizeIter" title="Permalink to this definition"></a></dt>
<dd><p>Resize a data iterator to a given number of batches.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>data_iter</strong> (<a class="reference internal" href="#mxnet.io.DataIter" title="mxnet.io.DataIter"><em>DataIter</em></a>) – The data iterator to be resized.</li>
<li><strong>size</strong> (<em>int</em>) – The number of batches per epoch to resize to.</li>
<li><strong>reset_internal</strong> (<em>bool</em>) – Whether to reset internal iterator on ResizeIter.reset.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">nd_iter</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">NDArrayIter</span><span class="p">(</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">100</span><span class="p">,</span><span class="mi">10</span><span class="p">)),</span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">25</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">resize_iter</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">ResizeIter</span><span class="p">(</span><span class="n">nd_iter</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">batch</span> <span class="ow">in</span> <span class="n">resize_iter</span><span class="p">:</span>
<span class="gp">... </span> <span class="k">print</span><span class="p">(</span><span class="n">batch</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
<span class="go">[<NDArray 25x10 @cpu(0)>]</span>
<span class="go">[<NDArray 25x10 @cpu(0)>]</span>
</pre></div>
</div>
</dd></dl>
<dl class="class">
<dt id="mxnet.io.PrefetchingIter">
<em class="property">class </em><code class="descclassname">mxnet.io.</code><code class="descname">PrefetchingIter</code><span class="sig-paren">(</span><em>iters</em>, <em>rename_data=None</em>, <em>rename_label=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.PrefetchingIter" title="Permalink to this definition"></a></dt>
<dd><p>Performs pre-fetch for other data iterators.</p>
<p>This iterator will create another thread to perform <code class="docutils literal"><span class="pre">iter_next</span></code> and then
store the data in memory. It potentially accelerates the data read, at the
cost of more memory usage.</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>iters</strong> (<em>DataIter or list of DataIter</em>) – The data iterators to be pre-fetched.</li>
<li><strong>rename_data</strong> (<em>None or list of dict</em>) – The <em>i</em>-th element is a renaming map for the <em>i</em>-th iter, in the form of
{‘original_name’ : ‘new_name’}. Should have one entry for each entry
in iter[i].provide_data.</li>
<li><strong>rename_label</strong> (<em>None or list of dict</em>) – Similar to <code class="docutils literal"><span class="pre">rename_data</span></code>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">iter1</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">NDArrayIter</span><span class="p">({</span><span class="s1">'data'</span><span class="p">:</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">100</span><span class="p">,</span><span class="mi">10</span><span class="p">))},</span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">25</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">iter2</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">NDArrayIter</span><span class="p">({</span><span class="s1">'data'</span><span class="p">:</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">100</span><span class="p">,</span><span class="mi">10</span><span class="p">))},</span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">25</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">piter</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">PrefetchingIter</span><span class="p">([</span><span class="n">iter1</span><span class="p">,</span> <span class="n">iter2</span><span class="p">],</span>
<span class="gp">... </span> <span class="n">rename_data</span><span class="o">=</span><span class="p">[{</span><span class="s1">'data'</span><span class="p">:</span> <span class="s1">'data_1'</span><span class="p">},</span> <span class="p">{</span><span class="s1">'data'</span><span class="p">:</span> <span class="s1">'data_2'</span><span class="p">}])</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">piter</span><span class="o">.</span><span class="n">provide_data</span><span class="p">)</span>
<span class="go">[DataDesc[data_1,(25, 10L),<type 'numpy.float32'>,NCHW],</span>
<span class="go"> DataDesc[data_2,(25, 10L),<type 'numpy.float32'>,NCHW]]</span>
</pre></div>
</div>
</dd></dl>
<dl class="class">
<dt id="mxnet.io.NDArrayIter">
<em class="property">class </em><code class="descclassname">mxnet.io.</code><code class="descname">NDArrayIter</code><span class="sig-paren">(</span><em>data</em>, <em>label=None</em>, <em>batch_size=1</em>, <em>shuffle=False</em>, <em>last_batch_handle='pad'</em>, <em>data_name='data'</em>, <em>label_name='softmax_label'</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.NDArrayIter" title="Permalink to this definition"></a></dt>
<dd><p>Returns an iterator for <code class="docutils literal"><span class="pre">mx.nd.NDArray</span></code> or <code class="docutils literal"><span class="pre">numpy.ndarray</span></code>.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="mi">10</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">labels</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">([</span><span class="mi">10</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">dataiter</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">NDArrayIter</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="bp">True</span><span class="p">,</span> <span class="n">last_batch_handle</span><span class="o">=</span><span class="s1">'discard'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">batch</span> <span class="ow">in</span> <span class="n">dataiter</span><span class="p">:</span>
<span class="gp">... </span> <span class="k">print</span> <span class="n">batch</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">asnumpy</span><span class="p">()</span>
<span class="gp">... </span> <span class="n">batch</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span>
<span class="gp">...</span>
<span class="go">[[[ 36. 37.]</span>
<span class="go"> [ 38. 39.]]</span>
<span class="go"> [[ 16. 17.]</span>
<span class="go"> [ 18. 19.]]</span>
<span class="go"> [[ 12. 13.]</span>
<span class="go"> [ 14. 15.]]]</span>
<span class="go">(3L, 2L, 2L)</span>
<span class="go">[[[ 32. 33.]</span>
<span class="go"> [ 34. 35.]]</span>
<span class="go"> [[ 4. 5.]</span>
<span class="go"> [ 6. 7.]]</span>
<span class="go"> [[ 24. 25.]</span>
<span class="go"> [ 26. 27.]]]</span>
<span class="go">(3L, 2L, 2L)</span>
<span class="go">[[[ 8. 9.]</span>
<span class="go"> [ 10. 11.]]</span>
<span class="go"> [[ 20. 21.]</span>
<span class="go"> [ 22. 23.]]</span>
<span class="go"> [[ 28. 29.]</span>
<span class="go"> [ 30. 31.]]]</span>
<span class="go">(3L, 2L, 2L)</span>
<span class="gp">>>> </span><span class="n">dataiter</span><span class="o">.</span><span class="n">provide_data</span> <span class="c1"># Returns a list of `DataDesc`</span>
<span class="go">[DataDesc[data,(3, 2L, 2L),<type 'numpy.float32'>,NCHW]]</span>
<span class="gp">>>> </span><span class="n">dataiter</span><span class="o">.</span><span class="n">provide_label</span> <span class="c1"># Returns a list of `DataDesc`</span>
<span class="go">[DataDesc[softmax_label,(3, 1L),<type 'numpy.float32'>,NCHW]]</span>
</pre></div>
</div>
<p>In the above example, data is shuffled as <cite>shuffle</cite> parameter is set to <cite>True</cite>
and remaining examples are discarded as <cite>last_batch_handle</cite> parameter is set to <cite>discard</cite>.</p>
<p>Usage of <cite>last_batch_handle</cite> parameter:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dataiter</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">NDArrayIter</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="bp">True</span><span class="p">,</span> <span class="n">last_batch_handle</span><span class="o">=</span><span class="s1">'pad'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">batchidx</span> <span class="o">=</span> <span class="mi">0</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">batch</span> <span class="ow">in</span> <span class="n">dataiter</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">batchidx</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">batchidx</span> <span class="c1"># Padding added after the examples read are over. So, 10/3+1 batches are created.</span>
<span class="go">4</span>
<span class="gp">>>> </span><span class="n">dataiter</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">NDArrayIter</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="bp">True</span><span class="p">,</span> <span class="n">last_batch_handle</span><span class="o">=</span><span class="s1">'discard'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">batchidx</span> <span class="o">=</span> <span class="mi">0</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">batch</span> <span class="ow">in</span> <span class="n">dataiter</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">batchidx</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">batchidx</span> <span class="c1"># Remaining examples are discarded. So, 10/3 batches are created.</span>
<span class="go">3</span>
</pre></div>
</div>
<p><cite>NDArrayIter</cite> also supports multiple input and labels.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'data1'</span><span class="p">:</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">10</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="s1">'data2'</span><span class="p">:</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">20</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">label</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'label1'</span><span class="p">:</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">1</span><span class="p">)),</span> <span class="s1">'label2'</span><span class="p">:</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><span class="mi">1</span><span class="p">))}</span>
<span class="gp">>>> </span><span class="n">dataiter</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">NDArrayIter</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="mi">3</span><span class="p">,</span> <span class="bp">True</span><span class="p">,</span> <span class="n">last_batch_handle</span><span class="o">=</span><span class="s1">'discard'</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>data</strong> (<em>array or list of array or dict of string to array</em>) – The input data.</li>
<li><strong>label</strong> (<em>array or list of array or dict of string to array, optional</em>) – The input label.</li>
<li><strong>batch_size</strong> (<em>int</em>) – Batch size of data.</li>
<li><strong>shuffle</strong> (<em>bool, optional</em>) – Whether to shuffle the data.</li>
<li><strong>last_batch_handle</strong> (<em>str, optional</em>) – How to handle the last batch. This parameter can be ‘pad’, ‘discard’ or
‘roll_over’. ‘roll_over’ is intended for training and can cause problems
if used for prediction.</li>
<li><strong>data_name</strong> (<em>str, optional</em>) – The data name.</li>
<li><strong>label_name</strong> (<em>str, optional</em>) – The label name.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="mxnet.io.NDArrayIter.provide_data">
<code class="descname">provide_data</code><a class="headerlink" href="#mxnet.io.NDArrayIter.provide_data" title="Permalink to this definition"></a></dt>
<dd><p>The name and shape of data provided by this iterator.</p>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.io.NDArrayIter.provide_label">
<code class="descname">provide_label</code><a class="headerlink" href="#mxnet.io.NDArrayIter.provide_label" title="Permalink to this definition"></a></dt>
<dd><p>The name and shape of label provided by this iterator.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.io.NDArrayIter.hard_reset">
<code class="descname">hard_reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.NDArrayIter.hard_reset" title="Permalink to this definition"></a></dt>
<dd><p>Ignore roll over data and set to start.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.io.MXDataIter">
<em class="property">class </em><code class="descclassname">mxnet.io.</code><code class="descname">MXDataIter</code><span class="sig-paren">(</span><em>handle</em>, <em>data_name='data'</em>, <em>label_name='softmax_label'</em>, <em>**_</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.MXDataIter" title="Permalink to this definition"></a></dt>
<dd><p>A python wrapper a C++ data iterator.</p>
<p>This iterator is the Python wrapper to all native C++ data iterators, such
as <cite>CSVIter, `ImageRecordIter</cite>, <cite>MNISTIter</cite>, etc. When initializing
<cite>CSVIter</cite> for example, you will get an <cite>MXDataIter</cite> instance to use in your
Python code. Calls to <cite>next</cite>, <cite>reset</cite>, etc will be delegated to the
underlying C++ data iterators.</p>
<p>Usually you don’t need to interact with <cite>MXDataIter</cite> directly unless you are
implementing your own data iterators in C++. To do that, please refer to
examples under the <cite>src/io</cite> folder.</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>handle</strong> (<em>DataIterHandle, required</em>) – The handle to the underlying C++ Data Iterator.</li>
<li><strong>data_name</strong> (<em>str, optional</em>) – Data name. Default to “data”.</li>
<li><strong>label_name</strong> (<em>str, optional</em>) – Label name. Default to “softmax_label”.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">src/io : The underlying C++ data iterator implementation, e.g., <cite>CSVIter</cite>.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.io.CSVIter">
<code class="descclassname">mxnet.io.</code><code class="descname">CSVIter</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.CSVIter" title="Permalink to this definition"></a></dt>
<dd><p>Returns the CSV file iterator.</p>
<p>In this function, the <cite>data_shape</cite> parameter is used to set the shape of each line of the input data.
If a row in an input file is <cite>1,2,3,4,5,6`</cite> and <cite>data_shape</cite> is (3,2), that row
will be reshaped, yielding the array [[1,2],[3,4],[5,6]] of shape (3,2).</p>
<p>By default, the <cite>CSVIter</cite> has <cite>round_batch</cite> parameter set to <code class="docutils literal"><span class="pre">True</span></code>. So, if <cite>batch_size</cite>
is 3 and there are 4 total rows in CSV file, 2 more examples
are consumed at the first round. If <cite>reset</cite> function is called after first round,
the call is ignored and remaining examples are returned in the second round.</p>
<p>If one wants all the instances in the second round after calling <cite>reset</cite>, make sure
to set <cite>round_batch</cite> to False.</p>
<p>If <code class="docutils literal"><span class="pre">data_csv</span> <span class="pre">=</span> <span class="pre">'data/'</span></code> is set, then all the files in this directory will be read.</p>
<p>Examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span>// Contents of CSV file ``data/data.csv``.
1,2,3
2,3,4
3,4,5
4,5,6
// Creates a `CSVIter` with `batch_size`=2 and default `round_batch`=True.
CSVIter = mx.io.CSVIter(data_csv = 'data/data.csv', data_shape = (3,),
batch_size = 2)
// Two batches read from the above iterator are as follows:
[[ 1. 2. 3.]
[ 2. 3. 4.]]
[[ 3. 4. 5.]
[ 4. 5. 6.]]
// Creates a `CSVIter` with default `round_batch` set to True.
CSVIter = mx.io.CSVIter(data_csv = 'data/data.csv', data_shape = (3,),
batch_size = 3)
// Two batches read from the above iterator in the first pass are as follows:
[[1. 2. 3.]
[2. 3. 4.]
[3. 4. 5.]]
[[4. 5. 6.]
[1. 2. 3.]
[2. 3. 4.]]
// Now, `reset` method is called.
CSVIter.reset()
// Batch read from the above iterator in the second pass is as follows:
[[ 3. 4. 5.]
[ 4. 5. 6.]
[ 1. 2. 3.]]
// Creates a `CSVIter` with `round_batch`=False.
CSVIter = mx.io.CSVIter(data_csv = 'data/data.csv', data_shape = (3,),
batch_size = 3, round_batch=False)
// Contents of two batches read from the above iterator in both passes, after calling
// `reset` method before second pass, is as follows:
[[1. 2. 3.]
[2. 3. 4.]
[3. 4. 5.]]
[[4. 5. 6.]
[2. 3. 4.]
[3. 4. 5.]]
</pre></div>
</div>
<p>Defined in src/io/iter_csv.cc:L202</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_csv</strong> (<em>string, required</em>) – The input CSV file or a directory path.</li>
<li><strong>data_shape</strong> (<em>Shape(tuple), required</em>) – The shape of one example.</li>
<li><strong>label_csv</strong> (<em>string, optional, default='NULL'</em>) – The input CSV file or a directory path. If NULL, all labels will be returned as 0.</li>
<li><strong>label_shape</strong> (<em>Shape(tuple), optional, default=(1,)</em>) – The shape of one label.</li>
<li><strong>batch_size</strong> (<em>int (non-negative), required</em>) – Batch size.</li>
<li><strong>round_batch</strong> (<em>boolean, optional, default=True</em>) – Whether to use round robin to handle overflow batch or not.</li>
<li><strong>prefetch_buffer</strong> (<em>long (non-negative), optional, default=4</em>) – Maximum number of batches to prefetch.</li>
<li><strong>dtype</strong> (<em>{None, 'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='None'</em>) – Output data type. <code class="docutils literal"><span class="pre">None</span></code> means no change.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The result iterator.</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.io.MXDataIter" title="mxnet.io.MXDataIter">MXDataIter</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.io.ImageDetRecordIter">
<code class="descclassname">mxnet.io.</code><code class="descname">ImageDetRecordIter</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.ImageDetRecordIter" title="Permalink to this definition"></a></dt>
<dd><p>Create iterator for image detection dataset packed in recordio.</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>path_imglist</strong> (<em>string, optional, default=''</em>) – Dataset Param: Path to image list.</li>
<li><strong>path_imgrec</strong> (<em>string, optional, default='./data/imgrec.rec'</em>) – Dataset Param: Path to image record file.</li>
<li><strong>aug_seq</strong> (<em>string, optional, default='det_aug_default'</em>) – Augmentation Param: the augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters. Make sure you don’t use normal augmenters for detection tasks.</li>
<li><strong>label_width</strong> (<em>int, optional, default='-1'</em>) – Dataset Param: How many labels for an image, -1 for variable label size.</li>
<li><strong>data_shape</strong> (<em>Shape(tuple), required</em>) – Dataset Param: Shape of each instance generated by the DataIter.</li>
<li><strong>preprocess_threads</strong> (<em>int, optional, default='4'</em>) – Backend Param: Number of thread to do preprocessing.</li>
<li><strong>verbose</strong> (<em>boolean, optional, default=True</em>) – Auxiliary Param: Whether to output parser information.</li>
<li><strong>num_parts</strong> (<em>int, optional, default='1'</em>) – partition the data into multiple parts</li>
<li><strong>part_index</strong> (<em>int, optional, default='0'</em>) – the index of the part will read</li>
<li><strong>shuffle_chunk_size</strong> (<em>long (non-negative), optional, default=0</em>) – the size(MB) of the shuffle chunk, used with shuffle=True, it can enable global shuffling</li>
<li><strong>shuffle_chunk_seed</strong> (<em>int, optional, default='0'</em>) – the seed for chunk shuffling</li>
<li><strong>label_pad_width</strong> (<em>int, optional, default='0'</em>) – pad output label width if set larger than 0, -1 for auto estimate</li>
<li><strong>label_pad_value</strong> (<em>float, optional, default=-1</em>) – label padding value if enabled</li>
<li><strong>shuffle</strong> (<em>boolean, optional, default=False</em>) – Augmentation Param: Whether to shuffle data.</li>
<li><strong>seed</strong> (<em>int, optional, default='0'</em>) – Augmentation Param: Random Seed.</li>
<li><strong>batch_size</strong> (<em>int (non-negative), required</em>) – Batch size.</li>
<li><strong>round_batch</strong> (<em>boolean, optional, default=True</em>) – Whether to use round robin to handle overflow batch or not.</li>
<li><strong>prefetch_buffer</strong> (<em>long (non-negative), optional, default=4</em>) – Maximum number of batches to prefetch.</li>
<li><strong>dtype</strong> (<em>{None, 'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='None'</em>) – Output data type. <code class="docutils literal"><span class="pre">None</span></code> means no change.</li>
<li><strong>resize</strong> (<em>int, optional, default='-1'</em>) – Augmentation Param: scale shorter edge to size before applying other augmentations, -1 to disable.</li>
<li><strong>rand_crop_prob</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Probability of random cropping, <= 0 to disable</li>
<li><strong>min_crop_scales</strong> (<em>, optional, default=(0,)</em>) – Augmentation Param: Min crop scales.</li>
<li><strong>max_crop_scales</strong> (<em>, optional, default=(1,)</em>) – Augmentation Param: Max crop scales.</li>
<li><strong>min_crop_aspect_ratios</strong> (<em>, optional, default=(1,)</em>) – Augmentation Param: Min crop aspect ratios.</li>
<li><strong>max_crop_aspect_ratios</strong> (<em>, optional, default=(1,)</em>) – Augmentation Param: Max crop aspect ratios.</li>
<li><strong>min_crop_overlaps</strong> (<em>, optional, default=(0,)</em>) – Augmentation Param: Minimum crop IOU between crop_box and ground-truths.</li>
<li><strong>max_crop_overlaps</strong> (<em>, optional, default=(1,)</em>) – Augmentation Param: Maximum crop IOU between crop_box and ground-truth.</li>
<li><strong>min_crop_sample_coverages</strong> (<em>, optional, default=(0,)</em>) – Augmentation Param: Minimum ratio of intersect/crop_area between crop box and ground-truths.</li>
<li><strong>max_crop_sample_coverages</strong> (<em>, optional, default=(1,)</em>) – Augmentation Param: Maximum ratio of intersect/crop_area between crop box and ground-truths.</li>
<li><strong>min_crop_object_coverages</strong> (<em>, optional, default=(0,)</em>) – Augmentation Param: Minimum ratio of intersect/gt_area between crop box and ground-truths.</li>
<li><strong>max_crop_object_coverages</strong> (<em>, optional, default=(1,)</em>) – Augmentation Param: Maximum ratio of intersect/gt_area between crop box and ground-truths.</li>
<li><strong>num_crop_sampler</strong> (<em>int, optional, default='1'</em>) – Augmentation Param: Number of crop samplers.</li>
<li><strong>crop_emit_mode</strong> (<em>{'center', 'overlap'},optional, default='center'</em>) – Augmentation Param: Emition mode for invalid ground-truths after crop. center: emit if centroid of object is out of crop region; overlap: emit if overlap is less than emit_overlap_thresh.</li>
<li><strong>emit_overlap_thresh</strong> (<em>float, optional, default=0.3</em>) – Augmentation Param: Emit overlap thresh for emit mode overlap only.</li>
<li><strong>max_crop_trials</strong> (<em>Shape(tuple), optional, default=(25,)</em>) – Augmentation Param: Skip cropping if fail crop trail count exceeds this number.</li>
<li><strong>rand_pad_prob</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Probability for random padding.</li>
<li><strong>max_pad_scale</strong> (<em>float, optional, default=1</em>) – Augmentation Param: Maximum padding scale.</li>
<li><strong>max_random_hue</strong> (<em>int, optional, default='0'</em>) – Augmentation Param: Maximum random value of H channel in HSL color space.</li>
<li><strong>random_hue_prob</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Probability to apply random hue.</li>
<li><strong>max_random_saturation</strong> (<em>int, optional, default='0'</em>) – Augmentation Param: Maximum random value of S channel in HSL color space.</li>
<li><strong>random_saturation_prob</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Probability to apply random saturation.</li>
<li><strong>max_random_illumination</strong> (<em>int, optional, default='0'</em>) – Augmentation Param: Maximum random value of L channel in HSL color space.</li>
<li><strong>random_illumination_prob</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Probability to apply random illumination.</li>
<li><strong>max_random_contrast</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Maximum random value of delta contrast.</li>
<li><strong>random_contrast_prob</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Probability to apply random contrast.</li>
<li><strong>rand_mirror_prob</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Probability to apply horizontal flip aka. mirror.</li>
<li><strong>fill_value</strong> (<em>int, optional, default='127'</em>) – Augmentation Param: Filled color value while padding.</li>
<li><strong>inter_method</strong> (<em>int, optional, default='1'</em>) – Augmentation Param: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.</li>
<li><strong>resize_mode</strong> (<em>{'fit', 'force', 'shrink'},optional, default='force'</em>) – Augmentation Param: How image data fit in data_shape. force: force reshape to data_shape regardless of aspect ratio; shrink: ensure each side fit in data_shape, preserve aspect ratio; fit: fit image to data_shape, preserve ratio, will upscale if applicable.</li>
<li><strong>mean_img</strong> (<em>string, optional, default=''</em>) – Augmentation Param: Mean Image to be subtracted.</li>
<li><strong>mean_r</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Mean value on R channel.</li>
<li><strong>mean_g</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Mean value on G channel.</li>
<li><strong>mean_b</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Mean value on B channel.</li>
<li><strong>mean_a</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Mean value on Alpha channel.</li>
<li><strong>std_r</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Standard deviation on R channel.</li>
<li><strong>std_g</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Standard deviation on G channel.</li>
<li><strong>std_b</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Standard deviation on B channel.</li>
<li><strong>std_a</strong> (<em>float, optional, default=0</em>) – Augmentation Param: Standard deviation on Alpha channel.</li>
<li><strong>scale</strong> (<em>float, optional, default=1</em>) – Augmentation Param: Scale in color space.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The result iterator.</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.io.MXDataIter" title="mxnet.io.MXDataIter">MXDataIter</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.io.ImageRecordIter">
<code class="descclassname">mxnet.io.</code><code class="descname">ImageRecordIter</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.ImageRecordIter" title="Permalink to this definition"></a></dt>
<dd><p>Iterates on image RecordIO files</p>
<p>Reads batches of images from .rec RecordIO files. One can use <code class="docutils literal"><span class="pre">im2rec.py</span></code> tool
(in tools/) to pack raw image files into RecordIO files. This iterator is less
flexible to customization but is fast and has lot of language bindings. To
iterate over raw images directly use <code class="docutils literal"><span class="pre">ImageIter</span></code> instead (in Python).</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data_iter</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">ImageRecordIter</span><span class="p">(</span>
<span class="n">path_imgrec</span><span class="o">=</span><span class="s2">"./sample.rec"</span><span class="p">,</span> <span class="c1"># The target record file.</span>
<span class="n">data_shape</span><span class="o">=</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">227</span><span class="p">,</span> <span class="mi">227</span><span class="p">),</span> <span class="c1"># Output data shape; 227x227 region will be cropped from the original image.</span>
<span class="n">batch_size</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="c1"># Number of items per batch.</span>
<span class="n">resize</span><span class="o">=</span><span class="mi">256</span> <span class="c1"># Resize the shorter edge to 256 before cropping.</span>
<span class="c1"># You can specify more augmentation options. Use help(mx.io.ImageRecordIter) to see all the options.</span>
<span class="p">)</span>
<span class="c1"># You can now use the data_iter to access batches of images.</span>
<span class="n">batch</span> <span class="o">=</span> <span class="n">data_iter</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="c1"># first batch.</span>
<span class="n">images</span> <span class="o">=</span> <span class="n">batch</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="c1"># This will contain 4 (=batch_size) images each of 3x227x227.</span>
<span class="c1"># process the images</span>
<span class="o">...</span>
<span class="n">data_iter</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span> <span class="c1"># To restart the iterator from the beginning.</span>
</pre></div>
</div>
<p>Defined in src/io/iter_image_recordio_2.cc:L583</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>path_imglist</strong> (<em>string, optional, default=''</em>) – Path to the image list (.lst) file. Generally created with tools/im2rec.py. Format (Tab separated): <index of record> <one or more labels> <relative path from root folder>.</li>
<li><strong>path_imgrec</strong> (<em>string, optional, default=''</em>) – Path to the image RecordIO (.rec) file or a directory path. Created with tools/im2rec.py.</li>
<li><strong>aug_seq</strong> (<em>string, optional, default='aug_default'</em>) – The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.</li>
<li><strong>label_width</strong> (<em>int, optional, default='1'</em>) – The number of labels per image.</li>
<li><strong>data_shape</strong> (<em>Shape(tuple), required</em>) – The shape of one output image in (channels, height, width) format.</li>
<li><strong>preprocess_threads</strong> (<em>int, optional, default='4'</em>) – The number of threads to do preprocessing.</li>
<li><strong>verbose</strong> (<em>boolean, optional, default=True</em>) – If or not output verbose information.</li>
<li><strong>num_parts</strong> (<em>int, optional, default='1'</em>) – Virtually partition the data into these many parts.</li>
<li><strong>part_index</strong> (<em>int, optional, default='0'</em>) – The <em>i</em>-th virtual partition to be read.</li>
<li><strong>shuffle_chunk_size</strong> (<em>long (non-negative), optional, default=0</em>) – The data shuffle buffer size in MB. Only valid if shuffle is true.</li>
<li><strong>shuffle_chunk_seed</strong> (<em>int, optional, default='0'</em>) – The random seed for shuffling</li>
<li><strong>shuffle</strong> (<em>boolean, optional, default=False</em>) – Whether to shuffle data randomly or not.</li>
<li><strong>seed</strong> (<em>int, optional, default='0'</em>) – The random seed.</li>
<li><strong>batch_size</strong> (<em>int (non-negative), required</em>) – Batch size.</li>
<li><strong>round_batch</strong> (<em>boolean, optional, default=True</em>) – Whether to use round robin to handle overflow batch or not.</li>
<li><strong>prefetch_buffer</strong> (<em>long (non-negative), optional, default=4</em>) – Maximum number of batches to prefetch.</li>
<li><strong>dtype</strong> (<em>{None, 'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='None'</em>) – Output data type. <code class="docutils literal"><span class="pre">None</span></code> means no change.</li>
<li><strong>resize</strong> (<em>int, optional, default='-1'</em>) – Down scale the shorter edge to a new size before applying other augmentations.</li>
<li><strong>rand_crop</strong> (<em>boolean, optional, default=False</em>) – If or not randomly crop the image</li>
<li><strong>max_rotate_angle</strong> (<em>int, optional, default='0'</em>) – Rotate by a random degree in <code class="docutils literal"><span class="pre">[-v,</span> <span class="pre">v]</span></code></li>
<li><strong>max_aspect_ratio</strong> (<em>float, optional, default=0</em>) – Change the aspect (namely width/height) to a random value in <code class="docutils literal"><span class="pre">[1</span> <span class="pre">-</span> <span class="pre">max_aspect_ratio,</span> <span class="pre">1</span> <span class="pre">+</span> <span class="pre">max_aspect_ratio]</span></code></li>
<li><strong>max_shear_ratio</strong> (<em>float, optional, default=0</em>) – Apply a shear transformation (namely <code class="docutils literal"><span class="pre">(x,y)->(x+my,y)</span></code>) with <code class="docutils literal"><span class="pre">m</span></code> randomly chose from <code class="docutils literal"><span class="pre">[-max_shear_ratio,</span> <span class="pre">max_shear_ratio]</span></code></li>
<li><strong>max_crop_size</strong> (<em>int, optional, default='-1'</em>) – Crop both width and height into a random size in <code class="docutils literal"><span class="pre">[min_crop_size,</span> <span class="pre">max_crop_size]</span></code></li>
<li><strong>min_crop_size</strong> (<em>int, optional, default='-1'</em>) – Crop both width and height into a random size in <code class="docutils literal"><span class="pre">[min_crop_size,</span> <span class="pre">max_crop_size]</span></code></li>
<li><strong>max_random_scale</strong> (<em>float, optional, default=1</em>) – Resize into <code class="docutils literal"><span class="pre">[width*s,</span> <span class="pre">height*s]</span></code> with <code class="docutils literal"><span class="pre">s</span></code> randomly chosen from <code class="docutils literal"><span class="pre">[min_random_scale,</span> <span class="pre">max_random_scale]</span></code></li>
<li><strong>min_random_scale</strong> (<em>float, optional, default=1</em>) – Resize into <code class="docutils literal"><span class="pre">[width*s,</span> <span class="pre">height*s]</span></code> with <code class="docutils literal"><span class="pre">s</span></code> randomly chosen from <code class="docutils literal"><span class="pre">[min_random_scale,</span> <span class="pre">max_random_scale]</span></code></li>
<li><strong>max_img_size</strong> (<em>float, optional, default=1e+10</em>) – Set the maximal width and height after all resize and rotate argumentation are applied</li>
<li><strong>min_img_size</strong> (<em>float, optional, default=0</em>) – Set the minimal width and height after all resize and rotate argumentation are applied</li>
<li><strong>random_h</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_h,</span> <span class="pre">random_h]</span></code> to the H channel in HSL color space.</li>
<li><strong>random_s</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_s,</span> <span class="pre">random_s]</span></code> to the S channel in HSL color space.</li>
<li><strong>random_l</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_l,</span> <span class="pre">random_l]</span></code> to the L channel in HSL color space.</li>
<li><strong>rotate</strong> (<em>int, optional, default='-1'</em>) – Rotate by an angle. If set, it overwrites the <code class="docutils literal"><span class="pre">max_rotate_angle</span></code> option.</li>
<li><strong>fill_value</strong> (<em>int, optional, default='255'</em>) – Set the padding pixes value into <code class="docutils literal"><span class="pre">fill_value</span></code>.</li>
<li><strong>inter_method</strong> (<em>int, optional, default='1'</em>) – The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.</li>
<li><strong>pad</strong> (<em>int, optional, default='0'</em>) – Change size from <code class="docutils literal"><span class="pre">[width,</span> <span class="pre">height]</span></code> into <code class="docutils literal"><span class="pre">[pad</span> <span class="pre">+</span> <span class="pre">width</span> <span class="pre">+</span> <span class="pre">pad,</span> <span class="pre">pad</span> <span class="pre">+</span> <span class="pre">height</span> <span class="pre">+</span> <span class="pre">pad]</span></code> by padding pixes</li>
<li><strong>mirror</strong> (<em>boolean, optional, default=False</em>) – Whether to mirror the image or not. If true, images are flipped along the horizontal axis.</li>
<li><strong>rand_mirror</strong> (<em>boolean, optional, default=False</em>) – Whether to randomly mirror images or not. If true, 50% of the images will be randomly mirrored (flipped along the horizontal axis)</li>
<li><strong>mean_img</strong> (<em>string, optional, default=''</em>) – Filename of the mean image.</li>
<li><strong>mean_r</strong> (<em>float, optional, default=0</em>) – The mean value to be subtracted on the R channel</li>
<li><strong>mean_g</strong> (<em>float, optional, default=0</em>) – The mean value to be subtracted on the G channel</li>
<li><strong>mean_b</strong> (<em>float, optional, default=0</em>) – The mean value to be subtracted on the B channel</li>
<li><strong>mean_a</strong> (<em>float, optional, default=0</em>) – The mean value to be subtracted on the alpha channel</li>
<li><strong>scale</strong> (<em>float, optional, default=1</em>) – Multiply the image with a scale value.</li>
<li><strong>max_random_contrast</strong> (<em>float, optional, default=0</em>) – Change the contrast with a value randomly chosen from <code class="docutils literal"><span class="pre">[-max_random_contrast,</span> <span class="pre">max_random_contrast]</span></code></li>
<li><strong>max_random_illumination</strong> (<em>float, optional, default=0</em>) – Change the illumination with a value randomly chosen from <code class="docutils literal"><span class="pre">[-max_random_illumination,</span> <span class="pre">max_random_illumination]</span></code></li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The result iterator.</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.io.MXDataIter" title="mxnet.io.MXDataIter">MXDataIter</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.io.ImageRecordIter_v1">
<code class="descclassname">mxnet.io.</code><code class="descname">ImageRecordIter_v1</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.ImageRecordIter_v1" title="Permalink to this definition"></a></dt>
<dd><p>Iterating on image RecordIO files</p>
<p>Read images batches from RecordIO files with a rich of data augmentation
options.</p>
<p>One can use <code class="docutils literal"><span class="pre">tools/im2rec.py</span></code> to pack individual image files into RecordIO
files.</p>
<p>Defined in src/io/iter_image_recordio.cc:L328</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>path_imglist</strong> (<em>string, optional, default=''</em>) – Path to the image list (.lst) file. Generally created with tools/im2rec.py. Format (Tab separated): <index of record> <one or more labels> <relative path from root folder>.</li>
<li><strong>path_imgrec</strong> (<em>string, optional, default=''</em>) – Path to the image RecordIO (.rec) file or a directory path. Created with tools/im2rec.py.</li>
<li><strong>aug_seq</strong> (<em>string, optional, default='aug_default'</em>) – The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.</li>
<li><strong>label_width</strong> (<em>int, optional, default='1'</em>) – The number of labels per image.</li>
<li><strong>data_shape</strong> (<em>Shape(tuple), required</em>) – The shape of one output image in (channels, height, width) format.</li>
<li><strong>preprocess_threads</strong> (<em>int, optional, default='4'</em>) – The number of threads to do preprocessing.</li>
<li><strong>verbose</strong> (<em>boolean, optional, default=True</em>) – If or not output verbose information.</li>
<li><strong>num_parts</strong> (<em>int, optional, default='1'</em>) – Virtually partition the data into these many parts.</li>
<li><strong>part_index</strong> (<em>int, optional, default='0'</em>) – The <em>i</em>-th virtual partition to be read.</li>
<li><strong>shuffle_chunk_size</strong> (<em>long (non-negative), optional, default=0</em>) – The data shuffle buffer size in MB. Only valid if shuffle is true.</li>
<li><strong>shuffle_chunk_seed</strong> (<em>int, optional, default='0'</em>) – The random seed for shuffling</li>
<li><strong>shuffle</strong> (<em>boolean, optional, default=False</em>) – Whether to shuffle data randomly or not.</li>
<li><strong>seed</strong> (<em>int, optional, default='0'</em>) – The random seed.</li>
<li><strong>batch_size</strong> (<em>int (non-negative), required</em>) – Batch size.</li>
<li><strong>round_batch</strong> (<em>boolean, optional, default=True</em>) – Whether to use round robin to handle overflow batch or not.</li>
<li><strong>prefetch_buffer</strong> (<em>long (non-negative), optional, default=4</em>) – Maximum number of batches to prefetch.</li>
<li><strong>dtype</strong> (<em>{None, 'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='None'</em>) – Output data type. <code class="docutils literal"><span class="pre">None</span></code> means no change.</li>
<li><strong>resize</strong> (<em>int, optional, default='-1'</em>) – Down scale the shorter edge to a new size before applying other augmentations.</li>
<li><strong>rand_crop</strong> (<em>boolean, optional, default=False</em>) – If or not randomly crop the image</li>
<li><strong>max_rotate_angle</strong> (<em>int, optional, default='0'</em>) – Rotate by a random degree in <code class="docutils literal"><span class="pre">[-v,</span> <span class="pre">v]</span></code></li>
<li><strong>max_aspect_ratio</strong> (<em>float, optional, default=0</em>) – Change the aspect (namely width/height) to a random value in <code class="docutils literal"><span class="pre">[1</span> <span class="pre">-</span> <span class="pre">max_aspect_ratio,</span> <span class="pre">1</span> <span class="pre">+</span> <span class="pre">max_aspect_ratio]</span></code></li>
<li><strong>max_shear_ratio</strong> (<em>float, optional, default=0</em>) – Apply a shear transformation (namely <code class="docutils literal"><span class="pre">(x,y)->(x+my,y)</span></code>) with <code class="docutils literal"><span class="pre">m</span></code> randomly chose from <code class="docutils literal"><span class="pre">[-max_shear_ratio,</span> <span class="pre">max_shear_ratio]</span></code></li>
<li><strong>max_crop_size</strong> (<em>int, optional, default='-1'</em>) – Crop both width and height into a random size in <code class="docutils literal"><span class="pre">[min_crop_size,</span> <span class="pre">max_crop_size]</span></code></li>
<li><strong>min_crop_size</strong> (<em>int, optional, default='-1'</em>) – Crop both width and height into a random size in <code class="docutils literal"><span class="pre">[min_crop_size,</span> <span class="pre">max_crop_size]</span></code></li>
<li><strong>max_random_scale</strong> (<em>float, optional, default=1</em>) – Resize into <code class="docutils literal"><span class="pre">[width*s,</span> <span class="pre">height*s]</span></code> with <code class="docutils literal"><span class="pre">s</span></code> randomly chosen from <code class="docutils literal"><span class="pre">[min_random_scale,</span> <span class="pre">max_random_scale]</span></code></li>
<li><strong>min_random_scale</strong> (<em>float, optional, default=1</em>) – Resize into <code class="docutils literal"><span class="pre">[width*s,</span> <span class="pre">height*s]</span></code> with <code class="docutils literal"><span class="pre">s</span></code> randomly chosen from <code class="docutils literal"><span class="pre">[min_random_scale,</span> <span class="pre">max_random_scale]</span></code></li>
<li><strong>max_img_size</strong> (<em>float, optional, default=1e+10</em>) – Set the maximal width and height after all resize and rotate argumentation are applied</li>
<li><strong>min_img_size</strong> (<em>float, optional, default=0</em>) – Set the minimal width and height after all resize and rotate argumentation are applied</li>
<li><strong>random_h</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_h,</span> <span class="pre">random_h]</span></code> to the H channel in HSL color space.</li>
<li><strong>random_s</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_s,</span> <span class="pre">random_s]</span></code> to the S channel in HSL color space.</li>
<li><strong>random_l</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_l,</span> <span class="pre">random_l]</span></code> to the L channel in HSL color space.</li>
<li><strong>rotate</strong> (<em>int, optional, default='-1'</em>) – Rotate by an angle. If set, it overwrites the <code class="docutils literal"><span class="pre">max_rotate_angle</span></code> option.</li>
<li><strong>fill_value</strong> (<em>int, optional, default='255'</em>) – Set the padding pixes value into <code class="docutils literal"><span class="pre">fill_value</span></code>.</li>
<li><strong>inter_method</strong> (<em>int, optional, default='1'</em>) – The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.</li>
<li><strong>pad</strong> (<em>int, optional, default='0'</em>) – Change size from <code class="docutils literal"><span class="pre">[width,</span> <span class="pre">height]</span></code> into <code class="docutils literal"><span class="pre">[pad</span> <span class="pre">+</span> <span class="pre">width</span> <span class="pre">+</span> <span class="pre">pad,</span> <span class="pre">pad</span> <span class="pre">+</span> <span class="pre">height</span> <span class="pre">+</span> <span class="pre">pad]</span></code> by padding pixes</li>
<li><strong>mirror</strong> (<em>boolean, optional, default=False</em>) – Whether to mirror the image or not. If true, images are flipped along the horizontal axis.</li>
<li><strong>rand_mirror</strong> (<em>boolean, optional, default=False</em>) – Whether to randomly mirror images or not. If true, 50% of the images will be randomly mirrored (flipped along the horizontal axis)</li>
<li><strong>mean_img</strong> (<em>string, optional, default=''</em>) – Filename of the mean image.</li>
<li><strong>mean_r</strong> (<em>float, optional, default=0</em>) – The mean value to be subtracted on the R channel</li>
<li><strong>mean_g</strong> (<em>float, optional, default=0</em>) – The mean value to be subtracted on the G channel</li>
<li><strong>mean_b</strong> (<em>float, optional, default=0</em>) – The mean value to be subtracted on the B channel</li>
<li><strong>mean_a</strong> (<em>float, optional, default=0</em>) – The mean value to be subtracted on the alpha channel</li>
<li><strong>scale</strong> (<em>float, optional, default=1</em>) – Multiply the image with a scale value.</li>
<li><strong>max_random_contrast</strong> (<em>float, optional, default=0</em>) – Change the contrast with a value randomly chosen from <code class="docutils literal"><span class="pre">[-max_random_contrast,</span> <span class="pre">max_random_contrast]</span></code></li>
<li><strong>max_random_illumination</strong> (<em>float, optional, default=0</em>) – Change the illumination with a value randomly chosen from <code class="docutils literal"><span class="pre">[-max_random_illumination,</span> <span class="pre">max_random_illumination]</span></code></li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The result iterator.</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.io.MXDataIter" title="mxnet.io.MXDataIter">MXDataIter</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.io.ImageRecordUInt8Iter">
<code class="descclassname">mxnet.io.</code><code class="descname">ImageRecordUInt8Iter</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.ImageRecordUInt8Iter" title="Permalink to this definition"></a></dt>
<dd><p>Iterating on image RecordIO files</p>
<p>This iterator is identical to <code class="docutils literal"><span class="pre">ImageRecordIter</span></code> except for using <code class="docutils literal"><span class="pre">uint8</span></code> as
the data type instead of <code class="docutils literal"><span class="pre">float</span></code>.</p>
<p>Defined in src/io/iter_image_recordio_2.cc:L600</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>path_imglist</strong> (<em>string, optional, default=''</em>) – Path to the image list (.lst) file. Generally created with tools/im2rec.py. Format (Tab separated): <index of record> <one or more labels> <relative path from root folder>.</li>
<li><strong>path_imgrec</strong> (<em>string, optional, default=''</em>) – Path to the image RecordIO (.rec) file or a directory path. Created with tools/im2rec.py.</li>
<li><strong>aug_seq</strong> (<em>string, optional, default='aug_default'</em>) – The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.</li>
<li><strong>label_width</strong> (<em>int, optional, default='1'</em>) – The number of labels per image.</li>
<li><strong>data_shape</strong> (<em>Shape(tuple), required</em>) – The shape of one output image in (channels, height, width) format.</li>
<li><strong>preprocess_threads</strong> (<em>int, optional, default='4'</em>) – The number of threads to do preprocessing.</li>
<li><strong>verbose</strong> (<em>boolean, optional, default=True</em>) – If or not output verbose information.</li>
<li><strong>num_parts</strong> (<em>int, optional, default='1'</em>) – Virtually partition the data into these many parts.</li>
<li><strong>part_index</strong> (<em>int, optional, default='0'</em>) – The <em>i</em>-th virtual partition to be read.</li>
<li><strong>shuffle_chunk_size</strong> (<em>long (non-negative), optional, default=0</em>) – The data shuffle buffer size in MB. Only valid if shuffle is true.</li>
<li><strong>shuffle_chunk_seed</strong> (<em>int, optional, default='0'</em>) – The random seed for shuffling</li>
<li><strong>shuffle</strong> (<em>boolean, optional, default=False</em>) – Whether to shuffle data randomly or not.</li>
<li><strong>seed</strong> (<em>int, optional, default='0'</em>) – The random seed.</li>
<li><strong>batch_size</strong> (<em>int (non-negative), required</em>) – Batch size.</li>
<li><strong>round_batch</strong> (<em>boolean, optional, default=True</em>) – Whether to use round robin to handle overflow batch or not.</li>
<li><strong>prefetch_buffer</strong> (<em>long (non-negative), optional, default=4</em>) – Maximum number of batches to prefetch.</li>
<li><strong>dtype</strong> (<em>{None, 'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='None'</em>) – Output data type. <code class="docutils literal"><span class="pre">None</span></code> means no change.</li>
<li><strong>resize</strong> (<em>int, optional, default='-1'</em>) – Down scale the shorter edge to a new size before applying other augmentations.</li>
<li><strong>rand_crop</strong> (<em>boolean, optional, default=False</em>) – If or not randomly crop the image</li>
<li><strong>max_rotate_angle</strong> (<em>int, optional, default='0'</em>) – Rotate by a random degree in <code class="docutils literal"><span class="pre">[-v,</span> <span class="pre">v]</span></code></li>
<li><strong>max_aspect_ratio</strong> (<em>float, optional, default=0</em>) – Change the aspect (namely width/height) to a random value in <code class="docutils literal"><span class="pre">[1</span> <span class="pre">-</span> <span class="pre">max_aspect_ratio,</span> <span class="pre">1</span> <span class="pre">+</span> <span class="pre">max_aspect_ratio]</span></code></li>
<li><strong>max_shear_ratio</strong> (<em>float, optional, default=0</em>) – Apply a shear transformation (namely <code class="docutils literal"><span class="pre">(x,y)->(x+my,y)</span></code>) with <code class="docutils literal"><span class="pre">m</span></code> randomly chose from <code class="docutils literal"><span class="pre">[-max_shear_ratio,</span> <span class="pre">max_shear_ratio]</span></code></li>
<li><strong>max_crop_size</strong> (<em>int, optional, default='-1'</em>) – Crop both width and height into a random size in <code class="docutils literal"><span class="pre">[min_crop_size,</span> <span class="pre">max_crop_size]</span></code></li>
<li><strong>min_crop_size</strong> (<em>int, optional, default='-1'</em>) – Crop both width and height into a random size in <code class="docutils literal"><span class="pre">[min_crop_size,</span> <span class="pre">max_crop_size]</span></code></li>
<li><strong>max_random_scale</strong> (<em>float, optional, default=1</em>) – Resize into <code class="docutils literal"><span class="pre">[width*s,</span> <span class="pre">height*s]</span></code> with <code class="docutils literal"><span class="pre">s</span></code> randomly chosen from <code class="docutils literal"><span class="pre">[min_random_scale,</span> <span class="pre">max_random_scale]</span></code></li>
<li><strong>min_random_scale</strong> (<em>float, optional, default=1</em>) – Resize into <code class="docutils literal"><span class="pre">[width*s,</span> <span class="pre">height*s]</span></code> with <code class="docutils literal"><span class="pre">s</span></code> randomly chosen from <code class="docutils literal"><span class="pre">[min_random_scale,</span> <span class="pre">max_random_scale]</span></code></li>
<li><strong>max_img_size</strong> (<em>float, optional, default=1e+10</em>) – Set the maximal width and height after all resize and rotate argumentation are applied</li>
<li><strong>min_img_size</strong> (<em>float, optional, default=0</em>) – Set the minimal width and height after all resize and rotate argumentation are applied</li>
<li><strong>random_h</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_h,</span> <span class="pre">random_h]</span></code> to the H channel in HSL color space.</li>
<li><strong>random_s</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_s,</span> <span class="pre">random_s]</span></code> to the S channel in HSL color space.</li>
<li><strong>random_l</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_l,</span> <span class="pre">random_l]</span></code> to the L channel in HSL color space.</li>
<li><strong>rotate</strong> (<em>int, optional, default='-1'</em>) – Rotate by an angle. If set, it overwrites the <code class="docutils literal"><span class="pre">max_rotate_angle</span></code> option.</li>
<li><strong>fill_value</strong> (<em>int, optional, default='255'</em>) – Set the padding pixes value into <code class="docutils literal"><span class="pre">fill_value</span></code>.</li>
<li><strong>inter_method</strong> (<em>int, optional, default='1'</em>) – The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.</li>
<li><strong>pad</strong> (<em>int, optional, default='0'</em>) – Change size from <code class="docutils literal"><span class="pre">[width,</span> <span class="pre">height]</span></code> into <code class="docutils literal"><span class="pre">[pad</span> <span class="pre">+</span> <span class="pre">width</span> <span class="pre">+</span> <span class="pre">pad,</span> <span class="pre">pad</span> <span class="pre">+</span> <span class="pre">height</span> <span class="pre">+</span> <span class="pre">pad]</span></code> by padding pixes</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The result iterator.</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.io.MXDataIter" title="mxnet.io.MXDataIter">MXDataIter</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.io.ImageRecordUInt8Iter_v1">
<code class="descclassname">mxnet.io.</code><code class="descname">ImageRecordUInt8Iter_v1</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.ImageRecordUInt8Iter_v1" title="Permalink to this definition"></a></dt>
<dd><p>Iterating on image RecordIO files</p>
<p>This iterator is identical to <code class="docutils literal"><span class="pre">ImageRecordIter</span></code> except for using <code class="docutils literal"><span class="pre">uint8</span></code> as
the data type instead of <code class="docutils literal"><span class="pre">float</span></code>.</p>
<p>Defined in src/io/iter_image_recordio.cc:L349</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>path_imglist</strong> (<em>string, optional, default=''</em>) – Path to the image list (.lst) file. Generally created with tools/im2rec.py. Format (Tab separated): <index of record> <one or more labels> <relative path from root folder>.</li>
<li><strong>path_imgrec</strong> (<em>string, optional, default=''</em>) – Path to the image RecordIO (.rec) file or a directory path. Created with tools/im2rec.py.</li>
<li><strong>aug_seq</strong> (<em>string, optional, default='aug_default'</em>) – The augmenter names to represent sequence of augmenters to be applied, seperated by comma. Additional keyword parameters will be seen by these augmenters.</li>
<li><strong>label_width</strong> (<em>int, optional, default='1'</em>) – The number of labels per image.</li>
<li><strong>data_shape</strong> (<em>Shape(tuple), required</em>) – The shape of one output image in (channels, height, width) format.</li>
<li><strong>preprocess_threads</strong> (<em>int, optional, default='4'</em>) – The number of threads to do preprocessing.</li>
<li><strong>verbose</strong> (<em>boolean, optional, default=True</em>) – If or not output verbose information.</li>
<li><strong>num_parts</strong> (<em>int, optional, default='1'</em>) – Virtually partition the data into these many parts.</li>
<li><strong>part_index</strong> (<em>int, optional, default='0'</em>) – The <em>i</em>-th virtual partition to be read.</li>
<li><strong>shuffle_chunk_size</strong> (<em>long (non-negative), optional, default=0</em>) – The data shuffle buffer size in MB. Only valid if shuffle is true.</li>
<li><strong>shuffle_chunk_seed</strong> (<em>int, optional, default='0'</em>) – The random seed for shuffling</li>
<li><strong>shuffle</strong> (<em>boolean, optional, default=False</em>) – Whether to shuffle data randomly or not.</li>
<li><strong>seed</strong> (<em>int, optional, default='0'</em>) – The random seed.</li>
<li><strong>batch_size</strong> (<em>int (non-negative), required</em>) – Batch size.</li>
<li><strong>round_batch</strong> (<em>boolean, optional, default=True</em>) – Whether to use round robin to handle overflow batch or not.</li>
<li><strong>prefetch_buffer</strong> (<em>long (non-negative), optional, default=4</em>) – Maximum number of batches to prefetch.</li>
<li><strong>dtype</strong> (<em>{None, 'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='None'</em>) – Output data type. <code class="docutils literal"><span class="pre">None</span></code> means no change.</li>
<li><strong>resize</strong> (<em>int, optional, default='-1'</em>) – Down scale the shorter edge to a new size before applying other augmentations.</li>
<li><strong>rand_crop</strong> (<em>boolean, optional, default=False</em>) – If or not randomly crop the image</li>
<li><strong>max_rotate_angle</strong> (<em>int, optional, default='0'</em>) – Rotate by a random degree in <code class="docutils literal"><span class="pre">[-v,</span> <span class="pre">v]</span></code></li>
<li><strong>max_aspect_ratio</strong> (<em>float, optional, default=0</em>) – Change the aspect (namely width/height) to a random value in <code class="docutils literal"><span class="pre">[1</span> <span class="pre">-</span> <span class="pre">max_aspect_ratio,</span> <span class="pre">1</span> <span class="pre">+</span> <span class="pre">max_aspect_ratio]</span></code></li>
<li><strong>max_shear_ratio</strong> (<em>float, optional, default=0</em>) – Apply a shear transformation (namely <code class="docutils literal"><span class="pre">(x,y)->(x+my,y)</span></code>) with <code class="docutils literal"><span class="pre">m</span></code> randomly chose from <code class="docutils literal"><span class="pre">[-max_shear_ratio,</span> <span class="pre">max_shear_ratio]</span></code></li>
<li><strong>max_crop_size</strong> (<em>int, optional, default='-1'</em>) – Crop both width and height into a random size in <code class="docutils literal"><span class="pre">[min_crop_size,</span> <span class="pre">max_crop_size]</span></code></li>
<li><strong>min_crop_size</strong> (<em>int, optional, default='-1'</em>) – Crop both width and height into a random size in <code class="docutils literal"><span class="pre">[min_crop_size,</span> <span class="pre">max_crop_size]</span></code></li>
<li><strong>max_random_scale</strong> (<em>float, optional, default=1</em>) – Resize into <code class="docutils literal"><span class="pre">[width*s,</span> <span class="pre">height*s]</span></code> with <code class="docutils literal"><span class="pre">s</span></code> randomly chosen from <code class="docutils literal"><span class="pre">[min_random_scale,</span> <span class="pre">max_random_scale]</span></code></li>
<li><strong>min_random_scale</strong> (<em>float, optional, default=1</em>) – Resize into <code class="docutils literal"><span class="pre">[width*s,</span> <span class="pre">height*s]</span></code> with <code class="docutils literal"><span class="pre">s</span></code> randomly chosen from <code class="docutils literal"><span class="pre">[min_random_scale,</span> <span class="pre">max_random_scale]</span></code></li>
<li><strong>max_img_size</strong> (<em>float, optional, default=1e+10</em>) – Set the maximal width and height after all resize and rotate argumentation are applied</li>
<li><strong>min_img_size</strong> (<em>float, optional, default=0</em>) – Set the minimal width and height after all resize and rotate argumentation are applied</li>
<li><strong>random_h</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_h,</span> <span class="pre">random_h]</span></code> to the H channel in HSL color space.</li>
<li><strong>random_s</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_s,</span> <span class="pre">random_s]</span></code> to the S channel in HSL color space.</li>
<li><strong>random_l</strong> (<em>int, optional, default='0'</em>) – Add a random value in <code class="docutils literal"><span class="pre">[-random_l,</span> <span class="pre">random_l]</span></code> to the L channel in HSL color space.</li>
<li><strong>rotate</strong> (<em>int, optional, default='-1'</em>) – Rotate by an angle. If set, it overwrites the <code class="docutils literal"><span class="pre">max_rotate_angle</span></code> option.</li>
<li><strong>fill_value</strong> (<em>int, optional, default='255'</em>) – Set the padding pixes value into <code class="docutils literal"><span class="pre">fill_value</span></code>.</li>
<li><strong>inter_method</strong> (<em>int, optional, default='1'</em>) – The interpolation method: 0-NN 1-bilinear 2-cubic 3-area 4-lanczos4 9-auto 10-rand.</li>
<li><strong>pad</strong> (<em>int, optional, default='0'</em>) – Change size from <code class="docutils literal"><span class="pre">[width,</span> <span class="pre">height]</span></code> into <code class="docutils literal"><span class="pre">[pad</span> <span class="pre">+</span> <span class="pre">width</span> <span class="pre">+</span> <span class="pre">pad,</span> <span class="pre">pad</span> <span class="pre">+</span> <span class="pre">height</span> <span class="pre">+</span> <span class="pre">pad]</span></code> by padding pixes</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The result iterator.</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.io.MXDataIter" title="mxnet.io.MXDataIter">MXDataIter</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="mxnet.io.MNISTIter">
<code class="descclassname">mxnet.io.</code><code class="descname">MNISTIter</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.io.MNISTIter" title="Permalink to this definition"></a></dt>
<dd><p>Iterating on the MNIST dataset.</p>
<p>One can download the dataset from <a class="reference external" href="http://yann.lecun.com/exdb/mnist/">http://yann.lecun.com/exdb/mnist/</a></p>
<p>Defined in src/io/iter_mnist.cc:L246</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>image</strong> (<em>string, optional, default='./train-images-idx3-ubyte'</em>) – Dataset Param: Mnist image path.</li>
<li><strong>label</strong> (<em>string, optional, default='./train-labels-idx1-ubyte'</em>) – Dataset Param: Mnist label path.</li>
<li><strong>batch_size</strong> (<em>int, optional, default='128'</em>) – Batch Param: Batch Size.</li>
<li><strong>shuffle</strong> (<em>boolean, optional, default=True</em>) – Augmentation Param: Whether to shuffle data.</li>
<li><strong>flat</strong> (<em>boolean, optional, default=False</em>) – Augmentation Param: Whether to flat the data into 1D.</li>
<li><strong>seed</strong> (<em>int, optional, default='0'</em>) – Augmentation Param: Random Seed.</li>
<li><strong>silent</strong> (<em>boolean, optional, default=False</em>) – Auxiliary Param: Whether to print out data info.</li>
<li><strong>num_parts</strong> (<em>int, optional, default='1'</em>) – partition the data into multiple parts</li>
<li><strong>part_index</strong> (<em>int, optional, default='0'</em>) – the index of the part will read</li>
<li><strong>prefetch_buffer</strong> (<em>long (non-negative), optional, default=4</em>) – Maximum number of batches to prefetch.</li>
<li><strong>dtype</strong> (<em>{None, 'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='None'</em>) – Output data type. <code class="docutils literal"><span class="pre">None</span></code> means no change.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The result iterator.</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.io.MXDataIter" title="mxnet.io.MXDataIter">MXDataIter</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<span class="target" id="module-mxnet.image"></span><p>Read individual image files and perform augmentations.</p>
<dl class="function">
<dt id="mxnet.image.imdecode">
<code class="descclassname">mxnet.image.</code><code class="descname">imdecode</code><span class="sig-paren">(</span><em>buf</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.imdecode" title="Permalink to this definition"></a></dt>
<dd><p>Decode an image to an NDArray.</p>
<p>Note: <cite>imdecode</cite> uses OpenCV (not the CV2 Python library).
MXNet must have been built with OpenCV for <cite>imdecode</cite> to work.</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>buf</strong> (<em>str/bytes or numpy.ndarray</em>) – Binary image data as string or numpy ndarray.</li>
<li><strong>flag</strong> (<em>int, optional, default=1</em>) – 1 for three channel color output. 0 for grayscale output.</li>
<li><strong>to_rgb</strong> (<em>int, optional, default=1</em>) – 1 for RGB formatted output (MXNet default). 0 for BGR formatted output (OpenCV default).</li>
<li><strong>out</strong> (<em>NDArray, optional</em>) – Output buffer. Use <cite>None</cite> for automatic allocation.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">An <cite>NDArray</cite> containing the image.</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.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray">NDArray</a></p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Example</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"flower.jpg"</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">str_image</span> <span class="o">=</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">image</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">img</span><span class="o">.</span><span class="n">imdecode</span><span class="p">(</span><span class="n">str_image</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">image</span>
<span class="go"><NDArray 224x224x3 @cpu(0)></span>
</pre></div>
</div>
<p>Set <cite>flag</cite> parameter to 0 to get grayscale output</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"flower.jpg"</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">str_image</span> <span class="o">=</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">image</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">img</span><span class="o">.</span><span class="n">imdecode</span><span class="p">(</span><span class="n">str_image</span><span class="p">,</span> <span class="n">flag</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">image</span>
<span class="go"><NDArray 224x224x1 @cpu(0)></span>
</pre></div>
</div>
<p>Set <cite>to_rgb</cite> parameter to 0 to get output in OpenCV format (BGR)</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"flower.jpg"</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">str_image</span> <span class="o">=</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">image</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">img</span><span class="o">.</span><span class="n">imdecode</span><span class="p">(</span><span class="n">str_image</span><span class="p">,</span> <span class="n">to_rgb</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">image</span>
<span class="go"><NDArray 224x224x3 @cpu(0)></span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.scale_down">
<code class="descclassname">mxnet.image.</code><code class="descname">scale_down</code><span class="sig-paren">(</span><em>src_size</em>, <em>size</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.scale_down" title="Permalink to this definition"></a></dt>
<dd><p>Scales down crop size if it’s larger than image size.</p>
<p>If width/height of the crop is larger than the width/height of the image,
sets the width/height to the width/height of the image.</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>src_size</strong> (<em>tuple of int</em>) – Size of the image in (width, height) format.</li>
<li><strong>size</strong> (<em>tuple of int</em>) – Size of the crop in (width, height) format.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A tuple containing the scaled crop size in (width, height) format.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">tuple of int</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Example</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">src_size</span> <span class="o">=</span> <span class="p">(</span><span class="mi">640</span><span class="p">,</span><span class="mi">480</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">size</span> <span class="o">=</span> <span class="p">(</span><span class="mi">720</span><span class="p">,</span><span class="mi">120</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">new_size</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">img</span><span class="o">.</span><span class="n">scale_down</span><span class="p">(</span><span class="n">src_size</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">new_size</span>
<span class="go">(640,106)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.resize_short">
<code class="descclassname">mxnet.image.</code><code class="descname">resize_short</code><span class="sig-paren">(</span><em>src</em>, <em>size</em>, <em>interp=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.resize_short" title="Permalink to this definition"></a></dt>
<dd><p>Resizes shorter edge to size.</p>
<p>Note: <cite>resize_short</cite> uses OpenCV (not the CV2 Python library).
MXNet must have been built with OpenCV for <cite>resize_short</cite> to work.</p>
<p>Resizes the original image by setting the shorter edge to size
and setting the longer edge accordingly.
Resizing function is called from OpenCV.</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>src</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – The original image.</li>
<li><strong>size</strong> (<em>int</em>) – The length to be set for the shorter edge.</li>
<li><strong>interp</strong> (<em>int, optional, default=2</em>) – Interpolation method used for resizing the image.
Default method is bicubic interpolation.
More details can be found in the documentation of OpenCV, please refer to
<a class="reference external" href="http://docs.opencv.org/master/da/d54/group__imgproc__transform.html">http://docs.opencv.org/master/da/d54/group__imgproc__transform.html</a>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">An ‘NDArray’ containing the resized image.</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.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray">NDArray</a></p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Example</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"flower.jpeg"</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">str_image</span> <span class="o">=</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">image</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">img</span><span class="o">.</span><span class="n">imdecode</span><span class="p">(</span><span class="n">str_image</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">image</span>
<span class="go"><NDArray 2321x3482x3 @cpu(0)></span>
<span class="gp">>>> </span><span class="n">size</span> <span class="o">=</span> <span class="mi">640</span>
<span class="gp">>>> </span><span class="n">new_image</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">img</span><span class="o">.</span><span class="n">resize_short</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">new_image</span>
<span class="go"><NDArray 2321x3482x3 @cpu(0)></span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.fixed_crop">
<code class="descclassname">mxnet.image.</code><code class="descname">fixed_crop</code><span class="sig-paren">(</span><em>src</em>, <em>x0</em>, <em>y0</em>, <em>w</em>, <em>h</em>, <em>size=None</em>, <em>interp=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.fixed_crop" title="Permalink to this definition"></a></dt>
<dd><p>Crop src at fixed location, and (optionally) resize it to size.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.random_crop">
<code class="descclassname">mxnet.image.</code><code class="descname">random_crop</code><span class="sig-paren">(</span><em>src</em>, <em>size</em>, <em>interp=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.random_crop" title="Permalink to this definition"></a></dt>
<dd><p>Randomly crop <cite>src</cite> with <cite>size</cite> (width, height).
Upsample result if <cite>src</cite> is smaller than <cite>size</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>src</strong> (Source image <cite>NDArray</cite>) – </li>
<li><strong>size</strong> (Size of the crop formatted as (width, height). If the <cite>size</cite> is larger) – than the image, then the source image is upsampled to <cite>size</cite> and returned.</li>
<li><strong>interp</strong> (<em>Interpolation method to be used in case the size is larger (default: bicubic).</em>) – Uses OpenCV convention for the parameters. Nearest - 0, Bilinear - 1, Bicubic - 2,
Area - 3. See OpenCV imresize function for more details.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><ul class="simple">
<li><em>NDArray</em>
An <cite>NDArray</cite> containing the cropped image.</li>
<li><em>Tuple</em>
A tuple (x, y, width, height) where (x, y) is top-left position of the crop in the
original image and (width, height) are the dimensions of the cropped image.</li>
</ul>
</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Example</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">im</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">array</span><span class="p">(</span><span class="n">cv2</span><span class="o">.</span><span class="n">imread</span><span class="p">(</span><span class="s2">"flower.jpg"</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">cropped_im</span><span class="p">,</span> <span class="n">rect</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">image</span><span class="o">.</span><span class="n">random_crop</span><span class="p">(</span><span class="n">im</span><span class="p">,</span> <span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">))</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">cropped_im</span>
<span class="go"><NDArray 100x100x1 @cpu(0)></span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">rect</span>
<span class="go">(20, 21, 100, 100)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.center_crop">
<code class="descclassname">mxnet.image.</code><code class="descname">center_crop</code><span class="sig-paren">(</span><em>src</em>, <em>size</em>, <em>interp=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.center_crop" title="Permalink to this definition"></a></dt>
<dd><p>Crops the image <cite>src</cite> to the given <cite>size</cite> by trimming on all four
sides and preserving the center of the image. Upsamples if <cite>src</cite> is smaller
than <cite>size</cite>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This requires MXNet to be compiled with USE_OPENCV.</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 simple">
<li><strong>src</strong> (<a class="reference internal" href="ndarray.html#mxnet.ndarray.NDArray" title="mxnet.ndarray.NDArray"><em>NDArray</em></a>) – Binary source image data.</li>
<li><strong>size</strong> (<em>list or tuple of int</em>) – The desired output image size.</li>
<li><strong>interp</strong> (<em>interpolation, optional, default=Area-based</em>) – <p>The type of interpolation that is done to the image.</p>
<blockquote>
<div>Possible values:</div></blockquote>
<p>0: Nearest Neighbors Interpolation.</p>
<p>1: Bilinear interpolation.</p>
<p>2: Area-based (resampling using pixel area relation). It may be a
preferred method for image decimation, as it gives moire-free
results. But when the image is zoomed, it is similar to the Nearest
Neighbors method. (used by default).</p>
<p>3: Bicubic interpolation over 4x4 pixel neighborhood.</p>
<p>4: Lanczos interpolation over 8x8 pixel neighborhood.</p>
<p>When shrinking an image, it will generally look best with AREA-based
interpolation, whereas, when enlarging an image, it will generally look best
with Bicubic (slow) or Bilinear (faster but still looks OK).</p>
</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><ul class="simple">
<li><em>NDArray</em>
The cropped image.</li>
<li><em>Tuple</em>
(x, y, width, height) where x, y are the positions of the crop in the
original image and width, height the dimensions of the crop.</li>
</ul>
</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Example</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"flower.jpg"</span><span class="p">,</span> <span class="s1">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">str_image</span> <span class="o">=</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">image</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">image</span><span class="o">.</span><span class="n">imdecode</span><span class="p">(</span><span class="n">str_image</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">image</span>
<span class="go"><NDArray 2321x3482x3 @cpu(0)></span>
<span class="gp">>>> </span><span class="n">cropped_image</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">)</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">image</span><span class="o">.</span><span class="n">center_crop</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">500</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">cropped_image</span>
<span class="go"><NDArray 500x1000x3 @cpu(0)></span>
<span class="gp">>>> </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">height</span>
<span class="go">(1241, 910, 1000, 500)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.color_normalize">
<code class="descclassname">mxnet.image.</code><code class="descname">color_normalize</code><span class="sig-paren">(</span><em>src</em>, <em>mean</em>, <em>std=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.color_normalize" title="Permalink to this definition"></a></dt>
<dd><p>Normalize src with mean and std.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.random_size_crop">
<code class="descclassname">mxnet.image.</code><code class="descname">random_size_crop</code><span class="sig-paren">(</span><em>src</em>, <em>size</em>, <em>min_area</em>, <em>ratio</em>, <em>interp=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.random_size_crop" title="Permalink to this definition"></a></dt>
<dd><p>Randomly crop src with size. Randomize area and aspect ratio.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.ResizeAug">
<code class="descclassname">mxnet.image.</code><code class="descname">ResizeAug</code><span class="sig-paren">(</span><em>size</em>, <em>interp=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ResizeAug" title="Permalink to this definition"></a></dt>
<dd><p>Make resize shorter edge to size augmenter.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.RandomCropAug">
<code class="descclassname">mxnet.image.</code><code class="descname">RandomCropAug</code><span class="sig-paren">(</span><em>size</em>, <em>interp=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.RandomCropAug" title="Permalink to this definition"></a></dt>
<dd><p>Make random crop augmenter</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.RandomSizedCropAug">
<code class="descclassname">mxnet.image.</code><code class="descname">RandomSizedCropAug</code><span class="sig-paren">(</span><em>size</em>, <em>min_area</em>, <em>ratio</em>, <em>interp=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.RandomSizedCropAug" title="Permalink to this definition"></a></dt>
<dd><p>Make random crop with random resizing and random aspect ratio jitter augmenter.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.CenterCropAug">
<code class="descclassname">mxnet.image.</code><code class="descname">CenterCropAug</code><span class="sig-paren">(</span><em>size</em>, <em>interp=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.CenterCropAug" title="Permalink to this definition"></a></dt>
<dd><p>Make center crop augmenter.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.RandomOrderAug">
<code class="descclassname">mxnet.image.</code><code class="descname">RandomOrderAug</code><span class="sig-paren">(</span><em>ts</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.RandomOrderAug" title="Permalink to this definition"></a></dt>
<dd><p>Apply list of augmenters in random order</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.ColorJitterAug">
<code class="descclassname">mxnet.image.</code><code class="descname">ColorJitterAug</code><span class="sig-paren">(</span><em>brightness</em>, <em>contrast</em>, <em>saturation</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ColorJitterAug" title="Permalink to this definition"></a></dt>
<dd><p>Apply random brightness, contrast and saturation jitter in random order.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.LightingAug">
<code class="descclassname">mxnet.image.</code><code class="descname">LightingAug</code><span class="sig-paren">(</span><em>alphastd</em>, <em>eigval</em>, <em>eigvec</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.LightingAug" title="Permalink to this definition"></a></dt>
<dd><p>Add PCA based noise.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.ColorNormalizeAug">
<code class="descclassname">mxnet.image.</code><code class="descname">ColorNormalizeAug</code><span class="sig-paren">(</span><em>mean</em>, <em>std</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ColorNormalizeAug" title="Permalink to this definition"></a></dt>
<dd><p>Mean and std normalization.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.HorizontalFlipAug">
<code class="descclassname">mxnet.image.</code><code class="descname">HorizontalFlipAug</code><span class="sig-paren">(</span><em>p</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.HorizontalFlipAug" title="Permalink to this definition"></a></dt>
<dd><p>Random horizontal flipping.</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.CastAug">
<code class="descclassname">mxnet.image.</code><code class="descname">CastAug</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.CastAug" title="Permalink to this definition"></a></dt>
<dd><p>Cast to float32</p>
</dd></dl>
<dl class="function">
<dt id="mxnet.image.CreateAugmenter">
<code class="descclassname">mxnet.image.</code><code class="descname">CreateAugmenter</code><span class="sig-paren">(</span><em>data_shape</em>, <em>resize=0</em>, <em>rand_crop=False</em>, <em>rand_resize=False</em>, <em>rand_mirror=False</em>, <em>mean=None</em>, <em>std=None</em>, <em>brightness=0</em>, <em>contrast=0</em>, <em>saturation=0</em>, <em>pca_noise=0</em>, <em>inter_method=2</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.CreateAugmenter" title="Permalink to this definition"></a></dt>
<dd><p>Creates an augmenter list.</p>
</dd></dl>
<dl class="class">
<dt id="mxnet.image.ImageIter">
<em class="property">class </em><code class="descclassname">mxnet.image.</code><code class="descname">ImageIter</code><span class="sig-paren">(</span><em>batch_size</em>, <em>data_shape</em>, <em>label_width=1</em>, <em>path_imgrec=None</em>, <em>path_imglist=None</em>, <em>path_root=None</em>, <em>path_imgidx=None</em>, <em>shuffle=False</em>, <em>part_index=0</em>, <em>num_parts=1</em>, <em>aug_list=None</em>, <em>imglist=None</em>, <em>data_name='data'</em>, <em>label_name='softmax_label'</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter" title="Permalink to this definition"></a></dt>
<dd><p>Image data iterator with a large number of augmentation choices.
This iterator supports reading from both .rec files and raw image files.</p>
<p>To load input images from .rec files, use <cite>path_imgrec</cite> parameter and to load from raw image
files, use <cite>path_imglist</cite> and <cite>path_root</cite> parameters.</p>
<p>To use data partition (for distributed training) or shuffling, specify <cite>path_imgidx</cite> parameter.</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>) – Number of examples per batch.</li>
<li><strong>data_shape</strong> (<em>tuple</em>) – Data shape in (channels, height, width) format.
For now, only RGB image with 3 channels is supported.</li>
<li><strong>label_width</strong> (<em>int, optional</em>) – Number of labels per example. The default label width is 1.</li>
<li><strong>path_imgrec</strong> (<em>str</em>) – Path to image record file (.rec).
Created with tools/im2rec.py or bin/im2rec.</li>
<li><strong>path_imglist</strong> (<em>str</em>) – Path to image list (.lst).
Created with tools/im2rec.py or with custom script.
Format: Tab separated record of index, one or more labels and relative_path_from_root.</li>
<li><strong>imglist</strong> (<em>list</em>) – A list of images with the label(s).
Each item is a list [imagelabel: float or list of float, imgpath].</li>
<li><strong>path_root</strong> (<em>str</em>) – Root folder of image files.</li>
<li><strong>path_imgidx</strong> (<em>str</em>) – Path to image index file. Needed for partition and shuffling when using .rec source.</li>
<li><strong>shuffle</strong> (<em>bool</em>) – Whether to shuffle all images at the start of each iteration or not.
Can be slow for HDD.</li>
<li><strong>part_index</strong> (<em>int</em>) – Partition index.</li>
<li><strong>num_parts</strong> (<em>int</em>) – Total number of partitions.</li>
<li><strong>data_name</strong> (<em>str</em>) – Data name for provided symbols.</li>
<li><strong>label_name</strong> (<em>str</em>) – Label name for provided symbols.</li>
<li><strong>kwargs</strong> – More arguments for creating augmenter. See mx.image.CreateAugmenter.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mxnet.image.ImageIter.reset">
<code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter.reset" title="Permalink to this definition"></a></dt>
<dd><p>Resets the iterator to the beginning of the data.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.image.ImageIter.next_sample">
<code class="descname">next_sample</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter.next_sample" title="Permalink to this definition"></a></dt>
<dd><p>Helper function for reading in next sample.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.image.ImageIter.next">
<code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter.next" title="Permalink to this definition"></a></dt>
<dd><p>Returns the next batch of data.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.image.ImageIter.check_data_shape">
<code class="descname">check_data_shape</code><span class="sig-paren">(</span><em>data_shape</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter.check_data_shape" title="Permalink to this definition"></a></dt>
<dd><p>Checks if the input data shape is valid</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.image.ImageIter.check_valid_image">
<code class="descname">check_valid_image</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter.check_valid_image" title="Permalink to this definition"></a></dt>
<dd><p>Checks if the input data is valid</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.image.ImageIter.imdecode">
<code class="descname">imdecode</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter.imdecode" title="Permalink to this definition"></a></dt>
<dd><p>Decodes a string or byte string to an NDArray.
See mx.img.imdecode for more details.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.image.ImageIter.read_image">
<code class="descname">read_image</code><span class="sig-paren">(</span><em>fname</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter.read_image" title="Permalink to this definition"></a></dt>
<dd><p>Reads an input image <cite>fname</cite> and returns the decoded raw bytes.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dataIter</span><span class="o">.</span><span class="n">read_image</span><span class="p">(</span><span class="s1">'Face.jpg'</span><span class="p">)</span> <span class="c1"># returns decoded raw bytes.</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="mxnet.image.ImageIter.augmentation_transform">
<code class="descname">augmentation_transform</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter.augmentation_transform" title="Permalink to this definition"></a></dt>
<dd><p>Transforms input data with specified augmentation.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.image.ImageIter.postprocess_data">
<code class="descname">postprocess_data</code><span class="sig-paren">(</span><em>datum</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.image.ImageIter.postprocess_data" title="Permalink to this definition"></a></dt>
<dd><p>Final postprocessing step before image is loaded into the batch.</p>
</dd></dl>
</dd></dl>
<span class="target" id="module-mxnet.recordio"></span><p>Read and write for the RecordIO data format.</p>
<dl class="class">
<dt id="mxnet.recordio.MXRecordIO">
<em class="property">class </em><code class="descclassname">mxnet.recordio.</code><code class="descname">MXRecordIO</code><span class="sig-paren">(</span><em>uri</em>, <em>flag</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXRecordIO" title="Permalink to this definition"></a></dt>
<dd><p>Reads/writes <cite>RecordIO</cite> data format, supporting sequential read and write.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXRecordIO</span><span class="p">(</span><span class="s1">'tmp.rec'</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span>
<span class="go"><mxnet.recordio.MXRecordIO object at 0x10ef40ed0></span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">record</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'record_</span><span class="si">%d</span><span class="s1">'</span><span class="o">%</span><span class="n">i</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXRecordIO</span><span class="p">(</span><span class="s1">'tmp.rec'</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">item</span> <span class="o">=</span> <span class="n">record</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">... </span> <span class="k">print</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="go">record_0</span>
<span class="go">record_1</span>
<span class="go">record_2</span>
<span class="go">record_3</span>
<span class="go">record_4</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">close</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>uri</strong> (<em>string</em>) – Path to the record file.</li>
<li><strong>flag</strong> (<em>string</em>) – ‘w’ for write or ‘r’ for read.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mxnet.recordio.MXRecordIO.open">
<code class="descname">open</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXRecordIO.open" title="Permalink to this definition"></a></dt>
<dd><p>Opens the record file.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.recordio.MXRecordIO.close">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXRecordIO.close" title="Permalink to this definition"></a></dt>
<dd><p>Closes the record file.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.recordio.MXRecordIO.reset">
<code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXRecordIO.reset" title="Permalink to this definition"></a></dt>
<dd><p>Resets the pointer to first item.</p>
<p>If the record is opened with ‘w’, this function will truncate the file to empty.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXRecordIO</span><span class="p">(</span><span class="s1">'tmp.rec'</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">item</span> <span class="o">=</span> <span class="n">record</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">... </span> <span class="k">print</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="go">record_0</span>
<span class="go">record_1</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span> <span class="c1"># Pointer is reset.</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">record</span><span class="o">.</span><span class="n">read</span><span class="p">())</span> <span class="c1"># Started reading from start again.</span>
<span class="go">record_0</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="mxnet.recordio.MXRecordIO.write">
<code class="descname">write</code><span class="sig-paren">(</span><em>buf</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXRecordIO.write" title="Permalink to this definition"></a></dt>
<dd><p>Inserts a string buffer as a record.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXRecordIO</span><span class="p">(</span><span class="s1">'tmp.rec'</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">record</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'record_</span><span class="si">%d</span><span class="s1">'</span><span class="o">%</span><span class="n">i</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">close</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>buf</strong> (<em>string (python2), bytes (python3)</em>) – Buffer to write.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.recordio.MXRecordIO.read">
<code class="descname">read</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXRecordIO.read" title="Permalink to this definition"></a></dt>
<dd><p>Returns record as a string.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXRecordIO</span><span class="p">(</span><span class="s1">'tmp.rec'</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">item</span> <span class="o">=</span> <span class="n">record</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">... </span> <span class="k">print</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="go">record_0</span>
<span class="go">record_1</span>
<span class="go">record_2</span>
<span class="go">record_3</span>
<span class="go">record_4</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">close</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">Returns:</th><td class="field-body"><strong>buf</strong>
Buffer read.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">string</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.recordio.MXIndexedRecordIO">
<em class="property">class </em><code class="descclassname">mxnet.recordio.</code><code class="descname">MXIndexedRecordIO</code><span class="sig-paren">(</span><em>idx_path</em>, <em>uri</em>, <em>flag</em>, <em>key_type=<type 'int'></em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXIndexedRecordIO" title="Permalink to this definition"></a></dt>
<dd><p>Reads/writes <cite>RecordIO</cite> data format, supporting random access.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">record</span><span class="o">.</span><span class="n">write_idx</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s1">'record_</span><span class="si">%d</span><span class="s1">'</span><span class="o">%</span><span class="n">i</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXIndexedRecordIO</span><span class="p">(</span><span class="s1">'tmp.idx'</span><span class="p">,</span> <span class="s1">'tmp.rec'</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">read_idx</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">record_3</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>idx_path</strong> (<em>str</em>) – Path to the index file.</li>
<li><strong>uri</strong> (<em>str</em>) – Path to the record file. Only supports seekable file types.</li>
<li><strong>flag</strong> (<em>str</em>) – ‘w’ for write or ‘r’ for read.</li>
<li><strong>key_type</strong> (<a class="reference internal" href="kvstore.html#mxnet.kvstore.KVStore.type" title="mxnet.kvstore.KVStore.type"><em>type</em></a>) – Data type for keys.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mxnet.recordio.MXIndexedRecordIO.close">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXIndexedRecordIO.close" title="Permalink to this definition"></a></dt>
<dd><p>Closes the record file.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.recordio.MXIndexedRecordIO.seek">
<code class="descname">seek</code><span class="sig-paren">(</span><em>idx</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXIndexedRecordIO.seek" title="Permalink to this definition"></a></dt>
<dd><p>Sets the current read pointer position.</p>
<p>This function is internally called by <cite>read_idx(idx)</cite> to find the current
reader pointer position. It doesn’t return anything.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.recordio.MXIndexedRecordIO.tell">
<code class="descname">tell</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXIndexedRecordIO.tell" title="Permalink to this definition"></a></dt>
<dd><p>Returns the current position of write head.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXIndexedRecordIO</span><span class="p">(</span><span class="s1">'tmp.idx'</span><span class="p">,</span> <span class="s1">'tmp.rec'</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">record</span><span class="o">.</span><span class="n">tell</span><span class="p">())</span>
<span class="go">0</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">record</span><span class="o">.</span><span class="n">write_idx</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s1">'record_</span><span class="si">%d</span><span class="s1">'</span><span class="o">%</span><span class="n">i</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">print</span><span class="p">(</span><span class="n">record</span><span class="o">.</span><span class="n">tell</span><span class="p">())</span>
<span class="go">16</span>
<span class="go">32</span>
<span class="go">48</span>
<span class="go">64</span>
<span class="go">80</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="mxnet.recordio.MXIndexedRecordIO.read_idx">
<code class="descname">read_idx</code><span class="sig-paren">(</span><em>idx</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXIndexedRecordIO.read_idx" title="Permalink to this definition"></a></dt>
<dd><p>Returns the record at given index.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXIndexedRecordIO</span><span class="p">(</span><span class="s1">'tmp.idx'</span><span class="p">,</span> <span class="s1">'tmp.rec'</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">record</span><span class="o">.</span><span class="n">write_idx</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s1">'record_</span><span class="si">%d</span><span class="s1">'</span><span class="o">%</span><span class="n">i</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXIndexedRecordIO</span><span class="p">(</span><span class="s1">'tmp.idx'</span><span class="p">,</span> <span class="s1">'tmp.rec'</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">read_idx</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">record_3</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="mxnet.recordio.MXIndexedRecordIO.write_idx">
<code class="descname">write_idx</code><span class="sig-paren">(</span><em>idx</em>, <em>buf</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.MXIndexedRecordIO.write_idx" title="Permalink to this definition"></a></dt>
<dd><p>Inserts input record at given index.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">record</span><span class="o">.</span><span class="n">write_idx</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s1">'record_</span><span class="si">%d</span><span class="s1">'</span><span class="o">%</span><span class="n">i</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">record</span><span class="o">.</span><span class="n">close</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>idx</strong> (<em>int</em>) – Index of a file.</li>
<li><strong>buf</strong> – Record to write.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="attribute">
<dt id="mxnet.recordio.IRHeader">
<code class="descclassname">mxnet.recordio.</code><code class="descname">IRHeader</code><a class="headerlink" href="#mxnet.recordio.IRHeader" title="Permalink to this definition"></a></dt>
<dd><p>An alias for HEADER. Used to store metadata (e.g. labels) accompanying a record.
See mxnet.recordio.pack and mxnet.recordio.pack_img for example uses.</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>flag</strong> (<em>int</em>) – Available for convenience, can be set arbitrarily.</li>
<li><strong>label</strong> (<em>float or an array of float</em>) – Typically used to store label(s) for a record.</li>
<li><strong>id</strong> (<em>int</em>) – Usually a unique id representing record.</li>
<li><strong>id2</strong> (<em>int</em>) – Higher order bits of the unique id, should be set to 0 (in most cases).</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>alias of <code class="xref py py-class docutils literal"><span class="pre">HEADER</span></code></p>
</dd></dl>
<dl class="function">
<dt id="mxnet.recordio.pack">
<code class="descclassname">mxnet.recordio.</code><code class="descname">pack</code><span class="sig-paren">(</span><em>header</em>, <em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.pack" title="Permalink to this definition"></a></dt>
<dd><p>Pack a string into MXImageRecord.</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>header</strong> (<a class="reference internal" href="#mxnet.recordio.IRHeader" title="mxnet.recordio.IRHeader"><em>IRHeader</em></a>) – Header of the image record.
<code class="docutils literal"><span class="pre">header.label</span></code> can be a number or an array. See more detail in <code class="docutils literal"><span class="pre">IRHeader</span></code>.</li>
<li><strong>s</strong> (<em>str</em>) – Raw image string to be packed.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>s</strong>
The packed string.</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>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">label</span> <span class="o">=</span> <span class="mi">4</span> <span class="c1"># label can also be a 1-D array, for example: label = [1,2,3]</span>
<span class="gp">>>> </span><span class="nb">id</span> <span class="o">=</span> <span class="mi">2574</span>
<span class="gp">>>> </span><span class="n">header</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">IRHeader</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span> <span class="k">as</span> <span class="nb">file</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">s</span> <span class="o">=</span> <span class="nb">file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">packed_s</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">header</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.recordio.unpack">
<code class="descclassname">mxnet.recordio.</code><code class="descname">unpack</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.unpack" title="Permalink to this definition"></a></dt>
<dd><p>Unpack a MXImageRecord to string.</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>s</strong> (<em>str</em>) – String buffer from <code class="docutils literal"><span class="pre">MXRecordIO.read</span></code>.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><ul class="simple">
<li><strong>header</strong> (<em>IRHeader</em>) –
Header of the image record.</li>
<li><strong>s</strong> (<em>str</em>) –
Unpacked string.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXRecordIO</span><span class="p">(</span><span class="s1">'test.rec'</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">item</span> <span class="o">=</span> <span class="n">record</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">header</span><span class="p">,</span> <span class="n">s</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">header</span>
<span class="go">HEADER(flag=0, label=14.0, id=20129312, id2=0)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.recordio.unpack_img">
<code class="descclassname">mxnet.recordio.</code><code class="descname">unpack_img</code><span class="sig-paren">(</span><em>s</em>, <em>iscolor=-1</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.unpack_img" title="Permalink to this definition"></a></dt>
<dd><p>Unpack a MXImageRecord to image.</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>s</strong> (<em>str</em>) – String buffer from <code class="docutils literal"><span class="pre">MXRecordIO.read</span></code>.</li>
<li><strong>iscolor</strong> (<em>int</em>) – Image format option for <code class="docutils literal"><span class="pre">cv2.imdecode</span></code>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><ul class="simple">
<li><strong>header</strong> (<em>IRHeader</em>) –
Header of the image record.</li>
<li><strong>img</strong> (<em>numpy.ndarray</em>) –
Unpacked image.</li>
</ul>
</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">record</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">MXRecordIO</span><span class="p">(</span><span class="s1">'test.rec'</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">item</span> <span class="o">=</span> <span class="n">record</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">header</span><span class="p">,</span> <span class="n">img</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">unpack_img</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">header</span>
<span class="go">HEADER(flag=0, label=14.0, id=20129312, id2=0)</span>
<span class="gp">>>> </span><span class="n">img</span>
<span class="go">array([[[ 23, 27, 45],</span>
<span class="go"> [ 28, 32, 50],</span>
<span class="go"> ...,</span>
<span class="go"> [ 36, 40, 59],</span>
<span class="go"> [ 35, 39, 58]],</span>
<span class="go"> ...,</span>
<span class="go"> [[ 91, 92, 113],</span>
<span class="go"> [ 97, 98, 119],</span>
<span class="go"> ...,</span>
<span class="go"> [168, 169, 167],</span>
<span class="go"> [166, 167, 165]]], dtype=uint8)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="mxnet.recordio.pack_img">
<code class="descclassname">mxnet.recordio.</code><code class="descname">pack_img</code><span class="sig-paren">(</span><em>header</em>, <em>img</em>, <em>quality=95</em>, <em>img_fmt='.jpg'</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.recordio.pack_img" title="Permalink to this definition"></a></dt>
<dd><p>Pack an image into <code class="docutils literal"><span class="pre">MXImageRecord</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 simple">
<li><strong>header</strong> (<a class="reference internal" href="#mxnet.recordio.IRHeader" title="mxnet.recordio.IRHeader"><em>IRHeader</em></a>) – Header of the image record.
<code class="docutils literal"><span class="pre">header.label</span></code> can be a number or an array. See more detail in <code class="docutils literal"><span class="pre">IRHeader</span></code>.</li>
<li><strong>img</strong> (<em>numpy.ndarray</em>) – Image to be packed.</li>
<li><strong>quality</strong> (<em>int</em>) – Quality for JPEG encoding in range 1-100, or compression for PNG encoding in range 1-9.</li>
<li><strong>img_fmt</strong> (<em>str</em>) – Encoding of the image (.jpg for JPEG, .png for PNG).</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>s</strong>
The packed string.</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>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">label</span> <span class="o">=</span> <span class="mi">4</span> <span class="c1"># label can also be a 1-D array, for example: label = [1,2,3]</span>
<span class="gp">>>> </span><span class="nb">id</span> <span class="o">=</span> <span class="mi">2574</span>
<span class="gp">>>> </span><span class="n">header</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">IRHeader</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">img</span> <span class="o">=</span> <span class="n">cv2</span><span class="o">.</span><span class="n">imread</span><span class="p">(</span><span class="s1">'test.jpg'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">packed_s</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">recordio</span><span class="o">.</span><span class="n">pack_img</span><span class="p">(</span><span class="n">header</span><span class="p">,</span> <span class="n">img</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<script>auto_index("api-reference");</script></div>
</div>
<div class="container">
<div class="footer">
<p> © 2015-2017 DMLC. All rights reserved. </p>
</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="#">Data Loading API</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#data-iterators">Data iterators</a></li>
<li><a class="reference internal" href="#helper-classes-and-functions">Helper classes and functions</a></li>
<li><a class="reference internal" href="#develop-a-new-iterator">Develop a new iterator</a><ul>
<li><a class="reference internal" href="#change-batch-layout">Change batch layout</a></li>
</ul>
</li>
<li><a class="reference internal" href="#api-reference">API Reference</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- pagename != index -->
<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 type="text/javascript">
$('body').ready(function () {
$('body').css('visibility', 'visible');
});
</script>
</div></body>
</html>