Code Monkey home page Code Monkey logo

road_simulator's Introduction

Road Simulator

The road_simulator is part of the 'ironcar' project. To see what the ironcar project is, go to the ironcar repository.
If you want to get the full tutorial for the entire project (ironcar hardware, software, simulator and model generation, you can also go there.

This simulator generates 'fake' pictures of a road as seen by a 1/10th car with a wide angle camera and creates a deep-learning model based on these images. We used it to get (250 * 70) RGB dimensional track pictures. It is quite fast (we can generate 100,000 images in 15 minutes which is faster than driving the car ourselves and capturing the images), and far more accurate in the learning process (less approximations of curves etc).

These are examples of what can be (very easily) generated:

dashed line 1 dashed line 2 dashed line 3 dashed line 4
plain line 1 plain line 2 plain line 3 plain line 4
dashed line 5 plain_line_5 plain_line_6 plain_line_7

With the model created in example/model_cnn.py and a dataset of 100,000 images created via simulator, we achieved a 94% accuracy and managed to get our car to successfully finish a lap on 2 different circuits it had never seen before !

Getting started

To install the library, do in the root folder:

$ pip install .

In this code, please adapt ./ground_pics to fit your current layout.

Each simulator is composed of layers to make it easy to adapt to your particular situation/track. The simpliest type of generator is the default Simulator object:

from roadsimulator.simulator import Simulator

simulator = Simulator()

Then, we add layers to our generator:

from roadsimulator.colors import White
from roadsimulator.layers.layers import Background, DrawLines, Perspective, Crop

white = White()

simulator.add(Background(n_backgrounds=3, path='./ground_pics', input_size=(250, 200)))
simulator.add(DrawLines(input_size=(250, 200), color_range=white))
simulator.add(Perspective())
simulator.add(Crop())

White object gives a range of white-ish colors to draw the lines. They may not appear exactly white on the images. There exists three colors for now (Yellow, White and DarkShadow) and a generic Color class. You can add more colors by replicating the yellow example.

Now, let's generate the images. We just need to write:

simulator.generate(n_examples=100, path='my_dataset')

where you need to set the number of images to be generated n_examples and the path you want them to be generated in path.

Creating a model

You can simply create a keras model.

First, let's load the images and their labels, split in a training and validation sets:

from roadsimulator.models.utils import get_datasets

train_X, train_Y, val_X, val_Y, _, _ = get_datasets('my_dataset', n_images=1000)

where n_images is the maximum number of images you want to get from the dataset 'my_dataset'.

Now, just create the model you want, using keras:

from keras.layers import Input, Convolution2D, MaxPooling2D, Activation
from keras.layers import Flatten, Dense
from keras.models import Model

img_in = Input(shape=(70, 250, 3), name='img_in')
x = img_in

x = Convolution2D(1, 3, 3, activation='relu', border_mode='same')(x)
x = MaxPooling2D(pool_size=(2, 2), strides=(2,2))(x)

x = Convolution2D(2, 3, 3, activation='relu', border_mode='same')(x)
x = MaxPooling2D(pool_size=(2, 2), strides=(2,2))(x)

x = Convolution2D(2, 3, 3, activation='relu', border_mode='same')(x)
x = MaxPooling2D(pool_size=(2, 2), strides=(2,2))(x)

x = Convolution2D(4, 3, 3, activation='relu', border_mode='same')(x)
x = MaxPooling2D(pool_size=(2, 2), strides=(2,2))(x)

flat = Flatten()(x)

x = Dense(20)(flat)
x = Activation('relu')(x)

x = Dense(5)(x)
angle_out = Activation('softmax')(x)

model = Model(input=[img_in], output=[angle_out])
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

model.fit([train_X], train_Y, batch_size=100, nb_epoch=20, validation_data=([val_X], val_Y))

And it's done !

road_simulator's People

Contributors

vhoulbreque avatar srdadian avatar

Watchers

James Cloos avatar Mohd Fitri Alif Bin Mohd Kasai 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.