0
0
TensorFlowml~20 mins

Batch normalization in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Batch Normalization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use batch normalization in training?

Batch normalization helps improve training by:

  • Avoiding vanishing gradients
  • Reducing internal covariate shift
  • Increasing model capacity
  • Replacing dropout

Which is the main reason batch normalization is used?

AIt reduces internal covariate shift by normalizing layer inputs during training.
BIt increases the number of neurons in each layer automatically.
CIt replaces the need for activation functions like ReLU.
DIt prevents overfitting by randomly dropping neurons.
Attempts:
2 left
💡 Hint

Think about what happens to the input distribution of layers during training.

Predict Output
intermediate
1:30remaining
Output shape after batch normalization layer

Given the following TensorFlow code, what is the shape of output?

TensorFlow
import tensorflow as tf
input_tensor = tf.random.normal([32, 28, 28, 3])
bn_layer = tf.keras.layers.BatchNormalization()
output = bn_layer(input_tensor)
output_shape = output.shape
A(32, 28, 28, 3)
B(28, 28, 3)
C(32, 3)
D(32, 28, 28)
Attempts:
2 left
💡 Hint

Batch normalization does not change the shape of the input tensor.

Hyperparameter
advanced
2:00remaining
Choosing momentum value in batch normalization

In TensorFlow's BatchNormalization layer, the momentum parameter controls the moving average of mean and variance. Which statement about setting momentum is true?

AA higher momentum means the moving averages update quickly, relying more on current batch values.
BMomentum controls the learning rate of the batch normalization layer.
CA higher momentum means the moving averages update slowly, relying more on past values.
DMomentum is only used during training and ignored during inference.
Attempts:
2 left
💡 Hint

Think about how moving averages work with momentum values close to 1.

🔧 Debug
advanced
2:00remaining
Why does batch normalization cause error with batch size 1?

Consider this code snippet:

import tensorflow as tf
input_tensor = tf.random.normal([1, 10])
bn = tf.keras.layers.BatchNormalization()
output = bn(input_tensor)

Running this raises an error. Why?

ABatch normalization requires input values to be positive.
BBatch normalization requires batch size > 1 to compute variance; batch size 1 causes division by zero.
CBatch normalization only works with 4D tensors, not 2D tensors.
DBatch normalization cannot be used on tensors created with tf.random.normal.
Attempts:
2 left
💡 Hint

Think about how variance is calculated with only one sample.

Metrics
expert
2:30remaining
Effect of batch normalization on training metrics

You train two identical neural networks on the same data. One uses batch normalization after each dense layer; the other does not. Which of the following is the most likely difference in training metrics?

ABatch normalization causes the training loss to increase and accuracy to decrease.
BThe network without batch normalization converges faster but has lower validation accuracy.
CBoth networks converge at the same speed but the one without batch normalization has better accuracy.
DThe network with batch normalization converges faster and achieves higher accuracy on training and validation sets.
Attempts:
2 left
💡 Hint

Batch normalization stabilizes and speeds up training.