Efficient Video Classification Using Fewer Frames
Shweta Bhardwaj Mukundhan Srinivasan Mitesh M. Khapra























Efficient Video Classification Using Fewer Frames
    Shweta BhardwajIndian Institute of Technology Madras and Robert Bosch Centre for Data Science and AI (RBC-DSAI)
  shweta@cse.iitm.ac.in 
        Mukundhan Srinivasan 
 NVIDIA Bangalore 
 msrinivasan@nvidia.com 

        Mitesh M. Khapra
  
        miteshk@cse.iitm.ac.in

    Received: date / Accepted: date
===================================================================================================================================================================================================================================================================================





Recently, there has been a lot of interest in building compact models for video classification which have a small memory footprint (< 1 GB) <cit.>. While these models are compact, they typically operate by repeated application of a small weight matrix to all the frames in a video. For example, recurrent neural network based methods compute a hidden state for every frame of the video using a recurrent weight matrix. Similarly, cluster-and-aggregate based methods such as NetVLAD have a learnable clustering matrix which is used to assign soft-clusters to every frame in the video. Since these models look at every frame in the video, the number of floating point operations (FLOPs) is still large even though the memory footprint is small. In this work, we focus on building compute-efficient video classification models which process fewer frames and hence have less number of FLOPs. Similar to memory efficient models, we use the idea of distillation albeit in a different setting. Specifically, in our case, a compute-heavy teacher which looks at all the frames in the video is used to train a compute-efficient student which looks at only a small fraction of frames in the video. This is in contrast to a typical memory efficient Teacher-Student setting, wherein both the teacher and the student look at all the frames in the video but the student has fewer parameters. Our work thus complements the research on memory efficient video classification. We do an extensive evaluation with three types of models for video classification, viz., (i) recurrent models (ii) cluster-and-aggregate models and (iii) memory-efficient cluster-and-aggregate models and show that in each of these cases, a see-it-all teacher can be used to train a compute efficient see-very-little student. Overall, we show that the proposed student network can reduce the inference time by 30% and the number of FLOPs by approximately 90% with a negligible drop in the performance. 








§ INTRODUCTION


Today video content has become extremely prevalent on the internet influencing all aspects of our life such as education, entertainment, communication etc. This has led to an increasing interest in automatic video processing with the aim of identifying activities <cit.>, generating textual descriptions <cit.>, generating summaries <cit.>, answering questions <cit.> and so on. On one hand, with the availability of large-scale datasets <cit.> for various video processing tasks, it has now become possible to train increasingly complex models which have high memory and computational needs but on the other hand there is a demand for running these models on low power devices such as mobile phones and tablets with stringent constraints on latency, memory and computational cost. It is important to balance the two and design models which can learn from large amounts of data but still be computationally cheap at inference time.

In this context, the recently concluded ECCV workshop on YouTube-8M Large-Scale Video Understanding (2018) <cit.> focused on building memory efficient models which use less than 1GB of memory. The main motivation was to discourage the use of ensemble based methods and instead focus on memory efficient single models. One of the main ideas explored by several participants <cit.> in this workshop was to use knowledge distillation to build more compact student models. More specifically, they first train a teacher network which has a large number of parameters and then use this network to guide a much smaller student network which has limited memory requirements and can thus be employed at inference time. Of course, in addition to requiring less memory, such a model would also require fewer FLOPs as the size of weight matrices, hidden representations, etc. would be smaller. However, there is scope for reducing the FLOPs further because existing models process all frames in the video which may be redundant.    

Based on the results of the ECCV workshop <cit.>, we found that the two most popular paradigms for video classification are (i) recurrent neural network based methods and (ii) cluster-and-aggregate based methods. Not surprisingly, the third type of approaches based on C3D (3D convolutions) <cit.> were not so popular because they are expensive in terms of their memory and compute requirements. For example, the popular I3D model <cit.> is trained using 64 GPUs as mentioned in the original paper. Hence, in this paper, we focus only on the first two paradigms. We first observe that, RNN based methods <cit.> compute a hidden representation for every frame in the video and then compute a final representation for the video based on these frame representations. Hence, even if the model is compact due to smaller weight matrix and/or hidden representations, the number of FLOPs would still be large because this computation needs to be done for every frame in the video. Similarly, cluster-and-aggregate based methods <cit.> have a learnable clustering matrix which is used for assigning soft clusters to every frame in the video. Even if the model is made compact by reducing the size of the clustering matrix and/or hidden representations, the number of FLOPs would still be large. To alleviate this problem, in this work, we focus on building models which have fewer FLOPs and are thus computationally efficient. Our work thus complements existing work on memory efficient models for video classification.









