Sheep flock counting method, device and equipment based on small target detection and storage medium

Through the method based on small-object detection, drones collect and preprocess flock pictures, combined with the backbone network, neck network and detection head network, efficient and accurate flock count statistics in a dynamic environment, solving the problem of current There are problems with insufficient accuracy and efficiency of flock counting in the technology.

CN119251708APending Publication Date: 2025-01-03CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411253103.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-09
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

The prior art has shortcomings in accuracy, real-time and counting efficiency in flock counting, especially in dynamic detection and large-scale grassland flock movement environments, which are difficult to achieve efficient and accurate flock counting.

Method used

Using a method based on small-object detection, the grassland sheep pictures are collected through drones, and then pre-processed and inputted to the pre-constructed target detection model. The backbone network extracts multi-scale features, the neck network performs feature fusion, and the detection head network performs targets. Detect and adjust model parameters until the model converges, achieving accurate identification of the sheep population.

Benefits of technology

It improves the accuracy and efficiency of flock counting, can accurately identify the number of flocks in a dynamic environment, saves manpower and material resources, and operates simple and objectively.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119251708A_ABST
    Figure CN119251708A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of artificial intelligence and financial science and technology, and relates to a sheep flock counting method based on small target detection, which comprises the steps of preprocessing a collected original sample data set, obtaining a training set and a test set, training a pre-constructed initial target detection model by using the training set and the test set, and obtaining a final target detection model. The target detection model comprises a backbone network, a neck network and a detection head network, predicting the to-be-counted sheep flock pictures through the trained target detection model, and recognizing the number of the sheep flock in the pictures. The invention further provides a sheep flock counting device and equipment based on small target detection and a storage medium. In addition, the invention also relates to a block chain technology, and the target detection model can be stored in a block chain. The counting efficiency and accuracy can be improved, and manpower and material resources are saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the fields of artificial intelligence and financial technology, and in particular to a sheep counting method, device, equipment and storage medium based on small target detection. Background Art

[0002] The sheep industry is an important part of the herbivorous animal husbandry industry. Sheep insurance can effectively share the risks of farmers and protect their interests. Most sheep are raised on grasslands. Grassland sheep have a lot of exercise every day. Generally, sheep move about 20 kilometers a day. When taking out sheep insurance, it is necessary to verify the number of sheep. The traditional method of counting sheep is mainly based on manual counting. The original herders have thousands of sheep. Manual counting is time-consuming, consumes a lot of manpower, is inefficient, and is prone to errors.

[0003] With the development of science and technology, the current solutions for sheep counting mainly include radio frequency tag technology and computer vision technology. Radio frequency tag technology mainly involves installing RFID electronic tags on sheep and installing technical equipment at the entrance and exit channels of the sheep. This method has a single function, high cost, and is not convenient for relocation with the pasture, which limits its popularity in a wide range of applications. With the rapid development of computer vision technology, the combination of deep learning and visual technology has also brought new ideas to the field of sheep detection. At present, target detection can be achieved with the help of deep learning technology, such as RCNN, FastRCNN, Faster RCNN, etc., which can detect the number of static sheep more accurately, but the real-time and dynamic detection needs to be improved. Summary of the invention

[0004] The purpose of the embodiments of the present application is to propose a sheep counting method, device, equipment and storage medium based on small target detection, so as to solve the technical problems that need to be improved in the accuracy, real-time and counting efficiency of sheep counting in related technologies.

[0005] In order to solve the above technical problems, the embodiment of the present application provides a flock counting method based on small target detection, which adopts the following technical solution:

[0006] The original pictures of sheep herds on the grassland collected by the drone are obtained as the original sample data set, and the original sample set is preprocessed to obtain a training set and a test set;

[0007] Inputting the training set into a pre-built initial target detection model, wherein the initial target detection model includes a backbone network, a neck network, and a detection head network;

[0008] Extracting features of different scales from the sheep pictures in the training set through the backbone network to obtain multi-scale feature pictures;

[0009] Inputting the multi-scale feature image into the neck network for feature fusion enhancement to obtain a multi-scale fusion feature map;

[0010] Performing target detection on the multi-scale fusion feature map through the detection head network, and outputting a predicted target detection result, wherein the predicted target detection result includes a predicted target position and a target rotation angle;

[0011] Decoding the predicted target detection result to obtain a predicted rotation bounding box;

[0012] Calculating a loss value between the predicted rotation bounding box and the actual bounding box according to a preset loss function;

[0013] Adjusting the model parameters of the initial target detection model based on the loss value, continuing iterative training until the model converges, obtaining a model to be tested, and testing the model to be tested using the test set to obtain a final target detection model;

[0014] Obtain a picture of a flock of sheep to be counted, input the picture of the flock of sheep to be counted into the target detection model, and obtain a flock counting result.

[0015] In order to solve the above technical problems, the embodiment of the present application further provides a sheep counting device based on small target detection, which adopts the following technical solution:

[0016] A preprocessing module is used to obtain the original pictures of grassland sheep herds collected by the drone as the original sample data set, and preprocess the original sample set to obtain a training set and a test set;

[0017] An input module, used to input the training set into a pre-built initial target detection model, wherein the initial target detection model includes a backbone network, a neck network and a detection head network;

[0018] A feature extraction module, used to extract features of different scales from the sheep pictures in the training set through the backbone network to obtain multi-scale feature pictures;

[0019] A fusion module, used for inputting the multi-scale feature image into the neck network for feature fusion enhancement to obtain a multi-scale fusion feature map;

[0020] A target prediction module is used to perform target detection on the multi-scale fusion feature map through the detection head network, and output a predicted target detection result, wherein the predicted target detection result includes a predicted target position and a target rotation angle;

[0021] A decoding module, used to decode the predicted target detection result to obtain a predicted rotation bounding box;

[0022] A loss calculation module, used to calculate the loss value between the predicted rotation bounding box and the actual bounding box according to a preset loss function;

[0023] An iterative module, used for adjusting the model parameters of the initial target detection model based on the loss value, continuing the iterative training until the model converges, obtaining a model to be tested, and testing the model to be tested through the test set to obtain a final target detection model;

[0024] The target detection module is used to obtain the picture of the sheep flock to be counted, input the picture of the sheep flock to be counted into the target detection model, and obtain the sheep flock counting result.

[0025] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:

[0026] The computer device comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the sheep counting method based on small target detection as described above when executing the computer-readable instructions.

[0027] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:

[0028] The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the sheep counting method based on small target detection as described above are implemented.

[0029] Compared with the prior art, the embodiments of the present application have the following beneficial effects:

[0030] The present application provides a flock counting method based on small target detection. The method comprises the following steps: preprocessing the collected original sample data set to obtain a training set and a test set, using the training set and the test set to train a pre-built initial target detection model to obtain a final target detection model. The target detection model comprises a backbone network, a neck network and a detection head network. The trained target detection model is used to predict a flock picture to be counted, and the number of flocks in the picture is inferred. The present application can improve the picture quality and enhance the diversity of picture data and the generalization ability of the model by preprocessing the original sample data set. The backbone network is used to extract multi-scale features of the picture, which can enhance the multi-scale feature extraction ability, extract richer and more distinguishable features from the image, and help improve the accuracy of target detection. The neck network is used to fuse feature maps of different scales, enhance the dependency between features, balance the semantic information of the picture, and further improve the detection ability of the model for targets of different sizes. The detection head network is used to predict targets of different scales, which further improves the comprehensiveness and accuracy of target detection. The trained target detection model is used to identify the number of flocks, which can improve the efficiency and accuracy of counting, and the operation is simple, convenient and objective, saving a lot of manpower and material resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0032] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;

