Multi-task real-time face analysis method and system based on openCV and lightweight DNN

By combining OpenCV and lightweight DNN in a multi-task real-time face analysis method, and integrating channel pruning, dynamic weight distillation, and multi-threaded parallel computing, this approach addresses the shortcomings of existing face analysis systems in terms of lightweight model accuracy, multi-task collaborative optimization, adaptation to complex scenarios, and engineering deployment, achieving efficient and accurate real-time face analysis.

CN122116444APending Publication Date: 2026-05-29杜彦达

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
杜彦达
Filing Date
2026-02-25
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing face analysis technologies have significant shortcomings in terms of lightweight model accuracy preservation, multi-task collaborative optimization, generalization ability in complex scenarios, real-time video stream processing efficiency, and flexibility in engineering deployment. They are difficult to achieve high efficiency, real-time performance, and accuracy on ordinary CPUs or embedded devices, and lack adaptability to complex environments and cross-device compatibility.

Method used

A multi-task real-time face analysis method based on OpenCV and a lightweight DNN is adopted. The lightweight MobileNet-SSD network is optimized by channel pruning and dynamic weight distillation. Combined with multi-threaded parallel computing and CUDA GPU acceleration, image preprocessing, face detection and multi-task analysis are realized. It supports asynchronous execution of static images and real-time video streams, and improves the collaborative reasoning ability of the model through cross-task feature interaction and attention enhancement structure.

Benefits of technology

This system achieves efficient face detection in ordinary hardware environments, improves the accuracy and robustness of multi-task inference in complex scenarios, enhances the efficiency of real-time video stream processing, and strengthens the practicality and scalability of the system to meet the diverse needs of different application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122116444A_ABST
    Figure CN122116444A_ABST
Patent Text Reader

Abstract

The application discloses a multi-task real-time face analysis method and system based on OpenCV and light DNN, and relates to the technical field of computer vision. Input data in the form of static images or real-time video streams is preprocessed through OpenCV; face detection is completed based on a light MobileNet-SSD network optimized through channel pruning and dynamic weight distillation, and effective face images are screened; the face images are input into a multi-task light DNN model, synchronous inference of expression recognition, age prediction and gender classification is realized through a cross-task feature interaction mechanism; real-time video streams are processed through multi-thread parallel computing and optional CUDA GPU acceleration, analysis results are stored in a database in association and visual display and query are supported. The system corresponds to data input, preprocessing, face detection, multi-task analysis, parallel acceleration, data storage and result display and interaction modules. The application balances model precision and computing efficiency, improves complex scene adaptability and real-time response capability, and is suitable for various intelligent interaction scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer vision technology, specifically to a multi-task real-time face analysis method and system based on OpenCV and lightweight DNN. Background Technology

[0002] With the deep integration of computer vision and deep learning technologies, facial analysis has become a core support in the field of intelligent interaction, widely applied in diverse scenarios such as intelligent security, educational assessment, and emotion recognition. Facial analysis solutions often face a triangular dilemma of accuracy, efficiency, and generalization: high-precision models typically involve a large number of parameters and high computational overhead, making it difficult to meet real-time requirements on ordinary CPUs or embedded devices; while lightweight models often suffer from insufficient recognition accuracy in complex scenarios. Against this backdrop, the fusion of OpenCV's efficient computer vision processing capabilities with lightweight DNN models has become a key direction for overcoming this dilemma, significantly reducing computational resource consumption while ensuring recognition accuracy and meeting the needs of multi-scenario deployment.

[0003] Current face analysis technology still faces many limitations in practical applications. At the model optimization level, existing lightweight solutions often employ fixed-threshold channel pruning or static distillation strategies, lacking the ability to dynamically adapt to feature importance. This easily leads to the loss of key features, affecting model generalization performance. Regarding multi-task processing, most systems adopt independent task branch designs, failing to fully utilize the correlation between tasks, resulting in feature redundancy and increased computational load, making it difficult to balance the accuracy and efficiency of multi-task collaborative inference. Furthermore, in real-time video stream processing, single-threaded architectures or simple task allocation mechanisms are prone to queue blocking, failing to fully utilize hardware computing power and restricting the system's real-time response performance.

[0004] Adaptability to complex environments and data bias are also prominent issues. Most existing models are trained on European and American facial datasets, resulting in poor adaptability to Asian facial features, leading to large age prediction errors and low accuracy in expression recognition. In complex scenarios such as low light, side profiles, and partial occlusion, image quality degradation severely affects the effectiveness of feature extraction. Traditional image enhancement methods struggle to specifically repair key facial regions, further reducing recognition reliability. Furthermore, the system deployment lacks flexibility; most solutions are incompatible with both static images and real-time video streams as input, and lack effective management and visualization of user operation records, impacting user experience and system usability.

[0005] In terms of engineering implementation, existing systems still have room for improvement in cross-device compatibility and resource consumption control. Some solutions rely excessively on high-performance GPU hardware, increasing deployment costs; while systems running purely on CPU suffer from insufficient frame rates and response latency issues. Furthermore, unreasonable front-end and back-end interaction architectures easily lead to data transmission delays, especially in real-time video analytics scenarios, making it difficult to meet the high frame rate and low latency business requirements. These problems severely limit the widespread application of facial analysis technology in resource-constrained scenarios such as small and medium-sized enterprises and educational institutions.

[0006] Therefore, existing face analysis technologies still have significant shortcomings in terms of lightweight model accuracy preservation, multi-task collaborative optimization, generalization ability in complex scenarios, real-time video stream processing efficiency, and flexibility in engineering deployment. There is an urgent need for a comprehensive solution that integrates dynamic model optimization, cross-task feature fusion, adaptation to complex environments, and efficient engineering deployment to meet the comprehensive needs of real-time performance, accuracy, and resource adaptability for different application scenarios. Summary of the Invention

[0007] To address the aforementioned technical issues, this application discloses a multi-task real-time face analysis method and system based on OpenCV and lightweight DNN; the multi-task real-time face analysis method based on OpenCV and lightweight DNN specifically includes:

[0008] Acquire input data, which includes static images or real-time video streams, wherein the real-time video streams support camera capture or import of local video files;

[0009] Image preprocessing is performed on the input data by loading a preprocessing model using OpenCV. The preprocessing includes image scaling, color space conversion, noise filtering, and illumination compensation.

[0010] A lightweight MobileNet-SSD network optimized by channel pruning and dynamic weight distillation is loaded based on the OpenCV DNN module to perform face detection on the preprocessed input data, output face region coordinates and confidence scores, and filter face regions that meet the confidence score requirements to obtain valid face images.

[0011] Input effective face images into a multi-task lightweight DNN model, simultaneously perform expression recognition, age prediction and gender classification tasks, and output the corresponding analysis results;

