Behavioral Cloning

Behavioral Cloning

Writeup Template

You can use this file as a template for your writeup if you want to submit it as a markdown file, but feel free to use some other method and submit a pdf if you prefer.


Behavioral Cloning Project

The goals / steps of this project are the following:

  • Use the simulator to collect data of good driving behavior
  • Build, a convolution neural network in Keras that predicts steering angles from images
  • Train and validate the model with a training and validation set
  • Test that the model successfully drives around track one without leaving the road
  • Summarize the results with a written report

Rubric Points

Here I will consider the rubric points individually and describe how I addressed each point in my implementation.


Files Submitted & Code Quality

1. Submission includes all required files and can be used to run the simulator in autonomous mode

My project includes the following files:

  • model.py containing the script to create and train the model
  • drive.py for driving the car in autonomous mode
  • model.h5 containing a trained convolution neural network
  • writeup_report.md or writeup_report.pdf summarizing the results
  • video.mp4

2. Submission includes functional code

The codes are submitted to the github: https://github.com/fighting41love/Udacity_Behavioral_Cloning
The video of the project is uploaded to the youtube: https://youtu.be/MEffY-gDWfg
Using the Udacity provided simulator and my drive.py file, the car can be driven autonomously around the track by executing

python==3.6.2
keras==2.0.6

python drive.py model.h5

3. Submission code is usable and readable

The model.py file contains the code for training and saving the convolution neural network. The file shows the pipeline I used for training and validating the model, and it contains comments to explain how the code works.

Model Architecture and Training Strategy

1. An appropriate model architecture has been employed

My model is similar to the Navidia model. It consists of several convolution neural layers and dense layers.
Here is a description of each layer:

model_visualization.jpg

The model includes RELU layers to introduce nonlinearity (code line 63-69), and the data is normalized in the model using a Keras lambda layer (code line 61).

2. Attempts to reduce overfitting in the model

The model doesn't contain dropout layers. We use earlystopping to avoid overfitting, i.e., train the model for 1-2 epochs, and the model runs well. If we run it at least 5 epochs, the model will be overfitting (the performance is very bad on track 1). We also flip and randomly modify the brightness to avoid overfitting too.

3. Model parameter tuning

The model used an adam optimizer, so the learning rate was not tuned manually (model.py line 78).
Why the adam optimizer performs well without manually tuning parameters?

4. Appropriate training data

I didn't use the provided images, and collected only 25000+ images by myself. All the images are used for training. I used a combination of center lane driving, recovering from the left and right sides of the road. The left and right images of the camera have a steering correction 0.35. The codes are as follows:

    # center: num==0, left: num==1, right: num == 2
    if num % 3 == 0:
        image_dir = all_data[0][num]
        angle = y[num]
    elif num % 3 == 1:
        image_dir = all_data[1][num]
        angle = y[num] + 0.35
    else:
        image_dir = all_data[2][num]
        angle = y[num] - 0.35

For details about how I created the training data, see the next section.

Model Architecture and Training Strategy

1. Solution Design Approach

My first step was to use a convolution neural network model similar to the nividia model. I thought this model might be appropriate because the model is deep enough. Deep convolutional neural network can learn high level features which may be very helpful for behavioral cloning.

The final step was to run the simulator to see how well the car was driving around track one. There were a few spots where the vehicle fell off the track. To improve the driving behavior in these cases, I collect more data and increase the steering correction ration, which greatly improves the performance.

At the end of the process, the vehicle is able to drive autonomously around the track without leaving the road.

2. Final Model Architecture

The final model architecture (model.py lines 60-74) consisted of a convolution neural network with the following layers and layer sizes .

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lambda_1 (Lambda)            (None, 160, 320, 3)       0         
_________________________________________________________________
cropping2d_1 (Cropping2D)    (None, 65, 320, 3)        0         
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 31, 158, 24)       1824      
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 14, 77, 36)        21636     
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 5, 37, 48)         43248     
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 3, 35, 64)         27712     
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 1, 33, 64)         36928     
_________________________________________________________________
flatten_1 (Flatten)          (None, 2112)              0         
_________________________________________________________________
dense_1 (Dense)              (None, 100)               211300    
_________________________________________________________________
dense_2 (Dense)              (None, 50)                5050      
_________________________________________________________________
dense_3 (Dense)              (None, 10)                510       
_________________________________________________________________
dense_4 (Dense)              (None, 1)                 11        
=================================================================

Here is a visualization of the architecture (note: visualizing the architecture is optional according to the project rubric)


model.png

3. Creation of the Training Set & Training Process

To capture good driving behavior, I first recorded two laps on track one using center lane driving. Here is an example image of center lane driving:

center lane driving

I then recorded the vehicle recovering from the left side and right sides of the road back to center so that the vehicle would learn to go back to center. These images show what a recovery looks like


righit side of the road

:

Start to turn left a little bit
Go back to center

After the collection process, I had 25710 number of data points. I then preprocessed this data by normalizing the pixels in images with a lambda layer and removing the top part of the images, which are irrelevant to self-driving.

model.add(Lambda(lambda x: (x / 255.0) - 0.5, input_shape=(160, 320, 3)))
model.add(Cropping2D(cropping=((70, 25), (0, 0))))

Then, I tried to randomly flip the image and randomly modify the brightness of the images to generate more data and improve the robustness of the model.

Flip image

I used this training data for training the model. The ideal number of epochs was 2 as evidenced by the performance on track 1. I used an adam optimizer so that manually training the learning rate wasn't necessary.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 和蟲(chóng)蟲(chóng)在2011.7.1踏上這片陌生的土地。踏在這座城市的第一刻我們便匆忙的趕起了地鐵,如今看來(lái),我們竟如此快速地...
    GrandFarmer閱讀 465評(píng)論 0 0
  • 目標(biāo)太大反而難以完成。每個(gè)人應(yīng)該根據(jù)自己的情況去選擇性讀書(shū),做筆記。像我。沒(méi)辦法做到一年讀200本書(shū)。也沒(méi)辦法,快...
    曾曾的麻麻閱讀 221評(píng)論 0 0
  • 第一章 黑暗 亞克從灰色的衣襟中摸索出一只懷表,這只懷表已經(jīng)有一些年頭了,亮銀色的表鏈如今已經(jīng)是面目全非,只能從表...
    沁水弦歌閱讀 851評(píng)論 0 3
  • “我一點(diǎn)都不喜歡自己?!?0大朋友在某次聊天時(shí)對(duì)我說(shuō)?!拔乙彩?。”90小朋友我想都不想就附和,想想在千千萬(wàn)萬(wàn)的平凡...
    貓薄荷海鹽閱讀 742評(píng)論 9 3

友情鏈接更多精彩內(nèi)容