Log In Sign Up

End-to-End Dense Video Captioning with Masked Transformer

Dense video captioning aims to generate text descriptions for all events in an untrimmed video. This involves both detecting and describing events. Therefore, all previous methods on dense video captioning tackle this problem by building two models, i.e. an event proposal and a captioning model, for these two sub-problems. The models are either trained separately or in alternation. This prevents direct influence of the language description to the event proposal, which is important for generating accurate descriptions. To address this problem, we propose an end-to-end transformer model for dense video captioning. The encoder encodes the video into appropriate representations. The proposal decoder decodes from the encoding with different anchors to form video event proposals. The captioning decoder employs a masking network to restrict its attention to the proposal event over the encoding feature. This masking network converts the event proposal to a differentiable mask, which ensures the consistency between the proposal and captioning during training. In addition, our model employs a self-attention mechanism, which enables the use of efficient non-recurrent structure during encoding and leads to performance improvements. We demonstrate the effectiveness of this end-to-end model on ActivityNet Captions and YouCookII datasets, where we achieved 10.12 and 6.58 METEOR score, respectively.


page 8

page 13


Joint Event Detection and Description in Continuous Video Streams

As a fine-grained video understanding task, dense video captioning invol...

Bidirectional Attentive Fusion with Context Gating for Dense Video Captioning

Dense video captioning is a newly emerging task that aims at both locali...

End-to-End Dense Video Captioning with Parallel Decoding

Dense video captioning aims to generate multiple associated captions wit...

Dual-Stream Transformer for Generic Event Boundary Captioning

This paper describes our champion solution for the CVPR2022 Generic Even...

Variational Stacked Local Attention Networks for Diverse Video Captioning

While describing Spatio-temporal events in natural language, video capti...

SwinBERT: End-to-End Transformers with Sparse Attention for Video Captioning

The canonical approach to video captioning dictates a caption generation...

End-to-end Dense Video Captioning as Sequence Generation

Dense video captioning aims to identify the events of interest in an inp...

1 Introduction

Video has become an important source for humans to learn and acquire knowledge (e.g. video lectures, making sandwiches [21], changing tires [1]). Video content consumes high cognitive bandwidth, and thus is slow for humans to digest. Although the visual signal itself can sometimes disambiguate certain semantics, one way to make video content more easily and rapidly understood by humans is to compress it in a way that retains the semantics. This is particularly important given the massive amount of video being produced everyday. Video summarization [42] is one way of doing this, but it loses the language components of the video, which are particularly important in instructional videos. Dense video captioning [20]—describing events in the video with descriptive natural language—is another way of achieving this compression while retaining the language components.

Figure 1: Dense video captioning is to localize (temporal) events from a video, which are then described with natural language sentences. We leverage temporal convolutional networks and self-attention mechanisms for precise event proposal generation and captioning.

Dense video captioning can be decomposed into two parts: event detection and event description. Existing methods tackle these two sub-problems using event proposal and captioning modules, and exploit two ways to combine them for dense video captioning. One way is to train the two modules independently and generate descriptions for the best event proposals with the best captioning model [13]. The other way is to alternate training [20] between the two modules, i.e., alternate between i) training the proposal module only and ii) training the captioning module on the positive event proposals while fine-tuning the proposal module. However, in either case, the language information cannot have direct impacts on the event proposal.

Intuitively, the video event segments and language are closely related and the language information should be able to help localize events in the video. To this end, we propose an encoder-decoder based end-to-end model for doing dense video captioning (see Fig. 1). The encoder encodes the video frames (features) into the proper representation. The proposal decoder then decodes this representation with different anchors to form event proposals, i.e., start and end time of the event, and a confidence score. The captioning decoder then decodes the proposal specific representation using a masking network, which converts the event proposal into a differentiable mask. This continuous mask enables both the proposal and captioning decoder to be trained consistently, i.e. the proposal module now learns to adjust its prediction based on the quality of the generated caption. In other words, the language information from caption now is able to guide the visual model to generate more plausible proposals. In contrast to the existing methods where the proposal module solves a class-agnostic binary classification problem regardless the details in the video content, our model enforces the consistency between the content in the proposed video segment and the semantic information in the language description.

