A duck egg recognition and positioning method

By improving the YOLOv7 target detection model, the problem of duck egg identification and positioning in the complex environment of duck farms has been solved, achieving fast and accurate duck egg detection, which is suitable for duck egg picking robots.

CN116758367BActive Publication Date: 2025-11-11HUAZHONG AGRI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310557346.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-17
Publication Date
2025-11-11
Estimated Expiration
2043-05-17

AI Technical Summary

Technical Problem

In duck farms, duck egg detection is difficult, especially in complex environments where it is hard to achieve rapid and accurate identification and location. Existing technologies rely on manual inspection, which is labor-intensive and costly.

Method used

The YOLOv7 target detection model was used for duck egg identification and localization. Through data augmentation and model improvement, including convolutional attention modules, depthwise separable convolutional networks, and spatial pyramid pooling structures, the model's detection capability in complex environments was improved.

Benefits of technology

It achieves rapid and accurate detection of duck eggs in complex environments. The YOLOV7_CDS model has an F1 score of 95.5% and an average accuracy of 85.2%. It has a fast detection speed and is suitable for deployment in duck egg picking robots.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116758367B_ABST
    Figure CN116758367B_ABST
Patent Text Reader

Abstract

The present application relates to a kind of duck egg recognition positioning method.Data acquisition and pre-processing: using feather, straw, silt or other materials, simulate the complex environment of duck house, using camera to shoot, the data obtained include duck egg image of multiple angles, multiple positions, different distances, different forms of sheltering;According to 6:2:2, the original image data collected is divided into training set, verification set, test set, to enrich the existing training set data information, prevent the model from overfitting, enhance training set sample data;YOLOV7 target detection model is established to detect data: the model is improved and trained, and the optimized model is established;Optimized model is used to recognize and position duck egg.The present application improves and trains YOLOV7 model, obtains the optimal detection model YOLOV7_CDS, its F1 score is 95.5%, and the average precision mean (mAP) is 85.2%, which provides technical support for duck egg picking robot to pick duck egg in duck farm.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of aquaculture technology, specifically relating to a method for identifying and locating duck eggs. Background Technology

[0002] Duck egg farming is generally characterized by "small-scale, large-group" operations, with inspection and egg collection relying entirely on manual labor, resulting in high labor intensity, high labor costs, and poor working conditions. Therefore, there is an urgent need for a robot that can replace manual labor for egg collection on duck farms. The key technology for developing a duck egg collection robot is to enable it to quickly and accurately detect and locate duck eggs in complex environments with varying levels of interference and obstruction.

[0003] Duck eggs are a special type of target for detection. In duck farms, duck eggs often appear in clusters, with overlapping and obscuring being common, making detection difficult. The environment in duck farms is complex and harsh, with mud, straw, and other materials often obscuring the eggs, as well as a large amount of duck feathers of similar color covering them, making target detection challenging. Therefore, the problem of automatic identification of duck eggs in poultry houses requires further in-depth research. Summary of the Invention

[0004] In view of the problems existing in the prior art, the present invention provides a method for identifying and locating duck eggs.

[0005] The technical solution adopted by the present invention to solve the above-mentioned technical problems is as follows:

[0006] A method for identifying and locating duck eggs includes the following steps:

[0007] 1) Data acquisition and preprocessing: Feathers, straw, mud or other materials were used to simulate the complex environment of the duck house. Cameras were used to take pictures, and the data obtained included duck egg images from multiple angles, multiple positions, different distances and different occlusion forms. 2600 JPG images with a resolution of 4000×3000 pixels were collected.

[0008] 2) Dataset Partitioning: The collected raw image data (2600 images) was divided into a training set (1560 images), a validation set (520 images), and a test set (520 images) in a 6:2:2 ratio. To enrich the existing training set data and prevent overfitting, the following data augmentation methods were used on the training set samples: 2.1) Adding 12% Gaussian noise. 2.2) Adding 2.5% salt-and-pepper noise. 2.3) Setting image gain a = 0.3 and a = 0.5 to change image brightness. After data augmentation, a total of 7800 training images were obtained. To ensure the accuracy and environmental adaptability of the model, the training set included images that affected recognition in various ways. The specific classifications included two main categories: occlusion and density. Occlusion was further divided into no occlusion, mutual occlusion, soil occlusion, and feather occlusion. Density was divided into sparse, medium, and clustered.

[0009] 3) Establish a YOLOv7 object detection model to detect objects in the data:

[0010] 4) Improve and train the model to build an optimized model;

[0011] 5) The optimized model is used to identify and locate duck eggs.

[0012] Preferably, in step 1), the preprocessing method is as follows:

[0013] Using MakeSense software, the duck egg image was annotated to obtain a txt file containing the coordinates (x, y) of the duck egg's center point, the height h and width w of the annotation box;

[0014] We added 12% Gaussian noise and 2.5% salt-and-pepper noise to the original image to reduce image smoothness by increasing redundant information; at the same time, to simulate the dim environment of a duck farm, we used a conversion formula in the RGB channels:

[0015] g(i,j)=af(i,j)+b (1)

[0016] In the formula, g(i,j) is the gray level of the converted image pixel; f(i,j) is the gray level of the original image pixel; a is the image gain; b is the image bias;

[0017] We set a=0.3, b=10 and a=0.5, b=10 respectively to reduce the brightness of the original image. In addition, during the training process, we used the Mosaic method to randomly crop and stitch multiple images to enrich the background of the object to be detected.

[0018] Preferably, in step 2), the following data augmentation methods are used on the training set samples: 2.1) adding 12% Gaussian noise, 2.2) adding 2.5% salt-and-pepper noise, 2.3) setting image gain a = 0.3 and a = 0.5, and changing the image brightness.

[0019] Preferably, in step 4), the model is improved and trained using a convolutional attention module, a depthwise separable convolutional network, and a spatial pyramid pooling structure; the convolutional attention module includes two modules: channel attention and spatial attention.

