liveBook · Manning

Tfdatasets

As explained in Deep Learning with R, Third Edition

tfdatasets is an R package that provides bindings for constructing and transforming TensorFlow data input pipelines.

tfdatasets provides R bindings for constructing and transforming TensorFlow data pipelines. It helps produce batched data and labels for Keras models while supporting parallel preprocessing and asynchronous prefetching. section 8.2.4

Build and transform a dataset

Create a dataset with tensor_slices_dataset(), batch it with dataset_batch(3), and reshape each element with dataset_map(). Iterate using as_iterator() and iter_next(), or pass the resulting Dataset directly to fit(). section 8.2.4

Common pipeline operations include:

  • dataset_shuffle() randomizes elements within a buffer. section 8.2.4
  • dataset_prefetch() prepares future batches to improve GPU utilization. section 8.2.4
  • dataset_map() applies transformations to each yielded element and can use parallel calls. section 8.2.4
Listing 8.9 Using image_dataset_from_directory() to read images from directories
image_size <- shape(180, 180)
batch_size <- 32

train_dataset <-
  image_dataset_from_directory(new_base_dir / "train",
                               image_size = image_size,
                               batch_size = batch_size)
validation_dataset <-
  image_dataset_from_directory(new_base_dir / "validation",
                               image_size = image_size,
                               batch_size = batch_size)
test_dataset <-
  image_dataset_from_directory(new_base_dir / "test",
                               image_size = image_size,
                               batch_size = batch_size)

Use image_dataset_from_directory() to create training, validation, and test datasets from directory-organized images. section 8.2.4

How Deep Learning with R, Third Edition covers it

How deep it goes
Demonstrates construction, iteration, batching, mapping, shapes, and model fitting without detailing Dataset internals.
Examples
Uses a 100-by-6 integer array, reshaping transformations, and image datasets loaded from train, validation, and test directories.
What it assumes
Assumes basic R usage and TensorFlow or Keras context while demonstrating dataset operations from concrete arrays.
What you can do after
Apply it via R pipelines to prepare batched inputs and train Keras models.
How it connects
Connects datasets with TensorFlow, Keras models, preprocessing, batching, iteration, parallelization, and prefetching.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.