Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
8a62b6fe
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
1 年多 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8a62b6fe
编写于
1月 09, 2020
作者:
B
baiyfbupt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Deployed ab60054 with MkDocs version: 1.0.4
上级
fc74b36d
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
207 addition
and
396 deletion
+207
-396
404.html
404.html
+1
-1
algo/algo/index.html
algo/algo/index.html
+1
-1
api/analysis_api/index.html
api/analysis_api/index.html
+10
-6
api/api_guide/index.html
api/api_guide/index.html
+2
-2
api/nas_api/index.html
api/nas_api/index.html
+67
-248
api/prune_api/index.html
api/prune_api/index.html
+7
-7
api/quantization_api/index.html
api/quantization_api/index.html
+4
-4
api/single_distiller_api/index.html
api/single_distiller_api/index.html
+1
-1
index.html
index.html
+2
-2
model_zoo/index.html
model_zoo/index.html
+1
-1
search.html
search.html
+1
-1
search/search_index.json
search/search_index.json
+1
-1
search_space/index.html
search_space/index.html
+87
-99
sitemap.xml
sitemap.xml
+2
-2
sitemap.xml.gz
sitemap.xml.gz
+0
-0
table_latency/index.html
table_latency/index.html
+3
-3
tutorials/demo_guide/index.html
tutorials/demo_guide/index.html
+1
-1
tutorials/distillation_demo/index.html
tutorials/distillation_demo/index.html
+1
-1
tutorials/nas_demo/index.html
tutorials/nas_demo/index.html
+2
-2
tutorials/pruning_demo/index.html
tutorials/pruning_demo/index.html
+1
-1
tutorials/quant_aware_demo/index.html
tutorials/quant_aware_demo/index.html
+2
-2
tutorials/quant_embedding_demo/index.html
tutorials/quant_embedding_demo/index.html
+5
-5
tutorials/quant_post_demo/index.html
tutorials/quant_post_demo/index.html
+4
-4
tutorials/sensitivity_demo/index.html
tutorials/sensitivity_demo/index.html
+1
-1
未找到文件。
404.html
浏览文件 @
8a62b6fe
...
...
@@ -104,7 +104,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"/api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"/api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
algo/algo/index.html
浏览文件 @
8a62b6fe
...
...
@@ -111,7 +111,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
api/analysis_api/index.html
浏览文件 @
8a62b6fe
...
...
@@ -123,7 +123,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -178,7 +178,7 @@
<h2
id=
"flops"
>
FLOPs
<a
class=
"headerlink"
href=
"#flops"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dt>
paddleslim.analysis.flops(program, detail=False)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/flops.py"
>
源代码
</a></dt>
<dt>
paddleslim.analysis.flops(program, detail=False)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/flops.py"
>
[源代码]
</a></dt>
<dd>
<p>
获得指定网络的浮点运算次数(FLOPs)。
</p>
</dd>
...
...
@@ -314,8 +314,12 @@
</td></tr></table>
<h2
id=
"model_size"
>
model_size
<a
class=
"headerlink"
href=
"#model_size"
title=
"Permanent link"
>
#
</a></h2>
<p>
paddleslim.analysis.model_size(program)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/model_size.py"
>
源代码
</a></p>
<dl>
<dt>
paddleslim.analysis.model_size(program)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/model_size.py"
>
[源代码]
</a></dt>
<dd>
<p>
获得指定网络的参数数量。
</p>
</dd>
</dl>
<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>
...
...
@@ -419,7 +423,7 @@
<h2
id=
"tablelatencyevaluator"
>
TableLatencyEvaluator
<a
class=
"headerlink"
href=
"#tablelatencyevaluator"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dt>
paddleslim.analysis.TableLatencyEvaluator(table_file, delimiter=",")
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/latency.py"
>
源代码
</a></dt>
<dt>
paddleslim.analysis.TableLatencyEvaluator(table_file, delimiter=",")
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/latency.py"
>
[源代码]
</a></dt>
<dd>
<p>
基于硬件延时表的模型延时评估器。
</p>
</dd>
...
...
@@ -427,7 +431,7 @@
<p><strong>
参数:
</strong></p>
<ul>
<li>
<p><strong>
table_file(str)
</strong>
- 所使用的延时评估表的绝对路径。关于演示评估表格式请参考:
<a
href=
"
../paddleslim/analysi
s/table_latency.md"
>
PaddleSlim硬件延时评估表格式
</a></p>
<p><strong>
table_file(str)
</strong>
- 所使用的延时评估表的绝对路径。关于演示评估表格式请参考:
<a
href=
"
https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/doc
s/table_latency.md"
>
PaddleSlim硬件延时评估表格式
</a></p>
</li>
<li>
<p><strong>
delimiter(str)
</strong>
- 硬件延时评估表中,操作信息之前所使用的分割符,默认为英文字符逗号。
</p>
...
...
@@ -438,7 +442,7 @@
<li><strong>
Evaluator
</strong>
- 硬件延时评估器的实例。
</li>
</ul>
<dl>
<dt>
paddleslim.analysis.TableLatencyEvaluator.latency(graph)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/latency.py"
>
源代码
</a></dt>
<dt>
paddleslim.analysis.TableLatencyEvaluator.latency(graph)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/latency.py"
>
[源代码]
</a></dt>
<dd>
<p>
获得指定网络的预估延时。
</p>
</dd>
...
...
api/api_guide/index.html
浏览文件 @
8a62b6fe
...
...
@@ -111,7 +111,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -187,7 +187,7 @@
<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>
<li><a
href=
".
/search_space.md
"
>
SearchSpace
</a></li>
</ul>
</div>
...
...
api/nas_api/index.html
浏览文件 @
8a62b6fe
...
...
@@ -110,22 +110,17 @@
<a
class=
"current"
href=
"./"
>
SA搜索
</a>
<ul
class=
"subnav"
>
<li
class=
"toctree-l3"
><a
href=
"#
paddleslimnas-api"
>
paddleslim.nas API文档
</a></li>
<li
class=
"toctree-l3"
><a
href=
"#
_1"
>
搜索空间参数的配置
</a></li>
<ul>
<li><a
class=
"toctree-l4"
href=
"#sanas-api"
>
SANAS API文档
</a></li>
<li><a
class=
"toctree-l4"
href=
"#class-sanas"
>
class SANAS
</a></li>
</ul>
<li
class=
"toctree-l3"
><a
href=
"#sanas"
>
SANAS
</a></li>
</ul>
</li>
<li
class=
""
>
<a
class=
""
href=
"../search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -178,24 +173,35 @@
<div
role=
"main"
>
<div
class=
"section"
>
<h1
id=
"paddleslimnas-api"
>
paddleslim.nas API文档
<a
class=
"headerlink"
href=
"#paddleslimnas-api"
title=
"Permanent link"
>
#
</a></h1>
<h2
id=
"sanas-api"
>
SANAS API文档
<a
class=
"headerlink"
href=
"#sanas-api"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"class-sanas"
>
class SANAS
<a
class=
"headerlink"
href=
"#class-sanas"
title=
"Permanent link"
>
#
</a></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>
<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>
<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>
<h2
id=
"sanas"
>
SANAS
<a
class=
"headerlink"
href=
"#sanas"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<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>
<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>
一个SANAS类的实例
</p>
<p><strong>
示例代码:
</strong>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
...
...
@@ -205,15 +211,18 @@
<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>
<hr
/>
<blockquote>
<p>
tokens2arch(tokens)
通过一组token得到实际的模型结构,一般用来把搜索到最优的token转换为模型结构用来做最后的训练。
</p>
</blockquote>
<p><strong>
参数:
</strong>
-
<strong>
tokens(list):
</strong>
一组token。
</p>
<p><strong>
返回
</strong>
返回一个模型结构实例。
</p>
<dl>
<dt>
paddlesim.nas.SANAS.tokens2arch(tokens)
</dt>
<dd>
通过一组token得到实际的模型结构,一般用来把搜索到最优的token转换为模型结构用来做最后的训练。
</dd>
</dl>
<p>
Note:
<br>
tokens是一个列表,token映射到搜索空间转换成相应的网络结构,一组token对应唯一的一个网络结构。
</p>
<p><strong>
参数:
</strong></p>
<ul>
<li><strong>
tokens(list):
</strong>
- 一组token。
</li>
</ul>
<p><strong>
返回:
</strong>
根据传入的token得到一个模型结构实例。
</p>
<p><strong>
示例代码:
</strong>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
2
...
...
@@ -228,12 +237,11 @@
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
output
</span>
</pre></div>
</td></tr></table></p>
<hr
/>
<blockquote>
<p>
next_archs():
获取下一组模型结构。
</p>
</blockquote>
<p><strong>
返回
</strong>
<dl>
<dt>
paddleslim.nas.SANAS.next_archs()
</dt>
<dd>
获取下一组模型结构。
</dd>
</dl>
<p><strong>
返回:
</strong>
返回模型结构实例的列表,形式为list。
</p>
<p><strong>
示例代码:
</strong>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
...
...
@@ -249,211 +257,22 @@
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
output
</span>
</pre></div>
</td></tr></table></p>
<hr
/>
<blockquote>
<p>
reward(score):
把当前模型结构的得分情况回传。
</p>
</blockquote>
<p><strong>
参数:
</strong>
<strong>
score
<float>
:
</strong>
当前模型的得分,分数越大越好。
</p>
<p><strong>
返回
</strong>
<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>
模型结构更新成功或者失败,成功则返回
<code>
True
</code>
,失败则返回
<code>
False
</code>
。
</p>
<p><strong>
代码示例
</strong>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
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
58
59
60
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
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
numpy
</span>
<span
class=
"kn"
>
as
</span>
<span
class=
"nn"
>
np
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"kn"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.nas
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SANAS
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.analysis
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
flops
</span>
<span
class=
"n"
>
max_flops
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"mi"
>
321208544
</span>
<span
class=
"n"
>
batch_size
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"mi"
>
256
</span>
<span
class=
"c1"
>
# 搜索空间配置
</span>
<span
class=
"n"
>
config
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[(
</span><span
class=
"s1"
>
'
MobileNetV2Space
'
</span><span
class=
"p"
>
)]
</span>
<span
class=
"c1"
>
# 实例化SANAS
</span>
<span
class=
"n"
>
sa_nas
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
SANAS
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
config
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
server_addr
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
""
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
8887
</span><span
class=
"p"
>
),
</span>
<span
class=
"n"
>
init_temperature
</span><span
class=
"o"
>
=
</span><span
class=
"mf"
>
10.24
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
reduce_rate
</span><span
class=
"o"
>
=
</span><span
class=
"mf"
>
0.85
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
search_steps
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
100
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
is_server
</span><span
class=
"o"
>
=
</span><span
class=
"bp"
>
True
</span><span
class=
"p"
>
)
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
step
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"nb"
>
range
</span><span
class=
"p"
>
(
</span><span
class=
"mi"
>
100
</span><span
class=
"p"
>
):
</span>
<span
class=
"n"
>
archs
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
sa_nas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
next_archs
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
train_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
test_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
startup_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"c1"
>
### 构造训练program
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
train_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
startup_program
</span><span
class=
"p"
>
):
</span>
<span
class=
"n"
>
image
</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"
>
'
image
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
shape
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"bp"
>
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"
>
'
float32
'
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
label
</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"
>
'
label
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
shape
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"bp"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
1
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
dtype
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
int64
'
</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=
"n"
>
image
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
out
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
fc
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
output
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
size
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
10
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
act
</span><span
class=
"o"
>
=
</span><span
class=
"s2"
>
"
softmax
"
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
softmax_out
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
softmax
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
input
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
out
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
use_cudnn
</span><span
class=
"o"
>
=
</span><span
class=
"bp"
>
False
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
cost
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
cross_entropy
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
input
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
softmax_out
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
label
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
label
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
avg_cost
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
mean
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
cost
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
acc_top1
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
accuracy
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
input
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
softmax_out
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
label
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
label
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
k
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
1
</span><span
class=
"p"
>
)
</span>
<span
class=
"c1"
>
### 构造测试program
</span>
<span
class=
"n"
>
test_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
train_program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
clone
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
for_test
</span><span
class=
"o"
>
=
</span><span
class=
"bp"
>
True
</span><span
class=
"p"
>
)
</span>
<span
class=
"c1"
>
### 定义优化器
</span>
<span
class=
"n"
>
sgd
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
optimizer
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
SGD
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
learning_rate
</span><span
class=
"o"
>
=
</span><span
class=
"mf"
>
1e-3
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
sgd
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
minimize
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
avg_cost
</span><span
class=
"p"
>
)
</span>
<span
class=
"c1"
>
### 增加限制条件,如果没有则进行无限制搜索
</span>
<span
class=
"k"
>
if
</span>
<span
class=
"n"
>
flops
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
train_program
</span><span
class=
"p"
>
)
</span>
<span
class=
"o"
>
>
</span>
<span
class=
"n"
>
max_flops
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
continue
</span>
<span
class=
"c1"
>
### 定义代码是在cpu上运行
</span>
<span
class=
"n"
>
place
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
CPUPlace
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
exe
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Executor
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
place
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
exe
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
run
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
startup_program
</span><span
class=
"p"
>
)
</span>
<span
class=
"c1"
>
### 定义训练输入数据
</span>
<span
class=
"n"
>
train_reader
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
paddle
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
batch
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
paddle
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
reader
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
shuffle
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
paddle
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
dataset
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
cifar
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
train10
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
cycle
</span><span
class=
"o"
>
=
</span><span
class=
"bp"
>
False
</span><span
class=
"p"
>
),
</span>
<span
class=
"n"
>
buf_size
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
1024
</span><span
class=
"p"
>
),
</span>
<span
class=
"n"
>
batch_size
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
batch_size
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
drop_last
</span><span
class=
"o"
>
=
</span><span
class=
"bp"
>
True
</span><span
class=
"p"
>
)
</span>
<span
class=
"c1"
>
### 定义预测输入数据
</span>
<span
class=
"n"
>
test_reader
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
paddle
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
batch
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
paddle
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
dataset
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
cifar
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
test10
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
cycle
</span><span
class=
"o"
>
=
</span><span
class=
"bp"
>
False
</span><span
class=
"p"
>
),
</span>
<span
class=
"n"
>
batch_size
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
batch_size
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
drop_last
</span><span
class=
"o"
>
=
</span><span
class=
"bp"
>
False
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
train_feeder
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
DataFeeder
</span><span
class=
"p"
>
([
</span><span
class=
"n"
>
image
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
label
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
program
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
train_program
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
test_feeder
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
DataFeeder
</span><span
class=
"p"
>
([
</span><span
class=
"n"
>
image
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
label
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
program
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
test_program
</span><span
class=
"p"
>
)
</span>
<span
class=
"c1"
>
### 开始训练,每个搜索结果训练5个epoch
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
epoch_id
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"nb"
>
range
</span><span
class=
"p"
>
(
</span><span
class=
"mi"
>
5
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
batch_id
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
data
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"nb"
>
enumerate
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
train_reader
</span><span
class=
"p"
>
()):
</span>
<span
class=
"n"
>
fetches
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[
</span><span
class=
"n"
>
avg_cost
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
]
</span>
<span
class=
"n"
>
outs
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
exe
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
run
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
train_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
feed
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
train_feeder
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
feed
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
data
</span><span
class=
"p"
>
),
</span>
<span
class=
"n"
>
fetch_list
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
fetches
</span><span
class=
"p"
>
)[
</span><span
class=
"mi"
>
0
</span><span
class=
"p"
>
]
</span>
<span
class=
"k"
>
if
</span>
<span
class=
"n"
>
batch_id
</span>
<span
class=
"o"
>
%
</span>
<span
class=
"mi"
>
10
</span>
<span
class=
"o"
>
==
</span>
<span
class=
"mi"
>
0
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
TRAIN: steps: {}, epoch: {}, batch: {}, cost: {}
'
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
step
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
epoch_id
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
batch_id
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
outs
</span><span
class=
"p"
>
[
</span><span
class=
"mi"
>
0
</span><span
class=
"p"
>
]))
</span>
<span
class=
"c1"
>
### 开始预测,得到最终的测试结果作为score回传给sa_nas
</span>
<span
class=
"n"
>
reward
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[]
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
batch_id
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
data
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"nb"
>
enumerate
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
test_reader
</span><span
class=
"p"
>
()):
</span>
<span
class=
"n"
>
test_fetches
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[
</span>
<span
class=
"n"
>
avg_cost
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
acc_top1
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span>
<span
class=
"p"
>
]
</span>
<span
class=
"n"
>
batch_reward
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
exe
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
run
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
test_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
feed
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
test_feeder
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
feed
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
data
</span><span
class=
"p"
>
),
</span>
<span
class=
"n"
>
fetch_list
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
test_fetches
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
reward_avg
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
np
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
mean
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
np
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
array
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
batch_reward
</span><span
class=
"p"
>
),
</span>
<span
class=
"n"
>
axis
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
1
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
reward
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
append
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
reward_avg
</span><span
class=
"p"
>
)
</span>
<span
class=
"k"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
TEST: step: {}, batch: {}, avg_cost: {}, acc_top1: {}
'
</span><span
class=
"o"
>
.
</span>
<span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
step
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
batch_id
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
batch_reward
</span><span
class=
"p"
>
[
</span><span
class=
"mi"
>
0
</span><span
class=
"p"
>
],
</span><span
class=
"n"
>
batch_reward
</span><span
class=
"p"
>
[
</span><span
class=
"mi"
>
1
</span><span
class=
"p"
>
]))
</span>
<span
class=
"n"
>
finally_reward
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
np
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
mean
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
np
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
array
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
reward
</span><span
class=
"p"
>
),
</span>
<span
class=
"n"
>
axis
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
0
</span><span
class=
"p"
>
)
</span>
<span
class=
"k"
>
print
</span><span
class=
"p"
>
(
</span>
<span
class=
"s1"
>
'
FINAL TEST: avg_cost: {}, acc_top1: {}
'
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
finally_reward
</span><span
class=
"p"
>
[
</span><span
class=
"mi"
>
0
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
finally_reward
</span><span
class=
"p"
>
[
</span><span
class=
"mi"
>
1
</span><span
class=
"p"
>
]))
</span>
<span
class=
"c1"
>
### 回传score
</span>
<span
class=
"n"
>
sa_nas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
reward
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
float
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
finally_reward
</span><span
class=
"p"
>
[
</span><span
class=
"mi"
>
1
</span><span
class=
"p"
>
]))
</span>
</pre></div>
</td></tr></table></p>
<dl>
<dt>
paddleslim.nas.SANAS.current_info()
</dt>
<dd>
返回当前token和搜索过程中最好的token和reward。
</dd>
</dl>
<p><strong>
返回:
</strong>
搜索过程中最好的token,reward和当前训练的token,形式为dict。
</p>
</div>
</div>
...
...
@@ -461,7 +280,7 @@
<div
class=
"rst-footer-buttons"
role=
"navigation"
aria-label=
"footer navigation"
>
<a
href=
"../
search_space/"
class=
"btn btn-neutral float-right"
title=
"搜索空间
"
>
Next
<span
class=
"icon icon-circle-arrow-right"
></span></a>
<a
href=
"../
../table_latency/"
class=
"btn btn-neutral float-right"
title=
"硬件延时评估表
"
>
Next
<span
class=
"icon icon-circle-arrow-right"
></span></a>
<a
href=
"../single_distiller_api/"
class=
"btn btn-neutral"
title=
"知识蒸馏"
><span
class=
"icon icon-circle-arrow-left"
></span>
Previous
</a>
...
...
@@ -495,7 +314,7 @@
<span><a
href=
"../single_distiller_api/"
style=
"color: #fcfcfc;"
>
«
Previous
</a></span>
<span
style=
"margin-left: 15px"
><a
href=
"../
search_space
/"
style=
"color: #fcfcfc"
>
Next
»
</a></span>
<span
style=
"margin-left: 15px"
><a
href=
"../
../table_latency
/"
style=
"color: #fcfcfc"
>
Next
»
</a></span>
</span>
</div>
...
...
api/prune_api/index.html
浏览文件 @
8a62b6fe
...
...
@@ -129,7 +129,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -184,7 +184,7 @@
<h2
id=
"pruner"
>
Pruner
<a
class=
"headerlink"
href=
"#pruner"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dt>
paddleslim.prune.Pruner(criterion="l1_norm")
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/pruner.py#L28"
>
源代码
</a></dt>
<dt>
paddleslim.prune.Pruner(criterion="l1_norm")
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/pruner.py#L28"
>
[源代码]
</a></dt>
<dd>
<p>
对卷积网络的通道进行一次剪裁。剪裁一个卷积层的通道,是指剪裁该卷积层输出的通道。卷积层的权重形状为
<code>
[output_channel, input_channel, kernel_size, kernel_size]
</code>
,通过剪裁该权重的第一纬度达到剪裁输出通道数的目的。
</p>
</dd>
...
...
@@ -202,7 +202,7 @@
</td></tr></table>
<dl>
<dt>
paddleslim.prune.Pruner.prune(program, scope, params, ratios, place=None, lazy=False, only_graph=False, param_backup=False, param_shape_backup=False)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/pruner.py#L36"
>
源代码
</a></dt>
<dt>
paddleslim.prune.Pruner.prune(program, scope, params, ratios, place=None, lazy=False, only_graph=False, param_backup=False, param_shape_backup=False)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/pruner.py#L36"
>
[源代码]
</a></dt>
<dd>
<p>
对目标网络的一组卷积层的权重进行裁剪。
</p>
</dd>
...
...
@@ -404,7 +404,7 @@
<hr
/>
<h2
id=
"sensitivity"
>
sensitivity
<a
class=
"headerlink"
href=
"#sensitivity"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dt>
paddleslim.prune.sensitivity(program, place, param_names, eval_func, sensitivities_file=None, pruned_ratios=None)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/sensitive.py#L34"
>
源代码
</a></dt>
<dt>
paddleslim.prune.sensitivity(program, place, param_names, eval_func, sensitivities_file=None, pruned_ratios=None)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/sensitive.py#L34"
>
[源代码]
</a></dt>
<dd>
<p>
计算网络中每个卷积层的敏感度。每个卷积层的敏感度信息统计方法为:依次剪掉当前卷积层不同比例的输出通道数,在测试集上计算剪裁后的精度损失。得到敏感度信息后,可以通过观察或其它方式确定每层卷积的剪裁率。
</p>
</dd>
...
...
@@ -653,7 +653,7 @@
<h2
id=
"merge_sensitive"
>
merge_sensitive
<a
class=
"headerlink"
href=
"#merge_sensitive"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dt>
paddleslim.prune.merge_sensitive(sensitivities)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/sensitive.py#L161"
>
源代码
</a></dt>
<dt>
paddleslim.prune.merge_sensitive(sensitivities)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/sensitive.py#L161"
>
[源代码]
</a></dt>
<dd>
<p>
合并多个敏感度信息。
</p>
</dd>
...
...
@@ -690,7 +690,7 @@
<p>
示例:
</p>
<h2
id=
"load_sensitivities"
>
load_sensitivities
<a
class=
"headerlink"
href=
"#load_sensitivities"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dt>
paddleslim.prune.load_sensitivities(sensitivities_file)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/sensitive.py#L184"
>
源代码
</a></dt>
<dt>
paddleslim.prune.load_sensitivities(sensitivities_file)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/sensitive.py#L184"
>
[源代码]
</a></dt>
<dd>
<p>
从文件中加载敏感度信息。
</p>
</dd>
...
...
@@ -706,7 +706,7 @@
<p>
示例:
</p>
<h2
id=
"get_ratios_by_loss"
>
get_ratios_by_loss
<a
class=
"headerlink"
href=
"#get_ratios_by_loss"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dt>
paddleslim.prune.get_ratios_by_loss(sensitivities, loss)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/sensitive.py#L206"
>
源代码
</a></dt>
<dt>
paddleslim.prune.get_ratios_by_loss(sensitivities, loss)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/sensitive.py#L206"
>
[源代码]
</a></dt>
<dd>
<p>
根据敏感度和精度损失阈值计算出一组剪切率。对于参数
<code>
w
</code>
, 其剪裁率为使精度损失低于
<code>
loss
</code>
的最大剪裁率。
</p>
</dd>
...
...
api/quantization_api/index.html
浏览文件 @
8a62b6fe
...
...
@@ -129,7 +129,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -254,13 +254,13 @@
</ul>
<div
class=
"admonition note"
>
<p
class=
"admonition-title"
>
注意事项
</p>
</div>
<ul>
<li>
此接口会改变
<code>
program
</code>
结构,并且可能增加一些
<code>
persistable
</code>
的变量,所以加载模型参数时请注意和相应的
<code>
program
</code>
对应。
</li>
<li>
此接口底层经历了
<code>
fluid.Program
</code>
-
>
<code>
fluid.framework.IrGraph
</code>
-
>
<code>
fluid.Program
</code>
的转变,在
<code>
fluid.framework.IrGraph
</code>
中没有
<code>
Parameter
</code>
的概念,
<code>
Variable
</code>
只有
<code>
persistable
</code>
和
<code>
not persistable
</code>
的区别,所以在保存和加载参数时,请使用
<code>
fluid.io.save_persistables
</code>
和
<code>
fluid.io.load_persistables
</code>
接口。
</li>
<li>
由于此接口会根据
<code>
program
</code>
的结构和量化配置来对
<code>
program
</code>
添加op,所以
<code>
Paddle
</code>
中一些通过
<code>
fuse op
</code>
来加速训练的策略不能使用。已知以下策略在使用量化时必须设为
<code>
False
</code>
:
<code>
fuse_all_reduce_ops, sync_batch_norm
</code>
。
</li>
<li>
如果传入的
<code>
program
</code>
中存在和任何op都没有连接的
<code>
Variable
</code>
,则会在量化的过程中被优化掉。
</li>
</ul>
</div>
<h2
id=
"convert"
>
convert
<a
class=
"headerlink"
href=
"#convert"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dt>
paddleslim.quant.convert(program, place, config, scope=None, save_int8=False)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/quant/quanter.py"
>
[源代码]
</a></dt>
...
...
@@ -283,8 +283,8 @@
</ul>
<div
class=
"admonition note"
>
<p
class=
"admonition-title"
>
注意事项
</p>
</div>
<p>
因为该接口会对
<code>
op
</code>
和
<code>
Variable
</code>
做相应的删除和修改,所以此接口只能在训练完成之后调用。如果想转化训练的中间模型,可加载相应的参数之后再使用此接口。
</p>
</div>
<p><strong>
代码示例
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
2
...
...
@@ -388,8 +388,8 @@
<p>
无。
</p>
<div
class=
"admonition note"
>
<p
class=
"admonition-title"
>
注意事项
</p>
</div>
<p>
因为该接口会收集校正数据的所有的激活值,所以使用的校正图片不能太多。
<code>
'KL'
</code>
散度的计算也比较耗时。
</p>
</div>
<p><strong>
代码示例
</strong></p>
<blockquote>
<p>
注: 此示例不能直接运行,因为需要加载
<code>
${model_dir}
</code>
下的模型,所以不能直接运行。
</p>
...
...
api/single_distiller_api/index.html
浏览文件 @
8a62b6fe
...
...
@@ -129,7 +129,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
index.html
浏览文件 @
8a62b6fe
...
...
@@ -129,7 +129,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -293,5 +293,5 @@
<!--
MkDocs version : 1.0.4
Build Date UTC : 2020-01-09 0
5:24:41
Build Date UTC : 2020-01-09 0
6:39:56
-->
model_zoo/index.html
浏览文件 @
8a62b6fe
...
...
@@ -151,7 +151,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
search.html
浏览文件 @
8a62b6fe
...
...
@@ -104,7 +104,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"./api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"./api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
search/search_index.json
浏览文件 @
8a62b6fe
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
api/
search_space/index.html
→
search_space/index.html
浏览文件 @
8a62b6fe
...
...
@@ -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 Docs
</title>
<link
rel=
"shortcut icon"
href=
"../img/favicon.ico"
>
<title>
Search space
- 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
=
"
\
u641c
\
u7d22
\
u7a7a
\
u95f4
"
;
var
mkdocs_page_input_path
=
"
api/
search_space.md
"
;
var
mkdocs_page_name
=
"
Search space
"
;
var
mkdocs_page_input_path
=
"
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=
"../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 Docs
</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,12 +50,12 @@
<li
class=
"toctree-l1"
>
<a
class=
""
href=
"..
/..
"
>
Home
</a>
<a
class=
""
href=
".."
>
Home
</a>
</li>
<li
class=
"toctree-l1"
>
<a
class=
""
href=
"../
../
model_zoo/"
>
模型库
</a>
<a
class=
""
href=
"../model_zoo/"
>
模型库
</a>
</li>
<li
class=
"toctree-l1"
>
...
...
@@ -64,23 +64,23 @@
<ul
class=
"subnav"
>
<li
class=
""
>
<a
class=
""
href=
"../
../
tutorials/quant_post_demo/"
>
离线量化
</a>
<a
class=
""
href=
"../tutorials/quant_post_demo/"
>
离线量化
</a>
</li>
<li
class=
""
>
<a
class=
""
href=
"../
../
tutorials/quant_aware_demo/"
>
量化训练
</a>
<a
class=
""
href=
"../tutorials/quant_aware_demo/"
>
量化训练
</a>
</li>
<li
class=
""
>
<a
class=
""
href=
"../
../
tutorials/quant_embedding_demo/"
>
Embedding量化
</a>
<a
class=
""
href=
"../tutorials/quant_embedding_demo/"
>
Embedding量化
</a>
</li>
<li
class=
""
>
<a
class=
""
href=
"../
../
tutorials/nas_demo/"
>
SA搜索
</a>
<a
class=
""
href=
"../tutorials/nas_demo/"
>
SA搜索
</a>
</li>
<li
class=
""
>
<a
class=
""
href=
"../
../
tutorials/distillation_demo/"
>
知识蒸馏
</a>
<a
class=
""
href=
"../tutorials/distillation_demo/"
>
知识蒸馏
</a>
</li>
</ul>
</li>
...
...
@@ -91,55 +91,38 @@
<ul
class=
"subnav"
>
<li
class=
""
>
<a
class=
""
href=
"../quantization_api/"
>
量化
</a>
<a
class=
""
href=
"../
api/
quantization_api/"
>
量化
</a>
</li>
<li
class=
""
>
<a
class=
""
href=
"../prune_api/"
>
剪枝与敏感度
</a>
<a
class=
""
href=
"../
api/
prune_api/"
>
剪枝与敏感度
</a>
</li>
<li
class=
""
>
<a
class=
""
href=
"../analysis_api/"
>
模型分析
</a>
<a
class=
""
href=
"../a
pi/a
nalysis_api/"
>
模型分析
</a>
</li>
<li
class=
""
>
<a
class=
""
href=
"../single_distiller_api/"
>
知识蒸馏
</a>
<a
class=
""
href=
"../
api/
single_distiller_api/"
>
知识蒸馏
</a>
</li>
<li
class=
""
>
<a
class=
""
href=
"../nas_api/"
>
SA搜索
</a>
<a
class=
""
href=
"../
api/
nas_api/"
>
SA搜索
</a>
</li>
<li
class=
"
current
"
>
<li
class=
""
>
<a
class=
"current"
href=
"./"
>
搜索空间
</a>
<ul
class=
"subnav"
>
<li
class=
"toctree-l3"
><a
href=
"#paddleslimnas"
>
paddleslim.nas 提供的搜索空间:
</a></li>
<ul>
<li><a
class=
"toctree-l4"
href=
"#_1"
>
搜索空间的配置介绍:
</a></li>
<li><a
class=
"toctree-l4"
href=
"#_2"
>
搜索空间示例:
</a></li>
</ul>
<li
class=
"toctree-l3"
><a
href=
"#search-space"
>
自定义搜索空间(search space)
</a></li>
</ul>
<a
class=
""
href=
"../api/search_space.md"
>
搜索空间
</a>
</li>
<li
class=
""
>
<a
class=
""
href=
"../
../
table_latency/"
>
硬件延时评估表
</a>
<a
class=
""
href=
"../table_latency/"
>
硬件延时评估表
</a>
</li>
</ul>
</li>
<li
class=
"toctree-l1"
>
<a
class=
""
href=
"../
../
algo/algo/"
>
算法原理
</a>
<a
class=
""
href=
"../algo/algo/"
>
算法原理
</a>
</li>
</ul>
...
...
@@ -152,7 +135,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 Docs
</a>
<a
href=
".."
>
PaddleSlim Docs
</a>
</nav>
...
...
@@ -160,18 +143,14 @@
<div
class=
"rst-content"
>
<div
role=
"navigation"
aria-label=
"breadcrumbs navigation"
>
<ul
class=
"wy-breadcrumbs"
>
<li><a
href=
"..
/..
"
>
Docs
</a>
»
</li>
<li><a
href=
".."
>
Docs
</a>
»
</li>
<li>
API
»
</li>
<li>
搜索空间
</li>
<li>
Search space
</li>
<li
class=
"wy-breadcrumbs-aside"
>
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/docs/
api/
search_space.md"
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/docs/docs/search_space.md"
class=
"icon icon-github"
>
Edit on GitHub
</a>
</li>
...
...
@@ -181,41 +160,61 @@
<div
role=
"main"
>
<div
class=
"section"
>
<h1
id=
"paddleslimnas"
>
paddleslim.nas 提供的搜索空间:
<a
class=
"headerlink"
href=
"#paddleslimnas"
title=
"Permanent link"
>
#
</a></h1>
<h2
id=
"_1"
>
搜索空间简介
<a
class=
"headerlink"
href=
"#_1"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dd>
搜索空间是神经网络搜索中的一个概念。搜索空间是一系列模型结构的汇集, SANAS主要是利用模拟退火的思想在搜索空间中搜索到一个比较小的模型结构或者一个精度比较高的模型结构。
</dd>
</dl>
<h2
id=
"paddleslimnas"
>
paddleslim.nas 提供的搜索空间
<a
class=
"headerlink"
href=
"#paddleslimnas"
title=
"Permanent link"
>
#
</a></h2>
<h5
id=
"_2"
>
根据初始模型结构构造搜索空间
<a
class=
"headerlink"
href=
"#_2"
title=
"Permanent link"
>
#
</a></h5>
<ol>
<li>
根据原本模型结构构造搜索空间:
</li>
<li>
<p>
MobileNetV2Space
<br>
 