We propose to achieve 
this 
by again using the idea of distillation wherein we train a computationally expensive teacher network which computes a representation for the video by processing all frames in the video. We then train a relatively inexpensive student network whose objective is to process only a few frames of the video and produce a representation which is very similar to the representation computed by the teacher. This is achieved by minimizing (i) the squared error loss between the representations of the student network and the teacher network and/or (ii) by minimizing the difference between the output distributions (class probabilities) predicted by the two networks. 
Figure <ref> illustrates this idea where the teacher sees every frame of the video but the student sees fewer frames, i.e., every j-th frame of the video. 
 At inference time, we then use the student network for classification thereby reducing  the time required for processing the video. 

We experiment with two different methods of training the Teacher-Student network. In the first method (which we call Serial Training), the teacher is trained independently and then the student is trained to match the teacher with or without an appropriate regularizer to account for the classification loss. In the second method (which we call Parallel Training), the teacher and student are trained jointly using the classification loss as well as the matching loss. This parallel training method is similar to on-the-fly knowledge distillation from a dynamic teacher as mentioned in <cit.>. We experiment with different students, viz., (i) a hierarchical RNN based model (ii) NetVLAD and (iii) NeXtVLAD which is a memory efficient version of NetVLAD and was the best single model in the ECCV'18 workshop. 
We experiment with the YouTube-8M dataset and show that the smaller student network reduces the inference time by upto 30% while still achieving a classification performance which is very close to that of the expensive teacher network. 




§ RELATED WORK

Since we focus on the task of video classification in the context of the YouTube-8M dataset <cit.>, we first review some recent work on video classification and then some relevant work on model compression.



 §.§ Video Classification
 One of the popular datasets for video classification is the YouTube-8M dataset which contains videos having an average length of 200 seconds. We use this dataset in all our experiments. 
The authors of this dataset proposed a simple baseline model which treats the entire video as a sequence of one-second frames and uses a Long Short-Term Memory network (LSTM) to encode this sequence. Apart from this, they also propose some simple baseline models like Deep Bag of Frames (DBoF) and Logistic Regression <cit.>.
Various other classification models <cit.> have been proposed and evaluated on this dataset (2017 version) which explore different methods of: (i) feature aggregation in videos
(temporal as well as spatial) <cit.>, (ii) capturing the interactions between labels <cit.> and (iii) learning new non-linear units to model the interdependencies among the activations of the network <cit.>. The state-of-the-art model on the 2017 version of the Youtube-8M dataset uses NetVLAD pooling <cit.> to aggregate information from all the frames of a video. 

In the recently concluded competition (2018 version), many methods <cit.> were proposed to compress the models such that they fit in 1GB of memory. As mentioned by <cit.>, the major motivation behind this competition was to avoid the late-stage model ensemble techniques and focus mainly on single model architectures at inference time <cit.>. 
One of the top performing systems in this competition was NeXtVLAD <cit.>, which modifies NetVLAD <cit.> to squeeze the dimensionality of modules (embeddings). However, this model still processes all the frames of the video and hence has a large number of FLOPs. In this work, we take this compact NeXtVLAD model and make it compute efficient by using the idea of distillation. One clear message from this workshop was that the emphasis should be on single model architectures and not ensembles. Hence, in this work, we focus on single model-based solutions. 


 §.§ Model Compression
 Recently, there has been a lot of work on model compression in the context of image classification. We refer the reader to the survey paper by <cit.> 
for a thorough review of the field. For brevity, here we refer to only those papers which use the idea of distillation. For example, <cit.> use Knowledge Distillation to learn a more compact student network from a computationally expensive teacher network. The key idea is to train a shallow 
student network using soft targets (or class probabilities) generated by the teacher instead of the hard targets present in the training data. 
There are several other variants of this technique such as, <cit.> extend this idea to train a student model which not only learns from the outputs of the teacher but also uses the intermediate representations learned by the teacher as additional hints. 

