Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
cef3cb25
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看板
提交
cef3cb25
编写于
2月 28, 2022
作者:
L
lubin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update optimizer and some comment
上级
fa45f73b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
15 addition
and
24 deletion
+15
-24
ppcls/data/dataloader/customized_cifar10.py
ppcls/data/dataloader/customized_cifar10.py
+2
-2
ppcls/loss/deephashloss.py
ppcls/loss/deephashloss.py
+8
-18
ppcls/optimizer/optimizer.py
ppcls/optimizer/optimizer.py
+5
-4
未找到文件。
ppcls/data/dataloader/customized_cifar10.py
浏览文件 @
cef3cb25
...
...
@@ -28,8 +28,8 @@ class CustomizedCifar10(Cifar10):
mode
=
'train'
,
download
=
True
,
backend
=
None
):
assert
mode
.
lower
()
in
[
'train'
,
'test'
,
'train'
,
'test'
],
\
"mode should be 'train
10', 'test10', 'train100' or 'test100
', but got {}"
.
format
(
mode
)
assert
mode
.
lower
()
in
[
'train'
,
'test'
],
\
"mode should be 'train
', 'test
', but got {}"
.
format
(
mode
)
self
.
mode
=
mode
.
lower
()
if
backend
is
None
:
...
...
ppcls/loss/deephashloss.py
浏览文件 @
cef3cb25
...
...
@@ -20,9 +20,6 @@ class DSHSDLoss(nn.Layer):
"""
# DSHSD(IEEE ACCESS 2019)
# paper [Deep Supervised Hashing Based on Stable Distribution](https://ieeexplore.ieee.org/document/8648432/)
# [DSHSD] epoch:70, bit:48, dataset:cifar10-1, MAP:0.809, Best MAP: 0.809
# [DSHSD] epoch:250, bit:48, dataset:nuswide_21, MAP:0.809, Best MAP: 0.815
# [DSHSD] epoch:135, bit:48, dataset:imagenet, MAP:0.647, Best MAP: 0.647
"""
def
__init__
(
self
,
alpha
,
multi_label
=
False
):
...
...
@@ -64,8 +61,6 @@ class DSHSDLoss(nn.Layer):
class
LCDSHLoss
(
nn
.
Layer
):
"""
# paper [Locality-Constrained Deep Supervised Hashing for Image Retrieval](https://www.ijcai.org/Proceedings/2017/0499.pdf)
# [LCDSH] epoch:145, bit:48, dataset:cifar10-1, MAP:0.798, Best MAP: 0.798
# [LCDSH] epoch:183, bit:48, dataset:nuswide_21, MAP:0.833, Best MAP: 0.834
"""
def
__init__
(
self
,
n_class
,
_lambda
):
...
...
@@ -98,11 +93,6 @@ class DCHLoss(paddle.nn.Layer):
"""
# paper [Deep Cauchy Hashing for Hamming Space Retrieval]
URL:(http://ise.thss.tsinghua.edu.cn/~mlong/doc/deep-cauchy-hashing-cvpr18.pdf)
# [DCH] epoch:150, bit:48, dataset:cifar10-1, MAP:0.768, Best MAP: 0.810
# [DCH] epoch:150, bit:48, dataset:coco, MAP:0.665, Best MAP: 0.670
# [DCH] epoch:150, bit:48, dataset:imagenet, MAP:0.586, Best MAP: 0.586
# [DCH] epoch:150, bit:48, dataset:nuswide_21, MAP:0.778, Best MAP: 0.794
"""
def
__init__
(
self
,
gamma
,
_lambda
,
n_class
):
...
...
@@ -111,14 +101,14 @@ class DCHLoss(paddle.nn.Layer):
self
.
_lambda
=
_lambda
self
.
n_class
=
n_class
def
d
(
self
,
hi
,
h
j
):
assert
hi
.
shape
[
1
]
==
h
j
.
shape
[
1
],
"feature len of
hi and h
j is different, please check whether the featurs are right"
K
=
h
i
.
shape
[
1
]
inner_product
=
paddle
.
matmul
(
hi
,
h
j
,
transpose_y
=
True
)
def
d
istance
(
self
,
feature_i
,
feature_
j
):
assert
feature_i
.
shape
[
1
]
==
feature_
j
.
shape
[
1
],
"feature len of
feature_i and feature_
j is different, please check whether the featurs are right"
K
=
feature_
i
.
shape
[
1
]
inner_product
=
paddle
.
matmul
(
feature_i
,
feature_
j
,
transpose_y
=
True
)
len_i
=
h
i
.
pow
(
2
).
sum
(
axis
=
1
,
keepdim
=
True
).
pow
(
0.5
)
len_j
=
h
j
.
pow
(
2
).
sum
(
axis
=
1
,
keepdim
=
True
).
pow
(
0.5
)
len_i
=
feature_
i
.
pow
(
2
).
sum
(
axis
=
1
,
keepdim
=
True
).
pow
(
0.5
)
len_j
=
feature_
j
.
pow
(
2
).
sum
(
axis
=
1
,
keepdim
=
True
).
pow
(
0.5
)
norm
=
paddle
.
matmul
(
len_i
,
len_j
,
transpose_y
=
True
)
cos
=
inner_product
/
norm
.
clip
(
min
=
0.0001
)
return
(
1
-
cos
.
clip
(
max
=
0.99
))
*
K
/
2
...
...
@@ -136,7 +126,7 @@ class DCHLoss(paddle.nn.Layer):
else
:
w
=
1
d_hi_hj
=
self
.
d
(
u
,
u
)
d_hi_hj
=
self
.
d
istance
(
u
,
u
)
cauchy_loss
=
w
*
(
s
*
paddle
.
log
(
d_hi_hj
/
self
.
gamma
)
+
paddle
.
log
(
1
+
self
.
gamma
/
d_hi_hj
))
...
...
ppcls/optimizer/optimizer.py
浏览文件 @
cef3cb25
...
...
@@ -47,15 +47,15 @@ class SGD(object):
def
__init__
(
self
,
learning_rate
=
0.001
,
parameters
=
None
,
weight_decay
=
None
,
grad_clip
=
None
,
name
=
None
):
name
=
None
,
multi_precision
=
False
):
self
.
learning_rate
=
learning_rate
self
.
parameters
=
parameters
self
.
weight_decay
=
weight_decay
self
.
grad_clip
=
grad_clip
self
.
name
=
name
self
.
multi_precision
=
multi_precision
def
__call__
(
self
,
model_list
):
# model_list is None in static graph
...
...
@@ -65,7 +65,8 @@ class SGD(object):
parameters
=
parameters
,
weight_decay
=
self
.
weight_decay
,
grad_clip
=
self
.
grad_clip
,
name
=
self
.
name
)
name
=
self
.
name
,
multi_precision
=
self
.
multi_precision
)
return
opt
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录