0
0
TensorFlowml~10 mins

Padding and stride in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a 2D convolutional layer with stride 1.

TensorFlow
conv_layer = tf.keras.layers.Conv2D(filters=32, kernel_size=3, strides=[1], padding='same')
Drag options to blanks, or click blank then click option'
A1
B2
C3
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using stride 0 causes an error because stride must be positive.
Using stride 2 changes the output size and is not what the question asks.
2fill in blank
medium

Complete the code to apply 'valid' padding in a Conv2D layer.

TensorFlow
conv_layer = tf.keras.layers.Conv2D(filters=64, kernel_size=5, strides=1, padding=[1])
Drag options to blanks, or click blank then click option'
A'same'
B'zero'
C'valid'
D'full'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'same' padding keeps output size but is not what the question asks.
Using 'full' or 'zero' are not valid padding options in TensorFlow Conv2D.
3fill in blank
hard

Fix the error in the stride parameter to correctly create a Conv2D layer with stride 2.

TensorFlow
conv_layer = tf.keras.layers.Conv2D(filters=16, kernel_size=3, strides=[1], padding='same')
Drag options to blanks, or click blank then click option'
A2
B(2, 2)
C[2, 2]
D'2'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string '2' causes a type error.
Using [2, 2] also works but tuple (2, 2) is the expected answer.
4fill in blank
hard

Fill both blanks to create a Conv2D layer with kernel size 3 and stride 2.

TensorFlow
conv_layer = tf.keras.layers.Conv2D(filters=10, kernel_size=[1], strides=[2], padding='valid')
Drag options to blanks, or click blank then click option'
A3
B(2, 2)
C2
D(3, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using stride as 2 (int) works but tuple is preferred for clarity.
Using kernel size as (3, 3) is valid but question expects int 3.
5fill in blank
hard

Fill all three blanks to create a Conv2D layer with kernel size (5,5), stride 1, and 'same' padding.

TensorFlow
conv_layer = tf.keras.layers.Conv2D(filters=20, kernel_size=[1], strides=[2], padding=[3])
Drag options to blanks, or click blank then click option'
A(5, 5)
B1
C'same'
D'valid'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'valid' padding shrinks output size.
Using stride other than 1 changes output size.