Coder Social home page Coder Social logo

sdc-live-trainer's Introduction

sdc-live-trainer

Live training program for Udacity's SDC Simulator. Created as a part of Udacity Self-Driving Car Project 3: Behavioral Cloning.

Overview

This program was created to allow the "remote" driving of Udacity's Self Driving Car (SDC) Simulator using a neural network, while also allowing an option for manual override and live-collection of data from real time fine-tuning of the neural network.

This was idea inspired by John Chen's Agile Trainer.

Note: If you want to use your own model, make sure you modify the preprocess_input method in live_trainer.py to do whatever preprocessing your model expects.

server.py

This is an object-oriented, modular version of the drive.py script that Udacity provided. I made a ControlServer class that triggers callbacks when the simulator connects and sends telemetry. This plugs into all the three programs listed below.

The main difficulty was in understanding how Tkinter's event loop works and how to make it play nice with the eventlet loop that drive.py uses to set up the WSGI server. Eventually, I was able to fold in the Tkinter UI loop as a sepearate eventlet "greenthread". Check the code for details on how this is implemented.

manual_driver.py

This was my initial proof of concept to see if it is possible to reliably control the SDC simulator using keyboard input, while the simulator is in "autonomous mode".

The keyboard input is used to increment and decrement a steering_angle state. The program also models some restoring-torque dynamics that slowly re-centers the steering when there is no keyboard input. There is also a simple proportional-gain controller that modulates the throttle to achieve a target speed that can be controlled by the user.

You can run it by typing: python manual_driver.py

Then start the Udacity SDC Simulator and click "Autonomous Mode". This should bring the program window into focus again once the simulator connects. The controls are:

Up/Down : Control speed
Left/Right : Steer the car

hybrid_driver.py

This was the second step to implementing the live trainer. This program allows the user to specify a Keras model that will predict a steering angle based on the image data sent by the simulator. It also allows a manual override option to take over control at any time.

Run it by typing: python hybrid_driver.py <model>.json

where <model>.json is the Keras model file. The program expects the weights for the model to be stored in <model>.h5.

The controls are:

Up/Down : Control speed
Left/Right : Steer the car
x : Toggle manual override and autonomous mode
c : Reset steering angle to zero (only in manual mode)

live_trainer.py

This is the final implementation of the live trainer. This program combines the functionality of the above two scripts, along with the capability to train the neural network in real-time. Every time a batch is trained, the model weights are saved to checkpoint.h5. Live training can be initiated at any time when the car is in manual override.

The controls are:

Up/Down : Control speed
Left/Right : Steer the car
x : Toggle manual override and autonomous mode
c : Reset steering angle to zero (only in manual mode)
z : Toggle live training (only in manual mode)

The program also displays an "Autonomous Rating" which is the percentage of runtime that the program was in fully autonomous mode.

The learning rate, checkpoint filename and batch size can be adjusted in parameters defined at the beginning of the script.

Usage

We start with a neural network that was trained on data from the SDC simulator that sort of works. I used NVIDIA's End-to-End Deep Learning Architecture. The live trainer is to be used for fine-tuning this original model. It may also be possible to train a model from scratch using this live trainer, but it might take considerably longer.

The idea is to let the model control the car until we feel like it has deviated too much from the track. Then we take over, and the train it as soon as we have set the steering angle to the right values for recovery. We continue training until we are through the "difficult" area and switch back to autonomous mode. By repeating this several times, the model will eventually learn to navigate any difficult spots it has encountered. It might also be helpful to slow down considerably (to 4-5 mph) while in difficult spots so that the more data can be collected for training.

sdc-live-trainer's People

Contributors

thomasantony avatar

Watchers

James Cloos avatar Nick avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.