Cutout Augmentation
Implement Cutout augmentation, a regularization technique that randomly masks out a square region of the input image by replacing it with zeros. This forces the model to learn more robust features by not relying on any single spatial region.
Algorithm:
1. Select a random top-left corner (x, y) within valid bounds.
2. Define a square mask of dimensions mask_size x mask_size.
3. Set all pixel values inside the mask region to 0.
Example:
Input: image = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]], size = 2
Output (one possible result): [[1, 2, 3],
[4, 0, 0],
[7, 0, 0]]
The output shows a 2x2 region starting at a randomly chosen position replaced with zeros. The remaining pixels are left unchanged. Because the position is random, different runs may mask different regions of the image.
Constraints:
Test Cases
[[1,2,3],[4,5,6],[7,8,9]][[1,2,3],[4,0,0],[7,0,0]][[1,2,3],[4,5,6],[7,8,9]][[1,2,3],[0,0,6],[0,0,9]]