[0033] Figure 2 is a flow chart of an embodiment of a sheep counting method based on small target detection according to the present application;

[0034] Figure 3 It is a schematic diagram of the structure of a target detection model provided in this embodiment of the present application;

[0035] Figure 4 is a structural schematic diagram of an embodiment of a sheep counting device based on small target detection according to the present application;

[0036] Figure 5 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION

[0037] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.

[0038] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0039] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0040] like Figure 1 As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables.

[0041] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0042] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to a laptop computer 1011, a tablet computer 1012 or a mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.

[0043] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .

[0044] It should be noted that the sheep counting method based on small target detection provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the sheep counting device based on small target detection is generally arranged in the server / terminal device.

[0045] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0046] Continue to refer Figure 2 , shows a flow chart of an embodiment of a sheep counting method based on small target detection according to the present application, comprising the following steps:

[0047] Step S201, obtaining original pictures of grassland sheep herds collected by drones as original sample data sets, and preprocessing the original sample sets to obtain training sets and test sets.

[0048] According to the flight altitude and camera parameters of the drone, the geographical range of the shooting area is calculated to obtain the coordinates of the shooting area. The drone is used in automatic flight mode to collect images of the grassland target area according to the preset flight route and altitude, and a large number of original pictures of grassland sheep are obtained as the original sample data set.

[0049] It should be noted that if the drone collects video data, the video data is subjected to frame extraction to obtain the original image data set.

[0050] In order to improve the robustness of the model, it is necessary to shoot under different lighting conditions, such as morning, noon, and evening. In addition, it is also necessary to take pictures of scenes with mixed animals such as flocks of sheep, cattle, and horses.

[0051] In this embodiment, the collected original image data set is preprocessed, and the preprocessing includes: denoising, enhancement, pixel slicing, image expansion, image annotation and other processing methods.

[0052] In some optional implementations of this embodiment, the above step of preprocessing the original sample set to obtain the training set and the test set includes:

[0053] According to the preset image size, the original picture of the grassland sheep is sliced ​​pixel by pixel using the overlap strategy to obtain the segmented sheep picture;

[0054] Perform image expansion on the segmented sheep flock image to obtain an expanded sheep flock image;

[0055] The frequency domain homomorphic filtering method is used to perform image degradation screening on the expanded sheep flock pictures to obtain the screened sheep flock pictures;

[0056] Performing target labeling on the screened sheep flock pictures to obtain labeled sheep flock pictures, wherein the labeled classes are the sheep in the sheep flock pictures;

[0057] A flock dataset is constructed based on the labeled flock images, and the flock dataset is randomly divided into a training set and a test set according to a preset ratio.

[0058] First, the collected original images are cleaned to remove abnormal data and noise data to improve data quality.

[0059] Since the images collected by drones are relatively large, in order to facilitate subsequent processing, the original images need to be pixel sliced. The size of the slices can be cut according to the model's adaptation. For example, they can be uniformly cut into 512*512 pixel slices to obtain segmented sheep pictures.

[0060] When slicing, if there are sheep at the edge of the picture, it is easy to cut the whole sheep into pieces. Use the overlap strategy for pixel slicing. The overlap strategy usually means that when dividing an image into multiple slices, instead of directly truncating the edge of each slice, a certain number of pixels are extended so that adjacent slices share a part of the area. The purpose is to reduce the risk of objects at the image boundary being misclassified or omitted. For example, when pixel slicing the original picture of a flock of sheep on the grassland, 100 pixels are extended as the overlapping area for edge object filtering.

[0061] Image augmentation is a data enhancement technology that can generate more training samples by performing image transformations such as rotation, flipping, translation, scaling, and noise injection on images to achieve image augmentation, which helps improve the generalization ability of the model. Among them, rotation is to randomly rotate the image to a certain angle; flipping is to flip the image horizontally or vertically; translation is to apply a random translation transformation on the image; scaling is to change the size of the image; and noise injection is to add random noise to the image.

[0062] In this embodiment, the frequency domain homomorphic filtering method is used to perform image degradation screening on the expanded sheep flock picture, wherein homomorphic filtering is a filtering method for adjusting image brightness and contrast, and is particularly suitable for images with uneven lighting. Frequency domain homomorphic filtering decomposes the image in the frequency domain, then filters each frequency component, and finally re-synthesizes the filtered results into a picture.

[0063] The selected sheep pictures are labeled. In this embodiment, it is only necessary to label the sheep in the picture, that is, to label the sheep in the picture using a bounding box. Commonly used picture labeling tools, such as LabelImg labeling tool, ImgLab labeling tool, etc., can be used for labeling.

[0064] All the annotated sheep flock images are combined into a sheep flock data set, and the sheep flock data set is randomly divided into a training set and a test set according to a preset ratio. For example, the preset ratio is 8:2, that is, the ratio of the training set to the test set is 8:2.

[0065] By slicing the original image dataset into pixels, the adaptive learning of the model can be improved, which helps to improve the model's recognition accuracy for small targets and reduce computing resources. By expanding the image, the diversity of sample data can be increased, which can improve the generalization and robustness of the model and reduce the risk of overfitting. By labeling targets, features related to the detection targets can be learned to better distinguish targets of different categories. This can also help the model learn to accurately locate and identify detection targets in images, thereby improving the accuracy and stability of sheep detection.

[0066] Step S202: input the training set into a pre-built initial target detection model, wherein the initial target detection model includes a backbone network, a neck network, and a detection head network.

[0067] In this embodiment, the initial target detection model is an improved YOLOv8 network model, see Figure 3As shown in the figure, it includes a backbone network, a neck network and a detection head network. The backbone network (Backbone) is responsible for feature extraction of the input image, which is used to extract features such as edges and textures in the image. The feature map output by the backbone network will be passed to the neck network for further processing; the neck network (Neck) is mainly used to fuse the feature map output by the backbone network. Through upsampling, downsampling and other operations, feature maps of different scales are fused to improve the model's detection ability for objects of different sizes; the detection head network (Head) is used for category prediction and bounding box regression through multi-scale detection.

[0068] The CBAM attention mechanism is introduced into the backbone network, and the convolutional layer in the Bottleneck block is replaced with the Ghost structure. The ADA attention mechanism is introduced into the Bottleneck block; the convolutional layer in the neck network is replaced with the Ghost structure.

[0069] Among them, the CBAM attention mechanism performs attention inference at the channel and space levels, and is composed of two sub-modules: the channel attention module and the spatial attention module. Its basic principle is: for the feature map to be processed, the features are first enhanced in the channel domain, the processed feature map is multiplied with the original feature map, and then some features are enhanced and some features are weakened through the spatial domain. The feature map generated in this way effectively utilizes network resources and automatically infers the feature enhancement area and weakened area. The CBAM attention mechanism adopts the attention mechanism in the channel domain and the spatial domain respectively. Its main function is to make the feature map contain more or better express the features of the area of ​​interest of the target detector. In this way, it is beneficial for the target detection model to obtain more effective information under the limited ability to obtain information, thereby improving the detection performance of the model.

[0070] The ADA attention mechanism (Adaptive Dual-Level Attention Mechanism) includes a per-space attention mechanism and a per-channel attention mechanism; the per-space attention mechanism helps the model focus on the key areas of the image containing the target, ignoring background noise and irrelevant information; in the presence of occlusion, the per-space attention mechanism helps the model extract useful information from partially visible targets and improve detection accuracy. The per-channel attention mechanism evaluates the importance of each feature channel and adjusts the weight of the channel accordingly. This mechanism can enhance the model's sensitivity to key features of the target, such as identifying a specific shape or color of a target in a complex background.

[0071] Step S203, extracting features of different scales from the sheep pictures in the training set through the backbone network to obtain multi-scale feature pictures.

