Goal-conditioned Imitation Learning
Abstract
Designing rewards for Reinforcement Learning (RL) is challenging because it needs to convey the desired task, be efﬁcient to optimize, and be easy to compute.
The latter is particularly problematic when applying RL to robotics, where detecting whether the desired conﬁguration is reached might require considerable supervision and instrumentation.
Furthermore, we are often interested in being able to reach a wide range of conﬁgurations, hence setting up a different reward every time might be unpractical.
Methods like Hindsight Experience Replay (HER) have recently shown promise to learn policies able to reach many goals, without the need of a reward.
Unfortunately, without tricks like resetting to points along the trajectory, HER might take a very long time to discover how to reach certain areas of the state-space.
In this work we investigate different approaches to incorporate demonstrations to drastically speed up the convergence to a policy able to reach any goal, also surpassing the performance of an agent trained with other Imitation Learning algorithms.
Furthermore, our method can be used when only trajectories without expert actions are available, which can leverage kinestetic or third person demonstration.
1. Introduction
Reinforcement Learning (RL) has shown impressive results in a plethora of simulated tasks, ranging from attaining super-human performance in video-games (Mnih et al., 2015; Vinyals et al., 2019) and board-games (Silver et al., 2017), to learning complex locomotion behaviors (Heess et al., 2017; Florensa et al., 2017a).
Nevertheless, these successes are shyly echoed in real world robotics (Riedmiller et al., 2018; Zhu et al., 2018a).
This is due to the difﬁculty of setting up the same learning environment that is enjoyed in simulation.
One of the critical assumptions that are hard to obtain in the real world are the access to a reward function.
Self-supervised methods have the power to overcome this limitation.
A very versatile and reusable form of self-supervision for robotics is to learn how to reach any previously observed state upon demand.
This problem can be formulated as training a goal-conditioned policy (Kaelbling, 1993; Schaul et al., 2015) that seeks to obtain the indicator reward of having the observation exactly match the goal.
Such a reward does not require any additional instrumentation of the environment beyond the sensors the robot already has.
But in practice, this reward is never observed because in continuous spaces like the ones in robotics, the exact same observation is never observed twice.
Luckily, if we are using an off-policy RL algorithm (Lillicrap et al., 2015; Haarnoja et al., 2018), we can “relabel" a collected trajectory by replacing its goal by a state actually visited during that trajectory, therefore observing the indicator reward as often as we wish.
This method was introduced as Hindsight Experience Replay (Andrychowicz et al., 2017) or HER.
In theory these approaches could learn how to reach any goal, but the breadth-ﬁrst nature of the algorithm makes that some areas of the space take a long time to be learned (Florensa et al., 2018b).
This is specially challenging when there are bottlenecks between different areas of the statespace, and random motion might not traverse them easily (Florensa et al., 2017b).
Some practical examples of this are pick-and-place, or navigating narrow corridors between rooms, as illustrated in Fig.
5 in appendix depicting the diverse set of environments we work with.
In both cases a speciﬁc state needs to be reached (grasp the object, or enter the corridor) before a whole new area of the space is discovered (placing the object, or visiting the next room).
This problem could be addressed by engineering a reward that guides the agent towards the bottlenecks, but this defeats the purpose of trying to learn without direct reward supervision.
In this work we study how to leverage a few demonstrations that traverse those bottlenecks to boost the learning of goal-reaching policies.
Learning from Demonstrations, or Imitation Learning (IL), is a well-studied ﬁeld in robotics (Kalakrishnan et al., 2009;
Ross et al., 2011; Bojarski et al., 2016).
In many cases it is easier to obtain a few demonstrations from an expert than to provide a good reward that describes the task.
Most of the previous work on IL is centered around trajectory following, or doing a single task.
Furthermore it is limited by the performance of the demonstrations, or relies on engineered rewards to improve upon them.
In this work we study how
IL methods can be extended to the goal-conditioned setting, and show that combined with techniques like HER it can outperform the demonstrator without the need of any additional reward.
We also investigate how the different methods degrade when the trajectories of the expert become less optimal, or less abundant.
Finally, the method we develop is able to leverage demonstrations that do not include the expert actions.
This is very convenient in practical robotics where demonstrations might have been given by a motion planner, by kinestetic demonstrations (moving the agent externally, and not by actually actuating it), or even by another agent.
To our knowledge, this is the ﬁrst framework that can boost goal-conditioned policy learning with only state demonstrations.
2. Preliminaries
We deﬁne a discrete-time ﬁnite-horizon discounted
Markov decision process (MDP) by a tuple M = ( S , A , P , r, ρ 0 , γ, H ) , where S is a state set, A is an action set, P : S ×
A × S → R + is a transition probability distribution, γ ∈ [0 , 1] is a discount factor, and H is the horizon.
Our objective is to ﬁnd a stochastic policy π θ that maximizes the expected discounted reward within the
MDP, η ( π θ ) =
E τ [ (cid:80) Tt =
γ t r ( s t , a t , s t +1 )] .
We denote by τ =
( s 0 , a 0 , ..., ) the entire state-action trajectory, where s 0 ∼ ρ 0 ( s 0 ) , a t ∼ π θ ( a t
| s t ) , and s t +1 ∼ P ( s t +1 | s t , a t ) .
In the goal-conditioned setting that we use here, the policy and the reward are also conditioned on a “goal" g ∈ S .
The reward is r ( s t , a t , s t +1 , g )
= 1 (cid:2) s t
+1 =
= g (cid:3) , and hence the return is the γ h , where h is the number of time-steps to the goal.
Given that the transition probability is not affected by the goal, g can be “relabeled" in hindsight, so a transition ( s t , a t , s t +1 , g, r = 0) can be treated as ( s t , a t , s t +1 , g (cid:48)
=
s t +1 , r = 1) .
Finally, we also assume access to D trajectories (cid:8) ( s j 0 , a j 0 , s j 1 , ... )
(cid:9) D j =
that were collected by an expert attempting to reach a goal g j sampled uniformly among the feasible goals.
Those trajectories must be approximately geodesics, meaning that the actions are taken such that the goal is reached as fast as possible.
3. Demonstrations in Goal-conditioned tasks
In this section we describe the different algorithms we compare to pure Hindsight Experience Replay (Andrychowicz et al., 2017).
See the Appendix to prior work on adding a Behavioral Cloning loss to the policy update as in (Nair et al.,
[Figure] [Figure]
Here we propose a novel expert relabeling technique, we formulate for the ﬁrst time a goal-conditioned GAIL algorithm, and propose a method to train it with state-only demonstrations.
3.1. Relabeling the expert
The expert trajectories are collected by asking the expert to reach a speciﬁc goal g j .
But they are also valid trajectories to reach any other state visited within the demonstration!
This is the key motivating insight to propose a new type of relabeling: if we have the transitions ( s jt , a jt , s jt +1 , g j ) in a demonstration, we can also consider the transition ( s jt , a jt , s jt +1 , g (cid:48)
=
s jt + k ) as also coming from the expert!
This can be understood as a type of data augmentation leveraging the assumption that the tasks we work on are quasi-static.
It will be particularly effective when not many demonstrations are available.
In Fig.
1 we compare the ﬁnal performance of two agents for Four Rooms environment, one trained with pure Behavioral Cloning, and the other one also using expert relabeling.
3.2. Goal-conditioned GAIL with Hindsight
The compounding error in Behavioral Cloning might make the policy deviate arbitrarily from the demonstrations, and it requires too many demonstrations when the state dimension increases.
The ﬁrst problem is less severe in our goalconditioned case because in fact we do want to visit and be able to purposefully reach all states, even the ones that the expert did not visited.
But the second drawback will become pressing when attempting to scale this method to practical robotics tasks where the observations might be high-dimensional sensory input like images.
Both problems can be mitigated by using other Imitation Learning algorithms that can leverage additional rollouts collected by the learning agent in a self-supervised manner, like GAIL (Ho & Ermon, 2016).
In this section we extend the formulation of GAIL to tackle goal-conditioned tasks, and then we detail how it can be combined with HER (Andrychowicz et al., 2017), which allows to outperform the demonstrator and generalize to all goals.
We call this algorithm goal-GAIL .
First of all, the discriminator needs to also be conditioned on the goal D ψ ( a, s, g ) .
Once the discriminator is ﬁtted, we can run our favorite RL algorithm on the reward log D ψ ( a ht , s ht , g h ) .
In our case we used the offpolicy algorithm DDPG (Lillicrap et al., 2015) to allow for the relabeling techniques outlined above.
In the goalconditioned case we also supplement with the indicator reward r ht = 1 (cid:2) s ht
+
= =
g h (cid:3) .
This combination is slightly tricky because now the ﬁtted Q φ does not have the same clear interpretation it has when only one of the two rewards is used (Florensa et al., 2018a) .
Nevertheless, both rewards are pushing the policy towards the goals, so it shouldn’t be too conﬂicting.
Furthermore, to avoid any drop in ﬁnal performance, the weight of the reward coming from GAIL ( δ GAIL ) can be annealed.
See Appendix for details.
3.3. Use of state-only Demonstrations
Both Behavioral Cloning and GAIL use state-action pairs from the expert.
This limits the use of the methods, combined or not with HER, to setups where the exact same agent was actuated to reach different goals.
Nevertheless, much more data could be cheaply available if the action was not required.
For example, kinestetic demonstration or third-person imitation (Stadie et al., 2017).
The main insight we have here is that we can replace the action in the GAIL formulation by the next state s (cid:48) , and in most environments this should be as informative as having access to the action directly.
Intuitively, given a desired goal g , it should be possible to determine if a transition s → s (cid:48) is taking the agent in the right direction.
The loss function to train a discriminator able to tell apart the current agent and demonstrations (always transitioning towards the goal) is simply:
[Equation]
4. Experiments
We are interested in answering the following questions:
Can the use of demonstrations accelerate the learning of goal-conditioned tasks without reward?
Is the Expert Relabeling an efﬁcient way of doing dataaugmentation on the demonstrations?
Can state-only demonstrations be leveraged equally
[Figure]
trajectories
Compared to Behavorial Cloning methods, is GAIL more robust to noise in the expert actions?
We evaluate these questions in two different simulated robotic goal-conditioned tasks that are detailed in the next subsection.
All the results use demonstrations.
All curves have 5 random seeds and
the shaded area
is
one standard deviation 4.1. Tasks
Experiments are conducted in two continuous environments in MuJoCo (Todorov et al., 2012).
The performance metric we use in all our experiments is the percentage of goals in the feasible goal space the agent is able to reach.
Four rooms environment : A point mass is placed in an environment with four rooms connected through small openings.
The action space is continuous and speciﬁes the desired change in state space which corresponds to the goal space.
Pick and Place : A fetch robot needs to pick a block and place it in a desired point in space as described in Nair et al.
The control is four-dimensional, corresponding to a change in position of the end-effector and a change in gripper opening.
The goal space is the position of the block.
4.2. Goal-conditioned Imitation Learning
In goal-conditioned tasks, HER (Andrychowicz et al., 2017) should eventually converge to a policy able to reach any desired goal.
Nevertheless, this might take a long time, specially in environments where there are bottlenecks that need to be traversed before accessing a whole new area of the goal space.
In this section we show how the methods introduced in the previous section can leverage a few demonstrations to improve the convergence speed of HER.
This was already studied for the case of Behavioral Cloning by (Nair et al., 2018), and in this work we show we also get a beneﬁt when using GAIL as the Imitation Learning algorithm.
In both environments, we observe that running GAIL with relabeling (GAIL+HER) considerably outperforms running each of them in isolation.
HER alone has a very slow convergence, although as expected it ends up reaching the same ﬁnal per-
[Figure]
formance if run long enough.
On the other hand GAIL by itself learns fast at the beginning, but its ﬁnal performance is capped.
This is because despite collecting more samples on the environment, those come with no reward of any kind indicating what is the task to perform (reach the given goals).
Therefore, once it has extracted all the information it can from the demonstrations it cannot keep learning and generalize to goals further from the demonstrations.
This is not an issue anymore when combined with HER, as our results show.
4.3. Expert relabeling
Here we show that the Expert Relabeling technique introduced in Section 3.1 is beneﬁcial in the goal-conditioned imitation learning framework.
As shown in Fig.
3, our expert relabeling technique brings considerable performance boosts for both Behavioral Cloning methods and goal-GAIL in both environments.
We also perform a further analysis of expert relabeling in the four-rooms environment.
We see in
Fig.
1 that without the expert relabeling, the agent fails to learn how to reach many intermediate states visited in the middle of a demonstration.
4.4. Using state-only demonstrations
Behavioral Cloning and standard GAIL rely on the stateaction ( s, a ) tuples from the expert.
Nevertheless there are many cases in robotics where we only have access to observation-only demonstrations.
In this section we want to emphasize that all the results obtained with our goal-GAIL method and reported in Fig.
2 and Fig.
3 do not require actions that the expert took.
Surprisingly, in the four rooms environment, despite the more restricted information goalGAIL has access to, it outperforms BC combined with HER.
This might be due to the superior imitation learning performance of GAIL, and also to the fact that these tasks might be possible to solve by only matching the state-distribution of the expert.
With GAIL conditioned only on current state but not action (as also done in other non-goal-conditioned works (Fu et al., 2018)), we observe that the discriminator learns a very well shaped reward that encourages the agent to go towards the goal, as pictured in Fig. 6 in appendix.
[Figure]
See the Appendix for more details.
4.5. Robustness to sub-optimal expert
In the above sections we assumed access to optimal experts.
Nevertheless, in practical applications the experts might have a more erratic behavior.
In this section we study how the different methods perform with a sub-optimal expert.
To do so we collect trajectories attempting goals g by modifying our optimal expert π ∗ ( a | s, g ) in two ways: We add noise α to the optimal actions and make it be (cid:15) -greedy.
The sub-optimal expert is then a = 1 [ r < (cid:15) ] u + 1 [ r > (cid:15) ]
( π ∗ ( a | s, g ) + α ) , where r ∼ Unif (0 , 1) , α ∼ N (0 , σ 2 α I ) and u is a uniformly sampled random action.
In Fig.
4 we observe that approaches that copy the action of the expert, like Behavioral Cloning, greatly suffer under a sub-optimal expert.
On the other hand, discriminator-based methods are able to leverage noisier experts.
A possible explanation is that a discriminator approach can give a positive signal as long as the transition is "in the right direction", without trying to exactly enforce a single action.
Under this lens, having some noise in the expert might actually improve the performance of these adversarial approaches, as it has been observed in many generative models literature (Goodfellow et al.).
5. Conclusions and Future Work
Hindsight relabeling can be used to learn useful behaviors without any reward supervision for goal-conditioned tasks, but they are inefﬁcient when the state-space is large or includes exploration bottlenecks.
In this work we show how only a few demonstrations can be leveraged to improve the convergence speed of these methods.
We introduce a novel algorithm, goal-GAIL, that converges faster than HER and to a better ﬁnal performance than a naive goal-conditioned
GAIL.
We also study the effect of doing expert relabeling as a type of data augmentation on the provided demonstrations, and demonstrate it improves the performance of our goal-GAIL as well as goal-conditioned Behavioral Cloning.
We emphasize that our goal-GAIL method only needs state demonstrations, without using expert actions like other Behavioral Cloning methods.
Finally, we show that goal-GAIL is robust to sub-optimalities in the expert behavior.
V. Dexterous Manipulation with Deep Reinforcement
Efﬁcient, General and Low-Cost
10 2018a
URL http://arxiv.
A. Related Work
Imitation Learning can be seen as an alternative to reward crafting to train desired behaviors.
There are many ways to leverage demonstrations, from Behavioral Cloning (Pomerleau, 1989) that directly maximizes the likelihood of the expert actions under the training agent policy, to Inverse Reinforcement Learning that extracts a reward function from those demonstrations and then trains a policy to maximize it (Ziebart et al., 2008; Finn et al., 2016; Fu et al., 2018).
Another formulation close to the later introduced by Ho &
Ermon (2016) is Generative Adversarial Imitation Learning (GAIL), explained in details in the next section.
Originally, the algorithms used to optimize the policy were on-policy methods like Trust Region Policy Optimization (Schulman et al., 2015), but recently there has been a wake of works leveraging the efﬁciency of off-policy algorithms without loss in stability (Blondé & Kalousis, 2019; Sasaki et al., 2019;
Schroecker et al., 2019; Kostrikov et al., 2019).
This is a key capability that we are going to exploit later on.
Unfortunately most work in the ﬁeld cannot outperform the expert, unless another reward is available during training (Vecerik et al., 2017; Gao et al., 2018; Sun et al., 2018), which might defeat the purpose of using demonstrations in the ﬁrst place.
Furthermore, most tasks tackled with these methods consist on tracking expert state trajectories (Zhu et al., 2018b; Peng et al., 2018), but can’t adapt to unseen situations.
In this work we are interested in goal-conditioned tasks, where the objective is to be able to reach any state upon demand.
This kind of multi-task learning are pervasive in robotics, but challenging if no reward-shaping is applied.
Relabeling methods like Hindsight Experience Replay (Andrychowicz et al., 2017) unlock the learning even in the sparse reward case (Florensa et al., 2018a).
Nevertheless, the inherent breath-ﬁrst nature of the algorithm might still make very inefﬁcient learning to learn complex policies.
To overcome the exploration issue we investigate the effect of leveraging a few demonstrations.
The closest prior work is by Nair et al.
(2018), where a Behavioral Cloning loss is used with a Q-ﬁlter.
We found that a simple annealing of the Behavioral Cloning loss (Rajeswaran et al., 2018) works better.
Furthermore, we also introduce a new relabeling technique of the expert trajectories that is particularly useful when only few demonstrations are available.
We also experiment with Goal-conditioned GAIL, leveraging the recently shown compatibility with off-policy algorithms.
For a more comprehensive review of related work, please see Appendix.
B. Goal-conditioned Behavioral Cloning
The most direct way to leverage demonstrations
[Equation]
is to construct a data-set D of all state-action-goal tuples ( s jt , a jt , g j ) , and run a supervised regression algorithm.
In the goal-conditioned case and assuming a deterministic policy π θ ( s, g ) , the loss is:
[Equation]
This loss and its gradient are computed without any additional environments samples from the trained policy π θ .
This makes it particularly convenient to combine a gradient descend step based on this loss with other policy updates.
In particular we can use a standard offpolicy Reinforcement Learning algorithm like DDPG (Lillicrap et al., 2015), where we ﬁt the Q φ ( a, s, g ) , and then estimate the gradient of the expected return as: ∇ θ ˆ J = 1 N (cid:80)
Ni =1 ∇ a Q φ ( a, s, g ) ∇ θ π θ ( s, g ) .
The improvement guarantees with respect to the task reward are lost when we combine the BC and the deterministic policy gradient updates, but this can be side-stepped by either applying a Q-ﬁlter: 1 (cid:8) Q ( s t , a t , g ) >
Q ( s t , π ( s t , g ) , g ) (cid:9) to the BC loss as proposed in (Nair et al., 2018), or by annealing it as we do in our experiments, which allows the agent to eventually outperform the expert.
C. Algorithm
All possible variants we study are detailed in Algorithmas presented in appendix.
In particular, α = 0 falls back to pure Behavioral Cloning, β = 0 removes the BC component, p = 0 doesn’t relabel agent trajectories, δ GAIL =removes the discriminator output from the reward, and EXPERT RELABEL indicates whether the here explained expert relabeling should be performed.
D. Environments, Hyperparameters and Architectures
In the two environments, i.e. Four Rooms environment and
Fetch Pick & Place, the task horizons are set to 300 and 100 respectively.
The discount factors are γ = 1 − 1 H .
In all experiments, the Q function, policy and discriminator are paramaterized by fully connected neural networks with two hidden layers of size 256.
DDPG is used for policy optimization and hindsight probability is set to p = 0 . 8 .
The initial value of the behavior cloning loss weight β is set to 0 .
and is annealed by 0.9 per 250 rollouts collected.
The initial value of the discriminator reward weight δ GAIL is set to 0 .
We found empirically that there is no need to anneal δ GAIL .
1: Input: Demonstrations D = (cid:8) ( s j 0 , a j 0 , s j 1 , ..., g j ) (cid:9) D j =0 , replay buffer R = {} , policy π θ ( s, g ) , discount γ , hindsight probability p 2: while not done do 3:
# Sample rollout 4: g ∼ R ∪ D 5:
Use π ( · , g ) to sample ( s 0 , a 0 , s 1 , ... )
→ ∪R 6: # Sample from buffers 7: (cid:8) ( s jt , a jt , s jt +1 , g j ) (cid:9) ∼ D , (cid:8) ( s it , a it , s it +1 , g i ) (cid:9) ∼ R 8: # Relabel agent 9: if HER then 10: for each i , with probability p do 11: g i ← s it + k , k ∼ Unif { t + 1 , . .
, T i } 12: end for 13: end if 14: if EXPERT RELABEL then 15: g j ← s jt + k (cid:48) , k (cid:48) ∼ Unif { t + 1 , . . .
, T j } 16: end if 17: r ht = 1 (cid:2) s ht
+
=
=
g h (cid:3) 18: if δ GAIL > 0 then 19: Ψ ← min ψ L GAIL ( D ψ , D , R ) 20: r ht =
(1 − δ GAIL )
r ht + δ GAIL log D ψ ( a ht , s ht , g h ) 21: end if 22: # Fit Q φ 23:
y ht = r ht
+ γQ φ ( π ( s ht
+1 , g h ) , s ht
+1 , g h ) 24: φ ← min φ (cid:80) h (cid:107) Q φ ( a ht , s ht , g h )
− y ht
(cid:107) 25:
# Update Policy 26: θ + = α ∇ θ ˆ J − β (cid:80) h ∇ θ L BC
( θ, ( a ht , s ht , g h )) 27:
Anneal δ GAIL and β 28: end while
For experiments with sub-optimal expert in section 4.5, (cid:15) is set to 0 .
4 and 0 . 5 , and σ α is set to 1 . 5 and 0 .
3 respectively for Four Rooms environment and Fetch Pick & Place.
E. Effect of Different Input of Discriminator
We trained the discriminator in three settings:
• current state and goal: ( s, g ) • current state, next state and goal: ( s, s (cid:48) , g ) • current state, action and goal: ( s, a, g )
We compare the three different setups in Fig.
7 and 8.
[Figure]
[Figure] [Figure]