Small target cattle body detection method and system based on MADS-YOLOv5s

The MADS-YOLOv5s small target detection method, combined with C3M-Backbone, dynamic upsampler Dysample and Shape-IoU loss function, solves the problem of insufficient small target detection accuracy in cattle counting and achieves efficient and accurate detection of cattle in near and far distances.

CN120808389APending Publication Date: 2025-10-17HANGZHOU DIANZI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510747194.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-05
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

Existing technologies for cattle counting and identification suffer from problems such as time-consuming and labor-intensive operations, high error rates, delayed data updates, blind spots in vision, lighting interference, target overlap, and complex posture changes. In particular, the detection accuracy of small targets in drone image acquisition is insufficient, making it difficult to adapt to scale changes and fuzzy features in near and far views.

Method used

A small target detection method based on MADS-YOLOv5s is adopted, combined with the C3 fusion lightweight ViT module and the multi-layer convolutional cascade cattle feature extraction backbone network C3M-Backbone, the dynamic upsampler Dysample and the four-scale detection layer, and the Shape-IoU loss function is introduced to improve the model's detection performance for small target cattle.

Benefits of technology

The model's ability to simultaneously detect cattle in the near and far distances has been improved, and the detection performance of small and blurred cattle has been enhanced. The detection accuracy and the ability to adapt to complex scenes have been improved, and the accuracy of small target detection has been significantly improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120808389A_ABST
    Figure CN120808389A_ABST
Patent Text Reader

Abstract

The invention discloses a small target detection method and a small target detection system based on MADS-YOLOv5s. The method comprises the following steps: step 1, acquiring cattle picture data of an unmanned aerial vehicle and a long-range camera; step 2, establishing a small target detection model based on MADS-YOLOv5s; and step 3, training and testing a small target detection model. According to the method, the C3M-Backbone backbone network combining global feature and local feature features is provided, and the capability of simultaneously detecting the short-range cattle and the long-range cattle by the model is improved. A proposed AD-Neck neck network adopts a dynamic upper sampler Dysample and a four-scale detection layer, lost detail features are effectively recovered, detail information of a small target is concerned, and the detection performance of the model on small and fuzzy cattle is improved. On the basis, a Shape-IoU loss function paying attention to the shape and the scale of the bounding box is adopted, so that bounding box regression is more accurate, the accuracy of small target detection and the adaptability to complex conditions are improved, and the detection performance of the model on short-range and long-range cattle and fuzzy cattle is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of livestock breeding management, and in particular to a small target cow body detection method and system based on MADS-YOLOv5s. BACKGROUND

[0002] In recent years, with the rapid development of China's livestock industry towards scale, intelligence and intensification, the economic benefits of beef and dairy cattle breeding have been significantly improved, and the industrial chain has been continuously improved. In the scenario of large-scale breeding management, cattle number statistics and individual identity recognition have become two core technical requirements for realizing fine operation. The traditional manual inventory method has defects such as time-consuming and labor-consuming, high error rate, data update lag, etc., and it is difficult to meet the urgent needs of modern ranches for real-time dynamic monitoring and efficient management.

[0003] In the field of cattle counting technology, the existing solutions mainly have the following technical bottlenecks: (1) The traditional manual inspection method is limited by the scope of work and labor cost, and it is difficult to realize the rapid counting of large-scale cattle herd; (2) The fixed monitoring device has a blind area in the field of view, and the image acquisition quality is easily disturbed by environmental factors such as light and shielding; (3) The conventional image recognition algorithm has insufficient adaptability to complex situations such as target overlap and posture change in dense herd breeding scenes. Although unmanned aerial vehicle technology has been applied to aerial image acquisition due to its strong maneuverability and wide coverage, it still faces technical challenges such as insufficient lightness of detection model and decline of cross-view target recognition accuracy in actual application.

[0004] With the development of deep learning, many scholars have carried out research on small target detection algorithms based on deep learning. On the basis of improving the SSD network model, the parameters of each convolutional layer in SSD are balanced to improve the accuracy of recognition, and an improved unmanned ship sea ship recognition algorithm is obtained. However, the SSD algorithm is mainly based on the anchor frame detection method, which needs to predefine a series of anchor frames to match the target. However, due to the existence of close-range and long-range cattle in open scenes, the use of anchor frames with fixed size and scale may not be able to adapt well to the scale changes of cattle. Li et al. proposed a TridentSSD based on SSD with three branch architecture, which integrates deconvolution components and feature fusion technology to enhance the detection of small targets and improve the detection accuracy of small targets. Although TridentSSD designs three branches to cope with different scale challenges, it still cannot adapt well to the scale changes of close-range and long-range cattle, because the scale of close-range and long-range cattle may change greatly in the image and be larger than the predefined scale range. Kisantal et al. adopted a strategy of copying and pasting small target instances to increase the frequency of these objects in the dataset, thereby improving the positive impact of small targets on model training. Although this method may be effective in general scenarios, small target cattle features are relatively less and relatively blurred in long-range scenarios and certain height unmanned aerial vehicle scenarios, and simple copying and pasting operations cannot be adapted.