[0020] The channel attention module performs global average pooling and global max pooling on the input feature map of size H×W×C to obtain two 1×1×C feature maps. The new feature maps are then added together after passing through two fully connected layers. The weight coefficients are then obtained through the σ function. The weight coefficients are multiplied by the input feature map to finally obtain the output feature map. The calculation method is as shown in formula (2).

[0021] The spatial attention module takes the feature map output by the channel attention module as input, performs max pooling and average pooling, and concatenates the resulting two H×W×1 feature maps in the channel dimension to become H×W×2. Then, it is reduced to one channel through convolution and spatial weight coefficients are generated through the σ function. The input feature map is multiplied by the weights to obtain the output feature map. The calculation method is shown in formula (3).

[0022] Mc(Fm)=σ(MLP(AvgPool(Fm))+MLP(MaxPool(Fm))) (2);

[0023] Ms(Fm)=σ(f 7×7 ([AvgPool(Fm);MaxPool(Fm))]) (3);

[0024] In the formula, Mc is the channel attention map, Ms is the spatial attention map; Fm is the input feature map; σ is the Sigmoid function; f 7×7 The convolution is 7×7; MLP is a Multilayer Perceptron neural network; the depthwise separable convolutional network consists of two parts: depthwise convolution and pointwise convolution. The first part is a 3×3 depthwise convolution, and the second part is a 1×1 pointwise convolution. Its floating point operation per second (FLOPs) is calculated as shown in (4). Compared with the floating point operation of standard convolution, the calculation formula is shown in (5):

[0025] FLOPs1 = Ci × K 2 ×Ho×Wo+Ci×Ho×Wo×Co (4)

[0026] FLOPs2 = Ci × K 2 ×Ho×Wo×Co (5)

[0027] In the formula, Ci and Co represent the number of input and output channels, respectively, K is the kernel size, and Ho and Wo represent the height and width of the output feature map, respectively. The ratio of their floating-point computation costs is: When Co is 4 and K is 3, the floating-point computation cost of depthwise separable convolution is reduced by approximately Spatial pyramid pooling structure: It adopts a uniform stride and different size convolution kernels to achieve different sensitivities to image regions. Finally, it concatenates the kernels through Concat and performs 1×1 convolution to achieve feature fusion, enhance the expressive power of the obtained feature map, and improve the detection accuracy. The spatial pyramid pooling structure is improved by using the output of each pooling as the input of the next pooling, which improves the model efficiency while maintaining the original advantages.

[0028] Preferably, in step 4), the evaluation index in the model improvement process is evaluated based on two aspects: detection accuracy and detection speed.

[0029] 1) Detection precision, which evaluates the accuracy of the model's predictions, is calculated as shown in (3); Recall, which evaluates the model's ability to detect target data, is calculated as shown in (4); F1 score is the harmonic mean of precision and recall, which avoids a single maximum value in precision or recall and is used to comprehensively reflect the overall performance, and is calculated as shown in (5); Mean Average Precision (mAP) is an indicator that measures the algorithm for predicting the location and category of the target, and is of certain significance for evaluating the target detection model.

[0030]

[0031]

[0032]

[0033] 2) Detection speed: The average time taken by the model to detect one image is used as a measure of the model's speed. At the same time, the floating point operations per second (FLOPs) and the amount of memory space occupied by the model are used to measure the model's ability to be deployed on embedded devices.

[0034] More preferably, in step 4), the model training parameters are: input image size 640×640 pixels, number of iterations 150 rounds, and training batch size (batch_size) set to 8; to ensure the model is both "fast" and "excellent" and to prevent overfitting, the initial learning rate is set to 0.01, the learning annealing parameter is 0.1, and during training, the model learning rate decreases from 0.01 to 0.001 with a cosine change. In addition, the yolov7.pt pre-trained weight file is used during model training.

[0035] More preferably, in step 4), the detection results of the model are: (1) missed detection: duck eggs exist, but the model identifies them as background and does not output a detection box; (2) false detection: ① the background is identified as a duck egg; ② n stuck duck eggs are identified as 1 duck egg, which is recorded as n false detections; In addition, the model outputs a single detection box of the correct size, and there is only a single duck egg covered by duck feathers in the detection box. This situation has little impact on the picking process of the duck egg picking robot, so this situation is not recorded as a missed detection or false detection.

[0036] More preferably, in step 4), the detection model is YOLOV7_CDS. The original YOLOV7 model used by YOLOV7_CDS is characterized as follows: In the backbone network, an image with an input size of 640×640×3 is stacked with four CBS (Conv+BN+SiLU) modules, and the output is 160×160×128 features. Then, it passes through the ELAN module and outputs 160×160×256 features. Subsequently, it is stacked with three MP+ELAN modules. The stacked outputs yielded sizes of 80×80×512, 40×40×1024, and 20×20×1024, respectively. Based on this, the following improvements were made: ① A CBAM module was added after stacking the outputs of the three MP+ELAN modules; ② The 3×3 convolutional kernel in the ELAN module was replaced with a depthwise separable convolutional module (DSC); ③ An SPPF module was introduced into the 20×20×1024 feature output of the third MP+ELAN module, reducing its channel count from 1024 to 512.

[0037] Compared with the prior art, the present invention has the following beneficial effects:

