A cow face detection method and detection system in complex scenes

By designing adaptive evaluation indicators and introducing CDAA attention mechanism to optimize the YOLOV7-tiny network, the accuracy and robustness of cow face detection in complex scenarios are solved, and the efficient cow face detection effect is achieved.

CN117152790BActive Publication Date: 2025-08-19INNER MONGOLIA UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310773782.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-28
Publication Date
2025-08-19
Estimated Expiration
2043-06-28

AI Technical Summary

Technical Problem

The existing bull face detection algorithms have low detection accuracy and poor robustness in complex scenarios, especially in backlight, occlusion and blur environments, and cannot meet the real-time monitoring needs.

Method used

The evaluation index of ambiguity, backlightness and occlusion rate was designed, the adaptive weight coefficient was determined through the normalization of the fuzzy membership function, the CDAA attention mechanism of the YOLOV7-tiny network was introduced, the channel and spatial attention parallel structure was designed, and the loss function was optimized to improve detection accuracy.

Benefits of technology

The accuracy and robustness of cow face detection in complex scenarios has been improved, especially under blur, backlight and occlusion conditions, the detection effect of small-target cow faces has been significantly improved, with the detection accuracy reaching 89.58%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117152790B_ABST
    Figure CN117152790B_ABST
Patent Text Reader

Abstract

The present invention provides a method and system for detecting cow faces in complex scenes. The method comprises the following steps: designing a blur evaluation index, a backlight evaluation index, and an occlusion rate evaluation index, normalizing the three evaluation indexes using a fuzzy membership function, and determining an adaptive weight coefficient; introducing an attention mechanism CDAA into a backbone feature extraction network based on YOLO V7-tiny, designing a parallel channel and spatial attention structure, and integrating the adaptive weight coefficient; and optimizing the YOLO V7-tiny loss function using the adaptive weight coefficient. The method can effectively address common interferences such as backlighting, occlusion, and blur.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of livestock monitoring, and in particular to a cow face detection method and a detection system for complex scenes. Background Art

[0002] In recent years, deep learning-based object detection technology has become a research hotspot in the field of computer vision, finding widespread application in areas such as daily safety, robot navigation, autonomous driving, intelligent video surveillance, traffic scene detection, and aerospace. Object detection algorithms have shown initial success in real-time livestock monitoring, significantly driving the rapid development of smart animal husbandry. Accurate livestock detection and identification can guarantee intelligent management and facilitate the integration of the unmanned ecological farming model into the growing agricultural sector.

[0003] Currently, cow face detection is a key step in achieving intelligent livestock husbandry on cattle farms, and its accuracy directly impacts the effectiveness of real-time monitoring. Traditional target detection algorithms extract target features through feature operators, with Scale-Invariant Feature Transform (SIFT) and Histogram of Oriented Gradient (HOG) being the most representative. These algorithms suffer from certain limitations in detection accuracy and speed, and cannot meet the requirements of real-time monitoring. With the continuous development of deep learning, two-stage detection algorithms such as RCNN and Fast-RCNN, and one-stage detection algorithms such as YOLO and SSD, have achieved impressive results in terms of detection accuracy and speed. Livestock target detection and recognition algorithms based on deep learning have broad application prospects, especially with the introduction of attention mechanisms, which can achieve better results. However, current detection algorithms are not ideal for detecting cow faces in complex environments. For example, during the detection process, the light at different times causes backlighting, the non-stationary state of the cow causes blur, and the farm's railings block the view. These factors are very unfavorable for cow face detection. The currently proposed method cannot take all of these factors into account and effectively solve application problems in different scenarios.

[0004] In view of this, the present invention is proposed. Summary of the Invention

[0005] In view of this, the present invention discloses a cow face detection method in complex scenes. Based on the lightweight deep network YOLOV7-tiny, a cow face detection algorithm based on a dual-branch adaptive attention mechanism in complex scenes is proposed. The algorithm can effectively target common interferences such as backlighting, occlusion and blur.

[0006] Specifically, the present invention is achieved through the following technical solutions:

[0007] In a first aspect, the present invention discloses a method for detecting cow faces in complex scenes, comprising the following steps:

[0008] The fuzziness evaluation index, backlighting evaluation index and occlusion rate evaluation index are designed, and the three evaluation indexes are normalized by fuzzy membership function to determine the adaptive weight coefficient.

[0009] Based on YOLOV7-tiny, the attention mechanism CDAA is introduced into the backbone feature extraction network, the channel and spatial attention parallel structure is designed, and the adaptive weight coefficient is integrated;

