Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
d8f049ae
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
116
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看板
提交
d8f049ae
编写于
12月 19, 2022
作者:
Z
zh-hike
提交者:
Walter
1月 04, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加代码规范,删除无用空格
上级
c5a29dba
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
8 addition
and
22 deletion
+8
-22
ppcls/arch/__init__.py
ppcls/arch/__init__.py
+0
-2
ppcls/arch/backbone/model_zoo/wideresnet.py
ppcls/arch/backbone/model_zoo/wideresnet.py
+0
-3
ppcls/configs/ssl/FixMatchCCSSL/FixMatchCCSSL_cifar100_10000_4gpu.yaml
.../ssl/FixMatchCCSSL/FixMatchCCSSL_cifar100_10000_4gpu.yaml
+1
-1
ppcls/engine/train/train_fixmatch_ccssl.py
ppcls/engine/train/train_fixmatch_ccssl.py
+1
-8
ppcls/loss/__init__.py
ppcls/loss/__init__.py
+1
-1
ppcls/loss/ccssl_loss.py
ppcls/loss/ccssl_loss.py
+3
-3
ppcls/loss/softsuploss.py
ppcls/loss/softsuploss.py
+2
-4
未找到文件。
ppcls/arch/__init__.py
浏览文件 @
d8f049ae
...
...
@@ -91,9 +91,7 @@ class RecModel(TheseusLayer):
out
=
dict
()
x
=
self
.
backbone
(
x
)
out
[
"backbone"
]
=
x
if
self
.
neck
is
not
None
:
feat
=
self
.
neck
(
x
)
out
[
"neck"
]
=
feat
...
...
ppcls/arch/backbone/model_zoo/wideresnet.py
浏览文件 @
d8f049ae
...
...
@@ -143,7 +143,6 @@ class Wide_ResNet(TheseusLayer):
# if use the output of projection head for classification
self
.
proj_after
=
proj_after
self
.
low_dim
=
low_dim
channels
=
[
16
,
16
*
widen_factor
,
32
*
widen_factor
,
64
*
widen_factor
]
...
...
@@ -184,7 +183,6 @@ class Wide_ResNet(TheseusLayer):
else
:
self
.
fc
=
nn
.
Linear
(
channels
[
3
],
num_classes
)
self
.
channels
=
channels
[
3
]
# projection head
if
self
.
proj
:
self
.
l2norm
=
Normalize
(
2
)
...
...
@@ -202,7 +200,6 @@ class Wide_ResNet(TheseusLayer):
feat
=
self
.
relu
(
self
.
bn1
(
feat
))
feat
=
F
.
adaptive_avg_pool2d
(
feat
,
1
)
feat
=
paddle
.
reshape
(
feat
,
[
-
1
,
self
.
channels
])
if
self
.
proj
:
pfeat
=
self
.
fc1
(
feat
)
pfeat
=
self
.
relu_mlp
(
pfeat
)
...
...
ppcls/configs/ssl/FixMatchCCSSL/FixMatchCCSSL_cifar100_10000_4gpu.yaml
浏览文件 @
d8f049ae
...
...
@@ -60,7 +60,7 @@ Loss:
UnLabelLoss
:
Train
:
-
CCSSLC
e
Loss
:
-
CCSSLC
E
Loss
:
weight
:
1.
-
SoftSupConLoss
:
weight
:
1.0
...
...
ppcls/engine/train/train_fixmatch_ccssl.py
浏览文件 @
d8f049ae
...
...
@@ -53,14 +53,12 @@ def train_epoch_fixmatch_ccssl(engine, epoch_id, print_batch_step):
inputs_x
,
targets_x
=
label_data_batch
inputs_w
,
inputs_s1
,
inputs_s2
=
unlabel_data_batch
[:
3
]
batch_size_label
=
inputs_x
.
shape
[
0
]
inputs
=
paddle
.
concat
([
inputs_x
,
inputs_w
,
inputs_s1
,
inputs_s2
],
axis
=
0
)
loss_dict
,
logits_label
=
get_loss
(
engine
,
inputs
,
batch_size_label
,
temperture
,
threshold
,
targets_x
,
)
loss
=
loss_dict
[
'loss'
]
loss
.
backward
()
...
...
@@ -76,13 +74,9 @@ def train_epoch_fixmatch_ccssl(engine, epoch_id, print_batch_step):
if
engine
.
ema
:
engine
.
model_ema
.
update
(
engine
.
model
)
update_metric
(
engine
,
logits_label
,
label_data_batch
,
batch_size
)
update_loss
(
engine
,
loss_dict
,
batch_size
)
engine
.
time_info
[
'batch_cost'
].
update
(
time
.
time
()
-
tic
)
if
iter_id
%
print_batch_step
==
0
:
log_info
(
engine
,
batch_size
,
epoch_id
,
iter_id
)
...
...
@@ -101,6 +95,7 @@ def get_loss(engine,
**
kwargs
):
out
=
engine
.
model
(
inputs
)
logits
,
feats
=
out
[
'logits'
],
out
[
'features'
]
feat_w
,
feat_s1
,
feat_s2
=
feats
[
batch_size_label
:].
chunk
(
3
)
feat_x
=
feats
[:
batch_size_label
]
...
...
@@ -118,9 +113,7 @@ def get_loss(engine,
'mask'
:
mask
,
'max_probs'
:
max_probs
,
}
unlabel_loss
=
engine
.
unlabel_train_loss_func
(
feats
,
batch
)
loss_dict
=
{}
for
k
,
v
in
loss_dict_label
.
items
():
if
k
!=
'loss'
:
...
...
ppcls/loss/__init__.py
浏览文件 @
d8f049ae
...
...
@@ -17,7 +17,7 @@ from .triplet import TripletLoss, TripletLossV2
from
.tripletangularmarginloss
import
TripletAngularMarginLoss
,
TripletAngularMarginLoss_XBM
from
.supconloss
import
SupConLoss
from
.softsuploss
import
SoftSupConLoss
from
.ccssl_loss
import
CCSSLC
e
Loss
from
.ccssl_loss
import
CCSSLC
E
Loss
from
.pairwisecosface
import
PairwiseCosface
from
.dmlloss
import
DMLLoss
from
.distanceloss
import
DistanceLoss
...
...
ppcls/loss/ccssl_loss.py
浏览文件 @
d8f049ae
...
...
@@ -4,9 +4,9 @@ import copy
import
paddle.nn
as
nn
class
CCSSLC
e
Loss
(
nn
.
Layer
):
class
CCSSLC
E
Loss
(
nn
.
Layer
):
def
__init__
(
self
,
**
kwargs
):
super
(
CCSSLC
e
Loss
,
self
).
__init__
()
super
(
CCSSLC
E
Loss
,
self
).
__init__
()
self
.
celoss
=
nn
.
CrossEntropyLoss
(
reduction
=
'none'
)
def
forward
(
self
,
inputs
,
batch
,
**
kwargs
):
...
...
@@ -16,4 +16,4 @@ class CCSSLCeLoss(nn.Layer):
loss_u
=
self
.
celoss
(
logits_s1
,
p_targets_u_w
)
*
mask
loss_u
=
loss_u
.
mean
()
return
{
'CCSSLC
e
Loss'
:
loss_u
}
return
{
'CCSSLC
E
Loss'
:
loss_u
}
ppcls/loss/softsuploss.py
浏览文件 @
d8f049ae
#
Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved
.
#
copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve
.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
...
...
@@ -47,9 +47,7 @@ class SoftSupConLoss(nn.Layer):
labels
=
labels
.
reshape
((
-
1
,
1
))
mask
=
paddle
.
equal
(
labels
,
labels
.
T
).
astype
(
'float32'
)
max_probs
=
max_probs
.
reshape
((
-
1
,
1
))
score_mask
=
paddle
.
matmul
(
max_probs
,
max_probs
.
T
)
mask
=
paddle
.
multiply
(
mask
,
score_mask
)
contrast_count
=
feat
.
shape
[
1
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录