[0072] Among them, the backbone network includes a standard convolutional layer, a first convolutional fusion module, a second convolutional fusion module, a first CBAM attention mechanism layer, a third convolutional fusion module, a second CBAM attention mechanism layer, a fourth convolutional fusion module, an SPPF module and a third CBAM attention mechanism layer connected in sequence.

[0073] In this embodiment, the step of extracting features of different scales from the sheep pictures in the training set through the backbone network to obtain multi-scale feature pictures includes:

[0074] Performing a convolution operation on the sheep pictures in the training set through a standard convolution layer to obtain a standard convolution feature map;

[0075] Performing first-scale feature extraction on the standard convolution feature map through a first convolution fusion module to obtain a first-scale convolution feature map;

[0076] Performing second-scale feature extraction on the first-scale convolution feature map through a second convolution fusion module to obtain a second-scale convolution feature map;

[0077] Generate a first attention feature map according to the weights of each channel and spatial position in the second-scale convolutional feature map through the first CBAM attention mechanism layer, and input the first attention feature map into the third convolutional fusion module and the neck network;

[0078] Performing third-scale feature extraction on the first attention feature map through a third convolution fusion module to obtain a third-scale convolution feature map;

[0079] Generate a second attention feature map according to the weight of each channel and spatial position in the third scale convolution feature map through the second CBAM attention mechanism layer, and input the second attention feature map into the fourth convolution fusion module and the neck network;

[0080] Performing fourth-scale feature extraction on the second attention feature map through a fourth convolution fusion module to obtain a fourth-scale convolution feature map;

[0081] The fourth-scale convolution feature map is input into the SPPF module for spatial pyramid pooling operation to obtain multi-scale pooling features;

[0082] The third CBAM attention mechanism layer performs a mixed calculation of channel attention and spatial attention on the multi-scale pooling features to obtain a multi-scale feature image.

[0083] Among them, the standard convolution layer, the first convolution fusion module, the second convolution fusion module, the third convolution fusion module and the fourth convolution fusion module respectively perform feature extraction of different scales. For example, assuming that the input sheep flock picture size is 512×512, after convolution by the standard convolution layer, a feature map of 256×256×64 is output, after convolution operation by the first convolution fusion module, a feature map of 128×128×128 is output, after convolution operation by the second convolution fusion module, a feature map of 64×64×256 is output, after convolution operation by the third convolution fusion module, a feature map of 32×32×512 is output, and after convolution operation by the fourth convolution fusion module, a feature map of 16×16×512 is output.

[0084] In this embodiment, the backbone network that introduces the CBAM attention mechanism improves the efficiency, performance and feature expression ability of the backbone network through layer-by-layer feature extraction, parameter sharing, feature reuse and enhanced network depth, and has better effects in target detection tasks.

[0085] In some optional implementations, the first convolution fusion module, the second convolution fusion module, the third convolution fusion module and the fourth convolution fusion module independently include a convolution layer and a C2f module, respectively, wherein the C2f module includes a first convolution block, a channel splitting layer, a Bottleneck block, a connection layer, a second convolution block and an ADA attention mechanism layer connected end to end in sequence.

[0086] In this embodiment, the C2f module is an improved C2f module that introduces an ADA attention mechanism layer, which can directly connect a lower-level feature map to a higher-level feature map, thereby effectively retaining more spatial information.

[0087] The principles of feature extraction by the first convolution fusion module, the second convolution fusion module, the third convolution fusion module and the fourth convolution fusion module are the same. Taking the first convolution fusion module as an example, the process of feature extraction by the convolution fusion module is explained.

[0088] The step of extracting the first scale feature from the standard convolution feature map by the first convolution fusion module to obtain the first scale convolution feature map includes:

[0089] Perform convolution operation on the standard convolution feature map through the convolution layer to obtain the downsampled convolution feature map;

[0090] Input the downsampled convolution feature map into the first convolution block for convolution operation to obtain the basic feature map;

[0091] The basic feature map is segmented through the channel splitting layer to obtain a first feature segmentation map and a second feature segmentation map, and the first feature segmentation map is input to the Bottleneck block, and the second feature segmentation map is input to the connection layer;

[0092] Perform convolution enhancement on the first feature segmentation map through the Bottleneck block to obtain an enhanced convolution feature map;

[0093] The enhanced convolution feature map and the second feature segmentation map are spliced ​​through the connection layer to obtain an enhanced fusion feature map;

[0094] The enhanced fusion feature map is convolved through the second convolution block to obtain the final optimized feature map;

[0095] The ADA attention mechanism layer is used to calculate the attention of the final optimized feature map to obtain the first-scale convolutional feature map containing contextual information.

[0096] Among them, the first convolution block usually includes a convolution layer, a batch normalization layer (BatchNorm), and an activation function (such as ReLU or SiLU) to extract the basic features of the downsampled convolution feature map output by the convolution layer.

[0097] The channel splitting layer (Split layer) splits the input basic feature map in the channel dimension to obtain the first feature segmentation map and the second feature segmentation map. The first feature segmentation map is passed to the subsequent Bottleneck block for further processing, and the second feature segmentation map is directly passed to the final connection layer for feature fusion. This splitting and transmission mechanism helps to retain more spatial and semantic information, providing rich feature representation for subsequent feature fusion and detection tasks.

[0098] Bottleneck blocks usually adopt a bottleneck structure to reduce the computational complexity by reducing and restoring the number of channels. The enhanced convolution feature maps processed by the Bottleneck block are concatenated in the connection layer (Concat) to achieve feature fusion.

[0099] The concatenated enhanced fused feature map is input to the final second convolution block for further processing to generate the final output feature map. The structure of the second convolution block can be the same as the first convolution block, including a convolution layer, a batch normalization layer, and an activation function for the final processing and optimization of the fused feature map.

[0100] Finally, the ADA attention mechanism layer is used to perform attention calculation on the final optimized feature map to enhance the model's sensitivity to key features.

[0101] In this embodiment, by introducing the ADA attention mechanism in the C2f module, the model can be helped to better capture important features in the image, thereby improving the accuracy and performance of the model.

[0102] In some optional implementations, the Bottleneck block includes multiple Bottleneck layers connected in sequence, each Bottleneck layer includes a first Ghost sublayer, a second Ghost sublayer and an EMA attention mechanism sublayer. Specifically, the first feature segmentation map is input into the Bottleneck block, and features of the first feature segmentation map are extracted in sequence through multiple Bottleneck layers to obtain an enhanced convolutional feature map; wherein the input from the second Bottleneck layer to the last Bottleneck layer is the output feature of the previous Bottleneck layer and the concatenated feature of the first feature segmentation map.

[0103] Taking the first Bottleneck layer as an example, the steps of extracting features from the first feature segmentation map through the first Bottleneck layer include:

[0104] Performing a convolution operation on the first feature segmentation map through the first Ghost sublayer to obtain a first Ghost convolution feature map;

[0105] Performing a convolution operation on the first Ghost convolution feature map through the second Ghost sublayer to obtain a second Ghost convolution feature map;

[0106] Concatenate the first feature segmentation map and the second Ghost convolution feature map to obtain a concatenated feature map;

[0107] The concatenated feature map is input into the EMA attention mechanism sublayer for attention calculation to obtain the output features of the first Bottleneck layer.

[0108] In this embodiment, the Ghost structure is used to replace the original convolutional layer, which can significantly reduce the amount of calculation and parameters and improve the calculation efficiency. In addition, the EMA attention mechanism is introduced to perform moving average processing on the model parameters, effectively reducing the fluctuation of parameter updates.