Another challenge for dense video captioning, and more broadly for sequence modeling tasks, is the need to learn a representation that is capable of capturing long term dependencies. Recurrent Neural Networks (RNN) are possible solutions to this problem, however, learning such representation is still difficult

[24]. Self-attention [22, 25, 30] allows for an attention mechanism within a module and is a potential way to learn this long-range dependence. In self-attention the higher layer in the same module is able to attend to all states below it. This made the length of the paths of states from the higher layer to all states in the lower layer to be one, and thus facilitates more effective learning. The shorter path length facilitates learning these dependencies because larger gradients can now pass to all states. Transformer [30] implements a fast self-attention mechanism and has demonstrated its effectiveness in machine translation. Unlike traditional sequential models, transformer does not require unrolling across time, and therefore trains and tests much faster as compared to RNN based models. We employ transformer in both the encoder and decoder of our model.

Our main contributions are twofold. First, we propose an end-to-end model for doing dense video captioning. A differentiable masking scheme is proposed to ensure the consistency between proposal and captioning module during training. Second, we employ self-attention: a scheme that facilitates the learning of long-range dependencies to do dense video captioning. To the best of our knowledge, our model is the first one that does not use a RNN-based model for doing dense video captioning. In addition, we achieve competitive results on ActivityNet Captions [20] and YouCookII [43] datasets.

2 Related Work

Image and Video Captioning.

 In contrast to earlier video captioning papers, which are based on models like hidden Markov models and ontologies

[40, 7], recent work on captioning is dominated by deep neural network-based methods [33, 35, 38, 44, 37, 27]

. Generally, they use Convolutional Neural Networks (CNNs)

[29, 16]

for encoding video frames, followed by a recurrent language decoder, e.g., Long Short-Term Memory 

[18]. They vary mainly based on frame encoding, e.g., via mean-pooling [32, 11], recurrent nets [8, 31], and attention mechanisms [36, 23, 11]. The attention mechanism was initially proposed for machine translation [3] and has achieved top performance in various language generation tasks, either as temporal attention [36], semantic attention [11] or both [23]. Our work falls into the first of the three types. In addition to using cross-module attention, we apply self-attention [30] within each module.

Temporal Action Proposals. Temporal action proposals (TAP) aim to temporally localize action-agnostic proposals in a long untrimmed video. Existing methods formulate TAP as a binary classification problem and differ in how the proposals are proposed and discriminated from the background. Shuo et al. [28]

propose and classify proposal candidates directly over video frames in a sliding window fashion, which is computationally expensive. More recently, inspired by the anchoring mechanism from object detection 

[26], two types of methods have been proposed—explicit anchoring [12, 43] and implicit anchoring [9, 5]. In the former case, each anchor is an encoding of the visual features between the anchor temporal boundaries and is classfied as action or background. In implicit anchoring, recurrent networks encode the video sequence and, at each anchor center, multiple anchors with various sizes are proposed based on the same visual feature. So far, explicit anchoring methods accompanied with location regression yield better performance [12]. Our proposal module is based upon Zhou et al. [43], which is designed to detect long complicated events rather than actions. We further improve the framework with a temporal convolutional proposal network and self-attention based context encoding.

Dense Video Captioning. The video paragraph captioning method proposed by Yu et al. [41] generates sentence descriptions for temporally localized video events. However, the temporal locations of each event are provided beforehand. Das et al. [7] generates dense captions over the entire video using sparse object stitching, but their work relies on a top-down ontology for the actual description and is not data-driven like the recent captioning methods. The most similar work to ours is Krishna et al. [20] who introduce a dense video captioning model that learns to propose the event locations and caption each event with a sentence. However, they combine the proposal and the captioning modules through co-training and are not able to take advantage of language to benefit the event proposal [17]. To this end, we propose an end-to-end framework for doing dense video captioning that is able to produce proposal and description simultaneously. Also, our work directly incorporates the semantics from captions to the proposal module.