[0010] The adaptive weight coefficient is used to optimize the YOLOV7-tiny loss function.

[0011] In a second aspect, the present invention discloses a cow face detection system for complex scenes, comprising:

[0012] Design module: used to design the fuzziness evaluation index, backlighting evaluation index and occlusion rate evaluation index, and normalize the three evaluation indexes through the fuzzy membership function to determine the adaptive weight coefficient;

[0013] Fusion module: used to introduce the attention mechanism CDAA into the backbone feature extraction network based on YOLOV7-tiny, design the channel and spatial attention parallel structure, and fuse the adaptive weight coefficients;

[0014] Optimization module: used to optimize the YOLOV7-tiny loss function using the adaptive weight coefficient.

[0015] In a third aspect, the present invention discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method for detecting cow faces in complex scenes as described in the first aspect.

[0016] In a fourth aspect, the present invention discloses a computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the method for detecting cow faces in complex scenes as described in the first aspect are implemented.

[0017] The solution of the present invention addresses the problem of low accuracy in cow face detection in complex scenes and proposes a cow face detection method in complex scenes based on a dual-branch adaptive attention mechanism. The core idea is: first, evaluation indicators are designed for the three interference factors of blur, backlighting, and occlusion, and the three different types of evaluation indicators are normalized through fuzzy membership functions, and adaptive weight coefficients are determined to truly reflect the complexity of the scene in which the target is located; then, based on YOLOV7-tiny, a new attention mechanism CDAA (Composite Dual-Branch Adaptive Attention) is introduced into the backbone feature extraction network, and a parallel structure of channel and spatial attention is designed, and adaptive weight coefficients are integrated to effectively improve the network's feature extraction ability in complex scenes and solve the problem of poor network detection accuracy in complex scenes; finally, the image scene evaluation index is introduced into the loss function, and the weight of the large-scale grid loss function is adaptively adjusted, so that the network focuses more on a large number of small targets during training, thereby improving the overall detection accuracy of the network. Compared with traditional target detection methods, this method is more accurate, more effective, and has good practical value.

[0018] In particular, a practical solution is given to the situation where cow faces in actual pastures are often severely interfered with by three common environmental factors: blur, backlighting and occlusion, which leads to low detection accuracy and poor robustness of existing lightweight algorithms. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present invention. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:

[0020] Figure 1 AA-YOLOV7-tiny network structure diagram;

[0021] Figure 2 Laplace operator;

[0022] Figure 3 Randomly occlude images;

[0023] Figure 4 CDAA attention module structure diagram;

[0024] Figure 5 Feature visualization result comparison chart;

[0025] Figure 6 Comparison test charts for different scenarios;

[0026] Figure 7 Mixed comparison test chart of various scenes;

[0027] Figure 8 Comparison test chart of different models;

[0028] Figure 9 A schematic structural diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0029] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all possible embodiments consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.

[0030] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. As used in this disclosure and the appended claims, the singular forms "a," "an," "the," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.

[0031] It should be understood that although the terms first, second, third, etc. may be used in this disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of this disclosure, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining."

[0032] The present invention provides a method for detecting cow faces in complex scenes, comprising the following steps:

[0033] The fuzziness evaluation index, backlighting evaluation index and occlusion rate evaluation index are designed, and the three evaluation indexes are normalized by fuzzy membership function to determine the adaptive weight coefficient.

[0034] Based on YOLOV7-tiny, the attention mechanism CDAA is introduced into the backbone feature extraction network, the channel and spatial attention parallel structure is designed, and the adaptive weight coefficient is integrated;

[0035] The adaptive weight coefficient is used to optimize the YOLOV7-tiny loss function.

[0036] The above detection method mainly consists of two parts: the image evaluation index design stage and the target detection stage, specifically:

[0037] A. Image evaluation index design stage:

[0038] 1) Design of fuzziness evaluation index: The fuzziness evaluation index is determined by edge detection. The image is obtained by taking the second-order derivatives of the Laplace operator in the x and y directions and then performing variance calculation to obtain the fuzziness evaluation coefficient. The calculation formula is as follows:

[0039]

[0040]

[0041] In the formula is the Laplace operator expression for the two-dimensional image f(x,y), var is the variance operator, and x1 is the blur evaluation coefficient. A larger blur evaluation coefficient indicates a larger variance and a clearer edge. Conversely, a smaller coefficient indicates a smoother edge and less information.

