fit_generator and Multi-Input Models

1,509 views
Skip to first unread message

mhubri...@gmail.com

unread,
Sep 30, 2016, 4:19:18 PM9/30/16
to Keras-users
Hello,

using the Merge layer to create multi-input models, is it still possible to train via fit_generator?

Let's say I have two input branches. This code
model.fit_generator([generator1, generator2])
gives me the following error message:
Exception: Error when checking model input: data should be a Numpy array, or list/dict of Numpy arrays. Found: <my.project.MyGenerator object at 0x2ae8364d868>

I'm aware that a list of Numpy arrays would solve the problem (and using model.fit() at the same time). Generators are just more convenient.

Klemen Grm

unread,
Oct 2, 2016, 7:45:31 PM10/2/16
to Keras-users, mhubri...@gmail.com
You can still use a generator with multiple input models, but it can only be a single generator. Your generator should return two lists, containing respectively a batch of each of your model's inputs and outputs.

mhubri...@gmail.com

unread,
Oct 3, 2016, 4:56:55 AM10/3/16
to Keras-users, mhubri...@gmail.com
Of course! It's always simpler than you think it is ;)

Thank you.

jin...@eng.ucsd.edu

unread,
Apr 11, 2017, 2:44:26 PM4/11/17
to Keras-users, mhubri...@gmail.com
Hi, but what if I want the fit_generator to generate two output with different batch_size? The batch_per_epoch can also take in two values?
Reply all
Reply to author
Forward
0 new messages