Skip to content

Commit

Permalink
np.pad (open-mmlab#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-s13 authored and ly015 committed Jan 5, 2022
1 parent b5e1bb6 commit d44eb6f
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions mmpose/core/evaluation/top_down_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,34 +366,10 @@ def post_dark_udp(coords, batch_heatmaps, kernel=3):
cv2.GaussianBlur(heatmap, (kernel, kernel), 0, heatmap)
np.clip(batch_heatmaps, 0.001, 50, batch_heatmaps)
np.log(batch_heatmaps, batch_heatmaps)
batch_heatmaps = np.transpose(batch_heatmaps,
(2, 3, 0, 1)).reshape(H, W, -1)

# cv2.copyMakeBorder will report an error when input dimension exceeds 512
batch_heatmaps_channel = batch_heatmaps.shape[2]
if batch_heatmaps_channel > 512:
total_group_number = int(np.ceil(batch_heatmaps_channel / 512))
splited_batch_heatmaps = []
for group_idx in range(total_group_number):
splited_batch_heatmap = batch_heatmaps[
..., group_idx *
512:min(batch_heatmaps_channel, (group_idx + 1) * 512)]
batch_heatmap_pad = cv2.copyMakeBorder(
splited_batch_heatmap,
1,
1,
1,
1,
borderType=cv2.BORDER_REFLECT)
splited_batch_heatmaps.append(batch_heatmap_pad)
batch_heatmaps_pad = np.concatenate(splited_batch_heatmaps, axis=2)
else:
batch_heatmaps_pad = cv2.copyMakeBorder(
batch_heatmaps, 1, 1, 1, 1, borderType=cv2.BORDER_REFLECT)

batch_heatmaps_pad = np.transpose(
batch_heatmaps_pad.reshape(H + 2, W + 2, B, K),
(2, 3, 0, 1)).flatten()
batch_heatmaps_pad = np.pad(
batch_heatmaps, ((0, 0), (0, 0), (1, 1), (1, 1)),
mode='edge').flatten()

index = coords[..., 0] + 1 + (coords[..., 1] + 1) * (W + 2)
index += (W + 2) * (H + 2) * np.arange(0, B * K).reshape(-1, K)
Expand Down

0 comments on commit d44eb6f

Please sign in to comment.