[0042] 2) Backlight evaluation index: Based on the high contrast and high brightness properties of an image, the image can be converted to grayscale. Pixels with grayscale values between 0 and 30 and 220 and 255 are uniformly converted to 255, and the grayscale values of the remaining pixels are set to 0. A statistical method can be used to determine the number of pixels with grayscale values greater than 0. Finally, by comparing this number with the total number of pixels in the image, a backlight evaluation index can be obtained. The calculation formula is as follows:

[0043] x2=(Q dark +Q bright ) / Q total (3)

[0044] Where Q dark is the number of pixels with grayscale values between 0 and 30, indicating extremely dark pixels; Q bright is the number of pixels with grayscale values between 220 and 255, indicating extremely bright pixels; Q total is the total number of pixels in the image, and x2 is the image backlighting evaluation coefficient. The more extremely bright pixels and extremely dark pixels there are, the greater the backlighting of the image.

[0045] 3) Occlusion Ratio Evaluation Index: Most cattle on pastures are fenced in, and cow faces may be obscured by the fences during face detection. The occlusion ratio evaluation coefficient can be calculated by calculating the ratio of the occluded area to the ground-truth frame area. The calculation formula is as follows:

[0046]

[0047] Where Si is the intersection area between the random occluded gray bar and the real frame, S r is the area of the true frame, and x3 is the evaluation coefficient of the occlusion rate. When more randomly occluded gray bars are located within the true frame, it means that the occlusion rate of the image is higher and the effective information in the true frame is less.

[0048] 4) Evaluation index based on fuzzy membership: A fuzzy membership function is introduced to normalize the three evaluation indexes to obtain a comprehensive evaluation index for the image scene. According to the actual situation, a small fuzzy membership function is used for the image fuzziness, and a large fuzzy membership function is used for the backlight degree and occlusion rate. Therefore, the following calculation formulas are designed as shown in (5)-(7):

[0049]

[0050]

[0051]

[0052] Formulas (5)-(7) are the fuzzy membership functions of blurriness, backlighting, and occlusion rate, respectively. When the blurriness of an image is less than a1, the backlighting is greater than a2, and the occlusion rate is greater than a3, it indicates that the image quality is extremely poor and the image cannot be recognized due to severe interference. When the blurriness of an image is greater than b1, the backlighting is less than b2, and the occlusion rate is less than b3, it indicates that the image quality is good and the detection process will not be interfered by the above three factors.

[0053] B. Target detection stage:

[0054] 1) Propose a CDAA attention mechanism

[0055] This attention mechanism builds on the ECA attention mechanism and incorporates spatial position information, forming a dual-branch attention mechanism with both channel and spatial parallel attention. A dynamic weighting method is used to assign weight coefficients α and β to the channel and spatial attention branches. These weight coefficients represent the degree of emphasis given to each attention branch and are determined by three evaluation metrics: blur, backlighting, and occlusion. The channel attention branch incorporates a global max-pooling feature channel. This is achieved by fusing global average pooling with global max-pooling. This allows the network to selectively emphasize informative features and suppress redundant ones, effectively highlighting edge features in the target, and effectively addressing image blur and occlusion issues. The spatial attention branch assigns importance to different locations in feature information, highlighting important spatial locations and suppressing redundant spatial information. To selectively distinguish the effects of the channel and spatial attention mechanisms in different complex scenarios, an adaptively weighted parallel fusion structure is used to enable application in diverse scenarios.

[0056] The present invention mainly addresses the problem of poor accuracy in cow face detection in complex scenes. The present invention mainly uses a deep neural network constructed using the Pytorch framework and a deep learning experimental platform built using the Ubuntu system, and cooperates with a self-built cow face detection data set to verify the effectiveness of the algorithm. The data sets are taken from 371 pictures of cows in the Coco data set and 202 pictures of cattle taken on actual pastures. The data set contains a total of 573 pictures, all of which are labeled using labelimg. Due to the small size of the data set, a random data enhancement algorithm is added to the YOLO algorithm, which includes random occlusion, flipping, scaling, color gamut conversion, changing contrast, and mosaic data enhancement methods to expand the data set. The number of pictures after expansion is 5438. Finally, 300 pictures in complex scenes in the data set are selected as the test set, and the remaining pictures are divided into training set and verification set according to the ratio of 0.9:0.1.

[0057] The algorithm of the present invention uses the common evaluation indicators of target detection, namely mean average precision (mAP), frame rate (FPS), precision (Precision) and recall (Recall) as the performance evaluation indicators of the model. The calculation formula is as follows:

