Reinforcement Learning in AirSim

We below describe how we can implement DQN in AirSim using CNTK. The easiest way is to first install python only CNTK (instructions).

CNTK provides several demo examples of deep RL. We will modify the DeepQNeuralNetwork.py to work with AirSim. We can utilize most of the classes and methods corresponding to the DQN algorithm. However, there are certain additions we need to make for AirSim.

Disclaimer

This is still in active development. What we share below is a framework that can be extended and tweaked to obtain better performance.

RL with Car

Source code

This example works with AirSimNeighborhood environment available in releases.

First, we need to get the images from simulation and transform them appropriately. Below, we show how a depth image can be obtained from the ego camera and transformed to an 84X84 input to the network. (you can use other sensor modalities, and sensor inputs as well – of course you’ll have to modify the code accordingly).

We further define the six actions (breaking, straight with throttle, full-left with throttle, full-right with throttle, half-left with throttle, half-right with throttle) that an agent can execute. This is done via the function interpret_action:

We then define the reward function in compute_reward as a convex combination of how fast the vehicle is travelling and how much it deviates from the center line. The agent gets a high reward when its moving fast and staying in the center of the lane.

The function isDone determines if the episode has terminated (e.g. due to collision). We look at the speed of the vehicle and if it is less than a threshold than the episode is considered to be terminated.

The main loop then sequences through obtaining the image, computing the action to take according to the current policy, getting a reward and so forth. If the episode terminates then we reset the vehicle to the original state via:

Note that the simulation needs to be up and running before you execute DQNcar.py. The video below shows first few episodes of DQN training.

Reinforcement Learning - Car

RL with Quadrotor

Source code

This example works with AirSimMountainLandscape environment available in releases.

We can similarly apply RL for various autonomous flight scenarios with quadrotors. Below is an example on how RL could be used to train quadrotors to follow high tension power lines (e.g. application for energy infrastructure inspection). There are seven actions here that correspond to different directions in which the quadrotor can move in (six directions + one hovering action).

The reward again is a function how how fast the quad travels in conjunction with how far it gets from the known powerlines.

We consider an episode to terminate if it drifts too much away from the known power line coordinates.

The reset function here flies the quadrotor to the initial starting point:

Here is the video of first few episodes during the training.

Reinforcement Learning - Quadrotor