Cutout blanks a rectangle of a photo. Mixup blends two whole photos and their labels. CutMix combines the two: it cuts a rectangle out of photo A and fills the hole with the same rectangle from photo B. The label is then mixed by area, so the model is told honestly how much of each photo it is looking at.
Both photos are grayscale grids of the same size, given as lists of rows. Labels are lists of class probabilities, either one-hot or already soft.
The rectangle is box = (top, left, bottom, right). It covers rows top up to but not including bottom, and columns left up to but not including right. Its position is chosen at random, so it may hang off the image: coordinates can be negative, or run past the last row or column. Only the part that lies inside the image is pasted.
If a fraction of the final image's pixels came from B, the new label is
where is label_a and is label_b, combined entry by entry.
Task: write cutmix(image_a, label_a, image_b, label_b, box) that returns a tuple (mixed_image, mixed_label):
mixed_image is a new grid equal to A everywhere except the pasted area, where it holds B's pixels. Leave the input lists unchanged.mixed_label is the mixed label, each entry rounded to 4 decimal places.