[0109] In some optional implementations of this embodiment, the first Ghost sublayer and the second Ghost sublayer independently include an intrinsic convolution unit, a first ghost convolution unit, a BN and ReLU activation function, a depth-separable convolution unit, a second ghost convolution unit, a BN unit and a splicing unit. The step of performing a convolution operation on the first feature segmentation map through the first Ghost sublayer to obtain the first Ghost convolution feature map includes:

[0110] Input the first feature segmentation map into the intrinsic convolution layer for convolution to obtain an intrinsic feature map;

[0111] Input the intrinsic feature map into the first ghost convolution unit for processing to obtain the first feature;

[0112] The first feature is normalized by BN and ReLU activation functions to obtain normalized convolution features;

[0113] The normalized convolutional features are convolved channel by channel through the depth-wise separable convolutional unit to obtain the deep convolutional features;

[0114] Input the deep convolution feature into the second ghost convolution unit to obtain the optimized deep convolution feature;

[0115] The optimized deep convolution features are normalized through the BN unit to obtain a deep separable feature map;

[0116] The intrinsic feature map and the depth-separable feature map are spliced ​​and fused through the splicing unit to output the first Ghost convolutional feature map.

[0117] In this embodiment, the number of the Bottleneck layers in the Bottleneck block can be flexibly adjusted according to demand.

[0118] In some optional implementations of this embodiment, in order to further enhance the gradient flow and feature expression capabilities of the Bottleneck block, a residual connection can be introduced. This method helps to alleviate the gradient vanishing problem in deep networks and accelerate the network training process.

[0119] In this embodiment, the output of each Bottleneck layer is used as the input of the connection layer in the C2f module.

[0120] By performing feature extraction using the improved Bottleneck block, it is possible to reduce the number and complexity of parameters of the computational network while extracting feature information, thereby improving the detection speed of the computational network.

[0121] In this embodiment, the SPPF (Spatial Pyramid Pooling-Fast) module is used to perform a fast spatial pyramid pooling strategy on the feature map. Specifically, the SPPF module performs pooling operations of different sizes on the feature map and integrates the results to obtain an output of a fixed size. This technology can effectively handle targets of various sizes and fuse information of different scales together, thereby improving the generalization ability and robustness of the model.

[0122] In some optional implementations, the LSKA attention mechanism is added after the Concat structure of the SPPF module to improve the model's extraction of flock features. Among them, LSKA (Large Separable Kernel Attention) is an innovative large separable kernel attention module that captures long-range dependencies and adaptability by decomposing large kernel convolution operations, and at the same time decomposes the decomposed 2D convolution kernel into a series of 1D kernels, reducing computational complexity and memory requirements.

[0123] This application uses an improved backbone network for feature extraction, which can improve feature extraction capabilities, better capture complex features in images, and be more lightweight, thereby increasing computing speed.

[0124] Step S204: input the multi-scale feature image into the neck network for feature fusion enhancement to obtain a multi-scale fusion feature map.

[0125] The neck network is mainly used to fuse the feature maps output by the backbone network. Through upsampling, downsampling and other operations, feature maps of different scales are fused to improve the model's ability to detect objects of different sizes.

[0126] In this embodiment, the neck network includes a first neck branch and a second neck branch, the first neck branch includes a first upsampling module, a first C2f module combination, a second upsampling module and a second C2f module combination, and the second neck branch includes a first Ghost module, a third C2f module combination, a second Ghost module and a fourth C2f module combination.

[0127] Specifically, the multi-scale feature image is input into the first upsampling module and the second Ghost module; the multi-scale feature image and the second attention feature map are upsampled and fused through the first upsampling module to obtain a first upsampling fusion feature map; the first upsampling fusion feature map is convolved through the first C2f module combination to obtain a first C2f feature map, and the first C2f feature map is input into the first Ghost module and the second upsampling module; the first C2f feature map and the first attention feature map are upsampled and fused through the second upsampling module to obtain a second upsampling fusion feature map; the second upsampling fusion feature map is convolved through the second C2f module combination to obtain a second C2f feature map, and the second C2f feature map is input into the first Ghost module and the detection head network; the first Ghost module is used to perform a convolution operation on the first upsampling fusion feature map and the first attention feature map. A C2f feature map and a second C2f feature map are subjected to a Ghost convolution operation to obtain a first Ghost convolution splicing feature map; a third C2f module combination is used to perform a convolution operation on the first Ghost convolution splicing feature map to obtain a third C2f feature map, and the third C2f feature map is input into the detection head network and the second Ghost module; a second Ghost module is used to perform a Ghost convolution operation on the third C2f feature map and a multi-scale feature image to obtain a second Ghost convolution splicing feature map; a fourth C2f module combination is used to perform a convolution operation on the second Ghost convolution splicing feature map to obtain a fourth C2f feature map, and the fourth C2f feature map is input into the detection head network; wherein the second C2f feature map, the third C2f feature map and the fourth C2f feature map constitute a multi-scale fusion feature map.

[0128] In this embodiment, the first C2f module combination, the second C2f module combination, the third C2f module combination and the fourth C2f module combination independently include a connection layer and a C2f module, and the structure of the C2f module adopts the same structure as the C2f module in the backbone network. Specifically, the connection layer in the first C2f module combination is connected to the second CBAM attention mechanism layer of the backbone network, and the connection layer in the second C2f module combination is connected to the first CBAM attention mechanism layer of the backbone network; the output of the third CBAM attention mechanism layer of the backbone network is respectively used as the input of the connection layer of the first upsampling module and the fourth C2f module combination; the input of the connection layer of the third C2f module combination is the output of the C2f module in the first C2f module combination and the first Ghost module.

[0129] In this embodiment, the first Ghost module and the second Ghost module independently include an intrinsic convolution layer, a first ghost convolution layer, a BN and ReLU activation function, a depth-separable convolution layer, a second ghost convolution layer, a BN layer and a splicing layer.

[0130] By performing feature fusion and enhancement at different levels through the improved neck network, the model's ability to detect targets of different scales can be improved, and the number of channels of the feature map can be reduced to reduce the computational complexity.

[0131] Step S205, performing target detection on the multi-scale fusion feature map through the detection head network, and outputting a predicted target detection result, where the predicted target detection result includes a predicted target position and a target rotation angle.

[0132] The detection head network is a key part of directional target detection. The detection head network adds a feature map for predicting rotation angles. Each scale feature map will generate a predicted feature map through a series of convolutional layers. These predicted feature maps contain information such as the target category, the target location (center point coordinates, width and height), and the rotation angle.

[0133] In this embodiment, the detection head network includes three detection heads, namely a first detection head, a second detection head and a third detection head, wherein each detection head includes a target category prediction branch and a bounding box prediction branch.

[0134] Three detection heads are used to detect targets of different scales: the first detection head is responsible for detecting large-sized targets, which can increase the model's ability to detect large targets; the second detection head is responsible for detecting medium-sized targets, which helps the model locate medium-sized targets more accurately; the third detection head is responsible for detecting small-sized targets, which can improve the model's detection sensitivity to small targets.

[0135] Specifically, through the target category prediction branch and the bounding box prediction branch of the first detection head, target category prediction and bounding box prediction are performed according to the second C2f feature map to obtain a first target feature map; through the target category prediction branch and the bounding box prediction branch of the second detection head, target category prediction and bounding box prediction are performed according to the third C2f feature map to obtain a second target feature map; through the target category prediction branch and the bounding box prediction branch of the third detection head, target category prediction and bounding box prediction are performed according to the fourth C2f feature map to obtain a third target feature map; the first target feature map, the second target feature map and the third target feature map are spliced ​​and output to obtain a predicted target detection result.

