title: ValueError: Error when checking target: expected dense_1 to have shape (16, 1, 2) but got array with shape (2, 1, 1)
body: <p>I'm very new to using machine learning and keras. This is my first CNN model. I built a model to classify the sounds into the UrbanSound8kDataset. When I run the model on a small dummy set, I keep getting the following error: </p>
  
  <pre><code>ValueError: Error when checking target: expected dense_1 to have shape (16, 1, 2) but got array with shape (2, 1, 1)
  </code></pre>
  
  <p>I looked at other posts with similar issues and tried changing the model loss to sparse_categorical_crossentropy rather than categorical_crossentropy. I also added model.flatten() before the first dense layer. Unfortunately, none of that resolved my error. </p>
  
  <p>Here is the relevant code for my model: </p>
  
  <pre><code>num_labels = yy.shape[1]
  filter_size = 2
  num_rows = 1
  num_columns = 1
  num_channels = 1    
  
  x_train = x_train.reshape(x_train.shape[0], num_rows, num_columns, num_channels)
  y_train = y_train.reshape(y_train.shape[0], 2, num_columns, num_channels)
  x_test = x_test.reshape(x_test.shape[0], 1, num_columns, num_channels)
  y_test = y_test.reshape(y_test.shape[0], 2, num_columns, num_channels)
  
  model = Sequential()
  model.add(Conv2D(filters=16, kernel_size=2, input_shape=(num_rows,
  
      num_columns, num_channels), activation='relu', data_format='channels_first',   padding="same"))
  model.add(MaxPooling2D(pool_size=1))
  model.add(Dropout(0.2))
  
  model.add(Conv2D(filters=32, kernel_size=1, activation='relu'))
  model.add(MaxPooling2D(pool_size=1))
  model.add(Dropout(0.2))
  
  model.add(Conv2D(filters=64, kernel_size=1, activation='relu'))
  model.add(MaxPooling2D(pool_size=1))
  model.add(Dropout(0.2))
  
  model.add(Conv2D(filters=64, kernel_size=1, activation='relu'))
  model.add(MaxPooling2D(pool_size=1))
  model.add(Dropout(0.2))
  
  #Flatten layer here:
  
  model.add(Dense(num_labels, activation='softmax'))
  model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')
  
  model.summary()
  
  
  num_epochs = 100
  num_batch_size = 132
  
  start = datetime.now()
  
  
  
  model.fit(x_train, y_train, batch_size=num_batch_size, epochs=num_epochs, validation_data=(x_test, y_test), verbose=1)
  </code></pre>
  
  <p>Here is the model summary: </p>
  
  <pre><code>Layer (type)                 Output Shape              Param #   
  =================================================================
  conv2d_1 (Conv2D)            (None, 16, 1, 1)          80        
  _________________________________________________________________
  max_pooling2d_1 (MaxPooling2 (None, 16, 1, 1)          0         
  _________________________________________________________________
  dropout_1 (Dropout)          (None, 16, 1, 1)          0         
  _________________________________________________________________
  conv2d_2 (Conv2D)            (None, 16, 1, 32)         64        
  _________________________________________________________________
  max_pooling2d_2 (MaxPooling2 (None, 16, 1, 32)         0         
  _________________________________________________________________
  dropout_2 (Dropout)          (None, 16, 1, 32)         0         
  _________________________________________________________________
  conv2d_3 (Conv2D)            (None, 16, 1, 64)         2112      
  _________________________________________________________________
  max_pooling2d_3 (MaxPooling2 (None, 16, 1, 64)         0         
  _________________________________________________________________
  dropout_3 (Dropout)          (None, 16, 1, 64)         0         
  _________________________________________________________________
  conv2d_4 (Conv2D)            (None, 16, 1, 64)         4160      
  _________________________________________________________________
  max_pooling2d_4 (MaxPooling2 (None, 16, 1, 64)         0         
  _________________________________________________________________
  dropout_4 (Dropout)          (None, 16, 1, 64)         0         
  _________________________________________________________________
  dense_1 (Dense)              (None, 16, 1, 2)          130       
  =================================================================
  Total params: 6,546
  Trainable params: 6,546
  Non-trainable params: 0
  ____________________________
  </code></pre>
  
  <p>The error occurs in the last line of the code I concluded, the model.fit line. </p>
  
  <p>Please let me know if I need to include more code. This is only my second time posting here, so I was not sure how much code to include. </p>
  
  <p>Thank you very much! </p>