title: CNN + LSTM implementation error for image classification
body: <p>I am trying to implement a CNN network + LSTM to be able to predict 4 different classes based on the sequence of x-ray images, which were preprocessed to 150x150x3 shape. My X-train shape is (4067, 150, 150, 3). When I am executing the code
  <strong>model.fit()</strong>, i am getting the error.</p>
  <pre><code># x_train = np.reshape(x_train, (4067, 150, 150, 3))
  # y_train = np.reshape(y_train, (4067, 4))
  
  model = Sequential()
  model.add(TimeDistributed(Conv2D(filters = 32, 
                                   kernel_size=(3,3), 
                                   padding='same', 
                                   activation = 'relu'), 
                            input_shape=(None, 150, 150, 3)))
  model.add(TimeDistributed(AveragePooling2D()))
  model.add(TimeDistributed(Flatten()))
  model.add(LSTM(100))
  model.add(Dense(24, activation='relu',name='output'))
  model.add(Dense(4, activation = 'softmax'))
  
  from tensorflow.keras.optimizers import Adam
  
  optimizer = Adam(lr=0.001)
  model.compile(optimizer = optimizer, 
                         loss = 'categorical_crossentropy',
                         metrics=['accuracy'])
  from tensorflow.keras.callbacks import ReduceLROnPlateau
  
  reduce_lr = ReduceLROnPlateau(monitor = 'val_accuracy',
                              factor = 0.3, 
                              patience = 2,
                              min_delta = 0.001,
                              mode = 'auto',
                              verbose = 1)
  
  hist_cnn_lstm = model.fit(x_train, y_train, batch_size=64, epochs=15,
                                     validation_data = (x_valid, y_valid),
                            callbacks=reduce_lr
                           )
  </code></pre>
  <p>ERROR:</p>
  <pre><code>Epoch 1/15
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-24-3ec61fbabcf1&gt; in &lt;module&gt;()
        1 hist_cnn_lstm = model.fit(x_train, y_train, batch_size=64, epochs=15,
        2                                    validation_data = (x_valid, y_valid),
  ----&gt; 3                           callbacks=reduce_lr
        4                          )
  
  1 frames
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs)
     1145           except Exception as e:  # pylint:disable=broad-except
     1146             if hasattr(e, &quot;ag_error_metadata&quot;):
  -&gt; 1147               raise e.ag_error_metadata.to_exception(e)
     1148             else:
     1149               raise
  
  ValueError: in user code:
  
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1021, in train_function  *
          return step_function(self, iterator)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1010, in step_function  **
          outputs = model.distribute_strategy.run(run_step, args=(data,))
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1000, in run_step  **
          outputs = model.train_step(data)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 859, in train_step
          y_pred = self(x, training=True)
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py&quot;, line 67, in error_handler
          raise e.with_traceback(filtered_tb) from None
      File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/input_spec.py&quot;, line 264, in assert_input_compatibility
          raise ValueError(f'Input {input_index} of layer &quot;{layer_name}&quot; is 
  
      ValueError: Input 0 of layer &quot;sequential_1&quot; is incompatible with the layer: expected shape=(None, None, 150, 150, 3), found shape=(None, 150, 150, 3)
  </code></pre>