[0136] Among them, the bounding box prediction branch includes a convolutional layer, a 2D convolutional layer, and a Bbox Loss layer connected end to end in sequence; the target category prediction branch includes a convolutional layer, a 2D convolutional layer, and a Cls Loss layer connected end to end in sequence.

[0137] The convolutional layer and 2D convolutional layer in each detection head are used to extract and integrate the information on the feature map to generate the final detection result. The bounding box prediction branch outputs the regression value of the bounding box, including the center point coordinates, width, height and possible rotation angle (for the oriented bounding box OBB) of the bounding box; the target category prediction branch outputs the category prediction of the target in each bounding box.

[0138] By outputting the target detection results through the detection head network, the flock can be detected accurately and efficiently, improving the accuracy of the detection results.

[0139] Step S206: decode the predicted target detection result to obtain a predicted rotation bounding box.

[0140] In this embodiment, the output predicted target detection result is decoded and filtered to obtain a final oriented bounding box (OBB), that is, a predicted rotation bounding box.

[0141] The decoding process includes converting the predicted target position, including the center point coordinates, width, height and target rotation angle, into the four corner coordinates of the rotated bounding box, and determining the position of the predicted rotated bounding box based on the coordinates; the filtering process removes redundant bounding boxes through the non-maximum suppression (NMS) algorithm to obtain the final detection result. The final detection result is output in the form of a rotated bounding box, each of which contains the target category, confidence score, and precise location and orientation information.

[0142] Step S207: Calculate the loss value between the predicted rotated bounding box and the actual bounding box according to a preset loss function.

[0143] In this embodiment, the preset loss function uses a confidence loss function to evaluate the accuracy of the model output.

[0144] Specifically, the Bbox Loss (bounding box regression loss) layer is used to calculate the bounding box regression loss, that is, the difference between the predicted bounding box and the true bounding box. The mean square error (MSE) is a commonly used loss function that assigns higher penalties when the error is large, which helps the model to quickly correct large prediction errors. Therefore, Bbox Loss calculates the sum of the squares of the differences between the predicted and actual coordinates. The specific calculation formula is as follows:

[0145]

[0146] Among them, x i represents the position of the actual bounding box; Represents the position of the predicted rotated bounding box; i represents the i-th coordinate of the bounding box; N represents the number of coordinates (including the coordinates of all corner points and the center of the bounding box).

[0147] The Cls Loss layer is used to calculate the classification loss, which is used to measure the difference between the category distribution predicted by the model and the true label. The cross entropy loss function is a commonly used loss function in classification tasks, which gives a large penalty for wrong predictions, especially when the predicted probability is very different from the actual label. Therefore, the Cls Loss layer helps the model optimize its predictions in classification problems, making the predicted probability distribution as close to the true label distribution as possible. The specific calculation formula is as follows:

[0148]

[0149] Among them, y o,c is an indicator, which is 1 if the object o belongs to category c (sheep), otherwise it is 0; p o represents the predicted probability that the target o belongs to the category c; M represents the number of targets.

[0150] The confidence calculation formula is as follows:

[0151]

[0152] In the formula, Represents the intersection-over-union ratio of the predicted rotated bounding box and the actual bounding box.

[0153] The confidence is taken as the loss value between the predicted rotated bounding box and the actual bounding box.

[0154] Step S208, adjust the model parameters of the initial target detection model based on the loss value, continue iterative training until the model converges, obtain the model to be tested, and test the model to be tested through the test set to obtain the final target detection model.

[0155] The condition for model convergence is that the loss value does not change significantly or the number of iterations reaches the preset number.

[0156] Use the test set to test the model to be tested to obtain the prediction accuracy. When the prediction accuracy is greater than or equal to the preset threshold, the model to be tested is output as the target detection model; when the prediction accuracy is less than the preset threshold, it is necessary to increase the number of samples, or modify the model parameters and retrain.

[0157] The prediction accuracy is the intersection-over-union ratio of the predicted box and the actual box. When the intersection-over-union ratio is greater than or equal to 0.8, the model to be tested is output as the target detection model.

[0158] It should be emphasized that in order to further ensure the privacy and security of the target detection model, the above target detection model can also be stored in a blockchain node.

[0159] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.

[0160] Step S209, obtaining a picture of the sheep herd to be counted, inputting the picture of the sheep herd to be counted into the target detection model, and obtaining a sheep herd counting result.

[0161] The image of the sheep to be counted is preprocessed and then input into the trained object detection model, which can quickly and accurately identify the number of sheep in the image. Specifically, the model can identify and calculate the number of frames of the entire sheep in the entire large image, and the number of frames is the number of sheep.

[0162] Counting sheep through the target detection model can be used as a basis for sheep insurance or claims, which is conducive to the accurate verification of insurance companies in the underwriting process and is also conducive to the standardized development of the sheep farming industry.

[0163] This application can improve the image quality by preprocessing the original sample data set, while enhancing the diversity of image data and improving the generalization ability of the model; multi-scale feature extraction of images through the backbone network can enhance the multi-scale feature extraction ability, extract richer and more distinctive features from the image, and help improve the accuracy of target detection; feature maps of different scales are fused through the neck network to enhance the dependency between features to balance the semantic information of the image, thereby improving the model's detection ability for targets of different sizes; targets of different scales are predicted through the detection head network, further improving the comprehensiveness and accuracy of target detection; using the trained target detection model to identify the number of sheep in a flock can improve the efficiency and accuracy of counting, and the operation is simple, convenient and objective, saving a lot of manpower and material resources.

[0164] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0165] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0166] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

[0167] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0168] Further references Figure 4 , as a response to the above Figure 2 The present application provides an embodiment of a sheep counting device based on small target detection, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0169] like Figure 4 As shown, the sheep counting device 400 based on small target detection described in this embodiment includes: a preprocessing module 401, an input module 402, a feature extraction module 403, a fusion module 404, a target prediction module 405, a decoding module 406, a loss calculation module 407, an iteration module 408 and a target detection module 409. Among them:

[0170] The preprocessing module 401 is used to obtain the original pictures of the grassland sheep herd collected by the drone as the original sample data set, and preprocess the original sample set to obtain a training set and a test set;

[0171] The input module 402 is used to input the training set into a pre-built initial target detection model, wherein the initial target detection model includes a backbone network, a neck network and a detection head network;

[0172] The feature extraction module 403 is used to extract features of different scales from the sheep pictures in the training set through the backbone network to obtain multi-scale feature pictures;

[0173] The fusion module 404 is used to input the multi-scale feature image into the neck network for feature fusion enhancement to obtain a multi-scale fusion feature map;

[0174] The target prediction module 405 is used to perform target detection on the multi-scale fusion feature map through the detection head network, and output a predicted target detection result, wherein the predicted target detection result includes a predicted target position and a target rotation angle;

[0175] The decoding module 406 is used to decode the predicted target detection result to obtain a predicted rotation bounding box;

[0176] The loss calculation module 407 is used to calculate the loss value between the predicted rotation bounding box and the actual bounding box according to a preset loss function;

[0177] The iteration module 408 is used to adjust the model parameters of the initial target detection model based on the loss value, continue iterative training until the model converges, obtain the model to be tested, and test the model to be tested through the test set to obtain the final target detection model;

[0178] The target detection module 409 is used to obtain a picture of a flock of sheep to be counted, input the picture of the flock of sheep to be counted into the target detection model, and obtain a flock counting result.

