A pig target detection method based on scene prior guidance

CN122676537APending Publication Date: 2026-09-01JIAOZUO YUKANG FOOD CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610833805.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-10
Publication Date
2026-09-01

AI Technical Summary

Technical Problem

当检测模型无法有效区分稳定背景区域与真实猪只区域时,背景区域产生的高响应特征可能在多层特征传播过程中被持续强化,从而导致背景误检、目标边界偏移以及目标定位不稳定等问题

Benefits of technology

1、本发明基于场景先验引导的猪只目标检测方法,解决了现有猪只目标检测方法缺少固定猪舍场景空间稳定性建模、背景区域干扰严重以及密集遮挡条件下检测稳定性不足的问题。利用固定猪舍场景中的空间稳定性建立场景先验信息,能够显式区分背景区域与目标活动区域,提高检测特征表达能力。通过坐标编码建立位置感知能力,使检测网络能够学习固定场景中的空间分布规律,增强目标区域定位稳定性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure FT_1
    Figure FT_1
  • Figure FT_2
    Figure FT_2
  • Figure FT_3
    Figure FT_3
Patent Text Reader

Abstract

A scene-prior-guided pig target detection method includes input image and feature extraction, coordinate encoding generation, and explicit foreground prior prediction. The method inputs features fused with spatial priors into a foreground prior prediction head. Foreground prior information is generated through convolutional mapping, normalization, and nonlinear activation. A foreground probability map is generated by activating the foreground probability map using the sigmoid function. The foreground probability map is then used to perform residual foreground modulation on the original detection features to enhance the foreground region. A weakly supervised foreground mask is automatically generated based on the target detection bounding boxes, and an auxiliary prior loss is constructed to supervise and constrain the foreground probability map. Finally, the enhanced detection features are input into the detection head to complete pig target classification and bounding box regression, outputting the final detection result. This invention solves the problems of existing pig target detection methods, such as lack of fixed pigsty scene spatial stability modeling, severe background interference, and insufficient detection stability under dense occlusion conditions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of computer vision and intelligent farming technology, specifically to a method for pig target detection based on scene prior guidance. Background Technology

[0002] With the continuous development of large-scale and intelligent farming technologies, computer vision-based intelligent pig sensing technology has gradually become an important research direction in the modern pig farming field. Among them, pig target detection, as a fundamental link in tasks such as pig behavior recognition, individual tracking, quantity statistics, health monitoring, and abnormal behavior analysis, directly affects the operational effectiveness of subsequent intelligent farming systems due to its accuracy and stability.

[0003] In existing technologies, target detection for pigs is typically achieved using deep learning-based target detection models, including single-stage detection methods based on convolutional neural networks and end-to-end detection methods based on Transformer structures. However, most existing methods are designed for open scenarios and lack the ability to explicitly model the spatial stability of fixed pigsty environments, thus making them susceptible to interference from fixed background areas.

[0004] In a fixed pigsty monitoring environment, the camera position, shooting angle, and scene structure remain stable over a long period. Background structures such as fences, walls, feed troughs, and shaded areas typically appear in fixed spatial locations and repeat at different times. When the detection model cannot effectively distinguish between stable background areas and real pig areas, the high-response features generated by the background areas may be continuously amplified during multi-layer feature propagation, leading to problems such as background false detection, target boundary shift, and unstable target localization.

[0005] In addition, existing detection models usually rely on implicit feature responses to model the target region, lacking an explicit mechanism to distinguish between "foreground region" and "background region". At the same time, existing methods lack spatial location awareness and have difficulty learning the spatial distribution patterns in a fixed pigsty environment. Under dense occlusion conditions, they are prone to background false detection and positioning offset problems.

[0006] Therefore, this invention proposes a scene prior-guided detection method that combines the spatial patterns of a fixed pigsty scene, prior location information, and explicit foreground region modeling mechanism to reduce the interference of fixed background regions on the target detection process and improve the stability and robustness of dense pig detection tasks in complex pigsty environments. Summary of the Invention

[0007] To address the shortcomings of existing technologies, this invention proposes a scene-prior guided pig target detection method. By constructing a scene-prior guided module (SPGM), the method leverages the spatial stability of a fixed pigsty scene to establish positional awareness. Combined with explicit foreground region modeling and residual foreground modulation mechanisms, it achieves enhanced representation of the target region and suppression of background interference, thereby improving detection stability, localization accuracy, and robustness under complex occlusion conditions in dense pigsty scenarios.

[0008] This invention can be applied to scenarios such as pig target detection, behavior analysis, individual monitoring, and intelligent breeding management in large-scale pig farming environments.

[0009] Invention technical solution: The present invention relates to a scene-prior guided method for pig target detection, and its technical implementation process is as follows: Step 1: Input Image and Multi-Scale Feature Extraction The acquired images of the pigsty to be detected are input into the backbone structure of the target detection network for multi-scale feature extraction, resulting in feature maps of different scales. The feature maps are used to characterize the target area of ​​the pigs, the background area, and the spatial structure information of the scene.

[0010] Step 2: Coordinate Encoding Generation A coordinate encoding is constructed for the detection feature map to generate position coordinate information corresponding to the spatial size of the detection feature map; the coordinate encoding is used to establish the spatial position perception capability of the detection feature, so that the detection network can explicitly perceive the spatial distribution pattern in the fixed pig house scene; then, the coordinate encoding is fused with the detection feature map to obtain a detection feature map with spatial position information. For the input feature map X, generate a horizontal coordinate mapping P_x and a vertical coordinate mapping P_y. Further, concatenate the horizontal and vertical coordinate mappings to obtain the spatial coordinate encoding. P="Concat"(P_x,P_y) The coordinate values ​​in the coordinate encoding are normalized to a range of [0,1]. Furthermore, the coordinate encoding is fused with the original detection features to establish a correlation between the detection features and spatial location. F_c="Concat"(X,P) Step 3: Explicit Foreground Prior Prediction The detected feature map containing spatial location information is input into the foreground prior prediction head for foreground region prediction, generating an explicit foreground prior to represent the probability distribution information of the current spatial location belonging to the foreground region of a pig; among which, channel mapping is performed on the fused features: F_1 = ϕ_1 (F_c) Subsequently, spatially aware convolution operations are performed on the mapped features: F_2 = ϕ_2 (F_1) Furthermore, the convolution results are normalized and nonlinearly activated: F_3=σ("Norm"(F_2)) Finally, foreground response prediction is performed on the enhanced features: L_p=ϕ_3 (F_3) Where L_p represents the foreground prior logits. The explicit foreground prior is used to characterize the probability distribution information that the current spatial location belongs to the foreground region of the pig.

[0011] Then, the prior prediction results of the foreground are further activated to generate a foreground probability map, which is used to distinguish the potential target region from the fixed background region. The foreground probability map is generated as follows: M_p="Sigmoid"(L_p) Where M_p represents the foreground probability map.

[0012] Step 4: Foreground-guided feature enhancement The generated foreground probability map is used to enhance the original detection features using foreground-guided enhancement. This foreground-guided feature enhancement process increases the proportion of the pig's main body region in the feature representation and suppresses the interference propagation of the background region to the detection network. Specifically, a residual foreground modulation method is used to enhance the features of the target-related region while preserving the original detection feature information. The calculation formula for the residual foreground modulation method is as follows: F_o=X+α(X⊙M_p ) Where: F_o represents the output enhancement feature; X represents the input detection feature; M_p represents the foreground probability map; ⊙ represents element-wise multiplication; α represents the learnable modulation coefficient.

