i want to evaluate the accuracy of the model but also implement the confusion matrix of all 10 classes of the cifar10 dataset, and i got this error message "Error when checking input: expected conv2d_9_input to have 4 dimensions, but got array with shape (10000, 10)"
def run_test_harness():
# load dataset
trainX, trainY, testX, testY = load_dataset()
# prepare pixel data
trainX, testX = prep_pixels(trainX, testX)
# define model
model = define_model()
# fit model
history = model.fit(trainX, trainY, epochs=100, batch_size=64, validation_data=(testX, testY), verbose=0)
# fig
y_pred=model.predict_classes(testY)
con_mat = tf.math.confusion_matrix(labels=y_true, predictions=y_pred).numpy()
con_mat_norm = np.around(con_mat.astype('float') / con_mat.sum(axis=1)[:, np.newaxis], decimals=2)
con_mat_df = pd.DataFrame(con_mat_norm, index = classes, columns = classes)
figure = plt.figure(figsize=(8, 8))
sns.heatmap(con_mat_df, annot=True,cmap=plt.cm.Blues)
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
accuracy, precision, recall = model.evaluate(testX, testY, verbose=0)
print ("recall")
print ('> %.3f' % (recall * 100.0))
print ("accuracy")
print('> %.3f' % (accuracy * 100.0))
print ("precision")
print('> %.3f' % (precision * 100.0))
# learning curves # end
accuracy, precision, recall = model.evaluate(testX, testY, verbose=0)
print ("recall")
print ('> %.3f' % (recall * 100.0))
print ("accuracy")
print('> %.3f' % (accuracy * 100.0))
print ("precision")
print('> %.3f' % (precision * 100.0))
this is the implementation on the Cnn
def define_model():
model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same', input_shape=(32, 32, 3)))
model.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same'))
model.add(MaxPooling2D((2, 2)))
model.add(Flatten())
model.add(Dense(128, activation='relu', kernel_initializer='he_uniform'))
model.add(Dense(10, activation='softmax'))
# compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy',precision_m, recall_m])
return model