Skip to content

Commit

Permalink
rename GaussianHeatMap to GaussianHeatmap (open-mmlab#745)
Browse files Browse the repository at this point in the history
* rename GaussianHeatMap to GaussianHeatmap
* allow .lower() case match
* add unittest and .copy()
  • Loading branch information
jin-s13 authored Jul 2, 2021
1 parent 1af6d9e commit 46bb615
Show file tree
Hide file tree
Showing 24 changed files with 102 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=17,
dataset_joints=17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=17,
dataset_joints=17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=17,
dataset_joints=17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=17,
dataset_joints=17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
dict(type='TextLoggerHook'),
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=16,
dataset_joints=16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
dict(type='TextLoggerHook'),
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=16,
dataset_joints=16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=8,
dataset_joints=8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=4,
dataset_joints=4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=6,
dataset_joints=6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=8,
dataset_joints=8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=4,
dataset_joints=4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=6,
dataset_joints=6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=21,
dataset_joints=21,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=21,
dataset_joints=21,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# dict(type='TensorboardLoggerHook')
])

target_type = 'GaussianHeatMap'
target_type = 'GaussianHeatmap'
channel_cfg = dict(
num_output_channels=21,
dataset_joints=21,
Expand Down
19 changes: 11 additions & 8 deletions mmpose/core/evaluation/top_down_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def keypoints_from_heatmaps(heatmaps,
kernel=11,
valid_radius_factor=0.0546875,
use_udp=False,
target_type='GaussianHeatMap'):
target_type='GaussianHeatmap'):
"""Get final keypoint predictions from heatmaps and transform them back to
the image.
Expand Down Expand Up @@ -505,8 +505,8 @@ def keypoints_from_heatmaps(heatmaps,
valid_radius_factor (float): The radius factor of the positive area
in classification heatmap for UDP.
use_udp (bool): Use unbiased data processing.
target_type (str): 'GaussianHeatMap' or 'CombinedTarget'.
GaussianHeatMap: Classification target with gaussian distribution.
target_type (str): 'GaussianHeatmap' or 'CombinedTarget'.
GaussianHeatmap: Classification target with gaussian distribution.
CombinedTarget: The combination of classification target
(response map) and regression target (offset map).
Paper ref: Huang et al. The Devil is in the Details: Delving into
Expand All @@ -518,6 +518,9 @@ def keypoints_from_heatmaps(heatmaps,
- preds (np.ndarray[N, K, 2]): Predicted keypoint location in images.
- maxvals (np.ndarray[N, K, 1]): Scores (confidence) of the keypoints.
"""
# Avoid being affected
heatmaps = heatmaps.copy()

