<jupyter_start><jupyter_text>Deep Learning Project - Lisbon traffic sign experiment  This notebook's purpose is to implement an experiment for classifying photographies of traffic signs taken in the city of Lisbon and to check how well the implemented traffic sign classification model performs on these images. Please adjust paths before running.<jupyter_code>import numpy as np
import pandas as pd
import keras
from keras.preprocessing.image import ImageDataGenerator
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
import os
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Predicting test set images<jupyter_code># Load a saved model
model = keras.models.load_model('model_final_without_weights_after_epoch_15')
test_dir = '/Users/philippmetzger/Documents/GitHub/Deep_Learning_Project_Group_10/Data/lisbon_traffic_signs'
#test_dir = '/Users/philippmetzger/Documents/GitHub/Deep_Learning_Project_Group_10/Data/Meta'<jupyter_output><empty_output><jupyter_text>Load ground truth data<jupyter_code>gt = pd.read_excel('/Users/philippmetzger/Documents/GitHub/Deep_Learning_Project_Group_10/Data/lisbon_traffic_signs/ground_truth.xlsx')
gt<jupyter_output><empty_output><jupyter_text>Normalization<jupyter_code>from tensorflow.keras.preprocessing.image import ImageDataGenerator

test_datagen = ImageDataGenerator(rescale=1./255)

test_generator = test_datagen.flow_from_directory(
    test_dir,
    target_size=(100,100),
    batch_size=20,
    shuffle=False,
    #class_mode=None,
    class_mode="categorical",
    color_mode="grayscale"
    )

x_test=np.concatenate([test_generator.next()[0] for i in range(test_generator.__len__())])

test_datagen = ImageDataGenerator(featurewise_center=True, featurewise_std_normalization=True)

test_datagen.fit(x_test)<jupyter_output>Found 86 images belonging to 1 classes.<jupyter_text>Re-Creating the generators with the normalized image data<jupyter_code>test_generator = test_datagen.flow_from_directory(
        test_dir,
        target_size=(100, 100),
        batch_size=20,
        shuffle=False,
        color_mode="grayscale",
        class_mode=None)

test_generator.reset()
pred_scores = model.predict_generator(test_generator)
class_pred = np.argmax(pred_scores, axis=-1)
target = list(gt['Target'])
index = list(gt['Index'])
df = pd.DataFrame(data={'index': index, 'target':target, 'prediction':class_pred})
df
i = 0

slice = [range(0,40), range(40,80), range(80,86)]

df.iloc[slice[i],:]
i = 1

df.iloc[slice[i],:]
i = 2

df.iloc[slice[i],:]
bool_ = (class_pred == target)
bool_
sum(bool_) / len(bool_)
sum(bool_)
len(bool_)
df.to_excel('Lisbon_traffic_signs_results.xlsx')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10143329658213891, 'fraction_numerical': 0.01727306137449467, 'mean_word_length': 6.889855072463768, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '172129', 'license': 'MIT', 'n_tokens_mistral': 967, 'n_tokens_neox': 908, 'n_words': 174, 'path': '2021-04-02_Lisbon_traffic_signs_experiment_PM.ipynb', 'repo_name': 'ph1001/Deep_Learning_Project_Group_10', 'size': '2721'}