horizontal flip OR rotate (0, 90, 180, 270 degrees) with flows
(img_list, flow_list, hflip=True, rot=True)
| 182 | |
| 183 | |
| 184 | def augment_flow(img_list, flow_list, hflip=True, rot=True): |
| 185 | """horizontal flip OR rotate (0, 90, 180, 270 degrees) with flows""" |
| 186 | hflip = hflip and random.random() < 0.5 |
| 187 | vflip = rot and random.random() < 0.5 |
| 188 | rot90 = rot and random.random() < 0.5 |
| 189 | |
| 190 | def _augment(img): |
| 191 | if hflip: |
| 192 | img = img[:, ::-1, :] |
| 193 | if vflip: |
| 194 | img = img[::-1, :, :] |
| 195 | if rot90: |
| 196 | img = img.transpose(1, 0, 2) |
| 197 | return img |
| 198 | |
| 199 | def _augment_flow(flow): |
| 200 | if hflip: |
| 201 | flow = flow[:, ::-1, :] |
| 202 | flow[:, :, 0] *= -1 |
| 203 | if vflip: |
| 204 | flow = flow[::-1, :, :] |
| 205 | flow[:, :, 1] *= -1 |
| 206 | if rot90: |
| 207 | flow = flow.transpose(1, 0, 2) |
| 208 | flow = flow[:, :, [1, 0]] |
| 209 | return flow |
| 210 | |
| 211 | rlt_img_list = [_augment(img) for img in img_list] |
| 212 | rlt_flow_list = [_augment_flow(flow) for flow in flow_list] |
| 213 | |
| 214 | return rlt_img_list, rlt_flow_list |
| 215 | |
| 216 | |
| 217 | def channel_convert(in_c, tar_type, img_list): |
nothing calls this directly
no test coverage detected