<jupyter_start><jupyter_text>Data & image transformations pipeline inspectionThis notebook is ment to explore data set and to check image transformation pipeline<jupyter_code>%load_ext autoreload
%autoreload 2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import cv2
from keras.preprocessing.image import img_to_array, load_img

%matplotlib inline

import train_model_lib as tm_lib<jupyter_output><empty_output><jupyter_text>Data set confsData from Udacity<jupyter_code>UDACITY_TRAINING_DATA_DIR = "./udacity_data/"
UDACITY_TRAINING_DATA_CSV = "driving_log.csv"<jupyter_output><empty_output><jupyter_text>Load training data<jupyter_code>recorded_data_df = tm_lib.load_data_from_file(UDACITY_TRAINING_DATA_DIR, UDACITY_TRAINING_DATA_CSV)<jupyter_output><empty_output><jupyter_text>Explore data from CSV file<jupyter_code>recorded_data_df.describe(include='all')<jupyter_output><empty_output><jupyter_text>Data histogramData are heavily unbalanced! Most data refers to straight driving and there are more left turns in train track than right turns. We need to tackle that.<jupyter_code>plt.figure()
recorded_data_df.hist(column='steering')<jupyter_output><empty_output><jupyter_text>Explore imagesExtract 3 random rows from data and print images<jupyter_code>plt.rcParams['figure.figsize'] = (12, 6)

samples = recorded_data_df.sample(3)

k = 0
for row in samples.iterrows():
    index, data = row
    
    print("Sample image number {} angle: {}".format(index,data["steering"]))  
    
    # Left
    plt.subplot(3, 3, k+1)
    img_l = mpimg.imread(data['left'])
    plt.imshow(img_l, aspect="auto")
    plt.axis('off')
    
    # Center
    plt.subplot(3, 3, k+2)
    img_c = mpimg.imread(data['center'])
    plt.imshow(img_c, aspect="auto")
    plt.axis('off')

    # Right
    plt.subplot(3, 3, k+3)
    img_r = mpimg.imread(data['right'])
    plt.imshow(img_r, aspect="auto")
    plt.axis('off')
    
    plt.show()
    
    k = k+3<jupyter_output><empty_output><jupyter_text>Test data augmentation function  Data augmentation - Choose Random Camera<jupyter_code>s_rows = recorded_data_df.sample(2)
for index, sr in s_rows.iterrows():    
    s_img, s_steering = tm_lib.camera_chooser(sr, True)<jupyter_output><empty_output><jupyter_text>Data augmentation - Flip Images<jupyter_code>s_rows = recorded_data_df.sample(5)
for index, sr in s_rows.iterrows():    
    s_img = load_img(sr["left"].strip())
    s_img = img_to_array(s_img)
    s_img, s_steering = tm_lib.horizontal_flip(s_img, sr["steering"], True)<jupyter_output><empty_output><jupyter_text>Data augmentation - Change Brightness<jupyter_code>plt.rcParams['figure.figsize'] = (12, 6)
s_rows = recorded_data_df.sample(3)
j = 0
for index, sr in s_rows.iterrows():    
    print("Change brightness of image number {} angle: {}".format(index,data["steering"]))  
    
    # Left
    plt.subplot(3, 2, j+1)
    img_l = mpimg.imread(data['left'])
    plt.imshow(img_l, aspect="auto")
    plt.axis('off')
    
    plt.subplot(3, 2, j+2)
    img_l_brightness = tm_lib.change_image_brightness(img_l,True)
    plt.imshow(img_l_brightness, aspect="auto")
    plt.axis('off')
    
    plt.show()
    
    j = j + 2<jupyter_output><empty_output><jupyter_text>Test image pipeline functions  Cropped imagesRemoved first 50 rows for the orizon and last 30 rows for the car bonnet<jupyter_code>k = 0
for row in samples.iterrows():
    index, data = row
    
    print("Cropped sample image number {} angle: {}".format(index,data["steering"]))  
    
    # Left
    plt.subplot(3, 2, k+1)
    #img_l_cropped = vertical_crop(mpimg.imread(data['left'].replace(" ","")))
    img_l = mpimg.imread(data['left'])
    plt.imshow(img_l, aspect="auto")
    plt.axis('off')
    
    plt.subplot(3, 2, k+2)
    img_l_cropped = tm_lib.vertical_crop_sim(img_l)
    plt.imshow(img_l_cropped, aspect="auto")
    plt.axis('off')
    
    plt.show()
    
    k = k+2<jupyter_output><empty_output><jupyter_text>Cropped and resized imageRemoved first 50 rows for the orizon and last 30 rows for the car bonnet.Reshape images to 96x96<jupyter_code>k = 0
for row in samples.iterrows():
    index, data = row
    
    print("Cropped and resized 96x96 sample image number {} angle: {}".format(index,data["steering"]))  
    
    # Left
    plt.subplot(3, 2, k+1)
    img_l = mpimg.imread(data['left'])
    plt.imshow(img_l, aspect="auto")
    plt.axis('off')
    
    plt.subplot(3, 2, k+2)
    img_l_cropped = tm_lib.vertical_crop(img_l)
    img_l_resized = tm_lib.resize_to_target_size(img_l_cropped)
    plt.imshow(img_l_resized, aspect="auto")
    plt.axis('off')
    
    plt.show()
    
    k = k+2<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12387676508344031, 'fraction_numerical': 0.013692768506632435, 'mean_word_length': 4.5588585017835905, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '249041', 'license': 'MIT', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1737, 'n_words': 334, 'path': 'data_and_img_pipeline_inspection.ipynb', 'repo_name': 'AndreaIncertiDelmonte/-CarND-Behavioral-Cloning-Project', 'size': '4674'}