Title: KEYFRAMING THE FUTURE: DISCOVERING TEMPORAL HIERARCHY WITH KEYFRAME-INPAINTER PREDICTION

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.

1. INTRODUCTION:

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.

Keyframe Predictor Sequence Inpainter:

Figure 1 : Keyframing the future. Instead of predicting one frame after the other, we propose to represent the sequence with the keyframes that depict the interesting moments of the sequence. The remaining frames can be inpainted given the keyframes.

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.

2. RELATED WORK:

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:

Figure 2 : A probabilistic model for jointly keyframing and inpainting a future sequence. First, a sequence of keyframes K1:N is generated, as well as corresponding temporal indices τ 1:N , defining the structure of the underlying sequence. In the second stage, for each pair of keyframes K n and K n+1 , the frames I τ n :τ n+1 -1 are inpainted.

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.

3.1. A PROBABILISTIC MODEL FOR JOINT KEYFRAMING AND INPAINTING:

We first describe a probabilistic model for joint keyframing and inpainting of a sequence I 1: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 I co and produces N keyframes K 1:N as well as the corresponding time indices τ 1:N :

p(K 1:N , τ 1:N |I co ) = n p(K n , τ n |K 1:n-1 , τ 1:n-1 , I co ).

(1)

From each pair of keyframes, the sequence inpainter generates the sequence of frames in between:

EQUATION

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 .

3.2. KEYFRAME DISCOVERY:

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, I co ). 1 We construct a variational lower bound on the likelihood of both I and K as follows2 :

EQUATION

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. For each predicted keyframe Kn we compute a target image Kn as the sum of the ground truth images weighted with the corresponding distribution over index τ n . Finally, we compute the reconstruction loss between the estimated image Kn and the soft target Kn .

4. CONTINUOUS RELAXATION BY LINEAR INTERPOLATION IN TIME:

I 1 I 2 I 3 I T … K n Kn τ n … Placement Distribution Ground Truth Sequence ℒ Keyframe Predictor Keyframe Target ∑ T t= 1 τ n t I t

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 |z 1:n , I co ) 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. 3Keyframe targets. To produce a keyframe target, Kn , we linearly interpolate between the ground truth images according to the predicted distribution over the keyframe's temporal placement τ n : Kn = t τ n t I t , 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 N J. 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 the generation of sequences longer than the target N J > 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 c n : c n = t≤T τ n t . The loss corresponding to the last two terms of Eq. ( 3) then becomes:

EQUATION

)

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 În 1:J between each pair of keyframes K n , K n+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 În j being matched to ground truth frame I t : Ĩt = ( n,j m n j,t În j )/ n,j m 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,j m n j,t . The full loss for our model is:

L total = L key + β I t ||I t -Ĩt || 2 .

(5)

5. DEEP VIDEO KEYFRAMING:

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.

