Year: 2019

Abstract:
To flexibly and efficiently reason about temporal sequences, abstract representations that compactly represent the important information in the sequence are needed. One way of constructing such representations is by focusing on the important events in a sequence. In this paper, we propose a model that learns both to discover such key events (or keyframes) as well as to represent the sequence in terms of them. We do so using a hierarchical Keyframe-Inpainter (KEYIN) model that first generates keyframes and their temporal placement and then inpaints the sequences between keyframes. We propose a fully differentiable formulation for efficiently learning the keyframe placement. We show that KEYIN finds informative keyframes in several datasets with diverse dynamics. When evaluated on a planning task, KEYIN outperforms other recent proposals for learning hierarchical representations.

text: To flexibly and efficiently reason about temporal sequences, abstract representations that compactly represent the important information in the sequence are needed. One way of constructing such representations is by focusing on the important events in a sequence. In this paper, we propose a model that learns both to discover such key events (or keyframes) as well as to represent the sequence in terms of them. We do so using a hierarchical Keyframe-Inpainter (KEYIN) model that first generates keyframes and their temporal placement and then inpaints the sequences between keyframes. We propose a fully differentiable formulation for efficiently learning the keyframe placement. We show that KEYIN finds informative keyframes in several datasets with diverse dynamics. When evaluated on a planning task, KEYIN outperforms other recent proposals for learning hierarchical representations.

heading: 1 INTRODUCTION
text: When thinking about the future, humans focus their thoughts on the important things that may happen (When will the plane depart?) without fretting about the minor details that fill each intervening moment (What is the last word I will say to the taxi driver?). Because the vast majority of elements in a temporal sequence contains redundant information, a temporal abstraction can make reasoning and planning both easier and more efficient. How can we build such an abstraction? Consider the example of a lead animator who wants to show what happens in the next scene of a cartoon. Before worrying about every low-level detail, the animator first sketches out the story by keyframing, drawing the moments in time when the important events occur. The scene can then be easily finished by other animators who fill in the rest of the sequence from the story laid out by the keyframes. In this paper, we argue that learning to discover such informative keyframes from raw sequences is an efficient and powerful way to learn to reason about the future.
Our goal is to learn such an abstraction for future image prediction. In contrast, much of the work on future image prediction has focused on frame-by-frame synthesis (Oh et al. (2015); Finn et al. (2016)). This strategy puts an equal emphasis on each frame, irrespective of the redundant content it may contain or its usefulness for reasoning relative to the other predicted frames. Other recent work has considered predictions that “jump” more than one step into the future, but these approaches either used fixed-offset jumps (Buesing et al., 2018) or used heuristics to select the predicted frames (Neitz et al., 2018; Jayaraman et al., 2019; Gregor et al., 2019). In this work, we propose a method that selects the keyframes that are most informative about the full sequence, so as to allow us to reason about the sequence holistically while only using a small subset of the frames. We do so by ensuring that the full sequence can be recovered from the keyframes with an inpainting strategy, similar to how a supporting animator finishes the story keyframed by the lead.
One possible application for a model that discovers informative keyframes is in long-horizon planning. Recently, predictive models have been employed for model-based planning and control (Ebert et al. (2018)). However, they reason about every single future time step, limiting their applicability to short horizon tasks. In contrast, we show that a model that reasons about the future using a small set of informative keyframes enables visual predictive planning for horizons much greater than previously possible by using keyframes as subgoals in a hierarchical planning framework.
To discover informative frames in raw sequence data, we formulate a hierarchical probabilistic model in which a sequence is represented by a subset of its frames (see Fig. 1). In this two-stage model, a keyframing module represents the keyframes as well as their temporal placement with stochastic latent variables. The images that occur at the timepoints between keyframes are then inferred by an inpainting module. We parametrize this model with a neural network and formulate a variational lower bound on the sequence log-likelihood. Optimizing the resulting objective leads to a model that discovers informative future keyframes that can be easily inpainted to predict the full future sequence.
Our contributions are as follows. We formulate a hierarchical approach for the discovery of informative keyframes using joint keyframing and inpainting (KEYIN). We propose a soft objective that allows us to train the model in a fully differentiable way. We first analyze our model on a simple dataset with stochastic dynamics in a controlled setting and show that it can reliably recover the underlying keyframe structure on visual data. We then show that our model discovers hierarchical temporal structure on more complex datasets of demonstrations: an egocentric gridworld environment and a simulated robotic pushing dataset, which is challenging for current approaches to visual planning. We demonstrate that the hierarchy discovered by KEYIN is useful for planning, and that the resulting approach outperforms other proposed hierarchical and non-hierarchical planning schemes on the pushing task. Specifically, we show that keyframes predicted by KEYIN can serve as useful subgoals that can be reached by a low-level planner, enabling long-horizon, hierarchical control.