3 Preliminary

In this section we introduce some background on Transformer [30], which is the building block for our model. We start by introducing the scaled dot-product attention, which is the foundation of transformer. Given a query from all queries, a set of keys and values where , the scaled dot-product attention outputs a weighted sum of values , where the weights are determined by the dot-products of query and keys . In practice, we pack and into matricies and , respectively. The attention output on query is:


The multi-head attention consists of paralleled scaled dot-product attention layers called “head”, where each “head” is an independent dot-product attention. The attention output from multi-head attention is as below:


where are the independent head projection matrices, , and .

This formulation of attention is quite general, for example when the query is the hidden states from the decoder, and both the keys and values are all the encoder hidden states, it represents the common cross-module attention. Self-attention [30] is another case of multi-head attention where the queries, keys and values are all from the same hidden layer (see also in Fig. 2).

Now we are ready to introduce Transformer model, which is an encoder-decoder based model that is originally proposed for machine translation [30]

. The building block for Transformer is multi-head attention and a pointwise feed-forward layer. The pointwise feed-forward layer takes the input from multi-head attention layer, and further transforms it through two linear projections with ReLU activation. The feed-forward layer can also be viewed as two convolution layers with kernel size one. The encoder and decoder of Transformer is composed by multiple such building blocks, and they have the same number of layers. The decoder from each layer takes input from the encoder of the same layer as well as the lower layer decoder output. Self-attention is applied to both encoder and decoder. Cross-module attention between encoder and decoder is also applied. Note that the self-attention layer in the decoder can only attend to the current and previous positions to preserve the auto-regressive property. Residual connection 

[16] is applied to all input and output layers. Additionally, layer normalization [2] (LayerNorm) is applied to all layers. Fig. 2 shows a one layered transformer.

Figure 2: Transformer with 1-layer encoder and 1-layer decoder.

4 End-to-End Dense Video Captioning

Our end-to-end model is composed of three parts: a video encoder, a proposal decoder, and a captioning decoder that contains a mask prediction network to generate text description from a given proposal. The video encoder is composed of multiple self-attention layers. The proposal decoder takes the visual features from the encoder and outputs event proposals. The mask prediction network takes the proposal output and generates a differentiable mask for a certain event proposal. To make the decoder caption the current proposal, we then apply this mask by element-wise multiplication between it, the input visual embedding and all outputs from proposal encoder. In the following sections, we illustrate each component of our model in detail.

4.1 Video Encoder

Each frame of the video is first encoded to a continuous representation . It is then fed forward to encoding layers, where each layer learns a representation by taking input from previous layer ,


where represents the function that performs layer normalization on the residual output,

denotes the 2-layered feed-forward neural network with ReLU nonlinearity for the first layer,

, are the weights for the feed-forward layers, and , are the biases. Notice the self-attention used in eq. 5. At each time step , is given as the query to the attention layer and the output is the weight sum of , , which encodes not only the information regarding the current time step, but also all other time steps. Therefore, each time step of the output from the self-attention is able to encode all context information. In addition, it is easy to see that the length of the path between time steps is only one. In contrast to recurrent models, this makes the gradient update independent with respect to their position in time, and thus makes learning potential dependencies amongst distant frames easier.

4.2 Proposal Decoder

Our event proposal decoder is based on ProcNets [43], for its state-of-the-art performance on long dense event proposals. We adopt the same anchor-offset mechanism as in ProcNets and design a set of explicit anchors for event proposals. Each anchor-based proposal is represented by an event proposal score and two offsets: center and length . The associated anchor has length and center . The proposal boundaries (, ) are determined by the anchor locations and offsets:


These proposal outputs are obtained from temporal convolution (i.e. 1-D convolutions) applied on the last layer output of the visual encoder. The score indicates the likelihood for a proposal to be an event. The offsets are used to adjust the proposed segment boundaries from the associated anchor locations. We made following changes to ProcNets:

  • The sequential prediction module in ProcNets is removed, as the event segments in a video are not closely coupled and the number of events is small in general.

  • Use input from a multi-head self-attention layer instead of a bidirectional LSTM (Bi-LSTM) layer  [15].

  • Use multi-layer temporal convolutions to generate the proposal score and offsets. The temporal convolutional network contain three 1-D conv. layers, with batch normalization 

    [19]. We use ReLU activation for hidden layers.

  • In our model, the conv. stride depends on kernel size (

    ) versus always 1 in ProcNets111 is a scalar that affects the convolution stride for different kernel size.

We encode the video context by a self-attention layer as it has potential to learn better context representation. Changing stride size based on kernel size reduces the number of longer proposals so that the training samples is more balanced, because a larger kernel size makes it easier to get good overlap with ground truth. It also speeds up training as the number of long proposals is reduced.

4.3 Captioning Decoder

Masked Transformer. The captioning decoder takes input from both the visual encoder and the proposal decoder. Given a proposal tuple and visual representations , the -layered captioning decoder generates the -th word by doing the following



represents word vector,


denotes the probability of each word in the vocabulary for time

, denotes the word embedding matrix with vocabulary size , and indicates elementwise multiplication. denotes the decoder representation, i.e. the output from feed-forward layer in Fig. 1. denotes the cross module attention that use the current decoder states to attend to encoder states (i.e. multi-head attention in Fig. 1). represents the self-attention in decoder. Notice that the subscript restricts the attention only on the already generated words. is a masking function that output values (near) zero when outside the predicted starting and ending locations, and (near) one otherwise. With this function, the receptive region of the model is restricted to the current segment so that the visual representation focuses on describing the current event. Note that during decoding, the encoder performs the forward propagation again so that the representation of each encoder layer contains only the information for the current proposal (see eq. 12). This is different from simply multiplying the mask with the existing representation from the encoder during proposal prediction, since the representation of the latter still contains information that is outside the proposal region. The representation from the -th layer of captioning decoder is then used for predicting the next word for the current proposal using a linear layer with softmax activation (see eq. 13).

Differentiable Proposal Mask. We cannot choose any arbitrary function for as a discrete one would prevent us from doing end-to-end training. We therefore propose to use a fully differentiable function to obtain the mask for visual events. This function maps the predicted proposal location to a differentiable mask for each time step .


where and are the start and end position of anchor, denotes concatenation, is a continuous function, and

is the logistic sigmoid function. We choose to use a multilayer perceptron to parameterize

. In other words, we have a feed-forward neural network that takes the positional encoding from the anchor and predicted boundary positions and the corresponding binary mask to predict the continuous mask. We use the same positional encoding strategy as in [30].

Directly learning the mask would be difficult and unnecessary, since we would already have a reasonable boundary prediction from the proposal module. Therefore, we use a gated formulation that lets the model choose between the learned continuous mask and the discrete mask obtained from the proposal module. More precisely, the gated masking function is


Since the proposal score , it now acts as a gating mechanism. This can also be viewed as a modulation between the continuous and proposal masks, the continuous mask is used as a supplement for the proposal mask in case the confidence is low from the proposal module.

4.4 Model Learning

Our model is fully differentiable and can be trained consistently from end-to-end The event proposal anchors are sampled as follows. Anchors that have overlap greater than 70% with any ground-truth segments are regarded as positive samples and ones that have less than 30% overlap with all ground-truth segments are negative. The proposal boundaries for positive samples are regressed to the ground-truth boundaries (offsets). We randomly sample anchors from positive and negative anchor pools that correspond to one ground-truth segment for each mini-batch.

The loss for training our model has four parts: the regression loss for event boundary prediction, the binary cross entropy mask prediction loss , the event classification loss (i.e. prediction ), and the captioning model loss . The final loss is a combination of these four losses,

