#Import libaries and datasets import matplotlib.pyplot as plt import numpy as np import tensorflow as tf import pandas as pd import seaborn as sns import pickle import random import os import numpy as np from keras.utils import np_utils with open(os.path.join("test", "test.p"), mode='rb') as validation_data: valid = pickle.load(validation_data) X_valid, y_valid = valid['features'], valid['labels'] from sklearn.utils import shuffle X_valid, y_valid = shuffle(X_valid, y_valid) # Normalize image to [0, 1] X_valid_norm = X_valid / 255 #TakeOnePicture (Klasse 0-19) filtered_indices = [i for i, label in enumerate(y_valid) if label >= 0 and label <= 19] indice = random.choice(filtered_indices) X_valid_subset = X_valid[indice][np.newaxis, ...] y_valid_subset = y_valid[indice][np.newaxis, ...] num_classes = 20 # Anzahl der Straßenschilder-Klassen y_valid_subset = np_utils.to_categorical(y_valid_subset, num_classes) #ownModel #convolutionalNeuralNetwork #fullyConnectedNeuralNetwork model = tf.keras.models.load_model('saved_model/fullyConnectedNeuralNetwork.h5') score = model.evaluate(X_valid_subset, y_valid_subset) print('Test Accuracy: {}'.format(score[1])) from sklearn.metrics import confusion_matrix predicted_classes = np.argmax(model.predict(X_valid_subset), axis=-1) y_true = np.argmax(y_valid_subset, axis=-1) cm = confusion_matrix(y_true, predicted_classes) plt.figure(figsize = (25, 25)) sns.heatmap(cm, annot = True) plt.show()