heading: 2 RELATED WORK
text: Hierarchical temporal structure. Hierarchical neural models for efficiently modeling sequences were proposed in Liu et al. (2015); Buesing et al. (2018). These approaches were further extended to predict with an adaptive step size so as to leverage the natural hierarchical structure in language data (Chung et al., 2016; Kádár et al., 2018). However, these models rely on autoregressive techniques for text generation and applying them to structured data, such as videos, might be impractical.
The video processing community has used keyframe representations as early as 1991 in the MPEG codec (Gall, 1991). Wu et al. (2018) adapted this algorithm in the context of neural compression; however, these approaches use constant offsets between keyframes and thus do not fully reflect the temporal structure of the data. Recently, several neural methods were proposed to leverage such temporal structure. Neitz et al. (2018) and Jayaraman et al. (2019) propose models that find and predict the least uncertain “bottleneck” frames. Gregor et al. (2019) construct a representation that can be used to predict any number of frames into the future. In contrast, we propose an approach for hierarchical video representation that discovers the keyframes that best describe a certain sequence.
In parallel to our work, Kipf et al. (2019) propose a related method for video segmentation via generative modeling. Kipf et al. (2019) focus on using the discovered task boundaries for training hierarchical RL agents, while we show that our model can be used to perform efficient hierarchical planning by representing the sequence with only a small set of keyframes. Also concurrently, Kim et al. (2019) propose a similar method to KEYIN for learning temporal abstractions. While Kim et al. (2019) focuses on learning hierarchical state-space models, we propose a model that operates directly in the observation space and performs joint keyframing and inpainting.
Video modeling. Early approaches to probabilistic video modeling include autoregressive models that factorize the distribution by considering pixels sequentially (Kalchbrenner et al., 2017; Reed et al., 2017). To reason about the images in the video holistically, latent variable approaches were developed based on variational inference (Chung et al., 2015; Rezende et al., 2014; Kingma & Welling, 2014), including (Babaeizadeh et al., 2018; Denton & Fergus, 2018; Lee et al., 2018) and large-scale models such as (Castrejon et al., 2019; Villegas et al., 2019). Kumar et al. (2019) is a recently proposed approach that uses exact inference based on normalizing flows (Dinh et al., 2014; Rezende & Mohamed, 2015). We build on existing video modeling approaches and show how they can be used to learn temporal abstractions with a novel keyframe-based generative model.
Visual planning and model predictive control. We build on recent work that explored applications of learned visual predictive models to planning and control. Several groups (Oh et al., 2015; Finn et al., 2016; Chiappa et al., 2017) have proposed models that predict the consequences of actions taken by an agent given its control output. Recent work (Byravan et al., 2017; Hafner et al., 2018; Ebert et al., 2018) has shown that visual model predictive control based on such models can be applied to a variety of different settings. In this work, we show that the hierarchical representation of a sequence in terms of keyframes improves planning performance in the hierarchical planning setting.
3 KEYFRAMING THE FUTURE
Our goal is to develop a model that generates sequences by first predicting key observations and the time steps when they occur and then filling in the remaining observations in between. To achieve this goal, in the following we (i) define a probabilistic model for joint keyframing and inpainting, and (ii) show how a maximum likelihood objective leads to the discovery of keyframe structure.

heading: 3.1 A PROBABILISTIC MODEL FOR JOINT KEYFRAMING AND INPAINTING
text: We first describe a probabilistic model for joint keyframing and inpainting of a sequence I1:T . The model consists of two parts: the keyframe predictor and the sequence inpainter (see Fig. 2).
The keyframe predictor takes in C conditioning frames Ico and produces N keyframes K1:N as well as the corresponding time indices τ1:N :
p(K1:N , τ1:N |Ico) = ∏ n p(Kn, τn|K1:n−1, τ1:n−1, Ico). (1)
From each pair of keyframes, the sequence inpainter generates the sequence of frames in between: p(Iτn:τn+1−1|Kn,Kn+1, τn+1 − τn) = ∏ n p(It|Kn,Kn+1, Iτn:t−1, τn+1 − τn), (2)
which completes the generation of the full sequence. The inpainter additionally observes the number of frames it needs to generate τn+1− τn. The temporal spacing of the most informative keyframes is data-dependent: shorter keyframe intervals might be required in cases of rapidly fluctuating motion, while longer intervals can be sufficient for steadier motion. Our model handles this by predicting the keyframe indices τ and inpainting τn+1−τn frames between each pair of keyframes. We parametrize the prediction of τn in relative terms by predicting offsets δn: τn = τn−1 + δn.

