Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
35437e22
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
35437e22
编写于
6月 13, 2021
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix distillation model infer and export model
上级
f3f0b399
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
6 deletion
+33
-6
ppcls/arch/__init__.py
ppcls/arch/__init__.py
+3
-2
ppcls/configs/ImageNet/Distillation/mv3_large_x1_0_distill_mv3_small_x1_0.yaml
...t/Distillation/mv3_large_x1_0_distill_mv3_small_x1_0.yaml
+4
-1
ppcls/data/postprocess/__init__.py
ppcls/data/postprocess/__init__.py
+14
-0
tools/export_model.py
tools/export_model.py
+12
-3
未找到文件。
ppcls/arch/__init__.py
浏览文件 @
35437e22
...
...
@@ -69,7 +69,8 @@ class DistillationModel(nn.Layer):
def
__init__
(
self
,
models
=
None
,
pretrained_list
=
None
,
freeze_params_list
=
None
):
freeze_params_list
=
None
,
**
kargs
):
super
().
__init__
()
assert
isinstance
(
models
,
list
)
self
.
model_list
=
[]
...
...
@@ -105,5 +106,5 @@ class DistillationModel(nn.Layer):
if
label
is
None
:
result_dict
[
model_name
]
=
self
.
model_list
[
idx
](
x
)
else
:
result_dict
[
model_name
]
=
self
.
model_list
[
idx
](
x
)
result_dict
[
model_name
]
=
self
.
model_list
[
idx
](
x
,
label
)
return
result_dict
ppcls/configs/ImageNet/Distillation/mv3_large_x1_0_distill_mv3_small_x1_0.yaml
浏览文件 @
35437e22
...
...
@@ -33,6 +33,8 @@ Arch:
name
:
MobileNetV3_small_x1_0
pretrained
:
False
infer_model_name
:
"
Student"
# loss function config for traing/eval process
Loss
:
...
...
@@ -136,7 +138,8 @@ Infer:
order
:
'
'
-
ToCHWImage
:
PostProcess
:
name
:
Topk
name
:
DistillationPostProcess
func
:
Topk
topk
:
5
class_id_map_file
:
"
ppcls/utils/imagenet1k_label_list.txt"
...
...
ppcls/data/postprocess/__init__.py
浏览文件 @
35437e22
...
...
@@ -25,3 +25,17 @@ def build_postprocess(config):
mod
=
importlib
.
import_module
(
__name__
)
postprocess_func
=
getattr
(
mod
,
model_name
)(
**
config
)
return
postprocess_func
class
DistillationPostProcess
(
object
):
def
__init__
(
self
,
model_name
=
"Student"
,
key
=
None
,
func
=
"Topk"
,
**
kargs
):
super
().
__init__
()
self
.
func
=
eval
(
func
)(
**
kargs
)
self
.
model_name
=
model_name
self
.
key
=
key
def
__call__
(
self
,
x
,
file_names
=
None
):
x
=
x
[
self
.
model_name
]
if
self
.
key
is
not
None
:
x
=
x
[
self
.
key
]
return
self
.
func
(
x
,
file_names
=
file_names
)
tools/export_model.py
浏览文件 @
35437e22
...
...
@@ -24,20 +24,27 @@ import paddle
import
paddle.nn
as
nn
from
ppcls.utils
import
config
from
ppcls.arch
import
build_model
,
RecModel
from
ppcls.arch
import
build_model
,
RecModel
,
DistillationModel
from
ppcls.utils.save_load
import
load_dygraph_pretrain
from
ppcls.arch.gears.identity_head
import
IdentityHead
class
ExportModel
(
nn
.
Layer
):
"""
Clas
Model: add softmax onto the model
Export
Model: add softmax onto the model
"""
def
__init__
(
self
,
config
):
super
().
__init__
()
self
.
base_model
=
build_model
(
config
)
self
.
infer_output_key
=
config
.
get
(
"infer_output_key"
)
# we should choose a final model to export
if
isinstance
(
self
.
base_model
,
DistillationModel
):
self
.
infer_model_name
=
config
[
"infer_model_name"
]
else
:
self
.
infer_model_name
=
None
self
.
infer_output_key
=
config
.
get
(
"infer_output_key"
,
None
)
if
self
.
infer_output_key
==
"features"
and
isinstance
(
self
.
base_model
,
RecModel
):
self
.
base_model
.
head
=
IdentityHead
()
...
...
@@ -54,6 +61,8 @@ class ExportModel(nn.Layer):
def
forward
(
self
,
x
):
x
=
self
.
base_model
(
x
)
if
self
.
infer_model_name
is
not
None
:
x
=
x
[
self
.
infer_model_name
]
if
self
.
infer_output_key
is
not
None
:
x
=
x
[
self
.
infer_output_key
]
if
self
.
softmax
is
not
None
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录