title: Neural network dimension mis-match
body: <p>I have a neural network setup for the MNIST digits dataset in Keras that looks like this:</p>
  
  <pre><code>input_size = features_train.shape[1]
  hidden_size = 200
  output_size = 9
  lambda_reg = 0.2
  learning_rate = 0.01
  num_epochs = 50
  batch_size = 30
  
  model = Sequential()
  model.add(Dense(input_size, hidden_size, W_regularizer=l2(lambda_reg), init='normal'))
  model.add(Activation('tanh'))
  model.add(Dropout(0.5))
  
  model.add(Dense(hidden_size, output_size, W_regularizer=l2(lambda_reg), init='normal'))
  model.add(Activation('softmax'))
  
  sgd = SGD(lr=learning_rate, decay=1e-6, momentum=0.9, nesterov=True)
  model.compile(loss='mean_squared_error', optimizer=sgd)
  
  history = History()
  
  model.fit(features_train, labels_train, batch_size=batch_size, nb_epoch=num_epochs, show_accuracy=True, verbose=2, validation_split=0.2, callbacks=[history])
  score = model.evaluate(features_train, labels_train, show_accuracy=True, verbose=1)
  predictions = model.predict(features_train)
  print('Test score:', score[0])
  print('Test accuracy:', score[1])
  </code></pre>
  
  <p>features_train is of shape (1000,784), labels_train is (1000,1), and both are numpy arrays. I want 784 input nodes, 200 hidden, and 9 output to classify the digits</p>
  
  <p>I keep getting an input dimension mismatch error:</p>
  
  <pre><code>Input dimension mis-match. (input[0].shape[1] = 9, input[1].shape[1] = 1)
  Apply node that caused the error: Elemwise{Sub}[(0, 0)](AdvancedSubtensor1.0, AdvancedSubtensor1.0)
  Inputs types: [TensorType(float32, matrix), TensorType(float32, matrix)]
  Inputs shapes: [(30L, 9L), (30L, 1L)]
  Inputs strides: [(36L, 4L), (4L, 4L)]
  Inputs values: ['not shown', 'not shown']
  </code></pre>
  
  <p>I'm trying to identify where my dimensions may be incorrect but I'm not seeing it. Can anyone see the problem?</p>