heading: 3.2 KEYFRAME DISCOVERY
text: To produce a complex multimodal distribution over K we use a per-keyframe latent variable z with prior distribution p(z) and approximate posterior q(z|I, Ico).1 We construct a variational lower bound
1For simplicity, the variable representing the full sequence is written without indices (I is the same as I1:T ).
on the likelihood of both I and K as follows2:
ln p(I,K|Ico) ≥ Eq(z|I,Ico) [ N∑ n=1 lnEp(τn,τn+1|z1:n,Ico) [ p(Iτn:τn+1 |Kn,n+1, τn+1 − τn) ]︸ ︷︷ ︸ inpainting
+ ln p(K|z, Ico)︸ ︷︷ ︸ keyframing
] −DKL (q(z|I, Ico)||p(z))︸ ︷︷ ︸
regularization
.
(3)
In practice, we use a weight β on the KL-divergence term, as is common in amortized variational inference (Higgins et al., 2017; Alemi et al., 2018; Denton & Fergus, 2018).
If a simple model is used for inpainting, most of the representational power of the model has to come from the keyframe predictor. We use a relatively powerful latent variable model for the keyframe predictor and a simpler Gaussian distribution produced with a neural network for inpainting. Because of this structure, the keyframe predictor has to predict keyframes that describe the underlying sequence well enough to allow a simpler inpainting process to maximize the likelihood. We will show that pairing a more flexible keyframe predictor with a simpler inpainter allows our model to discover semantically meaningful keyframes in video data.

heading: 4 CONTINUOUS RELAXATION BY LINEAR INTERPOLATION IN TIME
text: Our model can dynamically predict the keyframe placement τn. However, learning a distribution over the discrete variable τn is challenging due to the expensive evaluation of the expectation over p(τn|z1:n, Ico) in the objective in Eq. 3. To be able to evaluate this term efficiently and in a differentiable manner while still learning the keyframe placement, we propose a continuous relaxation of the objective. The placement distribution τn defines a probability for each predicted frame to match to a certain frame in the ground truth sequence. Instead of sampling from this distribution to pick a target frame we produce a soft target for each predicted frame by computing the expected target frame, i.e. the weighted sum of all frames in the true sequence, each multiplied with the probability of matching to the predicted frame. When the
entropy of τn converges to zero, the continuous relaxation objective is equivalent to the original, discrete objective. 3
Keyframe targets. To produce a keyframe target, K̃n, we linearly interpolate between the ground truth images according to the predicted distribution over the keyframe’s temporal placement τn: K̃n = ∑ t τ n t It, where τ n t is the probability that the n
th keyframe occurs at timestep t. This process is depicted in Fig. 3.
We parametrize temporal placement prediction in terms of offsets δ with a maximum offset of J . Because of this, the maximum possible length of the predicted sequence is NJ . It is desirable for J to be large enough to be able to capture the distribution of keyframes in the data, but this may lead to
2Keyframes K and time indices τ are modeled as independent given the corresponding latent variable z such that the latter captures the dependency between the former two.
3We find this occurs most of the time in practice.
the generation of sequences longer than the target NJ > T . To correctly compute the value of the relaxed objective in this case, we discard predicted frames at times > T and normalize the placement probability output by the network so that it sums to one over the first T steps. Specifically, for each keyframe we compute this probability as cn: cn = ∑ t≤T τ n t . The loss corresponding to the last two terms of Eq. (3) then becomes:
Lkey =
∑ n c n ( ||K̂n − K̃n||2 + β DKL ( q(zn|I−C+1:T , z1:n−1)||p(zn) ))∑ n c n . (4)
Inpainting targets. To complete our relaxed objective, for each ground truth frame, we produce a target image composed from the inpainted frames.4 We note that as offsets δ have a maximum range of J , and in general have non-zero probability on each timestep, the inpainting network needs to produce J frames În1:J between each pair of keyframes ( Kn,Kn+1 ) . As in the previous section, the targets for ground truth images are given as an interpolation between generated images weighted by the probability of the predicted frame Înj being matched to ground truth frame It: Ĩt = ( ∑ n,jm n j,tÎ n j )/ ∑ n,jm n j,t. Here, m n j,t is the probability that the j-th predicted image in segment n has an offset of t from the beginning of the predicted sequence, which can be computed from τn. To obtain a probability distribution over produced frames, we normalize the result with∑ n,jm n j,t. The full loss for our model is:
Ltotal = Lkey + βI ∑ t ||It − Ĩt||2. (5)

heading: 5 DEEP VIDEO KEYFRAMING
text: We show how to instantiate KEYIN with deep neural networks and train it on high-dimensional observations, such as images. We further describe an effective training procedure for KEYIN.