[0038] This invention employs the YOLOv7 model as the object detection method, adding a Convolutional Attention Module (CBAM) to the backbone network to enhance network information transmission, improve the model's sensitivity to features, and reduce interference from complex environments in duck egg recognition. It utilizes Depthwise Separable Convolution (DSC) and adjusts the Spatial Pyramid Pooling (SPP) structure to reduce the number of model parameters and computational cost. This enables fast and accurate detection of duck eggs under complex environments with varying brightness and interference. By improving and training the YOLOv7 model, this invention obtains the optimal detection model YOLOv7_CDS, with an F1 score of 95.5% and a mean average precision (mAP) of 85.2%. Compared with commonly used object detection models SSD, YOLOv4, and YOLOv5_M, the improved YOLOv7 model achieved F1 scores of 8.3, 10.1, 8.7, and 7.6 percentage points higher, respectively; and mAP of 15.4, 10.7, and 16.4 percentage points higher, respectively. These results demonstrate the feasibility of using the YOLOv7_CDS model for duck egg detection in complex environments. Experimental results show that the YOLOv7_CDS model exhibits high robustness, achieving superior detection results even in complex conditions such as clustered duck eggs, low lighting, and occlusion. The YOLOv7_CDS model also boasts fast detection speed, with an average time of only 0.022 seconds for single-image detection, representing reductions of 0.073, 0.072, and 0.011 seconds compared to SSD, YOLOv4, and YOLOv5_L, respectively. Meanwhile, the improved YOLOV7 model has a small memory footprint and is superior to embedded devices deployed in duck egg picking robots, providing technical support for duck egg picking robots to pick up duck eggs in duck farms. Attached Figure Description

[0039] Figure 1 The data samples for collected duck eggs are as follows: a) unobstructed, b) mutually obstructed, c) obstructed by soil, d) obstructed by feathers, e) clustered duck eggs, f) multiple targets, g) unobstructed duck eggs in the duck farm, h) clustered duck eggs in the duck farm, and i) duck eggs in a complex environment in the duck farm.

[0040] Figure 2 A data annotation map of duck eggs was created using MakeSense software to annotate the collected duck egg data.

[0041] Figure 3The images show a comparison of duck egg data augmentation: a is the original image, b is a with Gaussian noise added, and c is a is a with salt-and-pepper noise added. d is the original image, e is d with gain adjusted to a=0.5, and f is d with gain adjusted to a=0.3. g is the augmentation method using Mosaic stitching during training.

[0042] Figure 4 This represents a partial structure of YOLOv7, where a is the ELAN structure in YOLOv7 and b is the Repconv structure.

[0043] Figure 5 Convolutional attention module.

[0044] Figure 6 The images show a comparison between standard convolution and depthwise separable convolution. a represents standard convolution, and b represents depthwise separable convolution.

[0045] Figure 7 This specifies the exact location in YOLOv7 where depthwise separable convolutions are used.

[0046] Figure 8 Spatial pyramid pooling structure, a is the original structure in YOLOv7, b is the improved structure.

[0047] Figure 9 Improved overall structure of YOLOV7_CDS model

[0048] Figure 10 The structures of each improved model are shown below: a is the original YOLOv7 structure, b is the YOLOv7_C structure, and c is the YOLOv7_D structure.

[0049] d is a YOLOV7_S structure, f is a YOLOV7_CD structure, e is a YOLOV7_CS structure, g is a YOLOV7_DS structure, and h is a YOLOV7_CDS structure.

[0050] Figure 11 The images show the recognition results of different models for duck eggs without occlusion. a is the original image, b is the recognition result of the YOLOV7_CDS model, c is the recognition result of the YOLOV5_L model, d is the recognition result of the YOLOV5_M ​​model, e is the recognition result of the YOLOV4 model, and f is the recognition result of the SSD model.

[0051] Figure 12 The images show the recognition results of different models when duck eggs are mutually occluded. a is the original image, b is the recognition result of the YOLOV7_CDS model, c is the recognition result of the YOLOV5_L model, d is the recognition result of the YOLOV5_M ​​model, e is the recognition result of the YOLOV4 model, and f is the recognition result of the SSD model.

[0052] Figure 13 The images show the recognition results of different models when duck eggs are covered by mud. a is the original image, b is the recognition result of the YOLOV7_CDS model, c is the recognition result of the YOLOV5_L model, d is the recognition result of the YOLOV5_M ​​model, e is the recognition result of the YOLOV4 model, and f is the recognition result of the SSD model.

[0053] Figure 14 The images show the recognition results of different models when duck eggs are obscured by feathers. a is the original image, b is the recognition result of the YOLOV7_CDS model, c is the recognition result of the YOLOV5_L model, d is the recognition result of the YOLOV5_M ​​model, e is the recognition result of the YOLOV4 model, and f is the recognition result of the SSD model.

[0054] Figure 15 The images show the recognition results of different models when duck eggs are sparse. a is the original image, b is the recognition result of the YOLOV7_CDS model, c is the recognition result of the YOLOV5_L model, d is the recognition result of the YOLOV5_M ​​model, e is the recognition result of the YOLOV4 model, and f is the recognition result of the SSD model.

[0055] Figure 16 The images show the recognition results of different models for moderately dense duck eggs. a is the original image, b is the recognition result of the YOLOV7_CDS model, c is the recognition result of the YOLOV5_L model, d is the recognition result of the YOLOV5_M ​​model, e is the recognition result of the YOLOV4 model, and f is the recognition result of the SSD model.

[0056] Figure 17 The images show the recognition results of different models for the clustering of duck eggs. a is the original image, b is the recognition result of the YOLOV7_CDS model, c is the recognition result of the YOLOV5_L model, d is the recognition result of the YOLOV5_M ​​model, e is the recognition result of the YOLOV4 model, and f is the recognition result of the SSD model.

[0057] Figure 18 The image shows the recognition results of the improved YOLOV7_CDS model for the actual condition of duck eggs in a duck farm. A1-A6 are the original images, and B1-B6 are the recognition results of the YOLOV7_CDS model. Detailed Implementation

[0058] To better understand the present invention, the following description, in conjunction with embodiments and accompanying drawings, further clarifies the content of the present invention. However, in order to enable those skilled in the art to fully understand the technical solutions and beneficial effects of the present invention, the following description, in conjunction with specific embodiments, provides further explanation. The embodiments are merely simple examples of the present invention and do not represent or limit the scope of protection of the present invention. The scope of protection of the present invention is subject to the claims.

[0059] Example 1

[0060] 1. Materials and Methods

[0061] 1.1 Data Materials

[0062] 1.1.1 Data Acquisition and Preprocessing

