title: Extra dimension to MaxPool1D layer from Conv1D layer
body: <p>I'm very new to Tensorflow (this is my first project using it), and I don't really understand how input shapes work. I am trying to train a CNN-LSTM on a set of financial time series data.</p>
  <p>For my use case, I have a <code>tf.keras.data.DataLoader</code> object which is meant to serve batches of training data to the model.</p>
  <p>One training instance corresponds to the price history over the last 30 days, and hence should have shape <code>(30,)</code>.</p>
  <p>running the following code:</p>
  <pre><code>for x, y in train_ds:
      print(x, y)
      print(x.shape)
      break
  </code></pre>
  <p>I get that <code>x.shape</code> is <code>(4, 30)</code>, where the <code>Dataset</code> object I have defined serves training instances in batches of 4.</p>
  <p>Here is my code:</p>
  <pre><code># driver code for experiments
  import keras
  import numpy as np
  import matplotlib.pyplot as plt
  import tensorflow as tf
  from keras import layers
  
  WIDTH = 30
  BATCH_SIZE = 4
  
  # load datasets (prepended with 'n' for 'normalized' )
  
  nXtrain = np.load('cad_90s_nXtrain.npy')
  nytrain = np.load('cad_90s_nytrain.npy')
  nXval = np.load('cad_90s_nXval.npy')
  nyval = np.load('cad_90s_nyval.npy')
  nXtest = np.load('cad_90s_nXtest.npy')
  nytest = np.load('cad_90s_nytest.npy')
  
  # instantiate tensorflow Datasets
  train_ds = tf.data.Dataset.from_tensor_slices((nXtrain, nytrain)).batch(BATCH_SIZE)
  val_ds = tf.data.Dataset.from_tensor_slices((nXval, nyval)).batch(BATCH_SIZE)
  test_ds = tf.data.Dataset.from_tensor_slices((nXtest, nytest)).batch(BATCH_SIZE)
  
  
  input_shape = (BATCH_SIZE, WIDTH, 1 )
  
  testnet = tf.keras.Sequential([
      layers.InputLayer(input_shape=input_shape),
      layers.Conv1D(filters=32,
                    kernel_size=3,
                    activation='tanh',
                    padding='same',
                    strides=1),
      layers.MaxPool1D(pool_size=2,
                       padding='same'),
      layers.ReLU(),
      layers.LSTM(units=64, dropout=0.2, activation='tanh'),
      layers.Dense(units=1)
  ])
  
  testnet.build()
  testnet.summary()
  </code></pre>
  <p>with accompanying error message:</p>
  <pre><code>ValueError: Input 0 of layer &quot;max_pooling1d&quot; is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 4, 30, 32)
  
  </code></pre>
  <p>I don't understand what's going on--why is there an extra dimension coming out of the <code>Conv1D</code> layer? I mean, should the output of 1-D convolution not simply be
  <code>(BATCH_SIZE, WIDTH, 32)</code> (padding was set to <code>'same'</code>)?</p>
  <p>I apologize if this is addressed in the documentation, but I have been looking everywhere for an answer and I can't seem to fix this problem. I would really appreciate some help here.</p>
  <p>Thanks!</p>