Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
435144b5
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看板
提交
435144b5
编写于
6月 03, 2021
作者:
D
dongshuilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bugs imgnet and rec train
上级
452f5321
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
28 addition
and
10 deletion
+28
-10
ppcls/arch/head/arcmargin.py
ppcls/arch/head/arcmargin.py
+2
-0
ppcls/configs/Vehicle/ResNet50.yaml
ppcls/configs/Vehicle/ResNet50.yaml
+3
-0
ppcls/engine/trainer.py
ppcls/engine/trainer.py
+4
-1
ppcls/losses/__init__.py
ppcls/losses/__init__.py
+1
-1
ppcls/losses/celoss.py
ppcls/losses/celoss.py
+18
-8
未找到文件。
ppcls/arch/head/arcmargin.py
浏览文件 @
435144b5
...
...
@@ -50,6 +50,8 @@ class ArcMargin(nn.Layer):
weight
=
paddle
.
divide
(
weight
,
weight_norm
)
cos
=
paddle
.
matmul
(
input
,
weight
)
if
not
self
.
training
:
return
cos
sin
=
paddle
.
sqrt
(
1.0
-
paddle
.
square
(
cos
)
+
1e-6
)
cos_m
=
math
.
cos
(
self
.
margin
)
sin_m
=
math
.
sin
(
self
.
margin
)
...
...
ppcls/configs/Vehicle/ResNet50.yaml
浏览文件 @
435144b5
...
...
@@ -39,6 +39,9 @@ Loss:
-
TripletLossV2
:
weight
:
1.0
margin
:
0.5
Eval
:
-
CELoss
:
weight
:
1.0
Optimizer
:
name
:
Momentum
...
...
ppcls/engine/trainer.py
浏览文件 @
435144b5
...
...
@@ -244,6 +244,9 @@ class Trainer(object):
batch
[
0
]
=
paddle
.
to_tensor
(
batch
[
0
]).
astype
(
"float32"
)
batch
[
1
]
=
paddle
.
to_tensor
(
batch
[
1
]).
reshape
([
-
1
,
1
])
# image input
if
self
.
is_rec
:
out
=
self
.
model
(
batch
[
0
],
batch
[
1
])
else
:
out
=
self
.
model
(
batch
[
0
])
# calc build
if
loss_func
is
not
None
:
...
...
ppcls/losses/__init__.py
浏览文件 @
435144b5
...
...
@@ -43,6 +43,6 @@ class CombinedLoss(nn.Layer):
def
build_loss
(
config
):
module_class
=
CombinedLoss
(
co
nfig
)
module_class
=
CombinedLoss
(
co
py
.
deepcopy
(
config
)
)
logger
.
info
(
"build loss {} success."
.
format
(
module_class
))
return
module_class
ppcls/losses/celoss.py
浏览文件 @
435144b5
...
...
@@ -22,6 +22,7 @@ class Loss(object):
"""
Loss
"""
def
__init__
(
self
,
class_dim
=
1000
,
epsilon
=
None
):
assert
class_dim
>
1
,
"class_dim=%d is not larger than 1"
%
(
class_dim
)
self
.
_class_dim
=
class_dim
...
...
@@ -35,12 +36,16 @@ class Loss(object):
#do label_smoothing
def
_labelsmoothing
(
self
,
target
):
if
target
.
shape
[
-
1
]
!=
self
.
_class_dim
:
one_hot_target
=
F
.
one_hot
(
target
,
self
.
_class_dim
)
#do ont hot(23,34,46)-> 3 * _class_dim
one_hot_target
=
F
.
one_hot
(
target
,
self
.
_class_dim
)
#do ont hot(23,34,46)-> 3 * _class_dim
else
:
one_hot_target
=
target
#do label_smooth
soft_target
=
F
.
label_smooth
(
one_hot_target
,
epsilon
=
self
.
_epsilon
)
#(1 - epsilon) * input + eposilon / K.
soft_target
=
F
.
label_smooth
(
one_hot_target
,
epsilon
=
self
.
_epsilon
)
#(1 - epsilon) * input + eposilon / K.
soft_target
=
paddle
.
reshape
(
soft_target
,
shape
=
[
-
1
,
self
.
_class_dim
])
return
soft_target
...
...
@@ -64,7 +69,8 @@ class Loss(object):
(
target
+
eps
)
/
(
input
+
eps
))
*
self
.
_class_dim
return
cost
def
_jsdiv
(
self
,
input
,
target
):
#so the input and target is the fc output; no softmax
def
_jsdiv
(
self
,
input
,
target
):
#so the input and target is the fc output; no softmax
input
=
F
.
softmax
(
input
)
target
=
F
.
softmax
(
target
)
...
...
@@ -87,14 +93,19 @@ class CELoss(Loss):
super
(
CELoss
,
self
).
__init__
(
class_dim
,
epsilon
)
def
__call__
(
self
,
input
,
target
,
use_pure_fp16
=
False
):
if
type
(
input
)
is
dict
:
logits
=
input
[
"logits"
]
else
:
logits
=
input
cost
=
self
.
_crossentropy
(
logits
,
target
,
use_pure_fp16
)
return
{
"CELoss"
:
cost
}
class
JSDivLoss
(
Loss
):
"""
JSDiv loss
"""
def
__init__
(
self
,
class_dim
=
1000
,
epsilon
=
None
):
super
(
JSDivLoss
,
self
).
__init__
(
class_dim
,
epsilon
)
...
...
@@ -112,4 +123,3 @@ class KLDivLoss(paddle.nn.Layer):
p
=
paddle
.
nn
.
functional
.
softmax
(
p
)
q
=
paddle
.
nn
.
functional
.
softmax
(
q
)
return
-
(
p
*
paddle
.
log
(
q
+
1e-8
)).
sum
(
1
).
mean
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录