Lightweight visual Transform framework-based ass face recognition system and method
Through the donkey face recognition system based on the lightweight visual Transformer framework, combined with the CNN and LeViT models, the recognition efficiency and accuracy of traditional donkey individual recognition methods in intensive breeding scenarios is solved, and efficient and safe donkey identity recognition is achieved. Suitable for donkey farm management in complex environments.
Patent Information
- Application Number
- CN202411120142.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2024-12-31
AI Technical Summary
In dense and complex breeding scenarios, traditional donkey individual identification methods have problems such as easy damage to ear tags, easy interference from RFID signals, low recognition speed and low efficiency, resulting in low work efficiency and safety risks, making it difficult to meet the needs of efficient and convenient intelligent management.
Using the donkey face recognition system based on the lightweight visual Transformer framework, combining the convolutional neural network (CNN) and the LeViT model, through feature extraction module, Regular stage module, Shrink stage module, classification network module, loss function selection module, hyperparameters and The parameter initialization module and the backpropagation mechanism module are used to build a donkey face recognition system suitable for complex environments, improving the flexibility and reliability of recognition.
It significantly improves the accuracy and efficiency of donkey individual identification, reduces management costs, realizes efficient and safe contactless donkey identity recognition, simplifies the traditional identification process, and is suitable for donkey farm management in complex environments.
Smart Images