[0005] Compared with other small target detection of objects, small target detection of cattle faces some specific challenges and difficulties. In the open scene of the pasture camera environment, cattle will appear in close and far distances to form close-range and long-range cattle pictures at the same time, and long-range cattle will be blurred. The performance of detecting close-range and long-range cattle at the same time and the performance of detecting blurred cattle needs to be improved. The unmanned aerial vehicle cattle shooting picture at a certain height will also have the problem of small cattle target, which will cause the cattle features to be blurred and easy to miss detection. SUMMARY

[0006] The purpose of the present invention is to address the deficiencies of the existing technology and propose a small-target cow body detection method and system based on MADS-YOLOv5s. The method first proposes a cow feature extraction backbone network C3M-Backbone based on the C3 fusion lightweight ViT module (C3-MobileViTv3) and a multi-layer convolutional cascade. The C3 fusion lightweight ViT module (C3-MobileViTv3) combines CNN and Transformer, uses the self-attention mechanism of Transformer to capture long-range dependencies, uses the local kernel of CNN to capture local information, increases the depth of the network, and improves the model's ability to extract global and local features. It helps the model better understand the position, posture and background information of the cow in the entire image globally and the detailed features of the cow in the image locally, such as spots and textures, thereby improving the model's ability to simultaneously detect close-up cows and distant small-target cows. Secondly, a neck network consisting of a dynamic upsampler (Dysample) and a four-scale detection layer is proposed. Feature upsampling is a key factor in gradually restoring feature resolution in dense prediction models. The dynamic upsampler (Dysample) recovers lost detail information through content-aware upsampling. The large-scale detection layer in the neck can enhance the network's extraction of shallow detail semantic information, effectively locate the position of small targets, and focus on the detailed features of small targets, thereby improving the model's detection performance for small and blurred cattle. Finally, based on the previous work, since small-scale bounding boxes are more sensitive to changes in IoU values, a Shape-IoU loss function that focuses on the shape and scale of the bounding box itself is introduced to make the bounding box regression more accurate, thereby improving the accuracy of small target detection and its adaptability to complex situations.

[0007] The technical solution adopted by the present invention comprises the following steps: The small target detection method based on MADS-YOLOv5s includes the following steps: S1, collect cattle image data from drones and long-range cameras; Cameras were set up in open areas of four ranches to capture images in real time by pulling video streams. At the same time, drones were used to fly back and forth over the areas where the cattle were located under different lighting conditions and ground environments to obtain a cattle image dataset.

[0008] S2. Establish a small target detection model based on MADS-YOLOv5s; S2-1. Establish a C3M-Backbone network that combines global and local features. S2-2, establish AD-Neck network, using dynamic upsampler Dysample and four-scale detection layer; S2-3, the Shape-IoU loss function for establishing the shape and scale of the bounding box itself.

[0009] S3, training and testing of the small target detection model.

[0010] The application also provides a small target detection system based on the MADS-YOLOv5s, comprising: The data acquisition module acquires the picture data set of the cattle in the unmanned aerial vehicle scene and the picture data set of the cattle using the long-range camera. The small target detection model construction module establishes the small target detection model based on the MADS-YOLOv5s; the model comprises a C3M-Backbone backbone network combining the global feature and the local feature characteristics, an AD-Neck neck network adopting the up-sampler Dysample and the four-scale detection layer, and a Shape-IoU loss function for focusing on the shape and scale of the bounding box itself. The training and testing module trains and tests the small target detection model.

[0011] The application has the following beneficial effects: The MADS-YOLOv5s network model proposed in the application proposes the C3M-Backbone backbone network combining the global feature and the local feature characteristics, which helps the model better understand the global information such as the position and posture of the cattle in the entire image and the local information such as the spots and textures of the cattle, improves the ability of the model to detect the near and long-range cattle at the same time, proposes the AD-Neck neck network adopting the dynamic up-sampler Dysample and the four-scale detection layer, effectively restores the lost detail features and focuses on the detail information of the small target, improves the detection performance of the model on the small and blurred cattle, and on this basis, the Shape-IoU loss function for focusing on the shape and scale of the bounding box itself is adopted, so that the bounding box regression is more accurate, the accuracy of the small target detection is improved, and the adaptability to complex situations is improved, effectively improving the detection performance of the model on the near and long-range cattle and the blurred cattle. BRIEF DESCRIPTION OF DRAWINGS

