Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add prefetching to the dataset for better performance.
TensorFlow
dataset = dataset.shuffle(1000).batch(32).[1](tf.data.AUTOTUNE)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cache' instead of 'prefetch' which caches data but doesn't overlap data preparation.
Using 'repeat' which repeats the dataset but doesn't improve performance by preloading.
✗ Incorrect
Using 'prefetch' allows the dataset to prepare the next batch while the current one is being processed, improving performance.
2fill in blank
mediumComplete the code to prefetch data with an automatic buffer size.
TensorFlow
dataset = dataset.batch(64).[1](buffer_size=tf.data.AUTOTUNE)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cache' which stores data but does not overlap data loading.
Using 'shuffle' which randomizes data order but does not prefetch.
✗ Incorrect
The 'prefetch' method with buffer_size=tf.data.AUTOTUNE lets TensorFlow decide the best buffer size for prefetching.
3fill in blank
hardFix the error in the code to correctly prefetch the dataset.
TensorFlow
dataset = dataset.batch(32).prefetch([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an integer like 32 which may not optimize performance.
Passing None or True which are invalid for prefetch buffer size.
✗ Incorrect
Using tf.data.AUTOTUNE lets TensorFlow choose the best prefetch buffer size automatically.
4fill in blank
hardFill both blanks to create a dataset pipeline that shuffles, batches, and prefetches data.
TensorFlow
dataset = dataset.[1](1000).[2](64).prefetch(tf.data.AUTOTUNE)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'repeat' instead of 'shuffle' which repeats data but does not randomize.
Using 'cache' instead of 'batch' which caches data but does not group it.
✗ Incorrect
First shuffle the data with 'shuffle', then group it into batches with 'batch', and finally prefetch for performance.
5fill in blank
hardFill all three blanks to build a TensorFlow dataset pipeline that caches, shuffles, batches, and prefetches data.
TensorFlow
dataset = dataset.[1]().[2](500).[3](32).prefetch(tf.data.AUTOTUNE)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'repeat' instead of 'cache' which repeats data but does not store it.
Swapping the order of shuffle and batch which affects randomness.
✗ Incorrect
Cache the dataset first to speed up repeated reads, then shuffle to randomize, batch to group, and prefetch to improve performance.