where is the smooth loss defined in [14], BCE denotes binary cross entropy, CE represents cross entropy loss, and represent the ground-truth center and length offset with respect to the current anchor, is the ground-truth label for the proposed event, denotes the ground-truth word at time step , and are the coefficients that balance the contribution from each loss.

Simple Single Stage Models. The key for our proposed model to work is not the single stage learning of a compositional loss, but the ability to keep the consistency between the proposal and captioning. For example, we could make a single-stage trainable model by simply sticking them together with multi-task learning. More precisely, we can have the same model but choose a non-differentiable masking function in eq. 12. The same training procedure can be applied for this model (see the following section). Since the masking function would then be non-differentiable, error from the captioning model cannot be back propagated to modify the proposal predictions. However, the captioning decoder is still able to influence the visual representation that is learned from the visual encoder. This may be undesirable, as the updates the visual representation may lead to worse performance for the proposal decoder. As a baseline, we also test this single-stage model in our experiments.

5 Implementation Details

For the proposal decoder, the temporal convolutional networks take the last encoding output from video encoder as the input. The sizes of the temporal convolution kernels vary from 1 to 251 and we set the stride factor to 50. For our Transformer model, we set the model dimension (same as the Bi-LSTM hidden size) and set the hidden size of feed-forward layer to 2048. We set number of heads (H) to 8. In addition to the residual dropout and attention dropout layers in Transformer, we add a 1-D dropout layer at the visual input embedding to avoid overfitting. We use recurrent dropout proposed in [10] for this 1-D dropout. Due to space limits, more details are included in the supplementary material.

6 Experiments

6.1 Datasets

ActivityNet Captions [20] and YouCookII [43] are the two largest datasets with temporal event segments annotated and described by natural language sentences. ActivityNet Captions contains 20k videos, and on average each video has 3.65 events annotated. YouCookII has 2k videos and the average number of segments per video is 7.70. The train/val/test splits for ActivityNet Captions are 0.5:0.25:0.25 while for YouCookII are 0.66:0.23:0.1. We report our results from both datasets on the validation sets. For ActivityNet Captions, we also show the testing results on the evaluation server while the testing set for YouCookII is not available.

Data Preprocessing. We down-sample the video every 0.5s and extract the 1-D appearance and optical flow features per frame, as suggested by Xiong et al. [34]. For appearance features, we take the output of the “Flatten-673” layer in ResNet-200 [16]; for optical flow features, we extract the optical flow from 5 contiguous frames, encode with BN-Inception [19] and take output of the “global-pool” layer. Both networks are pre-trained on the ActivityNet dataset [6] for the action recognition task. We then concatenate the two feature vector and further encode with a linear layer. We set the window size

to 480. The input is zero padded in case the number of sampled frames is smaller than the size of the window. Otherwise, the video is truncated to fit the window. Note that we do not fine-tune the visual features for efficiency considerations, however, allowing fine-tuning may lead to better performance.

6.2 Baseline and Metrics

Baselines. Most of the existing methods can only caption an entire video or specified video clip. For example, LSTM-YT [32], S2YT [31], TempoAttn [36], H-RNN [41] and DEM [20]. The most relevant baseline is TempoAttn, where the model temporally attends on visual sequence inputs as the input of LSTM language encoder. For a fair comparison, we made the following changes to the original TempoAttn. First, all the methods take the same visual feature input. Second, we add a Bi-LSTM context encoder to TempoAttn while our method use self-attention context encoder. Third, we apply temporal attention on Bi-LSTM output for all the language decoder layers in TempoAttn since our decoder has attention each layer. We name this baseline Bi-LSTM+TempoAttn. Since zero inputs deteriorates Bi-LSTM encoding, we only apply the masking on the output of the LSTM encoder when it is passed to the decoder. We also compare with a a simple single-stage Masked Transformer baseline as mentioned in section 4.4, where the model employs a discrete binary mask.

