Data augmentation with random image flip. Required keys: 'img', 'joints_3d', 'joints_3d_visible', 'center' and 'ann_info'. Modifies key: 'img', 'joints_3d', 'joints_3d_visible', 'center' and 'flipped'. Args: flip (bool): Option to perform random flip. flip_prob
| 211 | |
| 212 | |
| 213 | class TopDownRandomFlip: |
| 214 | """Data augmentation with random image flip. |
| 215 | |
| 216 | Required keys: 'img', 'joints_3d', 'joints_3d_visible', 'center' and |
| 217 | 'ann_info'. |
| 218 | Modifies key: 'img', 'joints_3d', 'joints_3d_visible', 'center' and |
| 219 | 'flipped'. |
| 220 | |
| 221 | Args: |
| 222 | flip (bool): Option to perform random flip. |
| 223 | flip_prob (float): Probability of flip. |
| 224 | """ |
| 225 | |
| 226 | def __init__(self, flip_prob=0.5): |
| 227 | self.flip_prob = flip_prob |
| 228 | |
| 229 | def __call__(self, results): |
| 230 | """Perform data augmentation with random image flip.""" |
| 231 | img = results['image'] |
| 232 | joints_3d = results['joints_3d'] |
| 233 | joints_3d_visible = results['joints_3d_visible'] |
| 234 | center = results['center'] |
| 235 | |
| 236 | # A flag indicating whether the image is flipped, |
| 237 | # which can be used by child class. |
| 238 | flipped = False |
| 239 | if np.random.rand() <= self.flip_prob: |
| 240 | flipped = True |
| 241 | img = img[:, ::-1, :] |
| 242 | joints_3d, joints_3d_visible = fliplr_joints( |
| 243 | joints_3d, joints_3d_visible, img.shape[1], |
| 244 | results['ann_info']['flip_pairs']) |
| 245 | center[0] = img.shape[1] - center[0] - 1 |
| 246 | |
| 247 | results['image'] = img |
| 248 | results['joints_3d'] = joints_3d |
| 249 | results['joints_3d_visible'] = joints_3d_visible |
| 250 | results['center'] = center |
| 251 | results['flipped'] = flipped |
| 252 | |
| 253 | return results |
| 254 | |
| 255 | |
| 256 | class TopDownHalfBodyTransform: |