heading: 5.1 ARCHITECTURE
text: We use a common encoder-recurrent-decoder architecture (Denton & Fergus (2018); Hafner et al. (2018)). Video frames are first processed with a convolutional encoder module to produce image embeddings ιt = CNNenc(It). Inferred frame embeddings ι̂ are decoded with a convolutional decoder Înj = CNNdec(ι̂ n j ). The keyframe predictor p(K
1:N , τ1:N |z1:N , Ico) is parametrized with a Long Short-Term Memory network (LSTM, Hochreiter & Schmidhuber (1997)). To condition the keyframe predictor on past frames, we initialize its state with the final state of another LSTM that processes the conditioning frames. Similarly, we parametrize the sequence inpainter p(Iτn:τn+1 |Kn,Kn+1, τn+1 − τn) with an LSTM. We condition the inpainting on both keyframe embeddings, κ̂n−1 and κ̂n, as well as the temporal offset between the two, δn, by passing these inputs through a multi-layer perceptron that produces the initial state of the inpainting LSTM.
4This makes sure that each ground truth frame contributes equally to the final loss.
We use a Gaussian distribution with identity variance as the output distribution for both the keyframe predictor and the inpainting model and a multinomial distribution for δn. We parametrize the inference q(z1:N |I−C+1:T ) with an LSTM with attention over the entire input sequence. The inference distribution is a diagonal covariance Gaussian, and the prior p(z1:N ) is a unit Gaussian. Further details of the inference procedure are given in Sec. B and Fig. 8 of the Appendix.

heading: 5.2 TRAINING PROCEDURE
text: We train our model in two stages. First, we train the sequence inpainter to inpaint between ground truth frames sampled with random offsets, thus learning interpolation strategies for a variety of different inputs. In the second stage, we train the keyframe predictor using the loss from Eq. 5 by feeding the predicted keyframe embeddings to the inpainter. In this stage, the weights of the inpainter are frozen and are only used to backpropagate errors to the rest of the model. We found that this simple two-stage procedure improves optimization of the model.
We use L1 reconstruction losses to train the keyframe predictor. We found that this and adding a reconstruction loss on the predicted embeddings of the keyframes, weighted with a factor βκ, improved the ability of the model to produce informative keyframes. Target embeddings are computed using the same soft relaxation used for the target keyframes. More details of the loss computation are given in Sec. E and Algorithm 1 of the Appendix.

heading: 6 EXPERIMENTS
text: We evaluate the quality of KEYIN’s representation for future sequences by addressing the following questions: (i) Can it discover and predict informative keyframes? (ii) Can it model complex data distributions? (iii) Is the discovered hierarchy useful for long-horizon hierarchical planning?
Datasets. We evaluate our model on three datasets containing structured long-term behavior. The Structured Brownian motion (SBM) dataset consists of binary image sequences of size 32× 32 pixels in which a ball randomly changes directions after periods of straight movement of six to eight frames.
The Gridworld Dataset consists of 20k sequences of an agent traversing a maze with different objects. The agent sequentially navigates to objects and interacts with them following a task sketch.We use the same maze for all episodes and randomize the initial position of the agent and the task sketch. We use 64× 64 pixel image observations and further increase visual complexity by constraining the field of view to a 5× 5-cells egocentric window.
The Pushing Dataset consists of 50k sequences of a robot arm pushing a puck towards a goal on the opposite side of a wall. Each sequence consists of six consecutive pushes. We vary start and target position of the puck, as well as the placement of the wall. The demonstrations were generated with the MuJoCo simulator (Todorov et al., 2012) at a resolution of 64× 64 pixels. For more details on the data generation process, see Sec.D of the Appendix.
Further details about the experimental setup are given in Sec. C of the Appendix.

heading: 6.1 KEYFRAME DISCOVERY
text: To evaluate KEYIN’s ability to discover keyframes, we train KEYIN on all three datasets with N = 6, which can be interpreted as selecting the N most informative frames from a sequence. We show qualitative examples of keyframe discovery for the SBM dataset in Fig. 4 and for the Gridworld and Pushing datasets in Fig. 5.
On all datasets the model discovers meaningful keyframes which mark direction changes of the ball, transitions between pushes or interactions with objects, adapting its keyframe prediction patterns to the data. Consequently, the inpainter network is able to produce frames of high visual quality. Misplaced keyframes yield blurry interpolations, as can be seen for the jumpy prediction in Fig. 4. This suggests that keyframes found by KEYIN describe the overall sequences better.
To show that KEYIN discovers informative keyframes, we compare keyframe predictions against an alternative approach that measures the surprise associated with observing a frame given the previous frames. This approach selects keyframes as the N frames with the largest peaks in “surprise” as measured by the KL-divergence DKL[q(zt|I1:t)||p(zt)] between the prior and the posterior of a stochastic predictor based on Denton & Fergus (2018) (see Sec. F and Algorithm 2 of the Appendix for details). We provide comparisons to alternative formulations of surprise in Appendix Sec. F, Tab. 3.
For quantitative analysis, we define approximate ground truth keyframes to be the points of direction change for the SBM dataset, the moments when the robot lifts its arm to transitions between pushes, or when the agent interacts with objects in the gridworld. We report F1 scores that capture both the precision and recall of keyframe discovery.
We additionally compare to random keyframe placement, and a learned but static baseline that is the same for all sequences. The evaluation in Tab. 1 shows that KEYIN discovers better keyframes than alternative methods. The difference is especially large on the more complex Pushing and Gridworld datasets. The surprise-based method does not reason about which frames are most helpful to reconstruct the entire trajectory and thus is unable to discover the correct structure on the more complex datasets. In addition to the F1 scores, we report temporal distance between predicted and annotated keyframes in Appendix, Tab. 4, also indicating that KEYIN is better able to discover the temporal structure in both datasets.

