TransWikia.com

Keras generator Function

Data Science Asked by Yosra Griri on February 10, 2021

I am trying to write a batch generator function so that I can train my Keras model using it but I don’t know from where to start. Does anyone have some examples or tutorials?

One Answer

This tutorial explains in a nice and simple way how to create a data generator which you can pass to your Keras model to train using fit_generator(). Two things to keep in mind about Keras generators, in order to be compatible with Tensorflow 2.x requirements:

  1. Your generator should inherit from keras.utils.Sequence, which allows for internal parallelization of training
  2. Populate the __getitem__() and __len__() methods. The first makes your generator iterable and the second returns its length using the builtin len command on the generator object. Both are required by Keras.

Answered by pcko1 on February 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP