Bird
Raised Fist0
Computer Visionml~20 mins

Cutout and CutMix in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Cutout and CutMix Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of Cutout in image data augmentation?

Cutout is a popular data augmentation technique used in training image models. What is its main purpose?

ATo rotate the image by a random angle to increase data diversity.
BTo randomly erase a square patch from the input image to encourage the model to focus on less prominent features.
CTo add Gaussian noise to the image pixels to simulate sensor noise.
DTo blend two images together by mixing their pixel values and labels.
Attempts:
2 left
💡 Hint

Think about how Cutout modifies the image to prevent overfitting on specific parts.

🧠 Conceptual
intermediate
1:30remaining
How does CutMix differ from Cutout in data augmentation?

Both CutMix and Cutout modify images during training. What key difference distinguishes CutMix from Cutout?

ACutMix replaces a patch of one image with a patch from another image and mixes their labels, while Cutout only masks a patch with zeros.
BCutMix crops images to smaller sizes, Cutout enlarges images.
CCutMix adds noise to images, while Cutout changes brightness.
DCutMix rotates images randomly, whereas Cutout flips images horizontally.
Attempts:
2 left
💡 Hint

Consider how labels are handled in each technique.

❓ Predict Output
advanced
2:00remaining
What is the output shape and label mix ratio after applying CutMix?

Given two images of shape (3, 32, 32) and labels one-hot encoded as vectors, after applying CutMix with a patch covering 25% of the area, what is the expected label mix ratio?

Computer Vision
import numpy as np

img1 = np.random.rand(3, 32, 32)
img2 = np.random.rand(3, 32, 32)
label1 = np.array([1, 0, 0])  # class A
label2 = np.array([0, 1, 0])  # class B

# CutMix patch covers 25% of image area
patch_area_ratio = 0.25

# Label mix ratio calculation
label_mix_ratio = 1 - patch_area_ratio

mixed_label = label1 * label_mix_ratio + label2 * patch_area_ratio

output_shape = img1.shape
AOutput shape: (3, 32, 32), Label mix ratio: [0.75, 0.25, 0.0]
BOutput shape: (32, 32, 3), Label mix ratio: [0.25, 0.75, 0.0]
COutput shape: (3, 32, 32), Label mix ratio: [0.5, 0.5, 0.0]
DOutput shape: (3, 32, 32), Label mix ratio: [1.0, 0.0, 0.0]
Attempts:
2 left
💡 Hint

Remember the label mix ratio corresponds to the proportion of the original image area kept.

❓ Metrics
advanced
1:30remaining
How does CutMix typically affect model accuracy and robustness compared to no augmentation?

When training an image classification model, what is the typical effect of using CutMix augmentation on accuracy and robustness?

ACutMix has no effect on accuracy or robustness compared to no augmentation.
BCutMix decreases accuracy but improves robustness by confusing the model with mixed labels.
CCutMix usually improves both accuracy and robustness by providing diverse training samples and smoother decision boundaries.
DCutMix improves accuracy but reduces robustness due to overfitting on mixed images.
Attempts:
2 left
💡 Hint

Think about how mixing images and labels helps the model generalize.

🔧 Debug
expert
2:30remaining
Why does this CutMix implementation cause a label mismatch error?

Consider this simplified CutMix code snippet. Why does it raise an error when mixing labels?

Computer Vision
import numpy as np

def cutmix_labels(label1, label2, patch_ratio):
    mixed_label = label1 * patch_ratio + label2 * (1 - patch_ratio)
    return mixed_label

label1 = np.array([1, 0, 0])
label2 = np.array([0, 1, 0])
patch_ratio = 0.3

mixed = cutmix_labels(label1, label2, patch_ratio)
print(mixed)
AThe labels are not one-hot encoded, causing a shape mismatch error.
BThe patch_ratio must be an integer, not a float.
CThe function is missing a return statement.
DThe label mix formula is reversed; it should be label1 * (1 - patch_ratio) + label2 * patch_ratio.
Attempts:
2 left
💡 Hint

Check how the patch_ratio relates to the original and patched image areas.

Practice

(1/5)
1. What is the main purpose of the Cutout technique in computer vision?
easy
A. To remove a patch from an image to improve model robustness
B. To combine two images by overlaying one on the other
C. To increase image resolution for better detail
D. To convert images to grayscale for simpler processing

Solution

  1. Step 1: Understand Cutout's function

    Cutout removes a small patch from an image during training to force the model to learn from other parts.
  2. Step 2: Compare options

    Only To remove a patch from an image to improve model robustness describes removing a patch to improve robustness. Others describe different techniques.
  3. Final Answer:

    To remove a patch from an image to improve model robustness -> Option A
  4. Quick Check:

    Cutout = patch removal [OK]