heading: 6.2 KEYFRAME-BASED VIDEO MODELING
text: Even though the focus of this work is on discovering temporal structure via keyframing and not on improving video prediction quality, we verify that KEYIN can represent complex data distributions in terms of discovered keyframes and attains high diversity and visual quality. We show sample generations from our model on the Pushing and Gridworld datasets on the supplementary website5.
5https://sites.google.com/view/keyin
We see that KeyIn is able to faithfully model complex distributions of video sequences. We further visualize multiple sampled Pushing sequences from our model conditioned on the same start position in Fig. 6, showing that KEYIN is able to cover both modes of the demonstration distribution. We further show that KEYIN compares favorably to prior work on video prediction metrics on sequence modeling in Tab. 5 of the Appendix, and outperforms prior approaches in terms of keyframe modeling in Appendix, Tab. 6.

heading: 6.3 ROBUSTNESS OF KEYFRAME DETECTION
text: Table 2: Keyframe discovery for varied number of predicted keyframes. The data has approximately 6 keyframes. Uninterpretable entries are omitted for clarity: see the text for details.
# KEYFRAMES 4 6 8
BROWNIAN PRECISION 0.92 0.92 -RECALL - 0.96 0.90 PUSH PRECISION 0.30 0.38 -RECALL - 0.48 0.46 GRIDWORLD PRECISION 0.37 0.43 -RECALL - 0.41 0.40
In the previous sections, we showed that when the sequence can indeed be summarized with N keyframes, KEYIN predicts the keyframes that correspond to our notion of salient frames. However, what happens if we train KEYIN to select a larger or a smaller amount of keyframes?
To evaluate this, we measure KEYIN recall with extra and precision with fewer available keyframes. We note that high precision is unachievable in the first case and high recall is unachievable in the second case, since these problems are misspecified. As these numbers are not informative, we do not report them. In Tab. 2, we see that KEYIN is able to find informative keyframes even when N does not exactly match the structure of the data. We further qualitatively show that KEYIN selects a superset or a subset of the original keyframes respectively in Sec. G. This underlines that our method’s ability to discover keyframe structure is robust to the choice of the number of predicted keyframes.
As a first step towards analyzing the robustness of KEYIN under more realistic conditions we report keyframe discovery when trained and tested on sequences with additive Gaussian noise, a noise characteristic commonly found in real-world camera sensors. We find that KEYIN is still able to discover the temporal structure on both the Pushing and the Gridworld dataset. For qualitative and quantitative results, see Appendix Fig. 11 and Tab. 7.

heading: 6.4 HIERARCHICAL KEYFRAME-BASED PLANNING
text: We have seen that KEYIN can find frames that correspond to an intuitive notion of keyframes. This demonstrates that the keyframes discovered by KEYIN do indeed capture an abstraction that compactly describes the sequence. In light of this, we hypothesize that an informative set of keyframes contains sufficient information about a sequence to effectively follow the trajectory it shows. To test this, we use the inferred keyframes as subgoals for hierarchical planning in the pushing environment. During task execution, we first plan a sequence of keyframes that reaches the target using our learned keyframe predictor. Specifically, we generate keyframe trajectories from our model by sampling latent variables z from the prior and using them to roll out the keyframe prediction model. We optimize for a sequence of latent variables z that results in a keyframe trajectory which reaches the goal using the Cross-Entropy Method (CEM, Rubinstein & Kroese (2004)). We then execute the plan by using the keyframes as subgoals for a low-level planner. This planner reaches each subgoal via model predictive control using ground truth dynamics, again employing CEM for optimization of the action trajectory. This planning procedure is illustrated in Fig. 7 (left). For more details, see Sec. I and Algs. 3 and 4 of the Appendix.
We find that KEYIN is able to plan coherent subgoal paths towards the final goal that often lead to successful task execution (executions are shown on the supplementary website6). To quantitatively evaluate the keyframes discovered, we compare to alternative subgoal selection schemes: fixed time offset (Jumpy, similar to Buesing et al. (2018)), a method that determines points of peak surprise (Surprise, see Sec. 6.1), and a bottleneck-based subgoal predictor (time-agnostic prediction or TAP, Jayaraman et al. (2019)). We additionally compare to an approach that plans directly towards the final goal using the low-level planner (Flat). We evaluate all methods with the shortest path between
6https://sites.google.com/view/keyin
the target and the actual position of the object after the plan is executed. All compared methods use the same low-level planner as we only want to measure the quality of the predicted subgoals.
As shown in Fig. 7 (right), our method outperforms all prior approaches. TAP shows only a moderate increase in performance over the Flat planner, which we attribute to the fact that it fails to predict good subgoals and often simply predicts the final image as the bottleneck. This is likely due to the relatively large stochasticity of our dataset and the absence of the clear bottlenecks that TAP is designed to find. Our method outperforms the planners that use Jumpy and Surprise subgoals. This further confirms that KEYIN is able to produce keyframes that are informative about the underlying trajectory, such that planning toward these keyframes makes it easier to follow the trajectory.

