index.html 12.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 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 48 49 50 51 52 53 54 55 56 57
<!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">
  
  <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">
		
58 59 60 61 62
    <a class="" href="../../model_zoo/">模型库</a>
	    </li>
          
            <li class="toctree-l1">
		
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
    <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">
		
90 91 92 93 94 95 96 97
    <span class="caption-text">API</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../quantization_api/">量化</a>
                </li>
                <li class="">
                    
98
    <a class="" href="../prune_api/">剪枝与敏感度</a>
99 100 101
                </li>
                <li class="">
                    
102
    <a class="" href="../analysis_api/">模型分析</a>
103 104 105
                </li>
                <li class="">
                    
106
    <a class="" href="../single_distiller_api/">知识蒸馏</a>
107 108 109 110 111 112
                </li>
                <li class=" current">
                    
    <a class="current" href="./">SA搜索</a>
    <ul class="subnav">
            
113
    <li class="toctree-l3"><a href="#_1">搜索空间参数的配置</a></li>
114
    
115 116

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

    </ul>
                </li>
                <li class="">
                    
123
    <a class="" href="../../search_space/">搜索空间</a>
124
                </li>
125 126 127 128
                <li class="">
                    
    <a class="" href="../../table_latency/">硬件延时评估表</a>
                </li>
129 130 131
    </ul>
	    </li>
          
132 133 134 135 136
            <li class="toctree-l1">
		
    <a class="" href="../../algo/algo/">算法原理</a>
	    </li>
          
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
        </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">
      
166
        <a href="https://github.com/PaddlePaddle/PaddleSlim/edit/master/docs/api/nas_api.md"
167 168 169 170 171 172 173 174 175
          class="icon icon-github"> Edit on GitHub</a>
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
176 177 178 179 180 181 182 183 184
                <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>
185 186 187
<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>
188 189
<h2 id="sanas">SANAS<a class="headerlink" href="#sanas" title="Permanent link">#</a></h2>
<dl>
190
<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>
191 192 193 194 195 196 197 198 199 200 201 202 203 204
<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>
205
一个SANAS类的实例</p>
206
<p><strong>示例代码:</strong>
207 208 209
<div class="highlight"><pre><span></span>from paddleslim.nas import SANAS
config = [(&#39;MobileNetV2Space&#39;)]
sanas = SANAS(config=config)
210
</pre></div></p>
211 212 213 214
<dl>
<dt>paddlesim.nas.SANAS.tokens2arch(tokens)</dt>
<dd>通过一组token得到实际的模型结构,一般用来把搜索到最优的token转换为模型结构用来做最后的训练。</dd>
</dl>
215 216
<p>Note:<br>
tokens是一个列表,token映射到搜索空间转换成相应的网络结构,一组token对应唯一的一个网络结构。</p>
217 218 219 220 221 222
<p><strong>参数:</strong></p>
<ul>
<li><strong>tokens(list):</strong> - 一组token。</li>
</ul>
<p><strong>返回:</strong>
根据传入的token得到一个模型结构实例。</p>
223
<p><strong>示例代码:</strong>
224 225 226 227 228 229
<div class="highlight"><pre><span></span>import paddle.fluid as fluid
input = fluid.data(name=&#39;input&#39;, shape=[None, 3, 32, 32], dtype=&#39;float32&#39;)
archs = sanas.token2arch(tokens)
for arch in archs:
    output = arch(input)
    input = output
230
</pre></div></p>
231 232 233 234 235
<dl>
<dt>paddleslim.nas.SANAS.next_archs()</dt>
<dd>获取下一组模型结构。</dd>
</dl>
<p><strong>返回:</strong>
236
返回模型结构实例的列表,形式为list。</p>
237
<p><strong>示例代码:</strong>
238 239 240 241 242 243
<div class="highlight"><pre><span></span>import paddle.fluid as fluid
input = fluid.data(name=&#39;input&#39;, shape=[None, 3, 32, 32], dtype=&#39;float32&#39;)
archs = sanas.next_archs()
for arch in archs:
    output = arch(input)
    input = output
244
</pre></div></p>
245 246 247 248 249 250 251 252 253
<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>
254
模型结构更新成功或者失败,成功则返回<code>True</code>,失败则返回<code>False</code></p>
255 256 257 258 259 260
<dl>
<dt>paddleslim.nas.SANAS.current_info()</dt>
<dd>返回当前token和搜索过程中最好的token和reward。</dd>
</dl>
<p><strong>返回:</strong>
搜索过程中最好的token,reward和当前训练的token,形式为dict。</p>
261 262 263 264 265 266 267
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
268
        <a href="../../search_space/" class="btn btn-neutral float-right" title="搜索空间">Next <span class="icon icon-circle-arrow-right"></span></a>
269 270
      
      
271
        <a href="../single_distiller_api/" class="btn btn-neutral" title="知识蒸馏"><span class="icon icon-circle-arrow-left"></span> Previous</a>
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
      
    </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>
      
      
302
        <span style="margin-left: 15px"><a href="../../search_space/" style="color: #fcfcfc">Next &raquo;</a></span>
303 304 305 306 307 308
      
    </span>
</div>
    <script>var base_url = '../..';</script>
    <script src="../../js/theme.js" defer></script>
      <script src="../../mathjax-config.js" defer></script>
309
      <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" defer></script>
310 311 312 313
      <script src="../../search/main.js" defer></script>

</body>
</html>