Few-Shot Continual Learning for Activity Recognition in Classroom Surveillance Images
Yilei Qian Kanglei Geng Kailong Chen Shaoxu Cheng Linfeng Xu Hongliang Li Fanman Meng Qingbo Wu











Few-Shot Continual Learning for Activity Recognition in Classroom Surveillance Images
 ^† Corresponding author (lfxu@uestc.edu.cn) 
 ^* Equal Contribution 

    
    Yilei Qian^*, Kanglei Geng^*, Kailong Chen, Shaoxu Cheng, Linfeng Xu^†, Hongliang Li, Fanman Meng, Qingbo Wu 

    School of Information and Communication Engineering 

    University of Electronic Science and Technology of China, Chengdu, China 

    {yileiqian, kangleigeng, chenkailong, shaoxu.cheng}@std.uestc.edu.cn, {lfxu, hlli, fmmeng, qbwu}@uestc.edu.cn

    September 9, 2024
===================================================================================================================================================================================================================================================================================================================================================================================



§ ABSTRACT 
The application of activity recognition in the “AI + Education" field is gaining increasing attention. However, current work mainly focuses on the recognition of activities in manually captured videos and a limited number of activity types, with little attention given to recognizing activities in surveillance images from real classrooms. In real classroom settings, normal teaching activities such as reading, account for a large proportion of samples, while rare non-teaching activities such as eating, continue to appear. This requires a model that can learn non-teaching activities from few samples without forgetting the normal teaching activities, which necessitates few-shot continual learning (FSCL) capability. To address this gap, we constructed a continual learning dataset focused on classroom surveillance image activity recognition called ARIC (Activity Recognition in Classroom). The dataset has advantages such as multiple perspectives, 32 activity categories, and real-world scenarios, but it also presents challenges like similar activities and imbalanced sample distribution. To overcome these challenges, we designed a few-shot continual learning method that combines supervised contrastive learning (SCL) and an adaptive covariance classifier (ACC). The SCL improves the generalization ability of the model, while the ACC module provides a more accurate description of the distribution of new classes. Experimental results show that our method outperforms other existing approaches on the ARIC dataset.



Few-Shot Continual learning, Activity
Recognition in Classroom Surveillance Images, Adaptive Covariance Classifier




§ INTRODUCTION


In recent years, activity recognition has gained increasing attention as a significant application of AI in classroom settings. However, existing studies<cit.> have primarily focused on the recognition of a limited number of activities, and the data collected are often manually captured videos rather than classroom surveillance images. Activity recognition in classroom surveillance images faces multiple challenges, including class imbalance, high activity similarity, and privacy protection. To fill this gap, we constructed the ARIC dataset, specifically designed for activity recognition in classroom surveillance images. This dataset offers a rich variety of activity types, provides multi-perspective surveillance images, and is sourced from real classroom surveillance videos. However, the ARIC dataset also presents several challenges: 1) an imbalanced distribution of activity categories with significant differences in sample sizes; 2) high similarity between samples of different categories, which can lead to confusion; 3) features extracted by a shallow network to protect privacy, increasing recognition difficulty; and 4) the continuous occurrence of non-instructional activity in real scenarios, requiring the model to have continual learning capabilities.

To address the challenges faced by the ARIC dataset, we can apply few-shot continual learning methods. Few-shot continual learning has garnered significant attention in recent years, with mainstream approaches involving training a feature extractor during the base phase and freezing it during the incremental phase, using class prototypes as classifiers. The FACT<cit.> method creates virtual classes to reserve space for future classes, SAVC<cit.> introduces contrastive learning during base phase and achieves better model generalization through the fantasy space, and ALICE<cit.> uses angular penalty loss to achieve more compact intra-class clustering.

Nevertheless, current methods remain inadequate in addressing the specific challenges posed by the ARIC dataset. To this end, we propose a specialized few-shot continual learning method for activity recognition in classroom surveillance images. During the base phase, we use a feature-augmented supervised contrastive learning approach to enhance the model's generalization ability and reserve space for future activity categories to better achieve future class predictions. In the incremental phase, the covariance matrix is used as a memory unit, combined with an adaptive mechanism to form the ACC module. By analyzing the variance of new classes, it dynamically adjusts the classifier's decision boundaries to match the feature distribution of the new classes, effectively addressing the issues of small sample size and similarity between new and old classes. Experimental results demonstrate that our method outperforms existing approaches on the ARIC dataset.





