My capstone project for Udacity's Machine Learning Nanodegree

Overview

MLND-Capstone

My capstone project for Udacity's Machine Learning Nanodegree

Lane Detection with Deep Learning

In this project, I use a deep learning-based approach to improve upon lane detection. My final model uses a fully convolutional neural network to output an image of a predicted lane.

Please see my final Capstone Project Report here.

Also, see my original capstone proposal here.

Lastly, check out the wiki page in this repository to see some more of my steps along the way. The separate "early_steps" branch contains earlier code for previous versions of the neural network as well as files that can extract data for training and perform some automatic labeling.

See an early version of the model detecting lane lines with perspective transformed images here. An early version of my model trained without perspective transformed images, i.e. regular road images, can be seen here!

Lastly, with the finalized fully convolutional model, there are a couple additional videos I made. The first, which is the same video from the above two, has between 10-20% of the frames fed into the mode, as can be seen here. Additionally, a video made from the Challenge Video from Udacity's Advanced Lane Lines project in the SDCND, where the neural network had never seen the video before, can be seen here. The model performs fairly robustly on the never-before-seen video, with the only hitch due to the large light difference as it goes under the overpass.

An additional video can be seen at this Dropbox link.

Dataset

For fully convolutional network

You can download the full training set of images I used here and the full set of 'labels' (which are just the 'G' channel from an RGB image of a re-drawn lane with an extra dimension added to make use in Keras easier) here (157 MB).

Images with coefficient labels

If you just want the original training images with no flips or rotations (downsized to 80x160x3) you can find them here. You can also find the related coefficient labels (i.e. not the drawn lane labels, but the cofficients for a polynomial line) here.

Software Requirements

You can use this conda environment file. In the command line, use conda env create -f lane_environment.yml and then source activate lane_environment (or just activate with the environment name on Windows) to use the environment.

Key Files

Although I have included many of the python files I created to help process my images and various prototype neural networks in the "early_steps" branch, the key files are:

  • fully_conv_NN.py - Assuming you have downloaded the training images and labels above, this is the fully convolutional neural network to train using that data.
  • full_CNN_model.h5 - These are the final outputs from the above CNN. Note that if you train the file above the originals here will be overwritten! These get fed into the below.
  • draw_detected_lanes.py - Using the trained model and an input video, this predicts the lane, averages across 5 frames, and returns the original video with predicted lane lines drawn onto it. Note that it is currently set up to use the basic video from Udacity's SDCND Advanced Lane Lines project here, but the code at the end can be changed to accept different input videos.

Training Image Statistics

  • 21,054 total images gathered from 12 videos (a mix of different times of day, weather, traffic, and road curvatures)
  • 17.4% were clear night driving, 16.4% were rainy morning driving, and 66.2% were cloudy afternoon driving
  • 26.5% were straight or mostly straight roads, 30.2% were a mix or moderate curves, and 43.3% were very curvy roads
  • The roads also contain difficult areas such as construction and intersections
  • 14,235 of the total that were usable of those gathered (mainly due to blurriness, hidden lines, etc.)
  • 1,420 total images originally extracted from those to account for time series (1 in every 10)
  • 227 of the 1,420 unusable due to the limits of the CV-based model used to label (down from 446 due to various improvements made to the original model) for a total of 1,193 images
  • Another 568 images (of 1,636 pulled in) gathered from more curvy lines to assist in gaining a wider distribution of labels (1 in every 5 from the more curved-lane videos; from 8,187 frames)
  • In total, 1,761 original images
  • I pulled in the easier project video from Udacity's Advanced Lane Lines project (to help the model learn an additional camera's distortion) - of 1,252 frames, I used 1 in 5 for 250 total, 217 of which were usable for training
  • A total of 1,978 actual images used between my collections and the one Udacity video
  • After checking histograms for each coefficient of each label for distribution, I created an additional 4,404 images using small rotations of the images outside the very center of the original distribution of images. This was done in three rounds of slowly moving outward from the center of the data (so those further out from the center of the distribution were done multiple times). 6,382 images existed at this point.
  • Finally, I added horizontal flips of each and every road image and its corresponding label, which doubled the total images. All in all, there were a total of 12,764 images for training.