[0058]

[0059]

[0060]

[0061] Precision refers to the ratio of correctly predicted targets to the predicted results, while Recall refers to the ratio of correctly predicted targets to actual targets. TP, FP, and FN represent true positives, false positives, and false negatives, respectively. Using the calculated Precision and Recall, a PR curve is plotted with Precision as the y-axis and Recall as the x-axis. The area under the PR curve is the AP value. Since this article only detects a single type of target, only AP is required. FPS represents the target detection speed, that is, the number of images processed per second. The FPS value can be calculated by taking the inverse of the time required to detect a single image.

[0062] In the prior art, when the image is blurred, backlit and blocked, the detection accuracy of the small target cow face is most affected, and the actual data set image often contains a large number of small targets. Especially in actual scenes, the cow face often occupies a smaller image size, and the cow face taken at a distance shows the characteristics of a small target object. When the detection target is interfered by scenes of different complexity, the weight coefficient of the grid loss function of each scale of the YOLOV7-tiny algorithm is fixed, and it is impossible to adjust the weight of the large-scale grid, which will lead to inaccurate prediction information of the small target cow face in scenes of different complexity. To this end, the present invention optimizes the YOLOV7-tiny loss function on the basis of the loss function, and adaptively adjusts the weight of the large-scale grid loss function according to the complexity of the image scene, so that the network is more focused on a larger number of small targets during the training process, thereby improving the detection accuracy of the entire network.

[0063] Example

[0064] The method of this embodiment realizes the detection of cow faces in complex scenes, which mainly includes two parts: image evaluation calculation stage and target detection stage. Figure 1 The overall architecture diagram of the algorithm is as follows:

[0065] A. Image evaluation index stage:

[0066] Step 1: Randomly divide the prepared cow face dataset into training set and test set in a ratio of 0.9:0.1, and then divide the training set into training and validation sets in a ratio of 0.9:0.1.

[0067] Step 2: Input the image into the network to calculate the three evaluation indicators of the image. First, use the following Figure 2 The Laplace operator shown in the figure calculates the second-order derivative in the x and y directions and then calculates the variance to obtain the fuzzy evaluation coefficient. Then, by converting the image to a grayscale image, the pixels with grayscale values between 0 and 30 and 220 and 255 are uniformly converted to 255, and the grayscale values of the remaining pixels are changed to 0. The number of pixels with grayscale values greater than 0 can be obtained by statistical methods, and finally, the backlight evaluation index is obtained by comparing it with the total number of pixels in the image. Finally, random artificial occlusion is added to the normal image using Python language. The actual effect is shown in the attached figure. Figure 3 As shown in the figure, for a 640×640 image, to ensure the effectiveness of random occlusion, a Python algorithm was used to randomly add three 240×20 gray bars to simulate railing occlusion. The occlusion rate evaluation coefficient was obtained by calculating the ratio of the occluded area to the true frame area.

[0068] Step 3: Introduce the fuzzy membership function to normalize the three evaluation indicators to obtain the comprehensive evaluation indicator of the image scene.

[0069] B. Target detection stage:

[0070] Step 1: Introduce the CDAA attention mechanism with scene information after the first Multi_Concat_Block of the original network, which not only retains the rich original feature information of the image and avoids losing too many features in the downsampling process, but also suppresses the interference of complex background and improves the accuracy of cow face detection. The principle diagram of the CDAA module is as follows Figure 4 As shown in Figure 2, we first introduce the global average pooling feature channel into the channel attention branch. The specific calculation formula is as follows:

[0071]

[0072] ω z =σ(C1D k (z)) (12)

[0073]

[0074] In formula (11), z∈R c is an aggregated feature without dimensionality reduction, generated by the spatial dimension H×W of the compressed output u, and GAP is global average pooling; in formula (12), C1D represents one-dimensional convolution, k is the convolution kernel size, and σ is the Sigmoid activation function. After the ECA module uses global average pooling, it determines the adaptive convolution kernel size k and performs one-dimensional convolution. Then, the Sigmoid function learns the weights of each channel to obtain the normalized scalar ω z , through F in formula (13) scale Multiply the normalized weights to each channel to get the features in Secondly, the global maximum pooling feature channel is introduced. The specific calculation formula is as follows:

[0075] s c =GMP(u c )=max(u c ) (14)

[0076] ω s =σ(C1D k (s)) (15)

[0077]

[0078]

