Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
7badd5bf
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
接近 2 年 前同步成功
通知
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看板
提交
7badd5bf
编写于
12月 26, 2022
作者:
weixin_46524038
提交者:
cuicheng01
12月 28, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add metrics and postprocess
上级
a9cb4179
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
166 addition
and
2 deletion
+166
-2
deploy/python/postprocess.py
deploy/python/postprocess.py
+52
-0
deploy/python/predict_cls.py
deploy/python/predict_cls.py
+2
-1
ppcls/data/postprocess/attr_rec.py
ppcls/data/postprocess/attr_rec.py
+62
-0
ppcls/metric/__init__.py
ppcls/metric/__init__.py
+1
-1
ppcls/metric/metrics.py
ppcls/metric/metrics.py
+49
-0
未找到文件。
deploy/python/postprocess.py
浏览文件 @
7badd5bf
...
@@ -346,6 +346,58 @@ class PersonAttribute(object):
...
@@ -346,6 +346,58 @@ class PersonAttribute(object):
return
batch_res
return
batch_res
class
FaceAttribute
(
object
):
def
__init__
(
self
,
threshold
=
0.65
,
convert_cn
=
False
):
self
.
threshold
=
threshold
self
.
convert_cn
=
convert_cn
def
__call__
(
self
,
x
,
file_names
=
None
):
attribute_list
=
[
[
"CheekWhiskers"
,
"刚长出的双颊胡须"
],
[
"ArchedEyebrows"
,
"柳叶眉"
],
[
"Attractive"
,
"吸引人的"
],
[
"BagsUnderEyes"
,
"眼袋"
],
[
"Bald"
,
"秃头"
],
[
"Bangs"
,
"刘海"
],
[
"BigLips"
,
"大嘴唇"
],
[
"BigNose"
,
"大鼻子"
],
[
"BlackHair"
,
"黑发"
],
[
"BlondHair"
,
"金发"
],
[
"Blurry"
,
"模糊的"
],
[
"BrownHair"
,
"棕发"
],
[
"BushyEyebrows"
,
"浓眉"
],
[
"Chubby"
,
"圆胖的"
],
[
"DoubleChin"
,
"双下巴"
],
[
"Eyeglasses"
,
"带眼镜"
],
[
"Goatee"
,
"山羊胡子"
],
[
"GrayHair"
,
"灰发或白发"
],
[
"HeavyMakeup"
,
"浓妆"
],
[
"HighCheekbones"
,
"高颧骨"
],
[
"Male"
,
"男性"
],
[
"MouthSlightlyOpen"
,
"微微张开嘴巴"
],
[
"Mustache"
,
"胡子"
],
[
"NarrowEyes"
,
"细长的眼睛"
],
[
"NoBeard"
,
"无胡子"
],
[
"OvalFace"
,
"椭圆形的脸"
],
[
"PaleSkin"
,
"苍白的皮肤"
],
[
"PointyNose"
,
"尖鼻子"
],
[
"RecedingHairline"
,
"发际线后移"
],
[
"RosyCheeks"
,
"红润的双颊"
],
[
"Sideburns"
,
"连鬓胡子"
],
[
"Smiling"
,
"微笑"
],
[
"StraightHair"
,
"直发"
],
[
"WavyHair"
,
"卷发"
],
[
"WearingEarrings"
,
"戴着耳环"
],
[
"WearingHat"
,
"戴着帽子"
],
[
"WearingLipstick"
,
"涂了唇膏"
],
[
"WearingNecklace"
,
"戴着项链"
],
[
"WearingNecktie"
,
"戴着领带"
],
[
"Young"
,
"年轻人"
]
]
gender_list
=
[[
"Male"
,
"男性"
],
[
"Female"
,
"女性"
]]
age_list
=
[[
"Young"
,
"年轻人"
],
[
"Old"
,
"老年人"
]]
batch_res
=
[]
if
self
.
convert_cn
:
index
=
1
else
:
index
=
0
for
idx
,
res
in
enumerate
(
x
):
res
=
res
.
tolist
()
label_res
=
[]
threshold_list
=
[
self
.
threshold
]
*
len
(
res
)
pred_res
=
(
np
.
array
(
res
)
>
np
.
array
(
threshold_list
)
).
astype
(
np
.
int8
).
tolist
()
for
i
,
value
in
enumerate
(
pred_res
):
if
i
==
20
:
label_res
.
append
(
gender_list
[
0
][
index
]
if
value
==
1
else
gender_list
[
1
][
index
])
elif
i
==
39
:
label_res
.
append
(
age_list
[
0
][
index
]
if
value
==
1
else
age_list
[
1
][
index
])
else
:
if
value
==
1
:
label_res
.
append
(
attribute_list
[
i
][
index
])
batch_res
.
append
({
"attributes"
:
label_res
,
"output"
:
pred_res
})
return
batch_res
class
VehicleAttribute
(
object
):
class
VehicleAttribute
(
object
):
def
__init__
(
self
,
color_threshold
=
0.5
,
type_threshold
=
0.5
):
def
__init__
(
self
,
color_threshold
=
0.5
,
type_threshold
=
0.5
):
self
.
color_threshold
=
color_threshold
self
.
color_threshold
=
color_threshold
...
...
deploy/python/predict_cls.py
浏览文件 @
7badd5bf
...
@@ -136,7 +136,8 @@ def main(config):
...
@@ -136,7 +136,8 @@ def main(config):
if
"PersonAttribute"
in
config
[
if
"PersonAttribute"
in
config
[
"PostProcess"
]
or
"VehicleAttribute"
in
config
[
"PostProcess"
]
or
"VehicleAttribute"
in
config
[
"PostProcess"
]
or
"TableAttribute"
in
config
[
"PostProcess"
]
or
"TableAttribute"
in
config
[
"PostProcess"
]:
"PostProcess"
]
or
"FaceAttribute"
in
config
[
"PostProcess"
]:
filename
=
batch_names
[
number
]
filename
=
batch_names
[
number
]
print
(
"{}:
\t
{}"
.
format
(
filename
,
result_dict
))
print
(
"{}:
\t
{}"
.
format
(
filename
,
result_dict
))
else
:
else
:
...
...
ppcls/data/postprocess/attr_rec.py
浏览文件 @
7badd5bf
...
@@ -84,6 +84,7 @@ class PersonAttribute(object):
...
@@ -84,6 +84,7 @@ class PersonAttribute(object):
if
isinstance
(
x
,
dict
):
if
isinstance
(
x
,
dict
):
x
=
x
[
'logits'
]
x
=
x
[
'logits'
]
assert
isinstance
(
x
,
paddle
.
Tensor
)
assert
isinstance
(
x
,
paddle
.
Tensor
)
if
file_names
is
not
None
:
if
file_names
is
not
None
:
assert
x
.
shape
[
0
]
==
len
(
file_names
)
assert
x
.
shape
[
0
]
==
len
(
file_names
)
x
=
F
.
sigmoid
(
x
).
numpy
()
x
=
F
.
sigmoid
(
x
).
numpy
()
...
@@ -98,6 +99,7 @@ class PersonAttribute(object):
...
@@ -98,6 +99,7 @@ class PersonAttribute(object):
'Skirt&Dress'
'Skirt&Dress'
]
]
batch_res
=
[]
batch_res
=
[]
for
idx
,
res
in
enumerate
(
x
):
for
idx
,
res
in
enumerate
(
x
):
res
=
res
.
tolist
()
res
=
res
.
tolist
()
label_res
=
[]
label_res
=
[]
...
@@ -171,6 +173,66 @@ class PersonAttribute(object):
...
@@ -171,6 +173,66 @@ class PersonAttribute(object):
return
batch_res
return
batch_res
class
FaceAttribute
(
object
):
def
__init__
(
self
,
threshold
=
0.65
,
convert_cn
=
False
):
self
.
threshold
=
threshold
self
.
convert_cn
=
convert_cn
def
__call__
(
self
,
x
,
file_names
=
None
):
if
isinstance
(
x
,
dict
):
x
=
x
[
'logits'
]
assert
isinstance
(
x
,
paddle
.
Tensor
)
if
file_names
is
not
None
:
assert
x
.
shape
[
0
]
==
len
(
file_names
)
x
=
F
.
sigmoid
(
x
).
numpy
()
attribute_list
=
[
[
"CheekWhiskers"
,
"刚长出的双颊胡须"
],
[
"ArchedEyebrows"
,
"柳叶眉"
],
[
"Attractive"
,
"吸引人的"
],
[
"BagsUnderEyes"
,
"眼袋"
],
[
"Bald"
,
"秃头"
],
[
"Bangs"
,
"刘海"
],
[
"BigLips"
,
"大嘴唇"
],
[
"BigNose"
,
"大鼻子"
],
[
"BlackHair"
,
"黑发"
],
[
"BlondHair"
,
"金发"
],
[
"Blurry"
,
"模糊的"
],
[
"BrownHair"
,
"棕发"
],
[
"BushyEyebrows"
,
"浓眉"
],
[
"Chubby"
,
"圆胖的"
],
[
"DoubleChin"
,
"双下巴"
],
[
"Eyeglasses"
,
"带眼镜"
],
[
"Goatee"
,
"山羊胡子"
],
[
"GrayHair"
,
"灰发或白发"
],
[
"HeavyMakeup"
,
"浓妆"
],
[
"HighCheekbones"
,
"高颧骨"
],
[
"Male"
,
"男性"
],
[
"MouthSlightlyOpen"
,
"微微张开嘴巴"
],
[
"Mustache"
,
"胡子"
],
[
"NarrowEyes"
,
"细长的眼睛"
],
[
"NoBeard"
,
"无胡子"
],
[
"OvalFace"
,
"椭圆形的脸"
],
[
"PaleSkin"
,
"苍白的皮肤"
],
[
"PointyNose"
,
"尖鼻子"
],
[
"RecedingHairline"
,
"发际线后移"
],
[
"RosyCheeks"
,
"红润的双颊"
],
[
"Sideburns"
,
"连鬓胡子"
],
[
"Smiling"
,
"微笑"
],
[
"StraightHair"
,
"直发"
],
[
"WavyHair"
,
"卷发"
],
[
"WearingEarrings"
,
"戴着耳环"
],
[
"WearingHat"
,
"戴着帽子"
],
[
"WearingLipstick"
,
"涂了唇膏"
],
[
"WearingNecklace"
,
"戴着项链"
],
[
"WearingNecktie"
,
"戴着领带"
],
[
"Young"
,
"年轻人"
]
]
gender_list
=
[[
"Male"
,
"男性"
],
[
"Female"
,
"女性"
]]
age_list
=
[[
"Young"
,
"年轻人"
],
[
"Old"
,
"老年人"
]]
batch_res
=
[]
if
self
.
convert_cn
:
index
=
1
else
:
index
=
0
for
idx
,
res
in
enumerate
(
x
):
res
=
res
.
tolist
()
label_res
=
[]
threshold_list
=
[
self
.
threshold
]
*
len
(
res
)
pred_res
=
(
np
.
array
(
res
)
>
np
.
array
(
threshold_list
)
).
astype
(
np
.
int8
).
tolist
()
for
i
,
value
in
enumerate
(
pred_res
):
if
i
==
20
:
label_res
.
append
(
gender_list
[
0
][
index
]
if
value
==
1
else
gender_list
[
1
][
index
])
elif
i
==
39
:
label_res
.
append
(
age_list
[
0
][
index
]
if
value
==
1
else
age_list
[
1
][
index
])
else
:
if
value
==
1
:
label_res
.
append
(
attribute_list
[
i
][
index
])
batch_res
.
append
({
"attributes"
:
label_res
,
"output"
:
pred_res
})
return
batch_res
class
TableAttribute
(
object
):
class
TableAttribute
(
object
):
def
__init__
(
def
__init__
(
self
,
self
,
...
...
ppcls/metric/__init__.py
浏览文件 @
7badd5bf
...
@@ -21,7 +21,7 @@ from .metrics import DistillationTopkAcc
...
@@ -21,7 +21,7 @@ from .metrics import DistillationTopkAcc
from
.metrics
import
GoogLeNetTopkAcc
from
.metrics
import
GoogLeNetTopkAcc
from
.metrics
import
HammingDistance
,
AccuracyScore
from
.metrics
import
HammingDistance
,
AccuracyScore
from
.metrics
import
ATTRMetric
from
.metrics
import
ATTRMetric
from
.metrics
import
TprAtFpr
from
.metrics
import
TprAtFpr
,
MultilabelMeanAccuracy
class
CombinedMetrics
(
AvgMetrics
):
class
CombinedMetrics
(
AvgMetrics
):
...
...
ppcls/metric/metrics.py
浏览文件 @
7badd5bf
...
@@ -218,6 +218,55 @@ class TprAtFpr(nn.Layer):
...
@@ -218,6 +218,55 @@ class TprAtFpr(nn.Layer):
return
result
return
result
class
MultilabelMeanAccuracy
(
nn
.
Layer
):
def
__init__
(
self
,
class_num
=
40
):
super
().
__init__
()
self
.
gt_all_score_list
=
[]
self
.
gt_label_score_list
=
[]
self
.
max_acc
=
0.
self
.
class_num
=
class_num
def
forward
(
self
,
x
,
label
):
if
isinstance
(
x
,
dict
):
x
=
x
[
"logits"
]
x
=
F
.
sigmoid
(
x
)
label
=
label
[:,
0
,
:]
for
i
in
range
(
len
(
x
)):
self
.
gt_all_score_list
.
append
(
x
[
i
].
numpy
())
self
.
gt_label_score_list
.
append
(
label
[
i
].
numpy
())
return
{}
def
reset
(
self
):
self
.
gt_all_score_list
=
[]
self
.
gt_label_score_list
=
[]
self
.
max_acc
=
0.
@
property
def
avg
(
self
):
return
self
.
max_acc
@
property
def
avg_info
(
self
):
max_acc
=
0.
result
=
""
gt_all_score_list
=
np
.
array
(
self
.
gt_all_score_list
)
gt_label_score_list
=
np
.
array
(
self
.
gt_label_score_list
)
for
i
in
range
(
10
):
threshold
=
0.4
+
i
*
0.05
pred_label
=
(
gt_all_score_list
>
threshold
).
astype
(
int
)
TP
=
np
.
sum
(
(
gt_label_score_list
==
1
)
*
(
pred_label
==
1
)).
astype
(
float
)
TN
=
np
.
sum
(
(
gt_label_score_list
==
0
)
*
(
pred_label
==
0
)).
astype
(
float
)
acc
=
(
TP
+
TN
)
/
len
(
gt_all_score_list
)
if
max_acc
<=
acc
:
max_acc
=
acc
result
=
"threshold: {}, mean_acc: {}"
.
format
(
threshold
,
max_acc
/
self
.
class_num
)
self
.
max_acc
=
max_acc
/
self
.
class_num
return
result
class
Recallk
(
nn
.
Layer
):
class
Recallk
(
nn
.
Layer
):
def
__init__
(
self
,
topk
=
(
1
,
5
),
descending
=
True
):
def
__init__
(
self
,
topk
=
(
1
,
5
),
descending
=
True
):
super
().
__init__
()
super
().
__init__
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录