Code for "Adversarial Motion Priors Make Good Substitutes for Complex Reward Functions"

Overview

Adversarial Motion Priors Make Good Substitutes for Complex Reward Functions

Codebase for the "Adversarial Motion Priors Make Good Substitutes for Complex Reward Functions" project. This repository contains the code necessary to ground agent skills using small amounts of reference data (4.5 seconds). All experiments are performed using the A1 robot from Unitree. This repository is based off of Nikita Rudin's legged_gym repo, and enables us to train policies using Isaac Gym.

Maintainer: Alejandro Escontrela Affiliation: University of California at Berkeley Contact: [email protected]

Useful Links

Project website: https://bit.ly/3hpvbD6 Paper: https://drive.google.com/file/d/1kFm79nMmrc0ZIiH0XO8_HV-fj73agheO/view?usp=sharing

Installation

  1. Create a new python virtual env with python 3.6, 3.7 or 3.8 (3.8 recommended). i.e. with conda:
    • conda create -n amp_hw python==3.8
    • conda activate amp_hw
  2. Install pytorch 1.10 with cuda-11.3:
    • pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 tensorboard==2.8.0 pybullet==3.2.1 opencv-python==4.5.5.64 torchaudio==0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
  3. Install Isaac Gym
    • Download and install Isaac Gym Preview 3 (Preview 2 will not work!) from https://developer.nvidia.com/isaac-gym
    • cd isaacgym/python && pip install -e .
    • Try running an example cd examples && python 1080_balls_of_solitude.py
    • For troubleshooting check docs isaacgym/docs/index.html)
  4. Install rsl_rl (PPO implementation)
    • Clone this repository
    • cd AMP_for_hardware/rsl_rl && pip install -e .
  5. Install legged_gym
    • cd ../ && pip install -e .

CODE STRUCTURE

  1. Each environment is defined by an env file (legged_robot.py) and a config file (legged_robot_config.py). The config file contains two classes: one conatianing all the environment parameters (LeggedRobotCfg) and one for the training parameters (LeggedRobotCfgPPo).
  2. Both env and config classes use inheritance.
  3. Each non-zero reward scale specified in cfg will add a function with a corresponding name to the list of elements which will be summed to get the total reward. The AMP reward parameters are defined in LeggedRobotCfgPPO, as well as the path to the reference data.
  4. Tasks must be registered using task_registry.register(name, EnvClass, EnvConfig, TrainConfig). This is done in envs/__init__.py, but can also be done from outside of this repository.
  5. Reference data can be found in the datasets folder.

