Method for improving recognition of rest behaviors of cage-bred ducks by YOLOv8n model through affine transformation method

By using affine transformation and enhancement techniques, the ability of the YOLOv8n model to recognize resting behavior in caged ducks has been improved. This has solved the problems of weak static feature recognition, background interference, and poor posture adaptability, and has achieved high-precision and robust resting behavior recognition, which is suitable for the refined management of large-scale breeding.

CN122049809APending Publication Date: 2026-05-15INST OF ANIMAL SCI & VETERINARY HUBEI ACADEMY OF AGRI SCI
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
INST OF ANIMAL SCI & VETERINARY HUBEI ACADEMY OF AGRI SCI
Filing Date
2026-02-08
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing lightweight models based on the YOLO series suffer from problems such as weak static feature recognition, background interference, poor posture adaptability, and insufficient scene adaptability in recognizing the resting behavior of caged ducks. This results in low recognition accuracy and poor real-time performance, failing to meet the refined management needs of large-scale farming.

Method used

Affine transformation is used to enhance the input image, including coordinate normalization, rotation matrix, translation vector, and bounding box update. Combined with techniques such as horizontal flipping, vertical flipping, HSV color perturbation, Mosaic enhancement, Mixup enhancement, and random erasure, the model's ability to recognize resting behavior is enhanced. Furthermore, the robustness and real-time performance of the model are improved through generalization enhancement components and few-shot learning program components.

Benefits of technology

It improved the accuracy and robustness of recognizing resting behavior in caged ducks, enhanced the model's anti-interference ability and posture adaptability, met the full-scenario monitoring needs of large-scale farming, and achieved an AP@0.5 recognition accuracy of 0.938, which is 4.1% higher than the baseline model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122049809A_ABST
    Figure CN122049809A_ABST
Patent Text Reader

Abstract

The invention relates to the crossing field of computer vision, deep learning target detection and precise poultry breeding, in particular to a method for improving recognition of rest behaviors of cage-bred ducks by a YOLOv8n model through an affine transformation method. According to the method, YOLOv8n is taken as a basic model, a self-adaptive affine transformation algorithm is introduced, affine transformation rotates and translates around a rest behavior core area, static feature stretching and edge sample cutting are avoided, multi-angle postures of side-to-side rest and group lying are simulated, and the rest behavior of a user is simulated. According to the method, data enhancement parameters are optimized, enhanced Dropout regularization is introduced, and a learning rate scheduling mechanism adaptive to static features is designed, so that the problems of low accuracy, weak anti-interference capability, poor attitude adaptability and insufficient scene stability of existing cage-bred duck rest behavior recognition are solved, the accuracy, robustness and real-time performance of rest behavior recognition are improved, and the method is suitable for popularization and application. And the large-scale breeding full-scene monitoring requirement is met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the interdisciplinary field of computer vision, deep learning object detection, and precision poultry farming, and specifically to a method for improving the YOLOv8n model's ability to recognize resting behavior in caged ducks using affine transformation. This invention can be applied to resting behavior recognition in the daily monitoring of caged ducks, and is suitable for intelligent management scenarios such as welfare assessment and health early warning in large-scale duck farms. Background Technology

[0002] In intensive cage-raised duck farming, resting behavior is a core indicator reflecting the ducks' metabolic rate, stress level, and welfare. Abnormal duration or posture (such as lying still or curling up on their side) often indicates disease infection, environmental discomfort, or group stress. Traditional monitoring of resting behavior relies on manual observation, which has drawbacks such as poor real-time performance, strong subjectivity, and easy omission of static behaviors, failing to meet the needs of refined management in large-scale farming.

