Bird
Raised Fist0
TensorFlowml~20 mins

Pipeline orchestration in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Pipeline Orchestration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main purpose of a pipeline in TensorFlow?

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?

ATo store the trained model in a database
BTo visualize the model architecture in a graph
CTo automate and organize the sequence of data processing and model training steps
DTo only speed up the training by using multiple GPUs
Attempts:
2 left
💡 Hint

Think about how you can run multiple steps one after another without doing each manually.

❓ Predict Output
intermediate
2:00remaining
What is the output shape after this pipeline step?

Given this TensorFlow data pipeline code, what will be the shape of the output batch?

TensorFlow
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)
A(4,)
B(10,)
C(None, 4)
D(4, 1)
Attempts:
2 left
💡 Hint

Batching groups elements into batches of the given size.

❓ Model Choice
advanced
2:00remaining
Which pipeline step is best to normalize image data before training?

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?

Adataset.map(lambda x: x / 255.0)
Bdataset.batch(32)
Cdataset.shuffle(1000)
Ddataset.repeat()
Attempts:
2 left
💡 Hint

Normalization means scaling values to a smaller range.

❓ Hyperparameter
advanced
2:00remaining
Which batch size is likely to improve pipeline throughput without increasing memory too much?

You want to speed up your TensorFlow pipeline training by adjusting batch size. Which batch size choice balances throughput and memory use best?

ABatch size 1
BBatch size 32
CBatch size 10000
DBatch size 1024
Attempts:
2 left
💡 Hint

Too small batch sizes are slow; too large can cause memory errors.

🔧 Debug
expert
2:00remaining
Why does this TensorFlow pipeline raise an error?

Consider this pipeline code snippet. Why does it raise a TypeError?

TensorFlow
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)
ABecause Dataset.range cannot be batched
BBecause map function cannot divide integers
CBecause print cannot output tensors
DBecause batch size must be an integer, not a string
Attempts:
2 left
💡 Hint

Check the argument type passed to batch().

Practice

(1/5)
1. What is the main purpose of pipeline orchestration in TensorFlow?
easy
A. To visualize model predictions
B. To write TensorFlow code faster
C. To run machine learning steps automatically in a set order
D. To increase the size of the training dataset

Solution

  1. Step 1: Understand pipeline orchestration

    Pipeline orchestration means running steps like data prep, training, and evaluation automatically in order.
  2. Step 2: Match purpose with options

    Only To run machine learning steps automatically in a set order describes running steps automatically in order, which is the main purpose.
  3. Final Answer:

    To run machine learning steps automatically in a set order -> Option C
  4. Quick Check:

    Pipeline orchestration = automatic step order [OK]
Hint: Think: pipeline means steps run one after another [OK]
Common Mistakes:
  • Confusing pipeline orchestration with faster coding
  • Thinking it only visualizes results
  • Assuming it changes dataset size
2. Which of the following is the correct way to define a simple TensorFlow pipeline step using the `tf.data` API?
easy
A. dataset = tf.batch(32).from_tensor_slices(data)
B. dataset = tf.data.batch(32).from_tensor_slices(data)
C. dataset = tf.data.Dataset.batch(32).from_tensor_slices(data)
D. dataset = tf.data.Dataset.from_tensor_slices(data).batch(32)

Solution

  1. Step 1: Recall correct tf.data syntax

    The correct order is to create a Dataset from data, then apply batch().
  2. Step 2: Check each option

    Only dataset = tf.data.Dataset.from_tensor_slices(data).batch(32) uses tf.data.Dataset.from_tensor_slices(data).batch(32), which is valid syntax.
  3. Final Answer:

    dataset = tf.data.Dataset.from_tensor_slices(data).batch(32) -> Option D
  4. Quick Check:

    Dataset creation then batch() = dataset = tf.data.Dataset.from_tensor_slices(data).batch(32) [OK]
Hint: Remember: create Dataset first, then batch [OK]
Common Mistakes:
  • Swapping method order
  • Using tf.batch instead of tf.data.Dataset.batch
  • Calling batch before creating Dataset
3. Given the following TensorFlow pipeline code, what will be the output of for batch in dataset.take(1): print(batch.numpy())?
import tensorflow as tf

data = [1, 2, 3, 4, 5]
dataset = tf.data.Dataset.from_tensor_slices(data).batch(2)
medium
A. [[1 2]]
B. [1 2 3]
C. [[1 2] [3 4]]
D. [1 2]

Solution

  1. Step 1: Understand batching in tf.data

    Batch(2) groups elements into batches of size 2, so each batch is a 1D tensor with 2 elements.
  2. Step 2: Predict output of first batch

    The first batch contains elements 1 and 2, so printing batch.numpy() shows [[1 2]].
  3. Final Answer:

    [[1 2]] -> Option A
  4. Quick Check:

    Batch size 2 means output shape (1, 2) = [[1 2]] [OK]
Hint: Batch groups data into 2D arrays like [[1 2]] [OK]
Common Mistakes:
  • Forgetting take(1) shows only first batch
  • Confusing batch size with number of batches
  • Expecting 1D [1 2] instead of 2D [[1 2]]
4. You wrote this pipeline step but get an error: dataset = tf.data.Dataset.from_tensor_slices(data).batch(). What is the likely cause?
medium
A. Missing batch size argument in batch()
B. from_tensor_slices() requires a batch size
C. data must be a TensorFlow tensor, not a list
D. batch() cannot be used after from_tensor_slices()

Solution

  1. Step 1: Check batch() usage

    The batch() method requires a batch size argument, e.g., batch(32). Omitting it causes an error.
  2. Step 2: Verify other options

    from_tensor_slices() accepts lists, and batch() can be used after it. So only missing argument is the cause.
  3. Final Answer:

    Missing batch size argument in batch() -> Option A
  4. Quick Check:

    batch() needs size argument [OK]
Hint: batch() always needs a number inside parentheses [OK]
Common Mistakes:
  • Forgetting to pass batch size
  • Thinking data must be tensor, not list
  • Believing batch() can't follow from_tensor_slices()
5. You want to build a TensorFlow pipeline that reads images, resizes them, batches them, and then feeds them to a model. Which sequence of pipeline steps is correct?
hard
A. Batch -> Read images -> Resize -> Feed to model
B. Read images -> Resize -> Batch -> Feed to model
C. Resize -> Batch -> Read images -> Feed to model
D. Feed to model -> Read images -> Resize -> Batch

Solution

  1. Step 1: Understand pipeline order logic

    First, you must read the images to get data, then resize them to uniform size, then batch them for efficient processing.
  2. Step 2: Match correct order

    Read images -> Resize -> Batch -> Feed to model follows the logical order: Read -> Resize -> Batch -> Feed. Other options have steps in wrong order.
  3. Final Answer:

    Read images -> Resize -> Batch -> Feed to model -> Option B
  4. Quick Check:

    Data prep before batching before model input [OK]
Hint: Data must be ready before batching and feeding model [OK]
Common Mistakes:
  • Batching before reading data
  • Feeding model before preprocessing
  • Resizing after batching
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard