Giter VIP home page Giter VIP logo

lets-do-irl's Introduction

Let's do Inverse RL

image

Introduction

This repository contains PyTorch (v0.4.1) implementations of Inverse Reinforcement Learning (IRL) algorithms.

  • Apprenticeship Learning via Inverse Reinforcement Learning [2]
  • Maximum Entropy Inverse Reinforcement Learning [4]
  • Generative Adversarial Imitation Learning [5]
  • Variational Discriminator Bottleneck: Improving Imitation Learning, Inverse RL, and GANs by Constraining Information Flow [6]

We have implemented and trained the agents with the IRL algorithms using the following environments.

For reference, reviews of below papers related to IRL (in Korean) are located in Let's do Inverse RL Guide.

Table of Contents

Mountain car

We have implemented APP, MaxEnt using Q-learning as RL step in MountainCar-v0 environment.

1. Information

2. Expert's demonstrations

Navigate to expert_demo.npy in lets-do-irl/mountaincar/app/expert_demo or lets-do-irl/mountaincar/maxent/expert_demo.

Shape of expert's demonstrations is (20, 130, 3); (number of demonstrations, length of demonstrations, states and actions of demonstrations)

If you make demonstrations, Navigate to make_expert.py in lets-do-irl/mountaincar/app/expert_demo or lets-do-irl/mountaincar/maxent/expert_demo.

3. Train & Test

APP

Navigate to lets-do-irl/mountaincar/app folder.

Train the agent wtih APP without rendering.

python train.py

If you want to test APP, Test the agent with the saved model app_q_table.npy in app/results folder.

python test.py

MaxEnt

Navigate to lets-do-irl/mountaincar/maxent folder.

Train the agent wtih MaxEnt without rendering.

python train.py

If you want to test MaxEnt, Test the agent with the saved model maxent_q_table.npy in maxent/results folder.

python test.py

4. Trained Agent

We have trained the agents with two different IRL algortihms using MountainCar-v0 environment.

Algorithms Scores / Episodes GIF
APP app
MaxEnt maxent

Mujoco Hopper

We have implemented GAIL, VAIL using PPO as RL step in Hopper-v2 environment.

1. Installation

2. Expert's demonstrations

Navigate to expert_demo.p in lets-do-irl/mujoco/gail/expert_demo or lets-do-irl/mujoco/vail/expert_demo.

Shape of expert's demonstrations is (50000, 14); (number of demonstrations, states and actions of demonstrations)

We used demonstrations that get scores between about 2200 and 2600 on average.

If you want to make demonstrations, Navigate to main.py in lets-do-irl/mojoco/ppo folder.

Also, you can see detailed implementation story (in Korean) of PPO in PG Travel implementation story.

3. Train & Test

GAIL

Navigate to lets-do-irl/mujoco/gail folder.

Train the agent wtih GAIL without rendering.

python main.py

If you want to Continue training from the saved checkpoint,

python main.py --load_model ckpt_4000_gail.pth.tar
  • Note that ckpt_4000_gail.pth.tar file should be in the mujoco/gail/save_model folder.

If you want to test GAIL, Test the agent with the saved model ckpt_4000_gail.pth.tar in the mujoco/gail/save_model folder.

python test.py --load_model ckpt_4000_gail.pth.tar
  • Note that ckpt_4000_gail.pth.tar file should be in the mujoco/gail/save_model folder.

VAIL

Navigate to lets-do-irl/mujoco/vail folder.

Train the agent wtih VAIL without rendering.

python main.py

If you want to Continue training from the saved checkpoint,

python main.py --load_model ckpt_4000_vail.pth.tar
  • Note that ckpt_4000_vail.pth.tar file should be in the mujoco/vail/save_model folder.

If you want to test VAIL, Test the agent with the saved model ckpt_4000_vail.pth.tar in the mujoco/vail/save_model folder.

python test.py --load_model ckpt_4000_vail.pth.tar
  • Note that ckpt_4000_vail.pth.tar file should be in the mujoco/vail/save_model folder.

4. Tensorboard

Note that the results of trainings are automatically saved in logs folder. TensorboardX is the Tensorboard-like visualization tool for Pytorch.

Navigate to the lets-do-irl/mujoco/gail or lets-do-irl/mujoco/vail folder.

tensorboard --logdir logs

5. Trained Agent

We have trained the agents with two different IRL algortihms using Hopper-v2 environment.

Algorithms Scores / Iterations (total sample size : 2048)
PPO (to compare) ppo
GAIL gail
VAIL vail
Total total

Reference

We referenced the codes from below repositories.

Implementation team members

Dongmin Lee (project manager) : Github, Facebook

Seungje Yoon : Github, Facebook

Seunghyun Lee : Github, Facebook

Geonhee Lee : Github, Facebook

lets-do-irl's People

Contributors

clyde21c avatar dongminlee94 avatar geonhee-lee avatar sjyoondeltar 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