[0179] Based on the above-mentioned sheep counting device 300 based on small target detection, by preprocessing the original sample data set, it is possible to improve the image quality, enhance the diversity of the image data, and improve the generalization ability of the model; by extracting multi-scale features of the image through the backbone network, it is possible to enhance the multi-scale feature extraction capability, extract richer and more distinctive features from the image, and help improve the accuracy of target detection; by fusing feature maps of different scales through the neck network, the dependency between features is enhanced to balance the semantic information of the image, thereby improving the model's detection capability for targets of different sizes; by predicting targets of different scales through the detection head network, the comprehensiveness and accuracy of target detection are further improved; using the trained target detection model to identify the number of sheep can improve the efficiency and accuracy of counting, and the operation is simple, convenient and objective, saving a lot of manpower and material resources.

[0180] In some optional implementations, the preprocessing module 401 includes:

[0181] A slicing submodule is used to perform pixel slicing on the original picture of the grassland sheep herd according to a preset image size through an overlap strategy to obtain a segmented sheep herd picture;

[0182] An image expansion submodule, used for performing image expansion on the segmented sheep flock image to obtain an expanded sheep flock image;

[0183] A filtering submodule, for performing image degradation screening on the expanded sheep flock picture by using a frequency domain homomorphic filtering method to obtain a screened sheep flock picture;

[0184] A labeling submodule is used to label the selected sheep flock pictures to obtain labeled sheep flock pictures, wherein the labeled categories are the sheep in the sheep flock pictures;

[0185] The partitioning submodule is used to construct a flock data set according to the labeled flock images, and randomly divide the flock data set into a training set and a test set according to a preset ratio.

[0186] By preprocessing the original image dataset, the adaptive learning of the model can be improved, which helps to improve the model's recognition accuracy for small targets, reduce computing resources, increase the diversity of sample data, improve the generalization ability and robustness of the model, and reduce the risk of overfitting.

[0187] In some optional implementations, the backbone network includes a standard convolution layer, a first convolution fusion module, a second convolution fusion module, a first CBAM attention mechanism layer, a third convolution fusion module, a second CBAM attention mechanism layer, a fourth convolution fusion module, an SPPF module and a third CBAM attention mechanism layer, and the feature extraction module 403 is used to:

[0188] Performing a convolution operation on the sheep flock pictures in the training set through the standard convolution layer to obtain a standard convolution feature map;

[0189] Performing first-scale feature extraction on the standard convolution feature map through the first convolution fusion module to obtain a first-scale convolution feature map;

[0190] Performing second-scale feature extraction on the first-scale convolution feature map through the second convolution fusion module to obtain a second-scale convolution feature map;

[0191] Generate a first attention feature map according to the weight of each channel and spatial position in the second scale convolution feature map through the first CBAM attention mechanism layer, and input the first attention feature map into the third convolution fusion module and the neck network;

[0192] Performing third-scale feature extraction on the first attention feature map through the third convolution fusion module to obtain a third-scale convolution feature map;

[0193] Generate a second attention feature map according to the weight of each channel and spatial position in the third scale convolution feature map through the second CBAM attention mechanism layer, and input the second attention feature map into the fourth convolution fusion module and the neck network;

[0194] Performing fourth-scale feature extraction on the second attention feature map through the fourth convolution fusion module to obtain a fourth-scale convolution feature map;

[0195] Inputting the fourth-scale convolution feature map into the SPPF module to perform a spatial pyramid pooling operation to obtain a multi-scale pooling feature;

[0196] The multi-scale pooling features are subjected to a mixed calculation of channel attention and spatial attention through the third CBAM attention mechanism layer to obtain a multi-scale feature picture.

[0197] By performing feature extraction through an improved backbone network, the feature extraction capability can be improved, the complex features in the image can be better captured, and the network can be made lighter and the calculation speed can be increased.

[0198] In some optional implementations of this embodiment, the first convolution fusion module, the second convolution fusion module, the third convolution fusion module and the fourth convolution fusion module independently include a convolution layer and a C2f module, wherein the C2f module includes a first convolution block, a channel splitting layer, a Bottleneck block, a connection layer, a second convolution block and an ADA attention mechanism layer connected end to end in sequence, and the feature extraction module 403 is further used to:

[0199] Performing a convolution operation on the standard convolution feature map through the convolution layer to obtain a downsampled convolution feature map;

[0200] Inputting the downsampled convolution feature map into the first convolution block for convolution operation to obtain a basic feature map;

[0201] Perform channel segmentation on the basic feature map through the channel splitting layer to obtain a first feature segmentation map and a second feature segmentation map, and input the first feature segmentation map to the Bottleneck block, and input the second feature segmentation map to the connection layer;

[0202] Performing convolution enhancement on the first feature segmentation map by using the Bottleneck block to obtain an enhanced convolution feature map;

[0203] splicing the enhanced convolution feature map and the second feature segmentation map through the connection layer to obtain an enhanced fusion feature map;

[0204] Performing convolution processing on the enhanced fusion feature map through the second convolution block to obtain a final optimized feature map;

[0205] The ADA attention mechanism layer performs attention calculation on the final optimized feature map to obtain a first-scale convolutional feature map containing context information.

[0206] By introducing the ADA attention mechanism in the C2f module, the model can better capture important features in the image, thereby improving the accuracy and performance of the model.

[0207] In some optional implementations of this embodiment, the Bottleneck block includes a plurality of sequentially connected Bottleneck layers, each of which includes a first Ghost sublayer, a second Ghost sublayer, and an EMA attention mechanism sublayer, and the feature extraction module 403 is further used to:

[0208] Input the first feature segmentation map into the Bottleneck block, and extract features from the first feature segmentation map in sequence through the multiple Bottleneck layers to obtain an enhanced convolution feature map; wherein the input from the second Bottleneck layer to the last Bottleneck layer is the output feature of the previous Bottleneck layer and the concatenated feature of the first feature segmentation map;

[0209] The steps for generating the output features of the first Bottleneck layer include:

[0210] Performing a convolution operation on the first feature segmentation map through the first Ghost sublayer to obtain a first Ghost convolution feature map;

[0211] Performing a convolution operation on the first Ghost convolution feature map through the second Ghost sublayer to obtain a second Ghost convolution feature map;

[0212] Splicing the first feature segmentation map and the second Ghost convolution feature map to obtain a spliced ​​feature map;

[0213] The concatenated feature map is input into the EMA attention mechanism sublayer for attention calculation to obtain the output feature of the first Bottleneck layer.

[0214] By performing feature extraction using the improved Bottleneck block, it is possible to reduce the number and complexity of parameters of the computational network while extracting feature information, thereby improving the detection speed of the computational network.

[0215] In some optional implementations, the neck network includes a first neck branch and a second neck branch, the first neck branch includes a first upsampling module, a first C2f module combination, a second upsampling module and a second C2f module combination, the second neck branch includes a first Ghost module, a third C2f module combination, a second Ghost module and a fourth C2f module combination, and the fusion module 404 is used to:

[0216] Inputting the multi-scale feature image into the first upsampling module and the second Ghost module;

[0217] Upsampling and fusing the multi-scale feature image and the second attention feature map through the first upsampling module to obtain a first upsampling fused feature map;

[0218] Performing a convolution operation on the first up-sampled fusion feature map through the first C2f module combination to obtain a first C2f feature map, and inputting the first C2f feature map into the first Ghost module and the second up-sampling module;

[0219] Upsampling and fusing the first C2f feature map and the first attention feature map through the second upsampling module to obtain a second upsampling fused feature map;

[0220] Performing a convolution operation on the second upsampled fusion feature map through the second C2f module combination to obtain a second C2f feature map, and inputting the second C2f feature map into the first Ghost module and the detection head network;

[0221] Performing a Ghost convolution operation on the first C2f feature map and the second C2f feature map through the first Ghost module to obtain a first Ghost convolution splicing feature map;

[0222] Performing a convolution operation on the first Ghost convolution splicing feature map through the third C2f module combination to obtain a third C2f feature map, and inputting the third C2f feature map into the detection head network and the second Ghost module;

