Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could Keras prefetch data like tensorflow Dataset?

In TensorFlow's Dataset API, we can use dataset.prefetch(buffer_size=xxx) to preload other batches' data while GPU is processing the current batch's data, therefore, I can make full use of GPU.

I'm going to use Keras, and wonder if keras has a similar API for me to make full use of GPU, instead of serial execution: read batch 0->process batch 0->read batch 1-> process batch 1-> ...

I briefly looked through the keras API and did not see a description of the prefetch.

like image 294
Shouyu Chen Avatar asked Sep 05 '18 03:09

Shouyu Chen


People also ask

What is prefetch in keras?

Prefetching overlaps the preprocessing and model execution of a training step. While the model is executing training step s , the input pipeline is reading the data for step s+1 . Doing so reduces the step time to the maximum (as opposed to the sum) of the training and the time it takes to extract the data.

Which are the three main methods of getting data into a TensorFlow program?

TensorFlow's Basic Programming Elements TensorFlow allows us to assign data to three kinds of data elements: constants, variables, and placeholders. Let's take a closer look at what each of these data components represents.

Does TF data use GPU?

TensorFlow code, and tf. keras models will transparently run on a single GPU with no code changes required.


1 Answers

If you call fit_generator with workers > 1, use_multiprocessing=True, it will prefetch queue_size batches.

From docs: max_queue_size: Integer. Maximum size for the generator queue. If unspecified, max_queue_size will default to 10.

like image 104
Rocketq Avatar answered Oct 14 '22 05:10

Rocketq