heading: 7 DISCUSSION
text: We presented KEYIN, a method for representing a sequence by its informative keyframes by jointly keyframing and inpainting. KEYIN first generates the keyframes of a sequence and their temporal placement and then produces the full sequence by inpainting between keyframes. We showed that KEYIN discovers informative keyframes on several datasets with stochastic dynamics. Furthermore, by using the keyframes for planning, we showed our method outperforms several other hierarchical planning schemes. Our method opens several avenues for future work. First, an improved training procedure that allows end-to-end training is desirable. Second, more powerful hierarchical planning approaches can be designed using the keyframe representation to scale to long-term real-world tasks. Finally, the proposed keyframing method can be applied to a variety of applications, including video summarization, video understanding, and multi-stage hierarchical video prediction.

heading: B ARCHITECTURE DETAILS
text: We found simple attention over LSTM outputs to be an effective inference procedure. Our approximate inference network LSTMinf outputs (κ inf t , ζt)t≤T , where κ
inf is an embedding used to compute an attention weight and the ζt are values to be attended over. We compute the posterior distribution over zt using a key-value attention mechanism (Bahdanau et al., 2015; Luong et al., 2015):
an,t = exp(d(κ̂ n−1, κinft )) (6) µn, σn = ( ∑ t an,tζt)/ ∑ t an,t. (7)
The distance metric, d, is the standard inner product. The architecture used for keyframe inference, including the attention mechanism, is depicted in Supplemental Fig. 8.

heading: C EXPERIMENTAL SETUP
text: We set the prediction horizon to T = 30 frames and predict N = 6 segments with J = 10 frames each for the SBM dataset and 6 frames each for the Pushing dataset. We pre-train the interpolator on segments of two to eight frames for Structured Brownian motion data, and two to six frames for Pushing data. The weight on the KL-divergence term for the interpolator VAE is 1e−3. For training
the keyframe predictor, we set βK = 0, βκ = 1, β = 5e−2. The hyperparameters were hand-tuned. We activate the generated images with a sigmoid and use BCE losses on each color channel to avoid saturation. The convolutional encoder and decoder both have three layers for the Structured Brownian motion dataset and four layers for the Pushing dataset. We use a simple two-layer LSTM with a 256-dimensional state in each layer for all recurrent modules. Each LSTM has a linear projection layer before and after it that projects the observations to and from the correct dimensions. We use the Adam optimizer (Kingma & Ba, 2015) with β1 = 0.9 and β2 = 0.999, batch size of 30, and a learning rate of 2e−4. For more details please refer to the appendix. Each network was trained on a single high-end NVIDIA GPU. We trained the interpolator for 100K iterations, and the keyframe predictor for 200K iterations. The toal training time took about a day.
In the Pushing environment, we use a held-out test set of 120 of sequences. The Structured Brownian Motion dataset is generated automatically and is potentially infinite. We used 1000 testing samples on the Structured Brownian Motion generated using a different random seed.

heading: D DATA COLLECTION IN THE MUJOCO ENVIRONMENT
text: The data collection for our pushing dataset was performed in an environment simulated in MuJoCo Todorov et al. (2012). In the environment, a robot arm initialized at the center of the table pushes an object to a goal position located at the other side of a wall-shaped obstacle.
The demonstrations followed a rule-based algorithm that first samples subgoals between the initial position of the object and the goal and then runs a deterministic pushing procedure to the subgoals in order. The ground truth keyframes of the demonstrations were defined by frames at which subgoals were completed.
We subsampled demonstration videos by a factor of two when saving them to the dataset, dropping every other frame in the trajectory and averaging actions of every two consecutive frames. For all datasets we generated for this environment following a rule-based algorithm, we only kept successful demonstrations and dropped the ones that fail to push the object to the goal position within a predefined horizon.