[0012] Figure 1 It is a small target cattle body detection data set image example.

[0013] Figure 2 It is a MADS-YOLOv5s overall network structure diagram.

[0014] Figure 3 It is a C3 fusion lightweight ViT module (C3-MobileViTv3) structure schematic diagram.

[0015] Figure 4 It is a lightweight ViT module (MobileViTv3) schematic diagram.

[0016] Figure 5 Schematic diagram of the upsampling process of the dynamic upsampler Dysample.

[0017] Figure 6 Schematic diagram of the process of implementing the sampling set generator.

[0018] Figure 7 Schematic diagram for visualization of cow body detection features. DETAILED DESCRIPTION

[0019] The specific embodiments of the present invention will be further described below with reference to the accompanying drawings.

[0020] This embodiment uses a small object cow body detection method based on MADS-YOLOv5s, including the following steps: S1. Experimental dataset construction.

[0021] like Figure 1 As shown in Figure 2, the datasets used in this method are divided into two aspects: the cattle dataset in the drone scene and the cattle dataset using a long-range camera.

[0022] The drone dataset uses drones to collect images of cattle from four ranches in Inner Mongolia and Henan provinces, herding them into open areas. The drone, a DJI Mavic 3T, uses a vertically downward-facing camera with a wide-angle lens and a 1x focal length. Images are saved at a 4K resolution, and the flight altitude is 30 to 40 meters, at a speed of 2 meters per second, with a shutter speed of 1 second. Round-trip flights were performed over the cattle areas under varying lighting conditions and surface conditions. After careful selection, a total of 797 original images were collected, forming the UAV-Detection-797 cattle body detection dataset.

[0023] At the same time, in order to enrich the scenes, cameras were set up in the open areas of four ranches. By pulling video streams to capture images in real time, 1,155 distant images of cattle under different lighting and scenes were collected. The cattle body distant view dataset YuanJing-Detection-1155 was supplemented to establish the performance of the small object cattle body detection algorithm based on MADS-YOLOv5s proposed in this chapter.

[0024] S2. Design a small object cow body detection model based on MADS-YOLOv5s; The overall network structure of the small target cow body detection model based on MADS-YOLOv5s proposed in this paper is as follows Figure 2 shown.

[0025] The application firstly constructs a backbone network C3M-Backbone based on a C3 fused lightweight ViT module (C3-MobileViTv3). The global perception ability of the lightweight ViT module (MobileViTv3) and the local feature extraction characteristics of the convolution operation are combined to realize the bidirectional enhancement of the global information such as the position and posture of the cattle and the detail features such as the spots and textures through cascading a CBS standard convolution module, a C3 residual module and an SPPF multi-scale feature pyramid. The AD-Neck neck network adopts a dynamic up-sampler Dysample to reconstruct feature details, and a new 160x160 high-resolution detection layer is added. Through a four-scale (160x160, 80x80, 40x40, 20x20) feature fusion mechanism, the recognition ability of the micro-cattle of 4x4 pixels or more in the unmanned aerial vehicle aerial image is significantly improved. In addition, the model introduces a Shape-IoU loss function, dynamically adjusts the weight coefficients of the shape and scale of the bounding box, optimizes the positioning accuracy of the overlapping targets and fuzzy targets in the dense group raising scene, and forms an end-to-end efficient detection system.

[0026] S2-1 C3M-Backbone backbone network The C3 fused lightweight ViT module (C3-MobileViTv3) proposed by the application is a hybrid feature extraction unit that combines convolutional neural networks (CNN) and Transformers. The core innovation lies in the synergistic effect of the self-attention mechanism of the Transformer and the convolution operation, which realizes the bidirectional modeling of local details and global semantics of cattle images. The module embeds the Transformer layer in the lightweight ViT module (MobileViTv3) as a dynamic convolution kernel into the traditional convolution architecture, uses the self-attention mechanism to perform global correlation calculation on the input feature data, captures local context information such as cattle spots and textures, establishes long-range dependencies across regions, and effectively makes up for the shortcomings of traditional convolution modules in global feature perception.

[0027] The backbone network C3M-Backbone gradually expands the network depth and receptive field by cascading multiple layers of CBS standard convolution modules and C3 modules with residual structures, and introduces an SPPF multi-scale feature pyramid module at the end to enhance the semantic expression ability through cross-scale feature fusion. Finally, a lightweight backbone network architecture is formed that takes into account both local feature refinement and global spatial relationship modeling.

[0028] As Figure 2As shown in the left C3M-Backbone, the input picture is first extracted into a 160x160x128 feature map through two layers of CBS standard convolution modules and one layer of C3 modules, then into an 80x80x256 feature map through one layer of CBS standard convolution modules and one layer of C3 modules, then into a 40x40x512 feature map through one layer of CBS standard convolution modules and one layer of C3-MobileViTv3 fusion lightweight ViT modules, and then into a 20x20x1024 feature map through one layer of CBS standard convolution modules, one layer of C3 modules and one layer of SPPF multi-scale feature pyramid modules. The four feature maps are then input into the AD-Neck neck network for feature fusion. Among them, the 160x160x128 and 80x80x256 feature maps are shallow detail feature information, and the 40x40x512 and 20x20x1024 feature maps are deep semantic feature information.

[0029] The C3-MobileViTv3 fusion lightweight ViT module uses a MobileViTv3 lightweight ViT module as a bottleneck, as shown in the structure of Figure 3 The input feature map is divided into two groups. One group is first passed through one layer of CBS standard convolution modules and then through three layers of lightweight ViT modules, and the other group is passed through one layer of CBS standard convolution modules. Then, the two output features are concatenated and spliced in the channel dimension, and finally output after passing through one layer of CBS standard convolution.

[0030] The structure of the MobileViTv3 lightweight ViT module is as shown in Figure 4 First, the feature map with a size of CinxHxW is input into the Local Representation Block, and the local spatial information is extracted through the depth separable convolution (DWConv 3x3), and then a 1x1 convolution is used to fuse the channel features. Then the result is sent to the Global Representation Block. After adjusting the channel number through a 1x1 convolution, it is input into the stacked Transformer module to capture the global features of long-distance dependencies, and finally a 1x1 convolution is used to restore the channel dimension. After aligning the local and global features through 1x1 convolution, they are fused in the Fusion Block using addition and can form a residual connection with the input. Finally, the size of the output feature map is CoutxHxW, which realizes the effective combination of local and global information in the lightweight network.

[0031] The advantage of the lightweight ViT module (MobileViTv3) is that it can effectively capture local details and global information in the input tensor while reducing the number of parameters. It combines CNN and Transformer to get the advantages of both. First, it uses CNN to extract local features, then it expands the feature map into N non-overlapping flat rectangular regions (patches), and then it uses transformer to learn global information. Theoretically, the receptive field of the network is HxW, i.e. full receptive field. The model is smaller, more accurate, has better performance, stronger generalization ability and stronger robustness.

[0032] The lightweight ViT module (MobileViTv3) effectively integrates input features, local features and global features. In the fusion block of the lightweight ViT module (MobileViTv3), the local representation features and the global representation features are closely related. First, the features of the local and global representation blocks are fused together to simplify the learning task. Then, since the residual structure helps to optimize the deeper layers of the architecture, the fusion block will add the input features as the final operation when generating the output of the lightweight ViT module (MobileViTv3). The original feature map is combined with the feature map after the action of deep convolution and attention mechanism, thereby achieving the effect of cross-layer information transmission. The effective fusion of input features, local features and global features in the lightweight ViT module (MobileViTv3) greatly improves the performance of near and far range cattle target detection, and gives reasonable attention to global information such as cattle position and local detail information such as cattle texture, features and boundaries, effectively improving the detection performance of near and far range cattle.

[0033] As shown in Figure 3 The C3 fusion lightweight ViT module (C3-MobileViTv3) combines the ideas of residual structure and cross-layer connection, aiming to enhance the feature extraction and fusion capabilities. The C3 fusion lightweight ViT module (C3-MobileViTv3) divides the input features into two groups, one of which is processed by the CBS module, and the other is processed by the CBS module first and then by the lightweight ViT module (MobileViTv3). Then the two groups of output features are fused by splicing. The final output features contain features processed by different paths, enhancing the richness and description of the features, and significantly improving the detection performance of near and far range cattle.

