Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow Dataset API: dataset.batch(n).prefetch(m) prefetches m batches or samples?

If I use

dataset.batch(n).prefetch(m), 

m batches or m samples will be prefetched?

like image 581
lynn Avatar asked Apr 07 '18 11:04

lynn


People also ask

What is the use of prefetch () function in TensorFlow?

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf.data.Dataset class .prefetch () function is used to produce a dataset that prefetches the specified elements from this given dataset. Hey geek!

What is prefetch in dataset transformation?

The Dataset.prefetch (m) transformation prefetches m elements of its direct input. In this case, since its direct input is dataset.batch (n) and each element of that dataset is a batch (of n elements), it will prefetch m batches.

How to prefetch more than one batch of data at a time?

With tf.data, you can do this with a simple call to dataset.prefetch (1) at the end of the pipeline (after batching). This will always prefetch one batch of data and make sure that there is always one ready. In some cases, it can be useful to prefetch more than one batch.

How does batching work in TensorFlow?

The simplest form of batching stacks n consecutive elements of a dataset into a single element. The Dataset.batch () transformation does exactly this, with the same constraints as the tf.stack () operator, applied to each component of the elements: i.e. for each component i, all elements must have a tensor of the exact same shape.


1 Answers

The Dataset.prefetch(m) transformation prefetches m elements of its direct input. In this case, since its direct input is dataset.batch(n) and each element of that dataset is a batch (of n elements), it will prefetch m batches.

like image 73
mrry Avatar answered Oct 04 '22 19:10

mrry