For event proposals, we compare our self-attention transformer-based model with ProcNets and our own baseline with Bi-LSTM. For captioning-only models, we use the same baseline as the full dense video captioning but instead, replace the learned proposals with ground-truth proposals. Results for other dense captioning methods (e.g. the best published method DEM [20]) are not available on the validation set nor is the source code released. So, we compare our methods against those methods that participated in CVPR 2017 ActivityNet Video Dense-captioning Challenge [13] for test set performance on ActivityNet.

Evaluation Metrics.

 For ground-truth segment captioning, we measure the captioning performance with most commonly-used evaluation metrics: BLEU{3,4} and METEOR. For dense captioning, the evaluate metric takes both proposal accuracy and captioning accuracy into account. Given a tIoU threshold, if the proposal has an overlapping larger than the threshold with any ground-truth segments, the metric score is computed for the generated sentence and the corresponding ground-truth sentence. Otherwise, the metric score is set to 0. The scores are then averaged across all the proposals and finally averaged across all the tIoU thresholds–0.3, 0.5, 0.7, 0.9 in this case.

6.3 Comparison with State-of-the-Art Methods

We compare our proposed method with baselines on the ActivityNet Caption dataset. The validation and testing set results are shown in Tab. 1 and 2, respectively. All our models outperform the LSTM-based models by a large margin, which may be attributed to their better ability of modeling long-range dependencies.

We also test the performance of our model on the YouCookII dataset, and the result is shown in Tab. 3. Here, we see similar trend on performance. Our transformer based model outperforms the LSTM baseline by a significant amount. However, the results on learned proposals are much worse as compared to the ActivityNet dataset. This is possibly because of small objects, such as utensils and ingredients, are hard to detect using global visual features but are crucial for describing a recipe. Hence, one future extension for our work is to incorporate object detectors/trackers [39, 40] into the current captioning system.

Method B@3 B@4 M
Bi-LSTM 2.43 1.01 7.49
Masked Transformer 4.47 2.14 9.43
End-to-end Masked Transformer 4.76 2.23 9.56
Table 1: Captioning results from ActivityNet Caption Dataset with learned event proposals. All results are on the validation set and all our models are based on 2-layer Transformer. We report BLEU (B) and METEOR (M). All results are on the validation set. Top scores are highlighted.
DEM [20] 4.82
Wang et al. 9.12
Jin et al. 9.62
Guo et al. 9.87
Yao et al.222This work is unpublished. It employs external data for model training and the final prediction is obtained from an ensemble of models.(Ensemble) 12.84
Our Method 10.12
Table 2: Dense video captioning challenge leader board results. For results from the same team, we keep the highest one.
Method GT Proposals Learned Proposals
B@4 M B@4 M
Bi-LSTM 0.87 8.15 0.08 4.62
Our Method 1.42 11.20 0.30 6.58
Table 3: Recipe generation benchmark on YouCookII validation set. GT proposals indicate the ground-truth segments are given during inference.

We show qualitative results in Fig. 3 where the proposed method generates captions with more relevant semantic information. More visualizations are in the supplementary.

Figure 3: Qualitative results on ActivityNet Captions. The color bars represent different events. Colored text highlight relevant content to the event. Our model generates more relevant attributes as compared to the baseline.

6.4 Model Analysis

In this section we perform experiments to analyze the effectiveness of our model on different sub-tasks of dense video captioning.

Video Event Proposal. We first evaluate the effect of self-attention on event proposal, and the results are shown in Tab. 4. We use standard average recall (AR) metric  [9, 13] given 100 proposals. Bi-LSTM indicates our improved ProcNets-prop model by using temporal convolutional and large kernel strides. We use our full model here, where the context encoder is replaced by our video encoder. We have noticed that the anchor sizes have a large impact on the results. So, for fair comparison, we maintain the same anchor sizes across all three methods. Our proposed Bi-LSTM model gains a 7% relative improvement from the baseline results from the deeper proposal network and more balanced anchor candidates. Our video encoder further yields a 4.5% improvement from our recurrent nets-based model. We show the recall curve under high tIoU threshold (0.8) in Fig. 4 follow the convention [20]. DAPs [9], is initially proposed for short action proposals and adapted later for long event proposal [20]. The proposed models outperforms DAPs-event and ProcNets-prop by significant margins. Transformer based and Bi-LSTM based models yield similar recall results given sufficient number of proposals (100), while our self-attention encoding model is more accurate when the allowed number of proposals is small.