This idea of Knowledge Distillation has also been tried in the context of pruning networks for multiple object detection <cit.>, speech recognition <cit.> and reading comprehension <cit.>. 

In the context of video classification, there is some work <cit.> on using Quantization for model compression. Some work on video-based action recognition <cit.> tries to accelerate processing in a two-stream CNN architecture by transferring knowledge from motion modality to optical modality. In some very recent work on video classification <cit.> and video captioning <cit.> the authors use a reinforcement learning agent to select which frames to process. We do not focus on the problem of frame selection but instead focus on distilling knowledge from the teacher once fewer frames have been selected for the student. While in this work we simply select frames uniformly, the same ideas can also be used on top of an RL agent which selects the best frames but we leave this as a future work.










§ VIDEO CLASSIFICATION MODELS

Given a fixed set of m classes y_1, y_2, y_3, ..., y_m ∈𝒴 and a video 𝐕 containing N frames (F_0, F_1,…,F_N-1), the goal of video classification is to identify all the classes to which the video belongs. In other words, for each of the m classes we are interested in predicting the probability P(y_i | 𝐕). This probability can be parameterized using a neural network f which looks at all the frames in the video to predict:

    P(y_i | 𝐕) = f(F_0, F_1,…,F_N-1)


Given the setup, we now briefly discuss the two state-of-the-art models that we have considered as teacher/student for our experiments. 



 §.§ Recurrent Network Based Models

We consider the Hierarchical Recurrent Neural Network (H-RNN) based model which assumes that each video contains a sequence of b equal sized blocks. Each of these blocks in turn is a sequence of l frames thereby making the entire video a sequence of sequences. In the case of the YouTube-8M dataset, these frames are one-second shots of the video and each block b is a collection of l such one-second frames. The model contains a lower level RNN to encode each block (sequence of frames) and a higher level RNN to encode the video (sequence of blocks).



 §.§ Cluster and Aggregate Based Models

We consider the NetVLAD model with Context Gating (CG) as proposed in <cit.>. This model does not treat the video as a sequence of frames but simply as a bag of frames. For every frame in this bag, it first assigns a soft cluster to the frame which results is a M × k dimensional representation for the frame where k is the number of clusters considered and M is the size of the initial representation of the frame (say, obtained from a CNN). Instead of using a standard clustering algorithm such as k-means, the authors introduce a learnable clustering matrix which is trained along with all the parameters of the network. The cluster assignments are thus a function of a parameter which is learned during training. The video representation is then computed by aggregating all the frame representations obtained after clustering. This video representation is then fed to multiple fully connected layers with Context Gating (CG) which help to model interdependencies among network activations. We also experiment with NeXtVLAD <cit.> which is a compact version of NetVLAD wherein the M × k dimensional representation is downsampled by grouping which effectively reduces the total number of parameters in the network.

Note that all the models described above look at all the frames in the video.




§ PROPOSED APPROACH

The focus of this work is to design a simpler network g which looks at only a fraction of the N frames at inference time while still allowing it to leverage the information from all the N frames at training time. To achieve this, we propose a Teacher-Student network as described below wherein the teacher has access to more frames than the student.

TEACHER: The teacher network can be any state-of-the-art model described above (H-RNN, NetVLAD, NeXtVLAD). This teacher network looks at all the N frames of video (F_0, F_1,…,F_N-1) and computes an encoding ℰ_T of the video, which is then fed to a simple feedforward neural network with a multi-class output layer containing a sigmoid neuron for each of the 𝒴 classes.






 
 
 


The parameters of the teacher network are learnt using  a standard multi-label classification loss ℒ_CE, which is a sum of the cross-entropy loss for each of the 𝒴 classes. We refer to this loss as ℒ_CE where the subscript CE stands for cross entropy between the true labels y and predictions ŷ.

    ℒ_CE = - ∑_i=1^|𝒴| y_ilog(ŷ_i) + (1- y_i) log(1- ŷ_i)



