diff --git a/deploy/python/postprocess.py b/deploy/python/postprocess.py index c66b1abeb..2e35e996b 100644 --- a/deploy/python/postprocess.py +++ b/deploy/python/postprocess.py @@ -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 = [] diff --git a/ppcls/data/postprocess/attr_rec.py b/ppcls/data/postprocess/attr_rec.py index db84769ba..ff6dcee16 100644 --- a/ppcls/data/postprocess/attr_rec.py +++ b/ppcls/data/postprocess/attr_rec.py @@ -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 = [] diff --git a/ppcls/metric/metrics.py b/ppcls/metric/metrics.py index f00ef0b58..b69bc65a3 100644 --- a/ppcls/metric/metrics.py +++ b/ppcls/metric/metrics.py @@ -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