[0223] Performing a Ghost convolution operation on the third C2f feature map and the multi-scale feature image through the second Ghost module to obtain a second Ghost convolution splicing feature map;

[0224] The second Ghost convolutional splicing feature map is convolved by the fourth C2f module combination to obtain a fourth C2f feature map, and the fourth C2f feature map is input into the detection head network; wherein the second C2f feature map, the third C2f feature map and the fourth C2f feature map constitute the multi-scale fusion feature map.

[0225] By performing feature fusion and enhancement at different levels through the improved neck network, the model's ability to detect targets of different scales can be improved, and the number of channels of the feature map can be reduced to reduce the computational complexity.

[0226] In some optional implementations, the detection head network includes three detection heads, namely a first detection head, a second detection head and a third detection head, wherein each detection head includes a target category prediction branch and a bounding box prediction branch; the target prediction module 405 is used to:

[0227] Performing target category prediction and bounding box prediction according to the second C2f feature map through the target category prediction branch and the bounding box prediction branch of the first detection head to obtain a first target feature map;

[0228] Performing target category prediction and bounding box prediction according to the third C2f feature map through the target category prediction branch and the bounding box prediction branch of the second detection head to obtain a second target feature map;

[0229] Performing target category prediction and bounding box prediction according to the fourth C2f feature map through the target category prediction branch and the bounding box prediction branch of the third detection head to obtain a third target feature map;

[0230] The first target feature map, the second target feature map and the third target feature map are spliced ​​and output to obtain a predicted target detection result.

[0231] By outputting the target detection results through the detection head network, the flock can be detected accurately and efficiently, improving the accuracy of the detection results.

[0232] To solve the above technical problems, the present application also provides a computer device. Figure 5 , Figure 5 This is a basic structural block diagram of the computer device in this embodiment.

[0233] The computer device 5 includes a memory 51, a processor 52, and a network interface 53 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 5 with a memory 51, a processor 52, and a network interface 53, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.

[0234] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.

[0235] The memory 51 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 51 can be an internal storage unit of the computer device 5, such as a hard disk or memory of the computer device 5. In other embodiments, the memory 51 can also be an external storage device of the computer device 5, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. equipped on the computer device 5. Of course, the memory 51 can also include both the internal storage unit of the computer device 5 and its external storage device. In this embodiment, the memory 51 is generally used to store the operating system and various application software installed on the computer device 5, such as computer-readable instructions of a flock counting method based on small target detection, etc. In addition, the memory 51 can also be used to temporarily store various types of data that have been output or are to be output.

[0236] The processor 52 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 52 is generally used to control the overall operation of the computer device 5. In this embodiment, the processor 52 is used to run computer-readable instructions or process data stored in the memory 51, such as computer-readable instructions for running the sheep counting method based on small target detection.

[0237] The network interface 53 may include a wireless network interface or a wired network interface. The network interface 53 is generally used to establish a communication connection between the computer device 5 and other electronic devices.

[0238] By preprocessing the original sample data set, the image quality can be improved, the diversity of image data can be enhanced, and the generalization ability of the model can be improved; multi-scale feature extraction of images through the backbone network can enhance the multi-scale feature extraction ability, extract richer and more distinctive features from the image, and help improve the accuracy of target detection; feature maps of different scales are fused through the neck network to enhance the dependency between features to balance the semantic information of the image, thereby improving the model's detection ability for targets of different sizes; targets of different scales are predicted through the detection head network, further improving the comprehensiveness and accuracy of target detection; using the trained target detection model to identify the number of sheep in the flock can improve the efficiency and accuracy of counting, and the operation is simple, convenient and objective, saving a lot of manpower and material resources.

[0239] The present application also provides another embodiment, namely, providing a computer-readable storage medium, which stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the sheep counting method based on small target detection as described above.

[0240] By preprocessing the original sample data set, the image quality can be improved, the diversity of image data can be enhanced, and the generalization ability of the model can be improved; multi-scale feature extraction of images through the backbone network can enhance the multi-scale feature extraction ability, extract richer and more distinctive features from the image, and help improve the accuracy of target detection; feature maps of different scales are fused through the neck network to enhance the dependency between features to balance the semantic information of the image, thereby improving the model's detection ability for targets of different sizes; targets of different scales are predicted through the detection head network, further improving the comprehensiveness and accuracy of target detection; using the trained target detection model to identify the number of sheep in the flock can improve the efficiency and accuracy of counting, and the operation is simple, convenient and objective, saving a lot of manpower and material resources.

[0241] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0242] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.

Claims

1. A sheep counting method based on small target detection, characterized in that: The steps include: The original pictures of sheep herds on the grassland collected by the drone are obtained as the original sample data set, and the original sample set is preprocessed to obtain a training set and a test set; Inputting the training set into a pre-built initial target detection model, wherein the initial target detection model includes a backbone network, a neck network, and a detection head network; Extracting features of different scales from the sheep pictures in the training set through the backbone network to obtain multi-scale feature pictures; Inputting the multi-scale feature image into the neck network for feature fusion enhancement to obtain a multi-scale fusion feature map; Performing target detection on the multi-scale fusion feature map through the detection head network, and outputting a predicted target detection result, wherein the predicted target detection result includes a predicted target position and a target rotation angle; Decoding the predicted target detection result to obtain a predicted rotation bounding box; Calculating a loss value between the predicted rotation bounding box and the actual bounding box according to a preset loss function; Adjusting the model parameters of the initial target detection model based on the loss value, continuing iterative training until the model converges, obtaining a model to be tested, and testing the model to be tested using the test set to obtain a final target detection model; Obtain a picture of a flock of sheep to be counted, input the picture of the flock of sheep to be counted into the target detection model, and obtain a flock counting result.

2. The sheep counting method based on small target detection according to claim 1 is characterized in that: The step of preprocessing the original sample set to obtain a training set and a test set comprises: According to the preset image size, the original picture of the grassland sheep herd is pixel-sliced ​​by using the overlap strategy to obtain a segmented sheep herd picture; Performing image expansion on the segmented sheep flock picture to obtain an expanded sheep flock picture; Using a frequency domain homomorphic filtering method, the expanded sheep flock picture is subjected to image degradation screening to obtain a screened sheep flock picture; Performing target labeling on the screened sheep flock pictures to obtain labeled sheep flock pictures, wherein the labeled classes are the sheep in the sheep flock pictures; A flock data set is constructed according to the labeled flock images, and the flock data set is randomly divided into a training set and a test set according to a preset ratio.

3. The sheep counting method based on small target detection according to claim 1 is characterized in that: The backbone network includes a standard convolution layer, a first convolution fusion module, a second convolution fusion module, a first CBAM attention mechanism layer, a third convolution fusion module, a second CBAM attention mechanism layer, a fourth convolution fusion module, an SPPF module and a third CBAM attention mechanism layer. The step of extracting features of different scales from the sheep pictures in the training set through the backbone network to obtain a multi-scale feature picture includes: Performing a convolution operation on the sheep flock pictures in the training set through the standard convolution layer to obtain a standard convolution feature map; Performing first-scale feature extraction on the standard convolution feature map through the first convolution fusion module to obtain a first-scale convolution feature map; Performing second-scale feature extraction on the first-scale convolution feature map through the second convolution fusion module to obtain a second-scale convolution feature map; Generate a first attention feature map according to the weight of each channel and spatial position in the second scale convolution feature map through the first CBAM attention mechanism layer, and input the first attention feature map into the third convolution fusion module and the neck network; Performing third-scale feature extraction on the first attention feature map through the third convolution fusion module to obtain a third-scale convolution feature map; Generate a second attention feature map according to the weight of each channel and spatial position in the third scale convolution feature map through the second CBAM attention mechanism layer, and input the second attention feature map into the fourth convolution fusion module and the neck network; Performing fourth-scale feature extraction on the second attention feature map through the fourth convolution fusion module to obtain a fourth-scale convolution feature map; Inputting the fourth-scale convolution feature map into the SPPF module to perform a spatial pyramid pooling operation to obtain a multi-scale pooling feature; The multi-scale pooling features are subjected to a mixed calculation of channel attention and spatial attention through the third CBAM attention mechanism layer to obtain a multi-scale feature picture.

