Flip the flipped heatmaps back to the original form. Note: batch_size: N num_keypoints: K heatmap height: H heatmap width: W Args: output_flipped (np.ndarray[N, K, H, W]): The output heatmaps obtained from the flipped images. flip
(output_flipped, flip_pairs, target_type='GaussianHeatMap')
| 106 | |
| 107 | |
| 108 | def flip_back(output_flipped, flip_pairs, target_type='GaussianHeatMap'): |
| 109 | """Flip the flipped heatmaps back to the original form. |
| 110 | |
| 111 | Note: |
| 112 | batch_size: N |
| 113 | num_keypoints: K |
| 114 | heatmap height: H |
| 115 | heatmap width: W |
| 116 | |
| 117 | Args: |
| 118 | output_flipped (np.ndarray[N, K, H, W]): The output heatmaps obtained |
| 119 | from the flipped images. |
| 120 | flip_pairs (list[tuple()): Pairs of keypoints which are mirrored |
| 121 | (for example, left ear -- right ear). |
| 122 | target_type (str): GaussianHeatMap or CombinedTarget |
| 123 | |
| 124 | Returns: |
| 125 | np.ndarray: heatmaps that flipped back to the original image |
| 126 | """ |
| 127 | assert output_flipped.ndim == 4, \ |
| 128 | 'output_flipped should be [batch_size, num_keypoints, height, width]' |
| 129 | assert target_type in ('GaussianHeatMap', 'CombinedTarget') |
| 130 | shape_ori = output_flipped.shape |
| 131 | channels = 1 |
| 132 | if target_type == 'CombinedTarget': |
| 133 | channels = 3 |
| 134 | output_flipped[:, 1::3, ...] = -output_flipped[:, 1::3, ...] |
| 135 | output_flipped = output_flipped.reshape(shape_ori[0], -1, channels, |
| 136 | shape_ori[2], shape_ori[3]) |
| 137 | output_flipped_back = output_flipped.copy() |
| 138 | |
| 139 | # Swap left-right parts |
| 140 | for left, right in flip_pairs: |
| 141 | output_flipped_back[:, left, ...] = output_flipped[:, right, ...] |
| 142 | output_flipped_back[:, right, ...] = output_flipped[:, left, ...] |
| 143 | output_flipped_back = output_flipped_back.reshape(shape_ori) |
| 144 | # Flip horizontally |
| 145 | output_flipped_back = output_flipped_back[..., ::-1] |
| 146 | return output_flipped_back |
| 147 | |
| 148 | |
| 149 | def transform_preds(coords, center, scale, output_size, use_udp=False): |