Usage

  1. Train:
    ```python legged_gym/scripts/train.py --task=a1_amp``
    • To run on CPU add following arguments: --sim_device=cpu, --rl_device=cpu (sim on CPU and rl on GPU is possible).
    • To run headless (no rendering) add --headless.
    • Important: To improve performance, once the training starts press v to stop the rendering. You can then enable it later to check the progress.
    • The trained policy is saved in AMP_for_hardware/logs/<experiment_name>/<date_time>_<run_name>/model_<iteration>.pt. Where <experiment_name> and <run_name> are defined in the train config.
    • The following command line arguments override the values set in the config files:
    • --task TASK: Task name.
    • --resume: Resume training from a checkpoint
    • --experiment_name EXPERIMENT_NAME: Name of the experiment to run or load.
    • --run_name RUN_NAME: Name of the run.
    • --load_run LOAD_RUN: Name of the run to load when resume=True. If -1: will load the last run.
    • --checkpoint CHECKPOINT: Saved model checkpoint number. If -1: will load the last checkpoint.
    • --num_envs NUM_ENVS: Number of environments to create.
    • --seed SEED: Random seed.
    • --max_iterations MAX_ITERATIONS: Maximum number of training iterations.
  2. Play a trained policy:
    python legged_gym/scripts/play.py --task=a1_amp
    • By default the loaded policy is the last model of the last run of the experiment folder.
    • Other runs/model iteration can be selected by setting load_run and checkpoint in the train config.
  3. Record video of a trained policy python legged_gym/scripts/record_policy.py --task=a1_amp
    • This saves a video of the in the base directory.

Adding a new environment

The base environment legged_robot implements a rough terrain locomotion task. The corresponding cfg does not specify a robot asset (URDF/ MJCF) and no reward scales.

  1. Add a new folder to envs/ with '<your_env>_config.py, which inherit from an existing environment cfgs
  2. If adding a new robot:
    • Add the corresponding assets to resourses/.
    • In cfg set the asset path, define body names, default_joint_positions and PD gains. Specify the desired train_cfg and the name of the environment (python class).
    • In train_cfg set experiment_name and run_name
  3. (If needed) implement your environment in <your_env>.py, inherit from an existing environment, overwrite the desired functions and/or add your reward functions.
  4. Register your env in isaacgym_anymal/envs/__init__.py.
  5. Modify/Tune other parameters in your cfg, cfg_train as needed. To remove a reward set its scale to zero. Do not modify parameters of other envs!

Troubleshooting

  1. If you get the following error: ImportError: libpython3.8m.so.1.0: cannot open shared object file: No such file or directory, do: sudo apt install libpython3.8

Known Issues

  1. The contact forces reported by net_contact_force_tensor are unreliable when simulating on GPU with a triangle mesh terrain. A workaround is to use force sensors, but the force are propagated through the sensors of consecutive bodies resulting in an undesireable behaviour. However, for a legged robot it is possible to add sensors to the feet/end effector only and get the expected results. When using the force sensors make sure to exclude gravity from trhe reported forces with sensor_options.enable_forward_dynamics_forces. Example:
    sensor_pose = gymapi.Transform()
    for name in feet_names:
        sensor_options = gymapi.ForceSensorProperties()
        sensor_options.enable_forward_dynamics_forces = False # for example gravity
        sensor_options.enable_constraint_solver_forces = True # for example contacts
        sensor_options.use_world_frame = True # report forces in world frame (easier to get vertical components)
        index = self.gym.find_asset_rigid_body_index(robot_asset, name)
        self.gym.create_asset_force_sensor(robot_asset, index, sensor_pose, sensor_options)
    (...)

    sensor_tensor = self.gym.acquire_force_sensor_tensor(self.sim)
    self.gym.refresh_force_sensor_tensor(self.sim)
    force_sensor_readings = gymtorch.wrap_tensor(sensor_tensor)
    self.sensor_forces = force_sensor_readings.view(self.num_envs, 4, 6)[..., :3]
    (...)

    self.gym.refresh_force_sensor_tensor(self.sim)
    contact = self.sensor_forces[:, :, 2] > 1.
Comments
  • ValueError: Expected parameter loc (Tensor of shape (32880, 12)) of distribution Normal(loc: torch.Size([32880, 12]), scale: torch.Size([32880, 12])) to satisfy the constraint Real(), but found invalid values:

    ValueError: Expected parameter loc (Tensor of shape (32880, 12)) of distribution Normal(loc: torch.Size([32880, 12]), scale: torch.Size([32880, 12])) to satisfy the constraint Real(), but found invalid values:

    Describe the bug 'ValueError: Expected parameter loc (Tensor of shape (32880, 12)) of distribution Normal(loc: torch.Size([32880, 12]), scale: torch.Size([32880, 12])) to satisfy the constraint Real(), but found invalid values: tensor([[nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], ..., [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan]], device='cuda:0', grad_fn=)`

    To Reproduce Execute python legged_gym/scripts/train.py --task=a1_amp This error occurs.

    Expected behavior The normal record and no bugs.

    System (please complete the following information): Commit: https://github.com/Alescontrela/AMP_for_hardware/commit/8f3b9caa6376b81b36d5242c45a297f79ee5348c OS: Ubuntu 18.04 GPU: GeForce GTX 1080 Ti CUDA: 11.1 GPU Driver: 510.47.03

    bug 
    opened by COST-97 7
  • Race Data

    Race Data

    Describe the bug I check the website https://sites.google.com/berkeley.edu/amp-in-real/home experiment result, from the result "Informal race between Fu et al.* (left) and AMP Policy (right)", we could see A1 could run at a very high speed, but I check the trot0 and trot1 data from datasets file, it seems these data are not related to race, if yes, could you provide motion data related to race experiment? Thanks!

    To Reproduce Steps to reproduce the behavior:

    1. Execute ./path/script arg1 arg2
    2. Then ...
    3. See error: ...

    Expected behavior A clear and concise description of what you expected to happen.

    System (please complete the following information):

    • Commit: [e.g. 8f3b9ca]
    • OS: [e.g. Ubuntu 20.04]
    • GPU: [e.g. RTX 2060 Super]
    • CUDA: [e.g. 11.4]
    • GPU Driver: [e.g. 470.82.01]

    Additional context Add any other context about the problem here.

    enhancement 
    opened by JeffXu1 1
  • No trained file

    No trained file

    Describe the bug There is no logs file.

    To Reproduce Steps to reproduce the behavior:

    1. Execute python legged_gym/scripts/play.py --task=a1_amp
    2. Then report no logs run file I assume that you didn't put the saved agent policy model file which you used in the code file, could you release it? And could you give a guide how to implement the code in Unitree A1? I will appreciate it very much! .
    bug 
    opened by JeffXu1 1
  • RuntimeError: vstack expects a non-empty TensorList

    RuntimeError: vstack expects a non-empty TensorList

    Describe the bug There is something wrong when I run the train.py.

    To Reproduce Steps to reproduce the behavior:

    1. Execute ./legged_gym/scripts/train.py task=a1_amp
    2. See error: RuntimeError: vstack expects a non-empty TensorList

    Expected behavior I want to run the demo of train.py.

    System (please complete the following information):

    • Commit: [a8b6f44]
    • OS: [e.g. Ubuntu 18.04]
    • GPU: [e.g. RTX 3090]
    • CUDA: [e.g. 11.4]
    • GPU Driver: [e.g. 470.82.01]

    Additional context Add any other context about the problem here.

    bug 
    opened by cwjwudi 1
  • What's the hopturn task config setting?

    What's the hopturn task config setting?

    Hi @Alescontrela I'm trying to reproduce the hopturn result using the provided hopturn dataset, I'm wondering what's your training setting for the hopturn task, if possible can you share the config used for the hopturn task?

    opened by yangyichu 0
  • Question about motion data.

    Question about motion data.

    Hi Alescontrela, Thanks for your great job on amp_for_hardware! I can train it on a1, it is awesome. I have a question that I find that your mocap data is txt file and issacgym offical data, ase/amp mocap data is npy file. I want to try humanoid motion data on your repo. could you tell me how to translate that data? I noticed that your code AMP_LOADER has 'reorder_from_pybullet_to_isaac', is that translated by pybullet? Thanks!

    opened by zituka 1
  • Low speed for training

    Low speed for training

    Describe the bug Hi, the problem I meet now is the low speed for training. I remember you presented a result that the training was finished in 20 minutes, while executing the program by myself costed about 9-10 days. Do you know what happened with it? And what were commands you used in the terminal when you operated the program?

    To Reproduce Steps to reproduce the behavior:

    1. cd AMP_for_hardware/
    2. Then use ‘’’python legged_gym/scripts/train.py —task=a1_amp —headless —num_envs=1000 ‘’’
    3. The terminal shows Iteration time is about 1.76s, ETA is about 760000s

    Expected behavior I hope I can reproduce your result that spending about 20minutes finishes the train. Do you know what happened with it that the training speed is too slow? And what were commands you input to the terminal when you operated the program?

    System (please complete the following information):

    • OS: Centos7
    • GPU: Intel A100(80G), Note: the usage is 37% when I operate the train.py
    • CUDA: 11.3
    • GPU Driver: 510.47.03
    bug 
    opened by Joe618 0
