index.html 15.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!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 http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  <link rel="shortcut icon" href="../../img/favicon.ico">
  <title>SA搜索 - PaddleSlim Docs</title>
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="../../css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../css/theme_extra.css" type="text/css" />
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
17
  <link href="../../extra.css" rel="stylesheet">
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 48 49 50 51 52 53 54 55 56 57 58
  
  <script>
    // Current page data
    var mkdocs_page_name = "SA\u641c\u7d22";
    var mkdocs_page_input_path = "api/nas_api.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="../../js/jquery-2.1.1.min.js" defer></script>
  <script src="../../js/modernizr-2.8.3.min.js" defer></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</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 stickynav">
      <div class="wy-side-nav-search">
        <a href="../.." class="icon icon-home"> PaddleSlim Docs</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
	<ul class="current">
	  
          
            <li class="toctree-l1">
		
    <a class="" href="../..">Home</a>
	    </li>
          
            <li class="toctree-l1">
		
59 60 61 62 63
    <a class="" href="../../model_zoo/">模型库</a>
	    </li>
          
            <li class="toctree-l1">
		
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
    <span class="caption-text">教程</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../../tutorials/quant_post_demo/">离线量化</a>
                </li>
                <li class="">
                    
    <a class="" href="../../tutorials/quant_aware_demo/">量化训练</a>
                </li>
                <li class="">
                    
    <a class="" href="../../tutorials/quant_embedding_demo/">Embedding量化</a>
                </li>
                <li class="">
                    
    <a class="" href="../../tutorials/nas_demo/">SA搜索</a>
                </li>
                <li class="">
                    
    <a class="" href="../../tutorials/distillation_demo/">知识蒸馏</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
91 92 93 94 95 96 97 98
    <span class="caption-text">API</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../quantization_api/">量化</a>
                </li>
                <li class="">
                    
99
    <a class="" href="../prune_api/">剪枝与敏感度</a>
100 101 102
                </li>
                <li class="">
                    
103
    <a class="" href="../analysis_api/">模型分析</a>
104 105 106
                </li>
                <li class="">
                    
107
    <a class="" href="../single_distiller_api/">知识蒸馏</a>
108 109 110 111 112 113
                </li>
                <li class=" current">
                    
    <a class="current" href="./">SA搜索</a>
    <ul class="subnav">
            
114
    <li class="toctree-l3"><a href="#_1">搜索空间参数的配置</a></li>
115
    
116 117

    <li class="toctree-l3"><a href="#sanas">SANAS</a></li>
118 119 120 121 122 123
    

    </ul>
                </li>
                <li class="">
                    
124
    <a class="" href="../../search_space/">搜索空间</a>
125
                </li>
126 127 128 129
                <li class="">
                    
    <a class="" href="../../table_latency/">硬件延时评估表</a>
                </li>
130 131 132
    </ul>
	    </li>
          
133 134 135 136 137
            <li class="toctree-l1">
		
    <a class="" href="../../algo/algo/">算法原理</a>
	    </li>
          
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
        </ul>
      </div>
      &nbsp;
    </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="../..">PaddleSlim Docs</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="../..">Docs</a> &raquo;</li>
    
      
        
          <li>API &raquo;</li>
        
      
    
    <li>SA搜索</li>
    <li class="wy-breadcrumbs-aside">
      
167
        <a href="https://github.com/PaddlePaddle/PaddleSlim/edit/master/docs/api/nas_api.md"
168 169 170 171 172 173 174 175 176
          class="icon icon-github"> Edit on GitHub</a>
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
177 178 179 180 181 182 183 184 185
                <h2 id="_1">搜索空间参数的配置<a class="headerlink" href="#_1" title="Permanent link">#</a></h2>
