Search

Search papers and lessons

Learning Latent Dynamics for Planning from Pixels (PlaNet)

Danijar Hafner, Timothy Lillicrap, Ian Fischer et al. · 2018

PlaNet learns a model of the world from camera images and plans by simulating action sequences inside that model's compact latent space, matching model-free agents with far fewer episodes.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • World models
  • Reinforcement learning
  • Linear algebra
  • Neural network basics
  • Sign in to see your progress

TL;DR

Planning works well when the rules of the environment are known, but a robot or game agent must first learn them from experience. PlaNet learns a model that predicts the future from camera images. It then chooses each action by searching over imagined action sequences inside a compact hidden state, replanning after every step. With six continuous-control tasks learned from pixels alone, it reaches performance close to the best model-free agents using about 1,000 episodes where those agents used 100,000.

Where you'll see it: in agents that learn a world model from images and plan in its latent space instead of training a policy from scratch, and in the benchmark comparisons this paper set up on the DeepMind control suite.

The problem

To plan, an agent needs a model that says what happens after each action. In a known simulator, the model is given. In an unknown environment, it has to be learned, and the paper names the difficulties: small model errors that grow over many predicted steps, failure to represent several possible futures, and overconfident predictions for situations the model has not seen.

Earlier work on learned models mostly used low-dimensional states. Those models assume the agent can read the true state and the reward. Pixel observations are high-dimensional and do not reveal the full state, since a single frame hides velocities and anything out of view. The authors say that latent-space models had succeeded only on simple tasks such as balancing a cartpole or controlling a two-link arm, and used dense rewards. The goal was a planner that works from pixels, handles sparse rewards, contact and partial observability, and needs little experience.

Key idea

Learn a compact latent state that the agent can roll forward cheaply. Predicting images is expensive, so the planner never generates pictures. It scores action sequences by predicting rewards from the latent state. Images are needed only during training, as a learning signal for the latent state.

The latent state has two parts. A stochastic part can represent several possible futures. A deterministic part carries information across many steps, so the model does not forget. The paper shows both are needed. The paper argues that a purely stochastic model struggles to remember information over many steps. In its experiments, the agent does not learn without the stochastic part at all.

The method

The loop

PlaNet alternates two steps (its Algorithm 1). It starts from five seed episodes with random actions. It then trains the model on the data collected so far, and after every 100 gradient updates it runs the planner once in the real environment and adds that episode to the data. Actions are small random perturbations of the planner's output, and each chosen action is repeated for a few environment steps, so the planning horizon is shorter.

At every real step the planner is run again from the newest observation. This is model-predictive control: the agent acts on the first action of a plan and then replans. The policy is the planner itself, with no separate policy or value network.

The planner

The planner is the cross-entropy method (CEM). It keeps a Gaussian belief over action sequences of length HH, starting with zero mean and unit variance. In each iteration it draws JJ candidate sequences, scores each one under the model by summing predicted rewards along a sampled latent trajectory, keeps the top KK, and refits the Gaussian to them. After II iterations it returns the mean action for the current step. The belief is reset at every real step, which the authors say avoids local optima.

Because the planner runs in latent space, it can evaluate large batches of candidate sequences quickly.

The recurrent state-space model

The dynamics model is written as a generative process over a hidden state. The deterministic path and the stochastic path are:

ht=f(ht−1,st−1,at−1),st∼p(st∣ht),ot∼p(ot∣ht,st),rt∼p(rt∣ht,st)h_t = f(h_{t-1}, s_{t-1}, a_{t-1}), \qquad s_t \sim p(s_t \mid h_t), \qquad o_t \sim p(o_t \mid h_t, s_t), \qquad r_t \sim p(r_t \mid h_t, s_t)

Here hth_t is the deterministic state, a vector computed by a recurrent network ff (a GRU with 200 units in the paper). sts_t is the stochastic state, a 30-dimensional diagonal Gaussian. oto_t is the image and rtr_t the reward. The paper's Figure 1 shows the three designs compared: purely deterministic, purely stochastic, and this split model, which the paper calls the recurrent state-space model (RSSM).

Training uses a variational encoder q(st∣ht,ot)q(s_t \mid h_t, o_t) that sees the current image, so inference follows the same structure as the model. The objective is a bound on the data likelihood with two terms. A reconstruction term asks the model to predict the observed image and reward. A complexity term, a Kullback–Leibler Divergence between the posterior and the one-step prediction, keeps the prediction close to what the encoder inferred:

ln⁡p(o1:T∣a1:T)≥∑t=1T(Eq[ln⁡p(ot∣st)]−E[KL[q(st∣o≤t,a<t) ∥ p(st∣st−1,at−1)]])\ln p(o_{1:T} \mid a_{1:T}) \geq \sum_{t=1}^{T} \Big( \mathbb{E}_{q}[\ln p(o_t \mid s_t)] - \mathbb{E}\big[\mathrm{KL}[q(s_t \mid o_{\leq t}, a_{<t}) \,\|\, p(s_t \mid s_{t-1}, a_{t-1})]\big] \Big)