Owner
Alejandro Escontrela
On the first epoch.
Alejandro Escontrela
Write reproducible code for getting and processing ChEMBL

chembl_downloader Don't worry about downloading/extracting ChEMBL or versioning - just use chembl_downloader to write code that knows how to download

Charles Tapley Hoyt 34 Dec 25, 2022
python code used to download all images contained in a facebook uid , the uid can be profile,group,fanpage

python code used to download all images contained in a facebook uid , the uid can be profile,group,fanpage

VVHai 2 Dec 21, 2021
Code to scrape , download and upload to youtube daily

Youtube_Automated_Channel Code to scrape , download and upload to youtube daily INSTRUCTIONS Download the Github Repository Download and install Pytho

Atsiksdong 2 Dec 19, 2021
This repository contains code for a youtube-dl GUI written in PyQt.

youtube-dl-GUI This repository contains code for a youtube-dl GUI written in PyQt. It is based on youtube-dl which is a Video downloading script maint

M.Yasoob Ullah Khalid ☺ 191 Jan 2, 2023
Source code of paper: "HRegNet: A Hierarchical Network for Efficient and Accurate Outdoor LiDAR Point Cloud Registration".

HRegNet: A Hierarchical Network for Efficient and Accurate Outdoor LiDAR Point Cloud Registration Environments The code mainly requires the following

Intelligent Sensing, Perception and Computing Group 3 Oct 6, 2022
code for paper"3D reconstruction method based on a generative model in continuous latent space"

