Adaptive selects a channel or two channels. Args: probability: The probability that the Random Erasing operation will be performed. sl: Minimum proportion of erased area against input image. sh: Maximum proportion of erased area against input image. r1: Minim
| 8 | |
| 9 | |
| 10 | class ChannelExchange(object): |
| 11 | """ Adaptive selects a channel or two channels. |
| 12 | Args: |
| 13 | probability: The probability that the Random Erasing operation will be performed. |
| 14 | sl: Minimum proportion of erased area against input image. |
| 15 | sh: Maximum proportion of erased area against input image. |
| 16 | r1: Minimum aspect ratio of erased area. |
| 17 | mean: Erasing value. |
| 18 | """ |
| 19 | |
| 20 | def __init__(self, gray=2): |
| 21 | self.gray = gray |
| 22 | |
| 23 | def __call__(self, img): |
| 24 | |
| 25 | idx = random.randint(0, self.gray) |
| 26 | |
| 27 | if idx == 0: |
| 28 | # random select R Channel |
| 29 | img[1, :, :] = img[0, :, :] |
| 30 | img[2, :, :] = img[0, :, :] |
| 31 | elif idx == 1: |
| 32 | # random select B Channel |
| 33 | img[0, :, :] = img[1, :, :] |
| 34 | img[2, :, :] = img[1, :, :] |
| 35 | elif idx == 2: |
| 36 | # random select G Channel |
| 37 | img[0, :, :] = img[2, :, :] |
| 38 | img[1, :, :] = img[2, :, :] |
| 39 | else: |
| 40 | tmp_img = 0.2989 * img[0, :, :] + 0.5870 * img[1, :, :] + 0.1140 * img[2, :, :] |
| 41 | img[0, :, :] = tmp_img |
| 42 | img[1, :, :] = tmp_img |
| 43 | img[2, :, :] = tmp_img |
| 44 | return img |
| 45 | |
| 46 | |
| 47 | class SYSUData(data.Dataset): |