Skip to content

Commit

Permalink
remove center rounding in bottom-up affine
Browse files Browse the repository at this point in the history
  • Loading branch information
ly015 authored and Ben-Louis committed Jun 9, 2023
1 parent 25aa6ec commit e43ccce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
)
Expand Down
44 changes: 25 additions & 19 deletions mmpose/codecs/associative_embedding.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mmpose/datasets/transforms/bottomup_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit e43ccce

Please sign in to comment.