§ ARIC-DATASET


The ARIC is a brand-new and challenging dataset based on real classroom surveillance scenarios. We used surveillance videos from three different perspectives—front, middle, and real—of real classroom scenarios as the raw data.(as shown in Fig. <ref>). Images were then extracted from these videos, and the activities of students and teachers within the images were annotated, forming the image modality. We also extracted audio corresponding to 5 seconds before and after each image (a total of 10 seconds) as the audio modality. Additionally, we used the open-source large model InternVL<cit.> to generate captions for each image as the text modality.
The ARIC dataset is characterized by its real classroom scenarios, three modalities, and diverse perspectives. The complexity of human activities, the diversity of actions, and the uniqueness of crowded classroom scenes make this dataset highly challenging. The dataset consists of 36,453 surveillance images covering 32 classroom activities, such as listening to lecture, reading, and using mobile phone. The distribution of samples across different activities is shown in Fig. <ref>.

To protect the privacy of individuals appearing in the images and to avoid releasing the original images, we used shallow layers of pre-trained models to convert the original images into feature data. Considering the need for backbone models in the field of continual learning, we selected three commonly used pre-trained models: ResNet50<cit.>, ViT<cit.>, and CLIP-ViT<cit.>. For example, by using conv1 layer and 3x3 max pool layer of the ResNet50 pre-trained model, we converted the image data into feature data with dimensions of [1, 64, 56, 56].

We also pre-defined reasonable incremental learning task divisions within the dataset to standardize experiments across the dataset: A) In the base phase, provide a few categories with a large number of samples, then randomly and as evenly as possible distribute the remaining categories across different incremental phases. B) Arrange the categories in descending order by the number of samples and then allocate them to different incremental phases based on this order. The specific partitioning schemes will be represented using the formula: B+S×N. Here, B represents the number of the base class, S represents the number of incremental phases, and N represents the number of categories in each incremental phase. For example, 8+6×4 means there are 8  base categories, 6 incremental phases, and 4 categories in each incremental phase. 

The ARIC dataset can be downloaded, and more detailed information can be obtained by the link: https://ivipclab.github.io/publication_ARIC/ARIChttps://ivipclab.github.io/publication_ARIC/ARIC.













§ METHOD


In this section, we will first introduce the task setup for FSCL, followed by an explanation of our proposed method.



 §.§ Few-Shot Continual Learning



Base Session: In FSCL, the dataset needs to provide a base class training set with sufficient samples, denoted as 𝒟^0 = {(𝐱_i, 𝐲_i)}_i=1^N_0, and a base class test set 𝒟_t^0 = {(𝐱_i, 𝐲_i)}_i=1^M_0, where N_0 and M_0 represent the number of samples in the training set and test set respectively. Here, 𝐱_i ∈ℝ^D is the training instance for 𝐲_i ∈ Y_0, and Y_0 is the label space of the base task.

Incremental Session: In this stage, the training set for new tasks {𝒟^1 ,…,𝒟^B} are introduced sequentially. Each set is denoted as 𝒟^b = {(𝐱_i, 𝐲_i)}_i=1^N_b, where 𝐲_i ∈ Y_b, and Y_b ∩ Y_b' = ∅ for  b ≠ b'. The dataset 𝒟^b is only accessible during the training phase of task b. The limited instances in each dataset can be organized in an N-way, K-shot format, representing N classes with K sample instances per class at each incremental stage.





 §.§ Feature-Augmented Supervised Contrastive Learning



To address the challenge of high similarity between different activities in the ARIC dataset, we introduce supervised contrastive learning during the base phase. SCL is particularly effective in handling fine-grained differences, enabling the model to better distinguish and amplify subtle variations<cit.> between easily confused categories, such as reading a book versus looking at a phone. Additionally, SCL contributes to achieving more compact clustering, which reserves space for future incremental categories and thus enhances the model’s ability for FSCL.

