blob: 33a86fab8a74fabdef674a166bea069af3c90e8b [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>Performance Test and Feature Extraction &mdash; incubator-singa 0.3.0 documentation</title>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="top" title="incubator-singa 0.3.0 documentation" href="../index.html"/>
<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">
0.3.0
</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 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>Performance Test and Feature Extraction</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="performance-test-and-feature-extraction">
<span id="performance-test-and-feature-extraction"></span><h1>Performance Test and Feature Extraction<a class="headerlink" href="#performance-test-and-feature-extraction" title="Permalink to this headline"></a></h1>
<hr class="docutils" />
<p>Once SINGA finishes the training of a model, it would checkpoint the model parameters
into disk files under the <a class="reference external" href="checkpoint.html">checkpoint folder</a>. Model parameters can also be dumped
into this folder periodically during training if the
[checkpoint configuration[(checkpoint.html) fields are set. With the checkpoint
files, we can load the model parameters to conduct performance test, feature extraction and prediction
against new data.</p>
<p>To load the model parameters from checkpoint files, we need to add the paths of
checkpoint files in the job configuration file</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">checkpoint_path</span><span class="p">:</span> <span class="n">PATH_TO_CHECKPOINT_FILE1</span>
<span class="n">checkpoint_path</span><span class="p">:</span> <span class="n">PATH_TO_CHECKPOINT_FILE2</span>
<span class="o">...</span>
</pre></div>
</div>
<p>The new dataset is configured by specifying the <code class="docutils literal"><span class="pre">test_step</span></code> and the data input
layer, e.g. the following configuration is for a dataset with 100*100 instances.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">test_steps</span><span class="p">:</span> <span class="mi">100</span>
<span class="n">net</span> <span class="p">{</span>
<span class="n">layer</span> <span class="p">{</span>
<span class="n">name</span><span class="p">:</span> <span class="s2">&quot;input&quot;</span>
<span class="n">store_conf</span> <span class="p">{</span>
<span class="n">backend</span><span class="p">:</span> <span class="s2">&quot;kvfile&quot;</span>
<span class="n">path</span><span class="p">:</span> <span class="n">PATH_TO_TEST_KVFILE</span>
<span class="n">batchsize</span><span class="p">:</span> <span class="mi">100</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="o">...</span>
<span class="p">}</span>
</pre></div>
</div>
<div class="section" id="performance-test">
<span id="performance-test"></span><h2>Performance Test<a class="headerlink" href="#performance-test" title="Permalink to this headline"></a></h2>
<p>This application is to test the performance, e.g., accuracy, of the previously
trained model. Depending on the application, the test data may have ground truth
labels or not. For example, if the model is trained for image classification,
the test images must have ground truth labels to calculate the accuracy; if the
model is an auto-encoder, the performance could be measured by reconstruction error, which
does not require extra labels. For both cases, there would be a layer that calculates
the performance, e.g., the <code class="docutils literal"><span class="pre">SoftmaxLossLayer</span></code>.</p>
<p>The job configuration file for the cifar10 example can be used directly for testing after
adding the checkpoint path. The running command is</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ ./bin/singa-run.sh -conf examples/cifar10/job.conf -test
</pre></div>
</div>
<p>The performance would be output on the screen like,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Load</span> <span class="kn">from</span> <span class="nn">checkpoint</span> <span class="n">file</span> <span class="n">examples</span><span class="o">/</span><span class="n">cifar10</span><span class="o">/</span><span class="n">checkpoint</span><span class="o">/</span><span class="n">step50000</span><span class="o">-</span><span class="n">worker0</span>
<span class="n">accuracy</span> <span class="o">=</span> <span class="mf">0.728000</span><span class="p">,</span> <span class="n">loss</span> <span class="o">=</span> <span class="mf">0.807645</span>
</pre></div>
</div>
</div>
<div class="section" id="feature-extraction">
<span id="feature-extraction"></span><h2>Feature extraction<a class="headerlink" href="#feature-extraction" title="Permalink to this headline"></a></h2>
<p>Since deep learning models are good at learning features, feature extraction for
is a major functionality of deep learning models, e.g., we can extract features
from the fully connected layers of <a class="reference external" href="www.cs.toronto.edu/~fritz/absps/imagenet.pdf">AlexNet</a> as image features for image retrieval.
To extract the features from one layer, we simply add an output layer after that layer.
For instance, to extract the fully connected (with name <code class="docutils literal"><span class="pre">ip1</span></code>) layer of the cifar10 example model,
we replace the <code class="docutils literal"><span class="pre">SoftmaxLossLayer</span></code> with a <code class="docutils literal"><span class="pre">CSVOutputLayer</span></code> which extracts the features into a CSV file,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">layer</span> <span class="p">{</span>
<span class="n">name</span><span class="p">:</span> <span class="s2">&quot;ip1&quot;</span>
<span class="p">}</span>
<span class="n">layer</span> <span class="p">{</span>
<span class="n">name</span><span class="p">:</span> <span class="s2">&quot;output&quot;</span>
<span class="nb">type</span><span class="p">:</span> <span class="n">kCSVOutput</span>
<span class="n">srclayers</span><span class="p">:</span> <span class="s2">&quot;ip1&quot;</span>
<span class="n">store_conf</span> <span class="p">{</span>
<span class="n">backend</span><span class="p">:</span> <span class="s2">&quot;textfile&quot;</span>
<span class="n">path</span><span class="p">:</span> <span class="n">OUTPUT_FILE_PATH</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The input layer and test steps, and the running command are the same as in <em>Performance Test</em> section.</p>
</div>
<div class="section" id="label-prediction">
<span id="label-prediction"></span><h2>Label Prediction<a class="headerlink" href="#label-prediction" title="Permalink to this headline"></a></h2>
<p>If the output layer is connected to a layer that predicts labels of images,
the output layer would then write the prediction results into files.
SINGA provides two built-in layers for generating prediction results, namely,</p>
<ul class="simple">
<li>SoftmaxLayer, generates probabilities of each candidate labels.</li>
<li>ArgSortLayer, sorts labels according to probabilities in descending order and keep topk labels.</li>
</ul>
<p>By connecting the two layers with the previous layer and the output layer, we can
extract the predictions of each instance. For example,</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">layer</span> <span class="p">{</span>
<span class="n">name</span><span class="p">:</span> <span class="s2">&quot;feature&quot;</span>
<span class="o">...</span>
<span class="p">}</span>
<span class="n">layer</span> <span class="p">{</span>
<span class="n">name</span><span class="p">:</span> <span class="s2">&quot;softmax&quot;</span>
<span class="nb">type</span><span class="p">:</span> <span class="n">kSoftmax</span>
<span class="n">srclayers</span><span class="p">:</span> <span class="s2">&quot;feature&quot;</span>
<span class="p">}</span>
<span class="n">layer</span> <span class="p">{</span>
<span class="n">name</span><span class="p">:</span> <span class="s2">&quot;prediction&quot;</span>
<span class="nb">type</span><span class="p">:</span> <span class="n">kArgSort</span>
<span class="n">srclayers</span><span class="p">:</span> <span class="s2">&quot;softmax&quot;</span>
<span class="n">argsort_conf</span> <span class="p">{</span>
<span class="n">topk</span><span class="p">:</span> <span class="mi">5</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">layer</span> <span class="p">{</span>
<span class="n">name</span><span class="p">:</span> <span class="s2">&quot;output&quot;</span>
<span class="nb">type</span><span class="p">:</span> <span class="n">kCSVOutput</span>
<span class="n">srclayers</span><span class="p">:</span> <span class="s2">&quot;prediction&quot;</span>
<span class="n">store_conf</span> <span class="p">{}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The top-5 labels of each instance will be written as one line of the output CSV file.
Currently, above layers cannot co-exist with the loss layers used for training.
Please comment out the loss layers for extracting prediction results.</p>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2016 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:'0.3.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">
<img src="../_static/apache.jpg">
<span class="rst-current-version" data-toggle="rst-current-version">
<span class="fa fa-book"> incubator-singa </span>
v: 0.3.0
<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>
<dd><a href="../../jp/index.html">日本語</a></dd>
<dd><a href="../../kr/index.html">한국어</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>