[0079] GMP is the global maximum pooling, which is similar to the calculation process of the global average pooling feature channel. The features extracted for this module are Then, feature fusion is performed with the ECA module to form a complete channel attention branch. In formula (17), F cat Represents the feature fusion operation, first and Feature splicing is performed, the number of feature channels is doubled, and then the number of channels is restored through 1×1 convolution operation dimensionality reduction.

[0080] Step 2: In order to distinguish the detection target from the complex background, it is necessary to focus on the features in the target and increase the discriminability between the features. For this purpose, the spatial attention branch is introduced. This branch also uses the parallel structure of channel maximum pooling and channel average pooling to compress along the channel direction in the spatial dimension H×W, and perform feature splicing on the extracted channel features to obtain the fusion information of different channel features, making the extracted feature information more comprehensive. The multi-channel features are then compressed into single-channel features through convolution, effectively avoiding the interference of channel information on the spatial attention branch. Finally, the input features are multiplied by the obtained spatial weight information to form a new effective feature descriptor. The calculation formula of the spatial attention branch is as follows:

[0081] p (i,j) =F cmax (u (i,j) )=max(u (i,j) ) (18)

[0082]

[0083]

[0084] In formula (18), F cmax is the channel maximum pooling, F in formula (19) cavg is channel average pooling, both of which are operated along the channel direction in the spatial dimension H×W, u (i,j) Obtained from all channels at a certain position in the compressed space dimension H×W, the features p are extracted respectively through channel maximum pooling and channel average pooling. (i,j) and q (i,j) In formula (20) Extract features for the spatial attention module, where

[0085] Step 3: Before feature fusion, introduce adaptive weight coefficients α and β to strengthen the weights of the channel attention branch and the spatial attention branch, respectively. α is the weight of the channel attention branch, determined by the blur and occlusion rate; β is the weight of the spatial attention branch, determined by the backlight degree, which can strengthen regional features and suppress backlight factors with strong backgrounds. The specific calculation formula is as follows:

[0086]

[0087]

[0088]

[0089] In formula (21), ph1, ph2, and ph3 are the weight coefficients corresponding to blur, backlight, and occlusion, F1, F2, and F3 are the corresponding evaluation indicators, and f1, f2, and f3 are the detection difficulty coefficients of the three scenes in actual situations. Among them, occlusion will cause all features of the occluded part to be lost, backlighting will cause strong background interference, and blurring will cause edge features to be weakened. Therefore, it can be seen that the detection difficulty coefficients of the three scenes are f3>f2>f1. After the attention branch is strengthened, feature fusion is performed, which is specifically expressed as follows:

[0090]

[0091] To illustrate the effectiveness of the algorithm of the present invention, the intermediate feature layer is visualized through a heat map, and the output results are shown in the attached figure. Figure 5 The weights are distinguished by color (red, yellow, green, and blue). Darker colors represent larger weights and greater network attention. After the CDAA module is introduced, the darker areas near the cow's face become denser, the surrounding colors become essentially green and blue, and the red and yellow areas on the ground and the cow's body are significantly reduced. This demonstrates that the addition of the CDAA module to the network can focus the network's attention on the area near the cow's face, suppressing interference from environmental factors, thus demonstrating the effectiveness of the proposed algorithm.

[0092] Step 4: To make the network more focused on a large number of small objects during training, thereby improving the overall detection accuracy of the network, the YOLOV7-tiny loss function is optimized. The specific calculation process is as follows:

[0093] ε=ph1+ph2+ph3+1 (25)

[0094]

[0095] The ε in formula (25) is the optimization coefficient, which is determined by the weight coefficients ph1, ph2, and ph3 of the image evaluation index. b 、loss o 、loss c The λ represents the rectangular box loss, confidence loss, and classification loss, respectively. The subscripts 80, 40, and 20 represent the large, medium, and small scales, respectively. λ1, λ2, and λ3 are the weight coefficients of the grid loss function at each scale. As the complexity of the scene in which the target is located changes, the optimization coefficients of the large-scale grid are adaptively adjusted to cope with the changes in scene information, thereby improving the focus on the small target cow face.

[0096] Experimental Example 1

[0097] In order to verify the effectiveness of the algorithm of the embodiment of the present invention, an ablation experiment is first performed on a specific data set to verify the effect. The experimental results are shown in Table 1.

[0098] Table 1 AA-YOLOV7-tiny network ablation experiment

[0099]

