Cage-rearing meat duck overturning recognition algorithm based on deep neural network
By constructing a duck rollover detection algorithm based on the YOLO v8+Swin Transformer-tiny network structure of deep neural networks, the problems of accuracy and speed in duck rollover detection were solved, realizing real-time and low-cost duck rollover detection, reducing the mortality rate of ducks and improving breeding efficiency.
Patent Information
- Application Number
- CN202511017358.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-23
- Publication Date
- 2025-10-31
AI Technical Summary
Meat ducks are prone to being overturned in high-density farming. Existing technologies rely on manual identification, which leads to stress and high mortality rates, and it is difficult to achieve rapid and accurate overturning identification.
A duck rollover detection algorithm was constructed using a YOLO v8+Swin Transformer-tiny network structure based on deep neural networks. Data was collected through an autonomous inspection platform, and image annotation and preprocessing were performed to train the inference model. The algorithm was then deployed on an embedded device to achieve real-time detection.
It improves the accuracy and speed of identifying duck overturning, reduces computational complexity, decreases the workload of manual inspection, reduces the mortality rate of ducks, and improves breeding efficiency and economic benefits.
Smart Images

Figure CN120877331A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of target detection technology, and in particular to a deep neural network-based algorithm for recognizing the overturning of caged ducks. Background Technology
[0002] In duck farming, feed is generally high in energy, leading to rapid growth. Early muscle and internal organ development is rapid, but due to slower calcium and phosphorus deposition, skeletal development lags significantly behind muscle and organ development, resulting in physiological developmental incoordination. This leads to poor skeletal development, weak legs, and instability, making ducks prone to tipping over, typically around ten days of age. In high-density duck farming, tipping behavior detection relies heavily on manual intervention. On one hand, managerial actions can cause stress, increasing mortality and reducing production efficiency; on the other hand, tipping can further exacerbate diseases such as enteritis and serositis in ducks.
[0003] Therefore, research on the recognition model algorithm for overturned ducks in cages is crucial for the poultry farming industry, and the realization of intelligent detection and recognition of overturned ducks in layered cage rearing has strong practical significance. Summary of the Invention
[0004] This application aims to at least partially address one of the technical problems in related technologies. To this end, one objective of this application is to propose a deep neural network-based algorithm for identifying overturned ducks in cages, enabling duck farms to quickly, accurately, and cost-effectively detect overturned ducks and their location information.
[0005] One aspect of this application provides a deep neural network-based algorithm for recognizing the overturning of caged meat ducks, comprising:
[0006] Step S100: Establish a dataset for detecting caged ducks that have turned over;
[0007] Step S200: Select the base network YOLO v8, construct the YOLO v8+Swin Transformer-tiny network structure as the detection network for caged ducks that have rolled over, and train the inference model based on the detection network for caged ducks that have rolled over.
[0008] Step S300: Input the image of the duck to be detected and identified into the inference model to detect whether there are overturned ducks and their cage numbers in the duck image;
[0009] Step S400: Optimize the inference model and compile the corresponding PyTorch format file, then transfer the inference model to the JetSon ORIN development board for deployment;
[0010] The specific method for establishing the detection dataset of caged, overturned meat ducks is as follows:
[0011] Step S110: Collect an image dataset of actual caged ducks being turned over at the duck breeding base based on the autonomous inspection platform equipment;
[0012] Step S120: Use the Labelme tool to annotate the collected image dataset to obtain annotation information;
[0013] Step S130: Preprocess the labeled image dataset;
[0014] Furthermore, the annotation information includes the location of the overturned duck in the image and the cage number where it is located, and the annotation information is stored in txt format;
[0015] Furthermore, the preprocessing employs image enhancement methods, including batch processing operations using OpenCV to adjust brightness, contrast, and saturation;
[0016] The construction method of the YOLO v8+Swin Transformer-tiny network structure is as follows: YOLO v8 is selected as the base network, which includes Backbone, Neck and Head. Backbone includes C2F module, which is used for feature extraction. Neck is responsible for feature fusion and Head is responsible for target detection and classification tasks. The feature extraction network of SwinTransformer-tiny is introduced to replace the convolutional backbone network of YOLO v8. The shift window attention mechanism SW-MSA and the hierarchical self-attention mechanism are introduced. Through model distillation and model pruning, the pruned model is then quantized to obtain a lightweight YOLO v8+Swin Transformer-tiny network structure, which is used as the detection network for caged ducks that are turned over.
[0017] The specific method for training the inference model based on the identification and detection network for caged, overturned meat ducks is as follows:
[0018] 90% of the image dataset was used as the training and validation set, and 10% as the test set. The training and validation set was further divided into a 90% training set and a 10% validation set. Model training parameters were set, including learning rate, weight coefficients, training threshold, image size, number of training batches, and batch size. The caged overturned duck identification and detection network was trained by building a virtual environment on a GPU server. The training set was input into the caged overturned duck identification and detection network for training, using images of caged overturned ducks as input data and the corresponding labeled locations of the overturned ducks and their cage numbers as output data to train the inference model. The inference model was optimized using the validation set and tested using the test set.
[0019] The specific method for optimizing the inference model, compiling the corresponding PyTorch format file, and then deploying the inference model on the JetSon ORIN development board is as follows:
[0020] Step S410: Optimize the inference model using model distillation, model pruning, and model quantization.
[0021] Step S420: Prune the model for the Multi-HeadAttention special mechanism of the feature extraction network of Swin Transformer-tiny in the inference model. Use the Mask search algorithm to find the attention features with the lowest importance, and use the Mask reordering algorithm to prune the attention features with the lowest importance.
[0022] Step S430: Perform model quantization by converting the model weights from 32-bit floating-point numbers to 16-bit floating-point numbers;
[0023] Step S440: Set up the YOLO v8 environment on the JetSon ORIN development board, install torch and the corresponding version of the torchvision module, download the YOLO v8 source code and successfully run the inference model through debugging, optimize the trained inference model on the deep learning host, and compile the corresponding PyTorch format file and transfer it to the JetSon ORIN development board.
[0024] The deep neural network-based algorithm for identifying the turning over of caged ducks proposed in this application has the following advantages over existing technologies:
[0025] This application adopts the YOLO v8 network structure and introduces the Swin Transformer-tiny feature extraction network to construct a cage-raised duck overturning detection network. It can accurately detect and identify whether ducks have overturned in complex backgrounds and provide feedback on the cage number of the overturned duck. This reduces the computational complexity of the model, improves the accuracy and speed of recognition, facilitates the deployment of embedded computer devices, and also improves economic efficiency.
[0026] In establishing the selected YOLO v8 network structure, this application introduces the Swing Transformer-tiny feature extraction network structure and the SW-MSA shifted window attention mechanism to improve the computational efficiency of the YOLO v8 model. It also introduces a hierarchical self-attention mechanism to enhance the ability to capture deep features at different scales from local to global, thereby efficiently detecting caged overturned ducks, which can be widely used in the field of duck farming. Attached Figure Description
[0027] Figure 1 A flowchart of a method for identifying the overturning of caged meat ducks based on a deep neural network, provided in this application;
[0028] Figure 2 The YOLO v8 network architecture diagram provided in this application;
[0029] Figure 3 The overall architecture diagram of TransformerBlock provided in this application;
[0030] Figure 4 The network structure diagram of the lightweight YOLO v8+Swin Transformer-tiny model provided in this application. Detailed Implementation
[0031] To better understand this application, various aspects of this application will be described in more detail with reference to the accompanying drawings. It should be understood that these detailed descriptions are merely illustrative of exemplary embodiments of this application and are not intended to limit the scope of this application in any way. Throughout the specification, the same reference numerals refer to the same elements. The expression "and / or" includes any and all combinations of one or more of the associated listed items.
[0032] In the accompanying drawings, the size, dimensions, and shapes of the elements have been slightly adjusted for ease of illustration. The drawings are for illustrative purposes only and are not strictly to scale. As used herein, the terms “approximately,” “about,” and similar terms are used to indicate approximation, not degree, and are intended to illustrate inherent deviations in measured or calculated values that will be recognized by one of ordinary skill in the art. Furthermore, the order in which the steps are described in this application does not necessarily indicate the order in which these steps occur in actual operation, unless otherwise expressly defined or deduced from the context.
[0033] It should also be understood that expressions such as "comprising," "including," "having," "containing," and / or "comprising" are open-ended rather than closed-ended expressions in this specification, indicating the presence of the stated features, elements, and / or components, but not excluding the presence of one or more other features, elements, components, and / or combinations thereof. Furthermore, when expressions such as "at least one of..." appear after a list of listed features, they modify the entire list of features, not just individual elements in the list. Additionally, when describing embodiments of this application, the word "may" is used to mean "one or more embodiments of this application." And the term "exemplary" is intended to refer to examples or illustrations.
[0034] Unless otherwise specified, all terms used herein (including engineering and technical terms) shall have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. It should also be understood that, unless expressly stated herein, terms defined in common dictionaries shall be interpreted as having the meaning consistent with their meaning in the context of the relevant art, and not as having an idealized or overly formalized meaning.
[0035] It should be noted that, where there is no conflict, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0036] Example 1
[0037] like Figure 1 As shown, this application provides a deep neural network-based algorithm for recognizing the overturning of caged meat ducks, comprising:
[0038] Step S100: Establish a dataset for detecting caged ducks that have turned over;
[0039] The specific method for establishing the detection dataset of caged, overturned meat ducks is as follows:
[0040] Step S110: Collect an image dataset of actual caged ducks being turned over at the duck breeding base based on the autonomous inspection platform equipment;
[0041] Step S120: Use the Labelme tool to annotate the collected image dataset to obtain annotation information;
[0042] Furthermore, the annotation information includes the location of the overturned duck in the image and the cage number where it is located, and the annotation information is stored in txt format;
[0043] The Labelme tool is an open-source tool for image annotation that can use rectangles to mark targets in an image and provide category labels.
[0044] Step S130: Preprocess the labeled image dataset;
[0045] Furthermore, the preprocessing employs image enhancement methods, including batch processing operations using OpenCV to adjust brightness, contrast, and saturation;
[0046] The purpose of the image enhancement method is to improve image readability and training accuracy;
[0047] Step S100 above establishes a dataset for detecting and identifying overturned ducks through manual annotation, providing a data foundation for subsequent model training. The annotation information includes overturning status and location information, enabling simultaneous overturning detection and localization.
[0048] Step S200: Select the base network YOLO v8, construct the YOLO v8+Swin Transformer-tiny network structure as the detection network for caged ducks that have rolled over, and train the inference model based on the detection network for caged ducks that have rolled over.
[0049] like Figure 2 The diagram shown illustrates the YOLO v8 network architecture provided in this application, primarily composed of three modules: Backbone, Neck, and Head. The Backbone is a feature extraction network, typically employing common convolutional networks such as CSPDarknet53 to extract image features and output multi-scale feature maps. The YOLO v8 Backbone is mainly composed of multiple C2f modules connected in series. Each C2f module contains convolutional layers and CSP layers, which can reduce computational cost while retaining more gradient information, enabling the extraction of richer multi-scale features. The Neck is a feature fusion network that fuses the multi-scale feature maps output by the Backbone, allowing feature information from different receptive fields to be mutually referenced, thus improving detection accuracy. The YOLO v8 Neck uses a PANet structure, utilizing the FPN feature pyramid structure for top-down multi-scale feature fusion, supplemented by bottom-up feature upsampling and fusion, ultimately yielding rich multi-scale fused features. The Head is the detection head network, using convolution on the feature maps output by the Neck for target classification and location regression. For each preset anchor box, the Head predicts its category and the position and size that need to be adjusted relative to the anchor box. YOLO v8's Head uses an improved Anchor-free method, which no longer relies on preset anchor boxes, but directly regresses the center point position and height and width of the target on the feature map, greatly simplifying the design of the detection head.
[0050] The construction method of the YOLO v8+Swin Transformer-tiny network structure is as follows: YOLO v8 is selected as the base network, which includes Backbone, Neck and Head. Backbone includes C2F module, which is used for feature extraction. Neck is responsible for feature fusion and Head is responsible for target detection and classification tasks. The feature extraction network of SwinTransformer-tiny is introduced to replace the convolutional backbone network of YOLO v8. The shift window attention mechanism SW-MSA and the hierarchical self-attention mechanism are introduced. Through model distillation and model pruning, the pruned model is then quantized to obtain a lightweight YOLO v8+Swin Transformer-tiny network structure, which is used as the detection network for caged ducks that are turned over.
[0051] like Figure 3 The diagram shown is the overall architecture of the Transformer Block provided in this application. The Transformer Block is the basic unit that makes up the Swing Transformer, and it is mainly composed of the LN layer, the SW-MSA layer and the MLP layer.
[0052] LN layers normalize input features, which can accelerate model convergence and improve training stability. In TransformerBlock, an LN layer is typically placed before Self-Attention and before the MLP.
[0053] The SW-MSA layer is the core module for self-attention computation. Unlike traditional global multi-head self-attention, SW-MSA uses a moving window approach. It divides the feature map into non-overlapping windows, calculates self-attention for each window separately, and then shifts the entire window, repeating the above calculation. This method significantly reduces the computational cost of attention, while the multiple shifts ensure that each location has a chance to interact with global information.
[0054] The MLP layer consists of two fully connected layers connected by the GELU activation function. The MLP layer can further enhance the expressive power of features.
[0055] like Figure 4 The diagram shows the network structure of the lightweight YOLO v8+SwinTransformer-tiny model provided in this application. The lightweight YOLO v8+Swin Transformer-tiny network replaces the YOLO v8 CSPDarknet53 backbone network with Swin Transformer-tiny, which serves as the feature extractor in the backbone network. Compared to CSPDarknet53, SwinTransformer can model longer-distance feature dependencies and extract richer semantic information. Furthermore, thanks to its hierarchical structure, Swin Transformer can output feature maps at multiple scales as input to the Neck module.
[0056] The lightweight YOLO v8+Swin Transformer-tiny model network structure uses the PANet structure and anchor-free detection head from YOLOv8 for its Neck and Head. It performs feature fusion and target detection on the multi-scale feature maps generated by the Swin Transformer backbone network, and the detection head directly regresses the coordinates of the target center point and its height and width.
[0057] To further improve the model's inference speed and meet the requirements of real-time detection, a series of model lightweighting measures were implemented based on YOLO v8+SwinTransformer, including: replacing the original Swing Transformer with Swing Transformer-tiny, which significantly reduced the number of parameters in the backbone network; using model distillation to teach the smaller model with the original large model, maintaining performance as much as possible while reducing the number of parameters; removing unimportant attention heads using model pruning, which further compressed the model size; and adopting FP16 quantization to compress the model weights from 32-bit floating-point numbers to 16-bit numbers with almost no loss of accuracy, reducing storage and bandwidth requirements by half.
[0058] The improved lightweight YOLO v8+Swin Transformer-tiny model maintains high detection accuracy while significantly reducing model size and accelerating inference speed, making it more suitable for deployment on embedded devices. It also inherits the advantages of both YOLO and Transformer models, achieving excellent performance in both feature extraction and object detection.
[0059] The above construction method, by introducing an advanced Transformer structure and various acceleration and optimization techniques, yields a lightweight and efficient duck rollover detection network, which significantly improves detection accuracy and speed, reduces model computational resource requirements, and facilitates real-time deployment on embedded devices.
[0060] The specific method for training the inference model based on the identification and detection network for caged, overturned meat ducks is as follows:
[0061] 90% of the image dataset was used as the training and validation set, and 10% as the test set. The training and validation set was further divided into a 90% training set and a 10% validation set. Model training parameters were set, including learning rate, weight coefficients, training threshold, image size, number of training batches, and batch size. The caged overturned duck identification and detection network was trained by building a virtual environment on a GPU server. The training set was input into the caged overturned duck identification and detection network for training, using images of caged overturned ducks as input data and the corresponding labeled locations of the overturned ducks and their cage numbers as output data to train the inference model. The inference model was optimized using the validation set and tested using the test set.
[0062] Preferably, the learning rate is 0.001, the weight coefficient is 0.0005, the training threshold is 0.9, the image size is 960×720, the number of training batches is 300, and the batch size is 16.
[0063] The above step S200 involves systematically training and testing the model by dividing the dataset, and using the validation set to guide model optimization. This fully explores the model's performance, prevents overfitting, and improves the model's generalization ability. Ultimately, a robust and well-generalized inference model for detecting overturned ducks is obtained.
[0064] Step S300: Input the image of the duck to be detected and identified into the inference model to detect whether there are overturned ducks and their cage numbers in the duck image;
[0065] In step S300, the image or video stream to be detected is input into the inference model for target detection trained in step S200. This allows the overturned ducks to be found in the output file or output video stream and the corresponding cage number to be identified, thus realizing the detection and localization of overturned caged ducks.
[0066] Step S400: Optimize the inference model and compile the corresponding PyTorch format file, then transfer the inference model to the JetSon ORIN development board for deployment;
[0067] The specific method for optimizing the inference model, compiling the corresponding PyTorch format file, and then deploying the inference model on the JetSon ORIN development board is as follows:
[0068] Step S410: Optimize the inference model using model distillation, model pruning, and model quantization.
[0069] Step S420: Prune the model for the Multi-HeadAttention special mechanism of the feature extraction network of Swin Transformer-tiny in the inference model. Use the Mask search algorithm to find the attention features with the lowest importance, and use the Mask reordering algorithm to prune the attention features with the lowest importance.
[0070] Furthermore, the pruned model is fine-tuned to eliminate the performance degradation that may be caused by pruning;
[0071] Step S430: Perform model quantization by converting the model weights from 32-bit floating-point numbers to 16-bit floating-point numbers;
[0072] The model quantization method described above can reduce the model's memory footprint and accelerate computation, thereby improving inference speed and enabling real-time inference.
[0073] Step S440: Set up the YOLO v8 environment on the JetSon ORIN development board, install torch and the corresponding version of the torchvision module, download the YOLO v8 source code and successfully run the inference model through debugging, optimize the trained inference model on the deep learning host, and compile the corresponding PyTorch format file and transfer it to the JetSon ORIN development board.
[0074] The JetSon ORIN development board is an embedded artificial intelligence platform launched by NVIDIA. It is equipped with a powerful GPU and can realize real-time image and video analysis, making it suitable for edge computing needs in scenarios such as smart farming.
[0075] The process of converting model weights from 32-bit floating-point numbers to 16-bit floating-point numbers is called FP16 quantization. This converts model weights and activations from 32-bit floating-point numbers to 16-bit floating-point numbers, reducing bandwidth and storage requirements, improving inference speed, and having minimal impact on accuracy.
[0076] Step S400 described above, by deploying the inference model to an embedded device next to the cages, enables real-time and efficient detection of duck rollovers, significantly reducing the workload of farmers, enabling timely detection of rolled-over ducks and taking measures to save them, thereby reducing the mortality rate of ducks and improving farming efficiency and profitability. The embedded deployment solution offers advantages such as low cost, easy integration, and good real-time performance.
[0077] In addition, the parts of the technical solutions provided in the embodiments of this application that are consistent with the implementation principles of the corresponding technical solutions in the prior art have not been described in detail, so as to avoid excessive elaboration.
[0078] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the invention. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A deep neural network-based algorithm for recognizing the overturning of caged meat ducks, characterized in that, include: Establish a dataset for detecting the overturning of caged ducks; YOLO v8 was selected as the base network, and a YOLO v8+Swin Transformer-tiny network structure was constructed as the detection network for caged ducks that are turned over. The inference model was trained based on the detection network for caged ducks that are turned over. The images of ducks to be detected and identified are input into the inference model to detect whether there are overturned ducks and their cage numbers in the images. The inference model is optimized, and the corresponding PyTorch format file is compiled. The inference model is then transferred to the JetSon ORIN development board for deployment.
2. The deep neural network-based algorithm for recognizing the overturning of caged meat ducks as described in claim 1, characterized in that, The specific method for establishing the detection dataset for caged, overturned meat ducks is as follows: Image datasets of actual caged and overturned ducks were collected at a duck breeding base using an autonomous inspection platform. The collected image dataset was labeled using the Labelme tool to obtain the labeling information; Preprocess the labeled image dataset.
3. The deep neural network-based algorithm for recognizing the overturning of caged ducks as described in claim 2, characterized in that, The annotation information includes the location of the overturned duck in the image and the cage number it belongs to, and the annotation information is stored in txt format.
4. The deep neural network-based algorithm for recognizing the overturning of caged meat ducks as described in claim 3, characterized in that, The preprocessing employs image enhancement methods, including batch processing operations using OpenCV to adjust brightness, contrast, and saturation.
5. The deep neural network-based algorithm for recognizing the overturning of caged meat ducks as described in claim 4, characterized in that, The construction method of the YOLO v8+Swin Transformer-tiny network structure is as follows: YOLO v8 is selected as the base network, which includes Backbone, Neck and Head. Backbone includes C2F module, which is used for feature extraction. Neck is responsible for feature fusion and Head is responsible for target detection and classification tasks. The feature extraction network of Swin Transformer-tiny is introduced to replace the convolutional backbone network of YOLO v8. The shift window attention mechanism SW-MSA and the hierarchical self-attention mechanism are introduced. Through model distillation and model pruning, the pruned model is then quantized to obtain the lightweight YOLO v8+Swin Transformer-tiny network structure, which is used as the detection network for caged ducks that have been turned over.
6. The deep neural network-based algorithm for recognizing the overturning of caged meat ducks as described in claim 5, characterized in that, The specific method for training the inference model based on the identification and detection network for caged, overturned meat ducks is as follows: 90% of the image dataset was used as the training and validation set, and 10% as the test set. The training and validation set was further divided into a 90% training set and a 10% validation set. Model training parameters were set, including learning rate, weight coefficients, training threshold, image size, number of training batches, and batch size. The caged overturned duck identification and detection network was trained by building a virtual environment on a GPU server. The training set was input into the caged overturned duck identification and detection network for training, using images of caged overturned ducks as input data and the corresponding labeled locations of the overturned ducks and their cage numbers as output data to train the inference model. The inference model was optimized using the validation set and tested using the test set.
7. The deep neural network-based algorithm for recognizing the overturning of caged meat ducks as described in claim 6, characterized in that, The specific method for optimizing the inference model, compiling the corresponding PyTorch format file, and then deploying the inference model on the JetSon ORIN development board is as follows: The inference model is optimized using model distillation, model pruning, and model quantization. To address the unique Multi-Head Attention mechanism of the feature extraction network in the SwinTransformer-tiny in the inference model, we perform model pruning. We use the Mask search algorithm to find the attention features with the lowest importance and then use the Mask reordering algorithm to prune these attention features. The model quantization process is performed by converting the model weights from 32-bit floating-point numbers to 16-bit floating-point numbers. Set up the YOLO v8 environment on the JetSon ORIN development board, install torch and the corresponding version of the torchvision module, download the YOLO v8 source code and successfully run the inference model through debugging, optimize the trained inference model on the deep learning host, compile the corresponding PyTorch format file and transfer it to the JetSon ORIN development board.