(self, image, label=None,)
| 28 | self.mapped_left_right_pairs = mapped_left_right_pairs |
| 29 | |
| 30 | def __call__(self, image, label=None,): |
| 31 | if not self.p: |
| 32 | return image, label |
| 33 | |
| 34 | assert len(label), "hflip parsing needs label to map left and right pairs" |
| 35 | flip = random.randrange(2) * 2 -1 |
| 36 | |
| 37 | image = image[:, ::flip, :] |
| 38 | label = label[:, ::flip] |
| 39 | |
| 40 | if flip == -1: |
| 41 | left_idx = self.mapped_left_right_pairs[:, 0].reshape(-1) |
| 42 | right_idx = self.mapped_left_right_pairs[:, 1].reshape(-1) |
| 43 | for i in range(0, self.mapped_left_right_pairs.shape[0]): |
| 44 | right_pos = np.where(label == right_idx[i]) |
| 45 | left_pos = np.where(label == left_idx[i]) |
| 46 | label[right_pos[0], right_pos[1]] = left_idx[i] |
| 47 | label[left_pos[0], left_pos[1]] = right_idx[i] |
| 48 | |
| 49 | return image, label |
| 50 | |
| 51 | def __repr__(self): |
| 52 | return f'Hflip with {self.mapped_left_right_pairs}' |
nothing calls this directly
no outgoing calls
no test coverage detected