Comments
  • No matching ActionLib Distribution

    No matching ActionLib Distribution

    When I run conda env create -f lane_environment.yml I get the following error: Collecting actionlib==1.11.7 Could not find a version that satisfies the requirement actionlib==1.11.7

    If actionlib is required for this, can you maybe update the environment file with another compatible version?

    Thanks

    opened by corlinp 6
  • Return offset

    Return offset

    Hi Michael. Thank you so much for this intensive work! I wonder in your final method, is there any way that could calculate the offset of the car from lanes, comparing with the method that uses perspective transformation?

    opened by yanzhang0417 4
  • Any Idea for the use DC motors or etc for that?

    Any Idea for the use DC motors or etc for that?

    Hello. First, cong. Awesome project, I was wanting to learn deep learning with making lane detection. I can learn now but how can I control the motors sir? How we can calculate the lanes? I have idea with using Tan90=Sin90/Cos90 like that.

    Have a nice day!

    opened by mustafamerttunali 4
  • Dataset and Labels

    Dataset and Labels

    Hi, Iam facing following issues:

    1.I am not able to open the full_CNN_train.p and CNN_label.p in Matlab. 2.How can I train and label my own dataset using this code?

    Please can you guide where I am doing wrong

    opened by mrinaliniP 3
  • Cannot find scaler.p

    Cannot find scaler.p

    I tried to run this lane_lines.py and got the following error:

    Traceback (most recent call last): File "lane_lines.py", line 26, in label_scaler = pickle.load(open( "scaler.p", "rb" )) FileNotFoundError: [Errno 2] No such file or directory: 'scaler.p'

    opened by prodigystd 3
  • Where is the file: full_CNN_train.p ? File Not Found error. Thanks:)

    Where is the file: full_CNN_train.p ? File Not Found error. Thanks:)

    Dear @mvirgo , Thanks for creating such an amazing project! I am sure that I will learn from it. For now, I am using this as a benchmark for my new PC and I was wandering where the file 'Full_CNN_train.p' is as it is giving me a File Not Found error.

    I simply cloned the github repo. by .p, do you mean .py? Many thanks 👍

    Clement Secondary School Student :)

    opened by tongclement 2
  • ValueError: operands could not be broadcast together with shapes

    ValueError: operands could not be broadcast together with shapes

    when i run the check_labels.py in line 36 the issue is ValueError: operands could not be broadcast together with shapes and one more question what is list index out of range. Can you help me pls?

    opened by raflialhamdi 2
  • why I don't get the same output with the same input and same model?

    why I don't get the same output with the same input and same model?

    I use this code to get output file which is a road with detected path according to detected lines:

    from os.path import splitext, basename

    import numpy as np import cv2

    from moviepy.editor import VideoFileClip from keras.models import load_model

    model = load_model('full_CNN_model.h5')

    class Lanes(): def init(self): self.recent_fit = [] self.avg_fit = []

    lanes = Lanes() vid_in = "line_1.mp4" vid_output = 'line_1_out.mp4'

    video_capture = cv2.VideoCapture() fourcc = cv2.VideoWriter_fourcc(*'XVID') name, extension = splitext(basename(vid_in)) output = name + '.avi'

    if video_capture.open(vid_in): property_id = int(cv2.CAP_PROP_FRAME_COUNT) total_frames = int(cv2.VideoCapture.get(video_capture, property_id)) frame_no = 1 width, height = int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH)),
    int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) fps = video_capture.get(cv2.CAP_PROP_FPS)

    video_writer = cv2.VideoWriter(output, fourcc, fps, (width, height))
    while video_capture.isOpened():
        ret, frame = video_capture.read()
        if not ret:
            break
        
        small_img = np.array(np.resize(frame, (80, 160, 3)))
        small_img = small_img[None,:,:,:]
        
        prediction = model.predict(small_img)[0] * 255
    
        lanes.recent_fit.append(prediction)
        if len(lanes.recent_fit) > 5:
            lanes.recent_fit = lanes.recent_fit[1:]
    
        lanes.avg_fit = np.mean(np.array([i for i in lanes.recent_fit]), axis = 0)
    
        blanks = np.zeros_like(lanes.avg_fit).astype(np.uint8)
        lane_drawn = np.dstack((blanks, lanes.avg_fit, blanks))
        lane_image = np.resize(lane_drawn, (720, 1280, 3))
    
        result = cv2.addWeighted(lane_image, 1, lane_image, 1, 0)
    
    
        if frame_no % 20 == 0:
            print('# {}/{} frames processed!'.format(frame_no, total_frames))
    
        frame_no += 1
        video_writer.write(frame)
    video_capture.release()
    video_writer.release()
    

    I also used the code in the original repository, but I did not get the same output in repository, Although I use the same steps.

    Do I have to train another model now?

    opened by masouduut94 2
  • Training and validation loss graphs

    Training and validation loss graphs

    Please post the training loss graph and validation loss graph for your trained model. I am using as a reference for my dissertation. It will be very helpful.

    opened by sahrudaibond 2
  • labels and output

    labels and output

    how to make labels without that redrawn lanes ? or how to get those redrawn lanes can we change the final output to be a convolution and not a deconv and what should the output be

    opened by imaneelhg 2
  • OSError: Unable to open file (unable to open file: name = 'full_CNN_model.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

    OSError: Unable to open file (unable to open file: name = 'full_CNN_model.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

    I got an error after i had run python3 MLND-Capstone/draw_detected_lanes.py:

    Traceback (most recent call last): File "MLND-Capstone/draw_detected_lanes.py", line 9, in model = load_model('full_CNN_model.h5') File "/usr/lib/python3.7/site-packages/keras/engine/saving.py", line 458, in load_wrapper return load_function(*args, **kwargs) File "/usr/lib/python3.7/site-packages/keras/engine/saving.py", line 549, in load_model with H5Dict(filepath, mode='r') as h5dict: File "/usr/lib/python3.7/site-packages/keras/utils/io_utils.py", line 191, in init self.data = h5py.File(path, mode=mode) File "/usr/lib/python3.7/site-packages/h5py/_hl/files.py", line 394, in init swmr=swmr) File "/usr/lib/python3.7/site-packages/h5py/_hl/files.py", line 170, in make_fid fid = h5f.open(name, flags, fapl=fapl) File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "h5py/h5f.pyx", line 85, in h5py.h5f.open OSError: Unable to open file (unable to open file: name = 'full_CNN_model.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

    opened by mduccc 2
  • no output after changing output type of addweighted method

    no output after changing output type of addweighted method

    1# I got an error of different input types on add weighted method so I've to specify an output type

    before change: result = cv2.addWeighted(image, 1, lane_image, 1, 0) after change: result = cv2.addWeighted(image, 1, lane_image, 1, 0, dtype= cv2.CV_32F).astype(np.uint8)

    now there are no lanes on mn output video 2# and also I've used "from skimage.transform import resize as imresize" for image resize but I didn't change any other lines related to imresize is it ok? i.e lane_image = imresize(lane_drawn, (720, 1280, 3)) its same before and after

    opened by anees1998 2
  • About labels

    About labels

    Hello, I'm not understanding how you are creating labels and what's inside in labels.p file as you are dividing labels by 255.Why?

    Normalize labels - training images get normalized to start in the network

    labels = labels / 255 Please guide me in this. Thank You!

    opened by aansrajpoot 0
  • Dataset handling is very inefficient

    Dataset handling is very inefficient

    The current way the dataset is loaded for training is super inefficient and loads the whole dataset all at once. As such, I should consider changing the dataset from being stored as a pickle file, as well as whether to use flow_from_directory or similar techniques.

    opened by mvirgo 2
  • Use PIL over scipy's deprecated imresize

    Use PIL over scipy's deprecated imresize

    Scipy deprecated imresize as of 1.3.0 and now suggests using PIL to resize images. This will require both updating code as well as the environment file to eventually remove scipy and replace it with pillow.

    Can also consider using alternative image re-sizing functions from other libraries as well.

    enhancement 
    opened by mvirgo 0
Owner
Michael Virgo
Software Engineer
Michael Virgo
Vowpal Wabbit is a machine learning system which pushes the frontier of machine learning with techniques

Vowpal Wabbit is a machine learning system which pushes the frontier of machine learning with techniques such as online, hashing, allreduce, reductions, learning2search, active, and interactive learning.

Vowpal Wabbit 8.1k Dec 30, 2022
CD) in machine learning projectsImplementing continuous integration & delivery (CI/CD) in machine learning projects

CML with cloud compute This repository contains a sample project using CML with Terraform (via the cml-runner function) to launch an AWS EC2 instance

Iterative 19 Oct 3, 2022
learn python in 100 days, a simple step could be follow from beginner to master of every aspect of python programming and project also include side project which you can use as demo project for your personal portfolio

learn python in 100 days, a simple step could be follow from beginner to master of every aspect of python programming and project also include side project which you can use as demo project for your personal portfolio

BDFD 6 Nov 5, 2022
machine learning model deployment project of Iris classification model in a minimal UI using flask web framework and deployed it in Azure cloud using Azure app service

This is a machine learning model deployment project of Iris classification model in a minimal UI using flask web framework and deployed it in Azure cloud using Azure app service. We initially made this project as a requirement for an internship at Indian Servers. We are now making it open to contribution.

Krishna Priyatham Potluri 73 Dec 1, 2022
We have a dataset of user performances. The project is to develop a machine learning model that will predict the salaries of baseball players.

Salary-Prediction-with-Machine-Learning 1. Business Problem Can a machine learning project be implemented to estimate the salaries of baseball players

Ayşe Nur Türkaslan 9 Oct 14, 2022
Can a machine learning project be implemented to estimate the salaries of baseball players whose salary information and career statistics for 1986 are shared?

END TO END MACHINE LEARNING PROJECT ON HITTERS DATASET Can a machine learning project be implemented to estimate the salaries of baseball players whos

Pinar Oner 7 Dec 18, 2021
Exemplary lightweight and ready-to-deploy machine learning project

Exemplary lightweight and ready-to-deploy machine learning project

snapADDY GmbH 6 Dec 20, 2022
A machine learning project that predicts the price of used cars in the UK

Car Price Prediction Image Credit: AA Cars Project Overview Scraped 3000 used cars data from AA Cars website using Python and BeautifulSoup. Cleaned t

Victor Umunna 7 Oct 13, 2022
This project impelemented for midterm of the Machine Learning #Zoomcamp #Alexey Grigorev

MLProject_01 This project impelemented for midterm of the Machine Learning #Zoomcamp #Alexey Grigorev Context Dataset English question data set file F

Hadi Nakhi 1 Dec 18, 2021
A demo project to elaborate how Machine Learn Models are deployed on production using Flask API

This is a salary prediction website developed with the help of machine learning, this makes prediction of salary on basis of few parameters like interview score, experience test score.

null 1 Feb 10, 2022
Microsoft contributing libraries, tools, recipes, sample codes and workshop contents for machine learning & deep learning.

Microsoft contributing libraries, tools, recipes, sample codes and workshop contents for machine learning & deep learning.

Microsoft 366 Jan 3, 2023
A data preprocessing package for time series data. Design for machine learning and deep learning.

A data preprocessing package for time series data. Design for machine learning and deep learning.

Allen Chiang 152 Jan 7, 2023
A mindmap summarising Machine Learning concepts, from Data Analysis to Deep Learning.

A mindmap summarising Machine Learning concepts, from Data Analysis to Deep Learning.

Daniel Formoso 5.7k Dec 30, 2022
A comprehensive repository containing 30+ notebooks on learning machine learning!

A comprehensive repository containing 30+ notebooks on learning machine learning!

Jean de Dieu Nyandwi 3.8k Jan 9, 2023
MIT-Machine Learning with Python–From Linear Models to Deep Learning

MIT-Machine Learning with Python–From Linear Models to Deep Learning | One of the 5 courses in MIT MicroMasters in Statistics & Data Science Welcome t

null 2 Aug 23, 2022
Implemented four supervised learning Machine Learning algorithms

Implemented four supervised learning Machine Learning algorithms from an algorithmic family called Classification and Regression Trees (CARTs), details see README_Report.

Teng (Elijah)  Xue 0 Jan 31, 2022
High performance, easy-to-use, and scalable machine learning (ML) package, including linear model (LR), factorization machines (FM), and field-aware factorization machines (FFM) for Python and CLI interface.

What is xLearn? xLearn is a high performance, easy-to-use, and scalable machine learning package that contains linear model (LR), factorization machin

Chao Ma 3k Jan 8, 2023
cuML - RAPIDS Machine Learning Library

cuML - GPU Machine Learning Algorithms cuML is a suite of libraries that implement machine learning algorithms and mathematical primitives functions t

RAPIDS 3.1k Dec 28, 2022