MobileNetV2的网络结构可以参考:
<a
href=
"https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/image_classification/models/mobilenet_v2.py#L29"
>
代码
</a>
,
<a
href=
"https://arxiv.org/abs/1801.04381"
>
论文
</a></p>
</li>
<li>
<p>
MobileNetV1Space
<br>
 
MobilNetV1的网络结构可以参考:
<a
href=
"https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/image_classification/models/mobilenet_v1.py#L29"
>
代码
</a>
,
<a
href=
"https://arxiv.org/abs/1704.04861"
>
论文
</a></p>
</li>
<li>
<p>
ResNetSpace
<br>
 
ResNetSpace的网络结构可以参考:
<a
href=
"https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/image_classification/models/resnet.py#L30"
>
代码
</a>
,
<a
href=
"https://arxiv.org/pdf/1512.03385.pdf"
>
论文
</a></p>
</li>
</ol>
<p>
1.1 MobileNetV2Space
</p>
<p>
1.2 MobileNetV1Space
</p>
<p>
1.3 ResNetSpace
</p>
<h5
id=
"block"
>
根据相应模型的block构造搜索空间
<a
class=
"headerlink"
href=
"#block"
title=
"Permanent link"
>
#
</a></h5>
<ol>
<li>
根据相应模型的block构造搜索空间
</li>
<li>
<p>
MobileNetV1BlockSpace
<br>
 
