Horse face recognition method based on dynamic convolution residual deep learning network
By introducing a combination of dynamic convolution and coordinate attention mechanism into horse face recognition technology, the problems of low horse face recognition accuracy and high hardware resource consumption in the existing technology are solved, and a more efficient and robust horse face recognition effect is achieved. .
Patent Information
- Application Number
- CN202410645945.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-23
- Publication Date
- 2024-08-27
AI Technical Summary
Existing horse face recognition technology faces problems such as poor image quality, large individual differences, complex data processing, and complex network structures, resulting in high hardware resource consumption. Traditional methods have flaws in accuracy.
A deep learning network based on dynamic convolutional residuals is used, combined with the coordinate attention mechanism, to dynamically adjust the convolution kernel and attention weight, enhance the adaptability and generalization ability of the network, and improve feature extraction capabilities and recognition accuracy.
It improves the accuracy and efficiency of horse face recognition, reduces the risk of over-fitting, makes the model more robust, suitable for minicomputer applications, and shows higher accuracy in horse face recognition tasks.
Smart Images

Figure CN118552979A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of horse face recognition, and in particular to a horse face recognition method based on a dynamic convolution residual deep learning network. Background Art
[0002] With the development and progress of society, traditional horse identification methods, including freeze branding, hot iron branding, ear tags and electronic ear tags, can no longer meet the requirements of animal welfare. It has become possible to achieve horse identification by extracting subtle texture differences on the horse's face with the help of machine vision technology.
[0003] Gerard et al. used face image normalization and independent component analysis (ICA) to extract features and cosine distance for classification, and studied their method on a database containing 50 sheep, and Cai et al. used RASL and WLBP to extract features and chi-square distance for classification, and studied a database containing 30 cows.
[0004] Although horse recognition technology has made certain progress in China and the West, it still faces many challenges, such as poor image quality, large individual differences among horses, and complex data processing. Traditional methods such as ICA, RASL, WLBP, and LBP have great defects in accuracy.
[0005] Other mainstream methods now include YOLOv5 and RCNN, but their designs in the candidate region generation and feature extraction stages may result in insufficient positioning accuracy; for example, the residual neural network proposed by He Kaiming, although it solves the problem of gradient explosion when the network is deepened, its accuracy is not ideal when applied to horse face recognition.
[0006] For example, Wen Zhiqiang et al.'s method for recognizing and segmenting horse facial features based on Mask_RCNN uses the Mask_RCNN network to segment the horse face and horse facial features in the image to obtain a mask, and while detecting the horse face and horse facial features, it also achieves the segmentation of the horse face and horse facial feature image and the background. They also use Mask_RCNN combined with the ResNet50 network and the FPN network to train a detection model. Based on the existing detection of horse face and horse facial features, this model achieves the positioning of horse face and horse facial features and adds a segmentation branch. However, this method has a complex network structure and high requirements on hardware resources, which is not conducive to application on small computers. Summary of the invention
[0007] In view of the shortcomings of the existing methods, the present invention improves the residual neural network and introduces dynamic convolution and coordinate attention mechanisms, which can dynamically adjust the convolution kernel according to the characteristics of the horse, thereby enhancing the adaptability and generalization ability of the network; at the same time, the attention weight is adaptively adjusted according to the spatial position information of different areas in the image, which makes fuller use of the spatial information of the image and improves the feature extraction ability of the network; the combination of the two methods improves the efficiency and accuracy of the network, reduces the risk of overfitting, and makes the model more robust.
[0008] The technical solution adopted by the present invention is: a horse face recognition method based on a dynamic convolution residual deep learning network comprises the following steps:
[0009] Step 1: Collect horse face images, pre-process the images and divide the data sets;
[0010] As a preferred implementation of the present invention, preprocessing includes: random cropping, image to tensor conversion and normalization processing.
[0011] Step 2: Construct the DYCCARN network, which includes a 7×7 convolutional layer, a 3×3 maximum pooling layer, four residual stages containing several residual blocks, a global average pooling layer, a fully connected layer, and a Softmax activation function.
[0012] As a preferred embodiment of the present invention, the numbers of residual blocks in the four residual stages are 3, 4, 6 and 3 respectively, the first residual block in each residual stage is downsampled with a stride of 2; the stride of the remaining residual blocks is 1; and a coordinate attention module is introduced at the end of each residual stage.
[0013] As a preferred embodiment of the present invention, the residual block includes: input feature input conv11×1, then pass through a batch normalization layer and a ReLU activation function, then pass through a 3×3 dynamic convolution layer, a batch normalization layer and a ReLU activation function; then pass through a convolution layer conv11×1, a batch normalization layer and a ReLU activation function; and perform a residual connection with the input feature and then pass through a ReLU activation function.
[0014] As a preferred embodiment of the present invention, the global spatial information in the dynamic convolution layer is first compressed by global average pooling; then, two fully connected layers are used, with a ReLU between the fully connected layers and a second fully connected layer followed by a softmax to generate normalized attention weights of K convolution kernels.
[0015] As a preferred embodiment of the present invention, the coordinate attention module decomposes the channel attention into two parallel 1D feature encodings and integrates the spatial coordinate information into the attention map.
[0016] Step 3: Input the horse face image into the DYCCARN network to obtain the predicted value, calculate the cross entropy loss, back propagate and update the model parameters.
[0017] As a preferred embodiment of the present invention, a horse face recognition system based on a dynamic convolution residual deep learning network includes: a memory for storing instructions executable by a processor; and a processor for executing instructions to implement a horse face recognition method based on a dynamic convolution residual deep learning network.
[0018] As a preferred embodiment of the present invention, a computer readable medium stores a computer program code, and when the computer program code is executed by a processor, a horse face recognition method based on a dynamic convolution residual deep learning network is implemented.
[0019] Beneficial effects of the present invention:
[0020] 1. Design four residual stages, combine the residual block with the coordinate attention module, use dynamic convolution layer in the residual block, dynamically superimpose multiple convolution kernels according to attention, improve feature expression ability while saving computational cost, use dynamic convolution to increase model expression ability without increasing network depth or width, and adaptively adjust convolution parameters according to input features. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 This is a structural diagram of a dynamic convolution residual deep learning network according to the present invention;
[0022] Figure 2 These are side and frontal pictures of different horses;
[0023] Figure 3 is a residual block structure diagram of the present invention;
[0024] Figure 4 It is a dynamic convolution layer structure diagram of the present invention;
[0025] Figure 5 is a structural diagram of the coordinate attention module of the present invention;
[0026] Figure 6 It is the ACC curve and LOSS curve of the resnet network;
[0027] Figure 7 It is the ACC curve and LOSS curve diagram of the present invention. DETAILED DESCRIPTION
[0028] The present invention is further described below in conjunction with the accompanying drawings and embodiments. This figure is a simplified schematic diagram, which only illustrates the basic structure of the present invention in a schematic manner, and therefore it only shows the components related to the present invention.
[0029] like Figure 1 As shown, a horse face recognition method based on a dynamic convolution residual deep learning network includes the following steps:
[0030] First, the dataset is divided into a training set and a validation set, one for training and the other for testing. Then, the DYCCARN model (Dynamic Convolutional Coordinate Conscious Attention Residual Neural Network) is constructed. During the training process, the loss value and accuracy of the training set and validation set are monitored and recorded. At the same time, the model weight with the best performance on the validation set is saved. Finally, this weight is used to complete the prediction of a single image, and the one with the highest probability is the identity of the horse.
[0031] The horse face data used comes from the THoDBRL2015 horse face multi-view dataset. There are 47 horse images in the dataset, with an image resolution of 640×480 pixels. Figure 2 The left and right pictures show the side and front faces of the two horses respectively.
[0032] Random Resized Cropping, ToTensor and Normalization operations are performed on the training set images.
[0033] The validation set is subjected to resizing (Resize), center cropping (CenterCrop), image to tensor (ToTensor) and normalization (Normalize) operations.
[0034] In the DYCCARN network, first, the image (usually of size 224×224×3) is processed by a 7×7 convolutional layer with a stride of 2 and 64 output channels; the purpose of using a large-size 7×7 convolutional layer is to retain as many original features as possible during early downsampling.
[0035] Next, the large-size convolutional features pass through a 3×3 maximum pooling layer with a stride of 2 to extract the most significant features from the input feature map. The maximum pooling layer reduces the size of the feature map by selecting the maximum value in each pooling window so that the most significant features can be used for horse face recognition. This step reduces the image size by half.
[0036] Then, the image enters four residual stages, each of which contains multiple residual blocks, with the number of residual blocks being 3, 4, 6, and 3 respectively; the first residual block in each stage is downsampled with a stride of 2 to halve the spatial dimension, and the stride of the remaining residual blocks is 1; at the same time, a coordinate attention mechanism is added at the end of each residual stage to further extract the key features of the image.
[0037] After the last four residual stages, a global average pooling layer is applied to reduce the size of the feature map and reduce the risk of overfitting.
[0038] Finally, the image passes through a fully connected layer with 1000 neurons, and then the Softmax activation function is used to compress the K-dimensional real vector into a probability distribution; the category with the highest probability is the final predicted horse category.
[0039] like Figure 3 This is the residual block structure diagram. The input feature x is passed to the first convolution layer conv11×1, and then passes through the batch normalization layer and ReLU activation function; then a 3×3 dynamic convolution and batch normalization layer and ReLU activation function are used; then it is passed to the second convolution layer conv11×1, and the batch normalization layer and ReLU activation function are applied; then the residual connection is made with the input feature x and then passes through the ReLU activation function to output the final feature out.
[0040] Figure 3 The formula of the residual block is as follows:
[0041] H(X)=F(X)+X, that is, F(X)=H(X)-x (1)
[0042] Among them, H(X) is the predicted value and F(X) is the residual, so we can get
[0043]
[0044] Among them, x L represents the input of the Lth layer, F(x i ,w i ) is the residual of the i-th layer. The whole formula indicates that any deep residual unit L can be represented by the residual sum of the shallow layers n to L.
[0045] As the network deepens, the information obtained by the network will decrease layer by layer. By using residual block processing, the next layer not only includes the information x of the layer, but also the new information F(x) after nonlinear transformation of the layer, which can avoid information loss.
[0046] Using dynamic convolution instead of traditional static convolution and dynamically superimposing multiple convolution kernels according to attention not only significantly improves the expressive power, but also consumes very little additional computational cost. In addition, dynamic convolution can increase the expressive power of the model without increasing the depth or width of the network, and adaptively adjust the convolution parameters according to the input image.
[0047] Compared with static convolution, which uses the same convolution kernel to perform the same operation on all input images, dynamic convolution adjusts different images and processes them with more suitable convolution parameters to improve the performance of the network.
[0048] like Figure 4 , the global spatial information in the dynamic convolution layer is first compressed by global average pooling; then, two fully connected layers are used, with a ReLU between them and a second fully connected layer followed by softmax to generate the normalized attention weights of the K convolution kernels; W and b are the weight matrix and bias vector, {A1…A K} is the attention weight, which changes as the input x changes.
[0049] Dynamic convolution has K convolution kernels that share the same kernel size and input / output dimensions and is trained by using attention weights {A k} for aggregation:
[0050]
[0051] Among them, W k is the kth weight matrix, b k is the kth variation vector.
[0052] By dynamically adjusting the convolution kernel, we can better capture the local and global features in the data, thereby improving the expressiveness of the features.
[0053] like Figure 5 For the coordinate attention module, a coordinate attention mechanism is introduced after each residual stage to embed the position information into the channel attention, so that the lightweight network can pay attention to a larger area, while avoiding a large amount of computational overhead and alleviating the loss of position information caused by 2D global pooling. By decomposing the channel attention into two parallel 1D feature encodings, the spatial coordinate information is effectively integrated into the generated attention map.
[0054] The coordinate attention mechanism utilizes two one-dimensional global average pooling operations to aggregate the input features in the vertical and horizontal directions into two independent direction-aware feature maps respectively; then, the two feature maps embedded with specific direction information are encoded into two attention maps respectively, each of which captures the long-range dependency of the input feature map along a spatial direction; the position information is stored in the attention map, and the two attention maps are then multiplied to the input feature map to enhance the representation capability of the feature map.
[0055] XAvg Pool and YAvg Pool perform average pooling in the W and H directions respectively, then perform concat operation on the two multi-channel vectors in the spatial dimension, and use 1×1 convolution to compress the number of channels;
[0056] Then, BN and Non-linear are used to encode the spatial information in the vertical and horizontal directions, and then split separation is performed to re-divide the complete feature vector into vectors in two directions: the number of channels of the feature vectors in the two directions is readjusted through 1×1 convolution, and then the features are transformed through the Sigmoid function to make their dimensions consistent with the input; finally, they are merged with the original input information in two directions and output.
[0057] By introducing the coordinate attention mechanism after each stage, we can better focus on the importance of different areas in the image. The coordinate attention mechanism can adaptively adjust the attention weights according to the spatial position information of different areas in the image.
[0058] For the horse face recognition task, the horse face may appear in different positions of the image. Some positions may contain more useful feature information, while some positions may be less important. The coordinate attention mechanism is introduced to enhance the extraction of key features in the image. By dynamically adjusting the attention weights, the model can more effectively capture the features related to the horse face in the image, such as the outline, eyes, nose, etc. of the horse face, thereby improving the recognition accuracy. The introduction of the coordinate attention mechanism can enable the model to more intelligently utilize the spatial structure information in the image, thereby improving the accuracy and generalization ability of the horse face recognition task.
[0059] Experimental process:
[0060] Get the input image images and the corresponding labels labels, reset the optimizer's gradient to zero, input the input image into the DYCCARN model, get the predicted value logits; calculate the cross entropy loss, back-propagate and update the model parameters.
[0061] Calculate the training accuracy and add it to acc, calculate the training loss and add it to running_loss, update the progress bar display, calculate the average training loss for each epoch and add it to the train_loss list.
[0062] Verify on the validation set, traverse the validation set data, and perform the following operations: obtain the validation image val_images and the corresponding label val_labels, input the image into the DYCCARN model, obtain the predicted value outputs, calculate the cross entropy loss, calculate the validation accuracy and accumulate it to acc, calculate the validation loss and accumulate it to running_loss, update the progress bar display, calculate the average validation loss for each epoch and add it to the val_loss_list list.
[0063] If the current validation accuracy exceeds the best accuracy recorded previously, the current model parameters are saved, and an early stopping mechanism is added. By comparing the current validation loss with the historical best validation loss, if the validation loss does not decrease for three consecutive rounds, training is stopped.
[0064] Using the THoDBRL2015 database, the traditional resnet model and the DYCCARN model of the present invention are used to train the horse data. Figure 6 and Figure 7 They are the accuracy and loss curves for training and verification respectively; Figure 6 It can be seen that as the epoch increases, the ACC curve shows an upward trend, because there are more features that can be learned at the beginning, and they gradually become more complicated after subsequent iterations, so the image is steep at first and then becomes flat.
[0065] Figure 7 As the number of epochs increases, the loss gradually decreases and finally tends to be flat. The accuracy and loss of the training set and the test set eventually tend to be stable, and finally a better prediction effect can be achieved, which meets the model requirements.
[0066] Table 1 Comparison between the model of the present invention and Resnet
[0067]
[0068] The DYCCARN model showed higher accuracy than ResNet. The first accuracy of DYCCARN reached 99.63%, which was much higher than ResNet's 90.8%. After further training, the accuracy of the ResNet model reached 96.0%, while the accuracy of DYCCARN remained at 99.3%, which showed that DYCCARN had better performance and accuracy than ResNet in the horse face recognition task.
[0069] Based on the above ideal embodiments of the present invention, the relevant staff can make various changes and modifications without departing from the technical concept of the present invention through the above description. The technical scope of the present invention is not limited to the contents of the specification, and its technical scope must be determined according to the scope of the claims.
Claims
1. A horse face recognition method based on a dynamic convolutional residual deep learning network, characterized in that: The following steps are involved: Step 1: Collect horse face images, pre-process the images and divide the data sets; Step 2: Construct the DYCCARN network, which includes a 7×7 convolutional layer, a 3×3 maximum pooling layer, four residual stages containing several residual blocks, a global average pooling layer, a fully connected layer, and a Softmax activation function. Step 3: Input the horse face image into the DYCCARN network to obtain the predicted value, calculate the cross entropy loss, back propagate and update the model parameters.
2. The horse face recognition method based on dynamic convolution residual deep learning network according to claim 1 is characterized in that: The number of residual blocks in the four residual stages are 3, 4, 6 and 3 respectively. The first residual block in each residual stage is downsampled with a stride of 2; the stride of the remaining residual blocks is 1; the coordinate attention module is introduced at the end of each residual stage.
3. The horse face recognition method based on dynamic convolution residual deep learning network according to claim 2 is characterized in that: The residual block consists of: The image features are input into conv11×1, then passed through the batch normalization layer and ReLU activation function, then passed through the 3×3 dynamic convolution layer, batch normalization layer and ReLU activation function; then passed through the convolution layer conv11×1, batch normalization layer and ReLU activation function; after residual connection with the input image features, it passes through the ReLU activation function.
4. The horse face recognition method based on dynamic convolution residual deep learning network according to claim 3 is characterized in that: The global spatial information in the dynamic convolutional layer is first compressed by global average pooling; then, two fully connected layers are used, with a ReLU between the fully connected layers and the second fully connected layer followed by softmax to generate the normalized attention weights of K convolution kernels.
5. The horse face recognition method based on dynamic convolution residual deep learning network according to claim 2, characterized in that: The coordinate attention module decomposes the channel attention into two parallel 1D feature encodings and integrates the spatial coordinate information into the attention map.
6. The horse face recognition method based on dynamic convolution residual deep learning network according to claim 1, characterized in that: Preprocessing includes: Random cropping, image to tensor conversion and normalization.
7. Horse face recognition system based on dynamic convolution residual deep learning network, characterized by: include: a memory for storing instructions executable by a processor; A processor, configured to execute instructions to implement the horse face recognition method based on a dynamic convolutional residual deep learning network as described in any one of claims 1 to 6.
8. A computer readable medium storing a computer program code, characterized in that: When the computer program code is executed by a processor, the horse face recognition method based on the dynamic convolution residual deep learning network as described in any one of claims 1 to 6 is implemented.
Citation Information
Cited By
Concrete crack identification method and device based on dynamic convolution
CN119169435A
Illumination condition adaptive soil humidity estimation method based on multi-modal data fusion
CN119513523A
A light condition adaptive soil moisture estimation method based on multi-modal data fusion
CN119513523B
