Random flip the image either horizontally or vertically.
| 12 | |
| 13 | |
| 14 | class Flip(ImageAugmentor): |
| 15 | """ |
| 16 | Random flip the image either horizontally or vertically. |
| 17 | """ |
| 18 | def __init__(self, horiz=False, vert=False, prob=0.5): |
| 19 | """ |
| 20 | Args: |
| 21 | horiz (bool): use horizontal flip. |
| 22 | vert (bool): use vertical flip. |
| 23 | prob (float): probability of flip. |
| 24 | """ |
| 25 | super(Flip, self).__init__() |
| 26 | if horiz and vert: |
| 27 | raise ValueError("Cannot do both horiz and vert. Please use two Flip instead.") |
| 28 | if not horiz and not vert: |
| 29 | raise ValueError("At least one of horiz or vert has to be True!") |
| 30 | self._init(locals()) |
| 31 | |
| 32 | def get_transform(self, img): |
| 33 | h, w = img.shape[:2] |
| 34 | do = self._rand_range() < self.prob |
| 35 | if not do: |
| 36 | return NoOpTransform() |
| 37 | else: |
| 38 | return FlipTransform(h, w, self.horiz) |
| 39 | |
| 40 | |
| 41 | class Resize(ImageAugmentor): |
no outgoing calls
searching dependent graphs…