[0013] Step 5: Weakly supervised prospect constraint Weakly supervised foreground masks are automatically generated based on the sample labels in the dataset and used as supervision signals in the explicit foreground prior learning process. By constructing an auxiliary prior loss of multi-scale feature maps, the consistency between the foreground prior prediction results and the weakly supervised foreground masks is constrained. For any spatial location (x, y) in the image, the weakly supervised foreground mask is constructed as follows: M_gt (x,y)={■(1,&(x,y)∈b_i@0,&"otherwise" )┤ The target detection annotation set is represented as B={b_1,b_2,…,b_N}, where N represents the number of targets.

[0014] When multiple target bounding boxes overlap, the overall foreground region is constructed using a region union approach: M_gt=⋃_(i=1)^N▒b_i .

[0015] The auxiliary prior loss for multi-scale feature maps includes binary cross-entropy loss and Dice loss, and their expressions are as follows: L_prior=λ_1 L_bce+λ_2 L_dice Where: L_bce represents the binary cross-entropy loss; L_dice represents the Dice loss; λ_1, λ_2 represent the corresponding loss weight coefficients.

[0016] The binary cross-entropy loss expression is: L_bce=-1 / N ∑_(i=1)^N▒[M_gt^((i) ) log(M_pred^((i) ))+(1-M_gt^((i)))log(1-M_pred^((i) ))] Where: N is the total number of spatial locations in the feature map; M_pred^((i)) represents the foreground prediction probability of the i-th location; M_gt^((i)) represents the supervision label of the corresponding location.

[0017] The Dice Loss expression is: L_dice=1-(2·∑M_pred M_gt+ϵ) / (∑M_pred+∑M_gt+ϵ) The multi-scale auxiliary supervision loss expression is: L_prior^multi=∑_(k=1)^K▒L_prior^((k) ) Where: K represents the number of feature layers; L_prior^((k)) represents the auxiliary prior loss at the k-th scale.

[0018] Step 6: Detect Output The enhanced detection feature map, guided by scene priors, is fed into the feature fusion and detection head network of the target detector for further feature processing, completing the pig target classification and location regression, and outputting the final detection result.

[0019] The target detector is RT-DETRv1, and the final detection result is: Output="RT-DETRv1"(F_o), where F_o is the output enhancement feature of the foreground prior prediction head.

[0020] Beneficial effects of the invention: 1. This invention presents a scene-prior-guided pig target detection method, addressing the shortcomings of existing pig target detection methods, such as lack of spatial stability modeling for fixed pigsty scenes, severe background interference, and insufficient detection stability under dense occlusion conditions. By utilizing the spatial stability within a fixed pigsty scene to establish scene prior information, it can explicitly distinguish between background areas and target activity areas, improving the ability to represent detection features. Furthermore, by establishing position awareness through coordinate encoding, the detection network can learn the spatial distribution patterns within the fixed scene, enhancing the stability of target area localization.

[0021] 2. The present invention is a pig target detection method based on scene-prior guided module (SPGM). By constructing a scene-prior guided module (SPGM), the method establishes position awareness by utilizing the spatial stability in a fixed pig house scene. Combined with explicit foreground region modeling and residual foreground modulation mechanism, it achieves enhanced expression of the target region and suppression of background interference, thereby improving the detection stability and localization accuracy in dense pig scenes.

[0022] 3. This invention presents a scene-prior-guided pig target detection method. Through explicit foreground prior prediction and foreground-guided enhancement mechanisms, it reduces interference from background regions during feature propagation, improving robustness in dense pig detection scenarios. No additional pixel-level segmentation annotation is required; weakly supervised foreground masks can be generated using only rectangular bounding boxes, reducing data annotation costs. It is compatible with existing target detection frameworks and can be easily integrated into detection networks such as RT-DETR and YOLO, demonstrating good engineering adaptability and practical application value.

[0023] 4. This invention provides a scene-prior-guided pig target detection method. It learns the foreground region through a weakly supervised foreground mask and an auxiliary prior loss. The weakly supervised foreground mask is obtained by mapping the target detection box, eliminating the need for additional pixel-level segmentation and annotation. This improves the robustness of the method under complex occlusion conditions in dense pig detection tasks in complex pigsty environments, making it suitable for pig detection, behavior analysis, and intelligent monitoring tasks in large-scale smart farming scenarios. Attached Figure Description

[0024] Figure 1 The diagram shows the detection flowchart of the pig target detection method based on scene prior guidance of the present invention. Figure 2 The figure shows the hyperparameter settings of the pig target detection method based on scene prior guidance of the present invention; Figure 3 The figure shown is a training iteration error diagram of the pig target detection method based on scene prior guidance of the present invention; Figure 4 The image shows the pig house scene detection results of the pig target detection method based on scene prior guidance according to the present invention. Detailed Implementation

[0025] To make the technical concept and advantages of the invention clearer, the technical solution of the present invention will be further described in detail below with reference to the accompanying drawings. It should be understood that the following embodiments are merely preferred embodiments for explaining and illustrating the present invention, and should not be considered as, nor constitute a limitation on, the scope of patent protection claimed by the present invention. Example

[0026] See Figure 1 The present invention provides a pig target detection method based on scene prior guidance, comprising the following steps: S1, Input Image and Multi-Scale Feature Extraction An image of a pigsty to be detected is acquired and input into the backbone structure of a target detection network for multi-scale feature extraction, resulting in detection feature maps at different scales; the multi-scale features simultaneously include target region features and stable background region features. The resulting feature maps are used to characterize the target area, background area, and spatial structure information of the scene. Since the fences, walls, floors, feed troughs, and shaded areas in a fixed pigsty environment have spatial stability during long-term data collection, the multi-scale features simultaneously include target area features and stable background area features.

[0027] S2, Coordinate Encoding Generation A coordinate encoding is constructed for the detection feature map to generate position coordinate information corresponding to the spatial size of the feature map; the coordinate encoding is used to establish the spatial position perception capability of the detection features, enabling the detection network to explicitly perceive the spatial distribution pattern in a fixed pigsty scene; then, the coordinate encoding is fused with the original detection features to establish the correlation between the detection features and the spatial position, and a detection feature map with spatial position information is obtained. S3, Explicit Foreground Prior Prediction The detection feature map with spatial location information is input into the foreground prior prediction head to predict the foreground region and generate an explicit foreground prior, which is used to characterize the probability distribution information of the current spatial location belonging to the foreground region of the pig; the foreground prior prediction result is activated to generate a foreground probability map, which is used to distinguish the potential target region from the fixed background region. S4, Foreground Leading Feature Enhancement The generated foreground probability map is used to perform foreground-guided feature enhancement on the original detection features; Foreground-guided enhancement employs residual foreground modulation to enhance features in target-related regions while preserving original detection features. This foreground-guided feature enhancement process increases the proportion of the pig's main body region in feature representation and suppresses interference from background regions on the detection network.

[0028] S5, Weakly Supervised Prospect Constraint Weakly supervised foreground masks are automatically generated based on the sample labels in the dataset and used as supervision signals in the explicit foreground prior learning process. By constructing an auxiliary prior loss, the consistency between the foreground prior prediction results and the weakly supervised foreground masks is constrained. S6, Output Detection The enhanced detection feature map, guided by scene priors, is input into the feature fusion and detection head network of the target detector for further feature processing, completing the pig target classification and location regression, and outputting the final detection result. Example

[0029] like Figure 1 As shown, the present invention provides a pig target detection method based on scene prior guidance, comprising the following steps: Step 1: Input Image and Feature Extraction: Collect pig image data in a fixed pigsty environment, input it into the backbone structure of the target detection network for multi-scale feature extraction, and obtain detection feature maps at different scales.

[0030] Step 2: Coordinate encoding generation: For the feature map output by the backbone network, generate horizontal and vertical coordinate mappings according to the spatial dimensions, and concatenate them with the original features to form a joint feature that integrates spatial location information.

[0031] Step 3: Explicit Foreground Prior Prediction: Input the features after fusing spatial priors into the foreground prior prediction head. Through processes such as convolutional mapping, normalization, and nonlinear activation, generate foreground prior logits, and further generate a foreground probability map through Sigmoid activation.

[0032] Step 4: Foreground-guided enhancement: Residual foreground modulation is performed on the original detection features using the foreground probability map to enhance the foreground region while preserving the original feature information, thereby improving the response capability of the target region.

[0033] Step 5: Weakly supervised foreground constraint: A weakly supervised foreground mask is automatically generated based on the target detection bounding box, and an auxiliary prior loss is constructed to supervise and constrain the foreground probability map, thereby realizing foreground region learning.

[0034] Step 6: Detection Output: Input the enhanced detection features into the detection head to complete the pig target classification and bounding box regression, and output the final detection result. Example

[0035] The pig target detection method based on scene prior guidance in this embodiment includes the following implementation process: Step 1: Input Image and Multi-Scale Feature Extraction Acquire images of the pigsty to be inspected, and set the training hyperparameters as follows: Figure 2 That is, after uniformly adjusting the size to 640*640, the data is input into the ResNet18 backbone structure of the target detection network in batches for multi-scale feature extraction, resulting in feature maps P3, P4, and P5 at different scales. These feature maps are used to characterize the target area of ​​the pig, the background area, and the spatial structure information of the scene.

[0036] Step 2: Coordinate Encoding Generation For the input feature map, generate horizontal and vertical coordinate maps respectively. Concatenate the horizontal and vertical coordinate maps to obtain the spatial coordinate encoding. P="Concat"(P_x,P_y) The coordinate values ​​in the coordinate encoding are normalized, with a normalization range of [range to be specified]. Furthermore, the coordinate encoding is fused with the original detection features to establish a correlation between the detection features and spatial location. F_c="Concat"(X,P) Step 3: Explicit Foreground Prior Prediction The input features are fused with coordinate encoding and then input into the foreground prior prediction head for foreground region prediction, generating an explicit foreground prior; among these, channel mapping is performed on the fused features: F_1 = ϕ_1 (F_c) Subsequently, spatially aware convolution operations are performed on the mapped features: F_2 = ϕ_2 (F_1) Furthermore, the convolution results are normalized and nonlinearly activated: F_3=σ("Norm"(F_2)) Finally, foreground response prediction is performed on the enhanced features: L_p=ϕ_3 (F_3) Where L_p represents the foreground prior logits. The explicit foreground prior is used to characterize the probability distribution information that the current spatial location belongs to the foreground region of the pig.

[0037] Furthermore, the prior prediction results of the foreground are activated to generate a foreground probability map, which is used to distinguish potential target regions from fixed background regions. The foreground probability map is generated as follows: M_p="Sigmoid"(L_p) Where M_p represents the foreground probability map.

[0038] Step 4: Foreground-guided feature enhancement The generated foreground probability map is used to enhance the original detection features through foreground-guided enhancement. A residual foreground modulation method is employed to enhance features in the target-related region while preserving the original detection feature information. The calculation formula for the residual foreground modulation method is as follows: F_o = X + α(X⊙M_p) Where: F_o represents the output enhancement feature; X represents the input detection feature; M_p represents the foreground probability map; ⊙ represents element-wise multiplication; α represents the learnable modulation coefficient.

[0039] Step 5: Weakly supervised prospect constraint A weakly supervised foreground mask is automatically generated based on the object detection bounding boxes and used as a supervision signal in the explicit foreground prior learning process. The method for constructing the weakly supervised foreground mask for any spatial location in the image is as follows: M_gt (x,y)={■(1,&(x,y)∈b_i@0,&"otherwise" )┤ The target detection annotation set is represented as B={b_1,b_2,…,b_N}, where N represents the number of targets.

[0040] When multiple target bounding boxes overlap, the overall foreground region is constructed using a region union approach: M_gt=⋃_(i=1)^N▒b_i The auxiliary prior loss for multi-scale feature maps includes binary cross-entropy loss and Dice loss, and their expressions are as follows: L_prior=λ_1 L_bce+λ_2 L_dice Where: L_bce represents the binary cross-entropy loss; L_dice represents the Dice loss; λ_1, λ_2 represent the corresponding loss weight coefficients.

[0041] The binary cross-entropy loss expression is: L_bce=-1 / N ∑_(i=1)^N▒[M_gt^((i) ) log(M_pred^((i) ))+(1-M_gt^((i)))log(1-M_pred^((i) ))] Where: N represents the total number of spatial locations in the feature map; M_pred^((i)) represents the foreground prediction probability of the i-th location; M_gt^((i)) represents the supervision label of the corresponding location.

[0042] The Dice Loss expression is: L_dice=1-(2∑M_pred M_gt+ϵ) / (∑M_pred+∑M_gt+ϵ) The multi-scale auxiliary supervision loss expression is: L_prior^multi=∑_(k=1)^K▒L_prior^((k) ) Where: K represents the number of feature layers; L_prior^((k)) represents the auxiliary prior loss at the k-th scale. Figure 3 The trend of the total loss function during the training process of the model for 300 epochs (11,400 batches) shows that the overall loss value tends to stabilize as the number of training epochs increases (data augmentation is turned off in the last 10 training epochs).

[0043] Step 6: Detect the output The enhanced features, guided by scene priors, are input into the detection head to complete pig target classification and location regression, and the final detection result is output. The target detector is RT-DETRv1, and the final detection result is: Output="RT-DETRv1"(F_o), where F_o is the enhanced output feature of the foreground prior prediction head.

[0044] Figure 4 A visualization heatmap of P3-scale features output by the SPGM module.

[0045] This invention presents a scene-prior guided pig target detection method. By constructing a scene-prior guided module, it achieves fixed background region suppression and foreground region enhancement. It utilizes the spatial stability of a fixed pigsty scene to establish position awareness. Combined with explicit foreground region modeling and residual foreground modulation mechanism, it realizes enhanced expression of the target region and suppression of background region interference. This improves the stability, localization accuracy, engineering deployment adaptability, and robustness under complex occlusion conditions of pig target detection in dense pig occlusion scenes, complex background scenes, and long-term fixed monitoring scenes.

Claims

1. A method for pig target detection based on scene prior guidance, characterized in that, Includes the following steps: Step S1: Input Image and Multi-Scale Feature Extraction An image of the pigsty to be detected is acquired and input into the backbone structure of the target detection network for multi-scale feature extraction, resulting in detection feature maps at different scales; the multi-scale features include target region features and stable background region features; Step S2: Coordinate Encoding Generation A coordinate encoding is constructed for the detection feature map to generate position coordinate information corresponding to the spatial size of the detection feature map; the coordinate encoding is used to establish the spatial position perception capability of the detection feature, so that the detection network can explicitly perceive the spatial distribution pattern in the fixed pig house scene; then, the coordinate encoding is fused with the detection feature map to obtain a detection feature map with spatial position information. Step S3: Explicit Foreground Prior Prediction The detection feature map with spatial location information is input into the foreground prior prediction head to predict the foreground region and generate an explicit foreground prior, which is used to characterize the probability distribution information of the current spatial location belonging to the foreground region of the pig. The prior prediction results of the foreground are activated to generate a foreground probability map, which is used to distinguish potential target areas from fixed background areas; Step S4: Foreground-guided feature enhancement The generated foreground probability map is used to perform foreground-guided feature enhancement on the original detection features; By using a foreground region-guided feature enhancement process, the proportion of the main body region of the pig in the feature representation is increased, while the interference propagation of the background region on the detection network is suppressed. Step S5: Weakly supervised prospect constraint Weakly supervised foreground masks are automatically generated based on the sample labels in the dataset and used as a supervision signal in the explicit foreground prior learning process. By constructing an auxiliary prior loss of multi-scale feature maps, the consistency between the foreground prior prediction results and the weakly supervised foreground masks is constrained. Step S6: Detect the output The detection feature map, after scene-guided feature enhancement, is fed into the feature fusion and detection head network of the target detector for further feature processing, completing the pig target classification and location regression, and outputting the final detection result.

2. The pig target detection method based on scene prior guidance according to claim 1, characterized in that: In step S1, the backbone structure of the target detection network is ResNet18. Feature extraction is performed on the original input image I to obtain the detection feature map X: X = "ResNet18" (I), where the shape of I is (B, 3, H, W), which correspond to the batch size, number of channels, height and width of the image, respectively. The obtained detection feature map is used to characterize the target area of ​​the pig, the background area and the spatial structure information of the scene.

3. The pig target detection method based on scene prior guidance according to claim 1, characterized in that: Step S2, the specific process of generating coordinate codes is as follows: For the input feature map X, generate the horizontal coordinate mapping P_x and the vertical coordinate mapping P_y respectively. Then, the horizontal coordinate mapping and the vertical coordinate mapping are concatenated to obtain the spatial coordinate code: P="Concat" (P_x,P_y ), The coordinate values ​​in the coordinate encoding are normalized, with a normalization range of [0,1]. The normalized horizontal and vertical coordinates represent the relative position of the current pixel in the overall space. Furthermore, the coordinate encoding is fused with the original detection features to establish the correlation between the detection features and spatial location: F_c="Concat"(X,P).

4. The pig target detection method based on scene prior guidance according to claim 3, characterized in that: In step S2, the process of constructing coordinate encoding for the detection feature map and generating position coordinate information corresponding to the spatial size of the detection feature map includes: For the input detection feature map: X∈R^(C×H×W), where C represents the number of feature channels, H represents the feature map height, and W represents the feature map width; generate the horizontal coordinate mapping: P_x∈R^(1×H×W) and the vertical coordinate mapping: P_y∈R^(1×H×W). Further, concatenate the horizontal coordinate mapping and the vertical coordinate mapping to obtain the spatial coordinate encoding: P="Concat" (P_x,P_y ), and fuse the coordinate encoding with the original detection features: F_c="Concat"(X,P), where F_c represents the feature after fusing the spatial location prior.

5. The pig target detection method based on scene prior guidance according to any one of claims 1-4, characterized in that: In step S3, the foreground prior prediction head includes: a feature mapping layer, a spatially aware convolutional layer, a feature normalization layer, a nonlinear activation layer, and a foreground response prediction layer; Among these, channel mapping is performed on the fused features: F_1 = ϕ_1 (F_c) Subsequently, spatially aware convolution operations are performed on the mapped features: F_2 = ϕ_2 (F_1) Furthermore, the convolution results are normalized and nonlinearly activated: F_3=σ("Norm"(F_2)) Finally, foreground response prediction is performed on the enhanced features: L_p=ϕ_3 (F_3) Where L_p represents the foreground prior logits; The prior prediction results of the foreground are activated to generate a foreground probability map, which is used to distinguish potential target regions from fixed background regions. The foreground probability map is generated as follows: M_p="Sigmoid"(L_p) Where M_p represents the foreground probability map.

6. The pig target detection method based on scene prior guidance according to any one of claims 1-4, characterized in that: In step S4, the foreground-guided enhancement uses a residual foreground modulation method to enhance the features of the target-related region while retaining the original detection feature information; The calculation formula for the residual foreground modulation method is as follows: F_o = X + α(X⊙M_p) Where: F_o represents the output enhancement feature; X represents the input detection feature; M_p represents the foreground probability map; ⊙ represents element-wise multiplication; α represents the learnable modulation coefficient.

7. The pig target detection method based on scene prior guidance according to any one of claims 1-4, characterized in that: In step S5, a weakly supervised foreground mask is automatically generated based on the target detection bounding box and used as a supervision signal in the explicit foreground prior learning process. For any spatial location (x, y) in the image, the weakly supervised foreground mask is constructed as follows: M_gt (x,y)={■(1,&(x,y)∈b_i@0,&"otherwise" )┤ The target detection annotation set is represented as: B={b_1,b_2,…,b_N}, where N represents the number of targets; When multiple target bounding boxes overlap, the overall foreground region is constructed using a region union approach: M_gt=⋃_(i=1)^N▒b_i .

8. The pig target detection method based on scene prior guidance according to claim 7, characterized in that: In step S5, the auxiliary prior loss of the multi-scale feature map includes binary cross-entropy loss and Dice Loss, the expression of which is: L_prior=λ_1 L_bce+λ_2 L_dice Where: L_bce represents the binary cross-entropy loss; L_dice represents the Dice Loss loss; λ_1, λ_2 represent the corresponding loss weight coefficients; The binary cross-entropy loss expression is as follows: L_bce=-1 / N ∑_(i=1)^N▒[M_gt^((i) ) log(M_pred^((i) ))+(1-M_gt^((i) ))log(1-M_pred^((i) ))] Where: N represents the total number of spatial locations in the feature map; M_pred^((i)) represents the foreground prediction probability of the i-th location; M_gt^((i)) represents the supervision label of the corresponding location; The Dice Loss expression is as follows: L_dice=1-(2·∑M_pred M_gt+ϵ) / (∑M_pred+∑M_gt+ϵ) Where: ϵ is the minimum term.

9. The pig target detection method based on scene prior guidance according to claim 7, characterized in that: In step S5, the auxiliary prior loss of the multi-scale feature map includes an auxiliary supervision loss, and the expression for the auxiliary supervision loss of the multi-scale feature map is: L_prior^multi=∑_(k=1)^K▒L_prior^((k) ) Where: K represents the number of feature layers; L_prior^((k)) represents the auxiliary prior loss at the k-th scale.

10. The pig target detection method based on scene prior guidance according to any one of claims 1-4, 8, or 9, characterized in that: In step S6, the target detector is RT-DETRv1, and the final detection result is: Output="RT-DETRv1"(F_o), where: F_o is the output enhancement feature of the foreground prior prediction head.