Code Monkey home page Code Monkey logo

airsimtensorflow's Introduction

This repository contains Python scripts showing how you can use Microsoft AirSim to collect image data from a moving vehicle, then use that data to train and test a deep-learning neural net in TensorFlow.

Prerequisites

  • Recommended hardware for running UnrealEngine4, required for AirSim. Although it is possible build AirSim on OS X and Linux, we found it easiest to use the pre-compiled Windows binaries in the Neighborhood example.

  • Python3 for 64-bit Windows

  • TensorFlow. To run TensorFlow on your GPU as we and most people do, you'll need to follow the directions for installing CUDA and CuDNN. We recommend setting aside at least an hour to make sure you do this right.

Instructions

  1. Clone this repository.
  2. Download and unzip the Neighborhood example, open it, and click run.bat to launch AirSim.
  3. When prompted, go with the default car simulation. If you press the 3 key on your keyboard, you will see the little image on which the neural net will be trained.
  4. From the repository, run the image_collection.py script. It will start the car moving and stop when the car collides with the fence, creating a carpix folder containing the images on which you will train the network in the next step.
  5. From the repository, run the collision_training.py script. Running on an HP Z440 workstation with NVIDIA GeForce GTX 1080 Ti GPU, we were able to complete the 500 training iterations in a few seconds.
  6. From the repository, run the collision_testing.py script. This should drive the car forward as before, but but the car should stop right before it hits the fence, based on the collision predicted by the neural net.

How it works

The image_collection script maintains a queue of the ten most recent images and saves them to numbered files in the carpix folder. The collision_training script converts these color images to grayscale, then builds a training set in which all images but the final one are labeled as safe (no collision; code [1 0]), and the final one is labeled as a collision (code [0 1]).
Finally, this training script uses Python's built-in pickle library to save the trained network parameters (weights and biases). The collision_testing script uses pickle to restore these parameters, then reconstructs the TensorFlow neural net from them. (We found this approach easier than using TensorFlow's save-and-restore API.) Finally, the collision_testing script moves the vehicle forward, converting the live image into grayscale and running it through the network to make a collision/no-collision prediction. When the value of the “collision bit” exceeds 0.5, the script stops the vehicle by applying the brakes.

Future work

Our single-layer logistic regression network provides a simple proof-of-concept example; however, for a more realistic data set involving collisions with different types of objects, a convolutional network would make more sense. AirSim also provides access to depth images (just press the 1 key during the simulation) which, like the Lidar on today's self-driving cars, would provide a valuable additional source of information for avoiding collisions.

Credits

This code represents the combined work of two teams in Prof. Simon D. Levy's fall 2017 AI course (CSCI 315) at Washington and Lee University (listed alphabetically):

  • Jack Baird
  • Alex Cantrell
  • Keith Denning
  • Rajwol Joshi
  • Will McMurtry
  • Jacob Rosen

Acknowledgement

We thank David Pfaff of the W&L IQ Center for providing the hardware on which we developed this project.

airsimtensorflow's People

Contributors

simondlevy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

airsimtensorflow's Issues

Images are rewritten after each run

@simondlevy Every time the sim initialized with image_collection.py the 10 images leading to the crash are stored removing the images for the previous crash. My understanding is we need to collect as many "crash"images as we can to train the network. So is this an issue and a bug need to be fixed in the code or am I missing something?

Thanks!

collision_testing.py

Hi, help please update collision_testing. py. All working, but arrors in lines 71 and 74.

import airsim
#from AirSimClient import CarClient, CarControls, ImageRequest, AirSimImageType, AirSimClientBase
import os
import time
import tensorflow as tf
import pickle
import sys

from image_helper import loadgray, IMAGEDIR
from tf_softmax_layer import inference

TMPFILE = IMAGEDIR + '/active.png'
PARAMFILE = 'params.pkl'
IMGSIZE = 1032
INITIAL_THROTTLE= 0.65
BRAKING_DURATION = 15

connect to the AirSim simulator

client = airsim.CarClient()
client.confirmConnection()
print('Connected')
client.enableApiControl(True)
car_controls = airsim.CarControls()