[0034] S2-2AD-Neck neck network The backbone network C3M-Backbone extracts features from the input data, gradually extracting shallow detail feature information and deep semantic feature information, and the AD-Neck neck network further splices the multi-scale features extracted by the backbone network. The spliced features contain more context information, making the feature expression more powerful and robust. The AD-Neck neck network uses a feature pyramid (FPN) module for top-down fusion of features and a path aggregation (PAN) module for bottom-up fusion of features to extract and fuse multi-scale features. In the feature pyramid, a lightweight and efficient dynamic upsampler Dysample is used for content-aware upsampling, combining high-level semantic information with low-level detail information, restoring lost detail information, improving the model's detection ability for small target cattle boundaries, and improving the generalization ability. Reducing the number of parameters and improving performance, while using a four-scale detection mechanism to help the network better capture shallower detail information and improve the detection accuracy of small target cattle.

[0035] (1) Dynamic upsampler Dysample The AD-Neck neck network includes a top-down feature pyramid (FPN) module and a bottom-up path aggregation (PAN) module. FPN transfers deep semantic features from top to bottom to enhance semantic information, but does not transfer shallow positioning information. PAN compensates for FPN by adding a bottom-up pyramid structure after FPN, which can transfer shallow positioning information to deep layers. This "double tower" structure reflects the flow of features between low and high layers, as well as the fusion and transformation of features. The FPN module performs three upsampling operations, which can transfer more complex and abstract features from high-level feature maps to low-level layers for splicing. A lightweight and efficient dynamic upsampler Dysample is used for content-aware upsampling, combining high-level semantic information with low-level detail information, reducing the number of parameters, and improving performance.

[0036] Considering the heavy workload brought by dynamic convolution, the dynamic upsampler Dysample bypasses the kernel-based paradigm and returns to the essence of upsampling, i.e., point sampling, to redefine the upsampling process, reducing the number of parameters while improving performance. The implementation process is as shown in Figure 5 .

[0037] The dynamic upsampler Dysample uses a sampling set and PyTorch's built-in grid function to upsample the input continuous features to , where the sampling set generator generates the sampling set as shown in Figure 6As shown, the input feature is interpolated to a continuous feature X by a bilinear interpolation operation, a per-pixel offset O is generated by a linear projection, and the original mesh G is added to the per-pixel offset O to generate the content-aware sampling points, i.e., the sampling set S.

[0038] Figure 6 A specific implementation process of the sampling set generator is described: the process is given a parameter, i.e., an up-sampling scale factor s, and is given an input feature map X (with a size of CxHxW). In order to increase the flexibility of the offset, the input feature is linearly mapped by using linear layers linear1 and linear2, and the corresponding input and output channel numbers are C and 2s 2 , respectively, to generate a per-pixel "dynamic range factor", which is adjusted by using a sigmoid function and a 0.5 static factor, and a value in the range of [0, 0.5] centered on 0.25 is taken as a static range, to generate an offset o 2 with a size of 2s Figure 6 , where σ represents a sigmoid function, and the process can be represented as:

[0039] Then, o is reshaped to an offset O with a size of 2xsHx sW by pixel shuffling to meet the spatial size, and then the sampling set S is the sum of the offset O and the original sampling mesh G, and the process can be represented as:

[0040] In addition, the feature map can be divided into g groups along the channel dimension, and g groups of offsets are generated, where the features share the same sampling set in each group, and g is selected as 4 through experiments.

[0041] Given a feature map X with a size of CxH1xW1 and a sampling set S with a size of 2xH2xW2, 2 represents the x coordinate and the y coordinate, and the grid function is implemented: X is resampled to with a size of CxH2xW2 using the position information in S. As shown in Figure 3 , 4 , after obtaining the sampling set by the sampling point generator, the input feature X with a size of CxHxW can be resampled by the grid_sample mesh function to obtain the output feature with a size of CxsHxsW, which is represented as:

[0042] After the AD-Neck neck network is upsampled through the dynamic upsampler Dysample, the details in the deep features extracted by the backbone network are effectively recovered, and the detection capability of the model for the boundary contour of the small target cattle in the unmanned aerial vehicle and long-range scene is enhanced. The AD-Neck further combines the high-level semantic information with the low-level detail information, and effectively improves the detection performance of the small target cattle.

[0043] (2) Four-scale detection layer After the backbone network extracts feature maps of different scales, the AD-Neck neck network splices and fuses them, and the detection head Head detects the target. The AD-Neck neck network mainly realizes the fusion of shallow detail feature information and deep semantic feature information, and the backbone network is mainly divided into a shallow backbone network and a deep backbone network according to the extracted feature types; Figure 2 The feature maps of 160x160x128 and 80x80x256 belong to the shallow detail feature information output by the shallow backbone network; and the feature maps of 40x40x512 and 20x20x1024 belong to the deep semantic feature information output by the deep backbone network.

