Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
2df3f722
P
PaddleX
项目概览
PaddlePaddle
/
PaddleX
通知
138
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
43
列表
看板
标记
里程碑
合并请求
5
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleX
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
43
Issue
43
列表
看板
标记
里程碑
合并请求
5
合并请求
5
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2df3f722
编写于
5月 15, 2020
作者:
S
sunyanfang01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify time
上级
32c842bb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
17 deletion
+17
-17
paddlex/cv/models/slim/post_quantization.py
paddlex/cv/models/slim/post_quantization.py
+17
-17
未找到文件。
paddlex/cv/models/slim/post_quantization.py
浏览文件 @
2df3f722
...
...
@@ -21,7 +21,7 @@ import paddle.fluid as fluid
import
os
import
re
import
numpy
as
np
import
date
time
import
time
class
PaddleXPostTrainingQuantization
(
PostTrainingQuantization
):
...
...
@@ -134,18 +134,18 @@ class PaddleXPostTrainingQuantization(PostTrainingQuantization):
batch_id
=
0
logging
.
info
(
"Start to run batch!"
)
for
data
in
self
.
_data_loader
():
start
=
datetime
.
datetime
.
now
()
start
=
time
.
time
()
self
.
_executor
.
run
(
program
=
self
.
_program
,
feed
=
data
,
fetch_list
=
self
.
_fetch_list
,
return_numpy
=
False
)
self
.
_sample_data
(
batch_id
)
end
=
datetime
.
datetime
.
now
()
logging
.
debug
(
'[Run batch data] Batch={}/{}, time_each_batch={}
m
s.'
.
format
(
end
=
time
.
time
()
logging
.
debug
(
'[Run batch data] Batch={}/{}, time_each_batch={} s.'
.
format
(
str
(
batch_id
+
1
),
str
(
batch_ct
),
str
(
(
end
-
start
).
microseconds
)))
str
(
end
-
start
)))
batch_id
+=
1
if
self
.
_batch_nums
and
batch_id
>=
self
.
_batch_nums
:
break
...
...
@@ -241,7 +241,7 @@ class PaddleXPostTrainingQuantization(PostTrainingQuantization):
# apply channel_wise_abs_max quantization for weights
ct
=
1
for
var_name
in
self
.
_quantized_weight_var_name
:
start
=
datetime
.
datetime
.
now
()
start
=
time
.
time
()
data
=
self
.
_sampling_data
[
var_name
]
scale_factor_per_channel
=
[]
for
i
in
range
(
data
.
shape
[
0
]):
...
...
@@ -249,18 +249,18 @@ class PaddleXPostTrainingQuantization(PostTrainingQuantization):
scale_factor_per_channel
.
append
(
abs_max_value
)
self
.
_quantized_var_scale_factor
[
var_name
]
=
scale_factor_per_channel
end
=
datetime
.
datetime
.
now
()
logging
.
debug
(
'[Calculate weight] Weight_id={}/{}, time_each_weight={}
m
s.'
.
format
(
end
=
time
.
time
()
logging
.
debug
(
'[Calculate weight] Weight_id={}/{}, time_each_weight={} s.'
.
format
(
str
(
ct
),
str
(
len
(
self
.
_quantized_weight_var_name
)),
str
(
(
end
-
start
).
microseconds
)))
str
(
end
-
start
)))
ct
+=
1
ct
=
1
# apply kl quantization for activation
if
self
.
_is_use_cache_file
:
for
var_name
in
self
.
_quantized_act_var_name
:
start
=
datetime
.
datetime
.
now
()
start
=
time
.
time
()
sampling_data
=
[]
filenames
=
[
f
for
f
in
os
.
listdir
(
self
.
_cache_dir
)
\
if
re
.
match
(
var_name
+
'_[0-9]+.npy'
,
f
)]
...
...
@@ -276,15 +276,15 @@ class PaddleXPostTrainingQuantization(PostTrainingQuantization):
else
:
self
.
_quantized_var_scale_factor
[
var_name
]
=
\
np
.
max
(
np
.
abs
(
sampling_data
))
end
=
datetime
.
datetime
.
now
()
logging
.
debug
(
'[Calculate activation] Activation_id={}/{}, time_each_activation={}
m
s.'
.
format
(
end
=
time
.
time
()
logging
.
debug
(
'[Calculate activation] Activation_id={}/{}, time_each_activation={} s.'
.
format
(
str
(
ct
),
str
(
len
(
self
.
_quantized_act_var_name
)),
str
(
(
end
-
start
).
microseconds
)))
str
(
end
-
start
)))
ct
+=
1
else
:
for
var_name
in
self
.
_quantized_act_var_name
:
start
=
datetime
.
datetime
.
now
()
start
=
time
.
time
()
self
.
_sampling_data
[
var_name
]
=
np
.
concatenate
(
self
.
_sampling_data
[
var_name
])
if
self
.
_algo
==
"KL"
:
...
...
@@ -293,9 +293,9 @@ class PaddleXPostTrainingQuantization(PostTrainingQuantization):
else
:
self
.
_quantized_var_scale_factor
[
var_name
]
=
\
np
.
max
(
np
.
abs
(
self
.
_sampling_data
[
var_name
]))
end
=
datetime
.
datetime
.
now
()
logging
.
debug
(
'[Calculate activation] Activation_id={}/{}, time_each_activation={}
m
s.'
.
format
(
end
=
time
.
time
()
logging
.
debug
(
'[Calculate activation] Activation_id={}/{}, time_each_activation={} s.'
.
format
(
str
(
ct
),
str
(
len
(
self
.
_quantized_act_var_name
)),
str
(
(
end
-
start
).
microseconds
)))
str
(
end
-
start
)))
ct
+=
1
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录