5.1. ARCHITECTURE:

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 = CNN enc (I t ). Inferred frame embeddings ι are decoded with a convolutional decoder În j = CNN dec (ι n j ). The keyframe predictor p(K 1:N , τ 1:N |z 1:N , I co ) 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 |K n , K n+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. 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(z 1: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(z 1:N ) is a unit Gaussian. Further details of the inference procedure are given in Sec. B and Fig. 8 of the Appendix.

5.2. TRAINING PROCEDURE:

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.

6. EXPERIMENTS:

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. 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. We see that our model covers both modes of the distribution, producing both trajectories that go to the right and to the left of the obstacle.



Ground Truth Generated:

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 D KL [q(z t |I 1:t )||p(z t )] 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.

6.2. KEYFRAME-BASED VIDEO MODELING:

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 .

Under review as a conference paper at ICLR 2020

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. 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.

6.3. ROBUSTNESS OF KEYFRAME DETECTION:

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.

6.4. HIERARCHICAL KEYFRAME-BASED PLANNING:

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 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.

7. DISCUSSION:

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.

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.

D DATA COLLECTION IN THE MUJOCO ENVIRONMENT:

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.

E DETAILS OF THE LOSS COMPUTATION ALGORITHM:

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(N T J), which we find in practice to be negligible compared to the time needed for the forward and backward pass.

SURPRISE BASELINE:

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(z t |I 1:t )||p(z t )] 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. the prior N (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 = r M best sequences, where r is the elite ratio. We repeat the procedure above for a total of N iterations.

µ i = 0, σ i = I for i = 1 . . . H do Sample L sequences of latent variables: z 1:N ∼ N (µ i , σ i ) Produce L

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 u 0 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 u n+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 T max has been executed or the distance to the goal is below a set threshold.

:

For simplicity, the variable representing the full sequence is written without indices (I is the same as I 1:T ).

Keyframes 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.

We find this occurs most of the time in practice.

This makes sure that each ground truth frame contributes equally to the final loss.

https://sites.google.com/view/keyin

https://sites.google.com/view/keyin

In practice, we clip the sampled actions to a maximal action range[-amax, +amax] before passing them to the simulator.

Figures and Tables:

Figure 3: Soft keyframe loss in the relaxed formulation.For each predicted keyframe Kn we compute a target image Kn as the sum of the ground truth images weighted with the corresponding distribution over index τ n . Finally, we compute the reconstruction loss between the estimated image Kn and the soft target Kn .

Figure4: Sequences generated by KEYIN and a method with constant temporal keyframe offset (Jumpy) on Brownian Motion data. Generation is conditioned on the first five frames. The first half of the sequence is shown. Movement direction changes are marked red in the ground truth sequence and predicted keyframes are marked blue. We see that KEYIN can correctly reconstruct the motion as it selects an informative set of keyframes. The sequence generated by the Jumpy method does not reproduce the direction changes since they cannot be inferred from the selected keyframes.

Figure 5: Example generations by KEYIN on (top) Pushing and (bottom) Gridworld data. The generation is conditioned on a single ground truth frame. Twelve of the 30 predicted frames are shown. We observe that for each transition between pushes and each action of the Gridworld agent our network predicts a keyframe either exactly at the timestep of the event or one timestep apart. Note, although agent position is randomized, objects not visible in the first image can be predicted in Gridworld because the maze is fixed across episodes.

Figure 6: Distribution of trajectories sampled from KEYIN. Each black line denotes one of 100 trajectories of the manipulated object. The obstacle is shown in blue and the initial position in pink.We see that our model covers both modes of the distribution, producing both trajectories that go to the right and to the left of the obstacle.

Figure 7: Hierarchical planning on the Pushing dataset. Left: We use the model to produce keyframes that represent the sequence between the current observation image and the goal. A low-level planner based on model predictive control produces the actions, a t , executed to reach each keyframe, until the final goal is reached. Right: Planning performance on a Pushing task. The hierarchy discovered by KEYIN outperforms comparable planning approaches.

Figure 10: A training sequence and two samples from our model on the Structured Brownian motion dataset. Each image shows an entire trajectory. Our model first samples the keyframes (shown in red), and then deterministically predicts the rest of the sequence. The image resolution was enhanced for viewability.

Figure 12: The top row shows the planned subgoals using KEYIN. The bottom row shows snapshots from a successful trajectory between the start state on the left and goal state (depicted transparently in each frame). The low-level execution closely follows the given subgoals and successfully reaches the goal.

F1 accuracy score for keyframe discovery on all three datasets. Higher is better.

Table content: <table><tr><td>METHOD</td><td colspan="3">BROWNIAN PUSH GRIDWORLD</td></tr><tr><td>RANDOM</td><td>0.15</td><td>0.18</td><td>0.12</td></tr><tr><td>STATIC</td><td>0.21</td><td>0.18</td><td>0.25</td></tr><tr><td>SURPRISE</td><td>0.73</td><td>0.10</td><td>0.32</td></tr><tr><td colspan="2">KEYIN (OURS) 0.94</td><td>0.43</td><td>0.42</td></tr></table>

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.

Table content: <table><tr><td colspan="2"># KEYFRAMES 4</td><td>6</td><td>8</td></tr><tr><td>BROWNIAN</td><td colspan="3">PRECISION 0.92 0.92 -RECALL -0.96 0.90</td></tr><tr><td>PUSH</td><td colspan="3">PRECISION 0.30 0.38 -RECALL -0.48 0.46</td></tr><tr><td>GRIDWORLD</td><td colspan="3">PRECISION 0.37 0.43 -RECALL -0.41 0.40</td></tr></table>

We compare different formulations for a surprise-based keyframe detection method: (1) detecting maxima of the KL divergence between prior and posterior in a stochastic prediction model, (2) detecting maxima in the lower bound on data likelihood log p (ELBO) of a stochastic prediction model, (3) the formulation proposed inDenton & Fergus (2018) that detects maxima of the variance of a learned prior distribution.

Table content: <table><tr><td>DATASET</td><td/><td>PUSH</td><td/><td/><td colspan="2">GRIDWORLD</td></tr><tr><td>METHOD</td><td>F1 ↑</td><td colspan="3">min d TRUE KF ↓ min d PRED KF ↓ F1 ↑</td><td colspan="2">min d TRUE KF ↓ min d PRED KF ↓</td></tr><tr><td>KL-SUPRISE</td><td colspan="2">0.25 1.44</td><td>2.05</td><td>0.32</td><td>1.42</td><td>1.86</td></tr><tr><td>log p-SURPRISE</td><td colspan="2">0.24 1.42</td><td>2.08</td><td>0.31</td><td>1.45</td><td>1.83</td></tr><tr><td colspan="2">DENTON &amp; FERGUS (2018) 0.17</td><td>1.73</td><td>2.01</td><td colspan="2">0.35 1.10</td><td>1.53</td></tr></table>

In addition to the F1 scores we report the minimal temporal distance to the next keyframe as an metric that is more graceful with respect to "close misses". Specifically, we report the distance to the next annotated keyframe averaged across predicted keyframes, min d true KF , and, inversely, the distance to the next predicted keyframe for each annotated keyframe, min d pred KF . For both datasets the distance metrics support the F1 results: KEYIN discovers keyframes that are better aligned with the annotated keyframes than the baselines. Planning in the subgoal space.Input: Keyframe model KEYIN(., .), cost function c Input: Start and target images I 1 and I target Set the sampling distribution to the prior:

Table content: <table><tr><td>DATASET</td><td/><td>PUSH</td><td/><td/><td colspan="2">GRIDWORLD</td></tr><tr><td>METHOD</td><td>F1 ↑</td><td colspan="3">min d TRUE KF ↓ min d PRED KF ↓ F1 ↑</td><td colspan="2">min d TRUE KF ↓ min d PRED KF ↓</td></tr><tr><td>STATIC</td><td>0.18</td><td>1.67</td><td>1.25</td><td>0.25</td><td>1.22</td><td>1.07</td></tr><tr><td>SURPRISE</td><td>0.25</td><td>1.44</td><td>2.05</td><td>0.32</td><td>1.42</td><td>1.86</td></tr><tr><td colspan="3">KEYIN (OURS) 0.43 1.25</td><td>1.86</td><td colspan="2">0.42 1.03</td><td>0.99</td></tr><tr><td colspan="4">H VIDEO MODELING PERFORMANCE</td><td/><td/><td/></tr><tr><td colspan="7">We further report quantitative results on standard video prediction metrics, Structural Similarity Index</td></tr><tr><td colspan="7">(SSIM) and Peak Signal-to-Noise Ratio (PSNR), in Tab. 5. KEYIN is able to match performance of</td></tr><tr><td colspan="7">two comparable prior approaches, showing that the keyframe-based modeling is able to represent</td></tr><tr><td colspan="2">complex data distributions.</td><td/><td/><td/><td/><td/></tr><tr><td colspan="3">I PLANNING ALGORITHM</td><td/><td/><td/><td/></tr><tr><td>Algorithm 3</td><td/><td/><td/><td/><td/><td/></tr></table>



Table content: <table/>

Keyframe SSIM and PSNR scores on pushing and gridworld dataset. Higher is better. OURS) 29.5 ± 0.16 0.911 ± 0.001 18.4 ± 0.17 0.636 ± 0.001

