Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
84865b80
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
84865b80
编写于
11月 25, 2019
作者:
J
juncaipeng
提交者:
Tao Luo
11月 25, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add resnet50 test for post trainint quantization, test=develop (#21272)
上级
9a7832f8
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
67 addition
and
38 deletion
+67
-38
python/paddle/fluid/contrib/slim/quantization/post_training_quantization.py
...d/contrib/slim/quantization/post_training_quantization.py
+1
-1
python/paddle/fluid/contrib/slim/tests/CMakeLists.txt
python/paddle/fluid/contrib/slim/tests/CMakeLists.txt
+2
-1
python/paddle/fluid/contrib/slim/tests/test_post_training_quantization_mobilenetv1.py
...slim/tests/test_post_training_quantization_mobilenetv1.py
+32
-36
python/paddle/fluid/contrib/slim/tests/test_post_training_quantization_resnet50.py
...ib/slim/tests/test_post_training_quantization_resnet50.py
+32
-0
未找到文件。
python/paddle/fluid/contrib/slim/quantization/post_training_quantization.py
浏览文件 @
84865b80
...
...
@@ -99,7 +99,7 @@ class PostTrainingQuantization(object):
params_filename = None
save_model_path = path/to/save_model_path
# prepare the sample generator according to the model, and the
# sample generator must return a s
i
mple every time. The reference
# sample generator must return a s
a
mple every time. The reference
# document: https://www.paddlepaddle.org.cn/documentation/docs/zh
# /user_guides/howto/prepare_data/use_py_reader.html
sample_generator = your_sample_generator
...
...
python/paddle/fluid/contrib/slim/tests/CMakeLists.txt
浏览文件 @
84865b80
...
...
@@ -48,7 +48,8 @@ endfunction()
if
(
WIN32
)
list
(
REMOVE_ITEM TEST_OPS test_light_nas
)
list
(
REMOVE_ITEM TEST_OPS test_post_training_quantization
)
list
(
REMOVE_ITEM TEST_OPS test_post_training_quantization_mobilenetv1
)
list
(
REMOVE_ITEM TEST_OPS test_post_training_quantization_resnet50
)
endif
()
# int8 image classification python api test
...
...
python/paddle/fluid/contrib/slim/tests/test_post_training_quantization.py
→
python/paddle/fluid/contrib/slim/tests/test_post_training_quantization
_mobilenetv1
.py
浏览文件 @
84865b80
...
...
@@ -110,10 +110,9 @@ class TestPostTrainingQuantization(unittest.TestCase):
self
.
int8_download
=
'int8/download'
self
.
cache_folder
=
os
.
path
.
expanduser
(
'~/.cache/paddle/dataset/'
+
self
.
int8_download
)
self
.
data_cache_folder
=
''
data_urls
=
[]
data_md5s
=
[]
self
.
data_cache_folder
=
''
if
os
.
environ
.
get
(
'DATASET'
)
==
'full'
:
data_urls
.
append
(
'https://paddle-inference-dist.bj.bcebos.com/int8/ILSVRC2012_img_val.tar.gz.partaa'
...
...
@@ -145,7 +144,8 @@ class TestPostTrainingQuantization(unittest.TestCase):
'DATASET'
)
==
'full'
else
1
self
.
timestamp
=
time
.
strftime
(
'%Y-%m-%d-%H-%M-%S'
,
time
.
localtime
())
self
.
int8_model
=
''
self
.
int8_model
=
os
.
path
.
join
(
os
.
getcwd
(),
"post_training_"
+
self
.
timestamp
)
def
tearDown
(
self
):
try
:
...
...
@@ -191,14 +191,14 @@ class TestPostTrainingQuantization(unittest.TestCase):
def
download_model
(
self
):
pass
def
run_program
(
self
,
model_path
):
def
run_program
(
self
,
model_path
,
batch_size
,
infer_iterations
):
image_shape
=
[
3
,
224
,
224
]
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
[
infer_program
,
feed_dict
,
fetch_targets
]
=
\
fluid
.
io
.
load_inference_model
(
model_path
,
exe
)
val_reader
=
paddle
.
batch
(
val
(),
self
.
batch_size
)
iterations
=
self
.
infer_iterations
val_reader
=
paddle
.
batch
(
val
(),
batch_size
)
iterations
=
infer_iterations
test_info
=
[]
cnt
=
0
...
...
@@ -237,8 +237,6 @@ class TestPostTrainingQuantization(unittest.TestCase):
model_path
,
algo
=
"KL"
,
is_full_quantize
=
False
):
self
.
int8_model
=
os
.
path
.
join
(
os
.
getcwd
(),
"post_training_"
+
self
.
timestamp
)
try
:
os
.
system
(
"mkdir "
+
self
.
int8_model
)
except
Exception
as
e
:
...
...
@@ -264,52 +262,50 @@ class TestPostTrainingQuantization(unittest.TestCase):
ptq
.
quantize
()
ptq
.
save_quantized_model
(
self
.
int8_model
)
def
run_test
(
self
,
model
,
algo
,
data_urls
,
data_md5s
):
infer_iterations
=
self
.
infer_iterations
batch_size
=
self
.
batch_size
sample_iterations
=
self
.
sample_iterations
class
TestPostTrainingForMobilenetv1
(
TestPostTrainingQuantization
):
def
download_model
(
self
):
# mobilenetv1 fp32 data
data_urls
=
[
'http://paddle-inference-dist.bj.bcebos.com/int8/mobilenetv1_int8_model.tar.gz'
]
data_md5s
=
[
'13892b0716d26443a8cdea15b3c6438b'
]
self
.
model_cache_folder
=
self
.
download_data
(
data_urls
,
data_md5s
,
"mobilenetv1_fp32"
)
self
.
model
=
"MobileNet-V1"
self
.
algo
=
"KL"
def
test_post_training_mobilenetv1
(
self
):
self
.
download_model
()
model_cache_folder
=
self
.
download_data
(
data_urls
,
data_md5s
,
model
)
print
(
"Start FP32 inference for {0} on {1} images ..."
.
format
(
self
.
model
,
self
.
infer_iterations
*
self
.
batch_size
))
(
fp32_throughput
,
fp32_latency
,
fp32_acc1
)
=
self
.
run_program
(
self
.
model_cache_folder
+
"/model"
)
model
,
infer_iterations
*
batch_size
))
(
fp32_throughput
,
fp32_latency
,
fp32_acc1
)
=
self
.
run_program
(
model_cache_folder
+
"/model"
,
batch_size
,
infer_iterations
)
print
(
"Start INT8 post training quantization for {0} on {1} images ..."
.
format
(
self
.
model
,
self
.
sample_iterations
*
self
.
batch_size
))
format
(
model
,
sample_iterations
*
batch_size
))
self
.
generate_quantized_model
(
self
.
model_cache_folder
+
"/model"
,
algo
=
self
.
algo
,
is_full_quantize
=
True
)
model_cache_folder
+
"/model"
,
algo
=
algo
,
is_full_quantize
=
True
)
print
(
"Start INT8 inference for {0} on {1} images ..."
.
format
(
self
.
model
,
self
.
infer_iterations
*
self
.
batch_size
))
(
int8_throughput
,
int8_latency
,
int8_acc1
)
=
self
.
run_program
(
self
.
int8_model
)
model
,
infer_iterations
*
batch_size
))
(
int8_throughput
,
int8_latency
,
int8_acc1
)
=
self
.
run_program
(
self
.
int8_model
,
batch_size
,
infer_iterations
)
print
(
"FP32 {0}: batch_size {1}, throughput {2} images/second, latency {3} second, accuracy {4}"
.
format
(
self
.
model
,
self
.
batch_size
,
fp32_throughput
,
fp32_latency
,
fp32_acc1
))
format
(
model
,
batch_size
,
fp32_throughput
,
fp32_latency
,
fp32_acc1
))
print
(
"INT8 {0}: batch_size {1}, throughput {2} images/second, latency {3} second, accuracy {4}"
.
format
(
self
.
model
,
self
.
batch_size
,
int8_throughput
,
int8_latency
,
int8_acc1
))
format
(
model
,
batch_size
,
int8_throughput
,
int8_latency
,
int8_acc1
))
sys
.
stdout
.
flush
()
delta_value
=
fp32_acc1
-
int8_acc1
self
.
assertLess
(
delta_value
,
0.025
)
class
TestPostTrainingForMobilenetv1
(
TestPostTrainingQuantization
):
def
test_post_training_mobilenetv1
(
self
):
model
=
"MobileNet-V1"
algo
=
"KL"
data_urls
=
[
'http://paddle-inference-dist.bj.bcebos.com/int8/mobilenetv1_int8_model.tar.gz'
]
data_md5s
=
[
'13892b0716d26443a8cdea15b3c6438b'
]
self
.
run_test
(
model
,
algo
,
data_urls
,
data_md5s
)
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/contrib/slim/tests/test_post_training_quantization_resnet50.py
0 → 100644
浏览文件 @
84865b80
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
sys
import
unittest
from
test_post_training_quantization_mobilenetv1
import
TestPostTrainingQuantization
class
TestPostTrainingForResnet50
(
TestPostTrainingQuantization
):
def
test_post_training_resnet50
(
self
):
model
=
"ResNet-50"
algo
=
"direct"
data_urls
=
[
'http://paddle-inference-dist.bj.bcebos.com/int8/resnet50_int8_model.tar.gz'
]
data_md5s
=
[
'4a5194524823d9b76da6e738e1367881'
]
self
.
run_test
(
model
,
algo
,
data_urls
,
data_md5s
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录