STUDENT:
In addition to this teacher network, we introduce a student network which only processes every j^th  frame (F_0, F_j, F_2j, …, F_N/j-1) of the video and computes a representation ℰ_S of the video from these N/j frames. We use only same family distillation wherein both the teacher and the student have the same architecture. For example, Figure <ref> shows the setup when the teacher is H-RNN and the student is also H-RNN (please refer to the supplementary material for a similar diagram when the teacher and student are NetVLAD). Further, the parameters of the output layer are shared between the teacher and the student. The student is trained to minimize the squared error loss between the representation computed by the student network and the representation computed by the teacher. We refer to this loss as ℒ_rep where the subscript rep stands for representations. 


    ℒ_rep = || ℰ_T - ℰ_S ||^2


We also try a simple variant of the model, where in addition to ensuring that the final representations ℰ_S and ℰ_T  are similar, we also ensure that the intermediate representations (ℐ_S and ℐ_T) of the models are similar. In particular, we ensure that the representation of the frames j, 2j and so on computed by the teacher and  student network are very similar by minimizing the squared error distance between the corresponding intermediate representations. We refer to this loss as ℒ_rep^ℐ where the superscript ℐ stands for intermediate. 

    ℒ_rep^ℐ = ∑_i=j,2j,..^N/j-1 ||ℐ_T^i - ℐ_S^i ||^2


Alternately, the student can also be trained to minimize the difference between the class probabilities predicted by the teacher and the student. We refer to this loss as ℒ_pred where the subscript pred stands for predicted probabilities. More specifically if 𝒫_T = {p_T^1, p_T^2, ...., p_T^m} and 𝒫_S = {p_S^1, p_S^2, ...., p_S^m} are the probabilities predicted for the m classes by the teacher and the student respectively, then


    ℒ_pred = d(𝒫_T,𝒫_S)


where d is any suitable distance metric such as KL divergence or squared error loss.
 







TRAINING: Intuitively, it makes sense to train the teacher first and then use this trained teacher to guide the student. We refer to this as the Serial mode of training as the student is trained after the teacher as opposed to jointly. For the sake of analysis, we use different combinations of loss function to train the student as described below:



  (a) ℒ_rep: Here, we operate in two stages. In the first stage, we train the student network to minimize the ℒ_rep as defined above, i.e., we train the parameters of the student network to produce representations which are very similar to the teacher network. The idea is to let the student learn by only mimicking the teacher and not worry about the final classification loss. In the second stage, we then plug in the classifier trained along with the teacher (see Equation <ref>) and fine-tune all the parameters of the student and the classifier using the cross entropy loss, ℒ_CE. In practice, we found that the fine-tuning done in the second stage helps to improve the performance of the student. 


  (b) ℒ_rep + ℒ_CE: Here, we train the student to jointly minimize the representation loss as well as the classification loss. The motivation behind this was to ensure that while mimicking the teacher, the student also keeps an eye on the final classification loss from the beginning (instead of being fine-tuned later as in the case above). 

  (c) ℒ_pred: Here, we train the student to only minimize the difference between the class probabilities predicted by the teacher and the student. 


  (d) ℒ_pred + ℒ_CE: Here, in addition to mimicking the probabilities predicted by the teacher, the student is also trained to minimize the cross entropy loss.


  (e) ℒ_rep + ℒ_CE + ℒ_pred: Finally, we combine all the 3 loss functions. Figure <ref> illustrates the process of training the student with different loss functions. 


For the sake of completeness, we also tried an alternate mode in which we train the teacher and student in parallel such that the objective of the teacher is to minimize ℒ_CE and the objective of the student is to minimize one of the 3 combinations of loss functions described above. We refer to this as Parallel training.

 
 
 
















§ EXPERIMENTAL SETUP

In this section, we describe the dataset used for our experiments, the hyperparameters that we considered, the baseline models that we compared with and the effect of different loss functions and training methods.


1. Dataset:
The YouTube-8M dataset (2017 version) <cit.> contains 8
million videos with multiple classes associated with each video. The average length of a video is 200s and the maximum length of a video is 300s. The authors of the dataset have provided pre-extracted audio and visual features for every video such that every second of the video is encoded as a single frame. The original dataset consists of 5,786,881 training (70%), 1,652,167 validation (20%) and 825,602 test examples (10%). Since the authors did not release the test set, we used the original validation set as test set and report results on it. In turn, we randomly sampled 48,163 examples from the training data and used these as validation data for tuning the hyperparameters of the model. We trained our models using the remaining 5,738,718 training examples.

