An error coming out when fitting a model with keras I am trying to build a model using kerras but for some reason I receive a ValueError: Error when checking target: expected activation_5 to have 4 dimensions, but got array with shape (50000, 10) error. I have recently changed the model parameters, so I think it has something to do with that, but I cannot understand what exactly. Before I changed the model everything worked

Here is the code

from keras.models import Sequential, load_model
from keras.layers import Dense, Dropout, Flatten, BatchNormalization, Activation
from keras.layers.convolutional import Conv2D, MaxPooling2D
from keras.constraints import maxnorm
from keras.utils import np_utils
from keras.datasets import cifar10
from tensorflow.python.keras.callbacks import TensorBoard
from time import time
seed = 21
tensorboard = TensorBoard(log_dir="logs/{}".format(time()))


#loading and preprocessing training and testing data
(train_data, train_labels), (test_data, test_labels) = cifar10.load_data()
train_data = train_data.astype('float32')
test_data = test_data.astype('float32')
train_data = train_data / 255.0
test_data = test_data / 255.0
train_labels = np_utils.to_categorical(train_labels)
test_labels = np_utils.to_categorical(test_labels)
class_num = test_labels.shape[1]

#building model
model = Sequential()
model.add(Conv2D(32, (5,5), input_shape=(32,32,3), padding ='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='same'))
model.add(Conv2D(32, (5,5), padding ='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='same'))
model.add(Conv2D(64, (5,5), padding ='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='same'))
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dense(10))
model.add(Activation('softmax'))

epochs = 50
optimizer = 'adam'
model.summary()
model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=['accuracy'])

numpy.random.seed(seed)
model.fit(train_data, train_labels, validation_data=(test_data, test_labels), epochs=epochs, batch_size=64, callbacks=[tensorboard])
scores = model.evaluate(test_data, test_labels, verbose=0)
print("Accuracy: %.2f%%" % (scores[1]*100))
```
You are missing a flatten() layer between your last MaxPooling2D and Dense layer.