Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tf.dataset.prefetch() buffer_size meaning

dataset = dataset.batch(50)
dataset = dataset.prefetch(buffer_size=1)

Is it prefetch 1 batch or 1 element?

Per the API document in tensorflow, the buffer_size is the max num of elements prefetch. But it seems it is num of batch after batching the dataset.

like image 678
Yik Wai Ng Avatar asked Aug 01 '18 22:08

Yik Wai Ng


People also ask

What is Buffer_size in TensorFlow?

buffer_size: A tf. int64 scalar tf. Tensor, representing the maximum number elements that will be buffered when prefetching.

What is TF prefetch?

prefetch transformation. It can be used to decouple the time when data is produced from the time when data is consumed. In particular, the transformation uses a background thread and an internal buffer to prefetch elements from the input dataset ahead of the time they are requested.

What does TF data dataset From_tensor_slices do?

With that knowledge, from_tensors makes a dataset where each input tensor is like a row of your dataset, and from_tensor_slices makes a dataset where each input tensor is column of your data; so in the latter case all tensors must be the same length, and the elements (rows) of the resulting dataset are tuples with one ...

What does TF data dataset do?

The tf. data API enables you to build complex input pipelines from simple, reusable pieces. For example, the pipeline for an image model might aggregate data from files in a distributed file system, apply random perturbations to each image, and merge randomly selected images into a batch for training.


1 Answers

Since you are using dataset.prefetch(buffer_size=1) after dataset.batch(), it means that it will prefetch 1 batch.

like image 181
Djib2011 Avatar answered Oct 14 '22 03:10

Djib2011