Mixup blends whole images, producing ghostly overlays that never occur in real photos. CutMix instead cuts a rectangular patch out of one image and pastes it onto another, so every pixel still comes from a real image and the network must recognize objects from partial views. The label is mixed in proportion to the actual area each image contributes. The patch size comes from the mixing weight lam: the patch covers a fraction 1 - lam of the image area, with width and height sqrt(1 - lam) times the image's. The patch centre is random, and clipping at the image border can shrink the patch, so the label weight is recomputed from the clipped area.
Implement cutmix_box, cutmix and adjusted_lambda.
cutmix_box(H, W, lam, cy, cx) returns (y1, y2, x1, x2) where cut_h = int(H * sqrt(1 - lam)), cut_w = int(W * sqrt(1 - lam)), y1 = clip(cy - cut_h // 2, 0, H), y2 = clip(cy + cut_h // 2, 0, H) (same for x with cx).cutmix(img_a, img_b, box) returns a copy of img_a with the region [y1:y2, x1:x2] replaced by the same region of img_b. Images have shape (H, W, ...).adjusted_lambda(box, H, W) returns 1 - (y2 - y1) * (x2 - x1) / (H * W), the fraction of the result that still comes from img_a.Compute the box first, then paste, then compute the label weight from the real pasted area, not from the requested lam.
lam = 1 gives an empty box and leaves img_a untouched.
No results yet
Run your code to check it against the examples, or submit to run every test.