# 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()))

(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()

epochs = 50
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))
$$$$
`
• Your last layer has 10 "classes". How many classes do your data have? I guess 4? In this case you need to change 10 to 4 – Peter Mar 10 '20 at 13:29
• Tried that, didn't work. I do also think that the cifar10 set has 10 classes. – SoMax Mar 10 '20 at 17:20