# detect conflicts
if unbiased:
assert post_process not in [False, None, 'megvii']
Expand Down Expand Up @@ -558,13 +561,10 @@ def keypoints_from_heatmaps(heatmaps,

N, K, H, W = heatmaps.shape
if use_udp:
assert target_type.lower() in [
'GaussianHeatMap'.lower(), 'CombinedTarget'.lower()
]
if target_type == 'GaussianHeatMap':
if target_type.lower() == 'GaussianHeatMap'.lower():
preds, maxvals = _get_max_preds(heatmaps)
preds = post_dark_udp(preds, heatmaps, kernel=kernel)
elif target_type == 'CombinedTarget':
elif target_type.lower() == 'CombinedTarget'.lower():
for person_heatmaps in heatmaps:
for i, heatmap in enumerate(person_heatmaps):
kt = 2 * kernel + 1 if i % 3 == 0 else kernel
Expand All @@ -579,6 +579,9 @@ def keypoints_from_heatmaps(heatmaps,
index += W * H * np.arange(0, N * K / 3)
index = index.astype(np.int).reshape(N, K // 3, 1)
preds += np.concatenate((offset_x[index], offset_y[index]), axis=2)
else:
raise ValueError('target_type should be either '
"'GaussianHeatmap' or 'CombinedTarget'")
else:
preds, maxvals = _get_max_preds(heatmaps)
if post_process == 'unbiased': # alleviate biased coordinate
Expand Down
8 changes: 3 additions & 5 deletions mmpose/core/post_processing/post_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def fliplr_regression(regression,
return regression_flipped


def flip_back(output_flipped, flip_pairs, target_type='GaussianHeatMap'):
def flip_back(output_flipped, flip_pairs, target_type='GaussianHeatmap'):
"""Flip the flipped heatmaps back to the original form.
Note:
Expand All @@ -119,18 +119,16 @@ def flip_back(output_flipped, flip_pairs, target_type='GaussianHeatMap'):
from the flipped images.
flip_pairs (list[tuple()): Pairs of keypoints which are mirrored
(for example, left ear -- right ear).
target_type (str): GaussianHeatMap or CombinedTarget
target_type (str): GaussianHeatmap or CombinedTarget
Returns:
np.ndarray: heatmaps that flipped back to the original image
"""
assert output_flipped.ndim == 4, \
'output_flipped should be [batch_size, num_keypoints, height, width]'
assert target_type.lower() in ('GaussianHeatMap'.lower(),
'CombinedTarget'.lower())
shape_ori = output_flipped.shape
channels = 1
if target_type == 'CombinedTarget':
if target_type.lower() == 'CombinedTarget'.lower():
channels = 3
output_flipped[:, 1::3, ...] = -output_flipped[:, 1::3, ...]
output_flipped = output_flipped.reshape(shape_ori[0], -1, channels,
Expand Down
35 changes: 20 additions & 15 deletions mmpose/datasets/pipelines/top_down_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ class TopDownGenerateTarget:
keypoint_pose_distance: Keypoint pose distance for UDP.
Paper ref: Huang et al. The Devil is in the Details: Delving into
Unbiased Data Processing for Human Pose Estimation (CVPR 2020).
target_type (str): supported targets: 'GaussianHeatMap',
'CombinedTarget'. Default:'GaussianHeatMap'
target_type (str): supported targets: 'GaussianHeatmap',
'CombinedTarget'. Default:'GaussianHeatmap'
CombinedTarget: The combination of classification target
(response map) and regression target (offset map).
Paper ref: Huang et al. The Devil is in the Details: Delving into
Expand All @@ -253,7 +253,7 @@ def __init__(self,
sigma=2,
kernel=(11, 11),
valid_radius_factor=0.0546875,
target_type='GaussianHeatMap',
target_type='GaussianHeatmap',
encoding='MSRA',
unbiased_encoding=False):
self.sigma = sigma
Expand Down Expand Up @@ -405,17 +405,17 @@ def _udp_generate_target(self, cfg, joints_3d, joints_3d_visible, factor,
heatmap height: H
heatmap width: W
num target channels: C
C = K if target_type=='GaussianHeatMap'
C = K if target_type=='GaussianHeatmap'
C = 3*K if target_type=='CombinedTarget'
Args:
cfg (dict): data config
joints_3d (np.ndarray[K, 3]): Annotated keypoints.
joints_3d_visible (np.ndarray[K, 3]): Visibility of keypoints.
factor (float): kernel factor for GaussianHeatMap target or
factor (float): kernel factor for GaussianHeatmap target or
valid radius factor for CombinedTarget.
target_type (str): 'GaussianHeatMap' or 'CombinedTarget'.
GaussianHeatMap: Heatmap target with gaussian distribution.
target_type (str): 'GaussianHeatmap' or 'CombinedTarget'.
GaussianHeatmap: Heatmap target with gaussian distribution.
CombinedTarget: The combination of classification target
(response map) and regression target (offset map).
Expand All @@ -434,11 +434,7 @@ def _udp_generate_target(self, cfg, joints_3d, joints_3d_visible, factor,
target_weight = np.ones((num_joints, 1), dtype=np.float32)
target_weight[:, 0] = joints_3d_visible[:, 0]

assert target_type.lower() in [
'GaussianHeatMap'.lower(), 'CombinedTarget'.lower()
]

if target_type == 'GaussianHeatMap':
if target_type.lower() == 'GaussianHeatmap'.lower():
target = np.zeros((num_joints, heatmap_size[1], heatmap_size[0]),
dtype=np.float32)

Expand Down Expand Up @@ -481,7 +477,8 @@ def _udp_generate_target(self, cfg, joints_3d, joints_3d_visible, factor,
if v > 0.5:
target[joint_id][img_y[0]:img_y[1], img_x[0]:img_x[1]] = \
g[g_y[0]:g_y[1], g_x[0]:g_x[1]]
elif target_type == 'CombinedTarget':

elif target_type.lower() == 'CombinedTarget'.lower():
target = np.zeros(
(num_joints, 3, heatmap_size[1] * heatmap_size[0]),
dtype=np.float32)
Expand Down Expand Up @@ -510,6 +507,9 @@ def _udp_generate_target(self, cfg, joints_3d, joints_3d_visible, factor,
target[joint_id, 2, keep_pos] = y_offset[keep_pos]
target = target.reshape(num_joints * 3, heatmap_size[1],
heatmap_size[0])
else:
raise ValueError('target_type should be either '
"'GaussianHeatmap' or 'CombinedTarget'")

if use_different_joint_weights:
target_weight = np.multiply(target_weight, joint_weights)
Expand Down Expand Up @@ -544,6 +544,7 @@ def __call__(self, results):
target, target_weight = self._msra_generate_target(
results['ann_info'], joints_3d, joints_3d_visible,
self.sigma)

elif self.encoding == 'Megvii':
if isinstance(self.kernel, list):
num_kernels = len(self.kernel)
Expand All @@ -563,13 +564,17 @@ def __call__(self, results):
target, target_weight = self._megvii_generate_target(
results['ann_info'], joints_3d, joints_3d_visible,
self.kernel)

elif self.encoding == 'UDP':
if self.target_type == 'CombinedTarget':
if self.target_type.lower() == 'CombinedTarget'.lower():
factors = self.valid_radius_factor
channel_factor = 3
elif self.target_type == 'GaussianHeatMap':
elif self.target_type.lower() == 'GaussianHeatmap'.lower():
factors = self.sigma
channel_factor = 1
else:
raise ValueError('target_type should be either '
"'GaussianHeatmap' or 'CombinedTarget'")
if isinstance(factors, list):
num_factors = len(factors)
cfg = results['ann_info']
Expand Down
2 changes: 1 addition & 1 deletion mmpose/models/heads/interhand_3d_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def __init__(self,
self.hand_type_loss = build_loss(loss_hand_type)
self.train_cfg = {} if train_cfg is None else train_cfg
self.test_cfg = {} if test_cfg is None else test_cfg
self.target_type = self.test_cfg.get('target_type', 'GaussianHeatMap')
self.target_type = self.test_cfg.get('target_type', 'GaussianHeatmap')

def init_weights(self):
self.left_hand_head.init_weights()
Expand Down
2 changes: 1 addition & 1 deletion mmpose/models/heads/topdown_heatmap_base_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def decode(self, img_metas, output, **kwargs):
valid_radius_factor=self.test_cfg.get('valid_radius_factor',
0.0546875),
use_udp=self.test_cfg.get('use_udp', False),
target_type=self.test_cfg.get('target_type', 'GaussianHeatMap'))
target_type=self.test_cfg.get('target_type', 'GaussianHeatmap'))

all_preds = np.zeros((batch_size, preds.shape[1], 3), dtype=np.float32)
all_boxes = np.zeros((batch_size, 6), dtype=np.float32)
Expand Down
8 changes: 4 additions & 4 deletions mmpose/models/heads/topdown_heatmap_multi_stage_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self,

self.train_cfg = {} if train_cfg is None else train_cfg
self.test_cfg = {} if test_cfg is None else test_cfg
self.target_type = self.test_cfg.get('target_type', 'GaussianHeatMap')
self.target_type = self.test_cfg.get('target_type', 'GaussianHeatmap')

if extra is not None and not isinstance(extra, dict):
raise TypeError('extra should be dict or None.')
Expand Down Expand Up @@ -164,7 +164,7 @@ def get_accuracy(self, output, target, target_weight):

accuracy = dict()

if self.target_type == 'GaussianHeatMap':
if self.target_type == 'GaussianHeatmap':
_, avg_acc, _ = pose_pck_accuracy(
output[-1].detach().cpu().numpy(),
target.detach().cpu().numpy(),
Expand Down Expand Up @@ -420,7 +420,7 @@ def __init__(self,

self.train_cfg = {} if train_cfg is None else train_cfg
self.test_cfg = {} if test_cfg is None else test_cfg
self.target_type = self.test_cfg.get('target_type', 'GaussianHeatMap')
self.target_type = self.test_cfg.get('target_type', 'GaussianHeatmap')

self.out_shape = out_shape
self.unit_channels = unit_channels
Expand Down Expand Up @@ -501,7 +501,7 @@ def get_accuracy(self, output, target, target_weight):

accuracy = dict()

if self.target_type == 'GaussianHeatMap':
if self.target_type == 'GaussianHeatmap':
assert isinstance(output, list)
assert target.dim() == 5 and target_weight.dim() == 4
_, avg_acc, _ = pose_pck_accuracy(
Expand Down
4 changes: 2 additions & 2 deletions mmpose/models/heads/topdown_heatmap_simple_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self,

self.train_cfg = {} if train_cfg is None else train_cfg
self.test_cfg = {} if test_cfg is None else test_cfg
self.target_type = self.test_cfg.get('target_type', 'GaussianHeatMap')
self.target_type = self.test_cfg.get('target_type', 'GaussianHeatmap')

self._init_inputs(in_channels, in_index, input_transform)
self.in_index = in_index
Expand Down Expand Up @@ -180,7 +180,7 @@ def get_accuracy(self, output, target, target_weight):

accuracy = dict()

if self.target_type == 'GaussianHeatMap':
if self.target_type == 'GaussianHeatmap':
_, avg_acc, _ = pose_pck_accuracy(
output.detach().cpu().numpy(),
target.detach().cpu().numpy(),
Expand Down
Loading

0 comments on commit 46bb615

Please sign in to comment.