Bird
Raised Fist0
Computer Visionml~20 mins

Small dataset strategies in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Small Dataset Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use data augmentation with small image datasets?

Imagine you have only 100 images to train a computer vision model. Why is data augmentation helpful in this case?

AIt removes noisy images to improve dataset quality.
BIt artificially increases the dataset size by creating modified versions of images, helping the model learn better.
CIt compresses images to reduce storage space.
DIt converts images to grayscale to simplify the model.
Attempts:
2 left
💡 Hint

Think about how to get more training examples without collecting new images.

Predict Output
intermediate
1:30remaining
Output of image flipping augmentation code

What will be the shape of the output image after applying horizontal flip augmentation using this code?

Computer Vision
import numpy as np
image = np.random.rand(64, 64, 3)
flipped_image = np.flip(image, axis=1)
print(flipped_image.shape)
A(64, 64, 3)
B(3, 64, 64)
C(64, 3, 64)
D(128, 64, 3)
Attempts:
2 left
💡 Hint

Flipping changes pixel order but not image dimensions.

data_output
advanced
2:00remaining
Resulting dataset size after augmentation

You have 50 images. You apply 3 augmentation techniques: rotation, horizontal flip, and brightness change. Each technique creates one new image per original image. How many images will you have after augmentation?

A100
B150
C200
D250
Attempts:
2 left
💡 Hint

Count original images plus all augmented images.

🔧 Debug
advanced
2:00remaining
Identify the error in transfer learning code snippet

What error will this code produce when trying to fine-tune a pretrained model on a small dataset?

Computer Vision
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
from tensorflow.keras.models import Model

base_model = MobileNetV2(weights='imagenet', include_top=False, input_shape=(224,224,3))
for layer in base_model.layers:
    layer.trainable = False
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(10, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=x)
model.compile(optimizer='adam', loss='categorical_crossentropy')
ASyntaxError from missing colon in for loop
BTypeError because base_model has no attribute 'output'
CNo error, code runs fine
DValueError due to Dense layer applied to 4D tensor without flattening
Attempts:
2 left
💡 Hint

Check the shape of the output from base_model before Dense layer.

🚀 Application
expert
2:30remaining
Best strategy to improve model accuracy on very small image dataset

You have only 30 labeled images for a classification task. You want to improve your model's accuracy. Which strategy is most effective?

AUse transfer learning with a pretrained model and freeze most layers, then fine-tune on your data.
BTrain a deep neural network from scratch with many layers and epochs.
CUse only the original images without augmentation to avoid noise.
DReduce image resolution drastically to speed up training.
Attempts:
2 left
💡 Hint

Think about leveraging existing knowledge from large datasets.

Practice

(1/5)
1. Which of the following is a common strategy to improve model performance when you have a small image dataset?
easy
A. Train a deep model from scratch without any pre-trained weights
B. Use data augmentation to create more training images
C. Ignore validation to use all data for training
D. Reduce image resolution to save memory only

Solution

  1. Step 1: Understand small dataset challenges

    Small datasets often cause models to overfit and perform poorly on new data.
  2. Step 2: Identify effective strategies

    Data augmentation creates new images by modifying existing ones, increasing data variety and helping the model generalize better.
  3. Final Answer:

    Use data augmentation to create more training images -> Option B
  4. Quick Check:

    Data augmentation = More data variety [OK]
Hint: More data variety helps small datasets [OK]
Common Mistakes:
  • Training from scratch causes overfitting
  • Ignoring validation hides model issues
  • Reducing resolution alone doesn't add data
2. Which code snippet correctly applies data augmentation using the Python library torchvision.transforms?
easy
A. transforms.Compose([transforms.RandomHorizontalFlip(), transforms.ToTensor()])
B. transforms.RandomCrop(32, 32)
C. transforms.ToTensor(), transforms.Normalize()
D. transforms.Resize(256)