Figure CN119229470A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a donkey face recognition system and method based on a lightweight visual Transformer framework, belonging to the technical field of smart agriculture, and specifically to the technical field of intelligent animal husbandry. Background Art
[0002] The traditional ear tag method for individual donkey identification usually requires farmers to contact and control the individual to be identified, and then observe the ear tag for recording. On the one hand, the ear tag is easy to be contaminated or fall off, and on the other hand, the observation process is easy to cause stress reactions in donkeys. The RFID method requires farmers to hold the identification gun close to the individual to be identified and aim it near the RFID chip for collection. In dense breeding conditions, individuals tend to gather together, affecting the efficiency and accuracy of identification.
[0003] Both of the above methods involve the problem of dividing into circles and groups after the recording is completed. When faced with the task of identifying individual donkeys in intensive and complex breeding scenarios, these two methods are even more stretched. Donkeys in a free-range state are highly alert and are interfered by various environmental factors, which make them difficult to capture and approach. Donkeys have complex social relationships and are easy to form small groups. They have a certain degree of dependence on each other. When capturing one of them, it is usually interfered with and obstructed by other donkeys. These limitations not only lead to the low efficiency of traditional methods and increase unnecessary repeated operation time, but also increase the safety hazards of on-site operations, affecting the overall efficiency and stable operation of data collection.
[0004] Existing technologies for identifying individual donkeys in animal husbandry mainly rely on ear tags and more advanced electronic radio frequency identification technology (RFID), which are difficult to effectively handle identification problems in dense and complex breeding scenarios. The limitations are as follows:
[0005] 1. Ear tags are easily lost or damaged: In dense and complex breeding scenarios, donkeys may rub or collide with each other, causing ear tags to easily fall off or be damaged, thus affecting identification accuracy.
[0006] 2. RFID signals are susceptible to interference: Although RFID technology can achieve contactless individual identification, in densely populated scenarios, due to mutual occlusion and interference between donkeys, RFID signals may be blocked or interfered, which also affects the accuracy and stability of identification.
[0007] 3. The recognition speed and efficiency are low, and data management is inconvenient: In large-scale breeding scenarios, a large number of donkeys need to be identified quickly and accurately. Traditional methods may not meet the needs of high-efficiency identification, resulting in low production management efficiency; at the same time, the identification data obtained by ear tags or RFID methods requires a lot of sorting, storage and management, which increases breeding costs.
[0008] In view of the above pain points and the strong demand for efficient, convenient and intelligent management models in modern smart farming, how to develop an individual donkey identification and management system that can be used in intensive and complex farming scenarios has become an important issue that needs to be urgently solved in the industry. Summary of the invention
[0009] The purpose of the present invention is to address the defects and shortcomings of the above-mentioned prior art, and propose a donkey face recognition system and method based on a lightweight visual Transformer framework. By integrating a convolutional neural network (CNN) with a LeViT model and a series of improved operations, a donkey face recognition system suitable for complex environments is constructed, which greatly improves the flexibility and reliability of donkey individual identification in actual application scenarios, and effectively promotes the technological innovation and development of large-scale breeding of the donkey industry.
[0010] The technical solution adopted by the present invention to solve the technical problem is: a donkey face recognition system based on a lightweight visual Transformer framework, the system comprising: a feature extraction module, a Regular stage module, a Shrink stage module, a classification network module, a loss function selection module, a hyperparameter and parameter initialization module and a back propagation mechanism module;
[0011] The feature extraction module is used to ensure that the donkey face feature information is fully extracted, including two stages: initial feature extraction and backbone feature extraction;
[0012] The Regular stage module does not change the size of the feature map when used, and is composed of a regular LeViT attention module and two layers of 1×1 convolution and batch normalization, connected in series with a hard threshold activation, and then residually connected to the input feature map;
[0013] The Shrink stage module is used to achieve the effect of halving the size of the feature map, and in the residual connection process, average pooling is performed on the original input features;
[0014] The classification network module is used to send the obtained feature map into the classification network to realize donkey face recognition, including adaptive averaging processing and classification head;
[0015] The back-propagation mechanism module calculates the gradient of the loss function with respect to the model parameters by using the chain rule, and the gradient is back-propagated layer by layer through the model, and the weights of each layer are updated according to the gradient to reduce the loss function.
[0016] Furthermore, the feature extraction module includes: initial feature extraction is composed of MV2 units in MobileNetV2, channel and spatial attention mechanism units, and Transformer as CNN block units with overlapping information, the backbone feature extraction stage is built with a modified lightweight visual Transformer structure, and the classification network is composed of adaptive averaging processing and a classification head defined by a linear classifier;
[0017] The MV2 unit is a residual structure that can maintain the stability of the algorithm and ensure the convergence of a deeper network model. The main part of the MV2 unit is composed of a 1×1 point-wise convolution plus layer normalization, a 3×3 depth-wise convolution plus layer normalization, and a 1×1 point-wise convolution plus layer normalization connected in series. After the residual connection, it passes through the channel attention and spatial attention mechanisms in turn to finally form preliminary features;
[0018] The Transformer as CNN block unit with overlapping information includes: a Transformer structure in the image field consisting of a mapping layer consisting of image slicing, position encoding and word embedding, a nonlinear feature extraction unit consisting of key (K)-query (Q)-value (V) and an encoding layer consisting of MLP. In the image slicing part, by introducing a stride parameter, the number of blocks is increased to achieve the effect of information overlapping, thereby ensuring full use of local information of the input image.
[0019] Furthermore, the classification network module includes: an adaptive average processing module that enables the model to further focus on specific areas or blocks to improve recognition accuracy. The adaptive average processing module is composed of a transposition operation, image resizing, global deep convolution and image resizing in series, and the classification head is composed of a linear network.
[0020] Furthermore, the loss function selection module selects three loss functions: ArcFace, CosFace and SphereFace. The ArcFace loss is implemented by combining the inner product operation of the feature vector and the Softmax function. The CosFace loss function is a combination of the cosine function and the Softmax function to achieve comparison based on angle information. The SphereFace loss enhances the feature discrimination ability by increasing the angle interval, which is used to improve the classification accuracy.
[0021] Furthermore, the hyperparameter and parameter initialization module includes: hyperparameters include model construction parameters such as the number of layers, width and resolution of the input image, optimizer parameters such as learning rate, weight decay strategy and momentum, and attention mechanism parameters such as the number of attention heads and attention bias. The initial feature extraction part adopts the Kaiming initialization method, the backbone feature extraction part adopts the random initialization and Xavier initialization methods, the classification network structure part adopts the Xavier initialization method, and the normalization layer in the network model is initialized with a constant value of zero.
[0022] The present invention also proposes a donkey face recognition method based on a lightweight visual Transformer framework, the method specifically comprises the following steps:
[0023] Step 1: Construct a donkey face dataset, including a donkey individual dataset and a donkey facial dataset;
[0024] Step 2: Rewrite the method in the Dataset abstract class in Torch, and the user returns a single tuple sample in the dataset based on the given index;
[0025] Step 3: Use the DataLoader class in Torch to batch process the data set, shuffle the order, and load the data in multiple processes;
[0026] Step 4: Use the Model class in Torch to connect the initial feature extraction, backbone feature extraction, and classification network together to form a new model;
[0027] Step 5: Model training and prediction.
[0028] Furthermore, the step 1 comprises:
[0029] Donkey individual dataset: First, we collected video clips of two types of donkeys, the three-powder donkey and the black-headed donkey, by recording individual facial videos of donkeys. When recording, we paid attention to the left face, right face, frontal low-angle face, and high-angle face data to ensure the richness of individual donkey face data.
[0030] Donkey face dataset: The dataset is extracted by extracting frames from the video and removing individual image data with high similarity through the SSIM similarity test. Then, the donkey face information in each individual image is extracted through data annotation and image detection technology. The image size is adjusted to form a 112×224 donkey face dataset.
[0031] Furthermore, the step 2 includes: the tuple is composed of donkey face image data and corresponding numbered labels, and the data length is set to the size of the donkey face data set.
[0032] Furthermore, step 4 includes: the CBAM-MV2 module in the initial feature extraction stage converts the original image block of size (B, 3, 224, 112) into a preliminary feature map of size (B, 16, 112, 56), and the subsequent Tacblock with The overlapping module further converts the features into feature maps of size (B, 32, 112, 56), and finally uses CBAM-MV2 again to obtain the final initial feature map of size (B, 128, 28, 14); the backbone feature extraction network mainly adopts a lightweight version of the LeViT-Transformer structure, which is mainly composed of two types of modules, the conventional LeViT attention and the reduced LeViT attention, in which the conventional version keeps the image size unchanged, while the reduced version of the attention mechanism adjusts the image size to 1 / 2 of the original. After the backbone feature extraction network, the final feature map size is (B, 512, 7, 3); the classification network consists of adaptive averaging processing and a classification head. After adaptive averaging processing, a feature vector of size (B, 512) is obtained, which is optimally passed through a classification head composed of linear projection to finally realize donkey face recognition.
[0033] Furthermore, step 5 includes: by rewriting the training class implementation in torch, the training set and the test set are divided into 8:2, the epoch size is selected as 300, the initial learning rate is selected as 1e-3, the weight decay strategy is selected as the cosine descent method, and the feature vector obtained by the loss function in the previous layer of the classification head layer is weighted using ArcFace, CosFace and SphereFace losses. In addition, the model type output and category label are comprehensively processed using cross entropy loss.
[0034] Beneficial effects:
[0035] 1. The network structure model of the present invention is lightweight and has good expressiveness: by introducing the attention mechanism and residual connection, the expressiveness of this type of network is further improved. In addition, the use of deep convolution and point-wise convolution is emphasized to make the network further lightweight.
[0036] 2. The present invention can improve the donkey face feature extraction effect: using input image formats with different heights and widths greatly improves the unique local features of the original donkey face, so that the network has a better recognition rate.
[0037] 3. The present invention can reduce the management cost of donkeys in a donkey farm: the facial information of all donkeys in the donkey farm is saved, and a donkey face recognition solution based on images and deep learning is implemented, which is conducive to reducing the labor input and cost input of individual donkey management.
[0038] 4. The present invention can optimize the process of individual donkey identification: it uses high-definition intelligent cameras combined with deep learning technology to achieve efficient and safe contactless donkey identification, effectively simplifying the complexity of the traditional identification process and significantly improving identification efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 This is an overall framework diagram of a donkey face recognition system based on a lightweight visual Transformer framework in the present invention.
[0040] Figure 2 This is the CBAM-MV2 network structure diagram of the present invention.
[0041] Figure 3 This is the LeviT-Transformer network structure diagram after adjustment in the present invention.
[0042] Figure 4 This is a flow chart of a donkey face recognition method based on a lightweight visual Transformer framework in the present invention. DETAILED DESCRIPTION
[0043] The invention will be further described in detail below in conjunction with the accompanying drawings.
[0044] like Figure 1 As shown, the present invention proposes a donkey face recognition system based on a lightweight visual Transformer framework, which includes a feature extraction module, a Regular stage module, a Shrink stage module, a classification network module, a loss function selection module, a hyperparameter and parameter initialization module, and a back propagation mechanism module, as follows:
[0045] The feature extraction module includes two stages: initial feature extraction and backbone feature extraction, which ensures that the donkey face feature information is fully extracted. The initial feature extraction is composed of the MV2 unit in MobileNetV2, the channel and spatial attention mechanism (CBAM) unit, and the Transformer as CNN block unit with overlapping information. The backbone feature extraction stage is built with a modified lightweight visual Transformer structure (LeViT Transformer). The classification network consists of adaptive averaging processing and a classification head defined by a linear classifier.
[0046] like Figure 2As shown in the figure, the CBAM-MV2 unit is obtained by fusing the MV2 of the channel and spatial attention mechanisms. The CBAM-MV2 unit is used to directly use the original input donkey face image to preliminarily extract features. The MV2 unit is a residual structure that can maintain the stability of the algorithm and ensure the convergence of the deeper network model. The main part of the MV2 unit is composed of 1×1 point-wise convolution plus layer normalization, 3×3 depth convolution plus layer normalization and 1×1 point-wise convolution plus layer normalization in series. After the residual connection, it passes through the channel attention and spatial attention mechanisms in turn to finally form preliminary features;
[0047] Transformer as CNN block unit with overlapping information: The Transformer structure in the image field consists of a mapping layer consisting of image slicing, position encoding and word embedding, a nonlinear feature extraction unit consisting of key (K)-query (Q)-value (V) and an encoding layer consisting of MLP. In the image slicing part, the stride parameter is introduced to increase the number of blocks to achieve the effect of information overlapping. The advantage of this design is that it ensures full use of local information of the input image while introducing a small amount of calculation.
[0048] like Figure 3 As shown in the figure, the backbone feature extraction mainly includes the modified LetViT-Transformer structure. On the basis of the initial extraction network structure, the lightweight ViT structure is used to further integrate important features in the global range to improve the classification and recognition effect of the model. The structure has three layers, which are composed of 2, 3 and 4 Regular stages respectively, and the layers are connected by shrink stages.
[0049] The regular stage module does not change the size of the feature map when used. It consists of a regular LeViT attention module and two layers of 1×1 convolution and batch normalization, connected in series with a hard threshold activation, and then residually connected to the input feature map.
[0050] The basic structure of the shrink stage module is the same as that of the regular stage module. The regular LeViT attention module needs to be adjusted to the shrink LeViT attention module to achieve the effect of halving the size of the feature map. In addition, during the residual connection process, the original input features also need to be average pooled.
[0051] Classification network module: After the initial feature extraction and backbone feature extraction stages, the obtained feature map is sent to the classification network to realize donkey face recognition. It is composed of adaptive averaging processing and classification head. After the adaptive averaging processing module, the model can further focus on specific areas or blocks to improve the recognition accuracy. The adaptive averaging processing module is composed of transposition operation, image resizing, global deep convolution and image resizing in series, and the classification head is composed of a linear network.
[0052] Loss function selection module: ArcFace, CosFace and SphereFace are selected. ArcFace loss is implemented by combining the inner product operation of the feature vector and the Softmax function. The CosFace loss function is a combination of the cosine function and the Softmax function to achieve comparison based on angle information. The SphereFace loss increases the angle interval to enhance the feature discrimination ability and improve the classification accuracy.
[0053] Hyperparameters and parameter initialization module: Hyperparameters include model construction parameters such as the number of layers, width, and resolution of the input image, optimizer parameters such as learning rate, weight decay strategy, and momentum, as well as attention mechanism parameters such as the number of attention heads and attention bias. The initial feature extraction part uses the Kaiming initialization method, the backbone feature extraction part uses random initialization and Xavier initialization methods, the classification network structure part uses the Xavier initialization method, and the normalization layer in the network model is initialized with a constant value of zero.
[0054] Back propagation mechanism module: Using the chain rule, the gradient of the loss function with respect to the model parameters is calculated, and the gradient is back-propagated layer by layer through the model. The weights of each layer are updated according to the gradient to achieve the purpose of reducing the loss function.
[0055] To ensure that the model has good generalization ability, the original image data is enhanced by random cropping, rotation and flipping. The structure of this model is complex enough to ensure the representation ability of the model itself and improve the generalization ability. The lightweight design of each layer of the model makes the model parameters relatively small, further enhancing the generalization ability of the model.
[0056] The present invention discloses a donkey face recognition system based on a lightweight visual Transformer framework, which aims to develop an intelligent and convenient donkey face recognition method integrating a deep learning algorithm, break the limitations of traditional donkey individual recognition and management, realize efficient, convenient and accurate recognition and management in a dense and complex breeding environment, realize accurate recognition of donkey faces under complex environmental factors, ensure that donkey face recognition can be successfully completed under the influence of illumination changes, partial occlusion and angle changes, integrate convolutional neural network (CNN) and LeViT model within a limited computational budget framework, construct an efficient hybrid architecture, effectively accelerate model convergence through convolutional neural network, and ensure the final prediction accuracy and generalization ability through LeViT model, fully consider the global context information of the image in the donkey face recognition process, comprehensively analyze the features, textures, shapes and their mutual relationships in the entire image area, eliminate background interference and non-feature factors, ensure that the algorithm can accurately capture the unique features of donkey faces, improve recognition accuracy and robustness, and introduce CBAM attention mechanism (Convolutional Block Attention Module), based on the convolutional neural network, the model is fine-tuned. By combining the CBAM attention module, the weight information of the channel and spatial dimensions can be efficiently learned and integrated to achieve accurate grasp and effective use of the input feature map information.
[0057] like Figure 4 As shown, the present invention also proposes a donkey face recognition method based on a lightweight visual Transformer framework, which specifically includes the following steps:
[0058] Step 1: Construct a donkey face dataset, including a donkey individual dataset and a donkey facial dataset;
[0059] Donkey individual dataset: First, we collected video clips of two types of donkeys, the three-powder donkey and the black-headed donkey, by recording individual facial videos of donkeys. When recording, we paid attention to the left face, right face, frontal low-angle face, and high-angle face data to ensure the richness of individual donkey face data.
[0060] Donkey face dataset: By extracting frames from the video and removing individual image data with high similarity through SSIM similarity test, the donkey face information in each individual image is extracted through data annotation, image detection technology and other means, and the image size is adjusted appropriately to finally form a 112×224 size donkey face dataset.
[0061] Step 2: Rewrite the method in the Dataset abstract class in Torch. The user returns a single tuple sample in the dataset according to the given index. The tuple consists of donkey face image data and corresponding numbered labels. The data length is set to the size of the donkey face dataset.
[0062] Step 3: Use the DataLoader class in Torch to batch process the data set, shuffle the order, load the data in multiple processes, and select a batch_size of 64.
[0063] Step 4: The initial feature extraction is performed through the model class in Torch, which is composed of connecting the backbone feature extraction and classification networks together; the CBAM-MV2 module in the initial feature extraction stage converts the original image block of size (B, 3, 224, 112) into a preliminary feature map of size (B, 16, 112, 56), and the subsequent Tac block The withoverlapping module further converts the features into feature maps of size (B, 32, 112, 56), and finally uses CBAM-MV2 again to obtain the final initial feature map of size (B, 128, 28, 14); the backbone feature extraction network mainly adopts a lightweight version of the LeViT-Transformer structure, which is mainly composed of two types of modules, the conventional LeViT attention and the reduced LeViT attention, in which the conventional version keeps the image size unchanged, while the reduced version of the attention mechanism adjusts the image size to 1 / 2 of the original. After the backbone feature extraction network, the final feature map size is (B, 512, 7, 3); the classification network consists of adaptive averaging processing and a classification head. After adaptive averaging processing, a feature vector of size (B, 512) is obtained, which is optimally passed through a classification head composed of linear projection to realize donkey face recognition.
[0064] Step 5: Model training and prediction are implemented by rewriting the training class in torch. The training set and test set are divided into 8:2, the epoch size is selected as 300, the initial learning rate is selected as 1e-3, the weight decay strategy is selected as the cosine descent method, and the loss function uses ArcFace, CosFace and SphereFace losses to weight the feature vector obtained in the first layer before the classification head layer. In addition, the model type output and category label are comprehensively processed using cross entropy loss.
[0065] Embodiment 1
[0066] In a typical donkey farm, a high-definition camera with image transmission function is installed above the water trough or feed trough. Donkey face recognition can realize intelligent recording of donkey status and behavior. The specific implementation steps are as follows:
[0067] Step 1: Donkey face collection: The surveillance video captured by the camera is transmitted to the backend server, and the donkey face location information is determined through video frame extraction and donkey face detection algorithm, and then a donkey face dataset with ear tags or other label information is constructed;
[0068] Step 2: Donkey face dataset division: After data enhancement, the donkey face dataset is divided into a training set and a test set in a ratio of 8:2. The training set is used to train model parameters, and the test set is used to further adjust the model hyperparameters, so that the model has good stability and generalization ability.
[0069] Step 3, model training - donkey face feature extraction: the extracted donkey face data is sent to the network model and undergoes the following processing in sequence: image resizing: the donkey face image is adjusted to the format and size required for model input; initial feature extraction: the corresponding module is applied to extract the preliminary features of the obtained donkey face image; backbone feature extraction: based on the preliminary features, the backbone feature extraction model is further used to obtain the features that can finally be used for the classification network.
[0070] Step 4: Model training - donkey face recognition: Use the feature vector extracted by the feature extraction network to calculate the loss function by comparing it with the corresponding label;
[0071] Step 5: Model training: The loss function uses the Torch model to automatically calculate the gradients of each parameter, and updates the parameters of each layer of the network according to optimizer parameters such as learning rate, weight decay strategy, and momentum. Repeat steps 3 to 5 until the number of iterations reaches the upper limit or the loss function tends to a stable state.
[0072] Step 6: Model verification: Save the entire model structure, the optimal model parameters, and the feature vectors of each donkey face in the calculated donkey face dataset. When a new donkey face photo is obtained, the initial features, backbone features, and final feature vectors obtained by the classification network are calculated by directly passing them into the model, and compared with the saved donkey face feature vector to determine which donkey in the database it is or whether it is an unknown donkey face.
[0073] Finally, after multiple rounds of training, testing, and fine-tuning of the hyperparameters of each model hierarchy, a donkey face recognition algorithm with a recognition rate of over 94% was successfully obtained that takes into account both parameter quantity and operating efficiency. Based on the donkey face recognition algorithm, the automatic collection of individual data can be realized by turning on corresponding devices (such as inspection robots, etc.), achieving the preliminary function of intelligent farming.
[0074] The core of the present invention is to use a lightweight version of the ViT-Transformer network combined with an attention mechanism, image segmentation with overlapping information, a reduced version of the LeViT attention block, and adaptive averaging to perform donkey face recognition and to achieve individual identification of donkeys with high adaptability to complex environments.
[0075] Specifically include:
[0076] 1. Initial feature extraction with attention mechanism: Before implementing the lightweight ViT module, the initial features are extracted from the initial image. In this process, the channel and spatial attention mechanisms are integrated.
[0077] 2. Image segmentation mechanism with overlapping information: The image slice part in the Transformer structure is integrated with the stride translation parameter, so that the feature image contains overlapping blocks when it is segmented, so that more local feature image information can be passed into the Transformer structure.
[0078] 3. Residual connection mechanism in the backbone network: In the reduction block in the backbone feature extraction network, a residual connection based on the average pooling of the original feature image is introduced, making the feature extraction process more stable and the convergence speed faster.
[0079] The above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A donkey face recognition system based on a lightweight visual Transformer framework, characterized in that: The system comprises: a feature extraction module, a Regular stage module, a Shrink stage module, a classification network module, a loss function selection module, a hyperparameter and parameter initialization module and a back propagation mechanism module; The feature extraction module is used to ensure that the donkey face feature information is fully extracted, including two stages: initial feature extraction and backbone feature extraction; The Regular stage module does not change the size of the feature map when used, and is composed of a regular LeViT attention module and two layers of 1×1 convolution and batch normalization, connected in series with a hard threshold activation, and then residually connected to the input feature map; The Shrink stage module is used to achieve the effect of halving the size of the feature map, and in the residual connection process, average pooling is performed on the original input features; The classification network module is used to send the obtained feature map into the classification network to realize donkey face recognition, including adaptive averaging processing and classification head; The back-propagation mechanism module calculates the gradient of the loss function with respect to the model parameters by using the chain rule, and the gradient is back-propagated layer by layer through the model, and the weights of each layer are updated according to the gradient to reduce the loss function.
2. According to claim 1, a donkey face recognition system based on a lightweight visual Transformer framework is characterized in that: The feature extraction module includes: the initial feature extraction is composed of the MV2 unit in MobileNetV2, the channel and spatial attention mechanism unit, and the Transformer as CNN block unit with overlapping information. The backbone feature extraction stage is built with a modified lightweight visual Transformer structure, and the classification network is composed of adaptive averaging processing and a classification head defined by a linear classifier; The MV2 unit is a residual structure that can maintain the stability of the algorithm and ensure the convergence of a deeper network model. The main part of the MV2 unit is composed of a 1×1 point-wise convolution plus layer normalization, a 3×3 depth-wise convolution plus layer normalization, and a 1×1 point-wise convolution plus layer normalization connected in series. After the residual connection, it passes through the channel attention and spatial attention mechanisms in turn to finally form preliminary features; The Transformer as CNN block unit with overlapping information includes: a Transformer structure in the image field consisting of a mapping layer consisting of image slicing, position encoding and word embedding, a nonlinear feature extraction unit consisting of key (K)-query (Q)-value (V) and an encoding layer consisting of MLP. In the image slicing part, by introducing a stride parameter, the number of blocks is increased to achieve the effect of information overlapping, thereby ensuring full use of local information of the input image.
3. According to claim 1, a donkey face recognition system based on a lightweight visual Transformer framework is characterized in that: The classification network module includes: an adaptive average processing module that enables the model to further focus on specific areas or blocks to improve recognition accuracy. The adaptive average processing module is composed of a transposition operation, image size adjustment, global deep convolution and image size adjustment in series, and the classification head is composed of a linear network.
4. The donkey face recognition system based on a lightweight visual Transformer framework according to claim 1, characterized in that: The loss function selection module selects three loss functions: ArcFace, CosFace and SphereFace. The ArcFace loss is implemented by combining the inner product operation of the feature vector and the Softmax function. The CosFace loss function is a combination of the cosine function and the Softmax function to achieve comparison based on angle information. The SphereFace loss enhances the feature discrimination ability by increasing the angle interval, which is used to improve the accuracy of classification.
5. The donkey face recognition system based on a lightweight visual Transformer framework according to claim 1, characterized in that: The hyperparameter and parameter initialization module includes: hyperparameters include model construction parameters such as the number of layers, width and resolution of the input image, optimizer parameters such as learning rate, weight decay strategy and momentum, and attention mechanism parameters such as the number of attention heads and attention bias. The initial feature extraction part adopts the Kaiming initialization method, the backbone feature extraction part adopts the random initialization and Xavier initialization methods, the classification network structure part adopts the Xavier initialization method, and the normalization layer in the network model is initialized with a constant value of zero.
6. A donkey face recognition method based on a lightweight visual Transformer framework, characterized in that: The method has the following specific steps: Step 1: Construct a donkey face dataset, including a donkey individual dataset and a donkey facial dataset; Step 2: Rewrite the method in the Dataset abstract class in Torch, and the user returns a single tuple sample in the dataset based on the given index; Step 3: Use the DataLoader class in Torch to batch process the data set, shuffle the order, and load the data in multiple processes; Step 4: Use the model class in Torch to connect the initial feature extraction, backbone feature extraction, and classification network together to form a new model; Step 5: Model training and prediction.
7. A donkey face recognition method based on a lightweight visual Transformer framework according to the claim, characterized in that: The step 1 comprises: Donkey individual dataset: First, we collected video clips of two types of donkeys, the three-powder donkey and the black-headed donkey, by recording individual facial videos of donkeys. When recording, we paid attention to the left face, right face, frontal low-angle face, and high-angle face data to ensure the richness of individual donkey face data. Donkey face dataset: The dataset is extracted by extracting frames from the video and removing individual image data with high similarity through the SSIM similarity test. Then, the donkey face information in each individual image is extracted through data annotation and image detection technology. The image size is adjusted to form a 112×224 donkey face dataset.
8. A donkey face recognition method based on a lightweight visual Transformer framework according to the claim, characterized in that: The step 2 comprises: a tuple is composed of donkey face image data and corresponding number labels, the crossover probability is set to 0.8, two randomly selected parent individuals are crossed at a certain section of the path sequence, the coordinate point sequences of the two parts are exchanged, and a new child individual is generated.
9. A donkey face recognition method based on a lightweight visual Transformer framework according to the claim, characterized in that: The step 4 includes: the CBAM-MV2 module in the initial feature extraction stage converts the original image block of size (B, 3, 224, 112) into a preliminary feature map of size (B, 16, 112, 56), and the subsequent Tac block with The overlapping module further converts the features into feature maps of size (B, 32, 112, 56), and finally uses CBAM-MV2 again to obtain the final initial feature map of size (B, 128, 28, 14); the backbone feature extraction network mainly adopts a lightweight version of the LeViT-Transformer structure, which is mainly composed of two types of modules, the conventional LeViT attention and the reduced LeViT attention, in which the conventional version keeps the image size unchanged, while the reduced version of the attention mechanism adjusts the image size to 1 / 2 of the original. After the backbone feature extraction network, the final feature map size is (B, 512, 7, 3); the classification network consists of adaptive averaging processing and a classification head. After adaptive averaging processing, a feature vector of size (B, 512) is obtained, which is optimally passed through a classification head composed of linear projection to finally realize donkey face recognition.
10. A donkey face recognition method based on a lightweight visual Transformer framework according to the claim, characterized in that: The step 5 includes: rewriting the training class implementation in Torch, dividing the training set and the test set into 8:2, selecting the epoch size as 300, selecting the initial learning rate as 1e-3, selecting the cosine descent method as the weight decay strategy, and weighting the feature vector obtained by the loss function in the first layer before the classification head layer using ArcFace, CosFace and SphereFace losses. In addition, the model type output and category label are comprehensively processed using cross entropy loss.
