0
0
TensorFlowml~10 mins

Flatten and Dense layers 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 add a Flatten layer to the model.

TensorFlow
model = tf.keras.Sequential([
    [1](input_shape=(28, 28, 1))
])
Drag options to blanks, or click blank then click option'
AFlatten
BDense
CConv2D
DDropout
Attempts:
3 left
💡 Hint
Common Mistakes
Using Dense layer directly without flattening causes shape errors.
Using Conv2D layer without specifying filters and kernel size.
2fill in blank
medium

Complete the code to add a Dense layer with 128 units and ReLU activation.

TensorFlow
model.add([1](128, activation='relu'))
Drag options to blanks, or click blank then click option'
AFlatten
BMaxPooling2D
CConv2D
DDense
Attempts:
3 left
💡 Hint
Common Mistakes
Using Flatten instead of Dense for fully connected layers.
Forgetting to specify activation function.
3fill in blank
hard

Fix the error in the code to correctly add a Dense output layer with 10 units and softmax activation.

TensorFlow
model.add(Dense([1], activation='softmax'))
Drag options to blanks, or click blank then click option'
A1
B10
CNone
D'10'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing number of units as a string causes errors.
Using 1 unit instead of 10 for multi-class classification.
4fill in blank
hard

Fill both blanks to create a model with a Flatten layer followed by a Dense layer with 64 units.

TensorFlow
model = tf.keras.Sequential([
    [1](input_shape=(32, 32, 3)),
    [2](64, activation='relu')
])
Drag options to blanks, or click blank then click option'
AFlatten
BDense
CConv2D
DDropout
Attempts:
3 left
💡 Hint
Common Mistakes
Using Conv2D instead of Flatten for first layer.
Missing activation in Dense layer.
5fill in blank
hard

Fill all three blanks to build a model with Flatten, Dense 128 ReLU, and Dense 10 softmax layers.

TensorFlow
model = tf.keras.Sequential([
    [1](input_shape=(28, 28, 1)),
    [2](128, activation='relu'),
    [3](10, activation='softmax')
])
Drag options to blanks, or click blank then click option'
AFlatten
BDense
CConv2D
DDropout
Attempts:
3 left
💡 Hint
Common Mistakes
Using Conv2D instead of Flatten for input layer.
Using Dropout instead of Dense for hidden layers.
Wrong number of units in output layer.