0
0
TensorFlowml~20 mins

Data augmentation in pipeline in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Data Augmentation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of TensorFlow data augmentation pipeline
What is the shape of the output tensor after applying this augmentation pipeline to a batch of 32 images of size 64x64x3?
TensorFlow
import tensorflow as tf

batch_size = 32
image_size = 64

# Create dummy batch of images
images = tf.random.uniform([batch_size, image_size, image_size, 3])

# Define augmentation pipeline
augmentation = tf.keras.Sequential([
    tf.keras.layers.RandomFlip('horizontal'),
    tf.keras.layers.RandomRotation(0.1),
    tf.keras.layers.RandomZoom(0.2)
])

augmented_images = augmentation(images)
output_shape = augmented_images.shape
A(32, 62, 62, 3)
B(32, 64, 64, 3)
C(32, 64, 64, 1)
D(64, 64, 3)
Attempts:
2 left
💡 Hint
Augmentation layers keep the batch size and image dimensions the same.
🧠 Conceptual
intermediate
1:30remaining
Purpose of data augmentation in training pipelines
Why do we use data augmentation in machine learning training pipelines?
ATo artificially increase the diversity of training data and reduce overfitting
BTo remove noise from the training data
CTo convert images to grayscale for simpler models
DTo reduce the size of the training dataset for faster training
Attempts:
2 left
💡 Hint
Think about how augmentation affects model generalization.
Hyperparameter
advanced
1:30remaining
Choosing augmentation parameters for RandomRotation
Which of these RandomRotation parameters will rotate images up to 45 degrees in either direction?
Atf.keras.layers.RandomRotation(factor=0.125)
Btf.keras.layers.RandomRotation(factor=0.25)
Ctf.keras.layers.RandomRotation(factor=0.5)
Dtf.keras.layers.RandomRotation(factor=1.0)
Attempts:
2 left
💡 Hint
Rotation factor is a fraction of 2π radians (360 degrees).
Metrics
advanced
1:30remaining
Effect of data augmentation on training and validation accuracy
If a model trained without augmentation has training accuracy 98% and validation accuracy 75%, what is the most likely effect of adding data augmentation?
ABoth training and validation accuracy increase
BTraining accuracy increases, validation accuracy decreases
CTraining accuracy decreases, validation accuracy increases
DBoth training and validation accuracy decrease
Attempts:
2 left
💡 Hint
Augmentation makes training harder but improves generalization.
🔧 Debug
expert
2:30remaining
Debugging augmentation pipeline causing shape mismatch error
Given this pipeline, which option explains why a shape mismatch error occurs during training? ```python import tensorflow as tf augmentation = tf.keras.Sequential([ tf.keras.layers.RandomFlip('horizontal'), tf.keras.layers.RandomRotation(0.2), tf.keras.layers.Resizing(128, 128) ]) # Input images are 64x64x3 images = tf.random.uniform([16, 64, 64, 3]) augmented = augmentation(images) model = tf.keras.Sequential([ tf.keras.layers.InputLayer(input_shape=(64, 64, 3)), tf.keras.layers.Conv2D(32, 3, activation='relu'), tf.keras.layers.Flatten(), tf.keras.layers.Dense(10) ]) model(augmented) ```
AResizing layer is missing required arguments for interpolation
BRandomFlip changes the number of channels from 3 to 1, causing mismatch
CRandomRotation outputs a batch size different from input batch size
DThe model expects input shape (64,64,3) but augmentation outputs (128,128,3), causing mismatch
Attempts:
2 left
💡 Hint
Check the input shape expected by the model vs output shape of augmentation.