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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,185评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,445评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,684评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,564评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,681评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,874评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,025评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,761评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,217评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,545评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,694评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,351评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,988评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,778评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,007评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,427评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,580评论 2 349

推荐阅读更多精彩内容

  • 和虫虫在2011.7.1踏上这片陌生的土地。踏在这座城市的第一刻我们便匆忙的赶起了地铁,如今看来,我们竟如此快速地...
    GrandFarmer阅读 367评论 0 0
  • 目标太大反而难以完成。每个人应该根据自己的情况去选择性读书,做笔记。像我。没办法做到一年读200本书。也没办法,快...
    曾曾的麻麻阅读 187评论 0 0
  • 第一章 黑暗 亚克从灰色的衣襟中摸索出一只怀表,这只怀表已经有一些年头了,亮银色的表链如今已经是面目全非,只能从表...
    沁水弦歌阅读 666评论 0 3
  • “我一点都不喜欢自己。”80大朋友在某次聊天时对我说。“我也是。”90小朋友我想都不想就附和,想想在千千万万的平凡...
    不用了谢谢小姐阅读 699评论 9 3