This is the usual Variational Lower Bound (ELBO) for a latent sequence model, with the one-step transition as the prior.

Latent overshooting

The one-step KL term trains the transition only for one step ahead. The paper argues that a model with limited capacity, trained only on one-step predictions, need not be best at predicting several steps ahead, and planning needs the multi-step case. Latent overshooting adds KL terms for predictions up to DD steps ahead, using multi-step priors and no extra image reconstructions. The authors found that it helps other models but slightly hurts their final RSSM, so the final agent does not use it.

Implementation details

The image encoder and decoder are the convolutional and deconvolutional networks from Ha and Schmidhuber (2018). Other functions are two fully connected layers of size 200 with ReLU. Images are reduced to 5 bits. Training uses Adam with learning rate 10−310^{-3}, batches of 50 sequence chunks of length 50, and gradient clipping at norm 1000. The KL term has 3 free nats, meaning it is clipped below that value.

Worked examples

Example 1: how much data the planner sees per decision

The paper's planner settings are H=12H = 12 (horizon), I=10I = 10 (iterations), J=1000J = 1000 (candidates per iteration) and K=100K = 100 (refit set). Using these numbers:

  1. Each iteration scores J=1000J = 1000 candidate sequences.
  2. Ten iterations give 10×1000=10,00010 \times 1000 = 10{,}000 sequences scored per real action.
  3. Each sequence has 12 steps, so one decision costs 10,000×12=120,00010{,}000 \times 12 = 120{,}000 latent-model steps.
  4. Each step is a small network applied to a 200-unit state and a 30-dimensional latent, with no image generated.

The count is my arithmetic from the stated settings, not a figure the paper reports. It shows why the latent space matters. Generating 120,000 images for every action would cost far more than predicting 120,000 small latent steps.

Example 2: one CEM iteration in one dimension

Take a single action in [−1,1][-1, 1] with planning horizon 1, J=5J = 5 candidates and K=2K = 2 elites, starting from mean 0 and standard deviation 1.

  1. Draw five values from N(0,1)\mathcal{N}(0, 1) and keep those inside the range: 0.80.8, −0.3-0.3, 0.10.1, 0.60.6, −0.4-0.4.
  2. The model predicts a reward for each: 0.20.2, 0.050.05, 0.60.6, 0.010.01, 0.50.5.
  3. The two highest-scoring candidates are 0.10.1 (reward 0.60.6) and −0.4-0.4 (reward 0.50.5).
  4. Refit the mean to (0.1+(−0.4))/2=−0.15(0.1 + (-0.4)) / 2 = -0.15. The two elites lie 0.250.25 either side of that mean, so the refit standard deviation is 0.250.25.
  5. The next iteration samples around −0.15-0.15 with spread 0.250.25, so the search narrows.

After II iterations the planner returns the mean for the current step. The example is illustrative; the paper's own search uses 1000 candidates and 100 elites.

Results

Setup. The tasks come from the DeepMind control suite: cartpole swingup, reacher easy, cheetah run, finger spin, cup catch and walker walk. The only input is a third-person 64×64×364 \times 64 \times 3 camera image. The paper describes why each is hard: cartpole needs long horizons and memory of the cart when it leaves the view, reacher has a sparse reward, finger involves contact, cup has a sparse reward for catching the ball, and walker must stand before it can walk.

Table 1: final performance and data efficiency

MethodInputEpisodesCartpoleReacherCheetahFingerCupWalker
A3Cproprioceptive100,000558285214129105311
D4PGpixels100,000862967524985980968
PlaNet (this paper)pixels1,000821832662700930951
CEM with true simulatorsimulator state0850964656825993994
Data efficiency of PlaNet over D4PG25040500+30010090

The table shows PlaNet ahead of D4PG on cheetah, where it scores 662 against 524, and behind it on reacher, finger and cup. The paper says it "achieves similar performance" to D4PG overall. The data-efficiency row is the authors' estimate of how many episodes D4PG needs to reach PlaNet's final score, as the table caption describes. The cheetah entry is printed as "500+", and the paper does not explain the plus sign further.

Against model-free methods. Within 100 episodes PlaNet beats A3C, which trained for 100,000 episodes on proprioceptive states. After 500 episodes it is similar to D4PG on all tasks except finger. The paper reports a 26% relative gain over D4PG's final performance on cheetah run. Training takes 10 to 20 hours on one V100 GPU, depending on the task.

Design choices. Figure 3 compares the RSSM with a purely deterministic GRU and a purely stochastic state-space model. Both parts are needed. The paper calls the stochastic part "even more important": the agent does not learn without it on these tasks. Figure 4 compares PlaNet with a version that collects data under random actions and one that chooses the best of 1000 sampled sequences at each step without iterative refinement. Online data collection helps on every task, and iterative CEM improves on all tasks.

Multi-task. One agent trained on all six tasks, without being told which one it faces, learns all of them, but more slowly than separate agents (Appendix C).

