Deep learning-based chicken and egg target detection method for chicken farm
By improving the YOLOv5 model, using GhostNet and GSConv modules, combined with data enhancement and replacement loss functions, the problem of insufficient detection accuracy of existing technologies in complex scenarios has been solved, and more efficient and accurate chicken and egg target detection has been achieved.
Patent Information
- Application Number
- CN202410738657.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2024-08-23
AI Technical Summary
Existing target detection technology has insufficient accuracy in complex scenes, low-light conditions or target occlusion, especially for small targets or sparse targets. The accuracy is low, and the model generalization ability is insufficient and cannot adapt to new scenes or targets.
By improving the YOLOv5 model, using GhostNet to replace the backbone feature extraction network, introducing the lightweight convolution GSConv module to replace the standard convolution in the multi-scale feature fusion network, using the replacement loss function to MPDIoU, and combining data enhancement and GUI systems to perform chicken and Egg target detection.
It significantly improves the speed and accuracy of target detection, reduces model parameters and computational complexity, improves the model's reasoning speed and adaptability, and enhances detection capabilities in complex scenarios.
Smart Images

Figure CN118537802A
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of detection in chicken farms, and in particular to a method for detecting cage numbers, eggs and chickens connected to a USB camera based on an improved yolov5. Background Art
[0002] With the rapid development of computer vision technology and the increasing maturity of deep learning algorithms, object detection technology has made significant progress. In real-world scenarios such as chicken farms, manual operations may result in slow detection, especially when large amounts of data need to be processed or time requirements are tight. This may delay the production process or result in untimely information acquisition.
[0003] The existing target detection technology still has defects and shortcomings: First, although some advanced target detection models perform well on standard data sets, they still have insufficient accuracy in complex scenes, low light conditions or when the target is occluded. In particular, the accuracy rate may be low for the detection of small or sparse targets; second, target detection models usually require a large amount of labeled data for training, but if the training data set is biased or unbalanced, the model may not be able to generalize well and cannot adapt to new scenes or targets.
[0004] Using computer vision technology for automated target detection and recognition can not only improve production efficiency, but also reduce the burden of manual labor and realize intelligent management. Therefore, the cage number, egg and chicken head detection method in the chicken farm based on YOLOv5 represents the application prospect of target detection technology in the agricultural field and provides strong support for the digital transformation of agricultural production. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a chicken and egg target detection method in a chicken farm based on deep learning, to improve the model performance by improving the YOLOv5 structure, and to improve the speed and accuracy of the target detection results.
[0006] To achieve the above objectives, the present invention provides a method for detecting chicken and eggs in a chicken farm based on deep learning, comprising the following steps:
[0007] Step 1: Obtain the video signal through the camera, extract the video signal into frames for image preprocessing; convert its labels into YOLO training format, and divide the training set, validation set, and test set into a ratio of 8:1:1.
[0008] Step 2: Replace the backbone feature extraction network with GhostNet, that is, replace the 2nd, 4th, 6th, and 8th layers of YOLOv5 Backbone with GhostConv modules; replace the 3rd, 5th, 7th, and 9th layers of Backbone with C3Ghost modules, introduce lightweight convolution GSConv to replace the standard convolution Conv in the multi-scale feature fusion network Neck of the basic network, that is, replace the 13th, 17th, 21st, and 23rd layers of the Neck feature fusion network with GSConv modules; change the loss function to MPDIoU, that is, replace the bounding box regression loss function from CIoU to MPDIoU.
[0009] Step 3: Based on the data set processed in step 1, train the improved YOLOv5 model described in step 2 to obtain the optimal trained model.
[0010] Step 4: The GUI system production method for detecting and counting chickens and eggs, which implements the GUI detection and counting interface for detecting and counting chickens and eggs, includes: two display areas, one for real-time display of video data, and the other for displaying extracted images; buttons for starting and stopping monitoring, and buttons for viewing historical data; and two tables for displaying monitoring data. The trained YOLOv5 model is used to detect chickens and eggs in the chicken farm by connecting to a USB camera. The detected targets will be drawn on the frame and displayed on the GUI interface.
[0011] Furthermore, performing data enhancement on the image in step 1 includes: selecting a number of images, rotating, flipping, and cropping the images to obtain data-enhanced images. After converting the labels into the YOLO training format, the training set, validation set, and test set are divided into a ratio of 8:1:1.
[0012] Furthermore, in step 2, a preset number of C2f layers, i.e., the 2nd, 4th, 6th, and 8th layers in the Backbone feature extraction network of YOLOv5 are replaced with GhostConv modules; and Backbone layers 3, 5, 7, and 9 are replaced with C3Ghost modules. The backbone network includes a first convolution module, a second GhostConv module, a first C3Ghost module, a second GhostConv module, a second C3Ghost module, a third GhostConv module, a third C3Ghost module, a fourth GhostConv module, a fourth C3Ghost module, and an SPPF spatial pyramid pooling structure, which are connected in sequence.
[0013] Furthermore, replacing the backbone feature extraction network with GhostNet in step 2 can reduce the model parameters and computational complexity of the neural network structure and speed up the reasoning speed. The basic structure of GhostNet is the Ghost module, which first uses conventional convolution to extract features from the input feature map to generate a basic feature map; then performs deep convolution on each channel of the basic feature map to generate a Ghost feature map; finally, the basic feature map and the Ghost feature map are stacked as output;
[0014] When the input feature map is h×w×C in ; The output feature map is h′×w′×C out , the input feature layer is divided into n parts, and the convolution kernel is large inout and small is k:
[0015] The amount of conventional convolution calculation is:
[0016] H′×w′×C out ×k×k×C in
[0017] The calculation amount of Ghost module is:
[0018]
[0019] Furthermore, in step 2, the standard convolution Conv in the multi-scale feature fusion network Neck of the basic network is replaced by a lightweight convolution GSConv. Since the input image data must go through the conversion process of the backbone network, that is, the feature information is transmitted from the spatial information to the channel, and the feature map is spatially compressed and the channel is expanded each time, although the dense convolution retains the connection between the channels to the greatest extent, the sparse convolution cuts it off, resulting in the problem of semantic information loss. The ghost shuffle convolution (GSConv) module is introduced into the neck structure of the YOLOv5 model, which retains the connection between the channels to a certain extent, reduces the complexity of the model, and ensures the accuracy of target detection. The improved network model only uses the ghost shuffle convolution (GSConv) module in the Neck structure. If the ghost shuffle convolution (GSConv) module is used in the entire stage of the model, the number of model network layers will be deepened, thereby causing the model reasoning time to increase. When the feature map enters the neck structure, the channel dimension is the largest and the height and width dimension is the smallest. Using the ghost shuffle convolution (GSConv) module will make the model accuracy the best and improve the model reasoning speed.
[0020] The principle of the ghost shuffle convolution (GSConv) module is as follows: set the input channel to C1 and the output channel to C2. After the input feature map is subjected to standard convolution, a feature tensor with an output channel of C2 / 2 is obtained. After the feature tensor is subjected to depthwise separable convolution, another feature tensor is obtained. The two processed feature tensors are concatenated, and after the channels are shuffled, the generated information is infiltrated into each part of the feature tensor generated by the depthwise separable convolution.
[0021] Furthermore, in step 2, the loss function is replaced with MPDIoU, and the MPDIoU formula is:
[0022]
[0023] L MPDIOU =1-MPDIOU
[0024] Among them, A is the area of the predicted box, B is the area of the real box, A∩B is the intersection of the real box and the predicted box, A∪B is the union of the real box and the predicted box, x prd ,y prd , respectively, are the horizontal and vertical coordinates of the two points on the diagonal of the prediction box, x gt ,y gt They are the horizontal and vertical coordinates of the two points on the diagonal of the real box, d is the distance between the two points of the predicted box and the real box, h is the height of the real box, and w is the width of the real box.
[0025] Furthermore, the process of training the YOLOv5 model in step 3 includes:
[0026] Based on the data set processed in step 1, the YOLOv5 model is trained until the training is completed when the set number of learning iterations is reached, and a trained YOLOv5 model is obtained. After the training is completed, the model will save the best weight file best.pt with the best training result.
[0027] Furthermore, in step 3, the input image size is set to 640*640, the batch size is 16, the number of training iterations is 100, the initial learning rate is 0.01, the learning rate momentum is 0.9, and the weight decay coefficient is 0.0005. After the training is completed, the model will save the best weight file best.pt with the best training results.
[0028] Furthermore, in step 4, best.pt is used as a weight file for detecting chicken heads, eggs, and cage numbers in a chicken farm. A USB camera is connected to detect chickens and eggs in the chicken farm. OpenCV is used to capture the video stream of the USB camera, and the YOLOv5 model is run on each frame for target detection. The detected targets will be drawn on the frame and displayed on the interface. For each detected bounding box, it is classified according to its category information, and the corresponding count value is updated according to the number of detected bounding boxes. The video stream and detection results can be displayed at the same time, and the number of chickens and eggs in each cage that is updated in real time is stored in a table on the GUI interface.
[0029] It can be seen from the above technical solution that, compared with the prior art, the advantages of the present invention are:
[0030] In the model, GhostNet is used to replace the backbone feature extraction network; the lightweight convolution GSConv is used to replace the standard convolution Conv in the multi-scale feature fusion network Neck of the basic network; and OpenCV is used to capture the video stream of the USB camera, which significantly reduces the number of model parameters and calculations, making the model more lightweight, improving the computing efficiency during feature fusion, and helping to accelerate the training and reasoning process of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 A flowchart of the target detection method based on the improved YOLOv5 proposed by the present invention;
[0032] Figure 2 This is the improved YOLOv5 network structure diagram of the present invention;
[0033] Figure 3 This is the network structure diagram of the GhostNet module;
[0034] Figure 4 To fuse the GSConv module in Neck features;
[0035] Figure 5 Schematic diagram of the improved YOLOv5 chicken farm target detection method of the present invention Figure 1 ;
[0036] Figure 6 Schematic diagram of the improved YOLOv5 chicken farm target detection method of the present invention Figure 2 . DETAILED DESCRIPTION
[0037] The present invention will be further described below by way of examples, but the scope of the present invention is not limited thereto.
[0038] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0039] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present invention, and should not be construed as limiting the present invention.
[0040] The embodiment of the present invention discloses a method for detecting chicken and eggs in a chicken farm based on deep learning, comprising the following steps:
[0041] Step 1: Get the video signal through the camera, extract the video signal into images for image preprocessing, select several images, rotate, flip and crop them to get the data-enhanced images. Thus, we get the data set of cage numbers, eggs and chicken head images in the chicken farm, perform data enhancement on the cage numbers, eggs and chicken head images in the chicken farm, and convert their labels into YOLO training format, dividing the training set, validation set and test set into a ratio of 8:1:1.
[0042] Step 2: Replace the backbone feature extraction network with GhostNet, that is, replace the 2nd, 4th, 6th, and 8th layers of YOLOv5 Backbone with GhostConv modules; replace the 3rd, 5th, 7th, and 9th layers of Backbone with C3Ghost modules, and use lightweight convolution GSConv to replace the standard convolution Conv in the multi-scale feature fusion network Neck of the basic network, that is, replace the 13th, 17th, 21st, and 23rd layers of the Neck feature fusion network with GSConv modules; change the loss function to MPDIoU, that is, replace the bounding box regression loss function from CIoU to MPDIoU.
[0043] 1. Replace the 2nd, 4th, 6th, and 8th layers of Backbone of YOLOv5 with GhostConv modules; replace the 3rd, 5th, 7th, and 9th layers of Backbone with C3Ghost modules. The backbone network includes the first convolution module, the second GhostConv module, the first C3Ghost module, the second GhostConv module, the second C3Ghost module, the third GhostConv module, the third C3Ghost module, the fourth GhostConv module, the fourth C3Ghost module, and the SPPF spatial pyramid pooling structure, which are connected in sequence.
[0044] Replace the Backbone layers 2, 4, 6, and 8 of YOLOv5 with GhostConv modules; replace Backbone layers 3, 5, 7, and 9 with C3Ghost modules. Replacing its backbone feature extraction network with GhostNet can reduce the model parameters and the computational complexity of the neural network structure and speed up the reasoning speed. The Ghostbottleneck is mainly composed of two stacked Ghost modules. The first Ghost module is used as an expansion layer to increase the number of channels. The second Ghost module reduces the number of channels to match the shortcut path. Then, use shortcut to connect the input and output of the two Ghost modules.
[0045] The core module of the GhostNet module is Ghost BottleNeck. The overall structure of Ghost BottleNeck is very similar to the Inverted Residual in MobileNetv2. It can be considered as replacing the ordinary convolution in Inverted Residual with Ghost Module, such as Figure 3 As shown in the figure, in the structure (a) on the left, stride = 1, which is used to deepen the depth of the network. It consists of two Ghost modules in series. The first Ghost module can expand the number of channels, and the second Ghost module will reduce the number of channels to the same as the input. In the right (b), in order to compress the height and width of the feature map to half of the input, a Deepwise convolution with stride = 2 is added between the two Ghost modules. In the residual side part, a depthwise separable convolution with a stride of 2×2 and a 1×1 ordinary convolution are added to ensure the alignment of the Add operation.
[0046] If there is a lot of redundancy in the intermediate feature maps, the resources required to generate them can be reduced. In fact, given the input data X∈R c×h×w, where c is the number of input channels, h and w are the height and width of the input data, respectively, and the operation of any convolutional layer for generating n feature maps can be expressed as:
[0047] Y=X*f+b
[0048] Where * is the convolution operation, b is the bias term, and Y∈R ′ ×w′×n is the output feature map with n channels, f∈R c ×k×k×n is the convolution kernel in this layer. In addition, h' and w' are the height and width of the output data, respectively, and k×k is the kernel size of the convolution kernel f. In this convolution process, since the number of convolution kernels n and the number of channels c are usually very large (for example, 256 or 512), the number of FLOPs required is as much as n*h′*w′*c*k*k.
[0049] First, the original number of flops is: flops1 = n*h′*w′*c*k*k. According to the formula, the number of parameters to be optimized (parameters in f and b) is determined by the size of the input and output feature maps. The output feature maps of the convolutional layer usually contain a lot of redundancy, and some of them may be similar to each other. There is no need to use a large number of FLOPs and parameters to generate these redundant feature maps. Instead, the output feature maps are "phantoms" of a few original feature maps through some cheap transformations. These original feature maps are usually of smaller size and are generated by ordinary convolution kernels. Specifically, the m original feature maps Y′∈R h′xw′×m is generated using a single convolution:
[0050] Y′=X*f′
[0051] where f′∈R c×k×k×m is the convolution kernel used, m <= n, and the bias term is omitted for simplicity. The hyperparameters (such as kernel size, stride, padding) are the same as those in ordinary convolution to keep the spatial size of the output feature map (i.e., h′ and w′) consistent. In order to further obtain the required n feature maps, it is proposed to apply a series of cheap linear operations to each original feature in Y′ to generate s phantom feature maps:
[0052]
[0053] where y′ i is the i-th original feature map in Y′, and the above function is the jth linear operation used to generate the jth phantom feature map y ij , that is, y′ i Can have one or more ghost feature maps Final is an identity mapping used to preserve the original feature map. Through this operation, we can obtain n = m s feature maps Y = {y 11 ,y 12 , .., y ms} as the output data of the Ghost module.
[0054] The basic structure of GhostNet is the Ghost module, which first uses conventional convolution to extract features from the input feature map to generate a basic feature map; then performs deep convolution on each channel of the basic feature map to generate a Ghost feature map; finally, the basic feature map and the Ghost feature map are stacked as output;
[0055] When the input feature map is h×w×C in ; The output feature map is h′×w′×C out , the input feature layer is divided into n parts, and the convolution kernel is large inout and small is k:
[0056] The amount of conventional convolution calculation is:
[0057] H′×w′×C out ×k×k×C in
[0058] The calculation amount of Ghost module is:
[0059]
[0060] 2. Introduce lightweight convolution GSConv to replace the standard convolution Conv in the multi-scale feature fusion network Neck of the basic network, that is, replace the 13th, 17th, 21st, and 23rd layers in the Neck feature fusion network with GSConv modules; Introducing lightweight convolution GSConv can reduce the number of parameters and calculations without losing feature expression capabilities. The GSConv module is embedded in the feature fusion stage so that the new model has better results with significantly fewer parameters. GSConv is not used in the backbone network because it will lead to deeper backbone network layers, and deeper networks will increase resistance to spatial information flow, thereby affecting the inference speed.
[0061] The structure of the GSConv module is as follows Figure 4As shown in the figure. The structure of GSConv consists of two parts, a standard convolution (SC) layer and a depthwise separable convolution (DSC) layer. The SC layer is responsible for extracting high-level semantic information from the feature map, while the DSC layer is responsible for reducing the number of channels and the amount of computation of the feature map. The feature information extracted by these two layers is then concat, and then a channel shuffle operation is performed to obtain the output feature map. The channel shuffle operation is used to rearrange channels after group convolution so that information between different groups can be communicated, which can improve the performance and accuracy of the network.
[0062] The standard convolution layer is the most basic convolution operation in deep learning. Its process can be expressed by the following mathematical formula:
[0063] Given an input feature map X, the output Y of a standard convolutional layer can be calculated as:
[0064] Y=f(W*X+b)
[0065] Among them, * represents the convolution operation, X represents the input feature map, W represents the convolution kernel (filter), b represents the bias term, and f() represents the activation function. In the standard convolution layer, the convolution kernel W is element-wise multiplied with the input feature map X and the sum is calculated. Then the bias term b is added, and finally the output feature map Y is obtained through the activation function f().
[0066] Depthwise separable convolution is a lightweight convolution operation, which mainly consists of depthwise convolution and pointwise convolution. The process can be expressed by the following mathematical formula:
[0067] Given an input feature map X, the output Y of the depthwise separable convolutional layer can be calculated as:
[0068] Y=f(DSC(DW*X)+b)
[0069] Among them, DW represents the depthwise convolution operation, and DSC() represents the pointwise convolution operation. In the depthwise separable convolution layer, the input feature map X is first subjected to the depthwise convolution operation DW, which is equivalent to the convolution operation on the channel dimension. Then, the result of the depthwise convolution operation is subjected to the pointwise convolution operation DSC, that is, a 1×1 convolution kernel is used to perform convolution on each channel. Finally, the result of the pointwise convolution operation is added with the bias term b, and the output feature map Y is obtained through the activation function f().
[0070] 3. Replace the bounding box regression loss of YOLOv5 from CIoU to MPDIoU. The MPDIoU loss function takes into account the overlapping or non-overlapping areas of the bounding boxes, the width and height differences, and the center point distance, and simplifies the calculation process. The formula for MPDIoU is:
[0071]
[0072] L MPDIOU =1-MPDIOU
[0073] Among them, A is the area of the predicted box, B is the area of the real box, A∩B is the intersection of the real box and the predicted box, AUB is the union of the real box and the predicted box, and x prd ,y prd , respectively, are the horizontal and vertical coordinates of the two points on the diagonal of the prediction box, x gt ,y gt are the horizontal and vertical coordinates of the two points on the diagonal of the real box, d is the distance between the two points of the predicted box and the real box, h is the height of the real box, and w is the width of the real box. The MPDIoU loss function directly minimizes the distance between the upper left and lower right corners of the predicted box and the real box, improving the accuracy and efficiency of bounding box regression.
[0074] The idea of MPDIoU:
[0075] First, define the distance between objects. Traditional IoU measures the overlap between two bounding boxes, but does not consider the positional relationship between objects. MPDIoU introduces the distance between two objects as a measurement standard.
[0076] The distance between objects is measured using the Euclidean distance between the center points of the objects. This can better capture the positional relationship between objects, especially for long objects or objects with irregular shapes.
[0077] Calculate the distance between targets:
[0078]
[0079] For two bounding boxes, the minimum distance intersection (MDI) between them is calculated. MDI is the minimum distance of the intersection area of two bounding boxes. In other words, it measures the shortest distance between two bounding boxes and uses it to consider the positional relationship between objects.
[0080] Calculate the minimum distance intersection between them
[0081]
[0082] MDI is combined with traditional IoU to calculate MPDIoU. Specifically, MPDIoU is MDI divided by the area of the minimum bounding rectangle (MBR) of the two bounding boxes, and the result is divided by the IoU of the two bounding boxes. A1 and A2 represent the area of the two bounding boxes respectively.
[0083] Calculate MPDIoU:
[0084]
[0085] In a multi-target scenario, the MDIs between all targets can be averaged or weighted averaged to obtain the overall MPDIoU, which can comprehensively consider the positional relationships between multiple targets.
[0086] The closer MPDIoU is to 1, the higher the overlap between the two bounding boxes, while the closer it is to 0, the lower the overlap. In this way, MPDIoU not only considers the overlap of the bounding boxes, but also the distance relationship between them, making the object detection model more representative and robust.
[0087] Step 3: The process of training the YOLOv5 model in step 3 includes:
[0088] Based on the data set processed in step 1, after the division, the optimized target detection network is used for training to obtain the best target detection model. The input image size is set to 640*640, the batch size is 16, the number of training iterations is 100, the initial learning rate is 0.01, the learning rate momentum is 0.9, the weight decay coefficient is 0.0005, and the optimizer uses SGD.
[0089] The YOLOv5 model is trained until the set number of learning iterations is reached to complete the training, thereby obtaining a trained YOLOv5 model. After the training is completed, the model will save the best weight file best.pt with the best training result.
[0090] During the training process, the superiority of the network can be determined by various model evaluation indicators. The indicators for evaluating superiority include: Precision (precision / accuracy), Recal1 (recall / recall), AF (Average Precision). With recall as the horizontal axis and precision as the vertical axis, a PR curve can be drawn. The area under the PR curve is defined as AP, mAP (the average AP of each category). The calculation formulas for each evaluation indicator are as follows:
[0091]
[0092] Among them, IP means the number of positive classes predicted as positive classes; TN means the number of positive classes predicted as negative classes; FP means the number of negative classes predicted as positive classes; FN means the number of negative classes predicted as negative classes; r(k) means the kth largest recall rate; max(p(r(k))) means the maximum precision value at point r.
[0093] The comparison of the detection results of the present invention and YOLOv5s is shown in Table 1:
[0094] Table 1 Comparative experiment
[0095]
[0096] It can be seen from the above table that the present invention has a significant improvement in performance after making improvements on YOLOv5s. It is 0.2% higher than YOLOv5s in mAP@0.5%, 4.3% higher than YOLOv5s in mAP@0.5:0.95%, 2.411M less than YOLOv5s in Params, 5.8G less GFLOPS, and 15.602 less FPS.
[0097] In order to verify the effectiveness of the improved modules of the present invention on the model improvement, under the same parameter conditions, the present invention conducted the following seven groups of ablation experiments on three innovative points. Whether it is the use of GhostNet, the introduction of the GSConv module or the improved loss function MPDIoU, they all achieved good experimental results in the experiments, but the combination of the four has the best effect.
[0098] The results of the ablation experiment are shown in Table 2:
[0099] Table 2 Ablation experiment
[0100]
[0101] The effective improvement of the algorithm can be clearly seen from the data in the two tables in the above comparative experiment and ablation experiment.
[0102] Step 4: Through the above experimental comparison, it can be clearly seen that while ensuring the detection performance, the network structure is streamlined to the minimum, which greatly reduces the number of model parameters and calculations. For the GUI interface, create a program, create the main window and layout, and define the function; set the video source (can be a camera or a video file), load the YOLOv5 model weight; use OpenCV to capture the video stream of the USB camera, and run the YOLOv5 model on each frame for target detection; for each detected bounding box, classify it according to its category information, and update the corresponding count value according to the number of detected bounding boxes. It can display the video stream and the frame extraction detection results at the same time, and two tables are used to display monitoring data; use the trained YOLOv5 model and connect the USB camera to detect chickens and eggs in the chicken farm. The detected targets will be drawn on the frame and displayed on the GUI interface.
[0103] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but shall conform to the widest scope consistent with the principles and novel features of the present invention.
Claims
1. A chicken and egg target detection method in a chicken farm based on deep learning, characterized in that: The steps include: Step 1: Obtain video signals through a USB camera, extract frames of the video signals into images for image preprocessing; convert their labels into YOLO training format, and divide the training set, validation set, and test set into a ratio of 8:1:1; Step 2: Replace the backbone feature extraction network with GhostNet, that is, replace the 2nd, 4th, 6th, and 8th layers of Backbone of YOLOv5 with GhostConv modules; replace the 3rd, 5th, 7th, and 9th layers of Backbone with C3Ghost modules, introduce lightweight convolution GSConv to replace the standard convolution Conv in the multi-scale feature fusion network Neck of the basic network, that is, replace the 13th, 17th, 21st, and 23rd layers of the Neck feature fusion network with GSConv modules; change the loss function to MPDIoU, that is, replace the bounding box regression loss function from CIoU to MPDIoU; Step 3: Based on the data set processed in step 1, train the improved YOLOv5 model described in step 2 to obtain a trained model; Step 4: Use the trained YOLOv5 model and connect the USB camera to detect the chickens, eggs and cage numbers in the chicken farm. The detected targets will be drawn on the frame and displayed on the GUI interface.
2. According to claim 1, a chicken and egg target detection method based on deep learning in a chicken farm is characterized in that: The image data enhancement in step 1 includes: selecting a plurality of images, rotating, flipping, and cropping the plurality of images to obtain data enhanced images.
3. According to claim 2, a chicken and egg target detection method based on deep learning in a chicken farm is characterized in that: In step 2, a preset number of C2f layers, i.e., the 2nd, 4th, 6th, and 8th layers, in the Backbone feature extraction network of YOLOv5 are replaced with GhostConv modules; the 3rd, 5th, 7th, and 9th layers of Backbone are replaced with C3Ghost modules, and the backbone network includes a first convolution module, a second GhostConv module, a first C3Ghost module, a second GhostConv module, a second C3Ghost module, a third GhostConv module, a third C3Ghost module, a fourth GhostConv module, a fourth C3Ghost module, and an SPPF spatial pyramid pooling structure, which are connected in sequence.
4. The method for detecting chicken and eggs in a chicken farm based on deep learning according to claim 3, characterized in that: Replacing the backbone feature extraction network with GhostNet is as follows: The basic structure of GhostNet is the Ghost module, which first uses conventional convolution to extract features from the input feature map to generate a basic feature map; then performs deep convolution on each channel of the basic feature map to generate a Ghost feature map; finally, the basic feature map and the Ghost feature map are stacked as output; When the input feature map is h×w×Cin; the output feature map is h'×w'×Cout, the input feature layer is divided into n parts, and the convolution kernel is large, inout is small, and k is small: The amount of conventional convolution calculation is: H′×w′×C out ×k×k×C in The calculation amount of Ghost module is:
5. The method for detecting chicken and eggs in a chicken farm based on deep learning according to claim 2, characterized in that: In step 2, the MPDIoU formula is: L MPDIOU =1-MPDIOU Among them, A is the area of the predicted box, B is the area of the real box, A∪B is the union of the real box and the predicted box, x prd ,y prd , respectively, are the horizontal and vertical coordinates of the two points on the diagonal of the prediction box, x gt ,y gt They are the horizontal and vertical coordinates of the two points on the diagonal of the real box, d is the distance between the two points of the predicted box and the real box, h is the height of the real box, and w is the width of the real box.
6. The method for detecting chicken and eggs in a chicken farm based on deep learning according to claim 3, characterized in that: The process of training the YOLOv5 model in step 3 includes: Based on the data set processed in step 1, the YOLOv5 model is trained until the training is completed when the set number of learning iterations is reached, thereby obtaining a trained YOLOv5 model.
7. The low-light target detection method and system based on convolutional neural network according to claim 1, characterized in that: In step 3, the input image size is set to 640*640, the batch size is 16, the number of training iterations is 100, the initial learning rate is 0.01, the learning rate momentum is 0.937, the weight decay coefficient is 0.0005, and the optimizer uses SGD. After training, the model will save the best weight file best.pt with the best training results.
8. According to a deep learning-based chicken and egg target detection method in a chicken farm according to claim 4, it is characterized in that, in step 4, best.pt is used as a weight file for detecting chicken heads, eggs and cage numbers in a chicken farm, OpenCV is used to capture the video stream of the USB camera, and the YOLOv5 model is run on each frame for target detection; for each detected bounding box, it is classified according to its category information, and the corresponding count value is updated according to the number of detected bounding boxes, and the video stream and frame extraction detection results can be displayed simultaneously, and two tables are used to display monitoring data.
9. The method for detecting chicken and eggs in a chicken farm based on deep learning according to claim 1, characterized in that: The GUI detection and counting interface for realizing chicken and egg detection and counting includes: Two display areas, one for real-time display of video data and the other for displaying extracted images; buttons for starting and stopping monitoring; Button to view historical data; and Two tables for displaying monitoring data.
Citation Information
Patent Citations
Lightweight YOLO pet identification method based on GhostNet
CN115049966A
Method for identifying dead chicken in infrared image cage based on improved YOLOv5 model
CN115527234A
Weed detection method based on improved yolov5 network
CN115909070A
Improved mask wearing detection method based on YOLOv5
CN116453186A
Cage rearing broiler chicken state detection and counting system based on deep learning
CN116665129A
Cited By
Detection model training method, detection method, equipment, storage medium and product
CN119251648A
Dead chicken detection method based on image fusion and improved YOLOv9
CN119251865A
Appearance detection method for unshelled poultry eggs
CN119832328A
Farm chicken detection method, device, equipment and medium
CN120014672A
Methods, devices, equipment and media for testing chickens in poultry farms
CN120014672B