[0063] The experimental material consisted of Cherry Valley white-shelled duck eggs purchased from Shangqiu, Henan Province. To construct a duck egg image acquisition platform, materials such as feathers, straw, and mud were used to simulate the complex environment of a duck house. Images were captured using a Honor HLK-AL10 camera. To ensure the robustness and accuracy of the detection model, the obtained data included duck egg images from multiple angles, locations, distances, and occlusion patterns, such as... Figure 1 As shown, a total of 2600 JPG images with a resolution of 4000×3000 pixels were collected.

[0064] Use MakeSense software to annotate duck egg images, such as... Figure 2 The process yields a txt file containing the coordinates (x, y) of the duck egg's center point, and the height and width (w, h) of the bounding box. In this paper, the image is categorized into only two types during the annotation process: duck eggs and background. Since this paper only performs duck egg detection, only the duck eggs need to be annotated; the rest of the image is automatically annotated as background by Make Sense.

[0065] Data augmentation methods are applied to the original image to increase the amount of data for model training, preventing problems such as overfitting and poor generalization. Common data augmentation methods include rotation, flipping, translation, cropping, introducing noise, and adjusting brightness. This paper selects to add 12% Gaussian noise and 2.5% salt-and-pepper noise to the original image. By increasing redundant information and reducing image smoothness, a comparison image before and after adding noise is shown below. Figure 3 As shown in a, 3b, and 3c. Meanwhile, to simulate the dim environment of a duck farm, a conversion formula is used in the RGB channels:

[0066] g(i,j)=af(i,j)+b (1)

[0067] In the formula, g(i,j) is the gray level of the converted image pixel; f(i,j) is the gray level of the original image pixel; a is the image gain; and b is the image bias.

[0068] Setting a=0.3, b=10 and a=0.5, b=10 respectively reduces the brightness of the original image, which helps improve the robustness of the detection model. The comparison of the images before and after the transformation is shown below. Figure 3As shown in d, 3e, and 3f. Furthermore, during training, the Mosaic method is used to randomly crop and stitch multiple images together to enrich the background of the object to be detected. This method effectively improves the model's robustness to perturbations, and the stitching result is shown in... Figure 3 As shown in g.

[0069] 1.1.2 Dataset Partitioning

[0070] The collected raw image data (2600 images) was divided into a training set (1560 images), a validation set (520 images), and a test set (520 images) in a 6:2:2 ratio. To enrich the existing training set data and prevent overfitting, the following data augmentation methods were used on the training set samples: 1) Adding 12% Gaussian noise. 2) Adding 2.5% salt-and-pepper noise. 3) Setting image gain a = 0.3 and a = 0.5 to change image brightness. After data augmentation, a total of 7800 training images were obtained. To ensure the accuracy and environmental adaptability of the model, the training set included images with various impacts on recognition, as detailed in Table 1. Images with 1-5 duck eggs are considered sparsely distributed, 6-10 are considered moderately densely distributed, and 10 or more are considered clustered. Meanwhile, each type of image in the table has been processed by adding noise (12% Gaussian noise, 2.5% salt and pepper noise) and reducing brightness (setting image gain a=0.3, a=0.5).

[0071] After data augmentation, combined with the labeled original sample data, a total of 8840 images were obtained. The training set consisted of 7800 images, the validation set of 520 images, and the test set of 520 images. To ensure the model's accuracy and environmental adaptability, the training set included images with various impacts on recognition, as detailed in Table 1. Images with 1-5 duck eggs are classified as sparsely distributed, 6-10 as moderately densely distributed, and 10 or more as clustered. Furthermore, each image category in the table underwent noise addition and brightness reduction processing.

[0072] Table 1 Classification of Training Set

[0073]

[0074] 1.1.3 Test Platform

[0075] The training and testing of the duck egg detection model in this paper were both conducted in the same environment. The hardware configuration and software environment are shown in Table 2.

[0076] Table 2 Experimental Platform Environment

[0077] Hardware configuration model parameter CPU AMD Ryzen 7 5800X 3.8GHz GPU NVIDIA GeForce RTX 3070 8GB of video memory Software environment name Version system Windows 10 Network framework Pytorch 1.12.1 Computing architecture CUDA 11.6 compiler PyCharm 2021.1.3 programming language Python 3.7

[0078] 1.2 Detection Method

[0079] 1.2.1 YOLOv7 Object Detection Model

[0080] YOLO, as a single-stage object detection algorithm, can directly extract features from the network and output bounding boxes and labels. It boasts fast execution speed and is suitable for real-time detection systems. Furthermore, the YOLO algorithm can be improved based on the features of the target object and the application scenario, enhancing model performance. To better achieve real-time object detection, Chien-Yao Wang et al. researched algorithms more adaptable to edge devices and the cloud. Building upon YOLOv4 and YOLOv5, they proposed the YOLOv7 model. The efficient layer aggregation network in YOLOv7 differs from previous methods that enhanced network real-time performance by reducing the number of parameters and computational costs. ELAN controls the gradient path, allowing deeper networks to converge more efficiently and improving the network's learning ability. The ELAN network structure is as follows: Figure 4 As shown in a.

[0081] Meanwhile, while ensuring model performance, YOLOv7 uses re-parameterized convolution (RepConv) to accelerate the network. It fuses convolutional + batch normalization (BN) layers and different convolutional layers into a single convolutional module. Its structure is as follows: Figure 4 As shown in b.

[0082] 1.2.2 Model Improvement Methods

[0083] (1) Convolutional Attention Module

[0084] In machine vision, attention mechanisms focus the model's attention on important regions of the input image while suppressing irrelevant background, ultimately increasing the model's attention to important features. A Convolutional Block Attention Module (CBAM) is a lightweight attention module, such as... Figure 5 As shown, it contains two modules: channel attention and spatial attention.

[0085] The channel attention module performs global average pooling and global max pooling on the input feature map of size H×W×C to obtain two 1×1×C feature maps. The new feature maps are then passed through two fully connected layers and added together. The weight coefficients are then obtained through the σ function. The weight coefficients are multiplied by the input feature map to obtain the output feature map. The calculation method is shown in formula (2).

