Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
271fbf44
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看板
提交
271fbf44
编写于
7月 27, 2020
作者:
B
baiyfbupt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
replace datafeeder with dataloader
上级
fa44693a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
27 addition
and
19 deletion
+27
-19
demo/quant/pact_quant_aware/train.py
demo/quant/pact_quant_aware/train.py
+27
-19
未找到文件。
demo/quant/pact_quant_aware/train.py
浏览文件 @
271fbf44
...
...
@@ -15,6 +15,7 @@ from paddleslim.analysis import flops
from
paddleslim.quant
import
quant_aware
,
quant_post
,
convert
import
models
from
utility
import
add_arguments
,
print_arguments
sys
.
path
.
append
(
'./'
)
from
pact
import
*
quantization_model_save_dir
=
'./quantization_models/'
...
...
@@ -133,8 +134,8 @@ def compress(args):
raise
ValueError
(
"{} is not supported."
.
format
(
args
.
data
))
image_shape
=
[
int
(
m
)
for
m
in
image_shape
.
split
(
","
)]
assert
args
.
model
in
model_list
,
"{} is not in lists: {}"
.
format
(
args
.
model
,
model_list
)
assert
args
.
model
in
model_list
,
"{} is not in lists: {}"
.
format
(
args
.
model
,
model_list
)
image
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
image_shape
,
dtype
=
'float32'
)
if
args
.
use_pact
:
image
.
stop_gradient
=
False
...
...
@@ -196,8 +197,7 @@ def compress(args):
if
args
.
pretrained_model
:
def
if_exist
(
var
):
return
os
.
path
.
exists
(
os
.
path
.
join
(
args
.
pretrained_model
,
var
.
name
))
return
os
.
path
.
exists
(
os
.
path
.
join
(
args
.
pretrained_model
,
var
.
name
))
fluid
.
io
.
load_vars
(
exe
,
args
.
pretrained_model
,
predicate
=
if_exist
)
...
...
@@ -205,20 +205,29 @@ def compress(args):
train_reader
=
paddle
.
fluid
.
io
.
batch
(
train_reader
,
batch_size
=
args
.
batch_size
,
drop_last
=
True
)
train_feeder
=
feeder
=
fluid
.
DataFeeder
([
image
,
label
],
place
)
val_feeder
=
feeder
=
fluid
.
DataFeeder
(
[
image
,
label
],
place
,
program
=
val_program
)
train_loader
=
fluid
.
io
.
DataLoader
.
from_generator
(
feed_list
=
[
image
,
label
],
capacity
=
512
,
use_double_buffer
=
True
,
iterable
=
True
)
valid_loader
=
fluid
.
io
.
DataLoader
.
from_generator
(
feed_list
=
[
image
,
label
],
capacity
=
512
,
use_double_buffer
=
True
,
iterable
=
True
)
places
=
fluid
.
cuda_places
()
if
args
.
use_gpu
else
fluid
.
cpu_places
()
train_loader
.
set_sample_list_generator
(
train_reader
,
places
)
valid_loader
.
set_sample_list_generator
(
val_reader
,
place
)
def
test
(
epoch
,
program
):
batch_id
=
0
acc_top1_ns
=
[]
acc_top5_ns
=
[]
for
data
in
val
_re
ader
():
for
data
in
val
id_lo
ader
():
start_time
=
time
.
time
()
acc_top1_n
,
acc_top5_n
=
exe
.
run
(
program
,
feed
=
train_feeder
.
feed
(
data
),
fetch_list
=
[
acc_top1
.
name
,
acc_top5
.
name
])
program
,
feed
=
data
,
fetch_list
=
[
acc_top1
.
name
,
acc_top5
.
name
])
end_time
=
time
.
time
()
if
batch_id
%
args
.
log_period
==
0
:
_logger
.
info
(
...
...
@@ -230,20 +239,19 @@ def compress(args):
acc_top5_ns
.
append
(
np
.
mean
(
acc_top5_n
))
batch_id
+=
1
_logger
.
info
(
"Final eval epoch[{}] - acc_top1: {}; acc_top5: {}"
.
format
(
epoch
,
np
.
mean
(
np
.
array
(
acc_top1_ns
)),
np
.
mean
(
np
.
array
(
acc_top5_ns
))))
_logger
.
info
(
"Final eval epoch[{}] - acc_top1: {}; acc_top5: {}"
.
format
(
epoch
,
np
.
mean
(
np
.
array
(
acc_top1_ns
)),
np
.
mean
(
np
.
array
(
acc_top5_ns
))))
return
np
.
mean
(
np
.
array
(
acc_top1_ns
))
def
train
(
epoch
,
compiled_train_prog
):
batch_id
=
0
for
data
in
train_
re
ader
():
for
data
in
train_
lo
ader
():
start_time
=
time
.
time
()
loss_n
,
acc_top1_n
,
acc_top5_n
=
exe
.
run
(
compiled_train_prog
,
feed
=
train_feeder
.
feed
(
data
)
,
feed
=
data
,
fetch_list
=
[
avg_cost
.
name
,
acc_top1
.
name
,
acc_top5
.
name
])
end_time
=
time
.
time
()
loss_n
=
np
.
mean
(
loss_n
)
...
...
@@ -259,8 +267,8 @@ def compress(args):
threshold
=
{}
for
var
in
val_program
.
list_vars
():
if
'pact'
in
var
.
name
:
array
=
np
.
array
(
fluid
.
global_scope
().
find_var
(
var
.
name
)
.
get_tensor
())
array
=
np
.
array
(
fluid
.
global_scope
().
find_var
(
var
.
name
)
.
get_tensor
())
threshold
[
var
.
name
]
=
array
[
0
]
print
(
threshold
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录