Skip to content

Commit 2da5d29

Browse files
andrewpasterdomluna
authored andcommitted
Added more info to README, included writeup template, changed drive.py to accept model.h5 file (#1)
* modified README, drive.py to receive model.h5 file, and writeup template * changed filename in examples folder * clarified where students find simulator * fixed typo in README
1 parent 9ae0727 commit 2da5d29

File tree

5 files changed

+192
-18
lines changed

5 files changed

+192
-18
lines changed

README.md

+59-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,71 @@
1-
# CarND Behavioral Cloning Project (P3)
1+
# Project 3: Use Deep Learning to Clone Driving Behavior
22

3+
[![Udacity - Self-Driving Car NanoDegree](https://s3.amazonaws.com/udacity-sdc/github/shield-carnd.svg)](http://www.udacity.com/drive)
4+
5+
Overview
6+
---
37
This repository contains starting files for P3, Behavioral Cloning.
48

9+
In this project, you will use what you've learned about deep neural networks and convolutional neural networks to clone driving behavior. You will train, validate and test a model using Keras. The model will output a steering angle to an autonomous vehicle.
10+
11+
We have provided a simulator where you can steer a car around a track for data collection. You'll use image data and steering angles to train a neural network and then use this model to drive the car autonomously around the track.
12+
13+
We also want you to create a detailed writeup of the project. Check out the [writeup template](https://github.com/udacity/CarND-Behavioral-Cloning-P3/blob/master/writeup_template.md) for this project and use it as a starting point for creating your own writeup. The writeup can be either a markdown file or a pdf document.
14+
15+
To meet specifications, the project will require submitting four files:
16+
* model.py (script used to create and train the model)
17+
* drive.py (script to drive the car - feel free to modify this file)
18+
* model.h5 (a trained Keras model)
19+
* a report writeup file (either markdown or pdf)
20+
21+
Optionally, a video of your vehicle's performance can also be submitted with the project although this is optional. This README file describes how to output the video in the "Details About Files In This Directory" section.
22+
23+
Creating a Great Writeup
24+
---
25+
A great writeup should include the [rubric points](https://review.udacity.com/#!/rubrics/432/view) as well as your description of how you addressed each point. You should include a detailed description of the code used (with line-number references and code snippets where necessary), and links to other supporting documents or external references. You should include images in your writeup to demonstrate how your code works with examples.
26+
27+
All that said, please be concise! We're not looking for you to write a book here, just a brief description of how you passed each rubric point, and references to the relevant code :).
28+
29+
You're not required to use markdown for your writeup. If you use another method please just submit a pdf of your writeup.
30+
31+
The Project
32+
---
33+
The goals / steps of this project are the following:
34+
* Use the simulator to collect data of good driving behavior
35+
* Design, train and validate a model that predicts a steering angle from image data
36+
* Use the model to drive the vehicle autonomously around the first track in the simulator. The vehicle should remain on the road for an entire loop around the track.
37+
* Summarize the results with a written report
38+
39+
### Dependencies
40+
This lab requires:
41+
42+
* [CarND Term1 Starter Kit](https://github.com/udacity/CarND-Term1-Starter-Kit)
43+
44+
The lab enviroment can be created with CarND Term1 Starter Kit. Click [here](https://github.com/udacity/CarND-Term1-Starter-Kit/blob/master/README.md) for the details.
45+
46+
The following resources can be found in this github repository:
47+
* drive.py
48+
* video.py
49+
* writeup_template.md
50+
51+
The simulator can be downloaded from the classroom. In the classroom, we have also provided sample data that you can optionally use to help train your model.
52+
53+
## Details About Files In This Directory
54+
555
### `drive.py`
656

7-
Usage of `drive.py` requires you have saved the model definition as a JSON file, i.e. `model.json` and the weights as a h5 file, i.e. `model.h5`.
57+
Usage of `drive.py` requires you have saved the trained model as an h5 file, i.e. `model.h5`. See the [Keras documentation](https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model) for how to create this file using the following command:
58+
```sh
59+
model.save(filepath)
60+
```
61+
62+
Once the model has been saved, it can be used with drive.py using this command:
863

964
```sh
10-
python drive.py model.json
65+
python drive.py model.h5
1166
```
1267

13-
The above command will load the model definition and weights and use the model to make predictions on individual images in real-time and send the predicted angle back to the server via a websocket connection.
68+
The above command will load the trained model and use the model to make predictions on individual images in real-time and send the predicted angle back to the server via a websocket connection.
1469

1570
#### Saving a video of the autonomous agent
1671

drive.py

+4-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from flask import Flask
1313
from io import BytesIO
1414

15-
from keras.models import model_from_json
15+
from keras.models import load_model
1616

1717
sio = socketio.Server()
1818
app = Flask(__name__)
@@ -69,7 +69,7 @@ def send_control(steering_angle, throttle):
6969
parser.add_argument(
7070
'model',
7171
type=str,
72-
help='Path to model definition json. Model weights should be on the same path.'
72+
help='Path to model h5 file. Model should be on the same path.'
7373
)
7474
parser.add_argument(
7575
'image_folder',
@@ -79,18 +79,8 @@ def send_control(steering_angle, throttle):
7979
help='Path to image folder. This is where the images from the run will be saved.'
8080
)
8181
args = parser.parse_args()
82-
with open(args.model, 'r') as jfile:
83-
# NOTE: if you saved the file by calling json.dump(model.to_json(), ...)
84-
# then you will have to call:
85-
#
86-
# model = model_from_json(json.loads(jfile.read()))\
87-
#
88-
# instead.
89-
model = model_from_json(jfile.read())
90-
91-
model.compile("adam", "mse")
92-
weights_file = args.model.replace('json', 'h5')
93-
model.load_weights(weights_file)
82+
83+
model = load_model(args.model)
9484

9585
if args.image_folder != '':
9686
print("Creating image folder at {}".format(args.image_folder))

examples/placeholder.png

7.65 KB
Loading

examples/placeholder_small.png

4.79 KB
Loading

writeup_template.md

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#**Traffic Sign Recognition**
2+
3+
##Writeup Template
4+
5+
###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.
6+
7+
---
8+
9+
**Behavrioal Cloning Project**
10+
11+
The goals / steps of this project are the following:
12+
* Use the simulator to collect data of good driving behavior
13+
* Build, a convolution neural network in Keras that predicts steering angles from images
14+
* Train and validate the model with a training and validation set
15+
* Test that the model successfully drives around track one without leaving the road
16+
* Summarize the results with a written report
17+
18+
19+
[//]: # (Image References)
20+
21+
[image1]: ./examples/placeholder.png "Model Visualization"
22+
[image2]: ./examples/placeholder.png "Grayscaling"
23+
[image3]: ./examples/placeholder_small.png "Recovery Image"
24+
[image4]: ./examples/placeholder_small.png "Recovery Image"
25+
[image5]: ./examples/placeholder_small.png "Recovery Image"
26+
[image6]: ./examples/placeholder_small.png "Normal Image"
27+
[image7]: ./examples/placeholder_small.png "Flipped Image"
28+
29+
## Rubric Points
30+
###Here I will consider the [rubric points](https://review.udacity.com/#!/rubrics/432/view) individually and describe how I addressed each point in my implementation.
31+
32+
---
33+
###Files Submitted & Code Quality
34+
35+
####1. Submission includes all required files and can be used to run the simulator in autonomous mode
36+
37+
My project includes the following files:
38+
* model.py containing the script to create and train the model
39+
* drive.py for driving the car in autonomous mode
40+
* model.h5 containing a trained convolution neural network
41+
* writeup_report.md or writeup_report.pdf summarizing the results
42+
43+
####2. Submssion includes functional code
44+
Using the Udacity provided simulator and my drive.py file, the car can be driven autonomously around the track by executing
45+
```sh
46+
python drive.py model.h5
47+
```
48+
49+
####3. Submssion code is usable and readable
50+
51+
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.
52+
53+
###Model Architecture and Training Strategy
54+
55+
####1. An appropriate model arcthiecture has been employed
56+
57+
My model consists of a convolution neural network with 3x3 filter sizes and depths between 32 and 128 (model.py lines 18-24)
58+
59+
The model includes RELU layers to introduce nonlinearity (code line 20), and the data is normalized in the model using a Keras lambda layer (code line 18).
60+
61+
####2. Attempts to reduce overfitting in the model
62+
63+
The model contains dropout layers in order to reduce overfitting (model.py lines 21).
64+
65+
The model was trained and validated on different data sets to ensure that the model was not overfitting (code line 10-16). The model was tested by running it through the simulator and ensuring that the vehicle could stay on the track.
66+
67+
####3. Model parameter tuning
68+
69+
The model used an adam optimizer, so the learning rate was not tuned manually (model.py line 25).
70+
71+
####4. Appropriate training data
72+
73+
Training data was chosen to keep the vehicle driving on the road. I used a combination of center lane driving, recovering from the left and right sides of the road ...
74+
75+
For details about how I created the training data, see the next section.
76+
77+
###Model Architecture and Training Strategy
78+
79+
####1. Solution Design Approach
80+
81+
The overall strategy for deriving a model architecture was to ...
82+
83+
My first step was to use a convolution neural network model similar to the ... I thought this model might be appropriate because ...
84+
85+
In order to gauge how well the model was working, I split my image and steering angle data into a training and validation set. I found that my first model had a low mean squared error on the training set but a high mean squared error on the validation set. This implied that the model was overfitting.
86+
87+
To combat the overfitting, I modified the model so that ...
88+
89+
Then I ...
90+
91+
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 ....
92+
93+
At the end of the process, the vehicle is able to drive autonomously around the track without leaving the road.
94+
95+
####2. Final Model Architecture
96+
97+
The final model architecture (model.py lines 18-24) consisted of a convolution neural network with the following layers and layer sizes ...
98+
99+
Here is a visualization of the architecture (note: visualizing the architecture is optional according to the project rubric)
100+
101+
![alt text][image1]
102+
103+
####3. Creation of the Training Set & Training Process
104+
105+
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:
106+
107+
![alt text][image2]
108+
109+
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 .... These images show what a recovery looks like starting from ... :
110+
111+
![alt text][image3]
112+
![alt text][image4]
113+
![alt text][image5]
114+
115+
Then I repeated this process on track two in order to get more data points.
116+
117+
To augment the data sat, I also flipped images and angles thinking that this would ... For example, here is an image that has then been flipped:
118+
119+
![alt text][image6]
120+
![alt text][image7]
121+
122+
Etc ....
123+
124+
After the collection process, I had X number of data points. I then preprocessed this data by ...
125+
126+
127+
I finally randomly shuffled the data set and put Y% of the data into a validation set.
128+
129+
I used this training data for training the model. The validation set helped determine if the model was over or under fitting. The ideal number of epochs was Z as evidenced by ... I used an adam optimizer so that manually training the learning rate wasn't necessary.

0 commit comments

Comments
 (0)