In contrastive learning, image augmentation techniques play a crucial role<cit.>. However, since the ARIC dataset is released as features rather than images, we designed a feature augmentation strategy that adapts traditional image augmentation methods, including cropping, flipping, and rotation, to the feature space. This strategy is integrated into the MoCo<cit.> framework to implement SCL, as shown in Fig. <ref>. This framework maintains a continuously updated feature repository, allowing the model to learn the most recent feature representations. In each training iteration, we first apply a series of random augmentations to the input feature 𝐱, generating two augmented views 𝐱_q and 𝐱_k. These are then processed by their respective encoders ϕ_q, ϕ_k and projection layers h_q, h_k, resulting in query feature 𝐪 and key feature 𝐤. A feature queue stores the most recently computed key features along with their label information. The key network is updated using a momentum mechanism to ensure smoother and more robust parameter updates. This setup enables the model to learn more discriminative feature representations from a large pool of samples.

The supervised contrastive loss for each feature sample 𝐱 is computed as follows:


    ℒ_SCL (𝐱) 
       = -1/|P(𝐱)|∑_𝐤_+∈ P(𝐱)logexp(𝐪·𝐤_+ / τ)/∑_𝐤^'∈𝐤∪𝐐exp(𝐪·𝐤^' / τ)


Here, 𝐐 represents the feature queue, and P(𝐱) denotes the set of positive samples, which is the set of samples in 𝐤∪𝐐 that belong to the same class as 𝐱.

During the base phase, in addition to the SCL loss, we also use a cross-entropy classification loss to simultaneously optimize the model's classification ability and the discriminability of feature representations. We use ϕ_q in the query network as a feature extractor to extract features for classification. The cross-entropy classification loss is defined as follows:


    ℒ_cls(𝐱, 𝐲) = ℒ_ce(W^⊤ϕ_q(𝐱), 𝐲)


where ℒ_ce(·, ·) denotes the cross-entropy loss, W ∈ℝ^d × |Y_0|, and ϕ_q(𝐱) ∈ℝ^d × 1.

The final loss function is:

    ℒ_total = ℒ_cls +  ℒ_SCL







 §.§ Adaptive Covariance Classifier 


Traditional classifiers based on the Nearest Class Mean (NCM) rely on learning features from all classes together. However, in incremental learning, dynamic data streams can make NCM less effective. Mensink et al.<cit.> introduced the use of Mahalanobis distance to measure the distance between samples and classes, which is better suited for this scenario<cit.>. Additionally, a feature extractor trained only on base classes can result in high semantic similarity between new classes and some old classes<cit.>. As shown on the left side of Fig. <ref>, some new class samples have features that are too close to old classes, leading to classification errors. Our proposed ACC module leverages class variance characteristics to adjust the covariance matrix, making it more aligned with the class feature distribution. After adjustment, the decision boundaries for the new classes, as shown on the right side of the Fig. <ref>, allow a significant portion of the new classes to be correctly reclassified.

When predicting the label of a sample, the Mahalanobis distance 𝐃(𝐱) is used to calculate the distance between the sample and the class. Here, 𝐆 represents the Gaussian-transformed feature vector of the sample 𝐱, denoted as 𝐆(ϕ_q(𝐱)), and μ is the mean vector of the class, while Σ_𝐚 is the adaptive covariance matrix.


    𝐃(𝐱) = √((𝐆 -μ)^⊤Σ_𝐚^-1 
     (𝐆 - μ))


Using Gaussian-transformed data helps generate representative samples, but raw feature data often exhibits skewness<cit.>. To ensure that the input features approximate a Gaussian distribution, we applied the Box-Cox transformation, where λ is a hyperparameter:


    𝐆(x) = 
        x^λ - 1/λ   if λ≠ 0 
    log(x)    if λ = 0


In few-shot learning scenarios, the number of samples is much smaller than the feature dimensions, which can result in a rank-deficient covariance matrix, making it impossible to compute its inverse. To address this, we introduced covariance shrinkage<cit.>, incorporating the adaptive parameter α, and applied normalization to compute the adaptive covariance matrix Σ_𝐚. 


    Σ_𝐚 = Normal[ Σ + ασ_1 𝐈 +  σ_2 (1 - 𝐈)]




    α = k/N_b∑_i=1^N_b(ϕ_q(𝐱) - μ)^2


