A method for recognizing a cow face by improving illumination and camera differences
By using the Style-ResNet model and the Style-Loss loss function, the performance degradation of cow face recognition caused by differences in lighting and camera is solved, and efficient recognition is achieved in complex environments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU DIANZI UNIV
- Filing Date
- 2023-01-21
- Publication Date
- 2026-04-28
AI Technical Summary
Existing cow face recognition algorithms suffer from significant performance degradation in pastures due to differences in lighting and camera settings. Current technologies struggle to effectively remove style differences while preserving category information.
The Style-ResNet model is adopted. By constructing the feature normalization module Style-Block and the style normalization residual block Style-Resnet-Block, and combining the self-attention mechanism and the Style-Loss loss function, the recognition features are recovered and the category and style information are distinguished.
It improves the generalization ability of the cow face recognition algorithm in complex scenarios and enhances the model's recognition performance in environments with varying lighting and camera conditions.
Smart Images

Figure CN116012887B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of biometrics, specifically to a cow face recognition algorithm that improves upon differences in lighting and camera capabilities. Background Technology
[0002] my country's livestock farming is developing towards large-scale, information-based, and refined operations, with intensive cattle farming gradually replacing small-scale farming models.
[0003] To achieve refined management of cattle herds, it is essential to track and monitor the health status and movement patterns of each cow, with individual cow identification being crucial. Traditional methods of individual cow identification primarily involve physically marking specific parts of the cow's body or embedding microchips into the cow's body.
[0004] With the rapid development of neural networks, cow face recognition technology based on Convolutional Neural Networks (CNNs) has become increasingly mature. Some studies utilize features extracted by CNNs to construct sparse representation classification models, calculate residuals for each category, and identify individual cows based on the principle of minimizing residuals. However, current cow face recognition algorithms use the same segmented dataset for both training and testing. In real-world pastures, complex lighting environments and differences in camera sensors lead to variations in image data distribution, significantly weakening the model's generalization ability and reducing the recognition performance of existing cow face recognition algorithms in practical applications. Considering data bias caused by style factors such as lighting and camera sensors, some studies use style transfer to remove style differences between datasets, applying Instance Normalization (IN) to normalize each sample and each channel, reducing style differences between samples and improving the model's generalization ability. However, independently normalizing each sample inevitably results in the loss of some common and category information between samples, which significantly impacts the recognition performance of cow face recognition algorithms. Some studies have designed modality mitigation modules that use channel attention mechanisms and cross-means learning to guide instance normalization, effectively preserving image content information while mitigating the impact of style factors such as lighting and camera on recognition. However, this algorithm is susceptible to pseudo-label noise when using cross-means learning to guide network training, affecting the model's final performance. To avoid information loss, some studies have proposed Batch-Instance Normalization (BIN), adding a learnable parameter to each channel of the feature map. When extracting features, the model uses this parameter to determine the relevance of each feature map's information to the recognition task, deciding whether to use Batch Normalization (BN) or Inversion (IN). This improves model generalization while preserving recognition-related information. However, this algorithm only uses IN to remove style differences for features highly relevant to the recognition task, while still using BN for features with low relevance. Therefore, this algorithm cannot completely eliminate the influence of image style information on recognition. Furthermore, the lack of constraints on style and recognition information during training results in a low ability to distinguish between style and recognition information. Summary of the Invention
[0005] This addresses the technical problem that differences in lighting conditions and camera angles in pasture environments cause a significant drop in the algorithm's recognition performance in new environments.
[0006] This invention provides an improved method for cow face recognition based on differences in lighting and camera conditions, comprising the following steps:
[0007] S1 collects cow face data:
[0008] Under several different lighting conditions, cow face videos were captured using several different cameras. Cow face images were extracted from the cow face videos and classified, numbered, and filtered to construct the COWYCTC-868 dataset. The COWYCTC-868 dataset was then divided into a training set and a validation set.
[0009] S2 Style-ResNet Model Construction and Data Training
[0010] S2.1 Constructing the Feature Normalization Module Style-Block
[0011] In style-block, the feature F containing style information is first normalized through instance normalization to obtain the style-normalized feature that does not contain style information, as shown in the following formula.
[0012]
[0013] In the formula, μ and σ are the mean and variance of the cow face image features in each channel, and γ and β are the learnable parameters in instance normalization; then, the features F containing style information and the style-normalized features without style information are used. Calculate the residual features R, which contain instance-normalized information about lost cow face images, using the method shown in the following formula:
[0014]
[0015] The residual feature R∈R c×h× w, where w is a three-dimensional array of c×h×w, and the residual feature R contains category-related recognition features. And style features resulting from differences in lighting and camera. Where c, h, and w represent the number of channels, height, and width of the feature; in the channel dimension of the residual feature R, the relationship vector V between the residual feature R and the recognition task is obtained using a self-attention mechanism as shown in the following formula:
[0016] V=Sigmoid(Conv(ReLu(Conv(pool(R)))))
[0017] In the formula, the relation vector V = [V0, V1, ..., V...]. c-1 [Sigmoid is the activation function, pool is the global average pooling layer, ReLU is the activation function, and Conv is the convolutional layer; using the relation vector V, the category-related recognition features R in the residual features R are calculated according to the following formula.] + and style information features R - :
[0018] R + (k,:,:)=V k R(k,:,:)
[0019] R - (k,:,:)=(1-V k R(k,:,:)
[0020] in V is the feature of the k-th channel of feature R. k The value of the k-th dimension of the relation vector V is used to finally recover the recognition feature R. + and instance normalized features Adding them together yields the final output feature that contains only category information.
[0021]
[0022] Style features R- extracted from residual features R and instance normalized features are used to extract style-block from residual features R. Adding them together yields the final output feature containing style information.
[0023]
[0024] The style information is generated by differences in lighting conditions at the cattle farm and differences in camera footage;
[0025] S2.2 Constructing Style-ResNet-Block Residual Blocks
[0026] The main framework of the style normalization residual block is in the form of a residual block;
[0027] The input to the style normalization residual block is the normalized image features. The normalized image features It is obtained by passing the input image through a 3×3 convolutional layer and a max pooling layer;
[0028] The normalized image features The result obtained by performing several convolutional normalization and Mish activation function processes is compared with the normalized image features. The summation, followed by processing through the Mish activation function, is then input into the Style-Block feature normalization module, which outputs features containing only category information.
[0029] S2.3 Constructing the Style-ResNet Model
[0030] The input to the Style-ResNet model is the cow face image described in step S1. The Style-ResNet model includes a convolutional layer Cony, followed by a max pooling layer MaxPooling, then several style-normalized residual blocks Style-ResNet-Block, and finally an average pooling layer AvgPooling.
[0031] S2.4Style-ResNet Model Training
[0032] Construct a Style-Loss loss function, which includes a category information loss function and a style information loss function;
[0033] The definition of the category information loss function is shown in the following equation:
[0034]
[0035] In the formula, For a training batch, the characteristics of this type of cow are... The final recognition features are obtained after average pooling. Characteristics of this type of cattle The final recognition features are obtained after average pooling. For this category, other categories of cattle The final recognition features are obtained after average pooling. Other types of cattle The final recognition features are obtained after average pooling. express and The distance between them; when calculating the loss of the category information portion, It only contains category information, so and Those who belong to the same category should be as close as possible to each other, and It contains both style information and category information. and The distance should approach the median value. and The distance between them is less than and The distance between them; for samples of different categories. and The distance between them is also less than and The distance between them;
[0036] During training, similar samples and The distance between them is greater than and Distance between different classes of samples and The distance between them is less than and The distance between them;
[0037] The Style-Loss loss function is the sum of the category information loss function and the style information loss function, as shown in the following formula:
[0038]
[0039] The overall loss function is constructed as follows:
[0040]
[0041] In the formula, L softmax The cross-entropy loss is used for class constraints, where λ is the L value corresponding to each level of network block. style The regularization coefficient;
[0042] Input the training set described in step S1, and train the Style-ResNet model using the overall loss function to obtain the trained Style-ResNet model;
[0043] S3. Input the cow face data to be identified into the Style-Resnet model that has been trained in step S2.4, identify the cow face data to be identified, and output the recognition result.
[0044] Preferably, in step S1, the cow face images in the COWYCTC-868 dataset are...
[0045] Where C, H, and W represent the number of channels, height, and width of the input image, respectively.
[0046] Preferably, in step S2.2, the number of times is 3.
[0047] Preferably, in step S2.3, the specific number of Style-Resnet-Blocks is 4.
[0048] Preferably, in step S1, the COWYCTC-868 dataset contains 868 classes of cow face images from different cameras and under different lighting conditions, wherein each class of cow face images includes 45 images of each cow.
[0049] Preferably, in step S1, the cow face images in the training set are augmented with data, and the data augmentation method includes rotating, translating, scaling, and changing the brightness of the cow face images.
[0050] This invention proposes a feature normalization module, style-block, and a Style-ResNet cow face recognition algorithm. Based on the ResNet model, this invention designs a novel feature normalization method for complex cattle farm environments. style-block calculates residual features using batch-normalized features and style-normalized features, and recovers the recognition features lost during instance normalization from the residual features through a self-attention mechanism. Furthermore, it proposes a Style-Loss loss function, which narrows the gap between style-normalized features and recognition features while widening the gap between style-normalized features and segmentation features, enhancing the model's ability to distinguish between category-related features and style features, and improving the generalization ability of the cow face recognition algorithm in complex scenarios. Attached Figure Description
[0051] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the accompanying drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Some specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings in an exemplary and non-limiting manner. The same reference numerals in the drawings indicate the same or similar parts or components. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. In the drawings:
[0052] Figure 1 This is a diagram of the Style-block module structure.
[0053] Figure 2 This is a diagram of the residual block structure for style normalization.
[0054] Figure 3 This is a diagram of the Style-ResNet network framework.
[0055] Figure 4 This is the ROC curve of a normal image.
[0056] Figure 5 This is the ROC curve of a normal image.
[0057] Figure 6 This is a ROC curve for camera differences. Detailed Implementation
[0058] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. The technical solution adopted by this invention is as follows:
[0059] S1 collects cow face data:
[0060] The diverse activity states and postures of cattle in a cattle farm environment make it difficult to directly capture high-quality cattle face images. Therefore, the laboratory created the COWYCTC-868 dataset by first capturing cattle face videos and then extracting images frame by frame. To improve the generalization ability of the cattle face recognition model in cattle farm lighting scenarios, videos were captured under different lighting conditions and camera settings. Finally, cattle face images were extracted from the videos and then classified, numbered, and filtered. The COWYCTC-868 dataset contains 868 classes of cattle face images from different cameras and under different lighting conditions. Each cow has 45 images.
[0061] During training, the first 764 classes of the COWYCTC-868 dataset were used as the training set. These 764 classes of cow face images were then augmented 20 times through rotation, translation, scaling, and brightness transformation, resulting in a training set of 764 × 45 × 20 = 687,600 images. The remaining 104 classes of cow images were used as the validation set, containing 104 × 45 = 4,680 images. The validation set included 58 special image classes, comprising 1,632 images with lighting differences and 1,428 images with camera differences. The remaining 46 classes of cow images were normal images taken under the same low-light conditions and with the same camera.
[0062] S2 Style-ResNet Model Construction and Data Training
[0063] S2.1.1 Style-Block Feature Normalization Module
[0064] While Instantaneous Image Processing (IN) can eliminate stylistic features of images, thus improving the model's domain generalization performance, it also loses some category-related recognition features, reducing the model's recognition rate. Therefore, this paper proposes a Style-Block feature normalization module. This module removes image style information using instance normalization while simultaneously applying the output feature F and style-normalized features. The feature R that is lost due to instance normalization is obtained, and the network learns the correlation between the residual R and the recognition task through the self-attention mechanism to recover the category-related recognition information lost due to instance normalization.
[0065] exist Figure 1 In the style-block, the unnormalized feature F containing style information is first normalized through instance normalization to obtain the style-normalized feature that does not contain style information.
[0066]
[0067] In the formula, μ and σ represent the mean and variance of the cow face image features in each channel, and γ and β are learnable parameters in instance normalization. Then, F and... Calculate the residual features R∈R that contain instance-normalized cow face image content information that has been lost. c×h×w The feature is a three-dimensional array of size c × h × w, where c, h, and w represent the number of channels, height, and width of the feature, respectively.
[0068]
[0069] The residual feature R simultaneously includes both category-related identification features. And style features resulting from differences in lighting and camera. This paper employs a self-attention mechanism along the channel dimension of the residual feature R to obtain the relationship vector V = [V0, V1, ..., V1] between the residual feature and the recognition task. c-1 ]:
[0070] V=Sigmoid(Conv(Re Lu(Conv(pool(R)))))
[0071] In the formula, Sigmoid is the activation function, pool is the global average pooling layer, ReLU is the activation function, and Conv is the convolutional layer. Using the relation vector V, the category-related recognition feature R+ and style-related feature R in the residual feature R can be calculated:
[0072] R + (k,:,:)=V k R(k,:,:)
[0073] R - (k,:,:)=(1-V k R(k,:,:)
[0074] in V is the feature of the k-th channel of feature R. k The value of the k-th dimension of the relation vector V is used to finally recover the recognition feature R. + and instance normalized features Adding them together yields the final output feature that contains only category information.
[0075]
[0076] Style features R extracted from residual features R by style-block - and instance normalized features Adding them together yields the final output feature containing style information.
[0077]
[0078] S2.1.2 Style-Resnet-Block
[0079] Style normalization residual blocks, such as Figure 2 As shown, its main framework uses residual blocks. First, the input image is passed through a 3×3 convolutional layer and a max pooling layer to obtain the input features of the residual blocks. The result of re-normalizing the residual block of the Mish activation function through multiple convolutions is then compared with... The summation, followed by an activation function, and then the Style-Block output features containing only class information.
[0080] S2.1.3 Style-ResNet Overall Framework
[0081] like Figure 3 As shown, the backbone of Style-ResNet consists of multiple Style-ResNet-Blocks. After passing through multiple residual blocks, the batch-normalized features are subtracted from the instance-normalized features to obtain residual features containing information lost during instance-normalization. A self-attention mechanism is used to learn the correlation between the residual features and the recognition task, and the correlation is used to recover and recognize relevant information from the residual features.
[0082] S2.2Style-ResNet model training
[0083] After building the Style-ResNet model based on Style-block, we need to input the image into the model for training. In S1, we obtain the input image of the cow. C, H, and W represent the number of channels and the height and width of the input image, respectively. When extracting features, Style-ResNet first passes the input image X through a 3×3 convolutional layer and a max-pooling layer to obtain the input features of the residual blocks. In the residual block, Forward computation yields a feature F that simultaneously contains category information and style information resulting from differences in lighting and camera. Next, F is input to instance normalization to obtain style-normalized features that have had style information removed but have lost some image content information. Then F and The residual features R, which include information lost in instance normalization, are obtained by subtraction. R is then input into the feature normalization module style-block designed in this paper to obtain the correlation between R and the recognition task in the channel dimension. The image information lost in instance normalization is recovered through the correlation to obtain features containing only category information.
[0084] This paper proposes a Style-Loss loss function to guide model training, enabling the algorithm to better distinguish between category-related and style-related information. In style-block... A feature map that contains only category information. This is a feature map that includes style information resulting from differences in lighting conditions at the cattle farm and camera angles. The data contains both category and style information. Therefore, this paper proposes a Style-Loss loss-supervised network training method to bridge the gap between category and style information. and Increase the distance between them and The distance between them improves the model's ability to distinguish between recognition features and style features. Style-Loss loss consists of two parts: category information constraint and style information constraint.
[0085] The loss function that includes category information is:
[0086]
[0087] In the formula, For a training batch, the characteristics of this type of cow are... The final recognition features are obtained after average pooling. Characteristics of this type of cattle The final recognition features are obtained after average pooling. For this category, other categories of cattle The final recognition features are obtained after average pooling. Other types of cattle The final recognition features are obtained after average pooling. express and The distance between them. When calculating the loss for the category information portion, because... It only contains category information, so and Those who belong to the same category should be as close as possible to each other, and It contains both style information and category information. and The distance should approach the median value, so finally... and The distance between them is less than and The distance between them. Similarly, for samples of different categories. and The distance between them should also be less than and The distance between them.
[0088] The loss function for the style information part is:
[0089]
[0090] For feature blocks containing style information, since these feature blocks do not contain features related to category information, it is desirable to train similar samples... and The distance between them is greater than and Distance between different classes of samples and The distance between them is less than and The distance between them.
[0091] The final Style-Loss is:
[0092]
[0093] By incorporating Style-Loss during network training, the learned R can be effectively guaranteed. + R contains only category information. - Some sections only contain style information generated by cattle farm lighting and cameras. This improves the network's ability to distinguish between category-related and style-related information, making it easier for the model to recover image information lost during instance normalization during training and enhancing the model's classification ability.
[0094] The overall loss function of the model during training is:
[0095]
[0096] In the formula, L softmax The cross-entropy loss is a category-constrained loss, where λ is the L value corresponding to each level of network block. style The regularization coefficient.
[0097] S3 Simulation Results Analysis
[0098] 3.1 Dataset
[0099] Since there is no publicly available dataset of cow face images, this paper uses the COWYCTC-868 dataset, consisting of 868 cows collected from 5 cattle farms in the laboratory, to evaluate the algorithm presented in this paper.
[0100] The diverse activity states and postures of cattle in a cattle farm environment make it difficult to directly capture high-quality cattle face images. Therefore, the laboratory created the COWYCTC-868 dataset by first capturing cattle face videos and then extracting images frame by frame. To improve the generalization ability of the cattle face recognition model in cattle farm lighting scenarios, videos were captured under different lighting conditions and camera settings. Finally, cattle face images were extracted from the videos and then classified, numbered, and filtered. The COWYCTC-868 dataset contains 868 classes of cattle face images from different cameras and under different lighting conditions. Each cow has 45 images.
[0101] During training, the first 764 classes of the COWYCTC-868 dataset were used as the training set. These 764 classes of cow face images were then augmented 20 times through rotation, translation, scaling, and brightness transformation, resulting in a training set of 764 × 45 × 20 = 687,600 images. The remaining 104 classes of cow images were used as the validation set, containing 104 × 45 = 4,680 images. The validation set included 58 special image classes, comprising 1,632 images with lighting differences and 1,428 images with camera differences. The remaining 46 classes of cow images were normal images taken under the same low-light conditions and with the same camera.
[0102] 3.2 Experimental Environment and Parameter Settings
[0103] The experimental server used an NVIDIA TITAN RTX 3090 GPU, and the deep learning framework used was PyTorch. The input images were 3-channel cow face images with a resolution of [resolution value missing]. During training, data augmentation techniques such as random cropping, random horizontal flipping, and random erasure were used. The training batch size was 64 images, containing 4 cow face images from 16 cows. The loss function was optimized using an Adaptive Moment Estimation (ADAM) optimizer, with a learning rate of [learning rate missing] and a weight decay coefficient of 1e-6. The loss function weight λ was 0.2.
[0104] 3.3 Model Performance Evaluation Indicators
[0105] This paper uses ROC and Top-1 ranking to compare model performance. Recognition rate is compared using ROC curves, with the horizontal axis representing the False Acceptance Rate (FAR) and the vertical axis representing the False Rejection Rate (FRR). The false acceptance rate is the proportion of cow face images of different categories that are classified as cow faces of the same category in a 1:1 match; the false rejection rate is the proportion of cow face images of the same category that are classified as cow faces of different categories in a 1:1 match. Zero false rejection rate is the rejection rate when the false acceptance rate is 0.
[0106] Top-1 ranking performance was compared by statistically analyzing the success rate of Top-1 ranking: The first cow face image in the same category was selected as the template, and the remaining images in the same category were used as verification images. The verification images were compared with the template and the images outside the category, and the proportion of the template image ranking first was calculated.
[0107] This paper also visualizes the cow face features extracted by the model. From the visualized feature map, we can intuitively see the model's focus on the image and whether the model has learned the features of the cow face region.
[0108] 3.4 Recognition Performance
[0109] The proposed Style-ResNet cow face recognition algorithm was compared with and without Style-Loss loss constraints, along with other proposed ResNet-IBN, ResNet-50, ResNet-MAM, and ResNet-BIN recognition algorithms, on normal images, lighting differences, and camera differences test sets in the COWYCTC-868 image library.
[0110] 3.4.1 Top 1 sorting
[0111] Table 1 shows the Top-1 performance of the six algorithms on different datasets.
[0112] Table 1. Top-1 performance comparison of different algorithms on different poses of the cow face dataset. Unit: %
[0113]
[0114] As shown in Table 1, the Style-ResNet cow face recognition algorithm proposed in this paper effectively improves the Top-1 ranking success rate. In a special image database with differences in lighting and camera performance, it improves the success rate by 0.65% and 1.78% respectively compared to the ResNet-IBN recognition algorithm proposed by Hyeonseob Nam; after adding the Style-Loss loss function constraint, the success rates are improved by 2.29% and 2.01% respectively.
[0115] 3.4.2 Recognition Rate
[0116] Six algorithms were used to extract features from normal images, lighting differences, and camera differences in the COWYCTC-868 image library, and ROC curves of the recognition performance were obtained through simulation calculations.
[0117] from Figure 4 As shown in Figures 5 and 6, for the test image database with normal images, lighting differences, and camera differences, when the FAR is 0, the proposed Style-ResNet+Style-Loss loss-constrained cow face recognition algorithm has the lowest FRR. Compared with the ResNet-IBN recognition algorithm, it reduces FRR by 4.68%, 6.88%, and 2.96%, respectively; compared with Style-ResNet without Style-Loss constraints, it reduces FRR by 1.08%, 3.6%, 1.78%, and 4.1%, respectively.
[0118] To address the impact of lighting and camera variations in real-world cattle farms on model deployment, this invention proposes a Style-ResNet cattle face recognition algorithm. This algorithm ensures that the extracted features retain only category-related information, removing style information caused by differences in lighting and camera settings. Simultaneously, a Style-Loss loss function constraint model is proposed to narrow the gap between instance-normalized features and recognition features, while widening the gap between instance-normalized features and style features, effectively improving the algorithm's recognition performance in different cattle farm scenarios.
[0119] The above description is only a part of the specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the protection scope of the present invention.
Claims
1. A method for improving cow face recognition based on differences in lighting and camera illumination, characterized in that, Includes the following steps: S1 collects cow face data: Under several different lighting conditions, cow face videos were captured using several different cameras. Cow face images were extracted from the cow face videos and classified, numbered, and filtered to construct the COWYCTC-868 dataset. The COWYCTC-868 dataset was then divided into a training set and a validation set. S2 Style-ResNet Model Construction and Data Training S2.1 Constructing the Feature Normalization Module Style-Block In style-block, the feature F containing style information is first normalized through instance normalization to obtain the style-normalized feature that does not contain style information, as shown in the following formula. In the formula, μ and σ are the mean and variance of the cow face image features in each channel, and γ and β are the learnable parameters in instance normalization; then, the features F containing style information and the style-normalized features without style information are used. Calculate the residual features R, which contain instance-normalized information about lost cow face images, using the method shown in the following formula: The residual feature R∈R c×h×w The feature is a three-dimensional array of c×h×w, and the residual feature R contains category-related recognition features. And style features resulting from differences in lighting and camera. Where c, h, and w represent the number of channels, height, and width of the feature; in the channel dimension of the residual feature R, the relationship vector V between the residual feature R and the recognition task is obtained using a self-attention mechanism as shown in the following formula: V=Sigmoid(Conv(ReLu(Conv(pool(R))))) In the formula, the relation vector V = [V0, V1, ..., V c-1 [Sigmoid is the activation function, pool is the global average pooling layer, ReLU is the activation function, and Conv is the convolutional layer; using the relation vector V, the category-related recognition features R in the residual features R are calculated according to the following formula.] + and style information features R - : R + (k,:,:)=V k R(k,:,:) R - (k,:,:)=(1-V k )R(k,:,:) in V is the feature of the k-th channel of feature R. k The value of the k-th dimension of the relation vector V is used to finally recover the recognition feature R. + and instance normalized features Adding them together yields the final output feature that contains only category information. Style features R extracted from residual features R by style-block - and instance normalized features Adding them together yields the final output feature containing style information. The style information is generated by differences in lighting conditions at the cattle farm and differences in camera footage; S2.2 Constructing Style-ResNet-Block Residual Blocks The main framework of the style normalization residual block is in the form of a residual block; The input to the style normalization residual block is the normalized image features. The normalized image features It is obtained by passing the input image through a 3×3 convolutional layer and a max pooling layer; the normalized image features are obtained by... The result obtained by performing several convolutional normalization and Mish activation function processes is compared with the normalized image features. The summation, followed by processing through the Mish activation function, is then input into the Style-Block feature normalization module, which outputs features containing only category information. S2.3 Constructing the Style-ResNet Model The input to the Style-Resnet model is the cow face image mentioned in step S1. The Style-Resnet model includes a convolutional layer Conv, followed by a max pooling layer MaxPooling, then several style-normalized residual blocks Style-Resnet-Block, and finally an average pooling layer AvgPooling. S2.4 Style-ResNet Model Training Construct a Style-Loss loss function, which includes a category information loss function and a style information loss function; The definition of the category information loss function is shown in the following equation: In the formula, For a training batch, the characteristics of this type of cow are... The final recognition features are obtained after average pooling. Characteristics of this type of cattle The final recognition features are obtained after average pooling. For this category, other categories of cattle The final recognition features are obtained after average pooling. Other types of cattle The final recognition features are obtained after average pooling. express and The distance between them; when calculating the loss of the category information portion, It only contains category information, so and Those who belong to the same category should be as close as possible to each other, and It contains both style information and category information. and The distance should approach the median value. and The distance between them is less than and The distance between them; for samples of different categories. and The distance between them is also less than and The distance between them; The style information loss function is: During training, similar samples and The distance between them is greater than and Distance between different classes of samples and The distance between them is less than and The distance between them; The Style-Loss loss function is the sum of the category information loss function and the style information loss function, as shown in the following formula: The overall loss function is constructed as follows: In the formula, L softmax The cross-entropy loss is used for class constraints, where λ is the L value corresponding to each level of network block. style The regularization coefficient; Input the training set described in step S1, and train the Style-ResNet model using the overall loss function to obtain the trained Style-ResNet model; S3. Input the cow face data to be identified into the Style-Resnet model that has been trained in step S2.4, identify the cow face data to be identified, and output the recognition result.
2. The improved cow face recognition method based on differences in lighting and camera as described in claim 1, characterized in that, In step S1, the cow face images in the COWYCTC-868 dataset are Where C, H, and W represent the number of channels, height, and width of the input image, respectively.
3. The improved cow face recognition method based on differences in lighting and camera as described in claim 1, characterized in that, In step S2.2, the number of times is specifically 3 times.
4. The improved cow face recognition method based on differences in lighting and camera as described in claim 3, characterized in that, In step S2.3, the specific number of Style-Resnet-Blocks is 4.
5. The improved cow face recognition method based on differences in lighting and camera as described in claim 2, characterized in that, In step S1, the COWYCTC-868 dataset contains 868 classes of cow face images from different cameras and under different lighting conditions, wherein each class of cow face images includes 45 images of each cow.
6. The improved cow face recognition method based on differences in lighting and camera as described in claim 1, characterized in that, In step S1, the cow face images in the training set are augmented with data. The augmentation methods include rotating, translating, scaling, and changing the brightness of the cow face images.