Limits. The experiments are simulated. The paper notes that robotics video-prediction work deals with the visual complexity of the real world, while it focuses on simulated control with simple visuals. It makes no claim about real robots.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
Only one-step predictions are trainedMulti-step predictions drift, and planning needs multi-step accuracyMulti-step objective such as latent overshooting, which the paper found helpful for other models
Very long planning horizonsThe search space grows, and the paper's Figure 11 shows performance fallsShorter horizons, or a learned value function, which the paper lists as future work
No online data collectionLearned models see only random-action dataCollect episodes with the planner, which the paper found necessary on cartpole, finger and walker
Model-based planning with a known simulatorNo learned model is neededPlan with the true dynamics; the CEM row of Table 1 shows this upper bound

The horizon numbers come from Figure 11, which uses the true simulator on cheetah run. The paper reports that a horizon of 6 is not sufficient there and that horizons much longer than about 8 steps hurt, since the search space grows. That is a result for one setting, not a general rule.

Why it mattered

The paper says it "is a promising approach" to learn latent dynamics for planning in image domains, and that its agent reaches comparable performance with about 200 times fewer episodes. Its discussion lists the next steps it proposes: learning temporal abstraction instead of a fixed action repeat, adding a value function beyond the planning horizon, gradient-based planning for efficiency, representations that do not need reconstruction for visually diverse tasks, and sharing one dynamics model across tasks. Those are the directions the paper itself names. The paper also says it provides a starting point for multi-task control.

History

The paper's related-work section places it after earlier work it cites. That includes PILCO and neural-network dynamics models on low-dimensional states (Deisenroth and Rasmussen, 2011; Chua et al., 2018), E2C and RCE, which embed images into a latent space with locally linear transitions (Watter et al., 2015; Banijamali et al., 2017), and recurrent and state-space latent models for video (Chung et al., 2015; Karl et al., 2016). The paper says it lifts the Markov assumption of the E2C and RCE line of work, which makes its method applicable under partial observability, and that it tests on tasks with longer horizons, contact dynamics and sparse rewards.

Reading guide

Read the paper in this order and use these lessons for the sections that need them.

  1. Introduction (Section 1): Model-Based Reinforcement Learning for why planning with a learned model is attractive, and Reinforcement Learning for the model-free baselines.
  2. Latent planning (Section 2): Partially Observable Markov Decision Process for the problem setup, Model Predictive Control for replanning at each step, and Cross-Entropy Method for the planner.
  3. Recurrent state-space model (Section 3): Recurrent State Space Model for the model itself, Variational Autoencoder for the encoder, Variational Lower Bound (ELBO) for the objective, Gaussian (Normal) Distribution for the stochastic states, and Transposed Convolution for the image decoder.
  4. Latent overshooting (Section 4): Kullback–Leibler Divergence for the complexity term, which is what overshooting multiplies over several distances.
  5. Experiments (Sections 5 and 6): no new prerequisites. Table 1 and the design comparisons use the terms defined above.

Check yourself

QuestionPlaNet plans without generating images. Why is that choice necessary for the planner's cost?Show answer
The planner scores thousands of candidate action sequences at every step, and each one needs a predicted reward. Generating an image for every predicted step would multiply the cost of each candidate by the cost of a decoder pass. Predicting reward from the latent state alone keeps each step to small network evaluations, which is why the paper can use 1,000 candidates for 10 iterations at each decision.
QuestionUsing the paper's settings H = 12, I = 10 and J = 1000, how many latent-model steps does one real action cost?Show answer
10×1000×12=120,00010 \times 1000 \times 12 = 120{,}000 steps. The arithmetic is from the stated settings. The paper does not report this total.
QuestionWhy does the RSSM split its state into a deterministic path and a stochastic path, rather than using only one?Show answer
The deterministic path lets the model remember information over many steps without the variance having to reach zero, which the paper says optimisation may not find. The stochastic path lets the model represent several possible futures, which a purely deterministic model cannot do. The paper's experiments show the deterministic path is needed to remember and the stochastic path is needed for planning to work at all.
QuestionA learned model is 95% accurate for one-step predictions. Why might it still plan badly, and what does latent overshooting try to fix?Show answer
Small one-step errors compound over many steps, and a model fit only to one-step predictions does not have to be good at long rollouts. Planning needs multi-step accuracy because the search evaluates whole sequences. Latent overshooting adds KL terms for predictions up to D steps ahead, so the model is trained on multi-step cases. The paper found it helped other models but slightly hurt its final RSSM, so the final agent does not use it.
QuestionIn the table, PlaNet scores 662 on cheetah and D4PG scores 524. Does this mean PlaNet is better than D4PG everywhere?Show answer
No. It is better on cheetah, but D4PG scores higher on reacher (967 vs 832), finger (985 vs 700) and cup (980 vs 930). The paper's claim is that PlaNet is close to D4PG overall while using far fewer episodes. The data-efficiency row is a separate claim, about how many episodes D4PG needs to match PlaNet's final score.

Sources

Read the full paper

Danijar Hafner, Timothy Lillicrap, Ian Fischer et al., 2018. arXiv:1811.04551