[0086] The spatial attention module takes the feature map output by the channel attention module as input, performs max pooling and average pooling, and concatenates the resulting two H×W×1 feature maps in the channel dimension to become H×W×2. Then, it is reduced to one channel through convolution and spatial weight coefficients are generated through the σ function. The input feature map is multiplied by the weights to obtain the output feature map. The calculation method is shown in formula (3).

[0087] Mc(Fm)=σ(MLP(AvgPool(Fm))+MLP(MaxPool(Fm))) (2)

[0088] Ms(Fm)=σ(f 7×7 ([AvgPool(Fm);MaxPool(Fm))]) (3)

[0089] In the formula, Mc is the channel attention map, Ms is the spatial attention map; Fm is the input feature map; σ is the Sigmoid function; f 7×7 It is a 7×7 convolution; MLP is a Multilayer Perceptron neural network.

[0090] (2) Depthwise separable convolutional networks

[0091] In 2017, Howard et al. proposed MobileNet, a model suitable for mobile devices, which replaces standard convolutions with depthwise separable convolutions (DSC). Figure 6 As shown, it consists of two parts: depthwise convolution and pointwise convolution. The first part is a 3×3 depthwise convolution, and the second part is a 1×1 pointwise convolution. Its floating-point operation cost (FLOPs) is calculated as shown in (4). Compared with the standard convolution floating-point operation cost, the calculation formula is shown in (5). The specific usage location of the DSC module is as follows: Figure 7 As shown.

[0092] FLOPs1 = Ci × K 2 ×Ho×Wo+Ci×Ho×Wo×Co (4)

[0093] FLOPs2 = Ci × K 2 ×Ho×Wo×Co (5)

[0094] In the formula, Ci and Co represent the number of input and output channels, respectively, K is the kernel size, and Ho and Wo represent the height and width of the output feature map, respectively. The ratio of their floating-point computation costs is: When Co is 4 and K is 3, the floating-point computation cost of depthwise separable convolution is reduced by approximately

[0095] (3) Spatial pyramid pooling structure

[0096] To address the issues of incomplete features and shape distortion caused by image cropping and scaling operations in deep learning algorithms, Microsoft proposed Spatial Pyramid Pooling (SPP). This structure avoids redundant feature extraction in convolutional neural networks, effectively improving object detection speed and saving computational resources. In YOLOv7, drawing inspiration from SPP, a new pooling structure is proposed. It uses convolutional kernels with uniform stride but different sizes to achieve varying sensitivities to different image regions. Finally, concatenation and 1×1 convolution are performed to fuse features, enhancing the expressive power of the resulting feature map and improving detection accuracy. The YOLOv7 Spatial Pyramid Pooling structure is shown below. Figure 8 As shown in a.

[0097] This paper draws inspiration from the Spatial Pyramid Pooling-Fast (SPPF) structure and improves upon it by using the output of each pooling operation as the input for the next. This approach enhances model efficiency while retaining the original advantages. The structure is as follows: Figure 8 As shown in b.

[0098] The improved model's overall structure is as follows: Figure 9 As shown.

[0099] 1.2.3 Model Evaluation Indicators

[0100] To verify whether the trained model is suitable for real-time detection of duck eggs in complex environments, this paper will evaluate it from two aspects: detection accuracy and detection speed.

[0101] 1) Model accuracy metrics: Precision, which evaluates whether the model predicts accurately, is calculated as shown in (3); Recall, which evaluates the model's ability to detect target data, is calculated as shown in (4); F1 score is the harmonic mean of precision and recall, which avoids a single maximum value in precision or recall and is used to comprehensively reflect the overall performance, and is calculated as shown in (5); Mean Average Precision (mAP) is an indicator that measures the algorithm for predicting the location and category of the target and has certain significance for evaluating the target detection model.

[0102]

[0103]

[0104]

[0105] 2) Model speed metrics: The average time it takes for the model to detect one image is used as a metric to measure model speed. Additionally, floating-point operations per second (FLOPs) and the amount of memory the model occupies are used to measure the model's ability to be deployed on embedded devices.

[0106] 1.2.4 Model Training Parameters

[0107] The input image size is 640×640 pixels, the number of iterations is 150, and the training batch size is set to 8. To ensure the model is both fast and efficient while preventing overfitting, the initial learning rate is set to 0.01, and the learning annealing parameter is 0.1. During training, the model learning rate decays cosinely from 0.01 to 0.001. Furthermore, the yolov7.pt pre-trained weight file is used during model training.

[0108] 1.2.5 Model Feature Constraints

[0109] The original YOLOv7 model used in this invention is characterized as follows: In the backbone network, an image with an input size of 640×640×3 is stacked with four CBS (Conv+BN+SiLU) modules to output a feature size of 160×160×128. Then, after passing through the ELAN module, a feature size of 160×160×256 is output. Subsequently, after being stacked with three MP+ELAN modules, outputs of sizes of 80×80×512, 40×40×1024, and 20×20×1024 are obtained respectively. This paper presents improved YOLOv7 models with the following features: ① YOLOv7_C adds a CBAM module after the stacked output of the three MP+ELAN modules in the original model; ② YOLOv7_D replaces the 3×3 convolutional modules in the ELAN module of the original model with depthwise separable convolutional modules (DSC); ③ YOLOv7_S introduces an SPPF module to the 20×20×1024 feature output of the third MP+ELAN module in the original model, reducing its channel number from 1024 to 512. YOLOv7_CD combines methods ① and ②, YOLOv7_DS combines methods ② and ③, YOLOv7_CS combines methods ① and ③, and YOLOv7_CDS combines methods ①, ②, and ③. The network structures of each improved model are as follows: Figure 10 As shown.

[0110] 2 Results and Analysis

[0111] 2.1 Ablation Experiment Results