<p>通过参数配置搜索空间。更多搜索空间的使用可以参考<a href="../../search_space/">search_space</a></p>
<p><strong>参数:</strong></p>
<ul>
<li><strong>input_size(int|None)</strong>:- <code>input_size</code>表示输入feature map的大小。</li>
<li><strong>output_size(int|None)</strong>:- <code>output_size</code>表示输出feature map的大小。</li>
<li><strong>block_num(int|None)</strong>:- <code>block_num</code>表示搜索空间中block的数量。</li>
<li><strong>block_mask(list|None)</strong>:- <code>block_mask</code>是一组由0、1组成的列表,0表示当前block是normal block,1表示当前block是reduction block。如果设置了<code>block_mask</code>,则主要以<code>block_mask</code>为主要配置,<code>input_size</code><code>output_size</code><code>block_num</code>三种配置是无效的。</li>
</ul>
186 187 188
<p>Note:<br>
1. reduction block表示经过这个block之后的feature map大小下降为之前的一半,normal block表示经过这个block之后feature map大小不变。<br>
2. <code>input_size</code><code>output_size</code>用来计算整个模型结构中reduction block数量。</p>
189 190
<h2 id="sanas">SANAS<a class="headerlink" href="#sanas" title="Permanent link">#</a></h2>
<dl>
191
<dt>paddleslim.nas.SANAS(configs, server_addr=("", 8881), init_temperature=100, reduce_rate=0.85, search_steps=300, save_checkpoint='./nas_checkpoint', load_checkpoint=None, is_server=True)<a href="https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/nas/sa_nas.py#L36">源代码</a></dt>
192 193 194 195 196 197 198 199 200 201 202 203 204 205
<dd>SANAS(Simulated Annealing Neural Architecture Search)是基于模拟退火算法进行模型结构搜索的算法,一般用于离散搜索任务。</dd>
</dl>
<p><strong>参数:</strong></p>
<ul>
<li><strong>configs(list<tuple>)</strong> - 搜索空间配置列表,格式是<code>[(key, {input_size, output_size, block_num, block_mask})]</code>或者<code>[(key)]</code>(MobileNetV2、MobilenetV1和ResNet的搜索空间使用和原本网络结构相同的搜索空间,所以仅需指定<code>key</code>即可), <code>input_size</code><code>output_size</code>表示输入和输出的特征图的大小,<code>block_num</code>是指搜索网络中的block数量,<code>block_mask</code>是一组由0和1组成的列表,0代表不进行下采样的block,1代表下采样的block。 更多paddleslim提供的搜索空间配置可以参考。</li>
<li><strong>server_addr(tuple)</strong> - SANAS的地址,包括server的ip地址和端口号,如果ip地址为None或者为""的话则默认使用本机ip。默认:("", 8881)。</li>
<li><strong>init_temperature(float)</strong> - 基于模拟退火进行搜索的初始温度。默认:100。</li>
<li><strong>reduce_rate(float)</strong> - 基于模拟退火进行搜索的衰减率。默认:0.85。</li>
<li><strong>search_steps(int)</strong> - 搜索过程迭代的次数。默认:300。</li>
<li><strong>save_checkpoint(str|None)</strong> - 保存checkpoint的文件目录,如果设置为None的话则不保存checkpoint。默认:<code>./nas_checkpoint</code></li>
<li><strong>load_checkpoint(str|None)</strong> - 加载checkpoint的文件目录,如果设置为None的话则不加载checkpoint。默认:None。</li>
<li><strong>is_server(bool)</strong> - 当前实例是否要启动一个server。默认:True。</li>
</ul>
<p><strong>返回:</strong>
206
一个SANAS类的实例</p>
207
<p><strong>示例代码:</strong>
208 209 210 211 212 213 214
<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span>1
2
3</pre></div></td><td class="code"><div class="codehilite"><pre><span></span><span class="kn">from</span> <span class="nn">paddleslim.nas</span> <span class="kn">import</span> <span class="n">SANAS</span>
<span class="n">config</span> <span class="o">=</span> <span class="p">[(</span><span class="s1">&#39;MobileNetV2Space&#39;</span><span class="p">)]</span>
<span class="n">sanas</span> <span class="o">=</span> <span class="n">SANAS</span><span class="p">(</span><span class="n">config</span><span class="o">=</span><span class="n">config</span><span class="p">)</span>
</pre></div>
</td></tr></table></p>
215 216 217 218
<dl>
<dt>paddlesim.nas.SANAS.tokens2arch(tokens)</dt>
<dd>通过一组token得到实际的模型结构,一般用来把搜索到最优的token转换为模型结构用来做最后的训练。</dd>
</dl>
219 220
<p>Note:<br>
tokens是一个列表,token映射到搜索空间转换成相应的网络结构,一组token对应唯一的一个网络结构。</p>
221 222 223 224 225 226
<p><strong>参数:</strong></p>
<ul>
<li><strong>tokens(list):</strong> - 一组token。</li>
</ul>
<p><strong>返回:</strong>
根据传入的token得到一个模型结构实例。</p>
227
<p><strong>示例代码:</strong>
228 229 230 231 232 233 234 235 236 237 238 239 240
<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span>1
2
3
4
5
6</pre></div></td><td class="code"><div class="codehilite"><pre><span></span><span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
<span class="nb">input</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;input&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
<span class="n">archs</span> <span class="o">=</span> <span class="n">sanas</span><span class="o">.</span><span class="n">token2arch</span><span class="p">(</span><span class="n">tokens</span><span class="p">)</span>
<span class="k">for</span> <span class="n">arch</span> <span class="ow">in</span> <span class="n">archs</span><span class="p">:</span>
    <span class="n">output</span> <span class="o">=</span> <span class="n">arch</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span>
    <span class="nb">input</span> <span class="o">=</span> <span class="n">output</span>
</pre></div>
</td></tr></table></p>
241 242 243 244 245
<dl>
<dt>paddleslim.nas.SANAS.next_archs()</dt>
<dd>获取下一组模型结构。</dd>
</dl>
<p><strong>返回:</strong>
246
返回模型结构实例的列表,形式为list。</p>
247
<p><strong>示例代码:</strong>
248 249 250 251 252 253 254 255 256 257 258 259 260
<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span>1
2
3
4
5
6</pre></div></td><td class="code"><div class="codehilite"><pre><span></span><span class="kn">import</span> <span class="nn">paddle.fluid</span> <span class="k">as</span> <span class="nn">fluid</span>
<span class="nb">input</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;input&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
<span class="n">archs</span> <span class="o">=</span> <span class="n">sanas</span><span class="o">.</span><span class="n">next_archs</span><span class="p">()</span>
<span class="k">for</span> <span class="n">arch</span> <span class="ow">in</span> <span class="n">archs</span><span class="p">:</span>
    <span class="n">output</span> <span class="o">=</span> <span class="n">arch</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span>
    <span class="nb">input</span> <span class="o">=</span> <span class="n">output</span>
</pre></div>
</td></tr></table></p>
261 262 263 264 265 266 267 268 269
<dl>
<dt>paddleslim.nas.SANAS.reward(score)</dt>
<dd>把当前模型结构的得分情况回传。</dd>
</dl>
<p><strong>参数:</strong></p>
<ul>
<li><strong>score<float>:</strong> - 当前模型的得分,分数越大越好。</li>
</ul>
<p><strong>返回:</strong>
270
模型结构更新成功或者失败,成功则返回<code>True</code>,失败则返回<code>False</code></p>
271 272 273 274 275 276
<dl>
<dt>paddleslim.nas.SANAS.current_info()</dt>
<dd>返回当前token和搜索过程中最好的token和reward。</dd>
</dl>
<p><strong>返回:</strong>
搜索过程中最好的token,reward和当前训练的token,形式为dict。</p>
277 278 279 280 281 282 283
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
284
        <a href="../../search_space/" class="btn btn-neutral float-right" title="搜索空间">Next <span class="icon icon-circle-arrow-right"></span></a>
285 286
      
      
287
        <a href="../single_distiller_api/" class="btn btn-neutral" title="知识蒸馏"><span class="icon icon-circle-arrow-left"></span> Previous</a>
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</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>

  <div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
          <a href="https://github.com/PaddlePaddle/PaddleSlim/" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
      
      
        <span><a href="../single_distiller_api/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
318
        <span style="margin-left: 15px"><a href="../../search_space/" style="color: #fcfcfc">Next &raquo;</a></span>
319 320 321 322 323 324
      
    </span>
</div>
    <script>var base_url = '../..';</script>
    <script src="../../js/theme.js" defer></script>
      <script src="../../mathjax-config.js" defer></script>
325
      <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" defer></script>
326 327 328 329
      <script src="../../search/main.js" defer></script>

</body>
</html>