Method Average Recall (%)
ProcNets-prop [43] 47.01
Bi-LSTM (ours) 50.65
Self-Attn (our) 52.95
Table 4: Event proposal results from ActivityNet Captions dataset. We compare our proposed methods with our baseline method ProcNets-prop on the validation set.
Figure 4: Event proposal recall curve under tIoU threshold 0.8 with average 100 proposals per video.

Dense Video Captioning. Next, we look at the dense video captioning results in an ideal setting: doing the captioning based on the ground-truth event segments. This will give us an ideal captioning performance since all event proposals are accurate. Because we need access to ground-truth event proposal during test time, we report the results on validation set333The results are overly optimistic, however, it is fine here since we are interested in the best situation performance. The comparison is also fair, since all methods are tuned to optimize the validation set performance. (see Tab. 5). The proposed Masked Transformer (section 4.3) outperforms the baseline by a large margin (by more than 1 METEOR point). This directly substantiates the effectiveness of the transformer on both visual and language encoding and multi-head temporal attention. We notice that as the number of encoder and decoder layers increases, the performance gets further boosts by 1.3%-1.7%. As can be noted here, the 2-layer transformer strikes a good balance point between performance and computation, and thus we use 2-layer transformer for all our experiments.

Method B@3 B@4 M
Bi-LSTM 4.8 2.1 10.02
Our Method
1-layer 5.80 2.66 10.92
2-layer 5.69 2.67 11.06
4-layer 5.70 2.77 11.11
6-layer 5.66 2.71 11.10
Table 5: Captioning results from ActivityNet Caption Dataset with ground-truth proposals. All results are on the validation set. Top two scores are highlighted.
GT Proposals Learned Proposals
Method B@4 M B@4 M
Bi-LSTM 0.84 5.39 0.42 3.99
Our Method 1.13 5.90 1.04 5.93
Table 6: Evaluating only long events from ActivityNet Caption Dataset. GT proposals indicate the ground-truth segments are given during inference.

Analysis on Long Events. As mentioned in section 4.1, learning long-range dependencies should be easier with self-attention, since the next layer observes information from all time steps of the previous layer. To validate this hypothesis directly, we test our model against the LSTM baseline on longer event segments (where the events are at least 50s long) from the ActivityNet Caption dataset, where learning the long-range dependencies are crucial for achieving good performance. It is clear from the result (see Tab. 6) that our transformer based model performs significantly better than the LSTM baseline. The discrepancy is even larger when the model needs to learn both the proposal and captioning, which demonstrate the effectiveness of self-attention in facilitate learning long range dependencies.

7 Conclusion

We propose an end-to-end model for dense video captioning. The model is composed of an encoder and two decoders. The encoder encodes the input video to proper visual representations. The proposal decoder then decodes from this representation with different anchors to form video event proposals. The captioning decoder employs a differentiable masking network to restrict its attention to the proposal event, ensures the consistency between the proposal and captioning during training. In addition, we propose to use self-attention for dense video captioning. We achieved significant performance improvement on both event proposal and captioning tasks as compared to RNN-based models. We demonstrate the effectiveness of our models on ActivityNet Captions and YouCookII dataset.

Acknowledgement. The technical work was performed while Luowei was an intern at Salesforce Research. This work is also partly supported by ARO W911NF-15-1-0354 and DARPA FA8750-17-2-0112. This article solely reflects the opinions and conclusions of its authors but not the funding agents.


8 Appendix

8.1 Implementation Details

