Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
a7936b3f
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看板
未验证
提交
a7936b3f
编写于
7月 14, 2022
作者:
C
ceci3
提交者:
GitHub
7月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix auto compress bugs (#1293)
* fix demo * add unittest * update unittest
上级
ae630a78
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
82 addition
and
13 deletion
+82
-13
example/auto_compression/semantic_segmentation/run.py
example/auto_compression/semantic_segmentation/run.py
+2
-2
paddleslim/auto_compression/compressor.py
paddleslim/auto_compression/compressor.py
+2
-1
paddleslim/quant/post_quant_hpo.py
paddleslim/quant/post_quant_hpo.py
+9
-10
tests/act/test_demo.py
tests/act/test_demo.py
+69
-0
未找到文件。
example/auto_compression/semantic_segmentation/run.py
浏览文件 @
a7936b3f
...
...
@@ -47,7 +47,7 @@ def eval_function(exe, compiled_test_program, test_feed_names, test_fetch_list):
loader
=
paddle
.
io
.
DataLoader
(
eval_dataset
,
batch_sampler
=
batch_sampler
,
num_workers
=
1
,
num_workers
=
0
,
return_list
=
True
,
)
total_iters
=
len
(
loader
)
...
...
@@ -137,7 +137,7 @@ def main(args):
train_dataset
,
places
=
[
place
],
batch_sampler
=
batch_sampler
,
num_workers
=
2
,
num_workers
=
0
,
return_list
=
True
,
worker_init_fn
=
worker_init_fn
)
train_dataloader
=
reader_wrapper
(
train_loader
)
...
...
paddleslim/auto_compression/compressor.py
浏览文件 @
a7936b3f
...
...
@@ -143,6 +143,8 @@ class AutoCompression:
self
.
train_config
=
TrainConfig
(
**
config
.
pop
(
'TrainConfig'
))
else
:
self
.
train_config
=
None
else
:
self
.
train_config
=
None
self
.
strategy_config
=
extract_strategy_config
(
config
)
# prepare dataloader
...
...
@@ -596,7 +598,6 @@ class AutoCompression:
_logger
.
info
(
"==> The ACT compression has been completed and the final model is saved in `{}`"
.
format
(
final_model_path
))
os
.
_exit
(
0
)
def
single_strategy_compress
(
self
,
strategy
,
config
,
strategy_idx
,
train_config
):
...
...
paddleslim/quant/post_quant_hpo.py
浏览文件 @
a7936b3f
...
...
@@ -144,12 +144,7 @@ def standardization(data):
"""standardization numpy array"""
mu
=
np
.
mean
(
data
,
axis
=
0
)
sigma
=
np
.
std
(
data
,
axis
=
0
)
if
isinstance
(
sigma
,
list
)
or
isinstance
(
sigma
,
np
.
ndarray
):
for
idx
,
sig
in
enumerate
(
sigma
):
if
sig
==
0.
:
sigma
[
idx
]
=
1e-13
else
:
sigma
=
1e-13
if
sigma
==
0.
else
sigma
sigma
=
1e-13
if
sigma
==
0.
else
sigma
return
(
data
-
mu
)
/
sigma
...
...
@@ -246,15 +241,19 @@ def eval_quant_model():
if
have_invalid_num
(
out_float
)
or
have_invalid_num
(
out_quant
):
continue
out_float_list
.
append
(
list
(
out_float
))
out_quant_list
.
append
(
list
(
out_quant
))
try
:
if
len
(
out_float
)
>
3
:
out_float
=
standardization
(
out_float
)
out_quant
=
standardization
(
out_quant
)
except
:
continue
out_float_list
.
append
(
out_float
)
out_quant_list
.
append
(
out_quant
)
valid_data_num
+=
1
if
valid_data_num
>=
max_eval_data_num
:
break
out_float_list
=
standardization
(
out_float_list
)
out_quant_list
=
standardization
(
out_quant_list
)
emd_sum
=
cal_emd_lose
(
out_float_list
,
out_quant_list
,
out_len_sum
/
float
(
valid_data_num
))
_logger
.
info
(
"output diff: {}"
.
format
(
emd_sum
))
...
...
tests/act/test_demo.py
0 → 100644
浏览文件 @
a7936b3f
import
os
import
sys
import
unittest
sys
.
path
.
append
(
"../../"
)
import
paddle
from
PIL
import
Image
from
paddle.vision.datasets
import
DatasetFolder
from
paddle.vision.transforms
import
transforms
from
paddleslim.auto_compression
import
AutoCompression
paddle
.
enable_static
()
class
ImageNetDataset
(
DatasetFolder
):
def
__init__
(
self
,
path
,
image_size
=
224
):
super
(
ImageNetDataset
,
self
).
__init__
(
path
)
normalize
=
transforms
.
Normalize
(
mean
=
[
123.675
,
116.28
,
103.53
],
std
=
[
58.395
,
57.120
,
57.375
])
self
.
transform
=
transforms
.
Compose
([
transforms
.
Resize
(
256
),
transforms
.
CenterCrop
(
image_size
),
transforms
.
Transpose
(),
normalize
])
def
__getitem__
(
self
,
idx
):
img_path
,
_
=
self
.
samples
[
idx
]
return
self
.
transform
(
Image
.
open
(
img_path
).
convert
(
'RGB'
))
def
__len__
(
self
):
return
len
(
self
.
samples
)
class
ACTDemo
(
unittest
.
TestCase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
ACTDemo
,
self
).
__init__
(
*
args
,
**
kwargs
)
os
.
system
(
'wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV1_infer.tar'
)
os
.
system
(
'tar -xf MobileNetV1_infer.tar'
)
os
.
system
(
'wget https://sys-p0.bj.bcebos.com/slim_ci/ILSVRC2012_data_demo.tar.gz'
)
os
.
system
(
'tar -xf ILSVRC2012_data_demo.tar.gz'
)
def
test_demo
(
self
):
train_dataset
=
ImageNetDataset
(
"./ILSVRC2012_data_demo/ILSVRC2012/train/"
)
image
=
paddle
.
static
.
data
(
name
=
'inputs'
,
shape
=
[
None
]
+
[
3
,
224
,
224
],
dtype
=
'float32'
)
train_loader
=
paddle
.
io
.
DataLoader
(
train_dataset
,
feed_list
=
[
image
],
batch_size
=
32
,
return_list
=
False
)
ac
=
AutoCompression
(
model_dir
=
"./MobileNetV1_infer"
,
model_filename
=
"inference.pdmodel"
,
params_filename
=
"inference.pdiparams"
,
save_dir
=
"MobileNetV1_quant"
,
config
=
{
'Quantization'
:
{},
"HyperParameterOptimization"
:
{
'ptq_algo'
:
[
'avg'
],
'max_quant_count'
:
3
}
},
train_dataloader
=
train_loader
,
eval_dataloader
=
train_loader
)
ac
.
compress
()
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录