[0012] It employs a multi-threaded parallel computing mechanism to process real-time video streams, and uses task queue scheduling to achieve asynchronous execution of frame reading, face detection and multi-task analysis. CUDA GPU acceleration for inference can be optionally enabled.

[0013] The analysis results, input data identifiers, and processing timestamps are associated and stored in the database, supporting result visualization and historical record queries.

[0014] Preferably, the channel pruning adopts an adaptive threshold strategy based on feature importance. The pruning priority of each channel is determined by calculating the information entropy of the feature map and the inter-class separation degree. The pruning decision formula is as follows: , ,in, For the first The feature importance score of each channel For information entropy calculation, For the first Feature map of each channel The inter-class separation degree of features and labels. For the first Adaptive pruning threshold for each channel Based on the threshold, The average importance score for all channels.

[0015] Preferably, the dynamic weight distillation optimization process of the lightweight MobileNet-SSD network adopts an adaptive temperature adjustment mechanism, which dynamically adjusts the distillation temperature based on the differences in feature distribution, enabling the student model to accurately learn the higher-order features of the teacher model. The core optimization formula is:

[0016] , ,in, To adapt to distillation temperature, The initial temperature. For adjustment coefficients, Let JS divergence be the metric. , The feature distributions for the student model and the teacher model are respectively. For loss weighting coefficients, For classifying losses, , These are the output logits values ​​for the student model and the teacher model, respectively.

[0017] Preferably, the multi-task lightweight DNN model employs a cross-task feature interaction mechanism, using a dynamic weight matrix to achieve feature fusion between different task branches, thereby improving the accuracy of multi-task collaborative inference. The feature fusion formula is as follows: , in, The fused feature map These are the basic features extracted for the backbone network. Number of task branches For the first Dynamic weights of each task branch For the first Feature maps of each task branch It is the Sigmoid activation function. This is a global average pooling operation. This is the weight mapping matrix. This is a bias term.

[0018] Preferably, the multi-task lightweight DNN model adopts a backbone network plus task branches structure, specifically:

[0019] The backbone network is constructed using depthwise separable convolutions to extract global feature maps of the face. These feature maps contain information about the number of channels, height, and width.

[0020] The task branches include facial expression recognition, age prediction, and gender classification.

[0021] The facial expression recognition branch is constructed through multiple convolutional and fully connected layers, outputting the probability distribution of various facial expressions, which is then normalized by the Softmax function to obtain the final classification result;

[0022] The age prediction branch adopts a regression network structure, which outputs continuous values ​​as the predicted age through a fully connected layer, and the training process is optimized using the MSE loss function.

[0023] The gender classification branch constructs a binary classification network through multiple convolutional and fully connected layers, outputs gender probabilities through the Sigmoid function, and determines the gender category based on the probability magnitude.

[0024] Preferably, the facial expression recognition branch of the multi-task lightweight DNN model employs an attention-guided feature enhancement structure. Through the synergistic effect of spatial attention and channel attention, it strengthens the features of key facial expression regions. The attention calculation formula is as follows: , ,in, Features enhanced by spatial attention The output features of the convolutional layer This is a global max pooling operation. It is the Sigmoid activation function. For convolution operations, Features after channel attention enhancement For element-wise multiplication, It is a multilayer perceptron.

[0025] Preferably, the multi-task lightweight DNN model employs a cross-task feature interaction mechanism, using a dynamic weight matrix to achieve feature fusion between different task branches, thereby improving the accuracy of multi-task collaborative inference. The feature fusion formula is as follows: , in, The fused feature map These are the basic features extracted for the backbone network. Number of task branches For the first Dynamic weights of each task branch For the first Feature maps of each task branch It is the Sigmoid activation function. This is a global average pooling operation. This is the weight mapping matrix. This is a bias term.

[0026] Preferably, the multi-threaded parallel processing flow of the real-time video stream includes:

[0027] Create a frame reading thread, a face detection thread, and a multi-task analysis thread, and implement data transfer through a thread-safe queue;

[0028] The frame reading thread extracts image frames from the video stream at a fixed frame rate, performs initial scaling, and then stores them in the input queue.

[0029] The face detection thread extracts image frames from the input queue, calls the lightweight MobileNet-SSD network to complete face detection, and stores the valid face images into the analysis queue.

[0030] The multi-task analysis thread extracts face images from the analysis queue, inputs them into the multi-task lightweight DNN model to obtain analysis results, stores them in the result queue, and synchronizes them to the database.

[0031] Set up a thread scheduling mechanism to dynamically adjust thread priorities based on the amount of data in each queue, thereby avoiding queue blocking.

[0032] Preferably, the CUDA GPU-accelerated inference employs a tensor fusion and asynchronous execution mechanism, fusing multi-step inference operations into a single GPU kernel function, and achieving overlap between data transmission and inference computation through streaming parallelism, thereby improving GPU utilization. The core optimization strategy is as follows:

[0033] , in, For tensor fusion operations, to For continuous reasoning operations, For the merged GPU kernel functions, For streaming parallelism, , These are data transmission operations on the host side and the device side, respectively.

[0034] The multi-task real-time face analysis system based on OpenCV and lightweight DNN includes:

[0035] The data input module supports three input methods: local still image upload, real-time camera capture, and local video file import.

[0036] The preprocessing module integrates image scaling, color space conversion, noise filtering, illumination compensation, and data enhancement functions, and outputs standardized image data.

[0037] The face detection module loads a lightweight MobileNet-SSD network model optimized by channel pruning and dynamic weight distillation to achieve fast face region detection, confidence filtering, and coordinate output.

[0038] The multi-task analysis module is equipped with a lightweight DNN model containing a cross-task feature interaction mechanism, which simultaneously performs tasks such as facial expression recognition, age prediction, and gender classification, and outputs analysis results with confidence scores.

[0039] The parallel acceleration module includes a multi-threaded scheduling unit and a CUDA GPU acceleration unit. The multi-threaded scheduling unit enables asynchronous execution of frame reading, detection, and analysis, while the GPU acceleration unit supports hardware acceleration of the inference process.

[0040] The data storage module, based on a MySQL database, enables user information management and analysis record storage, and supports data encryption and access control.

[0041] The results display and interaction module provides a web-based visual interface that supports real-time display of analysis results, historical record queries, result export, and system parameter settings.

[0042] Compared with the prior art, the technical solution of this application has the following technical effects:

[0043] This invention significantly reduces the computational overhead and parameter count of the lightweight MobileNet-SSD network through a joint optimization strategy of channel pruning and dynamic weight distillation. At the same time, it retains the model's high-order feature representation capability by using an adaptive temperature adjustment mechanism, enabling efficient face detection in ordinary hardware environments. It effectively balances detection accuracy and real-time performance, and solves the problems of high resource consumption and difficulty in edge deployment of high-precision models.