[0112] Using the same dataset for training and testing, ablation experiments were conducted using various improved methods, and the results are shown in Table 3. Table 3 shows that the CBAM module optimizes both the channel and spatial dimensions. Specifically, the channel attention module performs global average pooling and global max pooling on the input feature maps, then uses an activation function to obtain weight coefficients, which are multiplied by the input features to obtain the output features. The spatial attention module performs pooling followed by concatenation and convolution along the channel dimension, while simultaneously using an activation function to obtain new output features. These two modules enhance the model's ability to extract features from the target object. For example, the YOLOV7_C model improves the F1 score by 5.1 percentage points compared to the YOLOV7 model; simultaneously, in terms of mAP, YOLOV7_C improves by 5.7 percentage points, YOLOV7_CD by 6.2 percentage points, YOLOV7_CS by 7.3 percentage points, and YOLOV7_CDS by 8.1 percentage points compared to the YOLOV7 model.

[0113] Table 3 Ablation Experiment Results

[0114] Model Precision rate P / % Recall rate R / % F1 score / % mAP / % YOLOV7 91.4 84.6 87.9 77.1 YOLOV7_C 94.5 91.3 93.0 82.8 YOLOV7_D 91.8 86.6 89.1 78.9 YOLOV7_S 92.7 88.2 90.4 81.1 YOLOV7_CD 95.2 91.9 93.5 83.3 YOLOV7_CS 96.3 92.5 94.4 84.4 YOLOV7_DS 94.1 91.6 92.8 83.9 YOLOV7_CDS 97.7 93.4 95.5 85.2

[0115] Furthermore, by adjusting the depthwise separable convolutional network and spatial pyramid pooling structure, YOLOV7_CDS reduces the floating-point operations (FLOPs) by 7.9G and the memory footprint by 6.1M compared to YOLOV7. The detection time of each model on the validation set was recorded, and the average time per image was taken as the model's detection speed. The experimental results are shown in Table 4. For a single image, the average detection time of the YOLOV7_CDS model is 0.022s. The experiments show that the YOLOV7_CDS model has a smaller memory footprint and exhibits advantages in both accuracy and speed, making it suitable for deployment in embedded devices for duck egg picking robots.

[0116] Table 4 Model Detection Performance

[0117] Model Average time / s Model size FLOPs YOLOV7 0.026 74.8M 105.1G YOLOV7_C 0.024 74.9M 105.2G YOLOV7_D 0.023 71.3M 103.2G YOLOV7_S 0.023 68.7M 99.0G YOLOV7_CD 0.024 68.8M 99.1G YOLOV7_CS 0.025 71.4M 105.2G YOLOV7_DS 0.023 68.7M 99.0G YOLOV7_CDS 0.022 68.7M 97.2G

[0118] 2.2 Performance Comparison of Different Models

[0119] The improved YOLOv7 model was compared with commonly used object detection models: SSD, YOLOv4, and YOLOv5. The results are shown in Table 5. Table 5 shows that YOLOv5_L and YOLOv7_CDS have certain advantages, with F1 scores exceeding 95%. In terms of F1 score, YOLOv7_CDS is 8.3 percentage points higher than the SSD model, 10.1 percentage points higher than the YOLOv4 model, 8.7 percentage points higher than the YOLOv5_M model, and 7.6 percentage points higher than the YOLOv7 model, but 0.4 percentage points lower than the YOLOv5_L model. This is because the network depth and width of the YOLOv5_L model are continuously increased and expanded under the influence of the C3 module and the number of convolutional kernels, resulting in a sacrifice of speed for higher accuracy. As shown in Table 6, the mean accuracy (mAP) of the YOLOV5_L model is 1.1 percentage points higher than that of the YOLOV7_CDS model, but the YOLOV7_CDS model occupies 24.1M less space than the YOLOV5_L. Meanwhile, compared to YOLOV5_L, the average time for single-image detection of YOLOV7_CDS is reduced by 0.011s, demonstrating a certain speed advantage and making it more suitable for deployment on embedded devices in duck egg picking robots.

[0120] Table 5 Detection performance of different models

[0121] Model Precision rate P / % Recall rate R / % F1 / Score% mAP / % Model size Average time / s SSD 92.2 82.7 87.2 69.8 90.6M 0.095 YOLOV4 90.3 81.1 85.4 74.5 244.0M 0.094 YOLOV5_M 89.5 84.2 86.8 68.8 41.1M 0.018 YOLOV5_L 97.2 94.7 95.9 86.3 92.8M 0.033 YOLOV7 91.4 84.6 87.9 77.1 74.8M 0.026 YOLOV7_CDS 97.7 93.4 95.5 85.2 68.7M 0.022

[0122] 2.3 Model Detection Results

[0123] This paper aims to detect duck eggs in the complex environment of a duck farm. To distinguish it from other target detection tasks, this paper defines and explains the results that the model will produce during detection. (1) Missed detection: Duck eggs are present, but the model identifies them as background and does not output a detection box. (2) False detection: ① The background is identified as a duck egg; ② n stuck duck eggs are identified as one duck egg, which is recorded as n false detections. In addition, the model outputs a single detection box of the correct size, and the detection box contains only a single duck egg covered by duck feathers. This situation has little impact on the picking process of the duck egg picking robot, so it is not recorded as a missed detection or false detection.

[0124] 2.3.1 Comparison of Occluded Target Detection

[0125] To further verify the ability of the YOLOV7_CDS model to solve the duck egg occlusion problem, four types of images—unoccluded, mutually occluded, mud-occluded, and feather-occluded—were input into the model. Figure 11 The results of each model are shown in the unoccluded case. As can be seen from the figure, each model accurately detected 6 targets in the unoccluded case, and the average confidence level reached 95% or above.

[0126] Figure 12 The results of each model are shown when duck eggs are occluded. As can be seen from the figure, YOLOv4 made a false detection, misidentifying the background as a duck egg, while the other models detected the target accurately.

[0127] Duck eggs being obscured by mud and feces is a common occurrence in duck farms. For duck eggs with only 10-20% visible area, the test results from various models are as follows: Figure 13 As shown in the figure, all five models accurately detected duck eggs covered by soil, with an average confidence level of over 90%, effectively solving the problem of detecting duck eggs that are covered by soil.