lets-do-irl's Issues

Testing model

Hi sir
I finished training the robot mobile model, need help to understand the testing, i used SAC algorithm
Could we make a deal about that please

RuntimeError while running VAIL

The main runs on pytorch 0.4.1 but it fails for pytorch 1.6.0.

Running the main.py for VAIL implementation I get a runtime error about a replacement in place of a variable.

I put here the stack trace.

Error detected in AddmmBackward. Traceback of forward call that caused the error:
File "/Users/lorenzoterenzi/Downloads/lets-do-irl-master/mujoco/vail/main.py", line 185, in
main()
File "/Users/lorenzoterenzi/Downloads/lets-do-irl-master/mujoco/vail/main.py", line 162, in main
train_actor_critic(actor, critic, memory, actor_optim, critic_optim, args)
File "/Users/lorenzoterenzi/Downloads/lets-do-irl-master/mujoco/vail/train_model.py", line 75, in train_actor_critic
values = critic(inputs)
File "/Users/lorenzoterenzi/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/Users/lorenzoterenzi/Downloads/lets-do-irl-master/mujoco/vail/model.py", line 36, in forward
v = self.fc3(x)
File "/Users/lorenzoterenzi/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/Users/lorenzoterenzi/.local/lib/python3.7/site-packages/torch/nn/modules/linear.py", line 91, in forward
return F.linear(input, self.weight, self.bias)
File "/Users/lorenzoterenzi/.local/lib/python3.7/site-packages/torch/nn/functional.py", line 1674, in linear
ret = torch.addmm(bias, input, weight.t())
(function print_stack)
Traceback (most recent call last):
File "/Users/lorenzoterenzi/Downloads/lets-do-irl-master/mujoco/vail/main.py", line 185, in
main()
File "/Users/lorenzoterenzi/Downloads/lets-do-irl-master/mujoco/vail/main.py", line 162, in main
train_actor_critic(actor, critic, memory, actor_optim, critic_optim, args)
File "/Users/lorenzoterenzi/Downloads/lets-do-irl-master/mujoco/vail/train_model.py", line 101, in train_actor_critic
loss.backward()
File "/Users/lorenzoterenzi/.local/lib/python3.7/site-packages/torch/tensor.py", line 185, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "/Users/lorenzoterenzi/.local/lib/python3.7/site-packages/torch/autograd/init.py", line 127, in backward
allow_unreachable=True) # allow_unreachable flag
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [100, 1]], which is output 0 of TBackward, is at version 2; expected version 1 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!

running test.py for VAIL

Hello,

I am running the VAIL example as explained in the README.

main.py works as expected.

When running test (e.g., as written: python test.py --load_model ckpt_4000_vail.pth.tar), there is an import error.

Specifically:

from utils.running_state import ZFilter

there is no file running_state. In the main.py the running state was defined from Zfilter.

Some questions or bugs?

Hi,
Thanks for you providing so nice code.
But when I try to play with "lets-do-irl/mujoco/vail", It make me very confused that the code in train_model.py:
vdb_loss = criterion(learner, torch.ones((states.shape[0], 1))) + \ criterion(expert, torch.zeros((demonstrations.shape[0], 1))) + \ beta * bottleneck_loss
I think this should be:
vdb_loss = criterion(learner, torch.zeros((states.shape[0], 1))) + \ criterion(expert, torch.ones((demonstrations.shape[0], 1))) + \ beta * bottleneck_loss
. In other words, the learner should be pushed to zeros, and expert should be pushed to ones, isn't it? Or both is fine?

By the way, the code in the same file:
beta = max(0, beta + args.alpha_beta * bottleneck_loss)
If beta equals beta + args.alpha_beta * bottleneck_loss, at the next time backward, there will report a bug about beta, which is modified by a inplace operation.

RunTimeError with vail

when i run main.py ,i met some problem:
Traceback (most recent call last):
File "main.py", line 186, in
main()
File "main.py", line 159, in main
expert_acc, learner_acc = train_vdb(vdb, memory, vdb_optim, demonstrations, 0, args)
File "/home/parallels/workspace/lets-do-irl-master/mujoco/vail/train_model.py", line 37, in train_vdb
vdb_loss.backward(retain_graph=True)
File "/home/parallels/anaconda3/envs/mujoco/lib/python3.8/site-packages/torch/_tensor.py", line 487, in backward
torch.autograd.backward(
File "/home/parallels/anaconda3/envs/mujoco/lib/python3.8/site-packages/torch/autograd/init.py", line 197, in backward
Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [100, 4]], which is output 0 of AsStridedBackward0, is at version 35; expected version 34 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!

Can go beyond the code line " idx_to_state"

state_idx = idx_to_state(env, state)

how can I fix this?

idx_to_state
position_idx = int((state[0] - env_low[0]) / env_distance[0])

TypeError: only size-1 arrays can be converted to Python scalars

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.