From e43ccce92c1ac32750685c7da3a2a21c74a15123 Mon Sep 17 00:00:00 2001 From: ly015 Date: Tue, 7 Feb 2023 18:44:06 +0800 Subject: [PATCH] remove center rounding in bottom-up affine --- .../ae_hrnet-w32_8xb24-300e_coco-512x512.py | 5 +-- mmpose/codecs/associative_embedding.py | 44 +++++++++++-------- .../transforms/bottomup_transforms.py | 2 +- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/configs/body_2d_keypoint/associative_embedding/coco/ae_hrnet-w32_8xb24-300e_coco-512x512.py b/configs/body_2d_keypoint/associative_embedding/coco/ae_hrnet-w32_8xb24-300e_coco-512x512.py index 677b59b73a..988db0dc7b 100644 --- a/configs/body_2d_keypoint/associative_embedding/coco/ae_hrnet-w32_8xb24-300e_coco-512x512.py +++ b/configs/body_2d_keypoint/associative_embedding/coco/ae_hrnet-w32_8xb24-300e_coco-512x512.py @@ -147,7 +147,7 @@ type=dataset_type, data_root=data_root, data_mode=data_mode, - ann_file='annotations/person_keypoints_val2017_tiny_clean.json', + ann_file='annotations/person_keypoints_val2017.json', data_prefix=dict(img='val2017/'), test_mode=True, pipeline=val_pipeline, @@ -157,8 +157,7 @@ # evaluators val_evaluator = dict( type='CocoMetric', - ann_file=data_root + - 'annotations/person_keypoints_val2017_tiny_clean.json', + ann_file=data_root + 'annotations/person_keypoints_val2017.json', nms_mode='none', score_mode='keypoint', ) diff --git a/mmpose/codecs/associative_embedding.py b/mmpose/codecs/associative_embedding.py index 0904249134..9c9a1f0a6e 100644 --- a/mmpose/codecs/associative_embedding.py +++ b/mmpose/codecs/associative_embedding.py @@ -1,12 +1,12 @@ # Copyright (c) OpenMMLab. All rights reserved. from collections import namedtuple -from copy import deepcopy +# from copy import deepcopy from itertools import product from typing import Any, List, Optional, Tuple import numpy as np import torch -from mmengine import dump +# from mmengine import dump from munkres import Munkres from torch import Tensor @@ -77,7 +77,7 @@ def _init_group(): tag_list=[]) return _group - group_history = [] + # group_history = [] for idx, i in enumerate(keypoint_order): # Get all valid candidate of the i-th keypoints @@ -105,7 +105,7 @@ def _init_group(): group.tag_list.append(tag) groups.append(group) - costs_copy = None + # costs_copy = None matches = None else: # Match keypoints to existing groups @@ -126,7 +126,7 @@ def _init_group(): if num_kpts > num_groups: padding = np.full((num_kpts, num_kpts - num_groups), 1e10) costs = np.concatenate((costs, padding), axis=1) - costs_copy = costs.copy() + # costs_copy = costs.copy() # Match keypoints and groups by Munkres algorithm matches = munkres.compute(costs) @@ -148,18 +148,18 @@ def _init_group(): group.scores[i] = vals_i[kpt_idx] group.tag_list.append(tags_i[kpt_idx]) - out = { - 'idx': idx, - 'i': i, - 'costs': costs_copy, - 'matches': matches, - 'kpts': np.array([g.kpts for g in groups]), - 'scores': np.array([g.scores for g in groups]), - 'tag_list': [np.array(g.tag_list) for g in groups], - } - group_history.append(deepcopy(out)) + # out = { + # 'idx': idx, + # 'i': i, + # 'costs': costs_copy, + # 'matches': matches, + # 'kpts': np.array([g.kpts for g in groups]), + # 'scores': np.array([g.scores for g in groups]), + # 'tag_list': [np.array(g.tag_list) for g in groups], + # } + # group_history.append(deepcopy(out)) - dump(group_history, 'group_history.pkl') + # dump(group_history, 'group_history.pkl') groups = groups[:max_groups] if groups: @@ -369,10 +369,10 @@ def _get_batch_topk(self, batch_heatmaps: Tensor, batch_tags: Tensor, L = batch_tags.shape[1] // K # Heatmap NMS - dump(batch_heatmaps.cpu().numpy(), 'heatmaps.pkl') + # dump(batch_heatmaps.cpu().numpy(), 'heatmaps.pkl') batch_heatmaps = batch_heatmap_nms(batch_heatmaps, self.decode_nms_kernel) - dump(batch_heatmaps.cpu().numpy(), 'heatmaps_nms.pkl') + # dump(batch_heatmaps.cpu().numpy(), 'heatmaps_nms.pkl') # shape of topk_val, top_indices: (B, K, TopK) topk_vals, topk_indices = batch_heatmaps.flatten(-2, -1).topk( @@ -534,7 +534,13 @@ def batch_decode(self, batch_heatmaps: Tensor, batch_tags: Tensor blur_kernel_size=self.decode_gaussian_kernel) else: keypoints = refine_keypoints(keypoints, heatmaps) - # keypoints += 0.75 + # The following 0.5-pixel shift is adapted from mmpose 0.x + # where the heatmap center is calculated by a biased + # rounding ``mu=[int(x), int(y)]``. We keep this shift + # operation for now to to compatible with 0.x checkpoints + # In mmpose 1.x, AE heatmap center is calculated by the + # unbiased rounding ``mu=[int(x+0.5), int(y+0.5)], so the + # following shift will be removed in the future. keypoints += 0.5 batch_keypoints.append(keypoints) diff --git a/mmpose/datasets/transforms/bottomup_transforms.py b/mmpose/datasets/transforms/bottomup_transforms.py index d6b67bdf28..1355d3359a 100644 --- a/mmpose/datasets/transforms/bottomup_transforms.py +++ b/mmpose/datasets/transforms/bottomup_transforms.py @@ -484,7 +484,7 @@ def transform(self, results: Dict) -> Optional[dict]: output_size=actual_input_size) else: center = np.array([img_w / 2, img_h / 2], dtype=np.float32) - center = np.round(center) + # center = np.round(center) scale = np.array([ img_w * padded_input_size[0] / actual_input_size[0], img_h * padded_input_size[1] / actual_input_size[1]