0
0
Computer Visionml~20 mins

Random erasing in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Random Erasing 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 random erasing in image data augmentation?

Random erasing is a technique used in training image models. What does it mainly help with?

AIt helps the model learn to ignore small occlusions or missing parts in images, improving robustness.
BIt increases the image resolution by adding random pixels.
CIt converts images to grayscale to reduce color bias.
DIt crops the image to a fixed size to standardize input.
Attempts:
2 left
💡 Hint

Think about how hiding parts of an image during training might help the model.

Predict Output
intermediate
2:00remaining
What is the output shape after applying random erasing to a batch of images?

Given a batch of 16 RGB images of size 64x64, what will be the shape of the batch after applying random erasing augmentation?

Computer Vision
import torch
import torchvision.transforms as transforms

transform = transforms.Compose([
    transforms.RandomErasing(p=1.0, scale=(0.02, 0.33), ratio=(0.3, 3.3))
])

batch = torch.randn(16, 3, 64, 64)  # batch of 16 images
augmented_batch = torch.stack([transform(img) for img in batch])
print(augmented_batch.shape)
Atorch.Size([16, 3, 64, 64])
Btorch.Size([16, 3, 32, 32])
Ctorch.Size([16, 1, 64, 64])
Dtorch.Size([3, 64, 64])
Attempts:
2 left
💡 Hint

Random erasing modifies pixels but does not change image size or batch size.

Hyperparameter
advanced
1:30remaining
Which hyperparameter controls the size of the erased area in random erasing?

In random erasing, which hyperparameter defines the proportion of the image area that can be erased?

Amean
Bratio
Cp
Dscale
Attempts:
2 left
💡 Hint

Think about which parameter sets the size range of the erased rectangle.

Metrics
advanced
1:30remaining
How does random erasing typically affect model accuracy on test data?

When random erasing is applied during training, what is the usual effect on the model's accuracy on unseen test images?

AIt usually decreases accuracy because it removes important image parts.
BIt has no effect on accuracy since it only changes training images.
CIt usually improves accuracy by making the model more robust to occlusions.
DIt causes the model to overfit the training data.
Attempts:
2 left
💡 Hint

Consider how training with harder examples affects generalization.

🔧 Debug
expert
2:00remaining
What error does this random erasing code raise?

Consider this code snippet using torchvision's RandomErasing. What error will it raise?

Computer Vision
import torchvision.transforms as transforms

transform = transforms.RandomErasing(p=1.0, scale=(0.5, 0.1))

# Applying transform to a tensor image
import torch
img = torch.randn(3, 32, 32)
transformed_img = transform(img)
ARuntimeError: input tensor must be 4D
BValueError: scale should be a tuple (min, max) with min <= max
CTypeError: RandomErasing expects a PIL Image, not a tensor
DNo error, code runs successfully
Attempts:
2 left
💡 Hint

Check the order of values in the scale tuple.