[0044] The multi-task lightweight DNN model of this invention features a cross-task feature interaction mechanism and attention enhancement structure, which achieves collaborative optimization of tasks such as facial expression recognition, age prediction, and gender classification. By mining inter-task correlation features through dynamic weight matrices and strengthening the feature expression of key regions, it significantly improves the accuracy and robustness of multi-task inference in complex scenarios and avoids feature redundancy in single-task models.

[0045] The engineering optimization based on multi-threaded parallel computing and CUDA GPU acceleration of this invention realizes asynchronous execution of frame reading, detection and analysis through task queue scheduling and tensor fusion technology, which greatly improves the efficiency of real-time video stream processing. At the same time, it is compatible with static image and video stream input, adapts to the diverse needs of different application scenarios, and ensures the stable operation of the system under high load.

[0046] The illumination compensation and data enhancement techniques in the image preprocessing stage of this invention effectively improve image quality in complex environments such as low light and occlusion, and enhance the cross-domain generalization ability of the model. The front-end and back-end separation architecture and database storage design not only simplify system deployment and maintenance, but also realize efficient management and visualization of analysis results, enhancing the practicality and scalability of the system.

[0047] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the preferred embodiments of this application are described in detail below with reference to the accompanying drawings.

[0048] The above and other objects, advantages and features of this application will become more apparent to those skilled in the art from the following detailed description of specific embodiments in conjunction with the accompanying drawings. Attached Figure Description

[0049] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In all drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn to scale.

[0050] Based on the description of the figures and their corresponding technical content in the document, the titles of the figures are as follows:

[0051] Figure 1 A schematic diagram illustrating the overall process of a multi-task real-time face analysis method based on OpenCV and lightweight DNN;

[0052] Figure 2 A diagram illustrating the backbone network, cross-task interaction module, and task branch architecture of a multi-task lightweight DNN model.

[0053] Figure 3 The overall architecture and data flow diagram of a multi-task real-time face analysis system comprising seven core modules;

[0054] Figure 4 Line graph showing the changes in age prediction loss, mean absolute error of age prediction, and gender classification loss and accuracy with the number of training epochs;

[0055] Figure 5 Statistical histogram of the age prediction error distribution of a multi-task lightweight DNN model;

[0056] Figure 6 Scatter plot of time distribution for frame-by-frame detection of real-time video stream;

[0057] Figure 7 Pie chart showing the distribution of the percentage of absolute error in age prediction for a multi-task lightweight DNN model. Detailed Implementation

[0058] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. In the following description, specific details such as specific configurations and components are provided merely to help fully understand the embodiments of this application. Therefore, those skilled in the art should understand that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. In addition, for clarity and brevity, descriptions of known functions and structures are omitted in the embodiments.

[0059] It should be understood that the phrase "an embodiment" or "this embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "an embodiment" or "this embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments.

[0060] Furthermore, reference numerals and / or letters may be repeated in different examples within this application. Such repetition is for the purpose of simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or settings discussed.

[0061] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, B exists alone, and A and B exist simultaneously. The term " / and" in this article describes another type of relationship between related objects, indicating that two relationships can exist. For example, A / and B can mean: A exists alone, and A and B exist alone. In addition, the character " / " in this article generally indicates that the related objects before and after it are in an "or" relationship.

[0062] In this article, the term "at least one" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, "at least one of A and B" can mean: A exists alone, A and B exist simultaneously, or B exists alone.

[0063] It should also be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion.

[0064] Example 1

[0065] This embodiment mainly describes a multi-task real-time face analysis method based on OpenCV and a lightweight DNN, such as... Figure 1 As shown, it specifically includes:

[0066] Acquire input data, which includes static images or real-time video streams, wherein the real-time video streams support camera capture or import of local video files;

[0067] Image preprocessing is performed on the input data by loading a preprocessing model using OpenCV. The preprocessing includes image scaling, color space conversion, noise filtering, and illumination compensation.

[0068] A lightweight MobileNet-SSD network optimized by channel pruning and dynamic weight distillation is loaded based on the OpenCV DNN module to perform face detection on the preprocessed input data, output face region coordinates and confidence scores, and filter face regions that meet the confidence score requirements to obtain valid face images.

[0069] Input effective face images into a multi-task lightweight DNN model, simultaneously perform expression recognition, age prediction and gender classification tasks, and output the corresponding analysis results;

[0070] It employs a multi-threaded parallel computing mechanism to process real-time video streams, and uses task queue scheduling to achieve asynchronous execution of frame reading, face detection and multi-task analysis. CUDA GPU acceleration for inference can be optionally enabled.

[0071] The analysis results, input data identifiers, and processing timestamps are associated and stored in the database, supporting result visualization and historical record queries.

[0072] Furthermore, the process of acquiring input data must meet the requirements of multi-source data compatibility and standardized processing, specifically including:

[0073] Static image input: Supports mainstream image formats. After input, the image is read into a BGR format image matrix by OpenCV's imread function. The matrix dimension is H×W×C (H is the image height, W is the image width, and C is the number of channels). The number of channels is automatically adapted according to the image type. Color images have 3 channels, and grayscale images have 1 channel.

[0074] Real-time video stream input: Camera acquisition is initialized through OpenCV's Video Capture class, with the parameter set to 0 to call the default camera, supporting video frame capture at a preset frame rate (default 30FPS); Local video file import supports mainstream video formats, and the file path is loaded through the Video Capture class to achieve frame reading. Frame extraction is performed frame by frame using the read function, and the data format of each frame is uniformly converted to a BGR image matrix.

[0075] Unified verification before input data preprocessing: For static images, size validity is verified, and invalid images with abnormal pixel dimensions (less than 32×32 pixels) are removed; for video streams, frame integrity is verified, and abnormal frames with corrupted frame data or resolution lower than 1080P are discarded to ensure the effectiveness of subsequent processing.

[0076] Furthermore, the image preprocessing adopts a standardized workflow and configurable parameter design, specifically as follows:

[0077] Image scaling: Bilinear interpolation algorithm is used to uniformly scale static images to 640×480 pixels and video stream frames to 1280×720 pixels. The aspect ratio of the image is kept unchanged during the scaling process, and blank areas are filled with black borders. The filling parameter is set to cv2.BORDER_CONSTANT and the filling value is (0,0,0).

[0078] Color space conversion: The BGR format is converted to RGB format using the cv2.cvtColor function with the conversion parameter cv2.COLOR_BGR2RGB to ensure compatibility with the input format of the deep learning model; for the preprocessing specific to the expression recognition task, the cv2.COLOR_RGB2GRAY function is used to convert it to a single-channel grayscale image, and the pixel value range of the grayscale image is normalized to [0,1].