[0128] When ducks move around in the duck farm, they scatter a lot of duck feathers. When duck feathers cover duck eggs, they make it difficult to detect the target because of their similar color. Figure 14 The detection capabilities of each model when duck eggs are obscured by duck feathers are shown (the duck egg labels and confidence levels are hidden in the figures for clearer observation of the detection results). The figures show that the SSD model missed 5 duck eggs and made 2 false positives. The YOLOv4 model missed 5 duck eggs and made 4 false positives. The YOLOv5_M model missed 2 duck eggs and made 8 false positives. The YOLOv7_CDS model had no missed or false positives and detected duck eggs obscured by feathers with high accuracy. Table 6 compares the detection performance of each model when solving the feather occlusion problem. The table shows that the improved model, with no missed or false positives, has a higher average confidence level and a smaller space size, indicating that it can effectively solve the duck egg detection problem when feathers are obscured.

[0129] Table 6 Comparison of different models for feather occlusion detection.

[0130] Model False detection Missed detection Average confidence level / % Model size Average time / s SSD 2 5 86.9 90.6M 0.095 YOLOV4 3 3 88.0 244.0M 0.094 YOLOV5_M 8 2 77.9 41.1M 0.018 YOLOV5_L 0 0 93.4 92.8M 0.033 YOLOV7_CDS 0 0 93.6 68.7M 0.022

[0131] 2.3.2 Comparison of Dense Target Detection

[0132] To test whether the model can solve the problem of detection difficulties caused by varying density of duck eggs in duck farms, three types of images—sparse, moderately dense, and clustered—were input into the model. The detection results are as follows: Figure 15 , Figure 16 , Figure 17As shown in the figure, each model is well-suited for detecting duck eggs in sparse and moderately dense conditions. However, in crowded conditions, the YOLOV5_M, YOLOV4, and SSD models all exhibit significant false negatives and missed detections, failing to address the problem of dense target detection. Table 7 compares the detection performance of YOLOV5_L and YOLOV7_CDS. The table shows that both models have no false negatives or missed detections for duck eggs in crowded conditions, demonstrating good applicability. The average confidence score of YOLOV7_CDS is 2.4 percentage points higher than that of YOLOV5_L. Considering the model size, average detection time, and average confidence score of the two models, the proposed YOLOV7_CDS model is more suitable for deployment on duck egg retrieval robots and provides technical support for these robots to retrieve densely distributed duck eggs in duck farms.

[0133] Table 7 Comparison of different models for detecting crowding situations.

[0134] Model False detection Missed detection Average confidence level Model size Average time / s YOLOV5_L 0 0 83.3% 92.8M 0.033 YOLOV7_CDS 0 0 85.7% 68.7M 0.022

[0135] 2.3.3 Duck Farm Case Study Test Results

[0136] Untrained images collected from the duck farm will be input into the improved model to observe its ability to detect duck eggs under real-world conditions. Figure 18 To improve the model's detection results, a comparison with the original image on the left shows that the YOLOV7_CDS model performs well in real-world scenarios. It has no false detections in dimly lit, multi-target, occluded, and large field-of-view scenarios, and can accurately detect duck eggs in complex environments.

[0137] By improving and training the YOLOv7 model, the optimal detection model, YOLOv7_CDS, was obtained, with an F1 score of 95.5% and a mean average precision (mAP) of 85.2%. Compared with commonly used object detection models SSD, YOLOv4, and YOLOv5_M, YOLOv7_CDS improved the F1 score by 8.3, 10.1, and 8.7 percentage points, respectively; and the mAP by 15.4, 10.7, and 16.4 percentage points, respectively. The results indicate that the YOLOv7_CDS model is feasible for duck egg detection in complex environments. Experimental results show that the YOLOv7_CDS model has high robustness and achieves excellent detection results even in complex situations such as clustered duck eggs, low lighting, and occlusion. The YOLOV7_CDS model boasts a fast detection speed, with an average processing time of only 0.022 seconds for a single image. Compared to SSD, YOLOV4, and YOLOV5_L, this represents reductions of 0.073, 0.072, and 0.011 seconds, respectively. Furthermore, the improved YOLOV7 model has a small memory footprint, offering advantages when deployed in embedded devices for duck egg-collecting robots, thus providing technical support for the robot's egg-collecting capabilities in duck farms.

[0138] The above embodiments are merely preferred technical solutions of the present invention and should not be considered as limitations on the present invention. The embodiments and features described in these embodiments can be arbitrarily combined without conflict. The scope of protection of the present invention should be limited to the technical solutions described in the claims, including equivalent substitutions of the technical features described in the claims. That is, equivalent substitutions and improvements within this scope are also within the scope of protection of the present invention.

Claims