heading: E DETAILS OF THE LOSS COMPUTATION ALGORITHM
text: We describe the details of the continuous relaxation loss computation in Algorithm 1.
Note that we efficiently implement computing of the cumulative distributions τ as a convolution, which allows us to vectorize much of the computation. Computational complexity of the proposed implementation scales linearly with the number of keyframes N , and number of allowed frames per segment J and number of ground truth frames T . The final complexity is O(NTJ), which we find in practice to be negligible compared to the time needed for the forward and backward pass.

heading: F SURPRISE BASELINE
text: Standard stochastic video prediction methods do not attempt to estimate keyframes, as they are designed to densely estimate future videos frame-by-frame. Accordingly, they cannot be used directly as baselines for keyframe prediction methods, such as KEYIN. However, Denton & Fergus (2018) observe that the variance of the learned prior of a stochastic video prediction model tends to spike before an uncertain event happens. We exploit this observation to find the points of high uncertainty for our strong Surprise baseline. We use the KL divergence between the prior and the approximate posterior KL[q(zt|I1:t)||p(zt)] to measure the surprise. This quantity can be interpreted as the number of bits needed to encode the latent variable describing the next state, it will be larger if the next state is more stochastic.
We train a stochastic video prediction network with a fixed prior (SVG-FP, Denton & Fergus (2018)) with the same architectures of encoder, decoder, and LSTM as our model. We found that selecting the peaks of suprise works the best for finding true keyframes. The procedure we use to select the keyframes is described in Algorithm 2. In order to find the keyframes in a sequence sampled from the prior, we run the inference network on the generated sequence.
Algorithm 1 Continuous relaxation loss computation Parameters: Number of ground truth frames T,Number of keyframes N Input: Ground truth frames I1:T ,Generated frames Îti , generated offset distributions δn Convert the distributions of interframe offsets δn to keyframe timesteps τn. For the first keyframe, τ1 = δ1. for t = 2 . . .M do
Compute further τn with chain rule. This can be efficiently computed via convolution: τn = τn−1 ∗ δn, i.e. τnt = ∑ j τn−1n−j+1δ n j .
end for Compute probabilities of keyframes being within the predicted sequence: cn = ∑ t≤T τ n t .
Compute soft keyframe targets: K̃n = ∑ t τ n t It.
Compute the keyframe loss: ( ∑ n c n||K̂n − K̃n||2)/ ∑ n c n.
Get probabilities of segments ending after particular frames: enj = ∑ j>i δ n j . Get distributions of individual frames timesteps: mnj,t ∝ τ n−1 t−j+1e n j .
Compute soft individual frames: Ĩt = ∑ t,im n j,tÎ t i
Compute the sequence loss: ∑ t ||It − Ĩt||2.
Algorithm 2 Selecting keyframes via Surprise Parameters: Number of ground truth frames N,Desired number of keyframes M Input: Input sequence I1:T ,Stochastic Video Prediction model SV G(.) Run the inference network over the sequence: q(z1:T |I1:T ) = SV G(I1:T ). Get the surprise measure: st = KL[q(zt|I1:t)||p(zt)]. Find the set of peak surprise points S where: st > st+1 ∧ st < st−1. if |S| < M then
add M − |S| maximum surprise points to S. end if Return: The M keyframes from S with maximum surprise.

heading: G ABLATION OF THE NUMBER OF PREDICTED KEYFRAMES
text: We show qualitative results of training KEYIN with N = 4, 6 (optimal number), and 8 on the SBM dataset in Fig. 9. We observe that if we train KEYIN to select a smaller or a larger number of keyframes than needed, it learns to predict a subset or a superset of the true keyframes, respectively. This property follows from the structure of the model, which encourages the model to predict the keyframes that allow the full sequence to be inpainted. When too few keyframes are available, the model will be unable to put keyframes at all important times, but those it picks must still be good for inpainting. When more keyframes are available than necessary, the model can place the additional keyframes at any time, as only a subset of the keyframes are needed to ensure good inpainting.

heading: 8 Keyframes

heading: 6 Keyframes

heading: 4 Keyframes
text: H VIDEO MODELING PERFORMANCE
We further report quantitative results on standard video prediction metrics, Structural Similarity Index (SSIM) and Peak Signal-to-Noise Ratio (PSNR), in Tab. 5. KEYIN is able to match performance of two comparable prior approaches, showing that the keyframe-based modeling is able to represent complex data distributions.

