提交 16968200 编写于 作者: weixin_46524038's avatar weixin_46524038 提交者: cuicheng01

Some modifications

上级 7badd5bf
......@@ -374,10 +374,7 @@ class FaceAttribute(object):
gender_list = [["Male", "男性"], ["Female", "女性"]]
age_list = [["Young", "年轻人"], ["Old", "老年人"]]
batch_res = []
if self.convert_cn:
index = 1
else:
index = 0
index = 1 if self.convert_cn else 0
for idx, res in enumerate(x):
res = res.tolist()
label_res = []
......
......@@ -84,7 +84,6 @@ class PersonAttribute(object):
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()
......@@ -99,7 +98,6 @@ class PersonAttribute(object):
'Skirt&Dress'
]
batch_res = []
for idx, res in enumerate(x):
res = res.tolist()
label_res = []
......@@ -209,10 +207,7 @@ class FaceAttribute(object):
gender_list = [["Male", "男性"], ["Female", "女性"]]
age_list = [["Young", "年轻人"], ["Old", "老年人"]]
batch_res = []
if self.convert_cn:
index = 1
else:
index = 0
index = 1 if self.convert_cn else 0
for idx, res in enumerate(x):
res = res.tolist()
label_res = []
......
......@@ -219,12 +219,17 @@ class TprAtFpr(nn.Layer):
class MultilabelMeanAccuracy(nn.Layer):
def __init__(self, class_num=40):
def __init__(self,
start_threshold=0.4,
num_iterations=10,
end_threshold=0.9):
super().__init__()
self.start_threshold = start_threshold
self.num_iterations = num_iterations
self.end_threshold = end_threshold
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):
......@@ -251,8 +256,10 @@ class MultilabelMeanAccuracy(nn.Layer):
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
for i in range(self.num_iterations):
threshold = self.start_threshold + i * (self.end_threshold -
self.start_threshold
) / self.num_iterations
pred_label = (gt_all_score_list > threshold).astype(int)
TP = np.sum(
(gt_label_score_list == 1) * (pred_label == 1)).astype(float)
......@@ -262,8 +269,8 @@ class MultilabelMeanAccuracy(nn.Layer):
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
threshold, max_acc / len(gt_label_score_list[0]))
self.max_acc = max_acc / len(gt_label_score_list[0])
return result
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册