[0100] As shown in Table 1, the detection accuracy AP value of the improved solution of the present invention has been significantly improved. In particular, after adding the CDAA attention module and optimizing the loss function, the detection accuracy reached 89.58%, and the detection speed FPS value was also very close to that of the original network YOLOV7-tiny.

[0101] In order to verify the algorithm robustness of the solution of the present invention, samples from different scenes and multiple scenes were selected for testing. The horizontal rows are the same test samples, the vertical columns are the same detection algorithm, and the positions in the yellow and blue circles are the cow faces that were not detected and the cow faces that were missed. The comparative test results of different scenes are shown in the attached figure. Figure 6 and attached Figure 7 As shown. Figure 6 In the first group of images, there are serious occlusions and blur interferences in the distance, so there are many missed detections before using the proposed algorithm. Figure 6 The second group of pictures has severe backlight interference in the distance. Figure 6 (a) Unable to detect the distant cow face; Figure 6 (b) False detection occurs, where the cow’s tail is detected as the cow’s face; Figure 6 (c) Although ECA attention and spatial attention were increased at the same time, two false detections still occurred. Figure 6 (d) The detection effect is the best in two different scenarios. Figure 7 The comparison results show that YOLOV7-tiny has the worst detection effect. After adding ECANet, Figure 7 (b) The first set of images detected the cow’s face blocked by the railing, but there were still some missed detections. The second set of images also had the cow’s back mistakenly detected as a face. After adding ECANet and the spatial attention mechanism, the detection effect was improved to a certain extent. Figure 7 (b) The cow face not detected in the first group of images, attached Figure 7 (c) can be detected, but there are still false detections in the second group of images. After comparison, it can be seen that in Figure 7 (d), the corresponding attention branches are strengthened for complex scenes, and the loss function is optimized, achieving better detection results. It can effectively detect the small target cow face under blurry backlighting and railing occlusion conditions.

[0102] Experimental Example 2

[0103] To further evaluate the model performance of the embodiment, the performance of the embodiment algorithm AA-YOLOV7-tiny is compared with the YOLOV5-s, YOLOX-s, YOLOV7-tiny+CBAM and MobileNetv2-SSD algorithms of the same type as YOLOV7-tiny. The comparison results are shown in Table 2, and the actual detection effect is shown in the attached figure. Figure 8 shown.

[0104] Table 2 Performance comparison results of different models

[0105]

[0106] As can be seen from Table 2, the AA-YOLOV7-tiny algorithm of the embodiment of the present invention has the highest detection accuracy. This is because the CDAA attention module introduced by this algorithm can effectively suppress the noise interference of the complex environment of the cattle farm. Figure 8 (a) It can be seen that although the MobileNetv2-SSD algorithm model is the smallest, its detection effect is the worst. It fails to detect the small, blurred cow face in the distance in the first group of images, the cow face blocked by the railing in the second group, and the cow face in the distance in the third group that is backlit, blocked, and blurred at the same time. Figure 8 (b) and (c) show that the YOLO algorithm of the same series has a certain degree of anti-interference ability in complex environments due to the increase in network parameters and training models. However, it can be seen from the second group of figures that these two algorithms have poor detection effects on severely occluded cow faces, and YOLOV5-s misses the blurred and occluded cow faces in the first and third groups. Figure 8 (d) As can be seen, the YOLOV7-tiny algorithm, after incorporating the traditional CBAM attention mechanism, can handle some complex scenes, but its robustness to occluded scenes is too poor, failing to detect the occluded cow faces in the second and third groups. Compared to the first four models, the proposed AA-YOLOV7-tiny not only has fewer parameters and a smaller model than YOLOV5-s and YOLOX-s, but also, due to the introduction of the CDAA attention module, has better robustness for cow face detection in complex environments, resulting in higher detection accuracy than other models.

[0107] In addition to providing a method for detecting cow faces in complex scenes, the present invention also provides a cow face detection system corresponding to the cow face detection method, including:

[0108] Design module: used to design the fuzziness evaluation index, backlighting evaluation index and occlusion rate evaluation index, and normalize the three evaluation indexes through the fuzzy membership function to determine the adaptive weight coefficient;

[0109] Fusion module: used to introduce the attention mechanism CDAA into the backbone feature extraction network based on YOLOV7-tiny, design the channel and spatial attention parallel structure, and fuse the adaptive weight coefficients;

[0110] Optimization module: used to optimize the YOLOV7-tiny loss function using the adaptive weight coefficient.