[0044] The shallow backbone network extracts detail features such as color, boundary, texture, etc. With the network deepening, the receptive field increases and the resolution decreases, and the deep backbone network extracts abstract semantic features, which will cause the perception ability and positioning accuracy of small size cattle targets to decrease.

[0045] In the traditional three-scale detection mechanism, after 8 times, 16 times and 32 times down-sampling, feature maps of 80x80, 40x40 and 20x20 scales are obtained to realize the detection of small, medium and large targets. However, in the actual pasture environment, the 80x80 detection layer will still miss and misdetect small target cattle, so the present application proposes a fourth scale detection layer, that is, an additional 160x160 scale detection layer. This large-scale detection layer can detect more boundary information and distribution position information of small target cattle in the pasture, and obtain more local context information, thereby improving the accuracy of small target cattle detection.

[0046] S2-3Shape-IoU bounding box regression loss The calculation of the bounding box regression loss is particularly important for improving the accuracy of small target cow detection, and therefore the Shape-IoU loss function is used for regression. The Shape-IoU loss function, which focuses on the shape and size of the bounding box itself, makes the bounding box regression more accurate, especially in unmanned aerial vehicle environments and long-range environments filled with small-scale cows, where the regression result of small-scale bounding boxes has a great influence on the target detection accuracy. The traditional YOLOv5 uses CIoU to calculate the bounding box loss, and many bounding box regression loss functions including CIoU are most concerned about the geometric relationship between the predicted box and the real box, and the relative position relationship between the two boxes, while ignoring the most important factor affected by the size change of the object itself, that is, the shape and size of the bounding box itself, which has a greater impact on the detection performance of small-scale targets. In contrast, the Shape-IoU loss function fully considers the shape and size of the bounding box itself, which has a significant impact on the regression result, especially in the case of small-scale bounding boxes. Therefore, using the Shape-IoU loss function can effectively improve the detection accuracy.

[0047] The calculation formula of the Shape-IoU loss function is as follows:

[0048] where IoU represents the overlap between the predicted box and the real box. distance shape represents the distance between the center points of the predicted box and the real box. Ω shape represents the shape consistency loss term, which is used to punish the deviation of the predicted box in width and height from the real box.

[0049] For a pair of real box and predicted box, the center point coordinates of the real box are , the height is , and the width is , the center point coordinates of the predicted box are , the height is h, and the width is w. The IoU in formula (4) is calculated by dividing the area of the overlapping part of the two rectangular boxes by the area of the set part of the two rectangular boxes. The specific calculation process of formula (4) is as follows:

[0050] The parameter c is the diagonal length of the smallest enclosing box obtained by enclosing the real box and the predicted box with the enclosing box. The parameter ww is the weight coefficient in the horizontal direction, and hh is the weight coefficient in the vertical direction. The values of these two are affected by the shape of the real box. When the real box is a square, ww and hh are both 1. The calculation process is shown in formula (7) and formula (8):

[0051]

[0052] The parameter scale is related to the scale of the target in the data set, and needs to be adjusted accordingly, which is called a scale factor. In target detection, the smaller the target, the greater the shape factor influence, and the scale needs to be increased accordingly.

[0053] After improving the C3M-Backbone and AD-Neck, realizing the simultaneous attention to global features and local features, focusing on detailed information, and effectively restoring detailed information, the Shape-IoU loss function which focuses on the shape and scale of the bounding box itself is used to reduce the sensitivity of small scale bounding boxes to the change of IoU value, and the accuracy of near and far view cattle and small target cattle detection is further improved.

[0054] S3, small target cattle detection model training based on MADS-YOLOv5s Randomly select 638 images of the UAV cattle detection data set UAV-Detection-797 proposed in S1 as the training set, and 159 images as the UAV test set UAV-Test-159. Randomly select 1040 images of the far view data set YuanJing-Detection-1155 as the training set, and 115 images as the far view test set YuanJing-Test-115, and perform model training and testing.

[0055] The GPU of the experimental server is NVIDIA GeForce RTX 3090, the deep learning framework used is Pytorch, the input image resolution is adjusted to 640*640, the training batch size is 32, the training round is 100 rounds, and the random gradient descent optimizer is selected to optimize the loss function.

[0056] S4, use the test set described in S1 to evaluate the performance of the model.

