S ELF -S UPERVISED P OLICY A DAPTATION DURING D EPLOYMENT
Anonymous authors
Paper under double-blind review
A BSTRACT
In most real world scenarios, a policy trained by reinforcement learning in one environment needs to be deployed in another, potentially quite different environment.
However, generalization across different environments is known to be hard.
A natural solution would be to keep training after deployment in the new environment, but this cannot be done if the new environment offers no reward signal.
Our work explores the use of self-supervision to allow the policy to continue training after deployment without using any rewards.
While previous methods explicitly anticipate changes in the new environment, we assume no prior knowledge of those changes yet still obtain signiﬁcant improvements.
Empirical evaluations are performed on diverse simulation environments from DeepMind Control suite and ViZDoom, as well as real robotic manipulation tasks in continuously changing environments, taking observations from an uncalibrated camera.
Our method improves generalization in 28 out of 32 environments across various tasks and outperforms domain randomization on a majority of environments.
Videos are available at https: //iclr2021submission.github.io/ICLR2021_Anonymized_PAD/ .
I NTRODUCTION
Deep reinforcement learning (RL) has achieved considerable success when combined with convolutional neural networks for deriving actions from image pixels (Mnih et al., 2013; Levine et al., 2016;
Nair et al., 2018; Yan et al., 2020; Andrychowicz et al., 2020).
However, one signiﬁcant challenge for real-world deployment of vision-based RL remains: a policy trained in one environment might not generalize to other new environments not seen during training.
Already hard for RL alone, the challenge is exacerbated when a policy faces high-dimensional visual inputs.
A well explored class of solutions is to learn robust policies that are simply invariant to changes in the environment (Rajeswaran et al., 2016;
Tobin et al., 2017; Sadeghi & Levine, 2016; Pinto et al., 2017b; Lee et al., 2019).
For example, domain randomization (Tobin et al., 2017; Peng et al., 2018;
Pinto et al., 2017a; Yang et al., 2019) applies data augmentation in a simulated environment to train a single robust policy, with the hope that the augmented environment covers enough factors of variation in the test environment.
However, this hope may be difﬁcult to realize when the test environment is truly unknown.
With too much randomization, training a policy that can simultaneously ﬁt numerous augmented environments requires much larger model and sample complexity.
With too little randomization, the actual changes in the test environment might not be covered, and domain randomization may do more harm than good since the randomized factors are now irrelevant.
Both phenomena have been observed in our experiments.
In all cases, this class of solutions requires human experts to anticipate the changes before the test environment is seen.
This cannot scale as more test environments are added with more diverse changes.
Instead of learning a robust policy invariant to all possible environmental changes, we argue that it is better for a policy to keep learning during deployment and adapt to its actual new environment.
A naive way to implement this in RL is to ﬁne-tune the policy in the new environment using rewards as supervision (Rusu et al., 2016;
Kalashnikov et al., 2018; Julian et al., 2020).
However, while it is relatively easy to craft a dense reward function during training (Gu et al., 2017; Pinto & Gupta, 2016), during deployment it is often impractical and may require substantial engineering efforts.
In this paper, we tackle an alternative problem setting in vision-based RL: adapting a pre-trained policy to an unknown environment without any reward.
We do this by introducing self-supervision to obtain “free” training signal during deployment.
Standard self-supervised learning employs auxiliary tasks designed to automatically create training labels using only the input data (see sectionfor details).
Inspired by this, our policy is jointly trained with two objectives: a standard RL objective and, additionally , a self-supervised objective applied on an intermediate representation of the policy network.
During training, both objectives are active, maximizing expected reward and simultaneously constraining the intermediate representation through self-supervision.
During testing / deployment, only the self-supervised objective (on the raw observational data) remains active, forcing the intermediate representation to adapt to the new environment.
We perform experiments both in simulation and with a real robot.
In simulation, we evaluate on two sets of environments: DeepMind Control suite (Tassa et al., 2018) and the CRLMaze
ViZDoom (Lomonaco et al., 2019; Wydmuch et al., 2018) navigation task.
We evaluate generalization by testing in new environments with visual changes unknown during training.
Our method improves generalization in 19 out of 22 test environments across various tasks in DeepMind Control suite, and in all considered test environments on CRLMaze.
Besides simulations, we also perform Sim2Real transfer on both reaching and pushing tasks with a Kinova Gen3 robot.
After training in simulation, we successfully transfer and adapt policies to 6 different environments, including continuously changing disco lights, on a real robot operating solely from an uncalibrated camera.
In both simulation and real experiments, our approach outperforms domain randomization in most environments.
R ELATED W ORK
Self-supervised learning is a powerful way to learn visual representations from unlabeled data (Vincent et al., 2008; Doersch et al., 2015; Wang & Gupta, 2015; Zhang et al., 2016; Pathak et al., 2016;
Noroozi & Favaro, 2016; Zhang et al., 2017; Gidaris et al., 2018).
Researchers have proposed to use auxiliary data prediction tasks, such as undoing rotation (Gidaris et al., 2018), solving a jigsaw puzzle (Noroozi & Favaro, 2016), tracking (Wang et al., 2019), etc. to provide supervision in lieu of labels.
In RL, the idea of learning visual representations and action at the same time has been investigated (Lange & Riedmiller, 2010; Jaderberg et al., 2016; Pathak et al., 2017; Ha & Schmidhuber, 2018; Yarats et al., 2019; Srinivas et al., 2020;
Laskin et al., 2020; Yan et al., 2020).
For example,
Srinivas et al.
(2020) use self-supervised contrastive learning techniques (Chen et al., 2020; H ´ enaff et al., 2019; Wu et al., 2018;
He et al., 2020) to improve sample efﬁciency in RL by jointly training the self-supervised objective and RL objective.
However, this has not been shown to generalize to unseen environments.
Other works have applied self-supervision for better generalization across environments (Pathak et al., 2017;
Ebert et al., 2018; Sekar et al., 2020).
For example, Pathak et al.
(2017) use a self-supervised prediction task to provide dense rewards for exploration in novel environments.
While results on environment exploration from scratch are encouraging, how to transfer a trained policy (with extrinsic reward) to a novel environment remains unclear.
Hence, these methods are not directly applicable to the proposed problem in our paper.
Generalization across different distributions is a central challenge in machine learning.
In domain adaptation, target domain data is assumed to be accessible (Geirhos et al., 2018;
Tzeng et al., 2017;
Ganin et al., 2016;
Gong et al., 2012; Long et al., 2016; Sun et al., 2019; Julian et al., 2020).
For example, Tzeng et al.
(2017) use adversarial learning to align the feature representations in both the source and target domain during training.
Similarly, the setting of domain generalization (Ghifary et al., 2015; Li et al., 2018; Matsuura & Harada, 2019) assumes that all domains are sampled from the same meta distribution, but the same challenge remains and now becomes generalization across meta-distributions.
Our work focuses instead on the setting of generalizing to truly unseen changes in the environment which cannot be anticipated at training time.
There have been several recent benchmarks in our setting for image recognition (Hendrycks &
Dietterich, 2018; Recht et al., 2018; 2019; Shankar et al., 2019).
For example, in Hendrycks & Dietterich (2018), a classiﬁer trained on regular images is tested on corrupted images, with corruption types unknown during training; the method of Hendrycks et al.
(2019) is proposed to improve robustness on this benchmark.
Following similar spirit, in the context of RL, domain randomization (Tobin et al., 2017; Pinto et al., 2017a;
Peng et al., 2018; Ramos et al., 2019;
Yang et al., 2019; James et al., 2019) helps a policy trained in simulation to generalize to real robots.
For example, Tobin et al.
(2017); Sadeghi & Levine (2016) propose to render the simulation environment with random textures and train the policy on top.
The learned policy is shown to generalize to real robot manipulation tasks.
Instead of deploying a ﬁxed policy, we train and adapt the policy to the new environment with observational data that is naturally revealed during deployment.
-time adaptation for deep used in computer example, Shocher et al.
(2018) shows that image super-resolution can be learned at test time (from scratch) simply by trying to upsample a downsampled version of the input image.
Bau et al.
(2019) show that adapting the prior of a generative adversarial network to the statistics of the test image improves photo manipulation tasks.
Our work is closely related to the test-time training method of
Sun et al.
(2020), which performs joint optimization of image recognition and self-supervised learning with rotation prediction (Gidaris et al., 2018), then uses the self-supervised objective to adapt the representation of individual images during testing.
Instead of image recognition, we perform test-time adaptation for RL with visual inputs in an online fashion.
As the agent interacts with an environment, we keep obtaining new observational data in a stream for training the visual representations.
M ETHOD
In this section, we describe our proposed Policy Adaptation during Deployment (PAD) approach.
It can be implemented on top of any policy network and standard RL algorithm (both on-policy and off-policy) that can be described by minimizing some RL objective J ( θ ) w.r.t.
the collection of parameters θ using stochastic gradient descent.
3. N ETWORK A RCHITECTURE
We design the network architecture to allow the policy and the self-supervised prediction to share features.
For the collection of parameters θ of a given policy network π , we split it sequentially into θ =
( θ e , θ a ) , where θ e collects the parameters of the feature extractor, and θ a is the head that outputs a distribution over actions.
We deﬁne networks π e with parameters θ e and π a with parameters θ a such that π ( s ; θ ) =
π a ( π e ( s )) , where s represents an image observation.
Intuitively, one can think of π e as a feature extractor, and π a as a controller based on these features.
The goal of our method is to update π e at test-time using gradients from a self-supervised task, such that π e
(and consequently π θ ) can generalize.
Let π s with parameters θ s be the self-supervised prediction head and its collection of parameters, and the input to π s be the output of π e (as illustrated in Figure 1).
In this work, the self-supervised task is inverse dynamics prediction for control, and rotation prediction for navigation.
3. I NVERSE D YNAMICS P REDICTION AND R OTATION P REDICTION
At each time step, we always observe a transition sequence in the form of ( s t , a t , s t +1 ) , during both training and testing.
Naturally, self-supervision can be derived from taking parts of the sequence and predicting the rest.
An inverse dynamics model takes the states before and after transition, and predicts the action in between.
In this work, the inverse dynamics model π s operates on the feature space extracted by π e .
We can write the inverse dynamics prediction objective formally as
[Equation]
For continuous actions, (cid:96) is the mean squared error between the ground truth and the model output.
For discrete actions, the output is a soft-max distribution over the action space, and (cid:96) is the crossentropy loss.
Empirically, we ﬁnd this self-supervised task to be most effective with continuous actions, possibly because inverse dynamics prediction in a small space of discrete actions is not as challenging.
Note that we predict the inverse dynamics instead of the forward dynamics, because when operating in feature space, the latter can produce trivial solutions such as the constant zero feature for every state 1 .
If we instead performed prediction with forward dynamics in pixel space, the task would be extremely challenging given the large uncertainty in pixel prediction.
As an alternative self-supervised task, we use rotation prediction (Gidaris et al., 2018).
We rotate an image by one of 0, 90, 180 and 270 degrees as input to the network, and cast this as a four-way classiﬁcation problem to determine which one of these four ways the image has been rotated.
This task is shown to be effective for learning representations for object conﬁguration and scene structure, which is beneﬁcial for visual recognition (Hendrycks et al., 2019; Doersch & Zisserman, 2017).
3. T RAINING AND T ESTING
Before deployment of the policy, because we have signals from both the reward and self-supervised auxiliary task, we can train with both in the fashion of multi-task learning.
This corresponds to the following optimization problem during training min θ a ,θ s ,θ e J ( θ a , θ e ) + αL ( θ s , θ e ) , where α > 0 is a trade-off hyper-parameter.
During deployment, we cannot optimize J anymore since the reward is unavailable, but we can still optimize L to update both θ s and θ e .
Empirically, we ﬁnd only negligible difference with keeping θ s ﬁxed at test-time, so we update both since the gradients have to be computed regardless; we ablate this decision in appendix C. As we obtain new images from the stream of visual inputs in the environment, θ keeps being updated until the episode ends.
This corresponds to, for each iteration t = 1 ...T :
[Equation]
) θ e ( t ) = θ e ( t − 1) − ∇ θ e L ( s t ; θ s ( t − 1) , θ [Equation] ( t − 1)) (4) a t = π ( s t ; θ ( t )) with θ ( t ) =
( θ e ( t ) , θ a ) , (5) where θ s (0)
=
θ s , θ e (0)
= θ e , s 0 is the initial condition given by the environment, a 0 = π θ ( s 0 ) , p is the unknown environment transition, and L is the self-supervised objective as previously introduced.
E XPERIMENTS
In this work, we investigate how well an agent trained in one environment (denoted the training environment ) generalizes to unseen and diverse test environments.
During evaluation, agents have no access to reward signals and are expected to generalize without trials nor prior knowledge about the test environments.
In simulation, we evaluate our method (PAD) and baselines extensively on continuous control tasks from DeepMind Control (DMC) suite (Tassa et al., 2018) as well as the CRLMaze (Lomonaco et al., 2019) navigation task, and experiment with both stationary (colors, objects, textures, lighting) and non-stationary (videos) environment changes.
We further show that PAD transfers from simulation to a real robot and successfully adapts to environmental differences during deployment in two robotic manipulation tasks.
Samples from DMC and CRLMaze environments are shown in Figure 2, and samples from the robot experiments are shown in Figure 4.
Code will be released.
Network details.
For DMC and the robotic manipulation tasks we implement PAD on top of Soft
Actor-Critic (SAC) (Haarnoja et al., 2018), and adopt both network architecture and hyper-parameters from Yarats et al.
(2019), with minor modiﬁcations: the feature extractor π e has 8 convolutional layers shared between the RL head π a and self-supervised head π s , and we split the network into architecturally identical heads following π e .
Each head consists of 3 convolutional layers followed by 4 fully connected layers.
For CRLMaze, we use Advantage Actor-Critic (A2C) as base algorithm (Mnih et al., 2016) and apply the same architecture as for the other experiments, but implement π e with only 6 convolutional layers.
Observations are stacks of k colored frames ( k = 3 on DMC and
CRLMaze; k = 1 in robotic manipulation) of size 100 × 100 and time-consistent random crop is applied as in Srinivas et al.
During deployment, we optimize the self-supervised objective online w.r.t.
θ e , θ s for one gradient step per time iteration.
See appendix E for implementation details.
[Table]
4. D EEP M IND C ONTROL
DeepMind Control (DMC) (Tassa et al., 2018) is a collection of continuous control tasks where agents only observe raw pixels.
Generalization benchmarks on DMC represent diverse real-world tasks for motor control, and contain distracting surroundings not correlated with the reward signals.
Experimental setup.
We experiment with 9 tasks from DMC and measure generalization to four types of test environments: (i) randomized colors; (ii) natural videos as background; (iii) distracting objects placed in the scene; and (iv) the unmodiﬁed training environment.
For each test environment, we evaluate methods across 10 seeds and 100 random initializations.
If a given test environment is not applicable to certain tasks, e.g. if a task has no background for the video background setting, they are excluded.
Tasks are selected on the basis of diversity, as well as the success of vision-based RL in prior work (Yarats et al., 2019; Srinivas et al., 2020; Laskin et al., 2020; Kostrikov et al., 2020).
We implement PAD on top of SAC and use an Inverse Dynamics Model (IDM) for self-supervision, as we ﬁnd that learning a model of the dynamics works well for motor control.
For completeness, we ablate the choice of self-supervision.
Learning curves are provided in appendix section B. We compare our method to the following baselines: (i) SAC with no changes (denoted SAC ); (ii) SAC trained with domain randomization on a ﬁxed set of 100 colors (denoted +DR ); and (iii) SAC trained jointly with an IDM but without PAD (denoted +IDM ).
Our method using an IDM with PAD is denoted by +IDM (PAD) .
For domain randomization, colors are sampled from the same distribution as in evaluation, but with lower variance, as we ﬁnd that training directly on the test distribution does not converge.
Random perturbation of color.
Robustness to subtle changes such as color is essential to realworld deployment of RL policies.
We evaluate generalization on a ﬁxed set of 100 colors of foreground, background and the agent itself, and report the results in Table 1 (ﬁrst 4 columns).
We ﬁnd PAD to improve generalization in all tasks considered , outperforming SAC trained with domain randomization in 6 out of 9 tasks.
Surprisingly, despite a substantial overlap between training and test domains of domain randomization, it generalizes no better than vanilla SAC on a majority of tasks.
Long-term stability.
We ﬁnd the relative improvement of PAD to improve over time, as shown in Figure 3.
To examine the long-term stability of PAD, we further evaluate on 10x episode lengths and summarize the results in the last two columns in Table 1 (goal-oriented tasks excluded).
While we do not explicitly prevent the embedding from drifting away from the RL task, we ﬁnd empirically that
PAD does not degrade the performance of the policy, even over long horizons, and when PAD does not improve, we ﬁnd it to hurt minimally.
We conjecture this is because we are not learning a new task, but simply continue to optimize the same (self-supervised) objective as during joint training, where both two tasks are compatible.
In this setting, PAD still improves generalization in 6 out oftasks, and thus naturally extends beyond episodic deployment.
For completeness, we also evaluate methods in the environment in which they were trained, and report the results in appendix section A.
We ﬁnd that, while PAD improves generalization to novel environments, performance is virtually unchanged on the training environment.
We conjecture this is because the self-supervised task is already fully learned and any continued training on the same data distribution thus has little impact.
[Table]
Non-stationary environments
[Table] To investigate whether PAD can adapt in non-stationary environments [Table] we evaluate generalization to diverse video backgrounds (refer to Figure 2).
We ﬁnd PAD to outperform all baselines on 7 out of 8 tasks, as shown in Table [Table] by as much as 104% over domain randomization on Finger, spin .
Domain randomization generalizes comparably worse to videos, which we conjecture is not because the environments are non-stationary, but rather because the image statistics of videos are not covered by its training domain of randomized colors.
In fact, domain randomization is outperformed by the vanilla SAC in most tasks with video backgrounds, which is in line with the ﬁndings of Packer et al.
Scene content.
We hypothesize that: (i) an agent trained with an IDM is comparably less distracted by scene content since objects uncorrelated to actions yield no predictive power; and (ii) that PAD can adapt to unexpected objects in the scene.
We test these hypotheses by measuring robustness to colored shapes at a variety of positions in both the foreground and background of the scene (no physical interaction).
Results are summarized in Table 2.
PAD outperforms all baselines in 3 out oftasks, with a relative improvement of 208% over SAC on Ball in cup, catch .
In the two cartpole tasks in which PAD does not improve, all methods are already relatively unaffected by the distractors.
Choice of self-supervised task.
We investigate how much the choice of self-supervised task contributes to the overall success of our method, and consider the following ablations: (i) replacing inverse dynamics with the rotation prediction task described in section 3.2; and (ii) replacing it with the recently proposed CURL (Srinivas et al., 2020) contrastive learning algorithm for RL.
As shown in Table 3, PAD improves generalization of CURL in a majority of tasks on the randomized color benchmark, and in 4 out of 9 tasks using rotation prediction.
However, inverse dynamics as auxiliary task produces more consistent results and offers better generalization overall.
We argue that learning an IDM produces better representations for motor control since it connects observations directly to actions, whereas CURL and rotation prediction operates purely on observations.
In general, we ﬁnd the improvement of PAD to be bigger in tasks that beneﬁt signiﬁcantly from visual information (see appendix section A), and conjecture that selecting a self-supervised task that learns features useful to the RL task is crucial to the success of PAD, which we discuss further in section 4.2. [Table] [Table]
Ofﬂine versus online learning.
Observations that arrive sequentially are highly correlated [Table] and we thus hypothesize that our method beneﬁts signiﬁcantly from learning online.
To test this hypothesis, we run an ofﬂine variant of our method in which network updates are forgotten after each step.
In this setting, our method can only adapt to single observations and does not beneﬁt from learning over time.
Results are shown in Table 3.
We ﬁnd that our method beneﬁts substantially from online learning
[Table]
but learning ofﬂine still improves generalization on select tasks
[Table]
4. CRLM AZE
CRLMaze (Lomonaco et al., 2019) is a time-constrained, discrete-action 3D navigation task for
ViZDoom (Wydmuch et al., 2018), in which an agent is to navigate a maze and collect objects.
There is a positive reward associated with green columns [Table] and a negative reward for lanterns as well as for living.
Readers are referred to the respective papers for details on the task and environment.
Experimental setup.
We train agents on a single environment and measure generalization to environments with novel textures for walls, ﬂoor, and ceiling, as well as lighting, as shown in Figure 2.
We implement PAD on top of A2C (Mnih et al., 2016) and use rotation prediction (see section 3.2) as self-supervised task.
Learning to navigate novel scenes requires a generalized scene understanding, and we ﬁnd that rotation prediction facilitates that more so than an IDM.
We compare to the following baselines: (i) a random agent (denoted Random ); (ii) A2C with no changes (denoted A2C ); (iii)
A2C trained with domain randomization (denoted +DR ); (iv) A2C with an IDM as auxiliary task (denoted +IDM ); and (v) A2C with rotation prediction as auxiliary task (denoted +Rot ).
We denote
Rot with PAD as +Rot (PAD) .
Domain randomization uses 56 combinations of diverse textures, partially overlapping with the test distribution, and we ﬁnd it necessary to train domain randomization for twice as many episodes in order to converge.
We closely follow the evaluation procedure of (Lomonaco et al., 2019) and evaluate methods across 20 starting positions and 10 random seeds.
Results.
We report performance on the CRLMaze environments in Table 4.
PAD improves generalization in all considered test environments , outperforming both A2C and domain randomization by a large margin.
Domain randomization performs consistently across all environments but is less successful overall.
We further examine the importance of selecting appropriate auxiliary tasks by a simple ablation: replacing rotation prediction with an IDM for the navigation task.
We conjecture that, while an auxiliary task can enforce structure in the learned representations, its features (and consequently gradients) need to be sufﬁciently correlated with the primary RL task for PAD to be [Figure] successful during deployment.
While PAD with rotation prediction improves generalization across all test environments considered, IDM does not, which suggests that rotation prediction is more suitable for tasks that require scene understanding, whereas IDM is useful for tasks that require motor control.
We leave it to future work to automate the process of selecting appropriate auxiliary tasks.
[Table]
We deploy our method and baselines on a real Kinova Gen3 robot and evaluate on two manipulation tasks: (i) reach , a task in which the robot reaches for a goal marked by a red disc; and (ii) push , a task in which the robot pushes a cube to the location of the red disc.
Both tasks use an XY action space, where the Z position of the actuator is ﬁxed.
Agents operate purely from pixel observations with no access to state information .
During deployment, we make no effort to calibrate camera, lighting, or physical properties such as dimensions, mass, and friction, and policies are expected to generalize with no prior knowledge of the test environment.
Samples from the push task are shown in Figure 4, and samples from reach are shown in appendix D. [Table]
Experimental setup.
We implement PAD on top of SAC (Haarnoja et al., 2018) and apply the same experimental setup as in section 4.1 using an Inverse Dynamics Model (IDM) for self-supervision, but without frame-stacking (i.e. k = 1 ).
Agents are trained in simulation with dense rewards and randomized initial conﬁgurations of arm, goal, and box, and we measure generalization to 3 novel environments in the real-world: (i) default environment with pixel observations that roughly mimic the simulation; (ii) a patterned table cloth that distracts visually and greatly increases friction; and (iii) disco, an environment with non-stationary visual disco light distractions.
Notably, all 3 environments also feature subtle differences in dynamics compared to the training environment, such as object dimensions, mass, friction, and uncalibrated actions.
In each setting, we evaluate the success rate across 25 test runs spanning across 5 pre-deﬁned goal locations throughout the table.
The goal locations vary between the two tasks, and the robot is reset after each run.
We perform comparison against direct transfer and domain randomization baselines as in section 4.1.
We further evaluate generalization to changes in dynamics by considering a variant of the simulated environment in which object mass, size, and friction, arm mount position, and end effector velocity is modiﬁed. We consider each setting both individually and jointly, and evaluate success rate across 50 unique conﬁgurations with the robot reset after each run.
Results.
We report transfer results in Table 5.
While all methods transfer successfully to reach (default) , we observe PAD to improve generalization in all settings in which the baselines show sub-optimal performance.
We ﬁnd PAD to be especially powerful for the push task that involves dynamics, improving by as much as 24% in push (cloth) .
While domain randomization proves highly effective in reach (cloth) , we observe no signiﬁcant beneﬁt in the other settings, which suggests that PAD can be more suitable in challenging tasks like push . To isolate the effect of dynamics, we further evaluate generalization to a number of simulated changes in dynamics on the push task as shown in Figure 6a. Results are shown in Table 6.
We ﬁnd PAD to improve generalization to changes in the physical properties of the object and end effector, whereas both SAC+IDM and PAD are relatively unaffected by changes to the mount position.
Consistent with the real robot results in table 5, PAD is found to be most effective when changes in dynamics are non-trivial, improving by as much as 28% in the push (all) setting, where all 3 environmental changes are considered jointly.
These results suggest that PAD can be a simple, yet effective method for generalization to diverse, unseen environments that vary in both visuals and dynamics.
C ONCLUSION
While previous work addresses generalization in RL by learning policies that are invariant to any environment changes that can be anticipated, we formulate an alternative problem setting in vision-based RL: can we instead adapt a pretrained-policy to new environments without any reward.
We propose Policy Adaptation during Deployment, a self-supervised framework for online adaptation at test-time, and show empirically that our method improves generalization of policies to diverse simulated and real-world environmental changes across a variety of tasks.
We ﬁnd our approach beneﬁts greatly from learning online, and we systematically evaluate how the choice of self-supervised task impacts performance.
While the current framework relies on prior knowledge on selecting self-supervised tasks for policy adaptation, we see our work as the initial step in addressing the problem of adapting vision-based policies to unknown environments.
We ultimately envision embodied agents in the future to be learning all the time, with the ﬂexibility to learn both with and without rewards, before and during deployment.
A P ERFORMANCE ON THE TRAINING ENVIRONMENT
Historically, agents have commonly been trained and evaluated in the same environment when benchmarking RL algorithms exclusively in simulation.
Although such an evaluation procedure does not consider generalization, it is still a useful metric for comparison of sample efﬁciency and stability of algorithms.
For completeness, we also evaluate our method and baselines in this setting on both
DMC and CRLMaze.
DMC results are reported in Table 7 and results on the CRLMaze environment are shown in Table 8.
In this setting, we also compare to an additional baseline on DMC: a blind
SAC agent that operates purely on its previous actions.
The performance of a blind agent indicates to which degree a given task beneﬁts from visual information.
We ﬁnd that, while PAD improves generalization to novel environments, performance is virtually unchanged when evaluated on the same environment as in training.
We conjecture that this is because the algorithm already is adapted to the training environment and any continued training on the same data distribution thus has little inﬂuence.
We further emphasize that, even when evaluated on the training environment, PAD still outperforms baselines on most tasks.
For example, we observe a 15% relative improvement over SAC on the Finger, spin task.
We hypothesize that this gain in performance is because the self-supervised objective improves learning by constraining the intermediate representation of policies.
A blind agent is no better than random on this particular task, which would suggest that agents beneﬁt substantially from visual information in Finger, spin .
Therefore, learning a good intermediate representation of that information is highly beneﬁcial to the RL objective, which we ﬁnd PAD to facilitate through its self-supervised learning framework.
Likewise, the SAC baseline only achieves a 51% improvement over the blind agent on Cartpole, balance , which indicates that extracting visual information from observations is not as crucial on this task.
Consequently, both PAD and baselines achieve similar performance on this task.
[Table]
[Table]
B L EARNING CURVES ON D EEP M IND C ONTROL
All methods are trained until convergence (500,000 frames) on the DeepMind Control suite.
While we do not consider the sample efﬁciency of our method and baselines in this study, we report learning curves for SAC, SAC+IDM and SAC trained with domain randomization on three tasks in Figurefor completeness.
SAC trained with and without an IDM are similar in terms of sample efﬁciency and ﬁnal performance, whereas domain randomization consistently displays worse sample efﬁciency, larger variation between seeds, and converges to sub-optimal performance in two out of the three tasks shown. [Figure]
C K EEPING π s FIXED DURING POLICY ADAPTATION
We now consider a variant of PAD where the self-supervised task head π s is ﬁxed at test-time such that the self-supervised objective L is optimized only wrt π e , as discussed in section 3.3.
We measure generalization to test environments with randomized colors and report the results in Table 9 for three tasks from the DeepMind Control suite.
Empirically we ﬁnd the difference between updating π s and keeping it ﬁxed negligible and we choose to update π s by default since its gradients are computed by back-propagation regardless.
[Table] IDM [Table] D A DDITIONAL ROBOTIC MANIPULATION SAMPLES
Figure 6 provides samples from the training and test environments for the reach robotic manipulation task.
Agents are trained in simulation and deployed on a real robot.
Samples from the push task are shown in Figure 4.
E I MPLEMENTATION D ETAILS
In this section, we elaborate on implementation details for our experiments on DeepMind Control (DMC) suite (Tassa et al., 2018) and CRLMaze (Lomonaco et al., 2019) for ViZDoom (Wydmuch et al., 2018).
Our implementation for the robotic manipulation experiments closely follows that of
DMC.
Architecture.
Our network architecture is illustrated in Figure 7.
Observations are stacked frames ( k = 3 ) rendered at 100 × 100 and cropped to 84 × 84 , i.e. inputs to the network are of dimensions 9 × 84 × 84 , where the ﬁrst dimension indicates the channel numbers and the following ones represent
[Figure]
spatial dimensions.
The same crop is applied to all frames in a stack.
The shared feature extractor π e consists of 8 (DMC, robotic manipulation) or 6 (CRLMaze) convolutional layers and outputs features of size 32 × 21 × 21 in DMC and robotic manipulation, and size 32 × 25 × 25 in CRLMaze.
The output from π e is used as input to both the self-supervised head π s and RL head π a , both of which consist of 3 convolutional layers followed by 3 fully-connected layers.
All convolutional layers use 32 ﬁlters and all fully connected layers use a hidden size of 1024, as in Yarats et al.
Learning algorithm.
We use Soft Actor-Critic (SAC) (Haarnoja et al., 2018) for DMC and robotic manipulation, and Advantage Actor-Critic (A2C) for CRLMaze.
Network outputs depend on the task and learning algorithm.
As the action spaces of both DMC and robotic manipulation are continuous, the policy learned by SAC outputs the mean and variance of a Gaussian distribution over actions.
CRLMaze has a discrete action space and the policy learned by A2C thus learns a soft-max distribution over actions.
For details on the critics learned by SAC and A2C, the reader is referred to
Haarnoja et al.
(2018) and Mnih et al.
(2016), respectively.
Hyper-parameters.
When applicable, we adopt our hyper-parameters from Yarats et al.
(2019) (DMC, robotic manipulation) and Lomonaco et al.
(2019) (CRLMaze).
For the robotic manipulation experiments, our implementation closely follows that of DMC, only differing by number of frames in an observation.
We use a frame stack of k = 3 frames for DMC and CRLMaze, and only k =frame for robotic manipulation.
For completeness, we detail all hyper-parameters used for the DMC and CRLMaze environments in Table 10 and Table 11.
Data augmentation.
Random cropping is a commonly used data augmentation used in computer vision systems (Krizhevsky et al., 2012; Szegedy et al., 2015) but has only recently gained interest as a stochastic regularization technique in the RL literature (Srinivas et al., 2020;
Kostrikov et al., 2020; Laskin et al., 2020).
We adopt the random crop proposed in Srinivas et al.
(2020): crop rendered observations of size 100 × 100 to 84 × 84 , applying the same crop to all frames in a stacked observation.
This has the added beneﬁts of regularization while still preserving spatio-temporal patterns between frames.
When learning an Inverse Dynamics Model, we apply the same crop to all [Table] [Table] frames of a given observation but apply two different crops to the consecutive observations ( s t , s t +1 ) used to predict action a t .
Policy Adaptation during Deployment.
We evaluate our method and baselines with episodic cumulative reward of an agent trained in a single environment and tested in a collection of test environments, each with distinct changes from the training environment.
We assume no reward signal at test-time and agents are expected to generalize without pre-training or resetting in the new environment.
Therefore, we make updates to the policy using a self-supervised objective, and we train using observations from the environment in an online manner without memory, i.e. we make one update per step using the most-recent observation.
Empirically, we ﬁnd that: (i) the random crop data augmentation used during training helps regularize learning at test-time; and (ii) our algorithm beneﬁts from learning from a batch of randomly cropped observations rather than single observations, even when all observations in the batch are augmented copies of the most-recent observation.
As such, we apply both of these techniques when performing
Policy Adaptation during Deployment and use a batch size of 32.
When using the policy to take actions, however, inputs to the policy are simply center-cropped.