Imagine you want to prepare your data, train a model, and then evaluate it automatically. What is the main purpose of using a pipeline in TensorFlow?
Think about how you can run multiple steps one after another without doing each manually.
A pipeline helps you automate and organize the steps like data loading, preprocessing, training, and evaluation so they run smoothly in order.
Given this TensorFlow data pipeline code, what will be the shape of the output batch?
import tensorflow as tf # Create dataset of numbers 0 to 9 dataset = tf.data.Dataset.range(10) # Batch the dataset with batch size 4 batched_dataset = dataset.batch(4) for batch in batched_dataset: output_shape = batch.shape break print(output_shape)
Batching groups elements into batches of the given size.
The batch size is 4, so each batch is a 1D tensor with 4 elements, shape (4,).
You have a pipeline that loads images as tensors with pixel values 0-255. Which TensorFlow pipeline step should you add to normalize pixel values to 0-1 before training?
Normalization means scaling values to a smaller range.
Using map with a function dividing by 255.0 scales pixel values from 0-255 to 0-1, which helps model training.
You want to speed up your TensorFlow pipeline training by adjusting batch size. Which batch size choice balances throughput and memory use best?
Too small batch sizes are slow; too large can cause memory errors.
Batch size 32 is a common balanced choice that improves throughput without using excessive memory.
Consider this pipeline code snippet. Why does it raise a TypeError?
import tensorflow as tf def preprocess(x): return x / 255.0 dataset = tf.data.Dataset.range(5) dataset = dataset.map(preprocess) dataset = dataset.batch(4) for batch in dataset: print(batch)
Check the argument type passed to batch().
The batch method expects an integer for batch size, but '4' is a string, causing a TypeError.