2. Hyperparameters:
For all our experiments, we used Adam Optimizer with the initial learning rate set to 0.001  and then decreased it exponentially with 0.95 decay rate. We used a batch size of 256. For both the student and teacher networks we used a 2-layered MultiLSTM Cell with cell size of 1024 for both the layers of the hierarchical model. 
For regularization, we used dropout (0.5) and 𝐋_2 regularization penalty of 2 for all the parameters. We trained all the models for 5 epochs and then picked the best model-based on validation performance. We did not see any benefit of training beyond 5 epochs. For the teacher network we chose the value of l (number of frames per block ) to be 20 and for the student network, we set the value of l to 5 or 3 depending on the reduced number of frames considered by the student.

In the training of NetVLAD model, we have used the standard hyperparameter settings as mentioned in <cit.>. We consider 256 clusters and 1024 dimensional hidden layers. 
Similarly, in the case of NeXtVLAD, we have considered the hyperparameters of the single best model as reported by <cit.>. In this network, we are working with a cluster size of 128 with hidden size as 2048. The input is reshaped and downsampled using 8 groups in the cluster as done in the original paper. For all these networks, we have worked with a batch size of 80 and an initial learning rate of 0.0002 exponentially decayed at the rate of 0.8. Additionally, we have applied dropout of 0.5 on the output of NeXtVLAD layer which helps for better regularization. 




3. Evaluation Metrics: We used the following metrics as proposed in <cit.> for evaluating the performance of different models :


  * GAP (Global Average Precision): is defined as

    GAP = ∑_i=1^P p(i) ∇ r(i)

where p(i) is the precision at prediction i, ∇ r(i) is the
change in recall at prediction i and P is the number of top predictions that we consider. Following the original YouTube-8M Kaggle competition we use the value of P as 20.




  * mAP (Mean Average Precision) : The mean average precision is computed
as the unweighted mean of all the per-class average precisions.




4. Models Compared: We compare our Teacher-Student network with the following models which helps us to better contextualize our results. 


  * : The original teacher model which processes all the frames of the video. This, in some sense, acts as the upper bound on the performance.

  * Baseline Methods: As baseline, we consider a model (H-RNN, NetVLAD or NeXtVLAD) which is trained from scratch but uses only k frames of the video. However, unlike the student model this model is not guided by a teacher. These k frames can be (i) separated by a constant interval and are thus equally spaced (k) or (ii) sampled randomly from the video (k) or (iii) the first k frames of the video (k) or (iv) the middle k frames of the video (k) or (v) the last k frames of the video (k) or (i) the first k/3, middle k/3 and last k/3 frames of the video (k). We report results with different values of k : 6, 10, 15, 20, 30.






§ DISCUSSION AND RESULTS
 
Since we have 3 different base models (H-RNN, NetVLAD, NeXtVLAD), 5 different combinations of loss functions (see section <ref>), 2 different training paradigms (Serial and Parallel) and 5 different baselines for each base model, the total number of experiments that we needed to run to report all these results was very large. To reduce the number of experiments we first consider only the H-RNN model to identify the (a) best baseline (k, k, k, k, k, k)  (b) best training paradigm (Serial v/s Parallel) and (c) best combination of loss function. We then run the experiments on NetVLAD and NeXtVLAD using only the best baseline, best training paradigm and best loss function thus identified. The results of our experiments using the H-RNN model are summarized in Table <ref> to Table <ref> and are discussed first followed by a discussion of the results using NetVLAD and NeXtVLAD as summarized in Tables <ref> and <ref>:    


0

1. Comparisons of different baselines: First, we simply compare the performance of different baselines listed in the top half of Table <ref>. As is evident, the Uniform-k baseline which looks at equally spaced k frames performs better than all the other baselines. The performance gap between Uniform-k and the other baselines is even more significant when the value of k is small. The main purpose of this experiment was to decide the right way of selecting frames for the student network. Based on these results, we ensured that for all our experiments, we fed equally spaced k frames to the student. 

2. Comparing Teacher-Student Network with Uniform-k Baseline: As mentioned above, the Uniform-k baseline is a simple but effective way of reducing the number of frames to be processed. We observe that all the teacher-student models outperform this strong baseline. Further, in a separate experiment as reported in Table <ref> we observe that when we reduce the number of training examples seen by the teacher and the student, then the performance of the Uniform-k baseline drops and is much lower than that of the corresponding Teacher-Student network. This suggests that the Teacher-Student network can be even more useful when the amount of training data is limited. 




