blob: 83a5bc771cfb6b636b78686e4962425961c3ad88 [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Train CNN over Cifar-10 &mdash; incubator-singa 1.1.0 documentation</title>
<link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
<link rel="top" title="incubator-singa 1.1.0 documentation" href="../../../../index.html"/>
<link href="../../../../_static/style.css" rel="stylesheet" type="text/css">
<script src="../../../../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="../../../../index.html" class="icon icon-home"> incubator-singa
<img src="../../../../_static/singa.png" class="logo" />
</a>
<div class="version">
1.1
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../downloads.html">Download SINGA</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../index.html">Documentation</a></li>
</ul>
<p class="caption"><span class="caption-text">Development</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../develop/schedule.html">Development Schedule</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../develop/how-contribute.html">How to Contribute to SINGA</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../develop/contribute-code.html">How to Contribute Code</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../develop/contribute-docs.html">How to Contribute to Documentation</a></li>
</ul>
<p class="caption"><span class="caption-text">Community</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../community/source-repository.html">Source Repository</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../community/mail-lists.html">Project Mailing Lists</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../community/issue-tracking.html">Issue Tracking</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../community/team-list.html">The SINGA Team</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../../index.html">incubator-singa</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../../index.html">Docs</a> &raquo;</li>
<li>Train CNN over Cifar-10</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="train-cnn-over-cifar-10">
<span id="train-cnn-over-cifar-10"></span><h1>Train CNN over Cifar-10<a class="headerlink" href="#train-cnn-over-cifar-10" title="Permalink to this headline"></a></h1>
<p>Convolution neural network (CNN) is a type of feed-forward artificial neural
network widely used for image and video classification. In this example, we
will train three deep CNN models to do image classification for the CIFAR-10 dataset,</p>
<ol class="simple">
<li><a class="reference external" href="https://code.google.com/p/cuda-convnet/source/browse/trunk/example-layers/layers-18pct.cfg">AlexNet</a>
the best validation accuracy (without data augmentation) we achieved was about 82%.</li>
<li><a class="reference external" href="http://torch.ch/blog/2015/07/30/cifar.html">VGGNet</a>, the best validation accuracy (without data augmentation) we achieved was about 89%.</li>
<li><a class="reference external" href="https://github.com/facebook/fb.resnet.torch">ResNet</a>, the best validation accuracy (without data augmentation) we achieved was about 83%.</li>
<li><a class="reference external" href="https://github.com/BVLC/caffe/tree/master/examples/cifar10">Alexnet from Caffe</a>, SINGA is able to convert model from Caffe seamlessly.</li>
</ol>
<div class="section" id="instructions">
<span id="instructions"></span><h2>Instructions<a class="headerlink" href="#instructions" title="Permalink to this headline"></a></h2>
<div class="section" id="singa-installation">
<span id="singa-installation"></span><h3>SINGA installation<a class="headerlink" href="#singa-installation" title="Permalink to this headline"></a></h3>
<p>Users can compile and install SINGA from source or install the Python version.
The code can ran on both CPU and GPU. For GPU training, CUDA and CUDNN (V4 or V5)
are required. Please refer to the installation page for detailed instructions.</p>
</div>
<div class="section" id="data-preparation">
<span id="data-preparation"></span><h3>Data preparation<a class="headerlink" href="#data-preparation" title="Permalink to this headline"></a></h3>
<p>The binary Cifar-10 dataset could be downloaded by</p>
<div class="highlight-python"><div class="highlight"><pre>python download_data.py bin
</pre></div>
</div>
<p>The Python version could be downloaded by</p>
<div class="highlight-python"><div class="highlight"><pre>python download_data.py py
</pre></div>
</div>
</div>
<div class="section" id="training">
<span id="training"></span><h3>Training<a class="headerlink" href="#training" title="Permalink to this headline"></a></h3>
<p>There are four training programs</p>
<ol>
<li><p class="first">train.py. The following command would train the VGG model using the python
version of the Cifar-10 dataset in &#8216;cifar-10-batches-py&#8217; folder.</p>
<div class="highlight-python"><div class="highlight"><pre> python train.py vgg cifar-10-batches-py
</pre></div>
</div>
<p>To train other models, please replace &#8216;vgg&#8217; to &#8216;alexnet&#8217;, &#8216;resnet&#8217; or &#8216;caffe&#8217;,
where &#8216;caffe&#8217; refers to the alexnet model converted from Caffe. By default
the training would run on a CudaGPU device, to run it on CppCPU, add an additional
argument</p>
<div class="highlight-python"><div class="highlight"><pre> python train.py vgg cifar-10-batches-py --use_cpu
</pre></div>
</div>
</li>
<li><p class="first">alexnet.cc. It trains the AlexNet model using the CPP APIs on a CudaGPU,</p>
<div class="highlight-python"><div class="highlight"><pre> ./run.sh
</pre></div>
</div>
</li>
<li><p class="first">alexnet-parallel.cc. It trains the AlexNet model using the CPP APIs on two CudaGPU devices.
The two devices run synchronously to compute the gradients of the mode parameters, which are
averaged on the host CPU device and then be applied to update the parameters.</p>
<div class="highlight-python"><div class="highlight"><pre> ./run-parallel.sh
</pre></div>
</div>
</li>
<li><p class="first">vgg-parallel.cc. It trains the VGG model using the CPP APIs on two CudaGPU devices similar to alexnet-parallel.cc.</p>
</li>
</ol>
</div>
<div class="section" id="prediction">
<span id="prediction"></span><h3>Prediction<a class="headerlink" href="#prediction" title="Permalink to this headline"></a></h3>
<p>predict.py includes the prediction function</p>
<div class="highlight-python"><div class="highlight"><pre> def predict(net, images, dev, topk=5)
</pre></div>
</div>
<p>The net is created by loading the previously trained model; Images consist of
a numpy array of images (one row per image); dev is the training device, e.g.,
a CudaGPU device or the host CppCPU device; It returns the topk labels for each instance.</p>
<p>The predict.py file&#8217;s main function provides an example of using the pre-trained alexnet model to do prediction for new images.
The &#8216;model.bin&#8217; file generated by the training program should be placed at the cifar10 folder to run</p>
<div class="highlight-python"><div class="highlight"><pre> python predict.py
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2017 The Apache Software Foundation. All rights reserved. Apache Singa, Apache, the Apache feather logo, and the Apache Singa project logos are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners..
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../../../',
VERSION:'1.1.0',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</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="../../../../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
<div class="rst-versions shift-up" data-toggle="rst-versions" role="note" aria-label="versions">
<a href="http://incubator.apache.org/">
<img src= "../../../../_static/apache.jpg">
</a>
<span class="rst-current-version" data-toggle="rst-current-version">
<span class="fa fa-book"> incubator-singa </span>
v: 1.1
<span class="fa fa-caret-down"></span>
</span>
<div class="rst-other-versions">
<dl>
<dt>Languages</dt>
<dd><a href="../../../../../en/index.html">English</a></dd>
<dd><a href="../../../../../zh/index.html">中文</a></dd>
</dl>
<dl>
<dt>Versions</dt>
<dd><a href="http://singa.apache.org/v0.3.0/">0.3</a></dd>
</dl>
</div>
</div>
<a href="https://github.com/apache/incubator-singa">
<img style="position: absolute; top: 0; right: 0; border: 0; z-index: 10000;"
src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"
alt="Fork me on GitHub">
</a>
</body>
</html>