[0057] The MADS-YOLOv5s algorithm proposed in the application is compared with the YOLOv5s algorithm, the YOLOv8n algorithm and the SSD algorithm on the same UAV cattle detection data set, and multiple key indicators are analyzed and evaluated, including feature visualization, precision, recall and average precision mean, which verifies the superior performance of the MADS-YOLOv5s algorithm proposed in the application in the UAV small target cattle detection task. At the same time, in order to enrich the scene, the same comparative simulation experiment is also carried out on the established far view test set, which further verifies the superior performance of the MADS-YOLOv5s algorithm proposed in this chapter in small target cattle detection.

[0058] S4-1, feature visualization One image is selected from each of the two test sets to visually demonstrate the areas of interest for the four comparison algorithm models when processing images, and feature visualization heat maps are generated as shown in Figure 7 The red parts of the heat maps represent the areas that the detection models mainly focus on and learn from when detecting cattle, while the yellow-green parts represent the areas that the detection models pay less attention to when detecting cattle.

[0059] It can be seen that in the images of the two scenes, the SSD algorithm focuses on a large number of non-cattle areas, and has weak ability to distinguish between background and cattle, and insufficient learning of cattle features; the YOLOv8n algorithm pays a little more attention to the image, but still does not pay enough attention to small target cattle, and also pays attention to some unnecessary background areas; the YOLOv5s algorithm improves the distinction between cattle and background, but still does not pay enough attention to small target cattle; compared with other algorithms, the MADS-YOLOv5s algorithm proposed in this chapter can more accurately focus on small target cattle areas and suppress background interference, significantly distinguishing between cattle and background, and showing stronger resolution ability, thereby improving detection accuracy.

[0060] S4-2, Performance comparison The four algorithms were used to perform experiments on the UAV test set UAV-Test-159 and the YuanJing test set YuanJing-Test-115, and the precision P, recall R, and average precision mean mAP performances were compared, as shown in Tables 1 and 2.

[0061] Table 1 Comparison of detection performance of four algorithms on UAV test set UAV-Test-159

[0062] As can be seen from Table 1, the MADS-YOLOv5s algorithm achieved the best precision, recall, and average precision performance on the UAV test set. Compared with the YOLOv5s algorithm, it improved by 1.4%, 0.9%, and 2.0% respectively; compared with the YOLOv8n algorithm, it improved by 4.6%, 2.0%, and 3.4% respectively; compared with the SSD algorithm, it improved by 31.8%, 29.6%, and 33.2% respectively.

[0063] Table 2 Comparison of detection performance of four algorithms on YuanJing test set YuanJing-Test-115

[0064] As can be seen from Table 2, the MADS-YOLOv5s algorithm achieves the best precision, recall and average precision performance on the long-range test set. Compared with the YOLOv5s algorithm, it is increased by 4.7%, 3.8% and 4.4% respectively; compared with the YOLOv8n algorithm, it is increased by 5.3%, 5.8% and 4.9% respectively; compared with the SSD algorithm, it is increased by 43.2%, 35.6% and 36.2% respectively.

[0065] The above detailed description of the examples of the present application in combination with the drawings, but the present application is not limited to the above examples, within the knowledge possessed by those skilled in the art, various changes can also be made without departing from the purpose of the present application, and should be considered as the protection scope of the present application.

Claims

1. A small target detection method based on MADS-YOLOv5s, characterized by: The following steps are involved: Step 1: Collect cattle image data from drones and perspective cameras; Cameras were set up in open areas of four ranches to capture real-time images by pulling video streams. UAVs were also used to fly back and forth over the cattle areas under varying lighting conditions and ground conditions, generating datasets of cattle images captured by drones and using long-range cameras. Step 2: Establish a small target detection model based on MADS-YOLOv5s; Step 2-1: Establish a C3M-Backbone network that combines global and local features; Step 2-2: Establish an AD-Neck network, using the upsampler Dysample and the four-scale detection layer; Step 2-3: Establish a Shape-IoU loss function that focuses on the shape and scale of the bounding box itself; Step 3: Training and testing of small target detection model.