heading: I PLANNING ALGORITHM
text: Algorithm 3 Planning in the subgoal space. Input: Keyframe model KEYIN(., .), cost function c Input: Start and target images I1 and Itarget Set the sampling distribution to the prior:
µi = 0, σi = I for i = 1 . . . H do
Sample L sequences of latent variables: z1:N ∼ N (µi, σi) Produce L subgoal plans: K̂1:N = KEYIN(I1, z1:N ) Compute cost between generated and true targets:
c(K̂N , Itarget) Choose L′ best plans, refit sampling distribution:
µi+1, σi+1 = fit(z′i) end for Return: Best subgoal plan K1:N
To apply the KEYIN model for planning, we use the approach for visual planning outlined in Algorithm 1. At the initial timestep, we use the cross-entropy method (CEM) Rubinstein & Kroese (2004) to select subgoals for the task. To do so, we sample M̃ latent sequences z0 from
the priorN (0, I) and use the keyframe model to retrieve M̃ corresponding keyframe sequences, each with L frames. We define the cost of an image trajectory as the distance between the target image and the final image of each keyframe sequence defined under a domain-specific distance function (see below). In the update step of the CEM algorithm, we rank the trajectories based on their cost and fit a diagonal Gaussian distribution to the latents z′ that generated the M̃ ′ = rM̃ best sequences, where r is the elite ratio. We repeat the procedure above for a total of N iterations.
We define the cost between two frames used during planning as the Euclidean distance between the center pixels of the object in both frames. We recover the center pixel via color-based segmentation of the object. While this cost function is designed for the particular planning environment we are testing on, our algorithm can be easily extended to use alternative, more domain-agnostic cost formulations that have been proposed in the literature Finn & Levine (2017); Ebert et al. (2017; 2018).
After subgoals are selected, we use a CEM based planner to produce rollout trajectories. Similar to the subgoal generation procedure, at each time step, we initially sample M action sequences u0 from the prior N (0, I) and use the ground truth dynamics of the simulator to retrieve M corresponding image sequences, each with l frames7. We define the cost of an image trajectory as the distance between the target image and the final image of each trajectory. In the update step, we rank the trajectories based on their cost and fit a diagonal Gaussian distribution to the actions u′ that generated the M ′ = rM best sequences. After sampling a new set of actions un+1 from the fitted Gaussian distributions we repeat the procedure above for a total of N iterations.
Finally, we execute the first action in the action sequence corresponding to the best rollout of the final CEM iteration. The action at the next time step is chosen using the same procedure with the next observation as input and reinitialized action distributions. The algorithm terminates when the specified maximal number of planning steps Tmax has been executed or the distance to the goal is below a set threshold.
7In practice, we clip the sampled actions to a maximal action range [−amax,+amax] before passing them to the simulator.
We switch between planned subgoals if (i) the subgoal is reached, i.e. the distance to the subgoal is below a threshold dswitch measured in pixels, or (ii) the current subgoal was not reached for Ts,max execution steps. We use the true goal image as an additional, final subgoal.
Algorithm 4 Full two-stage planning algorithm Input: Keyframe model K̂1:L = LSTMkey(I, z1:L) Input: Video prediction model Ît:t+l = LSTMinter(I1:t−1, u2:t+l) Input: Subgoal index update heuristics ixt+1 = f(ixt, It,K1:L) Input: Start and goal images I1 and Igoal. Initialize latents from prior: z0 ∼ N (0, I). for i = 1 . . . Nit do
Rollout keyframe model for L steps, obtain M̃ future keyframe sequences K̂1:L. Compute distance between final and goal image: c = dist(K̂L, Igoal). Choose M̃ ′ best sequences, refit Gaussian distribution: µkeyi+1,σ key i+1 = fit(K ′ i). Sample new latents from updated distribution: zi+1 ∼ N (µkeyi+1,σ key i+1).
end for Feed best sequence of latents into keyframe model to obtain subgoals: K∗1:L = LSTMkey(I1, z∗Nit,0). Set current subgoal to ix1 = 1. for t = 1 . . . Tplan do
Perform subgoal update ixt = f(ixt−1, It−1,K∗1:L). Initialize latents from prior: u0 ∼ N (0, I). for i = 0 . . . Nit do
Rollout prediction model for l steps, obtain M future sequences Ît:t+l. Compute distance between final and subgoal image: c = dist(Ît+l,Kixt). Choose M ′ best sequences, refit Gaussian distribution: µi+1,σi+1 = fit(u′i). Sample new latents from updated distribution: ui+1 ∼ N (µi+1,σi+1).
end for Execute u∗Nit,0 and observe next image It.
end for
The parameters used for our visual planning experiments are listed in Supplemental Table 8.

Review summaries:
The paper introduces a model trained for video prediction hierarchically: a series of significant frames called “keyframes” in the paper are first predicted and then intermediate frames between keyframes couples are generated. The training criterion is maximum likelihood with a variational approximation. Experiments are performed on 3 different video datasets and the evaluation is performed for 3 tasks: keyframe detection, frame prediction and planning in robot videos.

The authors address the problem of discovering and predicting with hierarchical structure in data sequences of relevance to planning. Starting with the kinds of data that have been used recently in video prediction, the authors aim at learning a sequence of keyframes (i.e., subsets of frames forming the overall sequence) that in a suitable sense "summarize" the overall trace. As they rightly note, many alternate models struggle with making good long term predictions in part because they focus on all levels of prediction equally.