Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing a multi-input model in Keras, each with a different sample sizes each (different batch sizes each)

I am currently trying to implement a multi-input model in Keras. The input consists of multiple batches, and each includes different samples, but I get a 'different samples'-error. My implementation looks like this:

The model site looks as follows:

for s in range(NUM_STREAMS):
    inp.append(Input(shape=(16,8)))
...

The site where the error occurs:

history = model.train_on_batch(
                x=[x for x in X_batch],
                y=[y for y in y_batch]
            )

The error I get is:

ValueError: All input arrays (x) should have the same number of
samples. Got array shapes: [(6, 16, 8), (7, 16, 8), (6, 16, 8), (6, 16, 8)]

The abstract model architecture looks as follow:

Multiple input, Multiple output

like image 524
DaveTheAl Avatar asked May 21 '17 20:05

DaveTheAl


People also ask

How do I set batch size in Keras?

If you ever need to specify a fixed batch size for your inputs (this is useful for stateful recurrent networks), you can pass a batch_size argument to a layer. If you pass both batch_size=32 and input_shape=(6, 8) to a layer, it will then expect every batch of inputs to have the batch shape (32, 6, 8) .

Does tf Keras sequential support multiple inputs?

Keras is able to handle multiple inputs (and even multiple outputs) via its functional API. Learn more about 3 ways to create a Keras model with TensorFlow 2.0 (Sequential, Functional, and Model Subclassing).

How does batch size affect LSTM?

For models like LSTM and CNN, the batch size is critical to learn the common patterns as important features. For a model to be able to figure out what are the common patterns and features across the input train samples we need to provide the samples as batches.


1 Answers

FYI, when faced with a similar problem, I rewrote my model in tensorflow, as their computational graphs are not constrained to keeping a batch size dimension constant.

like image 129
thorbjorn444 Avatar answered Sep 23 '22 16:09

thorbjorn444