[0111] Figure 9 This is a schematic diagram of the structure of a computer device disclosed in the present invention. Figure 9 As shown, the computer device includes: an input device 63, an output device 64, a memory 62 and a processor 61; the memory 62 is used to store one or more programs; when the one or more programs are executed by the one or more processors 61, the one or more processors 61 implement a cow face detection method provided in the above embodiment; wherein the input device 63, the output device 64, the memory 62 and the processor 61 can be connected by a bus or other means. Figure 9 The bus connection is taken as an example.

[0112] The memory 62 is a readable and writable storage medium of a computing device, which can be used to store software programs and computer executable programs, such as the program instructions corresponding to the cow face detection method described in the embodiment of the present application; the memory 62 may mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and at least one application required for a function; the data storage area can store data created according to the use of the device, etc.; in addition, the memory 62 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device; in some instances, the memory 62 may further include a memory remotely located relative to the processor 61, and these remote memories can be connected to the device via a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0113] The input device 63 may be used to receive input digital or character information, and generate key signal input related to user settings and function control of the device; the output device 64 may include a display device such as a display screen.

[0114] The processor 61 executes various functional applications and data processing of the device by running software programs, instructions and modules stored in the memory 62.

[0115] The present application also provides a storage medium containing computer executable instructions, which are used to perform the cow face detection method provided in the above embodiment when executed by a computer processor. The storage medium is any of various types of memory devices or storage devices, including: installation media, such as CD-ROM, floppy disk or tape device; computer system memory or random access memory, such as DRAM, DDR RAM, SRAM, EDO RAM, Rambus RAM, etc.; non-volatile memory, such as flash memory, magnetic media (such as hard disk or optical storage); registers or other similar types of memory elements; the storage medium may also include other types of memory or a combination thereof; in addition, the storage medium may be located in the first computer system in which the program is executed, or may be located in a different second computer system, the second computer system being connected to the first computer system via a network (such as the Internet); the second computer system may provide program instructions to the first computer for execution. The storage medium includes two or more storage media that can reside in different locations (for example, in different computer systems connected by a network). The storage medium can store program instructions (for example, specifically implemented as a computer program) that can be executed by one or more processors.

[0116] Finally, it should be noted that although this specification contains many specific implementation details, these should not be interpreted as limiting the scope of any invention or the scope of what is claimed, but are primarily intended to describe the features of specific embodiments of a particular invention. Certain features described in multiple embodiments within this specification may also be implemented in combination in a single embodiment. On the other hand, various features described in a single embodiment may also be implemented separately in multiple embodiments or in any suitable sub-combination. In addition, although features may function in certain combinations as described above and may even be initially claimed as such, one or more features from a claimed combination may in some cases be removed from the combination, and a claimed combination may refer to a sub-combination or a variation of a sub-combination.

[0117] Similarly, although operations are depicted in a particular order in the accompanying drawings, this should not be understood as requiring that these operations be performed in the particular order shown or performed sequentially, or that all illustrated operations be performed to achieve the desired results. In some cases, multitasking and parallel processing may be advantageous. In addition, the separation of various system modules and components in the above-described embodiments should not be understood as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product, or packaged into multiple software products.

[0118] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the following claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the particular order shown or sequential sequence to achieve the desired results. In some implementations, multitasking and parallel processing may be advantageous.

[0119] The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present disclosure should be included in the scope of protection of the present disclosure.

Claims