Hint: Cutout = cut a patch out of the image [OK]
Common Mistakes:
  • Confusing Cutout with CutMix
  • Thinking Cutout increases resolution
  • Assuming Cutout converts image color
2. Which of the following is the correct way to mix labels in CutMix augmentation in Python using PyTorch?
easy
A. new_label = label1 * lambda + label2 * (1 - lambda)
B. new_label = label1 + label2
C. new_label = label1 - label2
D. new_label = label1 / label2

Solution

  1. Step 1: Recall CutMix formula

    CutMix creates a new label by mixing two labels weighted by lambda and (1 - lambda).
  2. Step 2: Match formula to options

    new_label = label1 * lambda + label2 * (1 - lambda) correctly shows weighted sum of two labels. Others are incorrect operations.
  3. Final Answer:

    new_label = label1 * lambda + label2 * (1 - lambda) -> Option A
  4. Quick Check:

    CutMix = weighted sum [OK]
Hint: CutMix blends labels weighted by lambda [OK]
Common Mistakes:
  • Using addition without weights
  • Subtracting or dividing labels incorrectly
  • Confusing CutMix with Cutout
3. Given the following code snippet applying Cutout, what will be the shape of the output image tensor?
import torch
import torchvision.transforms as T

cutout = T.RandomErasing(p=1.0, scale=(0.1, 0.1))
image = torch.randn(3, 224, 224)
output = cutout(image)
print(output.shape)
medium
A. torch.Size([3, 112, 112])
B. torch.Size([1, 224, 224])
C. torch.Size([224, 224, 3])
D. torch.Size([3, 224, 224])

Solution

  1. Step 1: Understand RandomErasing effect

    RandomErasing (Cutout) masks part of the image but does not change its shape.
  2. Step 2: Check input and output shapes

    Input is (3, 224, 224), output remains same shape after Cutout.
  3. Final Answer:

    torch.Size([3, 224, 224]) -> Option D
  4. Quick Check:

    Cutout keeps shape same [OK]
Hint: Cutout masks but keeps image size [OK]
Common Mistakes:
  • Thinking Cutout changes image dimensions
  • Confusing channel order with shape
  • Assuming output is batch dimension added
4. The following code attempts to apply CutMix but causes an error. What is the main issue?
def cutmix(image1, image2, lam):
    bbx1, bby1, bbx2, bby2 = rand_bbox(image1.size(), lam)
    image1[:, bbx1:bbx2, bby1:bby2] = image2[:, bbx1:bbx2, bby1:bby2]
    return image1

# image1 and image2 are tensors of shape (3, 224, 448)
# lam is a float between 0 and 1
medium
A. rand_bbox returns coordinates in (x, y) but slicing expects (height, width)
B. rand_bbox expects size as tuple (H, W) instead of tensor.size() (C, H, W)
C. The function modifies image1 in-place which is not allowed
D. The function does not return the mixed label

Solution

  1. Step 1: Analyze rand_bbox input and slicing

    rand_bbox expects size as (height, width), but image1.size() returns (channels, height, width).
  2. Step 2: Identify mismatch in size argument

    Passing image1.size() (C, H, W) instead of (H, W) causes rand_bbox to compute wrong coordinates, leading to slicing errors.
  3. Final Answer:

    rand_bbox expects size as tuple (H, W) instead of tensor.size() (C, H, W) -> Option B
  4. Quick Check:

    Size argument mismatch = error [OK]
Hint: Pass (H, W) size to rand_bbox, not (C, H, W) [OK]
Common Mistakes:
  • Ignoring coordinate order difference
  • Assuming in-place modification causes error
  • Forgetting to return mixed label
5. You want to improve your image classifier's robustness by combining Cutout and CutMix. Which approach correctly applies both augmentations during training?
hard
A. Apply Cutout to each image separately, then combine them with CutMix
B. Apply Cutout only after training with CutMix is complete
C. Apply CutMix first to combine images, then apply Cutout to mask patches on the mixed image
D. Apply CutMix only on validation data and Cutout only on training data

Solution

  1. Step 1: Understand augmentation order

    CutMix combines two images, then Cutout can mask parts of the combined image to increase robustness.
  2. Step 2: Evaluate options for correct sequence

    Apply CutMix first to combine images, then apply Cutout to mask patches on the mixed image applies CutMix first, then Cutout, which is the correct order to augment the mixed image effectively.
  3. Final Answer:

    Apply CutMix first to combine images, then apply Cutout to mask patches on the mixed image -> Option C
  4. Quick Check:

    CutMix then Cutout = best practice [OK]
Hint: Mix images first, then mask patches [OK]
Common Mistakes:
  • Applying Cutout before mixing images
  • Using augmentations only on validation data
  • Applying augmentations after training
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard