Error when checking model input: expected convolution2d_input_1 to have 4 dimensions, but got array with shape (32, 32, 3) : <p>I want to train a deep network starting with the following layer:</p>

<pre><code>model = Sequential()
model.add(Conv2D(32, 3, 3, input_shape=(32, 32, 3)))
</code></pre>

<p>using </p>

<pre><code>history = model.fit_generator(get_training_data(),
                samples_per_epoch=1, nb_epoch=1,nb_val_samples=5,
                verbose=1,validation_data=get_validation_data()
</code></pre>

<p>with the following generator:</p>

<pre><code>def get_training_data(self):
     while 1:
        for i in range(1,5):
            image = self.X_train[i]
            label = self.Y_train[i]
            yield (image,label)
</code></pre>

<p>(validation generator looks similar).</p>

<p>During training, I get the error: </p>

<pre><code>Error when checking model input: expected convolution2d_input_1 to have 4 
dimensions, but got array with shape (32, 32, 3)
</code></pre>

<p>How can that be, with a first layer</p>

<pre><code> model.add(Conv2D(32, 3, 3, input_shape=(32, 32, 3)))
</code></pre>

<p>?</p>