PyTorch implementation of 3D-VGT(3D-VAE-GAN-Transformer) This repository contains the source code for the paper "3D reconstruction method based on a g

Tong 5 Apr 25, 2022
Code for "Temporal Difference Learning for Model Predictive Control"

Temporal Difference Learning for Model Predictive Control Original PyTorch implementation of TD-MPC from Temporal Difference Learning for Model Predic

Nicklas Hansen 156 Jan 3, 2023
GTK4 + Python tutorial with code examples

Taiko's GTK4 Python tutorial Wanna make apps for Linux but not sure how to start with GTK? This guide will hopefully help! The intent is to show you h

null 190 Jan 8, 2023
This is discord nitro code generator and checker made with python. This will generate nitro codes and checks if the code is valid or not. If code is valid then it will print the code leaving 2 lines and if not then it will print '*'.

Discord Nitro Generator And Checker ⚙️ Rᴜɴ Oɴ Rᴇᴘʟɪᴛ ??️ Lᴀɴɢᴜᴀɢᴇs Aɴᴅ Tᴏᴏʟs If you are taking code from this repository without a fork, then atleast

Vɪɴᴀʏᴀᴋ Pᴀɴᴅᴇʏ 37 Jan 7, 2023
This is the official source code for SLATE. We provide the code for the model, the training code, and a dataset loader for the 3D Shapes dataset. This code is implemented in Pytorch.

SLATE This is the official source code for SLATE. We provide the code for the model, the training code and a dataset loader for the 3D Shapes dataset.

Gautam Singh 66 Dec 26, 2022
IDE allow you to refactor code, Baron allows you to write refactoring code.

Introduction Baron is a Full Syntax Tree (FST) library for Python. By opposition to an AST which drops some syntax information in the process of its c

Python Code Quality Authority 278 Dec 29, 2022
Various code metrics for Python code

Radon Radon is a Python tool that computes various metrics from the source code. Radon can compute: McCabe's complexity, i.e. cyclomatic complexity ra

Michele Lacchia 1.4k Jan 7, 2023
Code examples for my Write Better Python Code series on YouTube.

Write Better Python Code This repository contains the code examples used in my Write Better Python Code series published on YouTube: https:/

null 858 Dec 29, 2022
Django project starter on steroids: quickly create a Django app AND generate source code for data models + REST/GraphQL APIs (the generated code is auto-linted and has 100% test coverage).

Create Django App ?? We're a Django project starter on steroids! One-line command to create a Django app with all the dependencies auto-installed AND

imagine.ai 68 Oct 19, 2022
TensorFlow code for the neural network presented in the paper: "Structural Language Models of Code" (ICML'2020)

SLM: Structural Language Models of Code This is an official implementation of the model described in: "Structural Language Models of Code" [PDF] To ap

null 73 Nov 6, 2022
Code to use Augmented Shapiro Wilks Stopping, as well as code for the paper "Statistically Signifigant Stopping of Neural Network Training"

This codebase is being actively maintained, please create and issue if you have issues using it Basics All data files are included under losses and ea

Justin Terry 32 Nov 9, 2021
Inference code for "StylePeople: A Generative Model of Fullbody Human Avatars" paper. This code is for the part of the paper describing video-based avatars.

NeuralTextures This is repository with inference code for paper "StylePeople: A Generative Model of Fullbody Human Avatars" (CVPR21). This code is for

Visual Understanding Lab @ Samsung AI Center Moscow 18 Oct 6, 2022
A code generator from ONNX to PyTorch code

onnx-pytorch Generating pytorch code from ONNX. Currently support onnx==1.9.0 and torch==1.8.1. Installation From PyPI pip install onnx-pytorch From

Wenhao Hu 94 Jan 6, 2023
SCodeScanner stands for Source Code scanner where the user can scans the source code for finding the Critical Vulnerabilities.

The SCodeScanner stands for Source Code Scanner, where you can scan your source code files like PHP and get identify the vulnerabilities inside it. The tool can use by Pentester, Developer to quickly identify the weakness.

null 136 Dec 13, 2022
This is the code for our KILT leaderboard submission to the T-REx and zsRE tasks. It includes code for training a DPR model then continuing training with RAG.

KGI (Knowledge Graph Induction) for slot filling This is the code for our KILT leaderboard submission to the T-REx and zsRE tasks. It includes code fo

International Business Machines 72 Jan 6, 2023