(image, apply_prob=0.2)
| 163 | |
| 164 | |
| 165 | def randomGrayScale(image, apply_prob=0.2): |
| 166 | expand_batch_dim = len(image.size()) == 3 |
| 167 | if expand_batch_dim: |
| 168 | image = image.unsqueeze(0) |
| 169 | batch_size = image.size(0) |
| 170 | for index in range(batch_size): |
| 171 | if random.random() < apply_prob: |
| 172 | tmp = 0.299 * image[index, 0] + 0.587 * image[ |
| 173 | index, 1] + 0.114 * image[index, 2] |
| 174 | image[index, 0] = tmp |
| 175 | image[index, 1] = tmp |
| 176 | image[index, 2] = tmp |
| 177 | return image |
| 178 | |
| 179 | |
| 180 | def mixUp(image, alpha=0.2): |