0
0
TensorFlowml~20 mins

Data augmentation for images in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Augmentation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output shape after applying random flip augmentation
Consider the following TensorFlow code that applies a random horizontal flip to a batch of images. What is the shape of the output tensor?
TensorFlow
import tensorflow as tf

images = tf.random.uniform([16, 64, 64, 3])  # batch of 16 images, 64x64 RGB
augmented_images = tf.image.random_flip_left_right(images)
output_shape = augmented_images.shape
print(output_shape)
A(16, 64, 64, 3)
B(64, 64, 3)
C(16, 128, 128, 3)
D(16, 64, 64)
Attempts:
2 left
💡 Hint
The random flip changes pixel order but not the shape.
Model Choice
intermediate
2:00remaining
Choosing augmentation for small dataset
You have a small image dataset and want to reduce overfitting by augmenting data during training. Which augmentation technique is best suited to increase data variety without changing image content drastically?
ARandom rotation by 90 degrees increments only
BRandom cropping with resizing back to original size
CRandom color inversion (negative colors)
DRandom Gaussian noise addition
Attempts:
2 left
💡 Hint
Think about preserving main image features while increasing variety.
Metrics
advanced
2:00remaining
Effect of augmentation on validation accuracy
A model is trained twice: once with data augmentation and once without. The validation accuracy with augmentation is 85%, without augmentation is 78%. What does this difference most likely indicate?
AAugmentation reduced model capacity
BAugmentation caused overfitting on training data
CAugmentation improved model generalization to unseen data
DAugmentation caused data leakage
Attempts:
2 left
💡 Hint
Higher validation accuracy usually means better generalization.
🔧 Debug
advanced
2:00remaining
Debugging augmentation pipeline error
You run this TensorFlow code but get a runtime error. What is the cause? ```python import tensorflow as tf images = tf.random.uniform([8, 32, 32, 3]) augmented = tf.image.random_brightness(images, max_delta=0.5) augmented = tf.image.random_flip_left_right(augmented) augmented = tf.image.random_crop(augmented, size=[8, 28, 28, 3]) ```
Arandom_crop cannot be applied after random_flip_left_right
Brandom_brightness requires images to be uint8, not float32
Crandom_flip_left_right only works on grayscale images
Drandom_crop size must be smaller than input size but batch dimension cannot be included
Attempts:
2 left
💡 Hint
Check the shape argument for random_crop carefully.
🧠 Conceptual
expert
2:00remaining
Why use augmentation only on training data?
Why is data augmentation typically applied only to training images and not to validation or test images?
ATo simulate more diverse training data and fairly evaluate model on original data
BBecause augmentation algorithms are too slow for validation and test sets
CBecause validation and test images are already augmented by default
DTo prevent the model from memorizing augmented images in validation and test sets
Attempts:
2 left
💡 Hint
Think about the purpose of validation and test sets.