TensorFlow Advanced TensorFlow Techniques 2 β Questions and Answers
Question 1: What is the purpose of tf.keras.callbacks.LambdaCallback?
- Allows arbitrary functions to be called at training events without writing a full callback class (Correct answer)
- Schedules lambda layer updates
- Applies gradient transformations
- Logs lambda function outputs
Correct answer: Allows arbitrary functions to be called at training events without writing a full callback class
LambdaCallback lets you pass Python functions for events like on_epoch_end or on_batch_begin without subclassing tf.keras.callbacks.Callback.
Question 2: What does tf.config.list_physical_devices('GPU') return?
- A list of available GPU devices on the system (Correct answer)
- GPU configuration settings
- The number of GPU cores
- GPU memory capacity
Correct answer: A list of available GPU devices on the system
tf.config.list_physical_devices('GPU') returns a list of PhysicalDevice objects representing each GPU visible to TensorFlow.
Question 3: Which strategy distributes training across multiple GPUs on a single machine?
- tf.distribute.MirroredStrategy (Correct answer)
- tf.distribute.MultiWorkerMirroredStrategy
- tf.distribute.CentralStorageStrategy
- tf.distribute.OneDeviceStrategy
Correct answer: tf.distribute.MirroredStrategy
MirroredStrategy replicates the model on each GPU and uses all-reduce to synchronize gradient updates across devices.
Question 4: What is the purpose of tf.debugging.assert_shapes()?
- Verifies tensor shapes match expectations and raises an error if not (Correct answer)
- Asserts that shapes are undefined
- Enforces shapes during graph compilation only
- Checks shape compatibility between layers
Correct answer: Verifies tensor shapes match expectations and raises an error if not
tf.debugging.assert_shapes() checks that tensors have specified shapes, raising an InvalidArgument error if they don't match.
Question 5: What does tf.keras.backend.clear_session() do?
- Resets Keras state including the global graph and frees GPU memory (Correct answer)
- Clears the training data cache
- Resets model weights only
- Closes all open files
Correct answer: Resets Keras state including the global graph and frees GPU memory
clear_session() destroys the current Keras session, resetting all state and freeing associated memory, useful when training multiple models in a loop.
Question 6: Which TensorFlow API generates text, image, or other creative content using generative models?
- TensorFlow Generative (tf.keras with custom generators/discriminators)
- tf.generate()
- tf.creative()
- TF-GAN library (Correct answer)
Correct answer: TF-GAN library
TF-GAN (tensorflow/gan) is a library that provides GAN building blocks, losses, and evaluation metrics for generative model development.
What is the purpose of tf.keras.callbacks.LambdaCallback?