This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model.save('traffic_classifier.h5') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.metrics import accuracy_score | |
| test = pd.read_csv("gtsrb-german-traffic-sign/Test.csv") | |
| test_labels = test['ClassId'].values | |
| test_img_path = "../input/gtsrb-german-traffic-sign" | |
| test_imgs = test['Path'].values | |
| test_data = [] | |
| test_labels = [] | |
| for img in test_imgs: | |
| im = Image.open(test_img_path + '/' + img) | |
| im = im.resize((30,30)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| plt.figure(0) | |
| plt.plot(history.history['accuracy'], label="Training accuracy") | |
| plt.plot(history.history['val_accuracy'], label="val accuracy") | |
| plt.title("Accuracy") | |
| plt.xlabel("epochs") | |
| plt.ylabel("accuracy") | |
| plt.legend() | |
| plt.figure(1) | |
| plt.plot(history.history['loss'], label="training loss") | |
| plt.plot(history.history['val_loss'], label="val loss") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| epochs = 15 | |
| history = model.fit(x_train, y_train, epochs=epochs, batch_size=64, validation_data=(x_test, y_test)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model = Sequential() | |
| model.add(Conv2D(filters=32, kernel_size=(5,5), activation="relu", input_shape=x_train.shape[1:])) | |
| model.add(Conv2D(filters=32, kernel_size=(5,5), activation="relu")) | |
| model.add(MaxPool2D(pool_size=(2,2))) | |
| model.add(Dropout(rate=0.25)) | |
| model.add(Conv2D(filters=64, kernel_size=(3,3), activation="relu")) | |
| model.add(Conv2D(filters=64, kernel_size=(3,3), activation="relu")) | |
| model.add(MaxPool2D(pool_size=(2,2))) | |
| model.add(Dropout(rate=0.25)) | |
| model.add(Flatten()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.model_selection import train_test_split | |
| x_train, x_test, y_train, y_test = train_test_split(data, labels, test_size=0.2, random_state=42) | |
| print("training shape: ",x_train.shape, y_train.shape) | |
| print("testing shape: ",x_test.shape, y_test.shape) | |
| y_train = to_categorical(y_train, 43) | |
| y_test = to_categorical(y_test, 43) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| path = "gtsrb-german-traffic-sign/Train/0/00000_00004_00029.png" | |
| img = Image.open(i0) | |
| img = img.resize((30, 30)) | |
| sr = np.array(img) | |
| plt.imshow(img) | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| imgs_path = "GTSRB_dataset/Train" | |
| data = [] | |
| labels = [] | |
| classes = 43 | |
| for i in range(classes): | |
| img_path = os.path.join(imgs_path, str(i)) #0–42 | |
| for img in os.listdir(img_path): | |
| im = Image.open(p + '/' + img) | |
| im = im.resize((30,30)) | |
| im = np.array(im) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| from PIL import Image | |
| import tensorflow as tf | |
| from keras.utils import to_categorical | |
| from keras.layers import Conv2D, Dense, Flatten, MaxPool2D, Dropout | |
NewerOlder