Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
8386c609
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
8386c609
编写于
12月 22, 2022
作者:
G
Guanghua Yu
提交者:
GitHub
12月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix unittest in post training quantization (#49256)
上级
4537ba23
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
17 deletion
+33
-17
python/paddle/fluid/contrib/slim/tests/test_post_training_quantization_mobilenetv1.py
...slim/tests/test_post_training_quantization_mobilenetv1.py
+33
-17
未找到文件。
python/paddle/fluid/contrib/slim/tests/test_post_training_quantization_mobilenetv1.py
浏览文件 @
8386c609
...
...
@@ -209,7 +209,12 @@ class TestPostTrainingQuantization(unittest.TestCase):
infer_program
,
feed_dict
,
fetch_targets
,
]
=
fluid
.
io
.
load_inference_model
(
model_path
,
exe
)
]
=
fluid
.
io
.
load_inference_model
(
model_path
,
exe
,
model_filename
=
"inference.pdmodel"
,
params_filename
=
"inference.pdiparams"
,
)
val_reader
=
paddle
.
batch
(
val
(),
batch_size
)
iterations
=
infer_iterations
...
...
@@ -224,16 +229,21 @@ class TestPostTrainingQuantization(unittest.TestCase):
label
=
label
.
reshape
([
-
1
,
1
])
t1
=
time
.
time
()
_
,
acc1
,
_
=
exe
.
run
(
pred
=
exe
.
run
(
infer_program
,
feed
=
{
feed_dict
[
0
]:
image
,
feed_dict
[
1
]:
label
},
feed
=
{
feed_dict
[
0
]:
image
},
fetch_list
=
fetch_targets
,
)
t2
=
time
.
time
()
period
=
t2
-
t1
periods
.
append
(
period
)
test_info
.
append
(
np
.
mean
(
acc1
)
*
len
(
data
))
pred
=
np
.
array
(
pred
[
0
])
sort_array
=
pred
.
argsort
(
axis
=
1
)
top_1_pred
=
sort_array
[:,
-
1
:][:,
::
-
1
]
top_1
=
np
.
mean
(
label
==
top_1_pred
)
test_info
.
append
(
np
.
mean
(
top_1
)
*
len
(
data
))
cnt
+=
len
(
data
)
if
(
batch_id
+
1
)
%
100
==
0
:
...
...
@@ -277,6 +287,8 @@ class TestPostTrainingQuantization(unittest.TestCase):
executor
=
exe
,
sample_generator
=
val_reader
,
model_dir
=
model_path
,
model_filename
=
"inference.pdmodel"
,
params_filename
=
"inference.pdiparams"
,
batch_size
=
batch_size
,
batch_nums
=
batch_nums
,
algo
=
algo
,
...
...
@@ -288,7 +300,11 @@ class TestPostTrainingQuantization(unittest.TestCase):
is_use_cache_file
=
is_use_cache_file
,
)
ptq
.
quantize
()
ptq
.
save_quantized_model
(
self
.
int8_model
)
ptq
.
save_quantized_model
(
self
.
int8_model
,
model_filename
=
"inference.pdmodel"
,
params_filename
=
"inference.pdiparams"
,
)
def
run_test
(
self
,
...
...
@@ -316,7 +332,7 @@ class TestPostTrainingQuantization(unittest.TestCase):
)
)
(
fp32_throughput
,
fp32_latency
,
fp32_acc1
)
=
self
.
run_program
(
os
.
path
.
join
(
model_cache_folder
,
"
model
"
),
os
.
path
.
join
(
model_cache_folder
,
"
MobileNetV1_infer
"
),
batch_size
,
infer_iterations
,
)
...
...
@@ -327,7 +343,7 @@ class TestPostTrainingQuantization(unittest.TestCase):
)
)
self
.
generate_quantized_model
(
os
.
path
.
join
(
model_cache_folder
,
"
model
"
),
os
.
path
.
join
(
model_cache_folder
,
"
MobileNetV1_infer
"
),
quantizable_op_type
,
batch_size
,
algo
,
...
...
@@ -371,9 +387,9 @@ class TestPostTrainingKLForMobilenetv1(TestPostTrainingQuantization):
algo
=
"KL"
round_type
=
"round"
data_urls
=
[
'http
://paddle-inference-dist.bj.bcebos.com/int8/mobilenetv1_int8_model.tar.gz
'
'http
s://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV1_infer.tar
'
]
data_md5s
=
[
'
13892b0716d26443a8cdea15b3c6438b
'
]
data_md5s
=
[
'
5ee2b1775b11dc233079236cdc216c2e
'
]
quantizable_op_type
=
[
"conv2d"
,
"depthwise_conv2d"
,
...
...
@@ -405,9 +421,9 @@ class TestPostTrainingavgForMobilenetv1(TestPostTrainingQuantization):
algo
=
"avg"
round_type
=
"round"
data_urls
=
[
'http
://paddle-inference-dist.bj.bcebos.com/int8/mobilenetv1_int8_model.tar.gz
'
'http
s://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV1_infer.tar
'
]
data_md5s
=
[
'
13892b0716d26443a8cdea15b3c6438b
'
]
data_md5s
=
[
'
5ee2b1775b11dc233079236cdc216c2e
'
]
quantizable_op_type
=
[
"conv2d"
,
"depthwise_conv2d"
,
...
...
@@ -437,9 +453,9 @@ class TestPostTraininghistForMobilenetv1(TestPostTrainingQuantization):
algo
=
"hist"
round_type
=
"round"
data_urls
=
[
'http
://paddle-inference-dist.bj.bcebos.com/int8/mobilenetv1_int8_model.tar.gz
'
'http
s://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV1_infer.tar
'
]
data_md5s
=
[
'
13892b0716d26443a8cdea15b3c6438b
'
]
data_md5s
=
[
'
5ee2b1775b11dc233079236cdc216c2e
'
]
quantizable_op_type
=
[
"conv2d"
,
"depthwise_conv2d"
,
...
...
@@ -471,9 +487,9 @@ class TestPostTrainingAbsMaxForMobilenetv1(TestPostTrainingQuantization):
algo
=
"abs_max"
round_type
=
"round"
data_urls
=
[
'http
://paddle-inference-dist.bj.bcebos.com/int8/mobilenetv1_int8_model.tar.gz
'
'http
s://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV1_infer.tar
'
]
data_md5s
=
[
'
13892b0716d26443a8cdea15b3c6438b
'
]
data_md5s
=
[
'
5ee2b1775b11dc233079236cdc216c2e
'
]
quantizable_op_type
=
[
"conv2d"
,
"mul"
,
...
...
@@ -503,9 +519,9 @@ class TestPostTrainingAvgONNXFormatForMobilenetv1(TestPostTrainingQuantization):
algo
=
"emd"
round_type
=
"round"
data_urls
=
[
'http
://paddle-inference-dist.bj.bcebos.com/int8/mobilenetv1_int8_model.tar.gz
'
'http
s://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV1_infer.tar
'
]
data_md5s
=
[
'
13892b0716d26443a8cdea15b3c6438b
'
]
data_md5s
=
[
'
5ee2b1775b11dc233079236cdc216c2e
'
]
quantizable_op_type
=
[
"conv2d"
,
"depthwise_conv2d"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录