Challenge - 5 Problems
Tensor Shape Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the shape of the tensor after reshaping?
Given the following TensorFlow code, what is the shape of the tensor
reshaped?TensorFlow
import tensorflow as tf original = tf.constant([[1, 2, 3], [4, 5, 6]]) reshaped = tf.reshape(original, [3, 2]) result_shape = reshaped.shape
Attempts:
2 left
💡 Hint
Remember that reshaping changes the shape but keeps the total number of elements the same.
✗ Incorrect
The original tensor has shape (2, 3) with 6 elements. Reshaping to (3, 2) keeps the total elements 6 but changes the shape accordingly.
❓ Model Choice
intermediate2:00remaining
Choosing the correct reshape for a batch of images
You have a batch of 10 grayscale images, each 28x28 pixels, stored in a tensor of shape (10, 28, 28). Which reshape will convert this batch into a 2D tensor suitable for feeding into a fully connected layer?
Attempts:
2 left
💡 Hint
Fully connected layers expect 2D inputs: (batch_size, features).
✗ Incorrect
Each 28x28 image has 784 pixels. Reshaping to (10, 784) flattens each image while keeping the batch size.
❓ Metrics
advanced2:00remaining
Calculating output shape after Conv2D layer
A Conv2D layer has input shape (batch_size, 64, 64, 3), kernel size (3, 3), stride 2, and 'valid' padding. What is the output shape (excluding batch size)?
Attempts:
2 left
💡 Hint
Output size = floor((input_size - kernel_size)/stride) + 1 for 'valid' padding.
✗ Incorrect
For each spatial dimension: floor((64 - 3)/2) + 1 = floor(61/2) + 1 = 30 + 1 = 31.
🔧 Debug
advanced2:00remaining
Why does this reshape cause an error?
Consider this code snippet:
import tensorflow as tf x = tf.constant([[1, 2, 3], [4, 5, 6]]) y = tf.reshape(x, [4, 2])Why does this raise an error?
Attempts:
2 left
💡 Hint
Check how many elements are in the original tensor and the new shape.
✗ Incorrect
Original tensor has 6 elements (2*3). New shape requires 8 elements (4*2). This mismatch causes an error.
🧠 Conceptual
expert2:00remaining
Effect of -1 in TensorFlow reshape
What does using -1 in a TensorFlow reshape shape argument do?
Attempts:
2 left
💡 Hint
Think about how to reshape without manually calculating one dimension.
✗ Incorrect
Using -1 lets TensorFlow infer the correct size for that dimension to keep the total elements unchanged.