The sizes of the temporal convolution kernels in the proposal module are 1 2, 3, 4, 5, 7, 9, 11, 15, 21, 29, 41, 57, 71, 111, 161, 211 and 251. We set the hyper-parameters for End-to-end Masked Transformer as follows. The dropout ratio for Transformer is set to 0.2 and that for visual input embedding is set to 0.1. We set the loss coefficients to

. For training, we use stochastic gradient descent (SGD) with Nesterov momentum, the learning rate is set between 0.01 and 0.1 depending on the convergence, and the momentum is set at 0.95. We decay the learning rate by half on plateau. We also clip the gradient 

[24] to have global norm of 1. For inference, we first pick event proposals with prediction score higher than a pre-defined threshold (0.7). We remove proposals that have high overlap (i.e.

) with each other. For each video, we have at least 50, and at most 500 event proposals. The descriptions are then generated for each of the proposal, and we use greedy decoding for text generation with at most 20 words. We implement the model in PyTorch and train it using 8 Tesla K80 GPUs with synchronous SGD. The model typically takes a day to converge.

The implementation for proposal-only and captioning-only model is slightly different. We apply Adam for training rather than SGD and set the learning rate to 0.0001. When training the captioning-only model, we apply scheduled sampling [4]

. We set the sampling ratio to 0.05 at the beginning of training, and increase it by 0.05 every 5 epoch until it reaches 0.25. Note that applying scheduled sampling to End-to-end Masked Transformer yield no improvements and hence disabled. In the proposal-only model, we report the results on a single-layer Transformer with the model size and hidden size to be 512 and 128. The temporal conv. stride factor

is set to 10.

8.2 Additional Results

To see the effectiveness of self-attention, we performed additional ablation studies, where we apply self-attention module at the encoder or decoder of the LSTM-based baseline. From the result it is clear that self-attention have significant impact on the performance of the model (see Tab. 7), especially as in the language decoder.

Note that the performance of captioning models over ground-truth segments vary little from number of layers. We choose to use 2-layer transformer for the rest of the experiments because 1) the 4 and 6 layer models are more computational expensive; 2) the learning is more complicated when the learned proposals are approximate, and a 2-layer model give us more flexibility for handling this case (see Tab. 7 for results on the 1-layer model).

Self-attention facilitates the learning of long-range dependencies, which should not hurt the performance on modeling relative short-range dependencies. To validate this we tested our model on shorter activities, where the activities are at most 15 seconds long. The result is shown in Tab. 8.

8.3 Additional Qualitative Results

We visualize the learned masks in Fig. 5. The first two correspond to the case where the proposal prediction is confident, i.e., proposal scores are high () and the last two correspond to the case where the prediction is less confident, i.e., proposal scores are low (). We visualize the cross module attention in Fig. 7. For convenience, we randomly choose one of the attention matrices from the multi-head attention. Also, we notice that attention weights from higher-level self-attention layer is tend to be flatter than these from the lower-level layer. Qualitative results for YouCookII are shown in Fig. 6. The visual recognition is challenging result from the small and ambiguous objects (e.g., black pepper, lamb).

Method B@3 B@4 M
SelfAttn + LSTM TempoAttn 2.91 1.35 7.88
BiLSTM + SelfAttn 4.06 1.92 9.05
Our Method (1-layer) 4.49 2.10 9.27
Table 7: Additional ablation experiments on ActivityNet.
GT Proposals Learned Proposals
Method B@4 M B@4 M
Bi-LSTM+TempoAttn 0.74 5.29 0.23 4.43
Our Method 0.87 5.82 0.68 5.06
Table 8: Evaluating only short events from ActivityNet.
(a) High proposal score. (b) High proposal score (b) Low proposal score (b) Low proposal score
Figure 5: Visualization of differentiable masks and final masks under hight (a and b) and low proposal score (c and d). Videos from ActivityNet Captions validation set.
Figure 6: Qualitative results on YouCookII videos. We only showed result for the first 6 events in the second example.
Figure 7: Visualization of weights from the cross-module attention layer. X axis represents the generated words at each time step. Y axis indicates the sampled frames.