Solution

  1. Step 1: Recognize data augmentation syntax

    Data augmentation requires combining multiple transforms, usually with Compose.
  2. Step 2: Check which option uses Compose with augmentation

    transforms.Compose([transforms.RandomHorizontalFlip(), transforms.ToTensor()]) uses Compose with RandomHorizontalFlip (augmentation) and ToTensor (conversion), which is correct.
  3. Final Answer:

    transforms.Compose([transforms.RandomHorizontalFlip(), transforms.ToTensor()]) -> Option A
  4. Quick Check:

    Compose + augmentation = transforms.Compose([transforms.RandomHorizontalFlip(), transforms.ToTensor()]) [OK]
Hint: Use Compose to combine augmentations [OK]
Common Mistakes:
  • Using single transform without Compose
  • Missing ToTensor conversion
  • Using only resizing without augmentation
3. Consider this Python code using transfer learning with PyTorch:
import torchvision.models as models
model = models.resnet18(pretrained=True)
for param in model.parameters():
    param.requires_grad = False
model.fc = torch.nn.Linear(512, 2)
What does this code do?
medium
A. Trains all layers of ResNet18 from scratch
B. Unfreezes all layers for fine-tuning
C. Freezes all layers except the last fully connected layer
D. Removes the last layer without replacement

Solution

  1. Step 1: Analyze parameter freezing

    The loop sets requires_grad=False for all parameters, freezing them during training.
  2. Step 2: Check the last layer replacement

    The last fully connected layer (fc) is replaced with a new Linear layer, which by default has requires_grad=True.
  3. Final Answer:

    Freezes all layers except the last fully connected layer -> Option C
  4. Quick Check:

    Freeze all but last layer = Freezes all layers except the last fully connected layer [OK]
Hint: Freeze parameters, then replace last layer [OK]
Common Mistakes:
  • Assuming all layers are trainable
  • Not noticing last layer replacement
  • Confusing freezing with unfreezing
4. You wrote this code to augment images but get an error:
transform = transforms.Compose([
    transforms.RandomRotation(30),
    transforms.ToTensor
])
What is the error and how to fix it?
medium
A. Transforms must be applied outside Compose
B. RandomRotation requires degrees as a tuple, fix by using (0,30)
C. Compose should be replaced by Sequential
D. Missing parentheses after ToTensor; fix by using transforms.ToTensor()

Solution

  1. Step 1: Identify the error in ToTensor usage

    transforms.ToTensor is a class, missing parentheses means it's not called, causing an error.
  2. Step 2: Correct the syntax

    Add parentheses to call ToTensor: transforms.ToTensor()
  3. Final Answer:

    Missing parentheses after ToTensor; fix by using transforms.ToTensor() -> Option D
  4. Quick Check:

    Call ToTensor() as function [OK]
Hint: Call transform classes with () [OK]
Common Mistakes:
  • Forgetting parentheses on transform classes
  • Misusing Compose with wrong functions
  • Incorrect argument types for RandomRotation
5. You have only 100 labeled images for a classification task. Which combined approach best improves model accuracy?
hard
A. Use transfer learning with a pre-trained model and apply data augmentation
B. Train a deep CNN from scratch with no augmentation
C. Use only data augmentation without pre-trained weights
D. Increase batch size to 512 and train for fewer epochs

Solution

  1. Step 1: Understand small dataset limits

    With only 100 images, training deep models from scratch risks overfitting and poor generalization.
  2. Step 2: Combine transfer learning and augmentation

    Transfer learning uses knowledge from large datasets, and augmentation increases data variety, both improving accuracy.
  3. Final Answer:

    Use transfer learning with a pre-trained model and apply data augmentation -> Option A
  4. Quick Check:

    Transfer learning + augmentation = Best for small data [OK]
Hint: Combine pre-trained models with augmentation [OK]
Common Mistakes:
  • Training from scratch with little data
  • Relying on augmentation alone
  • Using too large batch size causing poor learning