[0003] While existing lightweight models based on the YOLO series have made some progress in poultry behavior recognition, there are significant shortcomings in their specific optimization for resting behavior: First, resting behavior is a static behavior with low feature recognition and strong homogeneity with the background of the metal cage, making it prone to misjudgment due to background interference; second, resting behavior involves various postures (standing, lying on one's side, and huddled together), resulting in insufficient diversity of sample postures and inadequate feature learning by existing models; third, fluctuations in lighting in caged environments can easily blur the boundary between resting behavior and the background, and existing optimization strategies are mostly geared towards dynamic behaviors, lacking specific enhancement mechanisms for static weak features. Furthermore, general affine transformations suffer from problems such as static feature stretching and edge sample clipping, leading to poor recognition accuracy and scene adaptability. Therefore, there is an urgent need to develop a specific optimization model for the resting behavior of caged ducks to solve core problems such as static weak feature recognition, background interference, and poor posture adaptability, achieving accurate and real-time recognition of resting behavior. Summary of the Invention

[0004] To address the shortcomings of existing technologies, this invention provides a method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using affine transformation. This invention utilizes affine transformations and other operations within scene-specific enhancement components to rotate and translate around the core region of the resting behavior, avoiding static feature stretching and edge sample clipping. It simulates multi-angle postures such as sideways resting and group crouching, solving the problems of low accuracy, weak anti-interference ability, poor posture adaptability, and insufficient scene stability in existing caged duck resting behavior recognition methods. This improves the accuracy, robustness, and real-time performance of resting behavior recognition, meeting the monitoring needs of large-scale farming across all scenarios.

[0005] The technical solution of this invention is: a method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using affine transformation, wherein the affine transformation method is used to enhance the input image, characterized by the following steps: (1) Coordinate Standardization: The pixel coordinates of the input image are converted to normalized coordinates [0, 1]. Using the bounding box (x1, y1, x2, y2), where x1 is the minimum value on the X-axis of the original image, y1 is the minimum value on the Y-axis of the original image, x2 is the maximum value on the X-axis of the original image, and y1 is the maximum value on the Y-axis of the original image, the center of the core region of the image (C) is calculated. x C y The formula is , ; (2) Rotation matrix: Construct the rotation matrix Where k=1.0; θ∈{±6°,±12°,±18°} is randomly selected. Let θ be the attitude correction rotation matrix, and θ be the attitude correction angle. (3) Translation vector: compensates for the risk of edge sample clipping, the formula is as follows: b is the translation vector; (4) Coordinate Transformation and Restoration: The new pixel coordinates are obtained through coordinate centering, linear transformation, and restoration steps, as shown in the following formulas: + , : , The pixel coordinates of the bounding box for the resting behavior in the original image; The coordinates are the original pixel coordinates (x, y) after centering. The new centered coordinates are obtained after transformation by rotation matrix A and translation vector compensation; , The transformed pixel coordinates are obtained after restoring the new centered coordinates; (5) Bounding box update: Extract the four vertices of the original bounding box and perform the above transformation. Fit the minimum bounding rectangle to obtain the new bounding box (x1', y1', x2', y2'). Perform the affine transformation process of steps (1)-(4) on each of these four vertices to obtain the transformed pixel coordinates of each vertex. Based on the four transformed vertices, fit the minimum bounding rectangle to obtain the new bounding box (x1', y1', x2', y2'). x1' is the minimum value on the X-axis of the new image, y1' is the minimum value on the Y-axis of the new image, x2' is the maximum value on the X-axis of the new image, and y2' is the maximum value on the Y-axis of the new image. The labeling error is ≤1 pixel.

[0006] The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method described above is characterized by: an image width W of 640 and an image height H of 640.

[0007] The method for improving the YOLOv8n model's recognition of resting behavior of caged ducks using the affine transformation method described above is characterized by: further including using horizontal flipping, vertical flipping, HSV color perturbation, Mosaic enhancement, Mixup enhancement, or random erasure to enhance the input image, with the enhancement operation controlled by the auto_augment=randaugment strategy.

[0008] The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method described above is characterized by: horizontal flipping being a mirror flip along the vertical midline of the image, synchronously updating the x-coordinate of the resting behavior bounding box; the horizontal flipping probability ranges from 40% to 60%; vertical flipping being a vertical flip along the horizontal midline of the image, synchronously updating the y-coordinate of the bounding box, the vertical flipping probability ranges from 5% to 20%.

[0009] The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method described above is characterized by: HSV color perturbation: Illumination scenes are divided by the image brightness mean V_mean: Low-light scenes have brightness perturbation of +0.1 to +0.18 and saturation of +0.1 to +0.18; strong-light scenes have brightness perturbation of -0.1 to -0.18 and saturation of -0.05 to -0.15; normal lighting has hue ±0.08, saturation ±0.18, and brightness ±0.18, with the bounding box coordinates remaining unchanged. The HSV color perturbation probability range is 80% to 100%.

[0010] The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method described above is characterized by: Mosaic enhancement: stitching four images of the same type of resting posture into one image, selecting only images of the same type of posture for stitching, using Gaussian blur transition with σ=1.5 in the stitching area, mapping all bounding box coordinates according to the stitching ratio, and the Mosaic enhancement probability range is 70% to 100%.

[0011] The method for improving the YOLOv8n model's recognition of resting behavior of caged ducks using the affine transformation method described above is characterized by: Mixup enhancement: randomly selecting one training set image and fusing it with the current image using random weight pixels of 0.1-0.9, while retaining the bounding boxes of the two images; the Mixup enhancement probability range is 10% to 20%.

[0012] The method for improving the YOLOv8n model to recognize the resting behavior of caged ducks based on the affine transformation method described above is characterized by the following process: (1) Core region localization: the core torso region of the resting behavior is defined in the image; (2) Occlusion region generation: a rectangular occlusion is randomly generated outside the core region, with the occlusion area accounting for 5%-10%; (3) Pixel filling strategy: the pixels in the occlusion region are set to the local 5×5 pixel neighborhood mean.

[0013] The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method described above is characterized by the following steps: It further includes a generalization enhancement component, the working steps of which are as follows: receiving the multi-scale feature map output by the backbone network C2f module from the scene-enhanced image; inserting Dropout layers at the output of each C2f module and at specific layers of the PAN-FPN, randomly "closing" some feature channels at a ratio of 0.09 to 0.23, with the closed channels dynamically changing with each training iteration; and inputting the feature map after Dropout processing into the next-level network to output a clean feature map "removed from background interference".

[0014] The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method described above is characterized by the following steps: It further includes a few-shot learning plan component, the steps of which are as follows: Inputting "background interference removed" feature maps into the few-shot learning plan component; manually labeling the resting behavior bounding boxes, ensuring that the number of labeled "background interference removed" feature maps is greater than 10% of the total number; and inputting the feature maps into the YOLOv8n model for training. Attached Figure Description

[0015] Figure 1 Flowchart for optimizing the YOLOv8n-improved model.

[0016] Figure 2 The recognition results of each model for rest behavior are shown (from left to right, YOLOv5n, YOLOv8n, YOLOv11n, YOLOv12n and YOLOv8n-improved, with confidence levels labeled in the detection boxes). Detailed Implementation

[0017] The technical solution of the present invention will be further described below with reference to the accompanying drawings.

[0018] like Figure 1The present invention discloses a method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using affine transformation. Based on the YOLOv8n model, a progressively optimized architecture is constructed by integrating Scene-Specific Augmentation Components (SSA), Generalization Augmentation Components (GED), and Small Shot Learning Plan Components (SSOLS). The specific optimization process is as follows: Step 1, Scene-Specific Enhancement Component (SSA): The input consists of training images of caged ducks resting behavior: top-down views taken by a 4-megapixel camera from a standardized caged duck house (cage size 60cm×60cm×40cm), with original video resolution of 2560×1440 pixels and a frame rate of 60fps; containing clear instances of resting behavior (standing, lying on their side, huddled together, etc.), without severe blur (clarity ≥85%) or heavy occlusion (occlusion area ≤30%), and bounding boxes of resting behavior have been labeled using the X-AnyLabeling tool (labeling accuracy ≥95%); this enhancement is only applied to the training set images (2593 images, containing 862 instances of resting behavior), while the validation set (324 images) and test set (325 images) are not enhanced to avoid interfering with the objectivity of performance evaluation; keyframes are extracted from the original videos using the OpenCV library, and invalid samples with no resting behavior, blurred images, or ducks completely occluded are manually removed to ensure that the input images have basic features suitable for enhancement.

[0019] Image processing: During the training phase, the following augmentation operations are applied sequentially or randomly to each input image. All augmentation operations are randomly triggered by the auto_augment=randaugment policy to generate diverse training samples: Horizontal flip (probability 0.5): Performed with a 50% probability, mirroring the image along its vertical midline and simultaneously updating the x-coordinate of the resting behavior bounding box (x' = image width - original x-coordinate), simulating the duck's symmetrical resting posture. The probability of horizontal flipping in this step can range from 40% to 60%.

[0020] Vertical flip (probability 0.1): Performed with a 10% probability, flipping the image vertically along its horizontal midline while simultaneously updating the bounding box's y-coordinate (y' = image height - original y-coordinate), simulating the unique resting posture of a duck lying on its side. The probability of vertical flipping in this step can range from 5% to 20%.

[0021] HSV color perturbation: Performed with 100% probability, it divides the lighting scene based on the image's mean brightness (V_mean): Low-light scene (V_mean < 80): brightness perturbation +0.1~+0.18, saturation +0.1~+0.18; Strong-light scene (V_mean > 200): brightness perturbation -0.1~-0.18, saturation -0.05~-0.15; Normal lighting (80 ≤ V_mean ≤ 200): hue ±0.08, saturation ±0.18, brightness ±0.18, with bounding box coordinates remaining unchanged. This enhances the model's ability to distinguish resting behavior from the background under different lighting conditions. The probability range of HSV color perturbation in this step can be 80% to 100%, randomly triggered in conjunction with the auto_augment strategy to avoid excessive perturbation leading to distortion of static features.

[0022] Affine transformation (100% probability): Rotation and translation are performed around the core region of resting behavior to avoid static feature stretching and edge sample clipping, simulating multi-angle postures such as sideways resting and group crouching. The specific workflow of the affine transformation method disclosed in this invention is as follows: (1) Coordinate Standardization: The pixel coordinates of the input image are converted to normalized coordinates [0, 1]. Using the bounding box (x1, y1, x2, y2), where x1 is the minimum value on the X-axis of the original image, y1 is the minimum value on the Y-axis of the original image, x2 is the maximum value on the X-axis of the original image, and y1 is the maximum value on the Y-axis of the original image, the center of the core region of the image (C) is calculated. x C y The formula is , Where W is the image width and H is the image height, and W=640 and H=640 are the image dimensions, the core region center is... , ; (2) Rotation matrix: Based on the distribution of resting behavior postures (standing rest, lying on one's side, and group lying down), a rotation matrix with a fixed feature protection factor k=1.0 is constructed. The core function of k=1.0 is to completely preserve the original torso proportions and static feature contours of the resting behavior, avoid feature distortion during the transformation process, and improve the recognition consistency of multi-pose resting behaviors; θ∈{±6°,±12°,±18°} is randomly selected. The posture correction rotation matrix is ​​given by θ, where θ is the posture correction angle (±12° / ±18° is preferred for side-lying samples, and ±6° is preferred for standing / resting samples). This step's posture correction rotation matrix... The accuracy of recognizing resting postures can be improved by utilizing the coordinate restoration step.

[0023] (3) Translation vector: combined with the coordinates of the core region (C x Cy Calculate the translation vector to compensate for the risk of edge sample clipping; the formula is as follows. b is the translation vector. When W=640 and H=640, Ensure that the core area does not exceed the image range; (4) Coordinate Transformation and Restoration: The new pixel coordinates are obtained through coordinate centering, linear transformation, and restoration steps, as shown in the following formulas: + , In the formula , This is a general example notation for the centered coordinates of any vertex after transformation; more will follow. , This is the application of the example on a specific vertex.

[0024] , : Pixel coordinates of the four vertices of the bounding box of the resting behavior in the original image; b: Translation vector in affine transformation, used to compensate for the positional shift of the core region after rotation, avoiding edge sample clipping; : The original pixel coordinates (x, y) after centering; The new centered coordinates are obtained after transformation by rotation matrix A and translation vector compensation. , The transformed pixel coordinates obtained after restoring the new centered coordinates.

[0025] Coordinate centering: Converts pixel coordinates to coordinates with the image center as the origin, eliminating the influence of image size on rotation calculation, making the transformation logic adaptable to input images of any size, and improving versatility; Linear transformation: Through the synergistic effect of rotation matrix A and translation vector b, posture correction and position compensation of resting behavior are achieved, avoiding edge sample clipping and improving the utilization rate of effective samples; Coordinate Restoration: The centered coordinates are restored to pixel coordinates to fit the 640×640 input size requirement of the YOLOv8n model. The transformed image can be directly used for model training.

[0026] When W=640 and H=640 + , ; (5) Bounding box update: Extract the four vertices of the original bounding box and perform the above transformation. Fit the minimum bounding rectangle to obtain the new bounding box (x1', y1', x2', y2'). Perform the affine transformation process of steps (1)-(4) on each of these four vertices to obtain the transformed pixel coordinates of each vertex, which are (x1', y1', x2', y2'). a ',y a '), (x b ',y b '), (x c ',y c '), (x d ',y d Based on the transformed four vertices, fit the minimum bounding rectangle to obtain the new bounding box (x1', y1', x2', y2'). The fitting formula is: x1' = min (x a ', x b ', x c ', x d (Take the minimum value of the X-axis coordinates of the vertex after the four transformations); y1' = min (y a ',y b ',y c ',y d (Take the minimum value of the Y-axis coordinates of the four transformed vertices); x2' =min (x a ', x b ', x c ', x d (Take the maximum value of the X-axis coordinates of the four transformed vertices); y2' =min (y a ',y b ',y c ',y d (Take the maximum value of the Y-axis coordinates of the four transformed vertices).

[0027] x1' is the minimum value on the X-axis of the new image, y1' is the minimum value on the Y-axis of the new image, x2' is the maximum value on the X-axis of the new image, and y2' is the maximum value on the Y-axis of the new image. The labeling error is ≤1 pixel.

[0028] Mosaic enhancement (probability 0.9): Performed with a 90% probability, this step stitches four images of the same type of resting posture into one (resting postures are categorized into three types: individual resting, two ducks huddled together, and multiple ducks huddled together). Only images of the same type of posture are selected for stitching. The stitched region is transitioned using a Gaussian blur with σ=1.5. All bounding box coordinates are mapped according to the stitching ratio to simulate a scenario of multiple ducks huddled together for rest, thus improving the model's ability to extract features from group resting behavior. The probability of performing Mosaic enhancement in this step can range from 70% to 100%.

[0029] Mixup enhancement (probability 0.15): Performed with a 15% probability, this step randomly selects one training set image and merges it with the current image using random pixel weights of 0.1-0.9, preserving the bounding boxes of both images. This enhances the model's ability to distinguish resting behavior from the background. The probability of performing Mixup enhancement in this step can range from 10% to 20%.

[0030] Random erasure (probability 0.08): Executed with an 8% probability, (1) Core region localization: Define the core torso region of the resting behavior in the image as =[ +0.1W, +0.1H, -0.1W, -0.1H]; when W=640, H=640, ( =[ +0.1×640, +0.1×640, -0.1×640, -0.1×640];(2)Occlusion area generation: Randomly generate rectangular occlusion outside the core area, with the occlusion area accounting for 5%-10%;(3)Pixel filling strategy: Set the pixel of the occlusion area to the local 5×5 pixel neighborhood mean, the formula is pixel erase = ∑ (x,y)∈Rlocal pixel (x,y), where (x,y): the coordinates of any pixel within the occluded region, which is also the local neighborhood R. local Pixel coordinates within; R local : A 5×5 pixel local neighborhood centered on a pixel within the occluded area, used to extract smooth pixel values ​​and avoid occlusion; S local Local neighborhood R local The total number of pixels within the local neighborhood; pixel (x,y): local neighborhood R local Within, the original pixel grayscale / RGB value corresponding to coordinates (x, y); pixel eraseThe filled pixel value within the occluded area is the arithmetic mean of all pixel values ​​in the local neighborhood. This allows the model to focus on the global static features of resting behavior rather than local texture, improving its resistance to occlusion. The random erasure probability in this step can range from 5% to 15%.

[0031] The static weak features, multi-pose characteristics, and cage background interference of resting behavior are enhanced through the above-mentioned operations to expand feature diversity and protect core features. The principle is as follows: horizontal flipping, vertical flipping, and affine transformation expand multi-pose resting samples to solve the problem of "insufficient coverage of single pose features"; HSV color perturbation simulates different lighting conditions to avoid blurring of the boundary between resting behavior and cage background caused by lighting changes; Mosaic stitching generates group resting scenes, and Mixup merges different behavior boundary scenes to solve the problem of "insufficient generalization of single scenes"; random erasure simulates slight occlusion, so that the model ignores irrelevant backgrounds (such as metal cages) and focuses on the core static features of resting behavior.

[0032] Step 2, Generalization Enhancement Component (GED): Enhanced Dropout regularization is introduced into the backbone network and neck layer of the model. The Dropout ratio is set to 0.16 to suppress overfitting caused by background homogeneity.

[0033] The Generalization Enhancement Component (GED) takes as input the SSA-enhanced training set image feature map—that is, the intermediate feature map extracted from the input image by the YOLOv8n backbone network (C2f module), containing enhanced static features of resting behavior and cage background features. Its working steps are as follows:

[0034] Step 21, Feature Input: Receive the multi-scale feature map output by the backbone network C2f module after the image is enhanced by the Scene Specific Augmentation Component (SSA);

[0035] Step 22, Dropout Layer Function: A Dropout layer is inserted at the output of each C2f module and at a specific layer of PAN-FPN, randomly "closing" some feature channels at a ratio of 0.16, and the closed channels change dynamically with each training iteration; the ratio range in this step can be from 0.09 to 0.23. Background Feature Suppression in this Step: Since the background features of the cage are highly similar (high homogeneity) in multiple images, dynamically closing channels would disrupt the consistency of background features, while the static features of the resting behavior are diverse and will not lose core information due to the closure of some channels; therefore, it can reduce the amount of computation while ensuring the accuracy of the results.

[0036] Step 23, Feature Output: The feature map after Dropout processing is fed into the next level network, outputting a clean feature map "without background interference", laying the foundation for subsequent few-shot learning.

[0037] Differences between Enhanced Dropout and Standard Dropout: Standard Dropout (YOLOv8n default): 0.1 (used only in the shallow layers of the detection head); focuses on class prediction only for the classification branch of the detection head; general overfitting (e.g., sample noise, feature redundancy); no scene adaptation optimization, works independently. Enhanced Dropout (GED): 0.16 (used in both the backbone network C2f module and the neck PAN-FPN layer); covers both the backbone network (feature extraction stage) and the neck (feature fusion stage), suppressing background interference from the source; specifically suppresses overfitting caused by the homogeneity of the cage background, where the metal cage mesh texture is uniform in caged scenarios, making it easy for the model to mistakenly identify the background as resting features; the Generalization Enhancement Component (GED) works in conjunction with the color perturbation and random erasure of SSA to enhance the ability to distinguish between "background-target" features.

[0038] Step 3, Small Shot Learning Plan Component (SSOLS):

[0039] The specific working process of the Small Sample Learning Plan Component (SSOLS) is as follows:

[0040] Step 31: Input the “background interference removed” feature map output by the Generalization Enhancement Component (GED) into the Small Shot Learning Plan Component (SSOLS).

[0041] Step 32: Then, manually label the bounding boxes of the resting behavior. The number of "background interference removed" feature maps with labels should be greater than 10% of the total number.

[0042] Step 33: Input the feature map into the YOLOv8n model for training. Real-time performance metrics during training include validation set rest behavior AP@0.5, loss value, etc. These metrics can be set according to actual requirements.

[0043] The output after training is as follows: ① The weight file of the YOLOv8n-improved model after training convergence (best.pt format); ② The optimized model inference parameters (such as confidence threshold and IoU threshold); ③ Training log (including performance indicators for each period, used to verify the convergence effect).

[0044] In step 33, during training, the initial learning rate is set to 0.0018 and the final learning rate to 0.0001. A cosine annealing learning rate decay strategy is used to enable the model to converge quickly in the early stages of training and fine-tune it in the later stages, which is suitable for the slow learning of static features of resting behavior. The period for disabling Mosaic enhancement is set to 30 to avoid complex enhancements interfering with the stable convergence of small sample features. The training patience value is set to 70, meaning that if the performance on the validation set does not improve within 70 epochs, training is stopped early to prevent overfitting.

[0045] The synergistic advantages of the method in this invention are as follows: SSA and GED synergy: SSA breaks the visual consistency of the background through random erasure and color perturbation, while GED further suppresses redundant expression of background features through Dropout, thereby improving the discriminative power of "rest features - background features"; GED and SSOLS synergy: The features output by GED reduce the training noise of SSOLS, making it easier for static feature training with a low learning rate (0.0018) to converge; SSA and SSOLS synergy: The multi-pose and multi-environment samples expanded by SSA provide rich feature support for the small sample learning of SSOLS, avoiding the model from getting stuck in local optima due to a lack of samples. The baseline YOLOv8n achieved an AP@0.5 of 0.897 for resting behavior, YOLOv5n achieved 0.903, YOLOv11n achieved 0.889, and YOLOv12n achieved 0.901. The YOLOv8n-improved model optimized by this invention achieved an AP@0.5 of 0.938 for resting behavior, a 4.1% improvement over the baseline YOLOv8n (0.897) (Table 1). The overall model achieved an mAP@50 of 0.897, a recall of 0.823, a precision of 0.868, maintained 142 FPS (GPU environment), and maintained 3.0M parameters (Table 2). Ablation experiments verified that the AP@0.5 for resting behavior improved from 0.9215 to 0.9418 (+2.2%) (Table 3).

[0046] Table 1. Comparison of AP@0.5 values ​​for each model in validating duck resting behavior.

[0047] Model rest YOLOv5n 0.903 YOLOv8n 0.897 YOLOv11n 0.889 YOLOv12n 0.901 YOLOv8n-improved 0.938

[0048] Table 2. Comparison of overall performance of each model on the validation set

[0049] Model mAP@50 mAP@50-95 Precision (P) Recall rate (R) Number of parameters (M) FPS YOLOv5n 0.918 0.730 0.940 0.890 1.9 142 YOLOv8n 0.886 0.699 0.780 0.918 3.0 156 YOLOv11n 0.886 0.709 0.844 0.874 2.7 127 YOLOv12n 0.892 0.702 0.855 0.835 2.54 118 YOLOv8n-improved 0.897 0.687 0.868 0.823 3.0 142

[0050] Table 3. Comparison of performance indicators by ablation test category (AP@0.5)

[0051] experimental group rest Baseline_YOLOv8n 0.9215 SSA 0.9183 SSA+GED+SSOLS 0.9267 YOLOv8n-improved (optimized SSA+GED+SSOLS) 0.9418 GED+SSOLS 0.9376

[0052] The following is an example of the application and verification of the method of the present invention in a project, namely a method for detecting the resting behavior of caged ducks, including the following process:

[0053] 1. Dataset Construction

[0054] (1) Data collection: In the standardized caged duck house of the Hubei Academy of Agricultural Sciences Poultry Breeding Experimental Farm, each duck cage is 60cm×60cm×40cm in size. The camera is installed above the cage to collect top view, covering different lighting and time scenes such as cloudy days, sunny days, morning, noon, and evening. The video resolution is 3840×2160 and the frame rate is 25 fps.

[0055] (2) Data preprocessing: Keyframes were extracted using the OpenCV library. Clear images containing resting behaviors (standing, lying on one's side, group lying down, etc.) were manually selected, and blurry or severely occluded samples were removed. Finally, a dataset containing 3242 images was constructed, of which 1077 resting behavior instances accounted for 33.2%. The training set consisted of 2593 images (containing 862 resting behavior instances), the validation set consisted of 324 images (containing 108 resting behavior instances), and the test set consisted of 325 images (containing 107 resting behavior instances). Data augmentation strategies such as horizontal flipping, vertical flipping, and affine transformation were used to expand the diversity of training set samples.

[0056] (3) Data set partitioning: The dataset was randomly partitioned into a training set of 2593 images, a validation set of 324 images, and a test set of 325 images in a ratio of 8:1:1.

[0057] 2. Model optimization and ablation experiment verification

[0058] (1) Basic model configuration: YOLOv8n was selected as the basic model. Its backbone network is the C2f module, the neck is the PAN-FPN structure, the detection head adopts the anchor box design, and the pre-trained weights are the official release version.

[0059] (2) Component integration optimization: SSA component: configured with horizontal flip probability of 0.5, vertical flip probability of 0.1, HSV color perturbation parameters, affine transformation angle set θ∈{±6°, ±12°, ±18°}, Mosaic enhancement probability of 0.9, Mixup enhancement probability of 0.15, random erasure probability of 0.08, to enhance the diversity and generalization of rest behavior features; GED component: insert Dropout layer into the backbone network C2f module and neck PAN-FPN layer, with a ratio of 0.16, to suppress overfitting caused by the metal cage background; SSOLS component: initial learning rate of 0.0018, final learning rate of 0.0001, enable cos_lr=True (cosine annealing learning rate decay), close_mosaic=30 (disable Mosaic enhancement after the 30th training epoch), patience=70 (if the validation set performance does not improve after 70 epochs, training will be stopped early), to adapt to the slow convergence characteristics of static rest behavior features.

[0060] (3) Training parameter settings: input image size 640×640, batch size 64, optimizer AdamW, training cycle 100, enable AMP training, and complete training on NVIDIA GeForce RTX 4090 GPU (24GB VRAM).

[0061] (4) Ablation experiment verification: Five experimental groups were designed to verify the effectiveness of the components. The results showed that after integrating the three components SSA+GED+SSOLS, the resting behavior AP@0.5 reached 0.9418, which was 2.2% higher than the baseline, confirming the effectiveness of the model improvement.

[0062] 3. Generalization performance test

[0063] Four 5-minute video clips (1920×1080 resolution, 25 FPS) were collected from another untrained caged duck house, covering different scenes such as cloudy nights and sunny midday. Test results showed that the model maintained a confidence level of 0.74-0.75 in recognizing resting behavior, with a single-frame inference speed of 14.1 ms (≈71 FPS), a low false negative rate, no serious false positives, and significantly better resistance to changes in lighting and background interference than the baseline YOLOv8n.

Claims

1. A method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using affine transformation, characterized by employing affine transformation to enhance the input image: The affine transformation method includes the following steps: (1) Coordinate Standardization: The pixel coordinates of the input image are converted to normalized coordinates [0, 1]. Using the bounding box (x1, y1, x2, y2), where x1 is the minimum value on the X-axis of the original image, y1 is the minimum value on the Y-axis of the original image, x2 is the maximum value on the X-axis of the original image, and y1 is the maximum value on the Y-axis of the original image, the center of the core region of the image (C) is calculated. x C y The formula is , ; (2) Rotation matrix: Construct the rotation matrix Where k=1.0; θ∈{±6°,±12°,±18°} is randomly selected. Let θ be the attitude correction rotation matrix, and θ be the attitude correction angle. (3) Translation vector: compensates for the risk of edge sample clipping, the formula is as follows: b is the translation vector; (4) Coordinate Transformation and Restoration: The new pixel coordinates are obtained through coordinate centering, linear transformation, and restoration steps, as shown in the following formulas: + , : , The pixel coordinates of the bounding box for the resting behavior in the original image; The coordinates are the original pixel coordinates (x, y) after centering. The new centered coordinates are obtained after transformation by rotation matrix A and translation vector compensation; , The transformed pixel coordinates are obtained after restoring the new centered coordinates; (5) Bounding box update: Extract the four vertices of the original bounding box and perform the above transformation. Fit the minimum bounding rectangle to obtain the new bounding box (x1', y1', x2', y2'). Perform the affine transformation process of steps (1)-(4) on each of these four vertices to obtain the transformed pixel coordinates of each vertex. Based on the four transformed vertices, fit the minimum bounding rectangle to obtain the new bounding box (x1', y1', x2', y2'). x1' is the minimum value on the X-axis of the new image, y1' is the minimum value on the Y-axis of the new image, x2' is the maximum value on the X-axis of the new image, and y2' is the maximum value on the Y-axis of the new image. The labeling error is ≤1 pixel.

2. The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method according to claim 1, characterized in that: The image width W is 640 and the image height H is 640.

3. The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method according to claim 1 or 2, characterized in that: It also includes methods such as horizontal flipping, vertical flipping, HSV color perturbation, Mosaic enhancement, Mixup enhancement, or random erasure to enhance the input image. The enhancement operation is controlled by the auto_augment=randaugment strategy.

4. The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method according to claim 3, characterized in that: Horizontal flip is a mirror flip along the vertical midline of the image, synchronously updating the x-coordinate of the bounding box of the resting behavior; the horizontal flip probability ranges from 40% to 60%; vertical flip is a vertical flip along the horizontal midline of the image, synchronously updating the y-coordinate of the bounding box; the vertical flip probability ranges from 5% to 20%.

5. The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method according to claim 3, characterized in that: HSV Color perturbation: Illumination scenes are divided by the image brightness mean V_mean: low light scene brightness perturbation +0.1~+0.18, saturation +0.1~+0.18; strong light scene brightness perturbation -0.1~-0.18, saturation -0.05~-0.15; normal lighting hue ±0.08, saturation ±0.18, brightness ±0.18, bounding box coordinates remain unchanged, and the HSV color perturbation probability range is 80% to 100%.

6. The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method according to claim 3, characterized in that: Mosaic enhancement: Four images of the same type of resting pose are stitched into one image. Only images of the same type of pose are selected for stitching. The stitching area is transitioned with Gaussian blur of σ=1.

5. All bounding box coordinates are mapped according to the stitching ratio. The probability of Mosaic enhancement is 70% to 100%.

7. The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method according to claim 3, characterized in that: Mixup enhancement: Randomly select one training set image and fuse it with the current image with random weight pixels of 0.1-0.9, retaining the bounding boxes of the two images; the probability of Mixup enhancement is 10% to 20%.

8. The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method according to claim 3, characterized in that: Random erasure includes the following process: (1) Core region localization: The core torso region of the resting behavior is defined in the image; (2) Occlusion area generation: Randomly generate rectangular occlusion outside the core area, with the occlusion area accounting for 5%-10%. (3) Pixel filling strategy: Set the pixel value of the occlusion area to the local 5×5 pixel neighborhood average.

9. The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method according to claim 1, characterized in that: It also includes the step of generalization enhancement component, the working steps of which are as follows: receiving the multi-scale feature map output by the backbone network C2f module of the scene enhancement image; inserting Dropout layers at the output of each C2f module and a specific layer of PAN-FPN, randomly "closing" some feature channels at a ratio of 0.09 to 0.23, and the closed channels dynamically change with each training iteration; the feature map after Dropout processing is fed into the next level network, and outputs a clean feature map "removed from background interference".

10. The method for improving the YOLOv8n model's recognition of resting behavior in caged ducks using the affine transformation method according to claim 1, characterized in that: It also includes the steps of the few-shot learning plan component, which are as follows: input the "background interference removed" feature map into the few-shot learning plan component; manually label the rest behavior bounding boxes, and the number of labeled "background interference removed" feature maps should be greater than 10% of the total number; input the feature maps into the YOLOv8n model for training.