Giter Site home page Giter Site logo

microsoft / airsim-drone-racing-vae-imitation Goto Github PK

View Code? Open in Web Editor NEW
190.0 13.0 56.0 16.89 MB

Code associated with our paper "Learning Visuomotor Policies for Aerial Navigation Using Cross-Modal Representations": https://arxiv.org/abs/1909.06993

License: MIT License

Python 100.00%

airsim-drone-racing-vae-imitation's Introduction

Learning Visuomotor Policies for Aerial Navigation Using Cross-Modal Representations

Teaser

This repository provides a code base to evaluate and train models from the paper "Learning Visuomotor Policies for Aerial Navigation Using Cross-Modal Representations".

ArXiv pre-print: https://arxiv.org/abs/1909.06993

Paper video: https://youtu.be/VKc3A5HlUU8

License and Citation

This project is licensed under the terms of the MIT license. By using the software, you are agreeing to the terms of the license agreement.

If you use this code in your research, please cite us as follows:

@article{bonatti2020learning,
  title={Learning Visuomotor Policies for Aerial Navigation Using Cross-Modal Representations},
  author={Bonatti, Rogerio and Madaan, Ratnesh and Vineet, Vibhav and Scherer, Sebastian and Kapoor, Ashish},
  journal={arXiv preprint arXiv:1909.06993},
  year={2020}
}

Recommended system

Recommended system (tested):

  • Ubuntu 18.04
  • Python 2.7.15

Python packages used by the example provided and their recommended version:

  • airsimdroneracingvae==1.0.0
  • tensorflow==2.0.0-beta1
  • msgpack-rpc-python==0.4.1
  • numpy==1.16.4
  • matplotlib==2.1.1
  • scikit-learn==0.20.4
  • scipy==1.2.2
  • pandas==0.24.2

Downloading the drone racing files

In order for you to train the models and run Airsim you first need to download all image datasets, behavior cloning datasets, network weights and Airsim binaries:

  • Download all files and datasets Drone Racing files v. 1.0
  • Extract all individual files in the folders
  • Place the settings.json file inside ~/Documents/AirSim in your computer

Training and testing the cross-modal VAE representation

In order to train the cross-modal representations you can either use the downloaded image dataset from the previous step, or generate the data yourself using Airsim.

Teaser

Training with downloaded dataset

  • Go to folder cmvae, and inside file train_cmvae.py edit variable data_dir to the correct path of the extracted dataset within your computer. The default value is the directory with 1K images. But for final training you will need more images, such as the 50K or 300K datasets
  • Also, edit variable output_dir to the correct place where you want the models to be saved
  • Run
train_cmvae.py
  • Network weights will be saved every 5 epochs by default, and you can check loss values with tensorboard or by looking at the terminal
  • Once the network is trained you can evaluate it using another script, which will automatically plot histograms of errors, image reconstructions and latent space interpolations:
eval_cmvae.py

Generating your own dataset with Airsim

You may want to generate a custom dataset for training you cross-modal VAE. Here are the steps to do it:

  • Start the Airsim environment from the binary file:
$ cd /yourpath/all_files/airsim_binaries/vae_env
$ ./AirSimExe.sh -windowed
  • If it asks if you want the car model, click No
  • Inside the file datagen/img_generator/main.py first change the desired number of samples and saved dataset path
  • Run the script for generating data:
main.py     # inside datagen/img_generator
  • Once the dataset is generated, follow the previous scripts for training the CM-VAE

Generating imitation learning data for racing

In order to train the behavior cloning networks you can either use the downloaded image-action pairs dataset or generate the data yourself using Airsim.

Teaser

Training with downloaded dataset

  • Go to folder imitation_learning, and inside file train_bc.py edit variables base_path, data_dir_list, and output_dir. By default you will be using downloaded datasets with 0m to 3m of random gate displacement amplitude over a course with 8m of nominal radius
  • Edit the variables relative to the training mode (full end-to-end, latent representation or regression as latent representation) and weights path for the latent representations (not applicable for full end-to-end learning)
  • Run the script for training the behavior cloning policies:
train_bc.py

Generating your own imitation learning dataset with Airsim

You may want to generate a custom dataset for training you behavior cloning policies. Here are the steps to do it:

  • Start the Airsim environment from the binary file (not the same one for generating images for the cross-modal representation!):
$ cd /yourpath/all_files/airsim_binaries/recording_env
$ ./AirSimExe.sh -windowed
  • Inside the file datagen/action_generator/src/soccer_datagen.py change the desired meta-parameters (number of gates, track radius, gate displacement noise, etc)
  • Run the script for generating data:
soccer_datagen.py
  • Once you're satisfied with the motion, turn off trajectory visualization parameter viz_traj. Otherwise the recorded images will show the motion line
  • Once the quad is flying, press r on your keyboard to start recording images. Velocities will be automatically recorded. Both are saved inside ~/Documents/AirSim