[0079] Noise filtering: A combination strategy of Gaussian filtering and median filtering is adopted. First, Gaussian filtering is performed using the cv2.GaussianBlur function with a kernel size of (5,5) and a standard deviation σ of 1.5 to filter high-frequency noise. Then, median filtering is performed using the cv2.medianBlur function with a kernel size of 3 to remove salt-and-pepper noise. The order of the two filtering operations is fixed to ensure the noise reduction effect.

[0080] Illumination compensation: An improved Retinex algorithm is used to achieve illumination equalization through multi-scale Gaussian filtering and adaptive gain adjustment. The core formula is as follows: , ,in, For multi-scale illumination components, It corresponds to three scales (small, medium, and large). The weights for each scale are set to 0.3, 0.5, and 0.2, respectively. The Gaussian filter kernels for each scale are (3,3), (5,5), and (7,7), respectively. To prevent the minimum value of zero in the denominator (let's say 1e-6). For variance calculation, The adaptive gain coefficient is dynamically calculated based on the average grayscale value of the image. , Given an input image matrix, This is the enhanced reflection component (i.e., the image after illumination compensation).

[0081] Furthermore, based on face detection, this specifically includes:

[0082] The technical details of the face detection process based on the OpenCV DNN module and the optimized MobileNet-SSD network are as follows:

[0083] Network loading and initialization: The network configuration file (deploy.prototxt) and the pre-trained model file (res10_300x300_ssd_iter_140000.caffemodel) are loaded using the cv2.dnn.readNetFromCaffe function. After initialization, the network input parameters are set as follows: mean subtraction is set to (104, 117, 123), scaling factor is set to 1.0, and channel swap parameter is set to False to ensure that the input data is consistent with the preprocessing standard during training.

[0084] Channel pruning optimization: An adaptive threshold strategy based on feature importance is adopted. The pruning process includes three steps: feature importance calculation, adaptive threshold generation, and channel selection. The core formula is as follows: ,in, For the first The feature importance score of each channel For the first The information entropy of each channel feature map is calculated by... accomplish, For the first Feature map of each channel To determine the inter-class separation degree of features and labels, through calculate( For positive sample features, (for negative sample features) For the first Adaptive pruning threshold for each channel Set the base threshold (to 0.1). The average importance score for all channels. The maximum importance score across all channels is retained during pruning. Eliminate redundant channels.

[0085] Dynamic weight distillation optimization: Using ResNet-50 as the teacher model and lightweight MobileNet-SSD as the student model, an adaptive temperature adjustment mechanism is adopted. The core formula is as follows: , ,in, To adapt to distillation temperature, The initial temperature is set to 3.0. This is the adjustment factor (set to 0.5). JS divergence is used to measure the distribution of features in the student model. Teacher model feature distribution differences This is the loss weighting coefficient (set to 0.3). The classification loss is calculated using cross-entropy loss. , These are the output logits values ​​of the student model and the teacher model, respectively. The KL divergence is used to measure the difference between two probability distributions. During distillation, the total loss is jointly optimized. This enables the student model to learn higher-order features of the teacher model.

[0086] Face detection inference and filtering: The preprocessed image is converted into a network input blob using the cv2.dnn.blobFromImage function, with the blob size set to (300, 300). Then, the net.forward() function is called for inference. The inference output includes the bounding box coordinates (x1, y1, x2, y2) and confidence values ​​of the face regions. The confidence threshold is set to 0.6, and face regions with a confidence score ≥ 0.6 are selected as valid face images. The bounding box coordinates are inversely mapped to the original image size to ensure coordinate accuracy.

[0087] Furthermore, such as Figure 2 As shown, the multi-task lightweight DNN model adopts a backbone network, task branches, and cross-task interaction architecture, specifically as follows:

[0088] Overall model structure: The backbone network is constructed using depthwise separable convolutions, containing 6 depthwise separable convolutional blocks. Each convolutional block consists of a depthwise convolution (kernel size 3×3, stride 1, padding 1), a batch normalization layer, and a ReLU6 activation function. The backbone network outputs the basic feature map. The dimensions are C×H×W (C=128, H=64, W=64); the task branches include expression recognition, age prediction, and gender classification. The three branches run in parallel and share features through a cross-task feature interaction mechanism.

[0089] Cross-task feature interaction mechanism: Feature fusion between different task branches is achieved through a dynamic weight matrix. The core formula is as follows: , ,in, The fused feature map These correspond to the facial expression recognition, age prediction, and gender classification branches, respectively. For the first The dynamic weights of each task branch (dimension 1×C). For the first Feature maps of each task branch (dimensions C×H×W). It is the Sigmoid activation function. For global average pooling operations (to Pooling from C×H×W to C×1×1). This is the weight mapping matrix (dimension C×C). The bias term (dimension 1×C) has dynamic weights. Adaptive fusion of features between tasks is achieved through adaptive generation of basic feature maps.

[0090] The facial expression recognition branch consists of 3 convolutional layers and 2 fully connected layers. The convolutional layers all have a 3×3 kernel size, a stride of 1, and padding of 1, with output channels of 256, 128, and 64 respectively. The fully connected layers have output dimensions of 256 and 7 respectively. Finally, the probability distribution of the 7 facial expression categories is obtained by normalization using the Softmax function. The core formula is as follows:

[0091]

[0092]

[0093]

[0094] in, Features enhanced by spatial attention The output features of the branch convolutional layer This is a global max pooling operation. This is a 1×1 convolution operation (used for dimensionality compression). Features after channel attention enhancement For element-wise multiplication, It is a multilayer perceptron (containing one hidden layer, with an output dimension of C). This is the weight matrix of the fully connected layer (7×64 dimensions). This is the bias term (7×1 dimension). The probability distribution of 7 types of expressions (anger, disgust, fear, happiness, calmness, sadness, and surprise).

[0095] Age prediction branch: A regression network structure is adopted, consisting of two convolutional layers and two fully connected layers. The convolutional layers have 128 and 64 output channels, respectively, and the fully connected layers have 128 and 1 output dimensions, respectively. The training process uses the MSE loss function for optimization. The core formula is as follows: ,in, Predicting loss based on age, For the sample size, For the first The true age of each sample For the first Predicted age for each sample Output for age prediction (continuous values). This is the weight matrix of the fully connected layer (dimension 1×64). This is the bias term (dimension 1×1).

[0096] Gender classification branch: A binary classification network structure is adopted, consisting of two convolutional layers and one fully connected layer. The number of output channels in the convolutional layers are 128 and 64 respectively, and the output dimension of the fully connected layer is 1. The output is mapped to the [0,1] interval by the Sigmoid function. The core formula is as follows:

[0097]

[0098] in, This is the weight matrix of the fully connected layer (dimension 1×64). This is the bias term (dimension 1×1). This represents the probability value for gender. If the condition is met, the individual is identified as male; otherwise, they are identified as female.

[0099] Furthermore, the real-time video stream processing employs an optimization strategy that combines multi-threaded parallelism with GPU acceleration. Specific technical details are as follows:

[0100] Multi-threaded parallel computing mechanism: Three independent threads are created: frame reading thread, face detection thread, and multi-task analysis thread. Data is transferred between threads through thread-safe queues (Queue). The maximum length of the queues is set to 50 (input queue), 30 (analysis queue), and 30 (result queue) to avoid queue overflow.

[0101] Frame reading thread: Extracts image frames based on the original frame rate (FPS) of the video stream. If the original frame rate is higher than 30 FPS, a frame interval sampling strategy is adopted, with the sampling interval being... To ensure that the actual processing frame rate is stable at 30 FPS, after the frame is read, it is initially scaled (scaled to 1280×720 pixels) and then stored in the input queue.

[0102] Face detection thread: Extracts image frames from the input queue, calls the optimized MobileNet-SSD network to perform face detection, and stores the valid face images into the analysis queue after the detection is completed. The thread priority is set to medium priority (1) to ensure timely detection.

[0103] Multi-task analysis thread: Extract valid face images from the analysis queue, input them into the multi-task lightweight DNN model for inference, and after the inference is completed, store the analysis results (expression labels, age values, gender labels, confidence scores) into the result queue and synchronize them to the database. The thread priority is set to high priority (2) to ensure that the inference results are output quickly.

[0104] Thread scheduling mechanism: The thread priority is dynamically adjusted by monitoring the data volume of each queue. When the length of the input queue is ≥40, the priority of the frame reading thread is increased to 2 to speed up the frame reading speed. When the length of the analysis queue is ≥25, the priority of the face detection thread is increased to 2 to speed up the detection speed. When the length of the result queue is ≥25, the frame reading thread is paused until the length of the result queue is ≤15 to avoid queue blocking.

[0105] CUDA GPU-accelerated inference: Employing tensor fusion and asynchronous execution mechanisms, the core optimization strategies are as follows: , ,in, For tensor fusion operations, multi-step inference operations ( to This includes functions such as convolution, pooling, activation, and fully connected layers, which are fused into a single GPU kernel function. Reduce kernel function call overhead; To implement a streaming parallel mechanism, two CUDA streams are created (stream1 for data transfer and stream2 for inference computation) to enable data transfer from the host to the device. ), reasoning and calculation ( Data from the device to the host ( Overlapping execution improves GPU utilization. GPU acceleration is only enabled when an NVIDIA GPU is detected and the CUDA environment is configured; otherwise, it automatically switches to CPU mode.

[0106] Data storage uses a MySQL database, supporting persistent storage and visual querying of analysis results. Specific technical details are as follows:

[0107] Database table design: It includes two core data tables: user information table and analysis record table. The fields of user information table include user ID (int, primary key, auto-increment), username (varchar(32), unique constraint), encrypted password (varchar(512), encrypted with SHA256), email (varchar(32), not null), and registration time (datetime). The fields of analysis record table include record ID (int, primary key, auto-increment), user ID (int, foreign key, related to user information table), task type (varchar(64), distinguishing between static image / video stream), input data path (varchar(256), storage path of image / video file), expression recognition result (varchar(32)), expression confidence (float), age prediction result (int), gender classification result (varchar(16)), gender confidence (float), and processing timestamp (datetime).

[0108] Data storage process: After the analysis results are generated, data objects are constructed using the SQLAlchemy ORM framework, added to the database session by calling the session.add() method, and the transaction is committed by the session.commit() method to ensure data consistency. When writing data, a batch insertion strategy is adopted, and the data is committed in batches of 10 records to reduce database IO overhead.

[0109] Visualization and Query Support: A historical record query interface is provided through the Flask RESTful API, which supports filtering queries by user ID, time range (start time - end time), and task type. The query results are returned in JSON format, including record ID, processing time, various analysis results, and confidence level. The front-end uses Vue 3 + Element Plus to build a visualization interface, which supports the tabular display of analysis results and chart statistics (task quantity statistics by time dimension, expression / gender distribution statistics). The analysis results can be exported as JSON format files or Excel spreadsheets.

[0110] This implementation details how efficient collaboration in multi-task face analysis is achieved through dynamic model optimization, cross-task feature fusion, and engineering acceleration strategies. The lightweight network balances accuracy and resource consumption through pruning and distillation. The multi-task model enhances its adaptability to complex scenarios through attention enhancement and feature interaction. Parallel computing and GPU acceleration ensure real-time processing capabilities. Preprocessing optimization and standardized storage enhance the system's practicality and scalability.

[0111] Example 2 describes in detail a multi-task real-time face analysis system based on OpenCV and lightweight DNN, such as... Figure 3 As shown, it includes:

[0112] The data input module supports three input methods: local still image upload, real-time camera capture, and local video file import.

[0113] The preprocessing module integrates image scaling, color space conversion, noise filtering, illumination compensation, and data enhancement functions, and outputs standardized image data.

[0114] The face detection module loads a lightweight MobileNet-SSD network model optimized by channel pruning and dynamic weight distillation to achieve fast face region detection, confidence filtering, and coordinate output.

[0115] The multi-task analysis module is equipped with a lightweight DNN model containing a cross-task feature interaction mechanism, which simultaneously performs tasks such as facial expression recognition, age prediction, and gender classification, and outputs analysis results with confidence scores.

[0116] The parallel acceleration module includes a multi-threaded scheduling unit and a CUDA GPU acceleration unit. The multi-threaded scheduling unit enables asynchronous execution of frame reading, detection, and analysis, while the GPU acceleration unit supports hardware acceleration of the inference process.

[0117] The data storage module, based on a MySQL database, enables user information management and analysis record storage, and supports data encryption and access control.

[0118] The results display and interaction module provides a web-based visual interface that supports real-time display of analysis results, historical record queries, result export, and system parameter settings.

[0119] Furthermore, the data input module adopts a multi-source adaptation architecture, supporting mainstream static image and video formats, and possesses input validity verification and standardized preprocessing capabilities. Local static image uploading is achieved through a web-based file selection component, supporting batch uploading. After uploading, the file format and resolution are automatically verified, and invalid files are rejected. Real-time camera acquisition initializes the video stream by calling the device's camera interface, supporting the capture of frame data at a preset frame rate, and the frame data is transmitted to the preprocessing module in real time. Local video file import supports parsing mainstream encoding formats, extracting image data frame by frame through a video decoding component, and simultaneously recording video metadata (frame rate, resolution, duration) to provide parameter support for subsequent real-time processing. The module has a built-in input caching mechanism to temporarily store and sort continuously input image or video frames, avoiding data transmission congestion.

[0120] Furthermore, the preprocessing module adopts a pipelined processing architecture, with each functional unit working collaboratively in a fixed order. The image scaling unit, based on bilinear interpolation, dynamically adjusts the image size according to the subsequent model input requirements while maintaining a consistent aspect ratio. The color space conversion unit converts OpenCV's default BGR format to RGB format, and additionally provides grayscale conversion functionality for expression recognition tasks. The noise filtering unit combines Gaussian filtering and median filtering to filter high-frequency noise and salt-and-pepper noise sequentially, ensuring image clarity. The illumination compensation unit uses an improved Retinex algorithm, separating the illumination and reflection components through multi-scale Gaussian filtering, and optimizing image quality under complex lighting conditions through adaptive gain adjustment. The data augmentation unit provides operations such as random flipping, cropping, and brightness adjustment during the training phase, and only performs standardization processing during the inference phase to ensure data adaptability to model input requirements. The module supports parameter configuration, allowing adjustment of key parameters such as filter kernel size and scaling ratio according to different application scenarios.

[0121] Furthermore, the face detection module uses an optimized lightweight MobileNet-SSD network as its core, integrating model loading, inference computation, and result filtering functions. Upon module startup, the pre-trained network configuration file and model file are loaded via the OpenCV DNN module to complete network initialization. During inference, pre-processed image data is received, converted into a network input blob, and then forward inference is performed, outputting the coordinates and confidence scores of the face region bounding boxes. The result filtering unit filters low-confidence detection results according to a pre-set confidence threshold, retaining valid face regions and mapping the coordinates to the original image size. Regarding network optimization, the module integrates channel pruning and dynamic weight distillation functions. Redundant channels are adaptively removed through feature importance evaluation, and the distillation temperature is dynamically adjusted using a high-precision model as the teacher model, reducing the number of model parameters and computational load while ensuring detection accuracy.

[0122] Furthermore, the multi-task analysis module adopts a backbone network, task branches, and cross-task interaction architecture. The core is a lightweight DNN model with a cross-task feature interaction mechanism. The backbone network extracts global basic facial features through depthwise separable convolutions, outputting a fixed-dimensional feature map. The task branches include three parallel branches: expression recognition, age prediction, and gender classification, each with optimized network structures for its corresponding task. The cross-task feature interaction unit achieves adaptive feature fusion between tasks through a dynamic weight learning network, comprehensively improving the accuracy of multi-task collaborative inference. Specifically:

[0123] Basic Feature Extraction: The basic feature map output by the backbone network is generated through depthwise separable convolution and batch normalization stacking. The feature dimension mapping formula is:

[0124]

[0125] in, The preprocessed valid face image, This is a depthwise separable convolution operation (kernel size 3×3, stride 1, padding 1). For batch normalization operations, For dimension Basic feature map ( , , ).

[0126] Cross-task feature interaction mechanism: Feature fusion is achieved through a dynamic weight learning network, covering three stages: feature encoding, weight generation, and fusion enhancement. The core formula is as follows:

[0127] Feature encoding: The initial features of each task branch are uniformly encoded in terms of dimensions. , , ,in, , , These are the initial feature maps for expression recognition, age prediction, and gender classification branches, respectively. This is a 1×1 convolution operation used to uniformly map the feature dimensions to... dimension.

[0128] Weight generation: Generate a dynamic weight matrix based on global feature statistics.

[0129]

[0130]

[0131]

[0132]

[0133] in, This is a global average pooling operation. For feature splicing operations, For fully connected layer mapping, For activation function, 3× The dynamic weight matrix, , , The weight vectors for the three task branches are (dimension 1×). ).

[0134] Feature fusion: Fusion is achieved by dynamically weighting and weighting the features of each task. ,in, For channel-by-channel weighted multiplication, For the fused feature map (dimensions) The module outputs the analysis results and corresponding confidence scores for each task. For example, the expression recognition module outputs the expression label with the highest probability, the age prediction module outputs continuous age values, and the gender classification module determines the gender category based on the probability value, ensuring that the results are accurate and traceable.

[0135] Furthermore, the parallel acceleration module includes a multi-threaded scheduling unit and a CUDA GPU acceleration unit, working together to improve system processing efficiency. The multi-threaded scheduling unit adopts a producer-consumer pattern, creating three independent threads for frame reading, face detection, and multi-task analysis. Data transfer is achieved through a thread-safe queue with a limited length threshold to prevent memory overflow. The thread scheduling unit monitors the queue length and thread running status in real time, dynamically adjusting thread priorities to ensure matching processing speeds at each stage and preventing queue blocking. The CUDA GPU acceleration unit is optimized for the model inference process, supporting tensor fusion and asynchronous execution mechanisms. It merges multi-step inference operations into a single GPU kernel function, achieving overlapping execution of data transmission and inference computation through streaming parallelism, significantly improving GPU utilization. This unit has environmental adaptability, automatically detecting whether the hardware supports CUDA; if not, it switches to CPU mode to ensure system compatibility.

[0136] Furthermore, the data storage module is built on a MySQL database to achieve secure and efficient storage of user information and analysis records. The module comprises two sub-units: user information management and analysis record management. The user information management sub-unit stores information such as user ID, username, encrypted password, email address, and registration time. Passwords are encrypted using SHA256, and username uniqueness is ensured through unique constraints. The analysis record management sub-unit stores information such as record ID, user ID, task type, input data path, analysis results, confidence level, and processing timestamp. It is linked to the user information table via foreign keys to achieve data isolation and access control. The module supports encrypted data storage and access permission verification, ensuring that only authenticated users can access their own data. It also provides data backup and cleanup functions, automatically cleaning up expired data according to time ranges to guarantee storage efficiency.

[0137] Furthermore, the results display and interaction module is built on Vue 3 and Element Plus to create a web-based visual interface, providing a user-friendly human-computer interaction experience. The interface includes a function navigation area, data input area, results display area, history section, and system settings area. The function navigation area allows for quick switching between core functions; the data input area provides multiple input methods; the results display area presents face detection boxes, expression tags, age and gender prediction results, and corresponding confidence scores in real time, supporting visual annotation; the history section allows filtering and querying historical analysis records by time range and task type, and provides results export functionality (supporting JSON and Excel formats); the system settings area supports user information modification, password reset, interface theme switching, and detection parameter configuration. The module supports a responsive layout, adapting to different terminal devices to ensure ease of operation.

[0138] This embodiment details how lightweight network optimization and cross-task feature fusion, combined with engineered parallel acceleration and a multi-module collaborative architecture, have achieved a comprehensive improvement in the accuracy, real-time performance, and compatibility of multi-task face analysis. This effectively reduces the consumption of model computing resources and enhances the robustness of inference in complex scenarios. At the same time, through standardized storage and visual interactive design, the actual deployment and operation of the system are made more practical, fully meeting the technical requirements of real-time face analysis in multiple scenarios.

[0139] Based on Embodiment 1 or 2, this embodiment verifies the core technology of this application through experiments. By using mixed dataset training, multi-index quantitative statistics, and visualization analysis, the effectiveness of the proposed multi-task real-time face analysis scheme is verified. The experimental environment is configured with an Intel Core i7-12700H processor (base frequency 2.3GHz, maximum turbo frequency 4.7GHz), an NVIDIA RTX 3060 GPU (6GB GDDR6 video memory, 3840 CUDA cores), 16GB DDR4-3200 memory, and an Ubuntu 20.04 LTS system environment. The software framework is based on OpenCV 4.5.5 for computer vision preprocessing and PyTorch 1.12.1 for building deep learning models. Mixed precision computation is enabled during the training process to improve efficiency. The validation dataset uses a hybrid set of CelebA and Adience: CelebA provides 202,599 face images with gender annotations, and Adience provides 26,580 face images with age / gender annotations. The training and test sets are divided in a 7:3 ratio, with a training batch size of 32, an iteration count of 8, and an initial learning rate of 1e-4. A cosine annealing strategy is used to decay the learning rate by 0.8 after each iteration to ensure the stability of the model gradient updates.

[0140] In the model accuracy verification stage, key indicators during training were monitored in real time, and the generalization ability of the model was quantified using test set data. To visually present the training trend, the experiment recorded the changes in loss and accuracy of age prediction and gender classification tasks with the number of iterations, as shown in Table 1.

[0141] Table 1. Iteration round number variation data

[0142] As clearly shown in Table 1, with the increase in the number of training rounds, all indicators exhibit a stable optimization trend: the age prediction loss decreased from the initial 252.7 to 38.2, a reduction of over 85%; the mean absolute error of age prediction converged from 12.1 years to 4.7 years, a reduction of 61%; the gender classification loss decreased from 0.65 to 0.23, a reduction of 65%; and the gender classification accuracy improved from 0.70 to 0.91, an improvement of 30%. Figure 4The line graph of training process metrics shown indicates that the curves for age prediction loss and mean absolute error decrease smoothly and continuously during the iteration process without significant fluctuations, indicating that the model's learning process in the age regression task is stable and that there is no gradient explosion or vanishing. The curves for gender classification loss and accuracy show a completely matched inverse trend, verifying the beneficial effect of the multi-task feature interaction mechanism on the classification task. By fusing age and gender features through a dynamic weight matrix, the model can more accurately capture the correlation information between facial attributes, thereby improving classification accuracy.

[0143] To further quantify the error distribution characteristics of age prediction, the experiment performed error statistics on the age prediction results of the test set. The results were obtained through... Figure 5 The age prediction error histogram and Figure 7 The absolute error of age prediction is presented in a pie chart. Figure 5 It can be seen that the distribution of age prediction error exhibits a normal distribution characteristic with a high middle and low ends. The error range is concentrated between -2 years and 2 years, corresponding to more than 70% of the total samples. The proportion of samples with errors between -4 years and 4 years exceeds 90%, and only a small number of samples have errors exceeding ±4 years, indicating that the model's prediction bias for age is within a controllable range. Figure 7 The absolute error distribution shows that 90.5% of the samples have an absolute error ≤ 5 years old, 9.5% are between 5 and 10 years old, and there are no samples with an absolute error > 10 years old. This result meets the requirement that the age prediction error is acceptable within 5 years in practical application scenarios, proving that the age prediction module of this application can meet the accuracy requirements of most face analysis scenarios.

[0144] After completing the model accuracy verification, the experiment further tested the engineering performance. The core indicator was the frame-by-frame detection time, which directly determines the availability of the system in real-time video stream scenarios. The experiment selected 100 frames of video stream (resolution 1280×720) from the test set and recorded the detection time of each frame under a unified hardware environment, as shown in Table 2.

[0145] Table 2 Test Dataset

[0146] As shown in Table 2, this application exhibits excellent engineering performance under a unified hardware environment: the average frame-by-frame detection time is 10.2ms, the median is 10.1ms, the minimum is 8.1ms, the maximum is 12.1ms, and the standard deviation is only 0.9ms, indicating a highly concentrated time distribution and extremely strong stability; the average number of frames processed per second is 98.0, the median is 99.0, the minimum is 82.6, the maximum is 123.5, and the standard deviation is 7.3, indicating that the system can stably maintain a high frame rate output; the average memory usage is 1.5GB, and the average GPU utilization is 78.3%, indicating that the model maintains low resource consumption while efficiently utilizing hardware resources. Figure 6 The scatter plot analysis of frame-by-frame detection time shows that the detection time for 100 frames of video stream ranges from 8ms to 12ms, with no single detection exceeding 12ms. This indicates that the system can maintain stable latency when processing continuous video streams, without experiencing screen stuttering or data backlog due to sudden increases in latency. This result verifies the effectiveness of the parallel acceleration module. By allocating frame reading, face detection, and multi-task analysis to independent threads and using thread-safe queues for data transfer, the system can fully utilize the CPU's multi-core resources. Simultaneously, the CUDA acceleration unit integrates multi-step inference operations such as convolution and pooling into a single GPU kernel function and achieves overlapping execution of data transmission and inference computation through streaming parallelism, significantly improving GPU utilization and thus achieving low-latency, highly stable real-time processing capabilities.

[0147] The experimental results show that the multi-task real-time face analysis scheme proposed in this application achieves the following performance: In terms of model accuracy, the mean absolute error for age prediction is ≤4.7, and the accuracy for gender classification is ≥0.91, with the age prediction error concentrated within 5 years. In terms of engineering performance, it achieves a frame-by-frame detection time of ≤12.1ms and a frame processing rate of ≥82.6 frames per second, while maintaining low resource consumption. These results fully validate the effectiveness of the lightweight strategies of channel pruning and dynamic weight distillation, cross-task feature interaction, attention-enhanced multi-task inference mechanism, multi-threaded scheduling, and CUDA tensor fusion acceleration scheme proposed in this application. This scheme can meet the comprehensive requirements of high accuracy, low latency, and low resource consumption for face analysis in scenarios such as intelligent security, educational assessment, and emotion recognition.

[0148] The above are merely preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. For those skilled in the art, the present invention can have various modifications and variations. Any changes, modifications, substitutions, integrations, and parameter changes made to these embodiments within the spirit and principles of the present invention, without departing from the principles and spirit of the present invention, through conventional substitutions or to achieve the same function, fall within the scope of protection of the present invention.

Claims

1. A multi-task real-time face analysis method based on OpenCV and lightweight DNN, characterized in that, include: Acquire input data, which includes static images or real-time video streams, wherein the real-time video streams support camera capture or import of local video files; Image preprocessing is performed on the input data by loading a preprocessing model using OpenCV. The preprocessing includes image scaling, color space conversion, noise filtering, and illumination compensation. A lightweight MobileNet-SSD network optimized by channel pruning and dynamic weight distillation is loaded based on the OpenCV DNN module to perform face detection on the preprocessed input data, output face region coordinates and confidence scores, and filter face regions that meet the confidence score requirements to obtain valid face images. Input effective face images into a multi-task lightweight DNN model, simultaneously perform expression recognition, age prediction and gender classification tasks, and output the corresponding analysis results; It employs a multi-threaded parallel computing mechanism to process real-time video streams, and uses task queue scheduling to achieve asynchronous execution of frame reading, face detection and multi-task analysis. CUDA GPU acceleration for inference can be optionally enabled. The analysis results, input data identifiers, and processing timestamps are associated and stored in the database, supporting result visualization and historical record queries.

2. The method according to claim 1, characterized in that, The channel pruning employs an adaptive threshold strategy based on feature importance. The pruning priority for each channel is determined by calculating the information entropy of the feature map and the inter-class separation degree. The pruning decision formula is as follows: , ,in, For the first The feature importance score of each channel For information entropy calculation, For the first Feature map of each channel The inter-class separation degree of features and labels. For the first Adaptive pruning threshold for each channel Based on the threshold, The average importance score for all channels.

3. The method according to claim 2, characterized in that, The dynamic weight distillation optimization process of the lightweight MobileNet-SSD network employs an adaptive temperature adjustment mechanism. It dynamically adjusts the distillation temperature based on feature distribution differences, enabling the student model to accurately learn the higher-order features of the teacher model. The core optimization formula is: , ,in, To adapt to distillation temperature, The initial temperature. For adjustment coefficients, Let JS divergence be the metric. , The feature distributions for the student model and the teacher model are respectively. For loss weighting coefficients, For classifying losses, , These are the output logits values ​​for the student model and the teacher model, respectively.

4. The method according to claim 1, characterized in that, The multi-task lightweight DNN model employs a cross-task feature interaction mechanism, using a dynamic weight matrix to achieve feature fusion between different task branches, thereby improving the accuracy of multi-task collaborative inference. The feature fusion formula is as follows: , ,in, The fused feature map These are the basic features extracted for the backbone network. Number of task branches For the first Dynamic weights of each task branch For the first Feature maps of each task branch It is the Sigmoid activation function. This is a global average pooling operation. This is the weight mapping matrix. This is a bias term.

5. The method according to claim 1, characterized in that, The multi-task lightweight DNN model adopts a backbone network plus task branches structure, specifically: The backbone network is constructed using depthwise separable convolutions to extract global feature maps of the face. These feature maps contain information about the number of channels, height, and width. The task branches include facial expression recognition, age prediction, and gender classification. The facial expression recognition branch is constructed through multiple convolutional and fully connected layers, outputting the probability distribution of various facial expressions, which is then normalized by the Softmax function to obtain the final classification result; The age prediction branch adopts a regression network structure, which outputs continuous values ​​as the predicted age through a fully connected layer, and the training process is optimized using the MSE loss function. The gender classification branch constructs a binary classification network through multiple convolutional and fully connected layers, outputs gender probabilities through the Sigmoid function, and determines the gender category based on the probability magnitude.

6. The method according to claim 5, characterized in that, The facial expression recognition branch of the multi-task lightweight DNN model employs an attention-guided feature enhancement structure. Through the synergistic effect of spatial attention and channel attention, it strengthens the features of key facial expression regions. The attention calculation formula is as follows: , ,in, Features enhanced by spatial attention The output features of the convolutional layer This is a global max pooling operation. It is the Sigmoid activation function. For convolution operations, Features after channel attention enhancement For element-wise multiplication, It is a multilayer perceptron.

7. The method according to claim 6, characterized in that, The multi-task lightweight DNN model employs a cross-task feature interaction mechanism, using a dynamic weight matrix to achieve feature fusion between different task branches, thereby improving the accuracy of multi-task collaborative inference. The feature fusion formula is as follows: , in, The fused feature map These are the basic features extracted for the backbone network. Number of task branches For the first Dynamic weights of each task branch For the first Feature maps of each task branch It is the Sigmoid activation function. This is a global average pooling operation. This is the weight mapping matrix. This is a bias term.

8. The method according to claim 1, characterized in that, The multi-threaded parallel processing flow of the real-time video stream includes: Create a frame reading thread, a face detection thread, and a multi-task analysis thread, and implement data transfer through a thread-safe queue; The frame reading thread extracts image frames from the video stream at a fixed frame rate, performs initial scaling, and then stores them in the input queue. The face detection thread extracts image frames from the input queue, calls the lightweight MobileNet-SSD network to complete face detection, and stores the valid face images into the analysis queue. The multi-task analysis thread extracts face images from the analysis queue, inputs them into the multi-task lightweight DNN model to obtain analysis results, stores them in the result queue, and synchronizes them to the database. Set up a thread scheduling mechanism to dynamically adjust thread priorities based on the amount of data in each queue, thereby avoiding queue blocking.

9. The method according to claim 1, characterized in that, The CUDA GPU-accelerated inference employs a tensor fusion and asynchronous execution mechanism, fusing multi-step inference operations into a single GPU kernel function. It also achieves overlap between data transmission and inference computation through streaming parallelism, improving GPU utilization. The core optimization strategy is as follows: , in, For tensor fusion operations, to For continuous reasoning operations, For the merged GPU kernel functions, For streaming parallelism, , These are data transmission operations on the host side and the device side, respectively.

10. A multi-task real-time face analysis system based on OpenCV and lightweight DNN, characterized in that, include: The data input module supports three input methods: local still image upload, real-time camera capture, and local video file import. The preprocessing module integrates image scaling, color space conversion, noise filtering, illumination compensation, and data enhancement functions, and outputs standardized image data. The face detection module loads a lightweight MobileNet-SSD network model optimized by channel pruning and dynamic weight distillation to achieve fast face region detection, confidence filtering, and coordinate output. The multi-task analysis module is equipped with a lightweight DNN model containing a cross-task feature interaction mechanism, which simultaneously performs tasks such as facial expression recognition, age prediction, and gender classification, and outputs analysis results with confidence scores. The parallel acceleration module includes a multi-threaded scheduling unit and a CUDA GPU acceleration unit. The multi-threaded scheduling unit enables asynchronous execution of frame reading, detection, and analysis, while the GPU acceleration unit supports hardware acceleration of the inference process. The data storage module, based on a MySQL database, enables user information management and analysis record storage, and supports data encryption and access control. The results display and interaction module provides a web-based visual interface that supports real-time display of analysis results, historical record queries, result export, and system parameter settings.