Here, Σ is the class covariance matrix, 𝐈 is an identity matrix of the same shape as Σ, and 1 is an all-ones matrix of the same shape as Σ. The values σ_1 and σ_2 represent the mean of the diagonal and off-diagonal elements of Σ, respectively, with a scaling factor k > 1. The adaptive parameter α adjusts the covariance matrix through σ_1 and σ_2.




§ EXPERIMENTS





 §.§ Implementation Details


We evaluate our proposed method on the ARIC dataset, using only the image modality for this experiment. The task is divided as follows: the base phase utilizes 20 classes, and in the subsequent 4 incremental phases, 3 new classes are introduced at each phase, following a 3-way 5-shot setting. In each incremental phase, only 5 samples per new class are provided for training. This setup simulates the scenario in classroom surveillance images where non-instructional activities continuously appear but with a limited number of samples, requiring the model to learn effectively under constrained sample conditions. We adopt ResNet18<cit.> as the backbone of our network. In base phase, we utilized an SGD optimizer with a momentum of 0.9 and an initial learning rate of 0.1, adjusted using a cosine annealing scheduler. The model is trained for 200 epochs with a batch size of 256. During the incremental phase, set the parameter λ=0.2 for the Gaussian transformation, and set the adaptive scaling factor k=4 in the ACC module.








 §.§ Result


The experimental results of our method on the ARIC dataset are shown in Table <ref> (the evaluation metric is the average TOP-1 accuracy tested on all known classes). To demonstrate the effectiveness of our method on the ARIC dataset, we compared it with several state-of-the-art few-shot continual learning methods. ALICE<cit.>, FACT<cit.>, and SAVC<cit.>, are all based on the feature space and use prototypes as classifiers, while Teen<cit.> only adjusts the prototype classifier during the incremental phase. Additionally, we present the results of Finetune without using any continual learning methods. The experimental results show that our proposed method significantly outperforms existing methods in each incremental task on the ARIC dataset.





 §.§ Ablation Study


To evaluate the impact of each component in our proposed method, we conducted ablation experiments, as shown in Table <ref>. First, when we disabled the SCL loss (ℒ_SCL) during the base phase, the experimental results showed a significant drop in the model's performance on base class classification. This indicates that SCL allows the model to more accurately distinguish between easily confused categories. Additionally, the model’s performance after the last incremental phase also declined, suggesting that SCL achieved more compact clustering during the base phase, thereby enhancing the model’s few-shot continual learning ability. Second, when we removed the ACC module and used only the prototype classifier, the experimental results showed a decrease in performance at each incremental stage, indicating that the ACC classifier better defines the decision boundaries for each class in incremental tasks. We also added the ACC module to the FACT method for experimentation, and the results similarly demonstrated this point.

Finally, to verify the impact of the adaptive mechanism on the ACC module, we fixed the adaptive parameter α to 1 in our experiments. The results, shown in Table <ref>, indicate that disabling the adaptive mechanism led to a decline in performance across all incremental stages. This demonstrates the significant improvement provided by the adaptive mechanism to the covariance classifier, offering a quantitative assessment of its contribution to the model's performance.












 §.§ Visualization


As illustrated in Fig. <ref>, we compared the feature distribution in the feature space after the base phase for three different methods. It is evident that our method achieves superior clustering for the base classes. Compared to Fintune and FACT, incorporating supervised contrastive learning effectively increases the inter-class distance while reducing the intra-class distance, resulting in more compact clusters for each class. This significantly contributes to accurate base class recognition and better integration of incremental classes into the feature space.





§ CONCLUSION


In this study, we tackled the unique challenges of activity recognition in classroom surveillance images, particularly those presented by the ARIC dataset, by developing an innovative few-shot continual learning method. Our approach effectively addresses issues such as class imbalance, high activity similarity, and the need for privacy-preserving features. This is achieved by integrating feature-augmented SCL in the base phase and the ACC module in the incremental phase. The experimental results on the ARIC dataset demonstrate that our method significantly enhances the model's generalization ability and improves classifier accuracy.


IEEEtran


