Bird
Raised Fist0
Computer Visionml~8 mins

Cutout and CutMix in Computer Vision - Model Metrics & Evaluation

Choose your learning style10 modes available
Metrics & Evaluation - Cutout and CutMix
Which metric matters for Cutout and CutMix and WHY

Cutout and CutMix are data augmentation methods used to improve image model training. The key metrics to watch are accuracy and generalization metrics like validation accuracy or validation loss. These show if the model learns better features and avoids overfitting. Sometimes, robustness metrics on noisy or occluded images also matter, since these augmentations help models handle missing or mixed parts.

Confusion matrix example

Imagine a model trained on images with Cutout or CutMix. Here is a confusion matrix after testing:

      | Predicted Cat | Predicted Dog |
      |---------------|---------------|
      | True Cat: 45  | 5             |
      | True Dog: 7   | 43            |
    

From this, we calculate:

  • Precision for Cat = 45 / (45 + 5) = 0.9
  • Recall for Cat = 45 / (45 + 7) = 0.865
  • F1 score balances precision and recall.

This shows the model is good at recognizing cats and dogs after augmentation.

Precision vs Recall tradeoff with Cutout and CutMix

Cutout and CutMix help models learn better by showing partial or mixed images. This can improve recall because the model sees more varied examples and misses fewer true cases.

For example, in a wildlife camera trap, recall is important to catch all animals. Cutout helps by hiding parts of animals, so the model learns to recognize them even if partly hidden.

However, precision might drop slightly if the model gets confused by mixed images (CutMix). So, there is a tradeoff: better recall but sometimes lower precision.

What good vs bad metric values look like

Good values:

  • Validation accuracy above baseline without augmentation.
  • Balanced precision and recall (e.g., both above 0.8).
  • Lower validation loss showing better generalization.

Bad values:

  • Validation accuracy same or worse than baseline (augmentation not helping).
  • Very low precision or recall (model confused by augmentations).
  • High training accuracy but low validation accuracy (overfitting despite augmentation).
Common pitfalls in metrics with Cutout and CutMix
  • Accuracy paradox: High accuracy can hide poor recall on rare classes.
  • Data leakage: If augmented images leak test info, metrics look too good.
  • Overfitting: Sometimes augmentation is not enough; watch if validation loss stops improving.
  • Misinterpreting precision and recall: Know which matters more for your task.
Self-check question

Your image classifier trained with CutMix has 98% accuracy but only 12% recall on a rare class. Is it good for production? Why or why not?

Answer: No, it is not good. The low recall means the model misses most examples of the rare class, which could be critical (like missing a disease or defect). High accuracy is misleading because the rare class is small. You need to improve recall, possibly by adjusting augmentation or model.

Key Result
Cutout and CutMix improve model generalization by increasing recall and robustness, but watch precision and validation accuracy to ensure balanced performance.

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