client.reset()

go forward

car_controls.throttle = INITIAL_THROTTLE
car_controls.steering = 0
client.setCarControls(car_controls)

Load saved training params as ordinary NumPy

W,b = pickle.load(open('params.pkl', 'rb'))

with tf.Graph().as_default():

# Placeholder for an image
x = tf.placeholder('float', [None, IMGSIZE])

# Our inference engine, intialized with weights we just loaded
output = inference(x, IMGSIZE, 2, W, b)

# TensorFlow initialization boilerplate
sess = tf.Session()
init_op = tf.global_variables_initializer()
sess.run(init_op)

# Once the brakes come on, we need to keep them on for a while before exiting; otherwise,
# the vehicle will resume moving.
brakingCount = 0

# Loop until we detect a collision
while True:

    # Get RGBA camera images from the car
    responses = client.simGetImages([airsim.ImageRequest("1", airsim.ImageType.Scene)])

    # Save it to a temporary file
    image = responses[0].image_data_uint8
    AirSimClientBase.write_file(os.path.normpath(TMPFILE), image)  ### NameError: name 'AirSimClientBase' is not defined

    # Read-load the image as a grayscale array
    image = loadgray(TMPFILE) ### FileNotFoundError: [Errno 2] No such file or directory: './carpix/active.png'

    # Run the image through our inference engine.
    # Engine returns a softmax output inside a list, so we grab the first
    # element of the list (the actual softmax vector), whose second element
    # is the absence of an obstacle.
    safety = sess.run(output, feed_dict={x:[image]})[0][1]

    # Slam on the brakes if it ain't safe!
    if safety < 0.5:

        if brakingCount > BRAKING_DURATION:
            print('BRAKING TO AVOID COLLISSION')
            sys.stdout.flush()
            break
        
        car_controls.brake = 1.0
        client.setCarControls(car_controls)

        brakingCount += 1
        
    # Wait a bit on each iteration
    time.sleep(0.1)

client.enableApiControl(False)

Drone

Congratulations on your project. Have you tested something with the drone mode?
I am now doing the final thesis of my bachelor degree related to Machine Learning in drone simulations and I'm starting with something like what you did but with the drone mode, and some advices would be useful.

Thanks!

Some problem about the airsim

Hello, I download the AirSimNH 1.2.0 environment from the github, but when I run the run.bat and image_colleection.py the cmd shows as follow:
WARNING:tornado.general:Connect error on fd 284: WSAECONNREFUSED
WARNING:tornado.general:Connect error on fd 284: WSAECONNREFUSED
WARNING:tornado.general:Connect error on fd 284: WSAECONNREFUSED
WARNING:tornado.general:Connect error on fd 284: WSAECONNREFUSED
WARNING:tornado.general:Connect error on fd 284: WSAECONNREFUSED
Waiting for connection: Traceback (most recent call last):
File ".\image_collection.py", line 30, in
client.confirmConnection()
File "C:\Users\Asus\Desktop\AirSimTensorFlow\AirSimClient.py", line 160, in confirmConnection
home = self.getHomeGeoPoint()
File "C:\Users\Asus\Desktop\AirSimTensorFlow\AirSimClient.py", line 169, in getHomeGeoPoint
return GeoPoint.from_msgpack(self.client.call('getHomeGeoPoint'))
File "F:\Python3.5.4\lib\site-packages\msgpackrpc\session.py", line 41, in call
return self.send_request(method, args).get()
File "F:\Python3.5.4\lib\site-packages\msgpackrpc\future.py", line 43, in get
raise self._error
msgpackrpc.error.TransportError: Retry connection over the limit

I do know the airsim does not work, but I can not fix it. Could you help me please?

error in running Neigbourhoodevironment

I have downloaded neighbor environment from the link and after extracting am trying to run .bat file but it is giving Assertion error how can I resolve it
capture

problem executing run.bat

hi, I am facing crashing of the unreal engine 4 as I try to execute the file named run.don't know why it is happening can you guide me, please. also I wanted to ask which version of the unreal engine have you used in making the environment? bellow have attached the error that I am facing any help will be very helpful.
image

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.