4. The sheep counting method based on small target detection according to claim 3 is characterized in that: The first convolution fusion module, the second convolution fusion module, the third convolution fusion module and the fourth convolution fusion module independently include convolution layers and C2f modules, respectively, wherein the C2f module includes a first convolution block, a channel splitting layer, a Bottleneck block, a connection layer, a second convolution block and an ADA attention mechanism layer connected end to end in sequence, and the step of extracting first-scale features from the standard convolution feature map through the first convolution fusion module to obtain a first-scale convolution feature map includes: Performing a convolution operation on the standard convolution feature map through the convolution layer to obtain a downsampled convolution feature map; Inputting the downsampled convolution feature map into the first convolution block for convolution operation to obtain a basic feature map; Perform channel segmentation on the basic feature map through the channel splitting layer to obtain a first feature segmentation map and a second feature segmentation map, and input the first feature segmentation map to the Bottleneck block, and input the second feature segmentation map to the connection layer; Performing convolution enhancement on the first feature segmentation map by using the Bottleneck block to obtain an enhanced convolution feature map; splicing the enhanced convolution feature map and the second feature segmentation map through the connection layer to obtain an enhanced fusion feature map; Performing convolution processing on the enhanced fusion feature map through the second convolution block to obtain a final optimized feature map; The ADA attention mechanism layer performs attention calculation on the final optimized feature map to obtain a first-scale convolutional feature map containing context information.

5. The sheep counting method based on small target detection according to claim 4 is characterized in that: The Bottleneck block includes a plurality of sequentially connected Bottleneck layers, each of which includes a first Ghost sublayer, a second Ghost sublayer, and an EMA attention mechanism sublayer. The step of performing convolution enhancement on the first feature segmentation map through the Bottleneck block to obtain an enhanced convolution feature map includes: Input the first feature segmentation map into the Bottleneck block, and extract features from the first feature segmentation map in sequence through the multiple Bottleneck layers to obtain an enhanced convolution feature map; wherein the input from the second Bottleneck layer to the last Bottleneck layer is the output feature of the previous Bottleneck layer and the concatenated feature of the first feature segmentation map; The steps for generating the output features of the first Bottleneck layer include: Performing a convolution operation on the first feature segmentation map through the first Ghost sublayer to obtain a first Ghost convolution feature map; Performing a convolution operation on the first Ghost convolution feature map through the second Ghost sublayer to obtain a second Ghost convolution feature map; Splicing the first feature segmentation map and the second Ghost convolution feature map to obtain a spliced ​​feature map; The concatenated feature map is input into the EMA attention mechanism sublayer for attention calculation to obtain the output feature of the first Bottleneck layer.

6. The sheep counting method based on small target detection according to claim 3 is characterized in that: The neck network includes a first neck branch and a second neck branch, the first neck branch includes a first upsampling module, a first C2f module combination, a second upsampling module and a second C2f module combination, the second neck branch includes a first Ghost module, a third C2f module combination, a second Ghost module and a fourth C2f module combination, and the step of inputting the multi-scale feature image into the neck network for feature fusion enhancement to obtain a multi-scale fusion feature map includes: Inputting the multi-scale feature image into the first upsampling module and the second Ghost module; Upsampling and fusing the multi-scale feature image and the second attention feature map through the first upsampling module to obtain a first upsampling fused feature map; Performing a convolution operation on the first up-sampled fusion feature map through the first C2f module combination to obtain a first C2f feature map, and inputting the first C2f feature map into the first Ghost module and the second up-sampling module; Upsampling and fusing the first C2f feature map and the first attention feature map through the second upsampling module to obtain a second upsampling fused feature map; Performing a convolution operation on the second upsampled fusion feature map through the second C2f module combination to obtain a second C2f feature map, and inputting the second C2f feature map into the first Ghost module and the detection head network; Performing a Ghost convolution operation on the first C2f feature map and the second C2f feature map through the first Ghost module to obtain a first Ghost convolution splicing feature map; Performing a convolution operation on the first Ghost convolution splicing feature map through the third C2f module combination to obtain a third C2f feature map, and inputting the third C2f feature map into the detection head network and the second Ghost module; Performing a Ghost convolution operation on the third C2f feature map and the multi-scale feature image through the second Ghost module to obtain a second Ghost convolution splicing feature map; The second Ghost convolutional splicing feature map is convolved by the fourth C2f module combination to obtain a fourth C2f feature map, and the fourth C2f feature map is input into the detection head network; wherein the second C2f feature map, the third C2f feature map and the fourth C2f feature map constitute the multi-scale fusion feature map.

7. The sheep counting method based on small target detection according to claim 6 is characterized in that: The detection head network includes three detection heads, namely a first detection head, a second detection head and a third detection head, wherein each detection head includes a target category prediction branch and a bounding box prediction branch; the step of performing target detection on the multi-scale fusion feature map through the detection head network and outputting the predicted target detection result includes: Performing target category prediction and bounding box prediction according to the second C2f feature map through the target category prediction branch and the bounding box prediction branch of the first detection head to obtain a first target feature map; Performing target category prediction and bounding box prediction according to the third C2f feature map through the target category prediction branch and the bounding box prediction branch of the second detection head to obtain a second target feature map; Performing target category prediction and bounding box prediction according to the fourth C2f feature map through the target category prediction branch and the bounding box prediction branch of the third detection head to obtain a third target feature map; The first target feature map, the second target feature map and the third target feature map are spliced ​​and output to obtain a predicted target detection result.

8. A sheep counting device based on small target detection, characterized in that: include: A preprocessing module is used to obtain the original pictures of grassland sheep herds collected by the drone as the original sample data set, and preprocess the original sample set to obtain a training set and a test set; An input module, used to input the training set into a pre-built initial target detection model, wherein the initial target detection model includes a backbone network, a neck network and a detection head network; A feature extraction module, used to extract features of different scales from the sheep pictures in the training set through the backbone network to obtain multi-scale feature pictures; A fusion module, used for inputting the multi-scale feature image into the neck network for feature fusion enhancement to obtain a multi-scale fusion feature map; A target prediction module is used to perform target detection on the multi-scale fusion feature map through the detection head network, and output a predicted target detection result, wherein the predicted target detection result includes a predicted target position and a target rotation angle; A decoding module, used to decode the predicted target detection result to obtain a predicted rotation bounding box; A loss calculation module, used to calculate the loss value between the predicted rotation bounding box and the actual bounding box according to a preset loss function; An iterative module, used for adjusting the model parameters of the initial target detection model based on the loss value, continuing the iterative training until the model converges, obtaining a model to be tested, and testing the model to be tested through the test set to obtain a final target detection model; The target detection module is used to obtain the picture of the sheep flock to be counted, input the picture of the sheep flock to be counted into the target detection model, and obtain the sheep flock counting result.

9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the sheep counting method based on small target detection as described in any one of claims 1 to 7 when executing the computer-readable instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the sheep counting method based on small target detection as described in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Fish identification method, system, terminal and computer-readable storage medium

    CN119741737A

  • Engineering application-oriented lightweight small target detection method for scale dynamic loss and efficient multi-scale attention

    CN121788855A