Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
9ca38e72
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看板
未验证
提交
9ca38e72
编写于
12月 17, 2020
作者:
B
Bai Yifan
提交者:
GitHub
12月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix dygraph quant demo dataset issue (#555)
* fix dygraph quant demo dataset issue * fix dygraph quant demo dataset issue
上级
dacc4218
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
9 deletion
+18
-9
demo/dygraph/quant/README.md
demo/dygraph/quant/README.md
+3
-3
demo/dygraph/quant/train.py
demo/dygraph/quant/train.py
+15
-6
未找到文件。
demo/dygraph/quant/README.md
浏览文件 @
9ca38e72
...
...
@@ -22,7 +22,7 @@
### 配置量化参数
```
```
python
quant_config
=
{
'weight_preprocess_type'
:
None
,
'activation_preprocess_type'
:
None
,
...
...
@@ -70,9 +70,9 @@ quanter.save_quantized_model(net, 'save_dir', input_spec=[paddle.static.InputSpe
```
bash
# 单卡训练
python train.py
--model
=
'mobilenet_v1'
python train.py
--model
=
mobilenet_v1
# 多卡训练,以0到3号卡为例
python
-m
paddle.distributed.launch
--gpus
=
"0,1,2,3"
train.py
--model
=
'mobilenet_v1'
python
-m
paddle.distributed.launch
--gpus
=
"0,1,2,3"
train.py
--model
=
mobilenet_v1
```
-
MobileNetV3
...
...
demo/dygraph/quant/train.py
浏览文件 @
9ca38e72
...
...
@@ -28,6 +28,7 @@ import numpy as np
from
paddle.distributed
import
ParallelEnv
from
paddle.static
import
load_program_state
from
paddle.vision.models
import
mobilenet_v1
import
paddle.vision.transforms
as
T
from
paddleslim.common
import
get_logger
from
paddleslim.dygraph.quant
import
QAT
...
...
@@ -55,7 +56,7 @@ add_arg('use_pact', bool, False,
add_arg
(
'momentum_rate'
,
float
,
0.9
,
"The value of momentum_rate."
)
add_arg
(
'num_epochs'
,
int
,
1
,
"The number of total epochs."
)
add_arg
(
'total_images'
,
int
,
1281167
,
"The number of total training images."
)
add_arg
(
'data'
,
str
,
"imagenet"
,
"Which data to use. '
mnist
' or 'imagenet'"
)
add_arg
(
'data'
,
str
,
"imagenet"
,
"Which data to use. '
cifar10
' or 'imagenet'"
)
add_arg
(
'log_period'
,
int
,
10
,
"Log period in batches."
)
add_arg
(
'model_save_dir'
,
str
,
"./output_models"
,
"model save directory."
)
parser
.
add_argument
(
'--step_epochs'
,
nargs
=
'+'
,
type
=
int
,
default
=
[
10
,
20
,
30
],
help
=
"piecewise decay step"
)
...
...
@@ -87,12 +88,16 @@ def load_dygraph_pretrain(model, path=None, load_static_weights=False):
def
compress
(
args
):
if
args
.
data
==
"mnist"
:
train_dataset
=
paddle
.
vision
.
datasets
.
MNIST
(
mode
=
'train'
)
val_dataset
=
paddle
.
vision
.
datasets
.
MNIST
(
mode
=
'test'
)
if
args
.
data
==
"cifar10"
:
transform
=
T
.
Compose
([
T
.
Transpose
(),
T
.
Normalize
([
127.5
],
[
127.5
])])
train_dataset
=
paddle
.
vision
.
datasets
.
Cifar10
(
mode
=
"train"
,
backend
=
"cv2"
,
transform
=
transform
)
val_dataset
=
paddle
.
vision
.
datasets
.
Cifar10
(
mode
=
"test"
,
backend
=
"cv2"
,
transform
=
transform
)
class_dim
=
10
image_shape
=
"1,28,28"
args
.
total_images
=
60000
image_shape
=
[
3
,
32
,
32
]
pretrain
=
False
args
.
total_images
=
50000
elif
args
.
data
==
"imagenet"
:
import
imagenet_reader
as
reader
train_dataset
=
reader
.
ImageNetDataset
(
mode
=
'train'
)
...
...
@@ -199,6 +204,8 @@ def compress(args):
eval_reader_cost
+=
time
.
time
()
-
reader_start
image
=
data
[
0
]
label
=
data
[
1
]
if
args
.
data
==
"cifar10"
:
label
=
paddle
.
reshape
(
label
,
[
-
1
,
1
])
eval_start
=
time
.
time
()
...
...
@@ -262,6 +269,8 @@ def compress(args):
image
=
data
[
0
]
label
=
data
[
1
]
if
args
.
data
==
"cifar10"
:
label
=
paddle
.
reshape
(
label
,
[
-
1
,
1
])
train_start
=
time
.
time
()
out
=
net
(
image
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录