resnet_model.html 31.5 KB
Newer Older
Y
Yu Yang 已提交
1 2 3 4 5 6 7 8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
9
    <title>Model Zoo - ImageNet &#8212; PaddlePaddle  documentation</title>
Y
Yu Yang 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    
    <link rel="stylesheet" href="../../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '',
        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="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="PaddlePaddle  documentation" href="../../index.html" />
    <link rel="up" title="Examples and demos" href="../index.html" />
    <link rel="next" title="Chinese Word Embedding Model Tutorial" href="../embedding_model/index.html" />
    <link rel="prev" title="Regression MovieLens Ratting" href="../rec/ml_regression.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../embedding_model/index.html" title="Chinese Word Embedding Model Tutorial"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="../rec/ml_regression.html" title="Regression MovieLens Ratting"
             accesskey="P">previous</a> |</li>
48 49
        <li class="nav-item nav-item-0"><a href="../../index.html">PaddlePaddle  documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Examples and demos</a> &#187;</li> 
Y
Yu Yang 已提交
50 51 52 53 54 55 56 57 58 59
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="model-zoo-imagenet">
<span id="model-zoo-imagenet"></span><h1>Model Zoo - ImageNet<a class="headerlink" href="#model-zoo-imagenet" title="Permalink to this headline"></a></h1>
Y
Yu Yang 已提交
60
<p><a class="reference external" href="http://www.image-net.org/">ImageNet</a> is a popular dataset for generic object classification. This tutorial provides convolutional neural network(CNN) models for ImageNet.</p>
Y
Yu Yang 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
<div class="section" id="resnet-introduction">
<span id="resnet-introduction"></span><h2>ResNet Introduction<a class="headerlink" href="#resnet-introduction" title="Permalink to this headline"></a></h2>
<p>ResNets from paper <a class="reference external" href="http://arxiv.org/abs/1512.03385">Deep Residual Learning for Image Recognition</a> won the 1st place on the ILSVRC 2015 classification task. They present residual learning framework to ease the training of networks that are substantially deeper than those used previously. The residual connections are shown in following figure. The left building block is used in network of 34 layers and the right bottleneck building block is used in network of 50, 101, 152 layers .</p>
<p><center><img alt="resnet_block" src="../../_images/resnet_block.jpg" /></center>
<center>Figure 1. ResNet Block</center></p>
<p>We present three ResNet models, which are converted from the models provided by the authors <a class="reference external" href="https://github.com/KaimingHe/deep-residual-networks">https://github.com/KaimingHe/deep-residual-networks</a>.  The classfication errors tested in PaddlePaddle on 50,000 ILSVRC validation set with input images channel order of <strong>BGR</strong> by single scale with the shorter side of 256 and single crop as following table.
<center></p>
<table border="2" cellspacing="0" cellpadding="6" rules="all" frame="border">
<colgroup>
<col  class="left" />
<col  class="left" />
<col  class="left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="left">ResNet</th>
<th scope="col" class="left">Top-1</th>
<th scope="col" class="left">Model Size</th>
</tr>
</thead><tbody>
<tr>
<td class="left">ResNet-50</td>
<td class="left">24.9%</td>
<td class="left">99M</td>
</tr>
<tr>
<td class="left">ResNet-101</td>
<td class="left">23.7%</td>
<td class="left">173M</td>
</tr>
<tr>
<td class="left">ResNet-152</td>
<td class="left">23.2%</td>
<td class="left">234M</td>
</tr>
</tbody></table></center>
<br></div>
<div class="section" id="resnet-model">
<span id="resnet-model"></span><h2>ResNet Model<a class="headerlink" href="#resnet-model" title="Permalink to this headline"></a></h2>
Y
Yu Yang 已提交
100
<p>See <code class="docutils literal"><span class="pre">demo/model_zoo/resnet/resnet.py</span></code>. This config contains network of 50, 101 and 152 layers. You can specify layer number by adding argument like <code class="docutils literal"><span class="pre">--config_args=layer_num=50</span></code> in command line arguments.</p>
Y
Yu Yang 已提交
101 102
<div class="section" id="network-visualization">
<span id="network-visualization"></span><h3>Network Visualization<a class="headerlink" href="#network-visualization" title="Permalink to this headline"></a></h3>
Y
Yu Yang 已提交
103
<p>You can get a diagram of ResNet network by running the following commands. The script generates dot file and then converts dot file to PNG file, which uses installed draw_dot tool in our server. If you can not access the server, just install graphviz to convert dot file.</p>
104 105
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="n">demo</span><span class="o">/</span><span class="n">model_zoo</span><span class="o">/</span><span class="n">resnet</span>
<span class="o">./</span><span class="n">net_diagram</span><span class="o">.</span><span class="n">sh</span>
Y
Yu Yang 已提交
106 107 108 109 110
</pre></div>
</div>
</div>
<div class="section" id="model-download">
<span id="model-download"></span><h3>Model Download<a class="headerlink" href="#model-download" title="Permalink to this headline"></a></h3>
111 112
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="n">demo</span><span class="o">/</span><span class="n">model_zoo</span><span class="o">/</span><span class="n">resnet</span>
<span class="o">./</span><span class="n">get_model</span><span class="o">.</span><span class="n">sh</span>
Y
Yu Yang 已提交
113 114 115
</pre></div>
</div>
<p>You can run above command to download all models and mean file and save them in <code class="docutils literal"><span class="pre">demo/model_zoo/resnet/model</span></code> if downloading successfully.</p>
116
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">mean_meta_224</span>  <span class="n">resnet_101</span>  <span class="n">resnet_152</span>  <span class="n">resnet_50</span>
Y
Yu Yang 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
</pre></div>
</div>
<ul class="simple">
<li>resnet_50: model of 50 layers.</li>
<li>resnet_101: model of 101 layers.</li>
<li>resnet_152: model of 152 layers.</li>
<li>mean_meta_224: mean file with 3 x 224 x 224 size in <strong>BGR</strong> order. You also can use three mean values: 103.939, 116.779, 123.68.</li>
</ul>
</div>
<div class="section" id="parameter-info">
<span id="parameter-info"></span><h3>Parameter Info<a class="headerlink" href="#parameter-info" title="Permalink to this headline"></a></h3>
<ul>
<li><p class="first"><strong>Convolution Layer Weight</strong></p>
<p>As batch normalization layer is connected after each convolution layer, there is no parameter of bias and only one weight in this layer.
shape: <code class="docutils literal"><span class="pre">(Co,</span> <span class="pre">ky,</span> <span class="pre">kx,</span> <span class="pre">Ci)</span></code></p>
<ul class="simple">
<li>Co: channle number of output feature map.</li>
<li>ky: filter size in vertical direction.</li>
<li>kx: filter size in horizontal direction.</li>
<li>Ci: channle number of input feature map.</li>
</ul>
<p>2-Dim matrix: (Co * ky * kx, Ci), saved in row-major order.</p>
</li>
<li><p class="first"><strong>Fully connected Layer Weight</strong></p>
<p>2-Dim matrix: (input layer size, this layer size), saved in row-major order.</p>
</li>
<li><p class="first"><strong><a class="reference external" href="http://arxiv.org/abs/1502.03167">Batch Normalization</a> Layer Weight</strong></p>
</li>
</ul>
<p>There are four parameters in this layer. In fact, only .w0 and .wbias are the learned parameters. The other two are therunning mean and variance respectively. They will be loaded in testing. Following table shows parameters of a batch normzalization layer.
<center></p>
<table border="2" cellspacing="0" cellpadding="6" rules="all" frame="border">
<colgroup>
<col  class="left" />
<col  class="left" />
<col  class="left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="left">Parameter Name</th>
<th scope="col" class="left">Number</th>
<th scope="col" class="left">Meaning</th>
</tr>
</thead><tbody>
<tr>
<td class="left">_res2_1_branch1_bn.w0</td>
<td class="left">256</td>
<td class="left">gamma, scale parameter</td>
</tr>
<tr>
<td class="left">_res2_1_branch1_bn.w1</td>
<td class="left">256</td>
<td class="left">mean value of feature map</td>
</tr>
<tr>
<td class="left">_res2_1_branch1_bn.w2</td>
<td class="left">256</td>
<td class="left">variance of feature map</td>
</tr>
<tr>
<td class="left">_res2_1_branch1_bn.wbias</td>
<td class="left">256</td>
<td class="left">beta, shift parameter</td>
</tr>
</tbody></table></center>
<br></div>
<div class="section" id="parameter-observation">
<span id="parameter-observation"></span><h3>Parameter Observation<a class="headerlink" href="#parameter-observation" title="Permalink to this headline"></a></h3>
<p>Users who want to observe the parameters can use python to read:</p>
186 187
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
Y
Yu Yang 已提交
188 189 190 191 192 193 194 195 196 197 198

