title: How can I solve this error logits and labels must have the same first dimension
body: <p>this is my first time working with neural networks. After fitting my code I had this error: </p>
  
  <p><strong>logits and labels must have the same first dimension, got logits shape [4,4096] and labels shape [16384]
       [[node loss/activation_27_loss/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits 
  (defined at C:\Users\admin\Miniconda3\lib\site-packages\tensorflow_core\python\framework\ops.py:1751) ]] [Op:__inference_distributed_function_8265]
  Function call stack:
  distributed_function</strong></p>
  
  <p>Can you help please why I get this error, here is my code:</p>
  
  <pre><code>batch_size = 5
  learning_rate = 0.8
  no_classes = 1
  no_epochs = 3
  validation_split = 0.2
  verbosity = 0
  import tensorflow as tf
  import tensorflow.python.keras 
  from tensorflow.python.keras.models import Sequential
  from tensorflow.python.keras.layers import Input
  from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
  from tensorflow.python.keras.layers import Dense, Dropout, Activation, Flatten
  from tensorflow.python.keras.layers import Conv2D, MaxPooling2D
  from os import listdir
  from os.path import isfile, join
  import pickle
  from tensorflow.python.keras.utils import to_categorical
  from tensorflow.python.keras import backend as K
  from tensorflow.python.keras.layers.normalization import BatchNormalization
  
  
  pickle_in = open("X.pickle","rb")
  X= pickle.load(pickle_in)
  
  pickle_in = open("Y.pickle","rb")
  Y = pickle.load(pickle_in)
  
  # Y=Y/255
  
  img_rows=img_cols=64
  
  if K.image_data_format()== 'channels_first':
      X = np.array(X).reshape(np.array(X).shape[0], 1, img_rows, img_cols)
      Y= np.array(Y).reshape(np.array(Y).shape[0], 1, img_rows, img_cols)
      print(X.shape)
      print(Y.shape)
      input_shape = (1, img_rows, img_cols)
  else:
      X = np.array(X).reshape(np.array(X).shape[0], img_rows, img_cols, 1)
      Y = np.array(Y).reshape(np.array(Y).shape[0], img_rows, img_cols, 1)
      input_shape = (img_rows, img_cols,1)    
  
  print(X.shape)
  print(Y.shape)
  print(input_shape)
  
  model = Sequential()
  model.add(Conv2D(64, (3, 3),input_shape=input_shape,padding="same"))
  model.add(Activation('relu'))
  
  model.add(Conv2D(64, (3, 3)))
  model.add(Activation('relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  
  model.add(Conv2D(64, (3, 3)))
  model.add(Activation('relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  
  model.add(Flatten())
  model.add(Dense(64*64))
  model.add(Activation('relu'))
  
  model.summary()
  
  model.compile(loss=tensorflow.keras.losses.sparse_categorical_crossentropy,
                optimizer=tensorflow.keras.optimizers.Adam(),
                metrics=['accuracy'])
  
  model.fit(X,Y,
            batch_size=5,
            epochs=no_epochs,
            verbose=verbosity,
            validation_split=validation_split)
  score = model.evaluate(X,Y, batch_size=5)
  </code></pre>
  
  <p>I don't know what to do I've been struggling with this error </p>