1. A method for detecting cow faces in complex scenes, characterized in that: The steps include: The fuzziness evaluation index, backlighting evaluation index and occlusion rate evaluation index are designed, and the three evaluation indexes are normalized by fuzzy membership function to determine the adaptive weight coefficient. Based on YOLOV7-tiny, the attention mechanism CDAA is introduced into the backbone feature extraction network, the channel and spatial attention parallel structure is designed, and the adaptive weight coefficient is integrated; Optimizing the YOLOV7-tiny loss function using the adaptive weight coefficient; The method of normalizing the three evaluation indicators through the fuzzy membership function includes the following steps: introducing the fuzzy membership function to normalize the three evaluation indicators to obtain the comprehensive evaluation indicator of the image scene. The specific calculation formula is as follows: Blur a1, b1, backlight a2, b2, occlusion a3, b3; Methods for designing parallel structures for channel and spatial attention include: First, the global average pooling feature channel is introduced in the channel attention branch. The specific calculation formula is as follows: oh z =σ(C1D k (z)) z∈R c is the aggregated feature without dimensionality reduction, generated by the spatial dimension H×W of the compressed output u, GAP is the global average pooling; C1D represents one-dimensional convolution, k is the convolution kernel size, σ is the Sigmoid activation function, F scale Multiply the normalized weights to each channel to get the features in Secondly, the global maximum pooling feature channel is introduced. The specific calculation formula is as follows: s c =GMP(u c )=max(u c ) oh s =σ(C1D k (s)) GMP is global maximum pooling, is the feature extracted by the channel attention branch, F cat Represents the feature fusion operation, first and Perform feature splicing, the number of feature channels is doubled, and then the number of channels is restored through 1×1 convolution operation; The introduced spatial attention branch uses a parallel structure of channel maximum pooling and channel average pooling to compress along the channel direction in the spatial dimension H×W, and then compresses the multi-channel features into single-channel features through convolution. Finally, the input features are multiplied by the obtained spatial weight information to form an effective feature descriptor; the calculation formula of the spatial attention branch is as follows: p (i,j) =F cmax (u (i,j) )=max(u (i,j) ) F cmax is the channel maximum pooling, F cavg is channel average pooling, u (i,j) Obtained from all channels at a certain position in the compressed space dimension H×W, the features p are extracted respectively through channel maximum pooling and channel average pooling. (i,j) and q (i,j) , Extract features for the spatial attention module, where Methods for determining the self-weight coefficients α and β include: α is the weight of the channel attention branch, which is determined by the blur and occlusion rate; β is the weight of the spatial attention branch, which is determined by the backlight degree. The specific calculation formula is as follows: Ph1, ph2, and ph3 are the weight coefficients corresponding to blur, backlight, and occlusion rates, F1, F2, and F3 are the corresponding evaluation indicators, and f1, f2, and f3 are the detection difficulty coefficients of the three scenes in actual situations; The expression of the fusion weight coefficients α and β after attention enhancement is: The method of optimizing the YOLOV7-tiny loss function using the adaptive weight coefficient includes: ε=ph1+ph2+ph3+1 ε is the optimization coefficient, which is determined by the weight coefficients ph1, ph2, and ph3. b 、loss o 、loss c They represent rectangular box loss, confidence loss, and classification loss respectively. The subscripts 80, 40, and 20 represent large, medium, and small scales respectively. λ1, λ2, and λ3 are the weight coefficients of the grid loss function at each scale.

2. The cow face detection method according to claim 1, characterized in that The fuzziness evaluation index includes: the image is subjected to the Laplace operator to obtain the second-order derivative in the x and y directions respectively, and then the variance operation is performed to obtain the fuzzy evaluation coefficient. The calculation formula is as follows: In the formula is the Laplace operator expression of the two-dimensional image f(x,y), var is the variance operation, and x1 is the fuzziness evaluation coefficient.

3. The cow face detection method according to claim 1, characterized in that: The backlight evaluation index includes: according to the high contrast and high brightness properties of the image, the image is converted into a grayscale image, the pixels with grayscale values between 0 and 30 and 220 and 255 are uniformly converted to 255, and the grayscale values of the remaining pixels are changed to 0. The number of pixels with grayscale values greater than 0 is obtained by statistical methods, and finally compared with the total number of pixels in the image to obtain an evaluation index of backlight. The calculation formula is as follows: x2=(Q dark +Q bright ) / Q total Where Q dark is the number of pixels with grayscale values between 0 and 30, indicating extremely dark pixels; Q bright is the number of pixels with grayscale values between 220 and 255, indicating extremely bright pixels; Q total is the total number of pixels in the image, and x2 is the image backlighting evaluation coefficient.

4. The cow face detection method according to claim 1, wherein: The occlusion rate evaluation index includes: calculating the ratio of the occlusion area to the real frame area to obtain the occlusion rate evaluation coefficient, and the calculation formula is as follows: Where S i is the intersection area between the random occluded gray bar and the real frame, S r is the real frame area, and x3 is the evaluation coefficient of the occlusion rate.

5. A cow face detection system for complex scenes, using the cow face detection method according to any one of claims 1 to 4, characterized in that: include: Design module: used to design the fuzziness evaluation index, backlighting evaluation index and occlusion rate evaluation index, and normalize the three evaluation indexes through the fuzzy membership function to determine the adaptive weight coefficient; Fusion module: used to introduce the attention mechanism CDAA into the backbone feature extraction network based on YOLOV7-tiny, design the channel and spatial attention parallel structure, and fuse the adaptive weight coefficients; Optimization module: used to optimize the YOLOV7-tiny loss function using the adaptive weight coefficient.