TensorFlow tf.data Pipelines 2 β Questions and Answers
Question 1: Which tf.data method is used to read TFRecord files?
- tf.data.TFRecordDataset() (Correct answer)
- tf.data.RecordDataset()
- tf.data.BinaryDataset()
- tf.data.FileDataset()
Correct answer: tf.data.TFRecordDataset()
TFRecordDataset reads TFRecord binary files, the recommended format for large-scale TensorFlow datasets.
Question 2: What does the num_parallel_calls parameter in dataset.map() do?
- Parallelizes the map transformation across multiple CPU threads (Correct answer)
- Sets the number of GPUs to use
- Controls batch size
- Limits dataset size
Correct answer: Parallelizes the map transformation across multiple CPU threads
num_parallel_calls allows multiple map function calls to run simultaneously, improving throughput on multi-core systems.
Question 3: Which tf.data method caches dataset elements to memory or disk?
- dataset.cache() (Correct answer)
- dataset.store()
- dataset.persist()
- dataset.save()
Correct answer: dataset.cache()
dataset.cache() saves elements after the first epoch so subsequent epochs read from cache instead of re-processing.
Question 4: What does tf.io.parse_single_example() do?
- Parses a single serialized tf.train.Example protobuf (Correct answer)
- Reads a single CSV row
- Decodes a JPEG image
- Parses a JSON string
Correct answer: Parses a single serialized tf.train.Example protobuf
tf.io.parse_single_example() deserializes a TFRecord's tf.train.Example into tensors using a feature description dict.
Question 5: Which method creates a dataset from a list of filenames?
- tf.data.Dataset.list_files() (Correct answer)
- tf.data.Dataset.from_files()
- tf.data.Dataset.glob()
- tf.data.Dataset.file_list()
Correct answer: tf.data.Dataset.list_files()
tf.data.Dataset.list_files() creates a dataset of file path strings matching a glob pattern.
Question 6: What is the purpose of tf.data.experimental.AUTOTUNE?
- Lets TensorFlow automatically tune pipeline parameters like buffer sizes (Correct answer)
- Enables experimental model features
- Tunes learning rate automatically
- Auto-selects the best GPU
Correct answer: Lets TensorFlow automatically tune pipeline parameters like buffer sizes
AUTOTUNE allows the tf.data runtime to dynamically choose optimal values for buffer sizes and parallelism.
Which tf.data method is used to read TFRecord files?