Now you`ll need to process the raw recording so that you can match the time-stamps from velocity commands and images into a cohesive dataset. To do it:

  • Inside /Documents/AirSim, copy the contents of both folders (moveOnSpline_vel_cmd.txt, images folder and images.txt file) into a new directory, for example /all_files/il_datasets/bc_test.
  • In datagen/action_generator/src/data_processor.py, modify variable base_path to /all_files/il_datasets/bc_test. Then run:
data_processor.py
  • Finally, can train train_bc.py following the previous steps. You can combine different datasets with different noise levels to train the same policy

Deploying the trained policies

Now you can deploy the trained policies in AirSim, following these steps:

  • Start the Airsim environment from correct binary file:
$ cd /yourpath/all_files/airsim_binaries/vae_env
$ ./AirSimExe.sh -windowed
  • In file imitation_learning/bc_navigation.py, modify policy_type and gate_noise. Then run:
bc_navigation.py

The policies trained in AirSim using the cross-modal representations can transferred directly towards real-world applications. Please check out the paper and video to see more results from real-life deployment.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

airsim-drone-racing-vae-imitation's People

Contributors

madratman avatar microsoft-github-policy-service[bot] avatar rogeriobonatti 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

airsim-drone-racing-vae-imitation's Issues

PyTorch Implementation - Reproducibility

Hi,

congrats on this amazing work. I was trying to reproduce your results using PyTorch. However, I was not able to get the same results for the CM-VAE&control policy, using the parameters in the code and the training details reported in the paper. Below, I summarize the problems I encountered:

  1. For CMVAE Unconstrained:

    • Poor reconstruction quality when using the loss weights (w_img, w_gate) and beta as in train_cmvae.py. With this CMVAE performance, I was not able to train a good downstream control policy.
    • I improved the reconstruction quality by increasing the loss weights (w_img, w_gate, kept beta=8) and changing dataset splits from 80%-20% to 90%-10% for training and testing respectively. With these changes, I successfully trained the downstream policy. However, the navigation policy performance is far from the results reported in the paper ( Fig. 7), especially when random noise for gate offset is higher than 1.
  2. For CMVAE Constrained:

    • Same situation as in the unconstrained version. Improved the results increasing the loss weights as before, but I'm not getting a disentangled representation.
    • The navigation policy performance is similar to the unconstrained version (not good when random noise for gate offset is higher than 1).

I was wondering if you used fixed loss weights&beta during training? or if dynamic values were used during training (e.g. beta annealing, ...)?. Could you provide more training details about CM-VAE constrained?

In addition, is it possible to have the random seeds for the generated tracks/gates used in the navigation-policy performance assessment (Fig. 7)?

Thank you so much for your help! and again congrats, impressive work!

Performance issues about tf.function

Hello! Our static bug checker has found a performance issue in imitation_learning/train_bc.py: Python type argument epoch is passed to tf.function decorated function train instead of tensors. As there is a for loop, every time the value changes, a new graph will be generated, and that can trigger tf.function retracing warning.

Similar issue in cmvae/train_cmvae.py.

Here is the tensorflow document to support it.

Looking forward to your reply.

cannot running bc_navigation.py in imitation_learning

when running the bc_navigation.py,I get this error:

Traceback (most recent call last):
File "bc_navigation.py", line 72, in
client.enableApiControl(True, vehicle_name=drone_name)
File "/home/wy/anaconda3/envs/debug_vae/lib/python2.7/site-packages/airsimdroneracingvae/client.py", line 42, in enableApiControl
return self.client.call('enableApiControl', is_enabled, vehicle_name)
File "/home/wy/anaconda3/envs/debug_vae/lib/python2.7/site-packages/msgpackrpc/session.py", line 41, in call
return self.send_request(method, args).get()
File "/home/wy/anaconda3/envs/debug_vae/lib/python2.7/site-packages/msgpackrpc/future.py", line 45, in get
raise error.RPCError(self._error)
msgpackrpc.error.RPCError: rpclib: function 'enableApiControl' (called with 2 arg(s)) threw an exception. The exception is not derived from std::exception. No further information available.

I'm using:

aisimdroneracingvae-1.0.0
msgpack-rpc-python-0.4.1
numpy-1.16.4
tornado-4.5.3

How to change env.pak file

I have an issue with the env.pak file.
I deploy the project and successfully run the code, then I want to change the soccer.pak to my own env.pak. How to do this? I found some same parts between this project and the drone race project which has three envs, then I unpack the zhangjiaji.pak file, change a little number of files and load the env sucessfully. But when I load my own .pak file, I always failed.This is the part of AirSimExe.log:

[2020.05.14-02.22.06:828][277]LogOutputDevice: Warning:

Script Stack (0 frames):

[2020.05.14-02.22.06:832][277]LogCore: Error: appError called: Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:/home/madratman/projects/UnrealEngine4.22/UnrealEngine/Engine/Source/Runtime/Core/Public/Containers/Array.h] [Line: 611]

[2020.05.14-02.22.06:842][277]LogCore: === Critical error: ===
Unhandled Exception: SIGSEGV: invalid attempt to read memory at address 0x00000000000033fa

[2020.05.14-02.22.06:842][277]LogCore: Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:/home/madratman/projects/UnrealEngine4.22/UnrealEngine/Engine/Source/Runtime/Core/Public/Containers/Array.h] [Line: 611]

0x0000000002eaee54 AirSimExe!UnknownFunction(0x2caee53)
0x0000000002d3124b AirSimExe!UnknownFunction(0x2b3124a)
0x0000000002cd12b7 AirSimExe!UnknownFunction(0x2ad12b6)
0x0000000002cd10dd AirSimExe!UnknownFunction(0x2ad10dc)
0x0000000005070a6c AirSimExe!UnknownFunction(0x4e70a6b)
0x0000000005080d9a AirSimExe!UnknownFunction(0x4e80d99)
0x000000000508070e AirSimExe!UnknownFunction(0x4e8070d)
0x000000000504aa24 AirSimExe!UnknownFunction(0x4e4aa23)
0x000000000505c390 AirSimExe!UnknownFunction(0x4e5c38f)
0x0000000005067c94 AirSimExe!UnknownFunction(0x4e67c93)
0x0000000004ff9693 AirSimExe!UnknownFunction(0x4df9692)
0x000000000500001c AirSimExe!UnknownFunction(0x4e0001b)
0x0000000002f53a54 AirSimExe!UnknownFunction(0x2d53a53)
0x0000000002f4f0a7 AirSimExe!UnknownFunction(0x2d4f0a6)
0x0000000002f4e9be AirSimExe!UnknownFunction(0x2d4e9bd)
0x0000000002f597d6 AirSimExe!UnknownFunction(0x2d597d5)
0x0000000002f61607 AirSimExe!UnknownFunction(0x2d61606)
0x0000000002f603c5 AirSimExe!UnknownFunction(0x2d603c4)
0x0000000002f6cdc4 AirSimExe!UnknownFunction(0x2d6cdc3)
0x00000000031256bd AirSimExe!UnknownFunction(0x2f256bc)
0x0000000004e6883d AirSimExe!UnknownFunction(0x4c6883c)
0x000000000257864b AirSimExe!UnknownFunction(0x237864a)
0x000000000257ef5a AirSimExe!UnknownFunction(0x237ef59)
0x0000000005d7ae5f AirSimExe!UnknownFunction(0x5b7ae5e)
0x00007f9f4ff97b97 libc.so.6!__libc_start_main(+0xe6)
0x000000000256e029 AirSimExe!UnknownFunction(0x236e028)

[2020.05.14-02.22.06:854][277]LogExit: Executing StaticShutdownAfterError

Thank you!

Cannot run main.py in /datagen/img_generation

when running the main.py file I het this error

Traceback (most recent call last):
  File "main.py", line 15, in <module>
    pose_sampler = PoseSampler(num_samples, dataset_path)
  File "/home/momo/Desktop/GP/datagen/img_generator/PoseSampler.py", line 55, in __init__
    self.configureEnvironment()
  File "/home/momo/Desktop/GP/datagen/img_generator/PoseSampler.py", line 88, in configureEnvironment
    self.tgt_name = self.client.simSpawnObject("gate", "RedGate16x16", Pose(position_val=Vector3r(0,0,15)), 1.5)
  File "/home/momo/miniconda3/envs/GP/lib/python3.7/site-packages/airsim/client.py", line 471, in simSpawnObject
    return self.client.call('simSpawnObject', object_name, asset_name, pose, scale, physics_enabled)
  File "/home/momo/miniconda3/envs/GP/lib/python3.7/site-packages/msgpackrpc/session.py", line 41, in call
    return self.send_request(method, args).get()
  File "/home/momo/miniconda3/envs/GP/lib/python3.7/site-packages/msgpackrpc/future.py", line 45, in get
    raise error.RPCError(self._error)
msgpackrpc.error.RPCError: rpclib: function 'simSpawnObject' (called with 5 arg(s)) threw an exception. The exception is not derived from std::exception. No further information available.

I am using:

airsim-1.6.0
msgpack-python-0.5.6
msgpack-rpc-python-0.4.1
numpy-1.21.5
opencv-contrib-python-4.5.5.64
tornado-4.5.3

on KDE neon
The airsim binaries on google drive run fine.

Question regarding RL techniques used

Good afternoon,

I have been reading your paper and going through your code, and the machine learning technique used here still remains slightly unclear to me, could you clarify that? Otherwise congrats, impressive work!

Modify gates' characteristic in cmvae data generation

Hi there,

After reading your paper, I am really interested to use CM-VAE approach to estimate the gate post w.r.t to the quad-rotors.
Also, I plan to try it on the Game of Drones map. But in that case, I will need to modify the shape/ color of the gate.
Could you please let me know if it is possible to do so?

Thanks

How can I train the model efficiently?

Hi,

I've tried to train the model using train_cmvae.py and the 50k dataset on both my personal linux laptop as well as a dedicated DL machine. However, in both cases the training only occurs on my CPU and does not make use of the GPU.

As a result, the process is killed after some time after exceeding available memory on my laptop. The training runs very slowly on the DL machine, completing 1 epoch after several minutes. Since the base parameters are BATCH_SIZE=32 and EPOCHS=10000, at this rate it would take over half a year to finish training.

Could you please mention how you were able to train the model or how I can train it faster?

Thank you.

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.