title: ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (1188, 12, 2)
body: <p>So when I was trying to build a lstm network, every time it tells me that &quot;ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (1188, 12, 2)&quot;.
  My dataset has more than 1000 samples, 2 features, and I set the time_step as 12.
  I have already reshaped my dataset to 3-dim, however, the error tells that my last layer-Dense layer(I use this layer as output) expected a 2-dimention array.What shell I do?
  My codes are as follows:</p>
  <pre><code>    # read train set
  readColsPro = (7, 20)
  filename = 'train_set.txt'
  xProTrain_1 = readCsv.csvMat(filename, 1, cols=readColsPro, rows=[0, 1200])
  yProTrain_1 = readCsv.csvMat(filename, 1, cols=readColsPro, rows=[1, 1201])
  
  xProTrain_1 = xProTrain_1.reshape(xProTrain_1.shape[0], 2)
  yProTrain_1 = yProTrain_1.reshape(yProTrain_1.shape[0], 2)
  
  # erase 'nan' datas
  for i in xProTrain_1:
      if np.isnan(i[1]):
          i[1] = 0
  
  for i in yProTrain_1:
      if np.isnan(i[1]):
          i[1] = 0
  
  # read test set
  xProTest_1 = readCsv.csvMat(filename, 1, cols=readColsPro, rows=[1, 1201])
  yProTest_1 = readCsv.csvMat(filename, 1, cols=readColsPro, rows=[2, 1202])
  
  xProTest_1 = np.reshape(xProTest_1, (xProTest_1.shape[0], xProTest_1.shape[1]))
  yProTest_1 = np.reshape(yProTest_1, (yProTest_1.shape[0], yProTest_1.shape[1]))
  
  for i in xProTest_1:
      if np.isnan(i[1]):
          i[1] = 0
  
  for i in yProTest_1:
      if np.isnan(i[1]):
          i[1] = 0
  
  # parameters
  timeStepPro = 12
  epoch = 24
  batch_size = 24
  trainNumPro = xProTrain_1.shape[0]
  testNumPro = yProTrain_1.shape[0]
  
  # reshape datas to 3D
  xProTrain_2 = []
  for i in range(timeStepPro, trainNumPro):
      xProTrain_2.append(xProTrain_1[i - timeStepPro:i]) 
  xProTrain_2 = np.array(xProTrain_2)
  
  yProTrain_2 = []
  for i in range(timeStepPro, trainNumPro):
      yProTrain_2.append(yProTrain_1[i - timeStepPro:i])
  yProTrain_2 = np.array(yProTrain_2)
  print(xProTrain_2.shape)
  print(yProTrain_2.shape)
  
  # reshape datas to 3D
  xProTest_2 = []
  for i in range(timeStepPro, trainNumPro):
      xProTest_2.append(xProTest_1[i - timeStepPro:i])   
  xProTest_2 = np.array(xProTest_2)
  
  yProTest_2 = []
  for i in range(timeStepPro, trainNumPro):
      yProTest_2.append(yProTest_1[i - timeStepPro:i])   
  yProTest_2 = np.array(yProTest_2)
  
  
  # define network
  modelA = Sequential()
  modelA.add(LSTM(units=64, return_sequences=True,
                  input_shape=[xProTrain_2.shape[1], 2]))
  modelA.add(BatchNormalization())
  
  
  modelA.add(LSTM(units=128, return_sequences=True))
  
  modelA.add(LSTM(units=128, return_sequences=True))
  modelA.add(LSTM(units=256, return_sequences=True))
  modelA.add(LSTM(units=64, return_sequences=False))
  
  
  modelA.add(Dense(units=2, activation='relu'))
  
  modelA.compile(optimizer='adam',
                loss='mean_squared_error',
                metrics=['accuracy'])
  
  modelA.fit(x=xProTrain_2, y=yProTrain_2, epochs=epoch, batch_size=batch_size)
  </code></pre>
  <p>Error message are as follows:</p>
  <pre><code>ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (1188, 12, 2)
  </code></pre>