MobileNetV1Block的结构可以参考:
<a
href=
"https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/image_classification/models/mobilenet_v1.py#L173"
>
代码
</a></p>
</li>
<li>
<p>
MobileNetV2BlockSpace
<br>
 
MobileNetV2Block的结构可以参考:
<a
href=
"https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/image_classification/models/mobilenet_v2.py#L174"
>
代码
</a></p>
</li>
<li>
<p>
ResNetBlockSpace
<br>
 
ResNetBlock的结构可以参考:
<a
href=
"https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/image_classification/models/resnet.py#L148"
>
代码
</a></p>
</li>
<li>
<p>
InceptionABlockSpace
<br>
 
InceptionABlock的结构可以参考:
<a
href=
"https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/image_classification/models/inception_v4.py#L140"
>
代码
</a></p>
</li>
<li>
<p>
InceptionCBlockSpace
<br>
 
InceptionCBlock结构可以参考:
<a
href=
"https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/image_classification/models/inception_v4.py#L291"
>
代码
</a></p>
</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"
>
搜索空间的配置介绍:
<a
class=
"headerlink"
href=
"#_1"
title=
"Permanent link"
>
#
</a></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"
>
搜索空间示例:
<a
class=
"headerlink"
href=
"#_2"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"_3"
>
搜索空间示例
<a
class=
"headerlink"
href=
"#_3"
title=
"Permanent link"
>
#
</a></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})]。
<li>
使用paddleslim中提供用
初始
的模型结构来构造搜索空间的话,仅需要指定搜索空间名字即可。例如:如果使用原本的MobileNetV2的搜索空间进行搜索的话,传入SANAS中的config直接指定为[('MobileNetV2Space')]。
</li>
<li>
使用paddleslim中提供的block搜索空间构造搜索空间:
<br>
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})]。
<br>
2.2 使用
<code>
block_mask
</code>
构造搜索空间。例如:传入SANAS的config可以指定为[('MobileNetV2BlockSpace', {'block_mask': [0, 1, 1, 1, 1, 0, 1, 0]})]。
</li>
</ol>
<h
1
id=
"search-space"
>
自定义搜索空间(search space)
<a
class=
"headerlink"
href=
"#search-space"
title=
"Permanent link"
>
#
</a></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>
<h
2
id=
"search-space"
>
自定义搜索空间(search space)
<a
class=
"headerlink"
href=
"#search-space"
title=
"Permanent link"
>
#
</a></h2
>
<p>
自定义搜索空间类需要继承搜索空间基类并重写以下几部分:
<br>
 
