Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
aed02a21
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看板
提交
aed02a21
编写于
11月 15, 2022
作者:
U
user3984
提交者:
littletomatodonkey
11月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update pefd
上级
7ee8471d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
8 deletion
+17
-8
ppcls/loss/pefdloss.py
ppcls/loss/pefdloss.py
+17
-8
未找到文件。
ppcls/loss/pefdloss.py
浏览文件 @
aed02a21
...
@@ -24,7 +24,7 @@ class Regressor(nn.Layer):
...
@@ -24,7 +24,7 @@ class Regressor(nn.Layer):
def
__init__
(
self
,
dim_in
=
1024
,
dim_out
=
1024
):
def
__init__
(
self
,
dim_in
=
1024
,
dim_out
=
1024
):
super
(
Regressor
,
self
).
__init__
()
super
(
Regressor
,
self
).
__init__
()
self
.
conv
=
nn
.
Conv2D
(
dim_in
,
dim_out
,
1
)
self
.
conv
=
nn
.
Linear
(
dim_in
,
dim_out
)
def
forward
(
self
,
x
):
def
forward
(
self
,
x
):
x
=
self
.
conv
(
x
)
x
=
self
.
conv
(
x
)
...
@@ -38,29 +38,38 @@ class PEFDLoss(nn.Layer):
...
@@ -38,29 +38,38 @@ class PEFDLoss(nn.Layer):
Code reference: https://github.com/chenyd7/PEFD
Code reference: https://github.com/chenyd7/PEFD
"""
"""
def
__init__
(
self
,
student_channel
,
teacher_channel
,
num_projectors
=
3
):
def
__init__
(
self
,
student_channel
,
teacher_channel
,
num_projectors
=
3
,
mode
=
"flatten"
):
super
().
__init__
()
super
().
__init__
()
if
num_projectors
<=
0
:
if
num_projectors
<=
0
:
raise
ValueError
(
"Number of projectors must be greater than 0."
)
raise
ValueError
(
"Number of projectors must be greater than 0."
)
if
mode
not
in
[
"flatten"
,
"gap"
]:
raise
ValueError
(
"Mode must be
\"
flatten
\"
or
\"
gap
\"
."
)
self
.
mode
=
mode
self
.
projectors
=
nn
.
LayerList
()
self
.
projectors
=
nn
.
LayerList
()
for
_
in
range
(
num_projectors
):
for
_
in
range
(
num_projectors
):
self
.
projectors
.
append
(
Regressor
(
student_channel
,
teacher_channel
))
self
.
projectors
.
append
(
Regressor
(
student_channel
,
teacher_channel
))
def
forward
(
self
,
student_feature
,
teacher_feature
):
def
forward
(
self
,
student_feature
,
teacher_feature
):
if
student_feature
.
shape
[
2
:]
!=
teacher_feature
.
shape
[
2
:]:
if
self
.
mode
==
"gap"
:
raise
ValueError
(
student_feature
=
F
.
adaptive_avg_pool2d
(
student_feature
,
(
1
,
1
))
"Student feature must have the same H and W as teacher feature."
teacher_feature
=
F
.
adaptive_avg_pool2d
(
teacher_feature
,
(
1
,
1
))
)
student_feature
=
student_feature
.
flatten
(
1
)
f_t
=
teacher_feature
.
flatten
(
1
)
q
=
len
(
self
.
projectors
)
q
=
len
(
self
.
projectors
)
f_s
=
0.0
f_s
=
0.0
for
i
in
range
(
q
):
for
i
in
range
(
q
):
f_s
+=
self
.
projectors
[
i
](
student_feature
)
f_s
+=
self
.
projectors
[
i
](
student_feature
)
f_s
=
(
f_s
/
q
).
flatten
(
1
)
f_s
=
f_s
/
q
f_t
=
teacher_feature
.
flatten
(
1
)
# inner product (normalize first and inner product)
# inner product (normalize first and inner product)
normft
=
f_t
.
pow
(
2
).
sum
(
1
,
keepdim
=
True
).
pow
(
1.
/
2
)
normft
=
f_t
.
pow
(
2
).
sum
(
1
,
keepdim
=
True
).
pow
(
1.
/
2
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录