Table content: <table><tr><td>DATASET</td><td/><td>PUSH</td><td colspan="2">GRIDWORLD</td></tr><tr><td>METHOD</td><td>PSNR</td><td>SSIM</td><td>PSNR</td><td>SSIM</td></tr><tr><td>JUMPY</td><td colspan="2">28.25 ± 0.11 0.904 ± 0.001</td><td>16.3 ± 0.17</td><td>0.632 ± 0.001</td></tr><tr><td>KEYIN (</td><td/><td/><td/><td/></tr></table>

F1 score and distance to closest annotated / predicted keyframe when trained and tested on sequences with additive Gaussian noise. KEYIN is able to reliably find keyframes on both datasets even when trained and tested on noisy sequences. Even though the F1 score is lower on the Pushing dataset, the distances indicate that the discovered keyframes are well aligned with the annotated keyframes even under noise.

Table content: <table><tr><td>DATASET</td><td>PUSH</td><td/><td colspan="2">GRIDWORLD</td></tr><tr><td>METHOD</td><td colspan="4">F1 ↑ min d TRUE KF ↓ min d PRED KF ↓ F1 ↑ min d TRUE KF ↓ min d PRED KF ↓</td></tr><tr><td>KEYIN, NO-NOISE</td><td>0.43 1.25</td><td>1.86</td><td>0.42 1.03</td><td>0.99</td></tr><tr><td colspan="2">KEYIN, GAUSS-NOISE 0.25 1.21</td><td>1.34</td><td>0.43 1.00</td><td>0.96</td></tr></table>

Peer review (iclr2020):
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. The technical approach is to pose the problem as one of inferring the temporal location of each of these key frames and then to interpolate with a model to generate intermediate frames. One could try to make either step sophisticated - the authors choose to make the keyframe selection more sophisticated and interpolation simpler. The paper first described the KeyIn model in terms of a probabilistic model of jointly finding the Ks and then the inpainted Is. This can become delicate, so the authors propose a relaxation that is more forgiving when the keyframe locations are being searched for. Learning is driven by a reconstruction loss of finding the approximate location, locally interpolating and then seeing if this accords with the training data. This is all implemented with an LSTM based NN architecture which seems sound to me. I feel the paper is taking on the right kinds of questions, looking for ways to inject the right kind of structure. I do have some concerns about the overall formulation: 1. Much of the paper is focussed on rather clean images where nothing extraneous is happening. In reality, the backgrounds of real images is not so benign and other extraneous dynamics might interfere. While I understand this is a step towards the long term goal, I wonder if the end result is a bit too incremental in the absence of some attempt to explore this source of (lack of) robustness. 2. In §6.3, the authors try to demonstrate that the number of keyframes parameter can be wrong by a little bit but these are still small ranges. In realistic images it is likely that the total number of keyframes selected by such an algorithm is much larger due to extraneous events. This is why a proper robustness study is crucial on more realistic input. As it, in anything other than the trivial dot on black background, the precision-recall numbers are fairly modest. This will likely degenerate into noise in most camera-based images of the kind seen by a real robot. So, how much confidence should we expect to have in the approach*s generality? 3. For the baselines, the true good baseline might have been a human annotation that tells us how people really conceptualise the structure. With data such as pushing, this might not be so different from the simple visual inspection, but again with real data this will vary. The paper would really be much stronger if these were addressed.