<span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="n">file_name</span><span class="p">):</span>
    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
        <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span> <span class="c1"># skip header for float type.</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>

<span class="k">if</span> <span class="n">__name__</span><span class="o">==</span><span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">weight</span> <span class="o">=</span> <span class="n">load</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
</pre></div>
</div>
<p>or simply use following shell command:</p>
199
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">od</span> <span class="o">-</span><span class="n">j</span> <span class="mi">16</span> <span class="o">-</span><span class="n">f</span> <span class="n">_res2_1_branch1_bn</span><span class="o">.</span><span class="n">w0</span>
Y
Yu Yang 已提交
200 201 202 203 204 205 206 207 208
</pre></div>
</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>We provide both C++ and Python interfaces to extract features. The following examples use data in <code class="docutils literal"><span class="pre">demo/model_zoo/resnet/example</span></code> to show the extracting process in detail.</p>
<div class="section" id="c-interface">
<span id="c-interface"></span><h3>C++ Interface<a class="headerlink" href="#c-interface" title="Permalink to this headline"></a></h3>
209 210
<p>First, specify image data list in <code class="docutils literal"><span class="pre">define_py_data_sources2</span></code> in the config, see example <code class="docutils literal"><span class="pre">demo/model_zoo/resnet/resnet.py</span></code>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>    <span class="n">train_list</span> <span class="o">=</span> <span class="s1">&#39;train.list&#39;</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">is_test</span> <span class="k">else</span> <span class="kc">None</span>
Y
Yu Yang 已提交
211 212 213 214 215 216 217
    <span class="c1"># mean.meta is mean file of ImageNet dataset.</span>
    <span class="c1"># mean.meta size : 3 x 224 x 224.</span>
    <span class="c1"># If you use three mean value, set like:</span>
    <span class="c1"># &quot;mean_value:103.939,116.779,123.68;&quot;</span>
    <span class="n">args</span><span class="o">=</span><span class="p">{</span>
        <span class="s1">&#39;mean_meta&#39;</span><span class="p">:</span> <span class="s2">&quot;model/mean_meta_224/mean.meta&quot;</span><span class="p">,</span>
        <span class="s1">&#39;image_size&#39;</span><span class="p">:</span> <span class="mi">224</span><span class="p">,</span> <span class="s1">&#39;crop_size&#39;</span><span class="p">:</span> <span class="mi">224</span><span class="p">,</span>
218
        <span class="s1">&#39;color&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span><span class="s1">&#39;swap_channel:&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]}</span>
Y
Yu Yang 已提交
219 220 221 222 223 224 225 226
    <span class="n">define_py_data_sources2</span><span class="p">(</span><span class="n">train_list</span><span class="p">,</span>
                           <span class="s1">&#39;example/test.list&#39;</span><span class="p">,</span>
                           <span class="n">module</span><span class="o">=</span><span class="s2">&quot;example.image_list_provider&quot;</span><span class="p">,</span>
                           <span class="n">obj</span><span class="o">=</span><span class="s2">&quot;processData&quot;</span><span class="p">,</span>
                           <span class="n">args</span><span class="o">=</span><span class="n">args</span><span class="p">)</span>
</pre></div>
</div>
<p>Second, specify layers to extract features in <code class="docutils literal"><span class="pre">Outputs()</span></code> of <code class="docutils literal"><span class="pre">resnet.py</span></code>. For example,</p>
227
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Outputs</span><span class="p">(</span><span class="s2">&quot;res5_3_branch2c_conv&quot;</span><span class="p">,</span> <span class="s2">&quot;res5_3_branch2c_bn&quot;</span><span class="p">)</span>
Y
Yu Yang 已提交
228 229
</pre></div>
</div>
Y
Yu Yang 已提交
230
<p>Third, specify model path and output directory in <code class="docutils literal"><span class="pre">extract_fea_c++.sh</span></code>, and then run the following commands.</p>
231 232
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="n">demo</span><span class="o">/</span><span class="n">model_zoo</span><span class="o">/</span><span class="n">resnet</span>
<span class="o">./</span><span class="n">extract_fea_c</span><span class="o">++.</span><span class="n">sh</span>
Y
Yu Yang 已提交
233 234 235
</pre></div>
</div>
<p>If successful, features are saved in <code class="docutils literal"><span class="pre">fea_output/rank-00000</span></code> as follows. And you can use <code class="docutils literal"><span class="pre">load_feature_c</span></code> interface in <code class="docutils literal"><span class="pre">load_feature.py</span></code> to load such a file.</p>
236 237
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">-</span><span class="mf">0.115318</span> <span class="o">-</span><span class="mf">0.108358</span> <span class="o">...</span> <span class="o">-</span><span class="mf">0.087884</span><span class="p">;</span><span class="o">-</span><span class="mf">1.27664</span> <span class="o">...</span> <span class="o">-</span><span class="mf">1.11516</span> <span class="o">-</span><span class="mf">2.59123</span><span class="p">;</span>
<span class="o">-</span><span class="mf">0.126383</span> <span class="o">-</span><span class="mf">0.116248</span> <span class="o">...</span> <span class="o">-</span><span class="mf">0.00534909</span><span class="p">;</span><span class="o">-</span><span class="mf">1.42593</span> <span class="o">...</span> <span class="o">-</span><span class="mf">1.04501</span> <span class="o">-</span><span class="mf">1.40769</span><span class="p">;</span>
Y
Yu Yang 已提交
238 239 240 241 242 243 244 245 246 247
</pre></div>
</div>
<ul class="simple">
<li>Each line stores features of a sample. Here, the first line stores features of <code class="docutils literal"><span class="pre">example/dog.jpg</span></code> and second line stores features of <code class="docutils literal"><span class="pre">example/cat.jpg</span></code>.</li>
<li>Features of different layers are splitted by <code class="docutils literal"><span class="pre">;</span></code>, and their order is consistent with the layer order in <code class="docutils literal"><span class="pre">Outputs()</span></code>. Here, the left features are <code class="docutils literal"><span class="pre">res5_3_branch2c_conv</span></code> layer and right features are <code class="docutils literal"><span class="pre">res5_3_branch2c_bn</span></code> layer.</li>
</ul>
</div>
<div class="section" id="python-interface">
<span id="python-interface"></span><h3>Python Interface<a class="headerlink" href="#python-interface" title="Permalink to this headline"></a></h3>
<p><code class="docutils literal"><span class="pre">demo/model_zoo/resnet/classify.py</span></code> is an example to show how to use python to extract features. Following example still uses data of <code class="docutils literal"><span class="pre">./example/test.list</span></code>. Command is as follows:</p>
248 249
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="n">demo</span><span class="o">/</span><span class="n">model_zoo</span><span class="o">/</span><span class="n">resnet</span>
<span class="o">./</span><span class="n">extract_fea_py</span><span class="o">.</span><span class="n">sh</span>
Y
Yu Yang 已提交
250 251 252
</pre></div>
</div>
<p>extract_fea_py.sh:</p>
253 254 255 256 257 258 259 260 261
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">classify</span><span class="o">.</span><span class="n">py</span> \
     <span class="o">--</span><span class="n">job</span><span class="o">=</span><span class="n">extract</span> \
     <span class="o">--</span><span class="n">conf</span><span class="o">=</span><span class="n">resnet</span><span class="o">.</span><span class="n">py</span>\
     <span class="o">--</span><span class="n">use_gpu</span><span class="o">=</span><span class="mi">1</span> \
     <span class="o">--</span><span class="n">mean</span><span class="o">=</span><span class="n">model</span><span class="o">/</span><span class="n">mean_meta_224</span><span class="o">/</span><span class="n">mean</span><span class="o">.</span><span class="n">meta</span> \
     <span class="o">--</span><span class="n">model</span><span class="o">=</span><span class="n">model</span><span class="o">/</span><span class="n">resnet_50</span> \
     <span class="o">--</span><span class="n">data</span><span class="o">=./</span><span class="n">example</span><span class="o">/</span><span class="n">test</span><span class="o">.</span><span class="n">list</span> \
     <span class="o">--</span><span class="n">output_layer</span><span class="o">=</span><span class="s2">&quot;res5_3_branch2c_conv,res5_3_branch2c_bn&quot;</span> \
     <span class="o">--</span><span class="n">output_dir</span><span class="o">=</span><span class="n">features</span>
Y
Yu Yang 已提交
262 263 264
</pre></div>
</div>
<ul class="simple">
Y
Yu Yang 已提交
265 266 267 268 269 270 271
<li>--job=extract:              specify job mode to extract feature.</li>
<li>--conf=resnet.py:           network configure.</li>
<li>--use_gpu=1:             speficy GPU mode.</li>
<li>--model=model/resnet_5:     model path.</li>
<li>--data=./example/test.list: data list.</li>
<li>--output_layer=&#8221;xxx,xxx&#8221;:   specify layers to extract features.</li>
<li>--output_dir=features:      output diretcoty.</li>
Y
Yu Yang 已提交
272
</ul>
Y
Yu Yang 已提交
273
<p>Note, since the convolution layer in these ResNet models is suitable for the cudnn implementation which only support GPU. It not support CPU mode because of compatibility issue and we will fix later.</p>
Y
Yu Yang 已提交
274
<p>If run successfully, you will see features saved in <code class="docutils literal"><span class="pre">features/batch_0</span></code>, this file is produced with cPickle. You can use <code class="docutils literal"><span class="pre">load_feature_py</span></code> interface in <code class="docutils literal"><span class="pre">load_feature.py</span></code> to open the file, and it returns a dictionary as follows:</p>
275
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
Y
Yu Yang 已提交
276 277 278 279 280 281 282 283 284 285 286
<span class="s1">&#39;cat.jpg&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;res5_3_branch2c_conv&#39;</span><span class="p">:</span> <span class="n">array</span><span class="p">([[</span><span class="o">-</span><span class="mf">0.12638293</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.116248</span>  <span class="p">,</span> <span class="o">-</span><span class="mf">0.11883899</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.00895038</span><span class="p">,</span> <span class="mf">0.01994277</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.00534909</span><span class="p">]],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">float32</span><span class="p">),</span> <span class="s1">&#39;res5_3_branch2c_bn&#39;</span><span class="p">:</span> <span class="n">array</span><span class="p">([[</span><span class="o">-</span><span class="mf">1.42593431</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.28918779</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.32414699</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.45933616</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.04501402</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.40769434</span><span class="p">]],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">float32</span><span class="p">)},</span>
<span class="s1">&#39;dog.jpg&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;res5_3_branch2c_conv&#39;</span><span class="p">:</span> <span class="n">array</span><span class="p">([[</span><span class="o">-</span><span class="mf">0.11531784</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.10835785</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.08809858</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span><span class="mf">0.0055237</span><span class="p">,</span> <span class="mf">0.01505112</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.08788397</span><span class="p">]],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">float32</span><span class="p">),</span> <span class="s1">&#39;res5_3_branch2c_bn&#39;</span><span class="p">:</span> <span class="n">array</span><span class="p">([[</span><span class="o">-</span><span class="mf">1.27663755</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.18272924</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.90937918</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.25178063</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.11515927</span><span class="p">,</span> <span class="o">-</span><span class="mf">2.59122872</span><span class="p">]],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">float32</span><span class="p">)}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Observed carefully, these feature values are consistent with the above results extracted by C++ interface.</p>
</div>
</div>
<div class="section" id="prediction">
<span id="prediction"></span><h2>Prediction<a class="headerlink" href="#prediction" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">classify.py</span></code> also can be used to predict. We provide an example script <code class="docutils literal"><span class="pre">predict.sh</span></code> to predict data in <code class="docutils literal"><span class="pre">example/test.list</span></code> using a ResNet model with 50 layers.</p>
287 288
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="n">demo</span><span class="o">/</span><span class="n">model_zoo</span><span class="o">/</span><span class="n">resnet</span>
<span class="o">./</span><span class="n">predict</span><span class="o">.</span><span class="n">sh</span>
Y
Yu Yang 已提交
289 290 291
</pre></div>
</div>
<p>predict.sh calls the <code class="docutils literal"><span class="pre">classify.py</span></code>:</p>
292 293 294 295 296 297 298
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">classify</span><span class="o">.</span><span class="n">py</span> \
     <span class="o">--</span><span class="n">job</span><span class="o">=</span><span class="n">predict</span> \
     <span class="o">--</span><span class="n">conf</span><span class="o">=</span><span class="n">resnet</span><span class="o">.</span><span class="n">py</span>\
     <span class="o">--</span><span class="n">multi_crop</span> \
     <span class="o">--</span><span class="n">model</span><span class="o">=</span><span class="n">model</span><span class="o">/</span><span class="n">resnet_50</span> \
     <span class="o">--</span><span class="n">use_gpu</span><span class="o">=</span><span class="mi">1</span> \
     <span class="o">--</span><span class="n">data</span><span class="o">=./</span><span class="n">example</span><span class="o">/</span><span class="n">test</span><span class="o">.</span><span class="n">list</span>
Y
Yu Yang 已提交
299 300 301
</pre></div>
</div>
<ul class="simple">
Y
Yu Yang 已提交
302 303 304 305 306 307
<li>--job=extract:              speficy job mode to predict.</li>
<li>--conf=resnet.py:           network configure.</li>
<li>--multi_crop:               use 10 crops and average predicting probability.</li>
<li>--use_gpu=1:             speficy GPU mode.</li>
<li>--model=model/resnet_50:    model path.</li>
<li>--data=./example/test.list: data list.</li>
Y
Yu Yang 已提交
308 309
</ul>
<p>If run successfully, you will see following results, where 156 and 285 are labels of the images.</p>
310 311
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Label</span> <span class="n">of</span> <span class="n">example</span><span class="o">/</span><span class="n">dog</span><span class="o">.</span><span class="n">jpg</span> <span class="ow">is</span><span class="p">:</span> <span class="mi">156</span>
<span class="n">Label</span> <span class="n">of</span> <span class="n">example</span><span class="o">/</span><span class="n">cat</span><span class="o">.</span><span class="n">jpg</span> <span class="ow">is</span><span class="p">:</span> <span class="mi">282</span>
Y
Yu Yang 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Model Zoo - ImageNet</a><ul>
<li><a class="reference internal" href="#resnet-introduction">ResNet Introduction</a></li>
<li><a class="reference internal" href="#resnet-model">ResNet Model</a><ul>
<li><a class="reference internal" href="#network-visualization">Network Visualization</a></li>
<li><a class="reference internal" href="#model-download">Model Download</a></li>
<li><a class="reference internal" href="#parameter-info">Parameter Info</a></li>
<li><a class="reference internal" href="#parameter-observation">Parameter Observation</a></li>
</ul>
</li>
<li><a class="reference internal" href="#feature-extraction">Feature Extraction</a><ul>
<li><a class="reference internal" href="#c-interface">C++ Interface</a></li>
<li><a class="reference internal" href="#python-interface">Python Interface</a></li>
</ul>
</li>
<li><a class="reference internal" href="#prediction">Prediction</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="../rec/ml_regression.html"
                        title="previous chapter">Regression MovieLens Ratting</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="../embedding_model/index.html"
                        title="next chapter">Chinese Word Embedding Model Tutorial</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/demo/imagenet_model/resnet_model.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
360 361
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
Y
Yu Yang 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../embedding_model/index.html" title="Chinese Word Embedding Model Tutorial"
             >next</a> |</li>
        <li class="right" >
          <a href="../rec/ml_regression.html" title="Regression MovieLens Ratting"
             >previous</a> |</li>
386 387
        <li class="nav-item nav-item-0"><a href="../../index.html">PaddlePaddle  documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >Examples and demos</a> &#187;</li> 
Y
Yu Yang 已提交
388 389 390
      </ul>
    </div>
    <div class="footer" role="contentinfo">
391 392
        &#169; Copyright 2016, PaddlePaddle developers.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
Y
Yu Yang 已提交
393 394 395
    </div>
  </body>
</html>