In [1]:
#importing useful packages
from matplotlib import pyplot as plt
import random
import numpy as np
import tensorflow as tf
import tqdm
import time
import os.path
import pickle
from helper_Functions import *
from preprocess_augmentation import *
from model_calls import *
%matplotlib inline
from model_architecture import *
In [2]:
#Fill this in based on where you saved the training and testing data
testing_file = "traffic-signs-data/test.p"
valid_file = "traffic-signs-data/valid.p"
preProcFile = "traffic-signs-data/preProcData_pickle.p"
with open(testing_file, mode='rb') as f:
test = pickle.load(f)
with open(valid_file, mode='rb') as f:
valid = pickle.load(f)
X_test, y_test = test['features'], test['labels']
X_valid, y_valid = valid['features'], valid['labels']
if not os.path.isfile(preProcFile):
# Load training data
training_file = "traffic-signs-data/traina.p"
with open(training_file, mode='rb') as f:
train = pickle.load(f)
X_Train, y_Train = train['features'], train['labels']
X_train, y_train = pre_process_data(X_Train, y_Train, 3)
#Save pre-processed data
dist_pickle = {}
dist_pickle["X_Data"] = X_train
dist_pickle["y_Data"] = y_train
pickle.dump( dist_pickle, open( preProcFile, "wb" ))
else:
dist_pickle = pickle.load( open(preProcFile, "rb") )
X_train = dist_pickle["X_Data"]
y_train = dist_pickle["y_Data"]
In [3]:
#Shuffle training data
from sklearn.utils import shuffle
X_train, X_valid, y_train, y_valid = train_test_split(X_train, y_train, test_size=0.20, random_state=42)
assert(len(X_train) == len(y_train))
assert(len(X_valid) == len(y_valid))
assert(len(X_test) == len(y_test))
In [4]:
dataSetInfo(X_train, y_train, X_test, y_test, X_valid, y_valid)
visualize_augmentation(X_train)
In [5]:
#training model
saver = training_model(X_train, y_train, X_valid, y_valid, rate = 0.001)
In [6]:
import tensorflow as tf
save_file = './saved_models/model.ckpt'
saver = tf.train.import_meta_graph(save_file + '.meta')
with tf.Session() as sess:
saver.restore(sess, save_file)
test_accuracy = evaluate(X_test, y_test)
print("Test Accuracy = {:.3f}".format(test_accuracy))
In [7]:
import glob
#import images
imgLabes = []
images = []
for img in glob.glob("Test_Images/*.jpg"):
images.append(mpimg.imread(img))
imgLabes.append(img)
predict(images, imgLabes, save_file, y_train, X_train)
In [ ]: