Reference: https://github.com/simondlevy/AirSimTensorFlow
This repository demonstrates how to use Microsoft AirSim to collect image data from a simulated vehicle, train a neural network using TensorFlow, and perform real-time collision detection and multi-car simulations.
- Hardware: Recommended hardware for Unreal Engine 4 is required for running AirSim. We recommend using the precompiled AirSimNH Windows binary.
- Python: Use Python 3.8 (64-bit) to ensure compatibility with TensorFlow and other dependencies.
- Simulator: AirSim, launched via
run.bat
in the AirSimNH folder.
To isolate dependencies and ensure compatibility, create and activate a Conda environment named games
:
conda create -n games python=3.8
conda activate games
After activating the environment, install all required packages using the provided requirements.txt
:
pip install -r requirements.txt
This will install known-compatible versions of:
tensorflow==2.6.2
numpy==1.19.2
six==1.15.0
matplotlib==3.3.4
airsim==1.8.1
opencv-contrib-python==4.5.3.56
- and other necessary dependencies
- Launch AirSimNH using
run.bat
- Run this script to start collecting first-person-view images
- The car drives forward and saves images to the
carpix
directory - Stops when a collision is detected
- Converts images to grayscale
- Labels them as “safe” or “collision”
- Trains a softmax neural network with TensorFlow
- Saves the model parameters as
params.pkl
- Loads
params.pkl
- Reconstructs the trained network
- Feeds live images from AirSim
- Stops the vehicle before collision is predicted
- Creates a second car that backs out of a parking space
- Runs in parallel with the main car using threads
- Includes potential for further autonomous behaviors
- Images collected before a crash are labeled "safe", and the final image is labeled "collision"
- A softmax neural net is trained using TensorFlow 1.x API via
tensorflow.compat.v1
- The trained model is saved using
pickle
- During testing, live images are passed through the model to predict collisions and apply brakes
CollisionAvoidance.py
demonstrates multi-car behavior using AirSim APIs
After setup, you can freeze your environment to recreate it later:
pip freeze > requirements_exact.txt
Then restore with:
pip install -r requirements_exact.txt
Happy simulating! 🏎️