1. A method for identifying and locating duck eggs, characterized in that, Includes the following steps: 1) Data acquisition and preprocessing: Feathers, straw, mud or other materials are used to simulate the complex environment of the duck house. Cameras are used to take pictures, and the data obtained includes duck egg images from multiple angles, multiple positions, different distances and different occlusion forms. 2) Dataset partitioning: The collected raw image data is divided into training set, validation set and test set. The training set sample data is augmented. The training set contains various images that affect recognition. The specific classification includes two major categories of factors: occlusion and density. Occlusion is divided into no occlusion, mutual occlusion, soil occlusion and feather occlusion. Density is divided into sparse, medium and clustered. 3) Establish a YOLOv7 object detection model to detect objects in the data: 4) Improve and train the model to build an optimized model; 5) The optimized model is used to identify and locate duck eggs; In step 4), the model is improved and trained using a convolutional attention module, a depthwise separable convolutional network, and a spatial pyramid pooling structure; the convolutional attention module includes two modules: channel attention and spatial attention. The channel attention module performs global average pooling and global max pooling on the input feature map of size H×W×C, resulting in two 1×1×C feature maps. These new feature maps are then passed through two fully connected layers and added together. Finally, the input feature map is processed by... σ The function obtains the weight coefficients, which are multiplied by the input feature map to finally obtain the output feature map. The calculation method is as shown in formula (2). The spatial attention module takes the feature map output from the channel attention module as input, performs max pooling and average pooling, and concatenates the resulting two H×W×1 feature maps along the channel dimension to become H×W×2. Then, it is convolved to reduce the feature map to a single channel and passed through... σ The function generates spatial weight coefficients. The input feature map is multiplied by the weights to obtain the output feature map. The calculation method is shown in formula (3). Mc(Fm)=σ(MLP(AvgPool(Fm))+MLP(MaxPool(Fm))) (2); Ms(Fm) = σ(f 7×7 ([AvgPool(Fm);MaxPool(Fm))]) (3); In the formula Mc This is a channel attention map. Ms Spatial attention map; Fm Input feature map; σ For the Sigmoid function; f 7×7 It is a 7×7 convolution; MLP The Multilayer Perceptron neural network consists of two parts: depthwise convolution and pointwise convolution. The first part is a 3×3 depthwise convolution, and the second part is a 1×1 pointwise convolution. Its floating-point computation formula is as shown in (4). Compared with the standard convolution floating-point computation formula, the calculation formula is as shown in (5): FLOPs1=Ci×K 2 ×Ho×Wo+Ci×Ho×Wo×Co (4) FLOPs2=Ci×K 2 ×Ho×Wo×Co (5) In the formula Ci , Co These represent the number of input and output channels, respectively. K The kernel size is [size]. Ho , Wo These represent the height and width of the output feature map, respectively; the ratio of their floating-point computation costs is: ,when Co It is 4. K When the value is 3, the floating-point computation cost of depthwise separable convolution is reduced. Spatial pyramid pooling structure: It adopts convolution kernels with uniform stride and different sizes to achieve different sensitivities to image regions. Finally, it concatenates the kernels through Concat and performs 1×1 convolution to fuse features, enhance the expressive power of the obtained feature map, and improve the detection accuracy. An improvement to the spatial pyramid pooling structure is made by using the output of each pooling operation as the input for the next pooling operation, thereby improving model efficiency while maintaining the original advantages.

2. The duck egg identification and positioning method according to claim 1, characterized in that, In step 1), the preprocessing method is as follows: Using MakeSense software, the duck egg image was annotated to obtain a txt file containing the coordinates (x, y) of the duck egg's center point, the height h and width w of the annotation box; We added 12% Gaussian noise and 2.5% salt-and-pepper noise to the original image to increase redundant information and reduce image smoothness. Meanwhile, to simulate the dim environment of a duck farm, a conversion formula was used in the RGB channels: g(i,j) = af(i,j) + b (1) In the formula g(i,j) The grayscale values ​​of the converted image pixels; f(i,j) The original image pixel grayscale; a Image gain; b Image bias; Set a=0.3 and b=10 respectively; a=0.5, b=10; This reduces the brightness of the original image. Furthermore, during training, the Mosaic method is used to randomly crop and stitch multiple images together to enrich the background of the object to be detected.

3. The duck egg identification and positioning method according to claim 1, characterized in that, In step 2), the following data augmentation methods are used on the training set samples: 2.1) Add 12% Gaussian noise, 2.2) Add 2.5% salt and pepper noise, 2.3) Set the image gain a=0.3 and a=0.5 to change the image brightness.

4. The duck egg identification and positioning method according to claim 1, characterized in that, In step 4), the evaluation indicators in the process of improving the model are the detection accuracy and detection speed. 1) Detection accuracy, which evaluates whether the model prediction is accurate, is calculated as shown in (3); Recall rate, which evaluates the model's ability to detect target data, is calculated as shown in (4); The F1 score is the harmonic mean of precision and recall. It is an indicator used to comprehensively reflect the overall performance, avoiding a single maximum value in either precision or recall. The calculation formula is shown in (5). The mean precision is an indicator that measures the algorithm for predicting the location and category of the target, and it has certain significance for evaluating the target detection model. Precision = 100%(6) Recall = 100%(7) F1 Score = 100%(8) 2) Detection speed: The average time taken by the model to detect one image is used as a measure of the model's speed. At the same time, floating-point operations and the amount of memory space occupied by the model are used to measure the model's ability to be deployed on embedded devices.

5. The duck egg identification and positioning method according to claim 1, characterized in that, In step 4), the model training parameters are: input image size 640. The model has 640 pixels, 150 iterations, and a training batch size of 8. To ensure both speed and quality while preventing overfitting, the initial learning rate is set to 0.01, and the learning annealing parameter is set to 0.

1. During training, the learning rate decreases from 0.01 to 0.001 with a cosine variation. In addition, the yolov7.pt pre-trained weight file is used during model training.

6. The duck egg identification and positioning method according to claim 1, characterized in that, In step 4), the model's detection results are: (1) Missed detection: Duck eggs exist, but the model identifies them as background and does not output a detection box; (2) False detection: ① The background is identified as a duck egg; ② n stuck duck eggs are identified as 1 duck egg, which is recorded as n false detections; In addition, the model outputs a single detection box of the correct size, and there is only a single duck egg covered by duck feathers in the detection box.

7. The duck egg identification and positioning method according to claim 1, characterized in that, In step 4), the detection model is YOLOV7_CDS. YOLOV7_CDS uses the original YOLOV7 model, characterized as follows: In the backbone network, an input image of size 640×640×3 is stacked with four CBS modules (Conv + BN + SiLU) to output 160×160×128 features. Then, it passes through an ELAN module, outputting 160×160×256 features. Finally, it is stacked with three MP+ELAN modules to obtain features of sizes 80×80×512 and 40×40×1024 respectively. The output is 20×20×1024. Based on this, the following improvements are made: ① After stacking the output of the three MP+ELAN modules, a CBAM module is added; ② The 3×3 convolutional module in the ELAN module is replaced with a depthwise separable convolutional module; ③ The 20×20×1024 feature output by the third MP+ELAN module is supplemented with an SPPF module, which reduces the number of channels from 1024 to 512.