This file contains 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
monitor = tf.keras.callbacks.EarlyStopping(monitor = 'val_loss',patience = 8,restore_best_weights = True, min_delta = 0.01) | |
history = model_regularized.fit_generator(train_generator, validation_data=validation_generator,steps_per_epoch=(len(train_split_images) / 32),epochs = 52,verbose=1,callbacks=[monitor]) # 32 = batch size | |
# Visualization code begins | |
training_loss = history.history['loss'] | |
validation_loss = history.history['val_loss'] | |
# Create count of the number of epochs |
This file contains 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
monitor = tf.keras.callbacks.EarlyStopping(monitor = 'val_loss',patience = 8,restore_best_weights = True, min_delta = 0.01) | |
# Using the Callback | |
history = model_regularized.fit_generator(train_generator, validation_data=validation_generator,steps_per_epoch=(len(train_split_images) / 32),epochs = 52,verbose=1,callbacks=[monitor]) |
This file contains 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
training_datagen = tf.keras.preprocessing.image.ImageDataGenerator(zoom_range=0.3,width_shift_range=0.15,height_shift_range=0.15,shear_range=0.2,fill_mode='nearest') | |
validation_datagen = tf.keras.preprocessing.image.ImageDataGenerator() | |
# try and visualize your images | |
sign_generator = training_datagen.flow(train_images128[110:111], training_labels[110:111],batch_size=1) | |
sign = [next(sign_generator) for i in range(0,10)] | |
fig, ax = plt.subplots(1,10, figsize=(16, 6)) | |
print('Labels:', [item[1][0] for item in sign]) | |
l = [ax[i].imshow(sign[i][0][0]) for i in range(0,10)] |
This file contains 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
def print_random_images(images, labels, number_of_images_to_display, color_map='hsv'): | |
if number_of_images_to_display % 4 == 0: | |
num_rows = number_of_images_to_display / 4 | |
else: | |
num_rows = int(number_of_images_to_display / 4) + 1 | |
random_indices = [np.random.randint(0, images.shape[0]) for n in range(number_of_images_to_display)] | |
# print(random_indices) | |
for counter in range(number_of_images_to_display): | |
index = random_indices[counter] | |
plt.subplot(num_rows, 4, counter + 1) |
This file contains 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
{ | |
0: 'Warning for a bad road surface', | |
1: 'Warning for a speed bump', | |
2: 'Warning for a slippery road surface', | |
3: 'Warning for a curve to the left', | |
4: 'Warning for a curve to the right', | |
5: 'Warning for a double curve, first left then right', # Merge Classes 5 & 6 later | |
6: 'Warning for a double curve, first left then right', | |
7: 'Watch out for children ahead', | |
8: 'Watch out for cyclists', |
This file contains 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
def load_images(data_directory): | |
# lists to store Images and labels | |
images = [] | |
labels = [] | |
log_index = 0 | |
# get list of all directories present in the data_directory path | |
directories = [dir for dir in os.listdir(data_directory) | |
if os.path.isdir(os.path.join(data_directory,dir))] # to make sure that we include only directories and not any files present in the folder | |
print(len(directories)) |
This file contains 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
print(os.getcwd()) # returns your current working directory | |
DATASET_PATH = """/My Drive/Ml Datasets/Belgian Img Traffic Signs Datasets""" # Insert Data Path here relative to current working directory | |
os.chdir(DATASET_PATH) | |
print(os.getcwd()) # make sure you're in the directory containing dataset zipfiles | |
# Extracting Training Data | |
with zipfile.ZipFile('BelgiumTSC_Training.zip', 'r') as zipObj: | |
zipObj.extractall('TrainingData') | |
# Extracting Testing Data | |
with zipfile.ZipFile('BelgiumTSC_Testing.zip', 'r') as zipObj: | |
zipObj.extractall('TestingData') |