Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a pre-trained image classification model in TensorFlow.
TensorFlow
import tensorflow as tf model = tf.keras.applications.[1](weights='imagenet')
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing models not related to image classification like LinearRegression.
✗ Incorrect
ResNet50 is a popular pre-trained model for image classification available in TensorFlow Keras applications.
2fill in blank
mediumComplete the code to preprocess an image for the ResNet50 model.
TensorFlow
from tensorflow.keras.applications.resnet50 import preprocess_input img = tf.keras.utils.load_img('image.jpg', target_size=(224, 224)) img_array = tf.keras.utils.img_to_array(img) img_array = tf.expand_dims(img_array, axis=0) processed_img = [1](img_array)
Attempts:
3 left
💡 Hint
Common Mistakes
Using decode_predictions instead of preprocess_input for preprocessing.
✗ Incorrect
The preprocess_input function prepares the image array correctly for ResNet50 model input.
3fill in blank
hardFix the error in the code to get predictions from the model and decode them.
TensorFlow
preds = model.predict(processed_img) results = tf.keras.applications.resnet50.[1](preds, top=3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using preprocess_input instead of decode_predictions after prediction.
✗ Incorrect
decode_predictions converts model output into human-readable labels with probabilities.
4fill in blank
hardFill both blanks to create a simple image segmentation model using TensorFlow Keras.
TensorFlow
from tensorflow.keras import layers, models inputs = layers.Input(shape=(128, 128, 3)) x = layers.Conv2D(32, (3, 3), activation='relu', padding='same')([1]) x = layers.Conv2D(1, (1, 1), activation='sigmoid', padding='same')([2]) model = models.Model(inputs=inputs, outputs=x)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing wrong variables like 'outputs' or 'model' to layers.
✗ Incorrect
The first Conv2D layer takes inputs as input; the second Conv2D layer takes the output of the first layer 'x'.
5fill in blank
hardFill all three blanks to compute accuracy and loss for a classification model in TensorFlow.
TensorFlow
model.compile(optimizer='adam', loss=[1], metrics=[[2]]) history = model.fit(train_data, train_labels, epochs=5) final_acc = history.history[[3]][-1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'loss' key to get accuracy or wrong loss function.
✗ Incorrect
Loss is 'categorical_crossentropy', metric is 'accuracy', and final accuracy is accessed by 'accuracy' key in history.
