[Fix] fix hmean iou

This commit is contained in:
liukuikun 2022-06-01 02:56:30 +00:00 committed by gaotongxiao
parent 71d1a445c9
commit 2a852f23b5
2 changed files with 8 additions and 7 deletions

View File

@ -171,15 +171,15 @@ class HmeanIOUMetric(BaseMetric):
dataset_pred_num[i] += np.sum(~pred_ignore_flags)
for i, pred_score_thr in enumerate(self.pred_score_thrs):
precision, recall, hmean = compute_hmean(
recall, precision, hmean = compute_hmean(
int(dataset_hit_num[i]), int(dataset_hit_num[i]),
int(dataset_gt_num), int(dataset_pred_num[i]))
eval_results = dict(
precision=precision, recall=recall, hmean=hmean)
logger.info(f'prediction score threshold: {pred_score_thr}, '
f'recall: {eval_results["recall"]:.3f}, '
f'precision: {eval_results["precision"]:.3f}, '
f'hmean: {eval_results["hmean"]:.3f}\n')
logger.info(f'prediction score threshold: {pred_score_thr:.2f}, '
f'recall: {eval_results["recall"]:.4f}, '
f'precision: {eval_results["precision"]:.4f}, '
f'hmean: {eval_results["hmean"]:.4f}\n')
if eval_results['hmean'] > best_eval_results['hmean']:
best_eval_results = eval_results
return best_eval_results

View File

@ -68,9 +68,10 @@ class TestHmeanIOU(unittest.TestCase):
pred_data_sample = TextDetDataSample()
pred_data_sample.pred_instances = InstanceData()
pred_data_sample.pred_instances.polygons = [
torch.FloatTensor([0, 0, 1, 0, 1, 1, 0, 1]),
torch.FloatTensor([0, 0, 1, 0, 1, 1, 0, 1])
]
pred_data_sample.pred_instances.scores = torch.FloatTensor([0.8])
pred_data_sample.pred_instances.scores = torch.FloatTensor([1, 0.95])
predictions.append(pred_data_sample.to_dict())
self.predictions = predictions
@ -81,7 +82,7 @@ class TestHmeanIOU(unittest.TestCase):
metric.process(self.gt, self.predictions)
eval_results = metric.evaluate(size=2)
precision = 3 / 4
precision = 3 / 5
recall = 3 / 4
hmean = 2 * precision * recall / (precision + recall)
target_result = {