1. 初始化的tokens(
<code>
init_tokens
</code>
函数),可以设置为自己想要的tokens列表, tokens列表中的每个数字指的是当前数字在相应的搜索列表中的索引。例如本示例中若tokens=[0, 3, 5],则代表当前模型结构搜索到的通道数为[8, 40, 128]。
<br>
 
2. token中每个数字的搜索列表长度(
<code>
range_table
</code>
函数),tokens中每个token的索引范围。
<br>
 
3. 根据token产生模型结构(
<code>
token2arch
</code>
函数),根据搜索到的tokens列表产生模型结构。
<br>
</p>
<p>
以新增reset block为例说明如何构造自己的search space。自定义的search space不能和已有的search space同名。
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
2
...
...
@@ -277,7 +276,8 @@
58
59
60
61
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
### 引入搜索空间基类函数和search space的注册类函数
</span>
61
62
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
### 引入搜索空间基类函数和search space的注册类函数
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
.search_space_base
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SearchSpaceBase
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
.search_space_registry
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SEARCHSPACE
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
numpy
</span>
<span
class=
"kn"
>
as
</span>
<span
class=
"nn"
>
np
</span>
...
...
@@ -295,17 +295,18 @@
<span
class=
"k"
>
def
</span>
<span
class=
"nf"
>
init_tokens
</span><span
class=
"p"
>
(
</span><span
class=
"bp"
>
self
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
return
</span>
<span
class=
"p"
>
[
</span><span
class=
"mi"
>
0
</span><span
class=
"p"
>
]
</span>
<span
class=
"o"
>
*
</span>
<span
class=
"mi"
>
3
</span>
<span
class=
"o"
>
*
</span>
<span
class=
"nb"
>
len
</span><span
class=
"p"
>
(
</span><span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
block_mask
</span><span
class=
"p"
>
)
</span>
<span
class=
"c1"
>
### 定义
</span>
<span
class=
"c1"
>
### 定义
token的index的取值范围
</span>
<span
class=
"k"
>
def
</span>
<span
class=
"nf"
>
range_table
</span><span
class=
"p"
>
(
</span><span
class=
"bp"
>
self
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
return
</span>
<span
class=
"p"
>
[
</span><span
class=
"nb"
>
len
</span><span
class=
"p"
>
(
</span><span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
filter_num
</span><span
class=
"p"
>
)]
</span>
<span
class=
"o"
>
*
</span>
<span
class=
"mi"
>
3
</span>
<span
class=
"o"
>
*
</span>
<span
class=
"nb"
>
len
</span><span
class=
"p"
>
(
</span><span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
block_mask
</span><span
class=
"p"
>
)
</span>
<span
class=
"c1"
>
### 把token转换成模型结构
</span>
<span
class=
"k"
>
def
</span>
<span
class=
"nf"
>
token2arch
</span><span
class=
"p"
>
(
</span><span
class=
"bp"
>
self
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
tokens
</span><span
class=
"o"
>
=
</span><span
class=
"bp"
>
None
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
if
</span>
<span
class=
"n"
>
tokens
</span>
<span
class=
"o"
>
==
</span>
<span
class=
"bp"
>
None
</span><span
class=
"p"
>
:
</span>
<span
class=
"n"
>
tokens
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
init_tokens
</span><span
class=
"p"
>
()
</span>
<span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
bottleneck_params_list
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[]
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
i
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"nb"
>
range
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
len
</span><span
class=
"p"
>
(
</span><span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
block_mask
</span><span
class=
"p"
>
)):
</span>
<span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
bottleneck_params_list
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
append
</span><span
class=
"p"
>
(
</span><span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
filter_num
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
tokens
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
i
</span>
<span
class=
"o"
>
*
</span>
<span
class=
"mi"
>
3
</span>
<span
class=
"o"
>
+
</span>
<span
class=
"mi"
>
0
</span><span
class=
"p"
>
]],
</span>
<span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
bottleneck_params_list
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
append
</span><span
class=
"p"
>
(
</span><span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
filter_num
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
tokens
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
i
</span>
<span
class=
"o"
>
*
</span>
<span
class=
"mi"
>
3
</span>
<span
class=
"o"
>
+
</span>
<span
class=
"mi"
>
0
</span><span
class=
"p"
>
]],
</span>
<span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
filter_num
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
tokens
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
i
</span>
<span
class=
"o"
>
*
</span>
<span
class=
"mi"
>
3
</span>
<span
class=
"o"
>
+
</span>
<span
class=
"mi"
>
1
</span><span
class=
"p"
>
]],
</span>
<span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
filter_num
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
tokens
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
i
</span>
<span
class=
"o"
>
*
</span>
<span
class=
"mi"
>
3
</span>
<span
class=
"o"
>
+
</span>
<span
class=
"mi"
>
2
</span><span
class=
"p"
>
]],
</span>
<span
class=
"mi"
>
2
</span>
<span
class=
"k"
>
if
</span>
<span
class=
"bp"
>
self
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
block_mask
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
i
</span><span
class=
"p"
>
]
</span>
<span
class=
"o"
>
==
</span>
<span
class=
"mi"
>
1
</span>
<span
class=
"k"
>
else
</span>
<span
class=
"mi"
>
1
</span><span
class=
"p"
>
)
</span>
...
...
@@ -345,15 +346,6 @@
</div>
<footer>
<div
class=
"rst-footer-buttons"
role=
"navigation"
aria-label=
"footer navigation"
>
<a
href=
"../../table_latency/"
class=
"btn btn-neutral float-right"
title=
"硬件延时评估表"
>
Next
<span
class=
"icon icon-circle-arrow-right"
></span></a>
<a
href=
"../nas_api/"
class=
"btn btn-neutral"
title=
"SA搜索"
><span
class=
"icon icon-circle-arrow-left"
></span>
Previous
</a>
</div>
<hr/>
...
...
@@ -378,18 +370,14 @@
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/"
class=
"fa fa-github"
style=
"float: left; color: #fcfcfc"
>
GitHub
</a>
<span><a
href=
"../nas_api/"
style=
"color: #fcfcfc;"
>
«
Previous
</a></span>
<span
style=
"margin-left: 15px"
><a
href=
"../../table_latency/"
style=
"color: #fcfcfc"
>
Next
»
</a></span>
</span>
</div>
<script>
var
base_url
=
'
..
/..
'
;
</script>
<script
src=
"../
../
js/theme.js"
defer
></script>
<script
src=
"../
../
mathjax-config.js"
defer
></script>
<script>
var
base_url
=
'
..
'
;
</script>
<script
src=
"../js/theme.js"
defer
></script>
<script
src=
"../mathjax-config.js"
defer
></script>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
defer
></script>
<script
src=
"../
../
search/main.js"
defer
></script>
<script
src=
"../search/main.js"
defer
></script>
</body>
</html>
sitemap.xml
浏览文件 @
8a62b6fe
...
...
@@ -61,8 +61,8 @@
<changefreq>
daily
</changefreq>
</url>
<url>
<loc>
None
</loc>
<lastmod>
2020-01-09
</lastmod>
<loc></loc>
<changefreq>
daily
</changefreq>
</url>
<url>
...
...
sitemap.xml.gz
浏览文件 @
8a62b6fe
无法预览此类型文件
table_latency/index.html
浏览文件 @
8a62b6fe
...
...
@@ -111,7 +111,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
" current"
>
...
...
@@ -322,7 +322,7 @@
<a
href=
"../algo/algo/"
class=
"btn btn-neutral float-right"
title=
"算法原理"
>
Next
<span
class=
"icon icon-circle-arrow-right"
></span></a>
<a
href=
"../api/
search_space/"
class=
"btn btn-neutral"
title=
"搜索空间
"
><span
class=
"icon icon-circle-arrow-left"
></span>
Previous
</a>
<a
href=
"../api/
nas_api/"
class=
"btn btn-neutral"
title=
"SA搜索
"
><span
class=
"icon icon-circle-arrow-left"
></span>
Previous
</a>
</div>
...
...
@@ -350,7 +350,7 @@
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/"
class=
"fa fa-github"
style=
"float: left; color: #fcfcfc"
>
GitHub
</a>
<span><a
href=
"../api/
search_space
/"
style=
"color: #fcfcfc;"
>
«
Previous
</a></span>
<span><a
href=
"../api/
nas_api
/"
style=
"color: #fcfcfc;"
>
«
Previous
</a></span>
<span
style=
"margin-left: 15px"
><a
href=
"../algo/algo/"
style=
"color: #fcfcfc"
>
Next
»
</a></span>
...
...
tutorials/demo_guide/index.html
浏览文件 @
8a62b6fe
...
...
@@ -111,7 +111,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
tutorials/distillation_demo/index.html
浏览文件 @
8a62b6fe
...
...
@@ -134,7 +134,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
tutorials/nas_demo/index.html
浏览文件 @
8a62b6fe
...
...
@@ -123,7 +123,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -181,7 +181,7 @@
<h2
id=
"_2"
>
接口介绍
<a
class=
"headerlink"
href=
"#_2"
title=
"Permanent link"
>
#
</a></h2>
<p>
请参考。
</p>
<h3
id=
"1"
>
1. 配置搜索空间
<a
class=
"headerlink"
href=
"#1"
title=
"Permanent link"
>
#
</a></h3>
<p>
详细的搜索空间配置可以参考
<a
href=
'../../../paddleslim/nas/nas_api.md'
>
神经网络搜索API文档
</a>
。
<p>
详细的搜索空间配置可以参考
<a
href=
"https://paddlepaddle.github.io/PaddleSlim/api/nas_api/"
>
神经网络搜索API文档
</a>
。
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[(
</span><span
class=
"s1"
>
'
MobileNetV2Space
'
</span><span
class=
"p"
>
)]
</span>
</pre></div>
</td></tr></table></p>
...
...
tutorials/pruning_demo/index.html
浏览文件 @
8a62b6fe
...
...
@@ -111,7 +111,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
tutorials/quant_aware_demo/index.html
浏览文件 @
8a62b6fe
...
...
@@ -125,7 +125,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -181,7 +181,7 @@
<h1
id=
"_1"
>
在线量化示例
<a
class=
"headerlink"
href=
"#_1"
title=
"Permanent link"
>
#
</a></h1>
<p>
本示例介绍如何使用在线量化接口,来对训练好的分类模型进行量化, 可以减少模型的存储空间和显存占用。
</p>
<h2
id=
"_2"
>
接口介绍
<a
class=
"headerlink"
href=
"#_2"
title=
"Permanent link"
>
#
</a></h2>
<p>
请参考
<a
href=
'../../../paddleslim/quant/quantization_api_doc.md'
>
量化API文档
</a>
。
</p>
<p>
请参考
<a
href=
"https://paddlepaddle.github.io/PaddleSlim/api/quantization_api/"
>
量化API文档
</a>
。
</p>
<h2
id=
"_3"
>
分类模型的离线量化流程
<a
class=
"headerlink"
href=
"#_3"
title=
"Permanent link"
>
#
</a></h2>
<h3
id=
"1"
>
1. 配置量化参数
<a
class=
"headerlink"
href=
"#1"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
...
...
tutorials/quant_embedding_demo/index.html
浏览文件 @
8a62b6fe
...
...
@@ -125,7 +125,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -179,18 +179,18 @@
<div
class=
"section"
>
<h1
id=
"embedding"
>
Embedding量化示例
<a
class=
"headerlink"
href=
"#embedding"
title=
"Permanent link"
>
#
</a></h1>
<p>
本示例介绍如何使用Embedding量化的接口
<a
href=
""
>
paddleslim.quant.quant_embedding
</a>
。
<code>
quant_embedding
</code>
接口将网络中的Embedding参数从
<code>
float32
</code>
类型量化到
<code>
8-bit
</code>
整数类型,在几乎不损失模型精度的情况下减少模型的存储空间和显存占用。
</p>
<p>
接口介绍请参考
<a
href=
'../../../paddleslim/quant/quantization_api_doc.md'
>
量化API文档
</a>
。
</p>
<p>
本示例介绍如何使用Embedding量化的接口
<a
href=
"
https://paddlepaddle.github.io/PaddleSlim/api/quantization_api/
"
>
paddleslim.quant.quant_embedding
</a>
。
<code>
quant_embedding
</code>
接口将网络中的Embedding参数从
<code>
float32
</code>
类型量化到
<code>
8-bit
</code>
整数类型,在几乎不损失模型精度的情况下减少模型的存储空间和显存占用。
</p>
<p>
接口介绍请参考
<a
href=
"https://paddlepaddle.github.io/PaddleSlim/api/quantization_api/"
>
量化API文档
</a>
。
</p>
<p>
该接口对program的修改:
</p>
<p>
量化前:
</p>
<p
align=
"center"
>
<img
src=
"
.
/image/before.png"
height=
200
width=
100
hspace=
'10'
/>
<br
/>
<img
src=
"
https://raw.githubusercontent.com/PaddlePaddle/PaddleSlim/develop/demo/quant/quant_embedding
/image/before.png"
height=
200
width=
100
hspace=
'10'
/>
<br
/>
<strong>
图1:量化前的模型结构
</strong>
</p>
<p>
量化后:
</p>
<p
align=
"center"
>
<img
src=
"
.
/image/after.png"
height=
300
width=
300
hspace=
'10'
/>
<br
/>
<img
src=
"
https://raw.githubusercontent.com/PaddlePaddle/PaddleSlim/develop/demo/quant/quant_embedding
/image/after.png"
height=
300
width=
300
hspace=
'10'
/>
<br
/>
<strong>
图2: 量化后的模型结构
</strong>
</p>
...
...
tutorials/quant_post_demo/index.html
浏览文件 @
8a62b6fe
...
...
@@ -125,7 +125,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
@@ -181,7 +181,7 @@
<h1
id=
"_1"
>
离线量化示例
<a
class=
"headerlink"
href=
"#_1"
title=
"Permanent link"
>
#
</a></h1>
<p>
本示例介绍如何使用离线量化接口
<code>
paddleslim.quant.quant_post
</code>
来对训练好的分类模型进行离线量化, 该接口无需对模型进行训练就可得到量化模型,减少模型的存储空间和显存占用。
</p>
<h2
id=
"_2"
>
接口介绍
<a
class=
"headerlink"
href=
"#_2"
title=
"Permanent link"
>
#
</a></h2>
<p>
请参考
<a
href=
'../../../paddleslim/quant/quantization_api_doc.md'
>
量化API文档
</a>
。
</p>
<p>
请参考
<a
href=
"https://paddlepaddle.github.io/PaddleSlim/api/quantization_api/"
>
量化API文档
</a>
。
</p>
<h2
id=
"_3"
>
分类模型的离线量化流程
<a
class=
"headerlink"
href=
"#_3"
title=
"Permanent link"
>
#
</a></h2>
<h3
id=
"_4"
>
准备数据
<a
class=
"headerlink"
href=
"#_4"
title=
"Permanent link"
>
#
</a></h3>
<p>
在当前文件夹下创建
<code>
data
</code>
文件夹,将
<code>
imagenet
</code>
数据集解压在
<code>
data
</code>
文件夹下,解压后
<code>
data
</code>
文件夹下应包含以下文件:
...
...
@@ -200,7 +200,7 @@
</td></tr></table>
转化之后的模型存储在
<code>
inference_model/MobileNet/
</code>
文件夹下,可看到该文件夹下有
<code>
'model'
</code>
,
<code>
'weights'
</code>
两个文件。
</p>
<h3
id=
"_7"
>
离线量化
<a
class=
"headerlink"
href=
"#_7"
title=
"Permanent link"
>
#
</a></h3>
<p>
接下来对导出的模型文件进行离线量化,离线量化的脚本为
<a
href=
"
.
/quant_post.py"
>
quant_post.py
</a>
,脚本中使用接口
<code>
paddleslim.quant.quant_post
</code>
对模型进行离线量化。运行命令为:
<p>
接下来对导出的模型文件进行离线量化,离线量化的脚本为
<a
href=
"
https://github.com/PaddlePaddle/PaddleSlim/blob/develop/demo/quant/quant_post
/quant_post.py"
>
quant_post.py
</a>
,脚本中使用接口
<code>
paddleslim.quant.quant_post
</code>
对模型进行离线量化。运行命令为:
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
python
</span>
<span
class=
"n"
>
quant_post
</span><span
class=
"p"
>
.
</span><span
class=
"n"
>
py
</span>
<span
class=
"c1"
>
--model_path ./inference_model/MobileNet --save_path ./quant_model_train/MobileNet --model_filename model --params_filename weights
</span>
</pre></div>
</td></tr></table></p>
...
...
@@ -215,7 +215,7 @@
<p>
使用的量化算法为
<code>
'KL'
</code>
, 使用训练集中的160张图片进行量化参数的校正。
</p>
</blockquote>
<h3
id=
"_8"
>
测试精度
<a
class=
"headerlink"
href=
"#_8"
title=
"Permanent link"
>
#
</a></h3>
<p>
使用
<a
href=
"
.
/eval.py"
>
eval.py
</a>
脚本对量化前后的模型进行测试,得到模型的分类精度进行对比。
</p>
<p>
使用
<a
href=
"
https://github.com/PaddlePaddle/PaddleSlim/blob/develop/demo/quant/quant_post
/eval.py"
>
eval.py
</a>
脚本对量化前后的模型进行测试,得到模型的分类精度进行对比。
</p>
<p>
首先测试量化前的模型的精度,运行以下命令:
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
python
</span>
<span
class=
"n"
>
eval
</span><span
class=
"p"
>
.
</span><span
class=
"n"
>
py
</span>
<span
class=
"c1"
>
--model_path ./inference_model/MobileNet --model_name model --params_name weights
</span>
</pre></div>
...
...
tutorials/sensitivity_demo/index.html
浏览文件 @
8a62b6fe
...
...
@@ -111,7 +111,7 @@
</li>
<li
class=
""
>
<a
class=
""
href=
"../../api/search_space
/
"
>
搜索空间
</a>
<a
class=
""
href=
"../../api/search_space
.md
"
>
搜索空间
</a>
</li>
<li
class=
""
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录