TensorFlow Test 2 β Questions and Answers
Question 1: Which TensorFlow function is used to evaluate a model on test data and return loss and metrics?
- model.predict()
- model.evaluate() (Correct answer)
- model.fit()
- model.compile()
Correct answer: model.evaluate()
model.evaluate() runs forward passes on the provided dataset and returns the loss and any compiled metrics.
Question 2: When calling model.evaluate(), what does setting verbose=0 do?
- Suppresses all output to stdout (Correct answer)
- Enables debug logging
- Returns only accuracy
- Raises an error
Correct answer: Suppresses all output to stdout
verbose=0 silences the progress bar and per-batch logging during evaluation.
Question 3: In TensorFlow, which dataset split should NEVER be used to tune hyperparameters?
- Training set
- Validation set
- Test set (Correct answer)
- Both training and validation
Correct answer: Test set
The test set must remain unseen during development to provide an unbiased final performance estimate.
Question 4: What is the purpose of tf.data.Dataset.batch() when preparing test data?
- Shuffles the test data randomly
- Groups samples into mini-batches for efficient evaluation (Correct answer)
- Repeats the dataset indefinitely
- Applies data augmentation
Correct answer: Groups samples into mini-batches for efficient evaluation
batch() groups consecutive elements into tensors so the GPU can process multiple samples in parallel during evaluation.
Question 5: Which Keras callback is most useful for logging metrics to TensorBoard during evaluation?
- EarlyStopping
- ModelCheckpoint
- TensorBoard (Correct answer)
- ReduceLROnPlateau
Correct answer: TensorBoard
The TensorBoard callback writes loss and metric summaries to log files that TensorBoard can visualize.
Question 6: In model.evaluate(), the steps parameter controls what?
- Number of epochs to run
- Number of batches to draw from the dataset (Correct answer)
- Learning rate schedule
- Number of layers to freeze
Correct answer: Number of batches to draw from the dataset
steps specifies how many batches are pulled from a generator or tf.data pipeline before evaluation stops.
Question 7: What does model.evaluate() return when a model is compiled with multiple metrics?
- A dictionary of metric names to values
- A list where the first element is loss followed by each metric value (Correct answer)
- Only the final metric value
- A tf.Tensor of shape (num_metrics,)
Correct answer: A list where the first element is loss followed by each metric value
model.evaluate() returns a list: [loss, metric1, metric2, ...] in the order they were specified at compile time.
Which TensorFlow function is used to evaluate a model on test data and return loss and metrics?