提交 cf4e366c 编写于 作者: B baiyfbupt

Deployed 09f99c9e with MkDocs version: 1.0.4

上级 159a6f30
......@@ -8,7 +8,7 @@
<link rel="shortcut icon" href="/img/favicon.ico">
<title>PaddleSlim</title>
<title>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" />
......@@ -29,7 +29,7 @@
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-nav-search">
<a href="/." class="icon icon-home"> PaddleSlim</a>
<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" />
......@@ -43,80 +43,59 @@
<li class="toctree-l1">
<a class="" href="/.">Welcome to MkDocs</a>
<a class="" href="/.">Home</a>
</li>
<li class="toctree-l1">
<span class="caption-text">Docs</span>
<span class="caption-text">教程</span>
<ul class="subnav">
<li class="">
<a class="" href="/docs/">PaddleSlim</a>
<a class="" href="/tutorials/quant_post_demo/">离线量化</a>
</li>
<li class="">
<a class="" href="/docs/table_latency/">硬件延时评估表</a>
<a class="" href="/tutorials/quant_aware_demo/">量化训练</a>
</li>
<li class="">
<span class="caption-text">Api</span>
<ul class="subnav">
<li class="toctree-l3">
<a class="" href="/docs/api/analysis_api/">模型分析API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="/docs/api/api_guide/">PaddleSlim API文档导航</a>
</li>
<li class="toctree-l3">
<a class="" href="/docs/api/nas_api/">paddleslim.nas API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="/docs/api/prune_api/">卷积通道剪裁API文档</a>
<a class="" href="/tutorials/quant_embedding_demo/">Embedding量化</a>
</li>
<li class="toctree-l3">
<a class="" href="/docs/api/quantization_api/">paddleslim.quant API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="/docs/api/search_space/">paddleslim.nas 提供的搜索空间:</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="/docs/api/single_distiller_api/">paddleslim.dist API文档</a>
<a class="" href="/tutorials/nas_demo/">SA搜索</a>
</li>
</ul>
</li>
<li class="">
<span class="caption-text">Tutorials</span>
</li>
<li class="toctree-l1">
<span class="caption-text">API</span>
<ul class="subnav">
<li class="toctree-l3">
<li class="">
<a class="" href="/docs/tutorials/demo_guide/">Demo guide</a>
<a class="" href="/api/quantization_api/">量化</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="/docs/tutorials/nas_demo/">网络结构搜索示例</a>
<a class="" href="/api/prune_api/">剪枝</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="/docs/tutorials/quant_aware_demo/">在线量化示例</a>
<a class="" href="/api/analysis_api/">敏感度分析</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="/docs/tutorials/quant_embedding_demo/">Embedding量化示例</a>
<a class="" href="/api/single_distiller_api/">蒸馏</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="/docs/tutorials/quant_post_demo/">离线量化示例</a>
<a class="" href="/api/nas_api/">SA搜索</a>
</li>
</ul>
<li class="">
<a class="" href="/api/search_space/">搜索空间</a>
</li>
</ul>
</li>
......@@ -131,7 +110,7 @@
<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</a>
<a href="/.">PaddleSlim Docs</a>
</nav>
......@@ -182,12 +161,16 @@
<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>
</div>
<script>var base_url = '/';</script>
<script src="/js/theme.js" defer></script>
<script src="/mathjax-config.js" defer></script>
<script src="/MathJax.js?config=TeX-AMS-MML_HTMLorMML" defer></script>
<script src="/search/main.js" defer></script>
</body>
......
此差异已折叠。
......@@ -7,23 +7,23 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="../../../img/favicon.ico">
<title>PaddleSlim API文档导航 - PaddleSlim</title>
<link rel="shortcut icon" href="../../img/favicon.ico">
<title>PaddleSlim API文档导航 - 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="../../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 = "PaddleSlim API\u6587\u6863\u5bfc\u822a";
var mkdocs_page_input_path = "docs/api/api_guide.md";
var mkdocs_page_input_path = "api/api_guide.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="../../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>
......@@ -36,9 +36,9 @@
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-nav-search">
<a href="../../.." class="icon icon-home"> PaddleSlim</a>
<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">
<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>
......@@ -50,98 +50,59 @@
<li class="toctree-l1">
<a class="" href="../../..">Welcome to MkDocs</a>
<a class="" href="../..">Home</a>
</li>
<li class="toctree-l1">
<span class="caption-text">Docs</span>
<span class="caption-text">教程</span>
<ul class="subnav">
<li class="">
<a class="" href="../../">PaddleSlim</a>
<a class="" href="../../tutorials/quant_post_demo/">离线量化</a>
</li>
<li class="">
<a class="" href="../../table_latency/">硬件延时评估表</a>
<a class="" href="../../tutorials/quant_aware_demo/">量化训练</a>
</li>
<li class=" current">
<span class="caption-text">Api</span>
<ul class="subnav">
<li class="toctree-l3">
<a class="" href="../analysis_api/">模型分析API文档</a>
</li>
<li class="toctree-l3 current">
<a class="current" href="./">PaddleSlim API文档导航</a>
<ul class="subnav">
<li class="toctree-l4"><a href="#paddleslim-api">PaddleSlim API文档导航</a></li>
<ul>
<li><a class="toctree-l5" href="#_1">模型分析</a></li>
<li><a class="toctree-l5" href="#_2">卷积通道剪裁</a></li>
<li><a class="toctree-l5" href="#_3">蒸馏</a></li>
<li><a class="toctree-l5" href="#_5">小模型结构搜索</a></li>
</ul>
</ul>
</li>
<li class="toctree-l3">
<a class="" href="../nas_api/">paddleslim.nas API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../prune_api/">卷积通道剪裁API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../quantization_api/">paddleslim.quant API文档</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="../search_space/">paddleslim.nas 提供的搜索空间:</a>
<a class="" href="../../tutorials/quant_embedding_demo/">Embedding量化</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="../single_distiller_api/">paddleslim.dist API文档</a>
<a class="" href="../../tutorials/nas_demo/">SA搜索</a>
</li>
</ul>
</li>
<li class="">
<span class="caption-text">Tutorials</span>
</li>
<li class="toctree-l1">
<span class="caption-text">API</span>
<ul class="subnav">
<li class="toctree-l3">
<li class="">
<a class="" href="../../tutorials/demo_guide/">Demo guide</a>
<a class="" href="../quantization_api/">量化</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="../../tutorials/nas_demo/">网络结构搜索示例</a>
<a class="" href="../prune_api/">剪枝</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="../../tutorials/quant_aware_demo/">在线量化示例</a>
<a class="" href="../analysis_api/">敏感度分析</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="../../tutorials/quant_embedding_demo/">Embedding量化示例</a>
<a class="" href="../single_distiller_api/">蒸馏</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="../../tutorials/quant_post_demo/">离线量化示例</a>
<a class="" href="../nas_api/">SA搜索</a>
</li>
</ul>
<li class="">
<a class="" href="../search_space/">搜索空间</a>
</li>
</ul>
</li>
......@@ -156,7 +117,7 @@
<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</a>
<a href="../..">PaddleSlim Docs</a>
</nav>
......@@ -164,21 +125,16 @@
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../..">Docs</a> &raquo;</li>
<li><a href="../..">Docs</a> &raquo;</li>
<li>Api &raquo;</li>
<li>Docs &raquo;</li>
<li>PaddleSlim API文档导航</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/PaddlePaddle/PaddleSlim/edit/master/docs/api/api_guide.md"
class="icon icon-github"> Edit on GitHub</a>
</li>
</ul>
<hr/>
......@@ -186,10 +142,10 @@
<div role="main">
<div class="section">
<h1 id="paddleslim-api">PaddleSlim API文档导航</h1>
<h2 id="_1"><a href="../analysis_api/">模型分析</a></h2>
<h2 id="_2"><a href="../prune_api/">卷积通道剪裁</a></h2>
<h2 id="_3"><a href="">蒸馏</a></h2>
<h1 id="paddleslim-api">PaddleSlim API文档导航<a class="headerlink" href="#paddleslim-api" title="Permanent link">#</a></h1>
<h2 id="_1"><a href="../analysis_api/">模型分析</a><a class="headerlink" href="#_1" title="Permanent link">#</a></h2>
<h2 id="_2"><a href="../prune_api/">卷积通道剪裁</a><a class="headerlink" href="#_2" title="Permanent link">#</a></h2>
<h2 id="_3"><a href="">蒸馏</a><a class="headerlink" href="#_3" title="Permanent link">#</a></h2>
<ul>
<li>
<p><a href="../single_distiller_api/">单进程蒸馏</a></p>
......@@ -198,7 +154,7 @@
<p><a href="../prune_api/">通道剪裁</a></p>
</li>
</ul>
<h3 id="_4"><a href="../quantization_api/">量化</a></h3>
<h3 id="_4"><a href="../quantization_api/">量化</a><a class="headerlink" href="#_4" title="Permanent link">#</a></h3>
<ul>
<li>
<p><a href="../quantization_api/#量化训练API">量化训练</a></p>
......@@ -210,7 +166,7 @@
<p><a href="../quantization_api/#Embedding量化API">embedding量化</a></p>
</li>
</ul>
<h2 id="_5"><a href="">小模型结构搜索</a></h2>
<h2 id="_5"><a href="">小模型结构搜索</a><a class="headerlink" href="#_5" title="Permanent link">#</a></h2>
<ul>
<li><a href="../nas_api/">nas API</a></li>
<li><a href="../search_space/">SearchSpace</a></li>
......@@ -220,15 +176,6 @@
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../nas_api/" class="btn btn-neutral float-right" title="paddleslim.nas API文档">Next <span class="icon icon-circle-arrow-right"></span></a>
<a href="../analysis_api/" class="btn btn-neutral" title="模型分析API文档"><span class="icon icon-circle-arrow-left"></span> Previous</a>
</div>
<hr/>
......@@ -250,17 +197,17 @@
<div class="rst-versions" role="note" style="cursor: pointer">
<span class="rst-current-version" data-toggle="rst-current-version">
<span><a href="../analysis_api/" style="color: #fcfcfc;">&laquo; Previous</a></span>
<a href="https://github.com/PaddlePaddle/PaddleSlim/" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
<span style="margin-left: 15px"><a href="../nas_api/" style="color: #fcfcfc">Next &raquo;</a></span>
</span>
</div>
<script>var base_url = '../../..';</script>
<script src="../../../js/theme.js" defer></script>
<script src="../../../search/main.js" defer></script>
<script>var base_url = '../..';</script>
<script src="../../js/theme.js" defer></script>
<script src="../../mathjax-config.js" defer></script>
<script src="../../MathJax.js?config=TeX-AMS-MML_HTMLorMML" defer></script>
<script src="../../search/main.js" defer></script>
</body>
</html>
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
<!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>模型分析API文档 - PaddleSlim</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 = "\u6a21\u578b\u5206\u6790API\u6587\u6863";
var mkdocs_page_input_path = "docs/api/analysis_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</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="../../..">Welcome to MkDocs</a>
</li>
<li class="toctree-l1">
<span class="caption-text">Docs</span>
<ul class="subnav">
<li class="">
<a class="" href="../../">PaddleSlim</a>
</li>
<li class="">
<a class="" href="../../table_latency/">硬件延时评估表</a>
</li>
<li class=" current">
<span class="caption-text">Api</span>
<ul class="subnav">
<li class="toctree-l3 current">
<a class="current" href="./">模型分析API文档</a>
<ul class="subnav">
<li class="toctree-l4"><a href="#api">模型分析API文档</a></li>
<ul>
<li><a class="toctree-l5" href="#flops">flops</a></li>
<li><a class="toctree-l5" href="#model_size">model_size</a></li>
<li><a class="toctree-l5" href="#tablelatencyevaluator">TableLatencyEvaluator</a></li>
</ul>
</ul>
</li>
<li class="toctree-l3">
<a class="" href="../api_guide/">PaddleSlim API文档导航</a>
</li>
<li class="toctree-l3">
<a class="" href="../nas_api/">paddleslim.nas API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../prune_api/">卷积通道剪裁API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../quantization_api/">paddleslim.quant API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../search_space/">paddleslim.nas 提供的搜索空间:</a>
</li>
<li class="toctree-l3">
<a class="" href="../single_distiller_api/">paddleslim.dist API文档</a>
</li>
</ul>
</li>
<li class="">
<span class="caption-text">Tutorials</span>
<ul class="subnav">
<li class="toctree-l3">
<a class="" href="../../tutorials/demo_guide/">Demo guide</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/nas_demo/">网络结构搜索示例</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/quant_aware_demo/">在线量化示例</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/quant_embedding_demo/">Embedding量化示例</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/quant_post_demo/">离线量化示例</a>
</li>
</ul>
</li>
</ul>
</li>
</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</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>Docs &raquo;</li>
<li>模型分析API文档</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main">
<div class="section">
<h1 id="api">模型分析API文档</h1>
<h2 id="flops">flops</h2>
<blockquote>
<p>paddleslim.analysis.flops(program, detail=False) <a href="">源代码</a></p>
</blockquote>
<p>获得指定网络的每秒浮点运算次数(FLOPS)。</p>
<p><strong>参数:</strong></p>
<ul>
<li>
<p><strong>program(paddle.fluid.Program):</strong> 待分析的目标网络。更多关于Program的介绍请参考:<a href="https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/fluid_cn/Program_cn.html#program">Program概念介绍</a></p>
</li>
<li>
<p><strong>detail(bool):</strong> 是否返回每个卷积层的FLOPS。默认为False。</p>
</li>
</ul>
<p><strong>返回值:</strong></p>
<ul>
<li>
<p><strong>flops(float):</strong> 整个网络的FLOPS。</p>
</li>
<li>
<p><strong>params2flops(dict):</strong> 每层卷积对应的FLOPS,其中key为卷积层参数名称,value为FLOPS值。</p>
</li>
</ul>
<p><strong>示例:</strong></p>
<pre><code>import paddle.fluid as fluid
from paddle.fluid.param_attr import ParamAttr
from paddleslim.analysis import flops
def conv_bn_layer(input,
num_filters,
filter_size,
name,
stride=1,
groups=1,
act=None):
conv = fluid.layers.conv2d(
input=input,
num_filters=num_filters,
filter_size=filter_size,
stride=stride,
padding=(filter_size - 1) // 2,
groups=groups,
act=None,
param_attr=ParamAttr(name=name + &quot;_weights&quot;),
bias_attr=False,
name=name + &quot;_out&quot;)
bn_name = name + &quot;_bn&quot;
return fluid.layers.batch_norm(
input=conv,
act=act,
name=bn_name + '_output',
param_attr=ParamAttr(name=bn_name + '_scale'),
bias_attr=ParamAttr(bn_name + '_offset'),
moving_mean_name=bn_name + '_mean',
moving_variance_name=bn_name + '_variance', )
main_program = fluid.Program()
startup_program = fluid.Program()
# X X O X O
# conv1--&gt;conv2--&gt;sum1--&gt;conv3--&gt;conv4--&gt;sum2--&gt;conv5--&gt;conv6
# | ^ | ^
# |____________| |____________________|
#
# X: prune output channels
# O: prune input channels
with fluid.program_guard(main_program, startup_program):
input = fluid.data(name=&quot;image&quot;, shape=[None, 3, 16, 16])
conv1 = conv_bn_layer(input, 8, 3, &quot;conv1&quot;)
conv2 = conv_bn_layer(conv1, 8, 3, &quot;conv2&quot;)
sum1 = conv1 + conv2
conv3 = conv_bn_layer(sum1, 8, 3, &quot;conv3&quot;)
conv4 = conv_bn_layer(conv3, 8, 3, &quot;conv4&quot;)
sum2 = conv4 + sum1
conv5 = conv_bn_layer(sum2, 8, 3, &quot;conv5&quot;)
conv6 = conv_bn_layer(conv5, 8, 3, &quot;conv6&quot;)
print(&quot;FLOPS: {}&quot;.format(flops(main_program)))
</code></pre>
<h2 id="model_size">model_size</h2>
<blockquote>
<p>paddleslim.analysis.model_size(program) <a href="">源代码</a></p>
</blockquote>
<p>获得指定网络的参数数量。</p>
<p><strong>参数:</strong></p>
<ul>
<li><strong>program(paddle.fluid.Program):</strong> 待分析的目标网络。更多关于Program的介绍请参考:<a href="https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/fluid_cn/Program_cn.html#program">Program概念介绍</a></li>
</ul>
<p><strong>返回值:</strong></p>
<ul>
<li><strong>model_size(int):</strong> 整个网络的参数数量。</li>
</ul>
<p><strong>示例:</strong></p>
<pre><code>import paddle.fluid as fluid
from paddle.fluid.param_attr import ParamAttr
from paddleslim.analysis import model_size
def conv_layer(input,
num_filters,
filter_size,
name,
stride=1,
groups=1,
act=None):
conv = fluid.layers.conv2d(
input=input,
num_filters=num_filters,
filter_size=filter_size,
stride=stride,
padding=(filter_size - 1) // 2,
groups=groups,
act=None,
param_attr=ParamAttr(name=name + &quot;_weights&quot;),
bias_attr=False,
name=name + &quot;_out&quot;)
return conv
main_program = fluid.Program()
startup_program = fluid.Program()
# X X O X O
# conv1--&gt;conv2--&gt;sum1--&gt;conv3--&gt;conv4--&gt;sum2--&gt;conv5--&gt;conv6
# | ^ | ^
# |____________| |____________________|
#
# X: prune output channels
# O: prune input channels
with fluid.program_guard(main_program, startup_program):
input = fluid.data(name=&quot;image&quot;, shape=[None, 3, 16, 16])
conv1 = conv_layer(input, 8, 3, &quot;conv1&quot;)
conv2 = conv_layer(conv1, 8, 3, &quot;conv2&quot;)
sum1 = conv1 + conv2
conv3 = conv_layer(sum1, 8, 3, &quot;conv3&quot;)
conv4 = conv_layer(conv3, 8, 3, &quot;conv4&quot;)
sum2 = conv4 + sum1
conv5 = conv_layer(sum2, 8, 3, &quot;conv5&quot;)
conv6 = conv_layer(conv5, 8, 3, &quot;conv6&quot;)
print(&quot;FLOPS: {}&quot;.format(model_size(main_program)))
</code></pre>
<h2 id="tablelatencyevaluator">TableLatencyEvaluator</h2>
<blockquote>
<p>paddleslim.analysis.TableLatencyEvaluator(table_file, delimiter=",") <a href="">源代码</a></p>
</blockquote>
<p>基于硬件延时表的模型延时评估器。</p>
<p><strong>参数:</strong></p>
<ul>
<li>
<p><strong>table_file(str):</strong> 所使用的延时评估表的绝对路径。关于演示评估表格式请参考:<a href="../paddleslim/analysis/table_latency.md">PaddleSlim硬件延时评估表格式</a></p>
</li>
<li>
<p><strong>delimiter(str):</strong> 硬件延时评估表中,操作信息之前所使用的分割符,默认为英文字符逗号。</p>
</li>
</ul>
<p><strong>返回值:</strong></p>
<ul>
<li><strong>Evaluator:</strong> 硬件延时评估器的实例。</li>
</ul>
<blockquote>
<p>paddleslim.analysis.TableLatencyEvaluator.latency(graph) <a href="">源代码</a></p>
</blockquote>
<p>获得指定网络的预估延时。</p>
<p><strong>参数:</strong></p>
<ul>
<li><strong>graph(Program):</strong> 待预估的目标网络。</li>
</ul>
<p><strong>返回值:</strong></p>
<ul>
<li><strong>latency:</strong> 目标网络的预估延时。</li>
</ul>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../api_guide/" class="btn btn-neutral float-right" title="PaddleSlim API文档导航">Next <span class="icon icon-circle-arrow-right"></span></a>
<a href="../../table_latency/" class="btn btn-neutral" title="硬件延时评估表"><span class="icon icon-circle-arrow-left"></span> Previous</a>
</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">
<span><a href="../../table_latency/" style="color: #fcfcfc;">&laquo; Previous</a></span>
<span style="margin-left: 15px"><a href="../api_guide/" style="color: #fcfcfc">Next &raquo;</a></span>
</span>
</div>
<script>var base_url = '../../..';</script>
<script src="../../../js/theme.js" defer></script>
<script src="../../../search/main.js" defer></script>
</body>
</html>
<!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>paddleslim.nas API文档 - PaddleSlim</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 = "paddleslim.nas API\u6587\u6863";
var mkdocs_page_input_path = "docs/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</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="../../..">Welcome to MkDocs</a>
</li>
<li class="toctree-l1">
<span class="caption-text">Docs</span>
<ul class="subnav">
<li class="">
<a class="" href="../../">PaddleSlim</a>
</li>
<li class="">
<a class="" href="../../table_latency/">硬件延时评估表</a>
</li>
<li class=" current">
<span class="caption-text">Api</span>
<ul class="subnav">
<li class="toctree-l3">
<a class="" href="../analysis_api/">模型分析API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../api_guide/">PaddleSlim API文档导航</a>
</li>
<li class="toctree-l3 current">
<a class="current" href="./">paddleslim.nas API文档</a>
<ul class="subnav">
<li class="toctree-l4"><a href="#paddleslimnas-api">paddleslim.nas API文档</a></li>
<ul>
<li><a class="toctree-l5" href="#sanas-api">SANAS API文档</a></li>
<li><a class="toctree-l5" href="#class-sanas">class SANAS</a></li>
</ul>
</ul>
</li>
<li class="toctree-l3">
<a class="" href="../prune_api/">卷积通道剪裁API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../quantization_api/">paddleslim.quant API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../search_space/">paddleslim.nas 提供的搜索空间:</a>
</li>
<li class="toctree-l3">
<a class="" href="../single_distiller_api/">paddleslim.dist API文档</a>
</li>
</ul>
</li>
<li class="">
<span class="caption-text">Tutorials</span>
<ul class="subnav">
<li class="toctree-l3">
<a class="" href="../../tutorials/demo_guide/">Demo guide</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/nas_demo/">网络结构搜索示例</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/quant_aware_demo/">在线量化示例</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/quant_embedding_demo/">Embedding量化示例</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/quant_post_demo/">离线量化示例</a>
</li>
</ul>
</li>
</ul>
</li>
</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</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>Docs &raquo;</li>
<li>paddleslim.nas API文档</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main">
<div class="section">
<h1 id="paddleslimnas-api">paddleslim.nas API文档</h1>
<h2 id="sanas-api">SANAS API文档</h2>
<h2 id="class-sanas">class SANAS</h2>
<p>SANAS(Simulated Annealing Neural Architecture Search)是基于模拟退火算法进行模型结构搜索的算法,一般用于离散搜索任务。</p>
<hr />
<blockquote>
<p>paddleslim.nas.SANAS(configs, server_addr, init_temperature, reduce_rate, search_steps, save_checkpoint, load_checkpoint, is_server)</p>
</blockquote>
<p><strong>参数:</strong>
- <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提供的搜索空间配置可以参考。
- <strong>server_addr(tuple):</strong> SANAS的地址,包括server的ip地址和端口号,如果ip地址为None或者为""的话则默认使用本机ip。默认:("", 8881)。
- <strong>init_temperature(float):</strong> 基于模拟退火进行搜索的初始温度。默认:100。
- <strong>reduce_rate(float):</strong> 基于模拟退火进行搜索的衰减率。默认:0.85。
- <strong>search_steps(int):</strong> 搜索过程迭代的次数。默认:300。
- <strong>save_checkpoint(str|None):</strong> 保存checkpoint的文件目录,如果设置为None的话则不保存checkpoint。默认:<code>./nas_checkpoint</code>
- <strong>load_checkpoint(str|None):</strong> 加载checkpoint的文件目录,如果设置为None的话则不加载checkpoint。默认:None。
- <strong>is_server(bool):</strong> 当前实例是否要启动一个server。默认:True。</p>
<p><strong>返回:</strong>
一个SANAS类的实例</p>
<p><strong>示例代码:</strong></p>
<pre><code>from paddleslim.nas import SANAS
config = [('MobileNetV2Space')]
sanas = SANAS(config=config)
</code></pre>
<hr />
<blockquote>
<p>tokens2arch(tokens)
通过一组token得到实际的模型结构,一般用来把搜索到最优的token转换为模型结构用来做最后的训练。</p>
</blockquote>
<p><strong>参数:</strong>
- <strong>tokens(list):</strong> 一组token。</p>
<p><strong>返回</strong>
返回一个模型结构实例。</p>
<p><strong>示例代码:</strong></p>
<pre><code>import paddle.fluid as fluid
input = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32')
archs = sanas.token2arch(tokens)
for arch in archs:
output = arch(input)
input = output
</code></pre>
<hr />
<blockquote>
<p>next_archs():
获取下一组模型结构。</p>
</blockquote>
<p><strong>返回</strong>
返回模型结构实例的列表,形式为list。</p>
<p><strong>示例代码:</strong></p>
<pre><code>import paddle.fluid as fluid
input = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32')
archs = sanas.next_archs()
for arch in archs:
output = arch(input)
input = output
</code></pre>
<hr />
<blockquote>
<p>reward(score):
把当前模型结构的得分情况回传。</p>
</blockquote>
<p><strong>参数:</strong>
<strong>score<float>:</strong> 当前模型的得分,分数越大越好。</p>
<p><strong>返回</strong>
模型结构更新成功或者失败,成功则返回<code>True</code>,失败则返回<code>False</code></p>
<p><strong>代码示例</strong></p>
<pre><code class="python">import numpy as np
import paddle
import paddle.fluid as fluid
from paddleslim.nas import SANAS
from paddleslim.analysis import flops
max_flops = 321208544
batch_size = 256
# 搜索空间配置
config=[('MobileNetV2Space')]
# 实例化SANAS
sa_nas = SANAS(config, server_addr=(&quot;&quot;, 8887), init_temperature=10.24, reduce_rate=0.85, search_steps=100, is_server=True)
for step in range(100):
archs = sa_nas.next_archs()
train_program = fluid.Program()
test_program = fluid.Program()
startup_program = fluid.Program()
### 构造训练program
with fluid.program_guard(train_program, startup_program):
image = fluid.data(name='image', shape=[None, 3, 32, 32], dtype='float32')
label = fluid.data(name='label', shape=[None, 1], dtype='int64')
for arch in archs:
output = arch(image)
out = fluid.layers.fc(output, size=10, act=&quot;softmax&quot;)
softmax_out = fluid.layers.softmax(input=out, use_cudnn=False)
cost = fluid.layers.cross_entropy(input=softmax_out, label=label)
avg_cost = fluid.layers.mean(cost)
acc_top1 = fluid.layers.accuracy(input=softmax_out, label=label, k=1)
### 构造测试program
test_program = train_program.clone(for_test=True)
### 定义优化器
sgd = fluid.optimizer.SGD(learning_rate=1e-3)
sgd.minimize(avg_cost)
### 增加限制条件,如果没有则进行无限制搜索
if flops(train_program) &gt; max_flops:
continue
### 定义代码是在cpu上运行
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(startup_program)
### 定义训练输入数据
train_reader = paddle.batch(
paddle.reader.shuffle(
paddle.dataset.cifar.train10(cycle=False), buf_size=1024),
batch_size=batch_size,
drop_last=True)
### 定义预测输入数据
test_reader = paddle.batch(
paddle.dataset.cifar.test10(cycle=False),
batch_size=batch_size,
drop_last=False)
train_feeder = fluid.DataFeeder([image, label], place, program=train_program)
test_feeder = fluid.DataFeeder([image, label], place, program=test_program)
### 开始训练,每个搜索结果训练5个epoch
for epoch_id in range(5):
for batch_id, data in enumerate(train_reader()):
fetches = [avg_cost.name]
outs = exe.run(train_program,
feed=train_feeder.feed(data),
fetch_list=fetches)[0]
if batch_id % 10 == 0:
print('TRAIN: steps: {}, epoch: {}, batch: {}, cost: {}'.format(step, epoch_id, batch_id, outs[0]))
### 开始预测,得到最终的测试结果作为score回传给sa_nas
reward = []
for batch_id, data in enumerate(test_reader()):
test_fetches = [
avg_cost.name, acc_top1.name
]
batch_reward = exe.run(test_program,
feed=test_feeder.feed(data),
fetch_list=test_fetches)
reward_avg = np.mean(np.array(batch_reward), axis=1)
reward.append(reward_avg)
print('TEST: step: {}, batch: {}, avg_cost: {}, acc_top1: {}'.
format(step, batch_id, batch_reward[0],batch_reward[1]))
finally_reward = np.mean(np.array(reward), axis=0)
print(
'FINAL TEST: avg_cost: {}, acc_top1: {}'.format(
finally_reward[0], finally_reward[1]))
### 回传score
sa_nas.reward(float(finally_reward[1]))
</code></pre>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../prune_api/" class="btn btn-neutral float-right" title="卷积通道剪裁API文档">Next <span class="icon icon-circle-arrow-right"></span></a>
<a href="../api_guide/" class="btn btn-neutral" title="PaddleSlim API文档导航"><span class="icon icon-circle-arrow-left"></span> Previous</a>
</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">
<span><a href="../api_guide/" style="color: #fcfcfc;">&laquo; Previous</a></span>
<span style="margin-left: 15px"><a href="../prune_api/" style="color: #fcfcfc">Next &raquo;</a></span>
</span>
</div>
<script>var base_url = '../../..';</script>
<script src="../../../js/theme.js" defer></script>
<script src="../../../search/main.js" defer></script>
</body>
</html>
此差异已折叠。
<!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>paddleslim.nas 提供的搜索空间: - PaddleSlim</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 = "paddleslim.nas \u63d0\u4f9b\u7684\u641c\u7d22\u7a7a\u95f4\uff1a";
var mkdocs_page_input_path = "docs/api/search_space.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</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="../../..">Welcome to MkDocs</a>
</li>
<li class="toctree-l1">
<span class="caption-text">Docs</span>
<ul class="subnav">
<li class="">
<a class="" href="../../">PaddleSlim</a>
</li>
<li class="">
<a class="" href="../../table_latency/">硬件延时评估表</a>
</li>
<li class=" current">
<span class="caption-text">Api</span>
<ul class="subnav">
<li class="toctree-l3">
<a class="" href="../analysis_api/">模型分析API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../api_guide/">PaddleSlim API文档导航</a>
</li>
<li class="toctree-l3">
<a class="" href="../nas_api/">paddleslim.nas API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../prune_api/">卷积通道剪裁API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="../quantization_api/">paddleslim.quant API文档</a>
</li>
<li class="toctree-l3 current">
<a class="current" href="./">paddleslim.nas 提供的搜索空间:</a>
<ul class="subnav">
<li class="toctree-l4"><a href="#paddleslimnas">paddleslim.nas 提供的搜索空间:</a></li>
<ul>
<li><a class="toctree-l5" href="#_1">搜索空间的配置介绍:</a></li>
<li><a class="toctree-l5" href="#_2">搜索空间示例:</a></li>
</ul>
<li class="toctree-l4"><a href="#search-space">自定义搜索空间(search space)</a></li>
</ul>
</li>
<li class="toctree-l3">
<a class="" href="../single_distiller_api/">paddleslim.dist API文档</a>
</li>
</ul>
</li>
<li class="">
<span class="caption-text">Tutorials</span>
<ul class="subnav">
<li class="toctree-l3">
<a class="" href="../../tutorials/demo_guide/">Demo guide</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/nas_demo/">网络结构搜索示例</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/quant_aware_demo/">在线量化示例</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/quant_embedding_demo/">Embedding量化示例</a>
</li>
<li class="toctree-l3">
<a class="" href="../../tutorials/quant_post_demo/">离线量化示例</a>
</li>
</ul>
</li>
</ul>
</li>
</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</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>Docs &raquo;</li>
<li>paddleslim.nas 提供的搜索空间:</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main">
<div class="section">
<h1 id="paddleslimnas">paddleslim.nas 提供的搜索空间:</h1>
<ol>
<li>根据原本模型结构构造搜索空间:</li>
</ol>
<p>1.1 MobileNetV2Space</p>
<p>1.2 MobileNetV1Space</p>
<p>1.3 ResNetSpace</p>
<ol>
<li>根据相应模型的block构造搜索空间</li>
</ol>
<p>2.1 MobileNetV1BlockSpace</p>
<p>2.2 MobileNetV2BlockSpace</p>
<p>2.3 ResNetBlockSpace</p>
<p>2.4 InceptionABlockSpace</p>
<p>2.5 InceptionCBlockSpace</p>
<h2 id="_1">搜索空间的配置介绍:</h2>
<p><strong>input_size(int|None)</strong><code>input_size</code>表示输入feature map的大小。
<strong>output_size(int|None)</strong><code>output_size</code>表示输出feature map的大小。
<strong>block_num(int|None)</strong><code>block_num</code>表示搜索空间中block的数量。
<strong>block_mask(list|None)</strong><code>block_mask</code>表示当前的block是一个reduction block还是一个normal block,是一组由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>三种配置是无效的。</p>
<p><strong>Note:</strong>
1. reduction block表示经过这个block之后的feature map大小下降为之前的一半,normal block表示经过这个block之后feature map大小不变。
2. <code>input_size</code><code>output_size</code>用来计算整个模型结构中reduction block数量。</p>
<h2 id="_2">搜索空间示例:</h2>
<ol>
<li>使用paddleslim中提供用原本的模型结构来构造搜索空间的话,仅需要指定搜索空间名字即可。例如:如果使用原本的MobileNetV2的搜索空间进行搜索的话,传入SANAS中的config直接指定为[('MobileNetV2Space')]。</li>
<li>使用paddleslim中提供的block搜索空间构造搜索空间:
2.1 使用<code>input_size</code>, <code>output_size</code><code>block_num</code>来构造搜索空间。例如:传入SANAS的config可以指定为[('MobileNetV2BlockSpace', {'input_size': 224, 'output_size': 32, 'block_num': 10})]。
2.2 使用<code>block_mask</code>构造搜索空间。例如:传入SANAS的config可以指定为[('MobileNetV2BlockSpace', {'block_mask': [0, 1, 1, 1, 1, 0, 1, 0]})]。</li>
</ol>
<h1 id="search-space">自定义搜索空间(search space)</h1>
<p>自定义搜索空间类需要继承搜索空间基类并重写以下几部分:
1. 初始化的tokens(<code>init_tokens</code>函数),可以设置为自己想要的tokens列表, tokens列表中的每个数字指的是当前数字在相应的搜索列表中的索引。例如本示例中若tokens=[0, 3, 5],则代表当前模型结构搜索到的通道数为[8, 40, 128]。
2. token中每个数字的搜索列表长度(<code>range_table</code>函数),tokens中每个token的索引范围。
3. 根据token产生模型结构(<code>token2arch</code>函数),根据搜索到的tokens列表产生模型结构。</p>
<p>以新增reset block为例说明如何构造自己的search space。自定义的search space不能和已有的search space同名。</p>
<pre><code class="python">### 引入搜索空间基类函数和search space的注册类函数
from .search_space_base import SearchSpaceBase
from .search_space_registry import SEARCHSPACE
import numpy as np
### 需要调用注册函数把自定义搜索空间注册到space space中
@SEARCHSPACE.register
### 定义一个继承SearchSpaceBase基类的搜索空间的类函数
class ResNetBlockSpace2(SearchSpaceBase):
def __init__(self, input_size, output_size, block_num, block_mask):
### 定义一些实际想要搜索的内容,例如:通道数、每个卷积的重复次数、卷积核大小等等
### self.filter_num 代表通道数的搜索列表
self.filter_num = np.array([8, 16, 32, 40, 64, 128, 256, 512])
### 定义初始化token,初始化token的长度根据传入的block_num或者block_mask的长度来得到的
def init_tokens(self):
return [0] * 3 * len(self.block_mask)
### 定义
def range_table(self):
return [len(self.filter_num)] * 3 * len(self.block_mask)
def token2arch(self, tokens=None):
if tokens == None:
tokens = self.init_tokens()
self.bottleneck_params_list = []
for i in range(len(self.block_mask)):
self.bottleneck_params_list.append(self.filter_num[tokens[i * 3 + 0]],
self.filter_num[tokens[i * 3 + 1]],
self.filter_num[tokens[i * 3 + 2]],
2 if self.block_mask[i] == 1 else 1)
def net_arch(input):
for i, layer_setting in enumerate(self.bottleneck_params_list):
channel_num, stride = layer_setting[:-1], layer_setting[-1]
input = self._resnet_block(input, channel_num, stride, name='resnet_layer{}'.format(i+1))
return input
return net_arch
### 构造具体block的操作
def _resnet_block(self, input, channel_num, stride, name=None):
shortcut_conv = self._shortcut(input, channel_num[2], stride, name=name)
input = self._conv_bn_layer(input=input, num_filters=channel_num[0], filter_size=1, act='relu', name=name + '_conv0')
input = self._conv_bn_layer(input=input, num_filters=channel_num[1], filter_size=3, stride=stride, act='relu', name=name + '_conv1')
input = self._conv_bn_layer(input=input, num_filters=channel_num[2], filter_size=1, name=name + '_conv2')
return fluid.layers.elementwise_add(x=shortcut_conv, y=input, axis=0, name=name+'_elementwise_add')
def _shortcut(self, input, channel_num, stride, name=None):
channel_in = input.shape[1]
if channel_in != channel_num or stride != 1:
return self.conv_bn_layer(input, num_filters=channel_num, filter_size=1, stride=stride, name=name+'_shortcut')
else:
return input
def _conv_bn_layer(self, input, num_filters, filter_size, stride=1, padding='SAME', act=None, name=None):
conv = fluid.layers.conv2d(input, num_filters, filter_size, stride, name=name+'_conv')
bn = fluid.layers.batch_norm(conv, act=act, name=name+'_bn')
return bn
</code></pre>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../single_distiller_api/" class="btn btn-neutral float-right" title="paddleslim.dist API文档">Next <span class="icon icon-circle-arrow-right"></span></a>
<a href="../quantization_api/" class="btn btn-neutral" title="paddleslim.quant API文档"><span class="icon icon-circle-arrow-left"></span> Previous</a>
</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">
<span><a href="../quantization_api/" style="color: #fcfcfc;">&laquo; Previous</a></span>
<span style="margin-left: 15px"><a href="../single_distiller_api/" style="color: #fcfcfc">Next &raquo;</a></span>
</span>
</div>
<script>var base_url = '../../..';</script>
<script src="../../../js/theme.js" defer></script>
<script src="../../../search/main.js" defer></script>
</body>
</html>
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
site_name: PaddleSlim Docs
nav:
- Home: index.md
- 教程:
- 离线量化: tutorials/quant_post_demo.md
- 量化训练: tutorials/quant_aware_demo.md
- Embedding量化: tutorials/quant_embedding_demo.md
- SA搜索: tutorials/nas_demo.md
- API:
- 量化: api/quantization_api.md
- 剪枝: api/prune_api.md
- 敏感度分析: api/analysis_api.md
- 蒸馏: api/single_distiller_api.md
- SA搜索: api/nas_api.md
- 搜索空间: api/search_space.md
theme: readthedocs
markdown_extensions:
- pymdownx.arithmatex
- admonition
- codehilite
extra_javascript:
- mathjax-config.js
- MathJax.js?config=TeX-AMS-MML_HTMLorMML
......@@ -8,7 +8,7 @@
<link rel="shortcut icon" href="./img/favicon.ico">
<title>PaddleSlim</title>
<title>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" />
......@@ -29,7 +29,7 @@
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-nav-search">
<a href="./." class="icon icon-home"> PaddleSlim</a>
<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" />
......@@ -43,80 +43,59 @@
<li class="toctree-l1">
<a class="" href="./.">Welcome to MkDocs</a>
<a class="" href="./.">Home</a>
</li>
<li class="toctree-l1">
<span class="caption-text">Docs</span>
<span class="caption-text">教程</span>
<ul class="subnav">
<li class="">
<a class="" href="./docs/">PaddleSlim</a>
<a class="" href="./tutorials/quant_post_demo/">离线量化</a>
</li>
<li class="">
<a class="" href="./docs/table_latency/">硬件延时评估表</a>
<a class="" href="./tutorials/quant_aware_demo/">量化训练</a>
</li>
<li class="">
<span class="caption-text">Api</span>
<ul class="subnav">
<li class="toctree-l3">
<a class="" href="./docs/api/analysis_api/">模型分析API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="./docs/api/api_guide/">PaddleSlim API文档导航</a>
</li>
<li class="toctree-l3">
<a class="" href="./docs/api/nas_api/">paddleslim.nas API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="./docs/api/prune_api/">卷积通道剪裁API文档</a>
<a class="" href="./tutorials/quant_embedding_demo/">Embedding量化</a>
</li>
<li class="toctree-l3">
<a class="" href="./docs/api/quantization_api/">paddleslim.quant API文档</a>
</li>
<li class="toctree-l3">
<a class="" href="./docs/api/search_space/">paddleslim.nas 提供的搜索空间:</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="./docs/api/single_distiller_api/">paddleslim.dist API文档</a>
<a class="" href="./tutorials/nas_demo/">SA搜索</a>
</li>
</ul>
</li>
<li class="">
<span class="caption-text">Tutorials</span>
</li>
<li class="toctree-l1">
<span class="caption-text">API</span>
<ul class="subnav">
<li class="toctree-l3">
<li class="">
<a class="" href="./docs/tutorials/demo_guide/">Demo guide</a>
<a class="" href="./api/quantization_api/">量化</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="./docs/tutorials/nas_demo/">网络结构搜索示例</a>
<a class="" href="./api/prune_api/">剪枝</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="./docs/tutorials/quant_aware_demo/">在线量化示例</a>
<a class="" href="./api/analysis_api/">敏感度分析</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="./docs/tutorials/quant_embedding_demo/">Embedding量化示例</a>
<a class="" href="./api/single_distiller_api/">蒸馏</a>
</li>
<li class="toctree-l3">
<li class="">
<a class="" href="./docs/tutorials/quant_post_demo/">离线量化示例</a>
<a class="" href="./api/nas_api/">SA搜索</a>
</li>
</ul>
<li class="">
<a class="" href="./api/search_space/">搜索空间</a>
</li>
</ul>
</li>
......@@ -131,7 +110,7 @@
<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</a>
<a href="./.">PaddleSlim Docs</a>
</nav>
......@@ -189,12 +168,16 @@
<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>
</div>
<script>var base_url = '.';</script>
<script src="./js/theme.js" defer></script>
<script src="./mathjax-config.js" defer></script>
<script src="./MathJax.js?config=TeX-AMS-MML_HTMLorMML" defer></script>
<script src="./search/main.js" defer></script>
</body>
......
此差异已折叠。
此差异已折叠。
无法预览此类型文件
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册