title: InvalidArgumentError: Incompatible shapes: [32,50,1] vs. [32,1] after adding TimeDistributed layer on Dense layer
body: <blockquote>
    <p>InvalidArgumentError: Incompatible shapes: [32,50,1] vs. [32,1]<br>
    [[{{node
    training_7/Adam/gradients/loss_8/time_distributed_5_loss/mean_squared_error/SquaredDifference_grad/BroadcastGradientArgs}}]]
    [Op:__inference_keras_scratch_graph_53470]</p>
  </blockquote>
  
  <p>I am using keras to practise.
  I run into this error after I change the last layer from Dense to TimeDsitributed(Dense)</p>
  
  <p>This is my code:</p>
  
  <pre><code>def generate_time_series(batch_size, n_steps):
      freq1, freq2, offsets1, offsets2 = np.random.rand(4, batch_size, 1)
      time = np.linspace(0, 1, n_steps)
      series = 0.5 * np.sin((time - offsets1) * (freq1 * 10 + 10))  #   wave 1
      series += 0.2 * np.sin((time - offsets2) * (freq2 * 20 + 20)) # + wave 2
      series += 0.1 * (np.random.rand(batch_size, n_steps) - 0.5)   # + noise
      return series[..., np.newaxis].astype(np.float32)
  
  n_steps = 50
  series = generate_time_series(10000, n_steps + 1)
  X_train, y_train = series[:7000, :n_steps], series[:7000, -1]
  X_valid, y_valid = series[7000:9000, :n_steps], series[7000:9000, -1]
  X_test, y_test = series[9000:, :n_steps], series[9000:, -1]
  
  model_0 = keras.models.Sequential([
      keras.layers.SimpleRNN(20,return_sequences=True,input_shape=[None,1]),
      keras.layers.SimpleRNN(20,return_sequences=True),
      keras.layers.TimeDistributed(keras.layers.Dense(1))
  ])
  
  model_0.compile(loss="mse",optimizer="adam")
  
  history_0 = model_0.fit(X_train, y_train, epochs=20,
                  validation_data=(X_valid, y_valid))
  </code></pre>