3. Serial Versus Parallel Training of Teacher-Student: While the best results in Table <ref> are obtained using Serial training, if we compare the corresponding rows of Serial and Parallel training we observe that there is not much difference between the two. We found this to be surprising and investigated this further. In particular, we compared the performance of the teacher after different epochs in the Parallel training setup with the performance of a static teacher trained independently (Serial). We plotted this performance in Figure <ref> and observed that after 3-4 epochs of training, the Parallel teacher is able to perform at par with Serial teacher (the constant blue line). As a result, the Parallel student now learns from this trained teacher for a few more epochs and is almost able to match the performance of the Serial student. 
This trend is same across the different combinations of loss functions that we used.



4. Visualization of Teacher and Student Representations: Apart from evaluating the final performance of the model in terms of mAP and GAP, we also wanted to check if the representations learned by the teacher and student are indeed similar. To do this, we chose top-5 classes (class1: Vehicle, class2: Concert, class3: Association football, class4: Animal, class5: Food) in the Youtube-8M dataset and visualized the TSNE-embeddings of the representations computed by the student and the teacher for the same video (see Figure <ref>). We use the darker shade of a color to represent teacher embeddings of a video and a lighter shade of the same color to represent the student embeddings of the same video. We observe that the dark shades and the light shades of the same color almost completely overlap showing that the student and teacher representations are indeed very close to each other. This shows that introducing the ℒ_rep indeed brings the teacher and student representations close to each other. 





5. Matching Intermediate v/s Final representations: Intuitively, it seemed that the student should benefit more if we train it to match the intermediate representations of the teacher at different timesteps as opposed to only the final representation at the last time step. However, as reported in Table <ref>, we did not see any benefit of matching intermediate representations. 















6. Computation time of different models: 
The main aim of this work was to ensure that the computational cost and time is minimized at inference time. The computational cost can be measured in terms of the number of FLOPs. As shown in Table <ref> when k=30, the inference time drops by 30% and the number of FLOPs reduces by approximately 90%, but the performance of the model is not affected. In particular, as seen in Table <ref>, when k=30, the GAP and mAP drop by 0.5-0.9% and 0.9-2% respectively as compared to the teacher skyline. 

7. Performance using NetVLAD models: 
In Table <ref> we summarize the results obtained using NetVLAD as the base model in the Teacher-Student network. Here the student network was trained using the best loss function ( L_rep,L_pred,L_CE) and the best training paradigm (Serial) as identified from the experiments done using the H-RNN model. Further, we consider only the k baseline as that was the best baseline as observed in our previous experiments. Here again we observe that the student network does better than the k baseline. 

8. Combining with memory efficient models: 
Lastly, we experiment with the compact NeXtVLAD model and show that the student network performs slightly better than the k baseline in terms of mAP but not so much in terms of GAP (note that mAP gives equal importance to all classes but GAP is influenced more by the most frequent classes in the dataset). Once again, there is a significant reduction in the number of FLOPs (approximately 89%). 














§ CONCLUSION AND FUTURE WORK

We proposed a method to reduce the computation time for video classification using the idea of distillation. Specifically, we first train a teacher network which computes a representation of the video using all the frames in the video. We then train a student network which only processes k frames of the video. We use different combinations of loss functions which ensures that (i) the final representation produced by the student is the similar as that produced by the teacher and (ii) the output probability distributions produced by the student are similar to those produced by the teacher. We compare the proposed models with a strong baseline and skyline and show that the proposed model outperforms the baseline and gives a significant reduction in terms of computational time and cost when compared to the skyline.

In particular, we evaluate our model on the YouTube-8M dataset and show that the computationally less expensive student network can reduce the computation time by 30% while giving an approximately similar performance as the teacher network. 

As future work, we would like to evaluate our model on other video processing tasks such as summarization, question answering and captioning. We would also like to train a student with an ensemble of teachers (preferably from different families). Lastly, we would like to train a reinforcement learning agent to first select the most favorable k (or even fewer) frames in the video and use these as opposed to simply using equally spaced k frames.



Model        Student-Loss    CosSim

Serial     L_rep       0 

Serial     L_rep,L_CE       0 

Serial     L_rep,L_CE,L_pred       0 




ieee