2. The small target detection method based on MADS-YOLOv5s according to claim 1, characterized in that Step 2-1 is implemented as follows: The C3M-Backbone network gradually expands the network depth and receptive field by cascading multiple layers of CBS standard convolutional modules and C3 modules with residual structures. The SPPF multi-scale feature pyramid module is introduced at the end to enhance semantic expression capabilities through cross-scale feature fusion. Ultimately, a lightweight backbone network architecture is formed that takes into account both refined local feature extraction and global spatial relationship modeling. The specific implementation of the C3M-Backbone network is as follows: The input image first passes through 2 layers of CBS standard convolution modules and 1 layer of C3 modules to extract feature map I, then passes through 1 layer of CBS standard convolution modules and 1 layer of C3 modules to extract feature map II, then passes through 1 layer of CBS standard convolution modules and 1 layer of C3 fusion lightweight ViT module to extract feature map III, and then passes through 1 layer of CBS standard convolution module, 1 layer of C3 module and 1 layer of SPPF multi-scale feature pyramid module to extract feature map IV. These four feature maps are subsequently input into the AD-Neck network for feature fusion; among them, the features of feature maps I and II are shallow detail feature information, and the features of feature maps III and IV are deep semantic feature information.

3. The small target detection method based on MADS-YOLOv5s according to claim 2, characterized in that The proposed C3-fused lightweight ViT module integrates a hybrid feature extraction unit of a convolutional neural network and a Transformer. Through the synergy of the Transformer's self-attention mechanism and convolution operations, it achieves bidirectional modeling of local details and global semantics of cattle images. The Transformer layer in the C3-fused lightweight ViT module is embedded in the traditional convolutional architecture as a dynamic convolution kernel, and the self-attention mechanism is used to calculate the global correlation of the input feature data. The specific structure of the C3-fused lightweight ViT module is as follows: This module uses a lightweight ViT module as the bottleneck layer. Its input feature maps are evenly divided into two groups. One group first passes through a layer of CBS standard convolution module and then through three layers of lightweight ViT modules; the other group passes through a layer of CBS standard convolution module; the output features of the two groups are then spliced, and the feature maps of different scales are spliced ​​in the channel dimension, and finally passed through a layer of CBS standard convolution layer before output.

4. The small target detection method based on MADS-YOLOv5s according to claim 3, characterized in that The specific structure of the lightweight ViT module is as follows: The input of this module is a feature map of size Cin×H×W, which enters the local representation block, extracts local spatial information through depth-wise separable convolution, and then fuses channel features with a convolution; the result is then sent to the global representation block, where the number of channels is first adjusted through a convolution, and then input into the stacked Transformer module to capture long-distance dependent global features, and finally a convolution is used to restore the channel dimension; after the local and global features are aligned by convolution, they are fused using addition in the fusion block and form a residual connection with the input of this module; the final output is a feature map of size Cout×H×W, which realizes the effective combination of local and global information in the lightweight network.

5. The small target detection method based on MADS-YOLOv5s according to claim 3, characterized in that In step S2-2, the AD-Neck network concatenates the multi-scale features extracted by the backbone network C3M-Backbone. The AD-Neck network uses a feature pyramid module for top-down feature fusion and a path aggregation module for bottom-up feature fusion to extract and fuse multi-scale features. In addition, the AD-Neck network uses a lightweight and efficient dynamic upsampler Dysample for content-aware upsampling in the feature pyramid and adopts a scale detection mechanism. (1) The implementation of the dynamic upsampler Dysample is as follows: The dynamic upsampler Dysample uses the sampling set and the built-in grid function of PyTorch to upsample the input continuous feature X to obtain the feature ; (2) Four-scale detection layer The backbone network is mainly divided into shallow backbone network and deep backbone network according to the type of extracted features. The features of feature map I and feature map II belong to the shallow detail feature information output by the shallow backbone network, and the features of feature map III and feature map IV belong to the deep semantic feature information output by the deep backbone network; feature map I, feature map II, feature map III and feature map IV constitute four-scale detection, among which feature map I is the proposed fourth-scale detection layer.

6. The small target detection method based on MADS-YOLOv5s according to claim 5, characterized in that Steps 2-3 are implemented as follows: The calculation formula of Shape-IoU loss function is as follows: ; Among them, IoU represents the degree of overlap between the predicted box and the real box; distance shape Represents the distance between the center point of the predicted box and the real box; Ω shape Represents the shape consistency loss term, which is used to penalize the deviation of the predicted box from the true box in width and height.

7. Small target detection system based on MADS-YOLOv5s, characterized by: include Data collection module: collects cattle image datasets in drone scenarios and cattle image datasets using long-range cameras; Small object detection model construction module: Build a small object detection model based on MADS-YOLOv5s; this model includes the C3M-Backbone backbone network that combines global and local features, an AD-Neck network using the upsampler Dysample and four-scale detection layers, and a Shape-IoU loss function that focuses on the shape and scale of the bounding box itself; Training and testing module: training and testing the small target detection model.