Fish detection method based on improved YOLOv8 network, computer program product

By improving the YOLOv8 network, introducing multi-scale fusion and prior attention, and combining data augmentation and camera calibration, the problem of poor detection performance in fish detection was solved, achieving higher accuracy and stable fish detection.

CN122290174APending Publication Date: 2026-06-26UNIV OF SCI & TECH OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
UNIV OF SCI & TECH OF CHINA
Filing Date
2026-04-10
Publication Date
2026-06-26

AI Technical Summary

Technical Problem

Existing general detection algorithms struggle to robustly distinguish slender and curved targets in fish detection scenarios. They lack the ability to fuse features sensitive to fish posture and lack pixel-to-physical mapping calibration and distortion correction, resulting in poor detection performance.

Method used

An improved YOLOv8 network was adopted, which introduced an enhanced C2f_PPA multi-scale fusion structure and a combined prior attention layer into the backbone network, replaced the neck network with an enhanced bidirectional cross-scale feature pyramid network, and introduced enhancement strategies such as occlusion, overlap, and color change into the training dataset. Combined with camera calibration and distortion correction, the accuracy of fish detection was improved.

Benefits of technology

It improves the accuracy and stability of fish body detection, enhances the detection stability and key point availability of slender and curved fish bodies, and improves the network's generalization ability and detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122290174A_ABST
    Figure CN122290174A_ABST
Patent Text Reader

Abstract

This invention discloses a fish detection method and computer program product based on an improved YOLOv8 network, relating to the fields of aquaculture, water conservancy engineering, and biological monitoring. Specifically for fish recognition tasks, this invention improves upon the YOLOv8 network by developing the YOLOv8-Fish network. In the backbone network, the C2f structure in stage two is replaced with an enhanced C2f-PPA multi-scale fusion result to improve feature representation under occlusion and overlap conditions. Furthermore, combined prior attention is introduced before this to enhance fish saliency and morphological response. The neck network is replaced with an enhanced bidirectional cross-scale feature pyramid network to achieve more comprehensive cross-scale information interaction. This approach, through prior information and multi-scale fusion, improves the detection stability and keypoint availability of slender, curved, and overlapping fish, thereby enhancing the accuracy of fish detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of aquaculture, water conservancy engineering and biological monitoring technology, specifically to: 1. a fish detection method based on an improved YOLOv8 network; 2. a computer program product. Background Technology

[0002] Fish detection and posture analysis are of great significance for aquaculture, allowing farmers to analyze fish growth through test results and adjust aquaculture plans accordingly.

[0003] Currently, general detection algorithms (e.g., using the basic YOLOv8 network for detection) perform well on public datasets and rigid targets (e.g., vehicles, pedestrians), but they have structural shortcomings in fish application scenarios: the detection side lacks dedicated shape modeling and pose-sensitive feature fusion for slender and curved targets.

[0004] Fish bodies exhibit significant flexibility and non-rigidity, commonly switching between straight, S-shaped, and C-shaped postures. During rapid turning and chasing behaviors, they show large curvature changes and short-term acceleration spikes. Furthermore, the appearance of fish bodies has strong texture similarity and color similarity. Individual differences depend on subtle morphological proportions (such as body length / body height ratio), head and tail direction, and local patterns. This makes it difficult for the YOLOv8 network, which mainly uses axis-aligned rectangles, to robustly distinguish between overlapping and neighboring individuals, making it difficult for existing general detection algorithms to achieve good results.

[0005] Furthermore, at the data and measurement level, existing algorithms generally remain at the pixel space evaluation level (metrics include mAP, HOTA, IDF1, etc.), lacking calibration and distortion correction linked to real-world scales (e.g., millimeters, centimeters). Moreover, the distortion characteristics of underwater lenses and variations in shooting distance make the pixel-physical mapping nonlinear; without checkerboard calibration and perspective integration, intuitive pixel-based estimation cannot meet accuracy requirements. In addition, fish applications involve complex interferences such as lighting changes, water ripples, and occlusion, and the fish's flexible deformation and non-rigid motion characteristics make the detection key points unstable, further degrading the performance of existing general-purpose detection algorithms. Summary of the Invention

[0006] Therefore, it is necessary to address the problem that existing fish detection methods using general detection algorithms are ineffective, and to provide fish detection methods and computer program products based on the improved YOLOv8 network.

[0007] This invention is achieved using the following technical solution: In a first aspect, the present invention discloses a fish detection method based on an improved YOLOv8 network, comprising: using a trained YOLOv8-Fish network to identify target fish from an image to be identified.

[0008] The construction method of the YOLOv8-Fish network includes: The C2f structure in stage 2 of the YOLOv8 backbone is replaced with the Enhanced C2f_PPA multi-scale fusion structure to improve feature representation under occlusion and overlap conditions. A combined prior attention layer, including at least an improved convolutional block attention layer (ImprovedCBAM) and a fish shape attention layer (FishShapeAttention), is introduced before it to enhance the saliency and morphological response of the fish. The neck network of the YOLOv8 network was replaced with the Enhanced Bidirectional Cross-Scale Feature Pyramid Network (EnhancedBCFPN) to achieve more comprehensive cross-scale information interaction.

[0009] This fish detection method based on an improved YOLOv8 network implements the method or process according to embodiments of this disclosure.

[0010] Secondly, the present invention discloses a computer program product, comprising a computer program. When executed by a processor, the computer program implements the steps of the fish detection method based on the improved YOLOv8 network disclosed in the first aspect.

[0011] Compared with the prior art, the present invention has the following beneficial effects: 1. This invention improves upon the YOLOv8 network to create the YOLOv8-Fish network for fish recognition tasks. In the backbone network, the C2f structure in stage two is replaced with an enhanced C2f-PPA multi-scale fusion result to improve feature representation under occlusion and overlap conditions. Furthermore, combined prior attention is introduced before this to enhance fish saliency and morphological response. The neck network is replaced with an enhanced bidirectional cross-scale feature pyramid network to achieve more comprehensive cross-scale information interaction. This approach, through prior information and multi-scale fusion, improves the detection stability and keypoint availability of slender, curved, and overlapping fish, thereby enhancing the accuracy of fish detection.

[0012] 2. The combined prior attention of the present invention introduces pluggable fish color-specific attention, providing specific color priors for the fish body, which can enhance the recognition of fish of specific colors.

[0013] 3. When constructing a sample dataset, this invention adds various random combinations and random orders of enhancement strategies such as occlusion, overlap, color change, water ripple, and motion blur to the general enhancement, which can effectively improve the generalization ability of the network after training.

[0014] 4. In the final coordinate restoration, this invention introduces camera calibration and distortion correction, achieving accurate conversion from pixel coordinates to actual size.

[0015] 5. This invention introduces fish temporal consistency processing for video frame processing scenarios, which can perform cross-frame stabilization fusion of the prediction results of the current frame, reduce jitter and maintain the rationality of the shape. Attached Figure Description To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0016] Figure 1 This is a diagram of the YOLOv8-Fish network architecture provided in Embodiment 1 of the present invention; Figure 2 for Figure 1 Network architecture diagram of Improved CBAM; Figure 3 for Figure 1 Network architecture diagram of FishShapeAttention; Figure 4 for Figure 1 Network architecture diagram of FishColorAttention; Figure 5 for Figure 1 Network architecture diagram of New_Bottleneck within EnhancedC2f_PPA; Figure 6 for Figure 1 Network architecture diagram of EnhancedBCFPN; Figure 7 for Figure 6 Network architecture diagram of EnhancedBiFPNLayer. Detailed Implementation

[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0018] It should be noted that when a component is said to be "installed on" another component, it can be directly on the other component or it may be in a component that is centered on it. When a component is said to be "set on" another component, it can be directly set on the other component or it may also be in a component that is centered on it. When a component is said to be "fixed to" another component, it can be directly fixed to the other component or it may also be in a component that is centered on it.

[0019] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the specification of this invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "or / and" as used herein includes any and all combinations of one or more of the associated listed items.

[0020] Example 1 Please see Figure 1 , Figure 1 The fish detection method based on the improved YOLOv8 network in this invention includes the following operations: Step 1: Construct a sample dataset for fish detection.

[0021] It is important to note that the sample dataset must consist of a certain number of fish sample images with labeled content (including: the bounding rectangle of the fish body, and five key points: the head, neck, body center, tail root, and tail tip), covering diverse scenarios such as different lighting conditions (e.g., daytime and nighttime supplemental lighting), different water quality conditions (e.g., clear and turbid), and different movement states (e.g., still, slow swimming, and fast swimming).

[0022] The sample dataset can use existing, publicly known datasets, or it can be constructed by ourselves. In this Example 1, we adopt the method of constructing our own dataset—the specific process is as follows: S101 uses a high-definition camera to capture raw videos of the fishway in different scenarios. Video and from it at fixed intervals Δ t Extract frame images to form the original dataset. a 0.

[0023] As described above, the different scenarios here must cover at least different lighting conditions, different water quality conditions, and different motion states to ensure sample diversity.

[0024] S102, regarding the original dataset a 0. Image sizes were standardized, and manual annotation was performed using annotation tools to ensure that each image had annotation content, resulting in a standard dataset. a 1.

[0025] Original dataset a The size of the 0 must meet the input requirements of the YOLOv8 network—generally set to 640×640, but it can also be adjusted according to computing power to balance the accuracy of small target detection and training efficiency.

[0026] As described above, the annotations should at least include the bounding box (rectangle) of the fish's body. For pose analysis purposes, the annotations should also include the five key points of the fish's body—head, neck, body center, tail root, and tail tip. Thus, after manual annotation, an image with annotations is obtained.

[0027] Furthermore, it should be noted that since the YOLOv8-Fish network used subsequently is an improvement upon the YOLOv8 network, the standard dataset... a 1. It is recommended to save in YOLO format.

[0028] S103, for labeled datasets a 1. Perform data augmentation to expand the sample and obtain an expanded dataset. a 2 and used as a sample dataset.

[0029] S103 is designed to improve the robustness of the YOLOv8-Fish network against complex fishway imaging interference and small targets.

[0030] Specifically, S103's data augmentation, based on general augmentations (such as random HSV transformation, random affine / scaling, flipping, Mosaic, etc.), introduces augmentation strategies specifically for the fishway environment—including: occlusion augmentation (simulating partial occlusion with rectangular, elliptical, and irregular occlusion), overlap augmentation (simulating dense overlapping of fish schools with multiple blending modes), color variation augmentation (simulating illumination shift and underwater color drift), water ripple augmentation (simulating local geometric distortion caused by refraction and water ripples), and motion blur augmentation (simulating edge weakening caused by rapid swimming). These are executed in random combinations and in random order with general augmentations to simulate multi-factor superposition interference in the fishway environment.

[0031] It is important to note that during the data augmentation process described above, the annotation information should be updated synchronously to maintain annotation consistency.

[0032] Step 2: Adjust the structure based on the YOLOv8 network to obtain the YOLOv8-Fish network.

[0033] See Figure 1 In simple terms, compared to the YOLOv8 network, the YOLOv8-Fish network maintains the three-segment topology of backbone, neck, and head, as well as the single-scale input (INPUT) and three-scale output interfaces (three Detect), while performing structural replacements and enhancements at key nodes.

[0034] Specifically, the construction method of the YOLOv8-Fish network includes: I. Replace the C2f structure in stage 2 of the YOLOv8 network backbone with the enhanced C2f_PPA multi-scale fusion structure (referred to as EnhancedC2f_PPA) to improve feature representation under occlusion and overlap conditions, and introduce a combined prior attention layer before it - including at least: improved convolutional block attention layer (referred to as ImprovedCBAM) and fish shape attention layer (referred to as FishShapeAttention) to enhance fish saliency and morphological response.

[0035] Of course, to enhance the recognition of fish of a specific color, a fish color-specific attention layer (referred to as FishColorAttention) can be added to the combined prior attention layer.

[0036] like Figure 1 As shown, specifically: ImprovedCBAM is connected after the convolutional module (i.e., ConvModule) structure in stage two of the Backbone; FishShapeAttention is connected after ImprovedCBAM; the outputs of ImprovedCBAM and FishShapeAttention are fused and then input into EnhancedC2f_PPA; EnhancedC2f_PPA is connected before the convolutional module in stage three of the Backbone.

[0037] Of course, if FishColorAttention is added, then: ImprovedCBAM and FishColorAttention are connected in parallel after the convolutional module structure of stage two in the Backbone; FishShapeAttention is connected after ImprovedCBAM; the outputs of ImprovedCBAM, FishShapeAttention, and FishColorAttention are fused and then input into EnhancedC2f_PPA; EnhancedC2f_PPA is connected before the convolutional module of stage three in the Backbone.

[0038] The following sections provide a detailed introduction to ImprovedCBAM, FishShapeAttention, FishColorAttention, and EnhancedC2f_PPA: ① ImprovedCBAM primarily enhances saliency through improved channel and spatial attention. In other words, ImprovedCBAM is used for saliency screening, focusing more on which channels and locations resemble fish more.

[0039] See Figure 2 ImprovedCBAM can be divided into four parts: Grouped Channel Attention, Multi-Scale Spatial Attention, and two Residual Fusion layers.

[0040] In ImprovedCBAM: 101. The purpose of GroupedChannelAttention is not to directly compress all channels and calculate a single weight, but to split the input In_x of ImprovedCBAM into several groups according to channels so that different channel groups can learn weights of different semantic types, and then weight them with the corresponding channel groups to obtain the channel enhancement result x_ca_attn.

[0041] Specifically, GroupedChannelAttention first splits the input In_x of ImprovedCBAM into several groups according to channels, and performs global average pooling on each channel group. Then, the pooling results of each channel group are input into the group mapping subnetwork to realize the mapping of the corresponding channel group. Then, the channel weights are recombined through the Sigmoid activation function to form channel weights w_c. Finally, w_c is weighted with the corresponding channel group to obtain the channel enhancement result x_ca_attn.

[0042] GroupedChannelAttention is used because different channels may encode features such as texture, edge, brightness, and local shape. If a single-path shared mapping is used, all channels are easily treated too evenly. However, the grouping of GroupedChannelAttention allows the fish contour-related channels and the background texture-related channels to learn different emphasis and suppression strategies.

[0043] 102. The first ResidualFusion is a channel-specific residual fusion. It is not to further enhance x_ca_attn, but to prevent weak texture fish bodies from being mistakenly suppressed when the channel weights are too strong, to prevent the main features from being directly destroyed when the attention is not stable in the early stage of training, and to allow ImprovedCBAM to take into account both the original recoverability and the enhancement effectiveness.

[0044] Specifically, the first ResidualFusion performs adjustable weighting on x_ca_attn and In_x to obtain the primary fusion feature x_ca.

[0045] 103. Multi-Scale SpatialAttention is used to summarize the channel dimension information of x_ca into a spatial description, and then use convolutional branches with different receptive fields to estimate the regions worth focusing on in order to obtain the spatial augmentation result x_sa_attn.

[0046] Specifically, Multi-ScaleSpatialAttention first performs channel-dimensional averaging and channel-dimensional maximization on x_ca. Then, it concatenates the results of these two channel-dimensional processing to form a spatial description s containing the average response and extreme response. Then, it performs two convolutional processing on s in parallel at different scales (one is a small-scale convolution, corresponding to a small receptive field branch—more biased towards local boundaries, detail breakpoints, and local bright spot suppression; the other is a large-scale convolution, corresponding to a large receptive field branch—more biased towards the overall fish body region, continuous contours, and long strip target coverage). Next, it concatenates the results of these two convolutions and performs a fusion convolution, then uses a sigmoid activation function to generate spatial weights w_s. Finally, it multiplies w_s element-wise with x_ca to obtain the spatial augmentation result x_sa_attn.

[0047] Multi-ScaleSpatialAttention is used because fish are typically long and slender targets, where both local edges and overall contours are important. Using only single-scale convolutions may result in only seeing local highlights in the fish's head or only a general area. Multi-ScaleSpatialAttention, however, uses smaller receptive field branches to handle edges and details, while larger receptive field branches handle the complete fish body coverage—combining these two approaches suppresses background ripples while maintaining a consistent overall response for the fish.

[0048] Similar to the first ResidualFusion, the second ResidualFusion is a spatial residual fusion. It is not to further enhance x_sa_attn, but to prevent weak texture fish bodies from being mistakenly suppressed when the spatial weights are too strong, to prevent the main features from being directly destroyed when the attention is not stable in the early stage of training, and to make ImprovedCBAM take into account both the original recoverability and the enhancement effectiveness.

[0049] Specifically, the second ResidualFusion performs adjustable weighting on x_ca and x_sa_attn to obtain the secondary fusion feature x_cbam.

[0050] In summary, for ease of understanding, the above process of ImprovedCBAM can be expressed by the following formula: ; ; ; ; ; ; ; In the formula, GroupedMap(.) represents the grouped mapping sub-network processing; FuseConv(.) represents the fused convolution processing; GlobalAvgpool(.) represents the global average pooling processing; Sigmoid(.) represents the Sigmoid activation function processing; λ1 and λ2 represent the learnable weight coefficients corresponding to x_ca_attn and In_x. AvgalongC(.) represents the channel-dimensional averaging processing; MaxalongC(.) represents the channel-dimensional maximization processing; Concat(.) represents the concatenation processing; Conv small (.) indicates a small-scale convolution process; Conv big (.) denotes large-scale convolution; λ3 and λ4 represent the learnable weight coefficients corresponding to x_ca and x_sa_attn.

[0051] ② FishShapeAttention uses directional shape attention to enhance the fish's main direction and shape cues, enabling the network to maintain a stable response even under conditions of curved postures, weak texture, and background interference. In other words, FishShapeAttention is used for shape orientation enhancement, focusing more on the direction in which the fish extends and whether it bends.

[0052] See Figure 3FishShapeAttention can be divided into 6 parts: ChannelReduce, DirectionalConv, DirectionSelection, DirectionAggregation, ChannelExpand, and ResidualFusion.

[0053] In FishShapeAttention: 201. ChannelReduce is used to compress x_cbam along the channel dimension to obtain compressed features x_r.

[0054] 202, DirectionalConv is not a regular convolutional layer, but a multi-directional response extractor—it uses D directional convolutional kernels to scan x_r respectively; since each directional convolutional kernel is more likely to respond to textures or contours consistent with its own direction, multiple results observed in different directions can be obtained at the same location and stacked along the directional dimension to form directional features x_d.

[0055] It should be noted that DirectionalConv emphasizes not the fish's position, but rather the direction in which the fish's body extends and its current movement.

[0056] 203. DirectionSelection is used to normalize x_d along the direction dimension using the Softmax activation function to obtain the direction-normalized weight w_d.

[0057] It is important to note that w_d includes relative weights for multiple directions—the larger the relative weight of a certain direction, the more that direction conforms to the current main axis of the fish or the local bending trend.

[0058] 204. DirectionAggregation is used to weight and sum the elements along the directional dimension of x_d according to w_d to obtain the single-path feature w_s.

[0059] DirectionAggregation essentially folds multi-directional responses back into a single path according to the relative weight of each direction, thereby preserving the most reasonable direction while avoiding simply averaging all directions.

[0060] It is important to emphasize that because fish frequently turn, wag their tails, and bend, if DirectionSelection and DirectionAggregation are not processed in conjunction, multiple directional information will cancel each other out, leading to recognition errors.

[0061] 205. ChannelExpand is used to restore w_s to the same size as x_cbam in the channel dimension, resulting in the restored feature fx.

[0062] 206. ResidualFusion performs adjustable weighting on x_cbam and fx to obtain the shape fusion feature y_attn1.

[0063] In summary, for ease of understanding, the above process of FishShapeAttention can be expressed by the following formula: ; ; ; ; ; ; In the formula, CR(.) represents the channel compression process; Stack(.) represents the stacking process; DBranch1~DBranch D λ represents D convolutional kernels in different directions; CE(.) represents the channel recovery process; λ5 and λ6 represent the learnable weight coefficients corresponding to x_cbam and fx.

[0064] It should be noted that the combination of ImprovedCBAM and FishShapeAttention targets the slender shape and pose variations of fish. The former is more saliency-oriented, responsible for filtering out features that are more fish-like, while the latter is more structural, responsible for reorganizing these features into those that better conform to the shape of a fish. The two work together through a controllable fusion method, improving fine-grained representation capabilities without changing feature resolution and channel interfaces, making it more suitable for objects like fish that are slender, curved, with continuous contours but low local contrast.

[0065] ③ FishColorAttention, as a pluggable attention unit, targets the specific color prior of the fish. It generates a color mask by extracting color confidence and adaptive threshold, and combines multi-scale color fusion and occlusion perception enhancement. Color saliency is used as an explicit guiding signal to participate in feature modulation, thereby improving detectability and stability under complex lighting and color bias conditions.

[0066] See Figure 4 FishColorAttention can be divided into 6 parts: Channel Attention, Spatial Attention, Color Extractor, Adaptive Threshold, MultiScale Color Fusion, Occlusion Aware Attention, and Final Fusion.

[0067] In FishColorAttention: 301. ChannelAttention and SpatialAttention are connected to form a general main path, which extracts the fish body salient features x_attn from the input In_x of FishColorAttention without relying on color prior.

[0068] Specifically, Channel Attention identifies which channels in In_x are most discriminative, while Spatial Attention determines which regions these most discriminative channels are concentrated in. The resulting x_attn provides a baseline enhancement result without color bias for subsequent color processing.

[0069] 302. ColorExtractor is designed to extract specific color features. For example, if you need to enhance the recognition of fish with different colors, ColorExtractor is used to extract color features. Similarly, if you want to enhance the recognition of fish with other colors, ColorExtractor is used to extract the corresponding color features.

[0070] ColorExtractor is both an explicit color locator and a color feature encoder. Specifically, ColorExtractor first performs color mapping on In_x to facilitate color analysis. Then, it obtains the color confidence c_confidence, which represents a specific color, through color confidence estimation, and obtains the color enhancement feature c_enhanced, which preserves color discrimination, through color enhancement.

[0071] 303. AdaptiveThreshold generates an adaptive threshold t based on In_x, and generates a color mask c_mask by masking c_confidence according to t.

[0072] Specifically, Adaptive Threshold first processes In_x through global pooling and a thresholding network to obtain t, and then uses t to segment c_confidence to obtain c_mask.

[0073] It should be noted that the thresholding network aims to predict a reasonable threshold, and it consists of the following sequentially connected layers: a first linear layer, a first convolutional mapping layer, a non-linear activation layer, a second linear layer, a second convolutional mapping layer, and a sigmoid activation function. The thresholding network receives the results of the preceding global pooling to extract features such as global brightness, color distribution, and background style, and then maps them to a threshold prediction value. This value is then compressed to a stable range using the sigmoid activation function to obtain t.

[0074] An adaptive threshold t is used because the color intensity of the same fish can vary significantly under different water depths, reflective conditions, and color casts. A fixed threshold is too loose in some scenarios and too strict in others. An adaptive threshold t allows the mask generation to better fit the current object.

[0075] 304. MultiScaleColorFusion aims to elevate color information from local color patches to a continuous color structure. It processes c_enhanced through three color branches at small, medium, and large scales, and then splices and fuses the results of the three branches to obtain the color fusion feature c_fused.

[0076] It should be noted that the small-scale color branch focuses on local color patches and color edges; the medium-scale color branch focuses on color connectivity within local areas; and the large-scale color branch focuses on whether the entire fish body exhibits a continuous color distribution. This multi-scale color processing avoids misjudging a target based solely on local color noise, and also avoids losing the overall color structure of the fish body by retaining only a single color hotspot.

[0077] 305. OcclusionAwareAttention is used to perform reliable color correction on c_fused based on c_mask.

[0078] Specifically, OcclusionAwareAttention first uses c_mask to guide the modulation of c_fused, and then performs occlusion estimation and attention refinement in sequence to obtain the color path output c_path_out.

[0079] Here, `c_mask` provides explicit candidate color regions, and `c_fused` provides the color-enhanced feature representation. `OcclusionAwareAttention` does not simply multiply the color features by the mask; rather, it uses the mask to readjust the focus of attention for the color branches.

[0080] In summary, ColorExtractor, AdaptiveThreshold, MultiScaleColorFusion, and OcclusionAwareAttention work together to form a color specialization path.

[0081] 306. FinalFusion is used to fuse x_attn and c_path_out to obtain the color fusion feature y_attn2. As the convergence point of the general main path and the color-specialized path, FinalFusion incorporates color priors as supplementary information in the final decision.

[0082] Specifically, FinalFusion first concatenates x_attn and c_path_out, and then performs convolution to obtain y_attn2.

[0083] In summary, for ease of understanding, the above process of FishColorAttention can be expressed by the following formula: ; ; ; ; ; In the formula, SA(.) represents the spatial attention layer processing; CA(.) represents the channel attention layer processing; ColorExtractor(.) represents the color feature extractor processing; scBranch(.) represents the small-scale color branch processing; mcBranch(.) represents the medium-scale color branch processing; lcBranch(.) represents the large-scale color branch processing; fusion(.) represents the fusion processing; OAA(.) represents the multi-scale color fusion layer processing; and Conv(.) represents the convolution processing.

[0084] ④ EnhancedC2f_PPA, while maintaining the YOLOv8 hierarchy and interface, integrates multi-scale contexts and introduces enhanced paths for occlusion and overlap adaptation. It integrates multiple features through adaptive weighting, thereby significantly improving feature discrimination and recall stability in group game overlap and partial occlusion scenarios.

[0085] EnhancedC2f_PPA is obtained by replacing all bottleneck blocks (i.e., Bottleneck) within the C2f structure with bottleneck blocks of the new structure design (i.e., New_Bottleneck).

[0086] See Figure 5 For any New_Bottleneck, it can be divided into 5 parts: Occlusion Aware PPA, Overlap Separation, Multi-Scale Context Modeling, Adaptive Weighting, and Residual Add.

[0087] Therefore, within any New_Bottleneck: 401. OcclusionAwarePPA is used to perform occlusion perception on the input belonging to New_Bottleneck to obtain perceptual enhancement features x_occ. OcclusionAwarePPA mainly identifies reliable regions from the input and performs multi-scale enhancement on the reliable regions.

[0088] Specifically, OcclusionAwarePPA first extracts the local and global contexts from the input and performs context fusion to obtain context fusion features. Then, it performs occlusion estimation on the context fusion features to obtain the region response. Finally, it reweights the context fusion features based on the region response to obtain x_occ.

[0089] OcclusionAwarePPA works this way because in fish school scenes, often only a portion of a fish is visible. If ordinary multi-scale fusion is performed directly, occlusion noise might be amplified as valid information. However, with occlusion awareness, the enhancement focuses more on visible contours, visible boundaries, and reliable structures.

[0090] 402. OverlapSeparation is used to separate the overlap of x_occ to obtain the separation feature x_sep. OverlapSeparation is for cases where targets overlap (e.g., two fish stuck together). It does not perform actual instance cutting, but enhances the signal that the targets should be separated in advance at the feature layer.

[0091] Specifically, OverlapSeparation first extracts boundary cues and local separation cues from x_occ and performs separation and fusion to enhance the transition region between adjacent targets, thus obtaining target fusion features; then, it refines the target fusion features to reduce the tendency of large, sticky regions being mistaken for single targets, thus obtaining x_sep.

[0092] 403. MultiScaleContext is used to perform context modeling on x_sep through three scales: small, medium, and large. The context modeling results of each branch are then concatenated to obtain the context fusion feature x_ctc.

[0093] It should be noted that the small-scale context branch focuses on local textures, boundaries, and short-range structures; the medium-scale context branch focuses on the combination of local regions; and the large-scale context branch focuses on the outline of the entire fish and its surrounding context. By processing at multiple scales and combining a wider range of context, the overall shape of the fish can be made clearer, avoiding recognition errors caused by the fish's local textures being too similar to the background.

[0094] 404. AdaptiveWeighting is used to adaptively weight the features of x_ctc to obtain the comprehensive enhanced feature x_w.

[0095] Specifically, AdaptiveWeighting performs multi-branch feature transformation on x_ctc to obtain multiple transformed features. On the other hand, it performs global description extraction, weight prediction, and Softmax normalization on x_ctc to obtain the weights of the corresponding transformed features. Then, it performs weighted summation with the corresponding transformed features and then performs convolution to obtain x_w.

[0096] 405. ResidualAdd is used to combine Input and x_w to obtain Output.

[0097] ResidualAdd ensures that the enhancement bottleneck always retains the original semantic core, and even if the enhancement module makes a mistake, it will not completely destroy the Input, thereby improving the fault tolerance rate.

[0098] In summary, for ease of understanding, the above process of New_Bottleneck can be expressed by the following formula: ; ; ; ; ; In the formula, OAPPA(.) represents the occlusion perception parallel attention layer processing process; OS(.) represents the overlap separation layer processing process; ssBranch(.) represents the small-scale context branch processing process; msBranch(.) represents the medium-scale context branch processing process; lsBranch(.) represents the large-scale context branch processing process; and AW(.) represents the adaptive feature weighting layer processing process.

[0099] II. Replace the Neck of the YOLOv8 network with the Enhanced Bidirectional Cross-Scale Feature Pyramid Network (referred to as EnhancedBCFPN) to achieve more comprehensive cross-scale information interaction.

[0100] The following is a detailed introduction to Enhanced BCFPN: EnhancedBCFPN aims to achieve more comprehensive cross-layer interaction in both top-down and bottom-up paths, resulting in more stable, controllable, and fish-morphologically consistent bidirectional feature fusion.

[0101] See Figure 6 EnhancedBCFPN can be divided into three parts: channel alignment layer (also known as Align), enhanced bidirectional feature pyramid layer (also known as EnhancedBiFPNLayer), and shape-aware enhancement layer (also known as ShapeEnhance).

[0102] 501. Align is used to perform channel alignment on the three inputs P3_in~P5_in of EnhancedBCFPN to obtain the corresponding alignment features P3a~P5a, which facilitates subsequent feature processing.

[0103] It should be noted that P3_in is the output of EnhancedC2f_PPA; P4_in is the output of the C2f structure in stage three of the Backbone (which can be regarded as an intermediate layer feature); and P5_in is the output of the SPPF structure in stage four of the Backbone (which can be regarded as a high-level feature).

[0104] 502. EnhancedBiFPNLayer performs bidirectional feature extraction from top to bottom and bottom to top based on P3a~P5a, and combines it with dynamic weighted fusion between features to obtain the corresponding cross-scale fusion features P3BU~P5BU.

[0105] In other words, EnhancedBiFPNLayer can be viewed as performing both bottom-up and top-down data processing.

[0106] See Figure 7 Specifically: 5021. The bottom-up data processing procedure includes: Upsample P5a (i.e., Upsample in the figure) to obtain the upsampled feature P5a_up; Dynamic weighted fusion (i.e., Dynamic Weighted Fusion in the figure) is performed on P5a_up and P4a to obtain the fused feature P4td; P4td is subjected to depthwise separable convolution (i.e., Depthwise Separable Conv in the figure) to achieve feature refinement and obtain refined features P4TD; Upsample P4TD to obtain the upsampled feature P4TD_up; Dynamic weighted fusion of dual features of P4TD_up and P3a is performed to obtain the fused feature P3td; P3BU is obtained by performing depthwise separable convolution on P3td to refine features.

[0107] 5022. The top-down data processing procedure includes: Downsample P3BU (i.e., Downsample in the figure) to obtain the downsampled feature P3BU_down; Dynamic weighted fusion of three features, P3BU_down, P4a, and P4TD, is performed to obtain the fused feature P4bu. P4BU is obtained by performing depthwise separable convolution on P4bu to refine features. The P4BU is downsampled to obtain the downsampled feature P4BU_down; Dynamic weighted fusion of dual features of P4BU_down and P5a is performed to obtain the fused feature P5bu; P5BU is obtained by performing depthwise separable convolution on P5bu to refine features.

[0108] The aforementioned bidirectional feature extraction process actually involves bidirectional data backflow. It not only transmits strong semantic information from the high-level layer to the high-resolution layer layer by layer, allowing the shallow layer to not only retain edges but also have more explicit semantic support, but also sends the edges, local details, and more precise positional information of the shallow layer back to the high-level layer, preventing the high-level layer from losing precise shape while retaining only abstract semantics.

[0109] It should be noted that: ① For Dynamic Weighted Fusion, it dynamically assigns weights to its input (referred to as features), and first performs coarse fusion, then refinement, and then enhancement to obtain its output (referred to as Out).

[0110] Specifically, Dynamic Weighted Fusion first generates a corresponding number of learnable scalars for the features by learning weights (which determine the learnable scalar parameters based on the number of features: if the features are two features, the learnable scalar parameter is set to 2; if the features are three features, the learnable scalar parameter is set to 3). Then, it passes through the ReLU activation function and normalization to obtain the corresponding number of learnable weights, and then performs a weighted sum with the features to obtain the coarse fusion feature fused. Next, fused is passed through channel alignment, batch normalization, and SiLU activation function to obtain the normalized fusion feature fused_b. Then, fused_b is passed through channel attention to obtain the attention value att, and then multiplied element-wise with fused_b to obtain the refined fusion feature fused_att. Finally, fused_att and fused are subjected to adjustable weighting to achieve enhancement and obtain Out.

[0111] Therefore, referring to the above, if features are P5a_up and P4a, then Out is P4td; the same applies to others, which will not be elaborated further.

[0112] ② As for DepthwiseSeparableConv, as a low-cost feature organizer, it can reorganize fused features with low computational cost.

[0113] Specifically, DepthwiseSeparableConv sequentially passes its input through channel-wise convolution, point-wise convolution, batch normalization, and SiLU activation function to obtain its output.

[0114] Among them, channel-wise convolution is responsible for local spatial organization within each channel, while point-wise convolution is responsible for remixing channel information. The two work together to refine the features.

[0115] 503. ShapeEnhance performs shape post-correction on P3BU~P5BU to obtain the corresponding cross-scale interactive features P3_out~P5_out.

[0116] ShapeEnhance performs similarity processing on P3BU~P5BU. Taking PiBU as an example, i∈{3,4,5}: ShapeEnhance sequentially passes PiBU through two layers of orientation-aware convolution (which can be implemented using grouped convolution; the first layer of the two orientation-aware convolutions is used to extract long strip orientation responses, and the second layer is used to further expand the continuity of orientation responses), batch normalization, and SiLU activation function to obtain the shape-aware feature PiBU_shape. Then, PiBU and PiBU_shape are superimposed to obtain Pi_out.

[0117] In summary, EnhancedBCFPN enables features at different scales to adaptively adjust their contribution based on fish size and scene density, and to collaboratively represent local details and global contours, thereby improving detection stability under conditions of curved poses, weak textures, and high overlap.

[0118] In summary, for ease of understanding, the above process of EnhancedBCFPN can be expressed by the following formula: ; ; ; ; ; ; In the formula, Align(.) represents the channel alignment layer processing; DSConv(.) represents the depth-separable convolution processing; DWF(.) represents the dynamic weighted fusion processing; Upsample(.) represents the upsampling processing; Downsample(.) represents the downsampling processing; and SE(.) represents the shape-aware enhancement layer processing.

[0119] Step 3: Train the YOLOv8-Fish network based on the sample dataset to obtain the trained YOLOv8-Fish network.

[0120] Generally, the sample dataset is divided into training, validation and test sets according to a certain ratio, which serve as the data basis for training and evaluating the YOLOv8-Fish network.

[0121] Specifically, it is recommended to use the PyTorch framework to build the training environment; initialize the YOLOv8-Fish network parameters, set the network input specifications (e.g., 640×640, or adjust according to computing power to balance small object detection accuracy and training efficiency), input the training set in batches, and construct a loss function to backpropagate and update the network parameters. The loss function is a comprehensive loss that integrates bounding box regression loss, prediction classification loss, and detection-related evaluation constraints, and its form can be expressed as: L_total = αL_box + βL_cls + γL_det; Where L_total represents the overall loss, L_box represents the bounding box regression loss, L_cls represents the prediction classification loss, L_det represents the detection-related evaluation constraint term, and α, β, and γ represent the weight coefficients corresponding to each loss component.

[0122] After each training cycle, the detection accuracy metrics (such as mAP@50, mAP@50-95, etc.) and keypoint-related metrics (such as keypoint error / visibility) are evaluated on the validation set. Visualization tools are used to monitor the loss and metric changes, and hyperparameters and enhancement intensity are adjusted as needed to avoid overfitting or underfitting.

[0123] During training, the network parameters with the best performance on the validation set are automatically saved, and the network parameters of the final round are also saved for reproduction and comparison—the better one is selected as the trained YOLOv8-Fish network.

[0124] Step 4: Use the trained YOLOv8-Fish network to identify the target fish from the image to be identified and obtain the prediction result.

[0125] Step four is the formal commencement of reasoning: S401, Obtain the image to be recognized.

[0126] The image to be identified can be a standalone image or an image obtained frame by frame from a real-time video stream or an offline video file.

[0127] S402, preprocess the image to be recognized to meet the input requirements of the YOLOv8-Fish network.

[0128] Generally, the image to be recognized is scaled to conform to the network input specifications, and the pixels are normalized to convert it into a tensor input format.

[0129] S403, input the preprocessed image to be identified into the trained YOLOv8-Fish network to obtain the prediction result.

[0130] The trained YOLOv8-Fish network will output prediction results that include the identified bounding boxes, key points, and confidence scores.

[0131] Step 5: Post-process the prediction results to obtain the detection results.

[0132] Specifically, the post-processing process is as follows: The prediction results are then subjected to confidence filtering and non-maximum suppression to remove redundant candidate boxes. Finally, the coordinates are mapped back to the size of the image to be identified to obtain the detection result.

[0133] It should be noted that, in order to ensure the accuracy of coordinate mapping, camera calibration and distortion correction are recommended to achieve accurate conversion from pixel coordinates to actual size.

[0134] ① Camera calibration: The camera intrinsic parameters K (camera matrix) and distortion coefficients D (distortion coefficients) are estimated by detecting the corner points within the checkerboard grid. The pixel-to-millimeter conversion ratio is estimated based on the actual size of a single checkerboard grid cell (unit: mm) and the pixel spacing between the corner points, in order to reduce the impact of camera shooting.

[0135] ② Distortion Correction: Based on the camera intrinsic parameter K and distortion coefficient D, a correction mapping is generated or a point correction function is used to correct the coordinates of key points, so that the key points are mapped to the correction coordinate system, ensuring the accuracy of the real scale conversion.

[0136] In addition, considering that the application scenarios of this method often involve video frames, which are prone to jitter in key point recognition, it is recommended to perform fish temporal consistency processing before confidence screening in post-processing to improve the stability and usability of key point recognition, reduce jitter and maintain morphological rationality.

[0137] Fish temporal consistency processing is actually based on window history caching and temporal consistency constraints to stabilize and fuse the key points and confidence of the current frame prediction, reduce jitter and maintain the rationality of morphological geometric relationships, so as to realize the identification and correction of key points in the current frame. This makes the identification results obtained independently frame by frame into corrected results that are smoother, more in line with motion laws and more in line with the fish skeleton structure, thereby improving the effect of subsequent post-processing.

[0138] Specifically, the process of handling fish temporal consistency is as follows: S501 copies the predicted keypoints (represented as keypoints) of the current frame into a cached version that does not backpropagate gradients and appends it to the historical sequence. Then, it extracts the most recent frames from the historical sequence through window pruning and performs motion pattern detection on them to obtain the probability distribution of the running mode. Finally, it obtains three constraint strength factors (including: smoothness strength factor, motion consistency strength factor, and shape consistency strength factor) through adaptive transformation.

[0139] S502, the predicted keypoints (represented as keypoints) and confidence (represented as confidence) of the current frame are processed with three-way temporal consistency (including: temporal smoothing to suppress frame-by-frame jitter, motion consistency to ensure that the displacement and velocity changes of keypoints are close to the real motion, and consistency to ensure that the relative geometric relationship of keypoints conforms to the shape of the fish) to obtain the corresponding three-way consistency features. The corresponding three-way consistency weights are obtained by passing the Softmax activation function. Then, the three-way consistency weights and the three-way consistency features are weighted and summed to obtain the weighted feature x_tc.

[0140] S503 first summarizes the three constraint strength factors into the overall constraint strength and normalizes it to the stable range of the constraint. Then, it is not only weighted with keypoints to obtain the original branch feature k_raw, but also weighted with x_tc to obtain the constraint branch feature k_tc. After that, k_raw and k_tc are superimposed to obtain the correction result. Then, confidence screening and non-maximum suppression are performed.

[0141] This embodiment 1 also provides a fish detection device based on an improved YOLOv8 network, which uses the above-mentioned fish detection method based on an improved YOLOv8 network.

[0142] A fish detection device based on an improved YOLOv8 network may include: a dataset construction module, a network construction module, a network training module, a network prediction module, and a post-processing module.

[0143] The dataset building module is configured to build a sample dataset for fish detection.

[0144] The network building module is configured to: adjust the structure based on the YOLOv8 network to obtain the YOLOv8-Fish network.

[0145] The network training module is configured to train the YOLOv8-Fish network based on the sample dataset to obtain a trained YOLOv8-Fish network.

[0146] The network prediction module is configured to use the trained YOLOv8-Fish network to identify the target fish from the image to be identified and obtain the prediction result.

[0147] The post-processing module is configured to perform post-processing on the prediction results to obtain the detection results.

[0148] Since this device uses the fish detection method based on the improved YOLOv8 network described above, it has the same effect, which will not be repeated here.

[0149] Simulation verification To illustrate the effectiveness of this method, Example 1 presents a performance evaluation and comparison based on a test set: (1) Using mAP@50 and mAP@50-95 as the main indicators, the results of this method and the standard YOLOv8-pose baseline are as follows: Table 1. Performance Comparison Results of the Methods It can be seen that, for both bounding box detection and detection of 5 key points, the proposed method shows significant improvements in mAP@50 and mAP@50-95, indicating that the proposed method has a good improvement in target localization accuracy, fine-grained representation ability and overall robustness in complex scenarios. It also shows that the YOLOv8-Fish network has a significant suppression effect on missed detections and false detections, verifying the effectiveness and superiority of the proposed method.

[0150] (2) Ablation experiments were conducted to verify the effectiveness of data augmentation strategies, EnhancedC2f_PPA, and EnhancedBCFPN. The results are as follows: Table 1. Performance Comparison Results of the Methods It is known that removing any of the data augmentation strategies, EnhancedC2f_PPA, or EnhancedBCFPN will affect network performance.

[0151] Among them, the data augmentation strategy significantly improved mAP@50-95, indicating that it enhanced the network's generalization ability in complex scenarios; EnhancedC2f_PPA brought stable gains to the detection of bounding boxes and 5 key points, indicating its effectiveness in feature representation and occlusion scene modeling; EnhancedBCFPN made the most outstanding contribution to the mAP@50-95 of bounding boxes, indicating that it significantly enhanced the multi-scale feature fusion and accurate localization capabilities.

[0152] (3) Deployment was carried out on the hardware platform, and the end-to-end inference speed and resource consumption were examined. The results are as follows: End-to-end deployment tests were conducted on the baseline method and the proposed method on current mainstream CPU hardware platforms. The results show that the baseline method has an average inference latency of 54.53 ms, a P95 latency of 66.66 ms, an inference speed of 18.34 FPS, 3,083,424 parameters, and a network size of approximately 11.76 MB. The proposed method has an average inference latency of 102.06 ms, a P95 latency of 119.13 ms, an inference speed of 9.80 FPS, 3,340,466 parameters, and a network size of approximately 12.74 MB.

[0153] It can be seen that while the network accuracy is improved by this method, the computational overhead and inference latency increase. However, the overall parameter scale and network volume increase are relatively small, indicating that this method achieves performance enhancement at a relatively controllable resource cost and still has good engineering deployment feasibility.

[0154] Example 3 This embodiment 3 discloses a computer device, including a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, it implements the steps of the fish detection method based on the improved YOLOv8 network disclosed in embodiment 1.

[0155] The computer equipment can be either a mobile terminal or a fixed terminal. Examples of the former include mobile phones, laptops, digital radio receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), and in-vehicle terminals (such as in-vehicle navigation terminals); examples of the latter include digital TVs and desktop computers.

[0156] This embodiment 3 also discloses a readable storage medium storing computer program instructions. When the computer program instructions are read and executed by a processor, the steps of the fish detection method based on the improved YOLOv8 network disclosed in embodiment 1 are performed.

[0157] The readable storage medium may include, but is not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above.

[0158] This embodiment 3 also discloses a computer program product, including a computer program. When executed by a processor, the computer program implements the steps of the fish detection method based on the improved YOLOv8 network disclosed in embodiment 1.

[0159] It should be noted that the computer program used to execute the above can be written in one or more programming languages ​​or a combination thereof. These programming languages ​​include object-oriented programming languages—such as Java, Smalltalk, and C++—as well as conventional procedural programming languages—such as C or similar languages. The computer program can be executed entirely on the user's computer, partially on the user's computer, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer through any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN).

[0160] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0161] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this invention patent should be determined by the appended claims.

Claims

1. A fish detection method based on an improved YOLOv8 network, characterized in that, This includes: using a trained YOLOv8-Fish network to identify target fish from an image to be identified; The construction method of the YOLOv8-Fish network includes: The C2f structure in stage 2 of the YOLOv8 backbone is replaced with the Enhanced C2f_PPA multi-scale fusion structure to improve feature representation under occlusion and overlap conditions. A combined prior attention layer, including at least an improved convolutional block attention layer (ImprovedCBAM) and a fish shape attention layer (FishShapeAttention), is introduced before it to enhance the saliency and morphological response of the fish. The neck network of the YOLOv8 network was replaced with the Enhanced Bidirectional Cross-Scale Feature Pyramid Network (EnhancedBCFPN) to achieve more comprehensive cross-scale information interaction.

2. The fish detection method based on the improved YOLOv8 network according to claim 1, characterized in that, EnhancedC2f_PPA is obtained by replacing all bottleneck blocks Bottleneck within the C2f structure with the new bottleneck block New_Bottleneck designed in the new structure. The New_Bottleneck includes: OcclusionAwarePPA (Occlusion Aware Parallel Attention Layer), OverlapSeparation (Overlap Separation Layer), MultiScaleContext (Multi-Branch Context Modeling Layer), AdaptiveWeighting (Adaptive Feature Weighting Layer), and ResidualAdd (Residual Addition Layer). Within any New_Bottleneck: OcclusionAwarePPA is used to perform occlusion awareness on the input of its New_Bottleneck to obtain the perceptual enhancement feature x_occ; OverlapSeparation is used to perform overlap separation on x_occ to obtain the separation feature x_sep; MultiScaleContext is used to perform context modeling on x_sep through three scales of context branches (small, medium, and large), and the context modeling results of each branch are concatenated to obtain the context fusion feature x_ctc; AdaptiveWeighting is used to perform adaptive feature weighting on x_ctc to obtain the comprehensive enhancement feature x_w; ResidualAdd is used to superimpose the input and x_w to obtain the output of its New_Bottleneck.

3. The fish detection method based on the improved YOLOv8 network according to claim 2, characterized in that, OcclusionAwarePPA first extracts the local and global contexts from the input and performs context fusion to obtain context fusion features. Then, it performs occlusion estimation on the context fusion features to obtain the region response. Finally, it reweights the context fusion features based on the region response to obtain x_occ. Or / and, OverlapSeparation first extracts boundary cues and local separation cues from x_occ, and performs separation and fusion to enhance the transition region between adjacent targets, thus obtaining target fusion features; The target fusion features are further refined to reduce the tendency of large, contiguous areas being mistaken for a single target, resulting in x_sep; Or / and, AdaptiveWeighting performs multi-branch feature transformation on x_ctc to obtain multiple transformed features, and on the other hand, it performs global description extraction, weight prediction, and Softmax normalization on x_ctc to obtain the weights of the corresponding transformed features. Then, it performs weighted summation with the corresponding transformed features and then performs convolution to obtain x_w.

4. The fish detection method based on the improved YOLOv8 network according to claim 1, characterized in that, The combined prior attention layer includes: ImprovedCBAM and FishShapeAttention; ImprovedCBAM is connected after the convolutional module of stage two in the backbone network; FishShapeAttention is connected after ImprovedCBAM; the outputs of ImprovedCBAM and FishShapeAttention are fused and then input into EnhancedC2f_PPA; EnhancedC2f_PPA is connected before the convolutional module of stage three in the backbone network. ImprovedCBAM includes: GroupedChannelAttention, Multi-ScaleSpatialAttention, and two ResidualFusion layers; In ImprovedCBAM: GroupedChannelAttention splits the input In_x of ImprovedCBAM into several groups according to channels, allowing different channel groups to learn weights for different semantic types, and then weights them with the corresponding channel groups to obtain the channel enhancement result x_ca_attn; the first ResidualFusion performs adjustable weighting on x_ca_attn and In_x to obtain the primary fusion feature x_ca; Multi-ScaleSpatialAttention is used to summarize the channel dimension information of x_ca into a spatial description, and then uses convolutional branches with different receptive fields to estimate the regions worth focusing on to obtain the spatial enhancement result x_sa_attn; the second ResidualFusion performs adjustable weighting on x_ca and x_sa_attn to obtain the secondary fusion feature x_cbam; FishShapeAttention includes: ChannelReduce, DirectionalConv, DirectionSelection, DirectionAggregation, ChannelExpand, and ResidualFusion. In FishShapeAttention: ChannelReduce compresses x_cbam along the channel dimension to obtain compressed features x_r; DirectionalConv scans x_r with D directional convolutional kernels to obtain multiple results observed in different directions at the same location, and stacks them along the direction dimension to form directional features x_d; DirectionSelection normalizes x_d along the direction dimension using the Softmax activation function to obtain directional normalization weights w_d; DirectionAggregation weights x_d element-wise along the direction dimension based on w_d and sums them to obtain single-path features w_s; ChannelExpand restores w_s to the same size as x_cbam along the channel dimension to obtain restored features fx; ResidualFusion performs adjustable weighting on x_cbam and fx to obtain shape fusion features y_attn1.

5. The fish detection method based on the improved YOLOv8 network according to claim 1, characterized in that, The combined prior attention layers include: ImprovedCBAM, FishShapeAttention, and the fish color-specific attention layer FishColorAttention; ImprovedCBAM and FishColorAttention are connected in parallel after the convolutional module structure of stage two in the backbone network; FishShapeAttention is connected after ImprovedCBAM; the outputs of ImprovedCBAM, FishShapeAttention, and FishColorAttention are fused and then input into EnhancedC2f_PPA; EnhancedC2f_PPA is connected before the convolutional module of stage three in the backbone network. ImprovedCBAM includes: GroupedChannelAttention, Multi-ScaleSpatialAttention, and two ResidualFusion layers; In ImprovedCBAM: GroupedChannelAttention splits the input In_x of ImprovedCBAM into several groups according to channels, allowing different channel groups to learn weights for different semantic types, and then weights them with the corresponding channel groups to obtain the channel enhancement result x_ca_attn; the first ResidualFusion performs adjustable weighting on x_ca_attn and In_x to obtain the primary fusion feature x_ca; Multi-ScaleSpatialAttention is used to summarize the channel dimension information of x_ca into a spatial description, and then uses convolutional branches with different receptive fields to estimate the regions worth focusing on to obtain the spatial enhancement result x_sa_attn; the second ResidualFusion performs adjustable weighting on x_ca and x_sa_attn to obtain the secondary fusion feature x_cbam; FishShapeAttention includes: ChannelReduce, DirectionalConv, DirectionSelection, DirectionAggregation, ChannelExpand, and ResidualFusion. In FishShapeAttention: ChannelReduce compresses x_cbam along the channel dimension to obtain compressed features x_r; DirectionalConv scans x_r with D directional convolutional kernels to obtain multiple results observed in different directions at the same location, and stacks them along the direction dimension to form directional features x_d; DirectionSelection normalizes x_d along the direction dimension using the Softmax activation function to obtain directional normalization weights w_d; DirectionAggregation weights x_d element-wise along the direction dimension based on w_d and sums them to obtain single-path features w_s; ChannelExpand restores w_s to the same size as x_cbam along the channel dimension to obtain restored features fx; ResidualFusion performs adjustable weighting on x_cbam and fx to obtain shape fusion features y_attn1. FishColorAttention includes: ChannelAttention, SpatialAttention, ColorExtractor, AdaptiveThreshold, MultiScaleColorFusion, OcclusionAwareAttention, and FinalFusion. In FishColorAttention: ChannelAttention and SpatialAttention are concatenated to form a general main path, which extracts the fish body salient features x_attn from the input In_x of FishColorAttention without relying on color priors. ColorExtractor first performs color mapping on In_x to facilitate color analysis. Then, one path estimates the color confidence c_confidence, which represents a specific color, and the other path enhances the color to obtain the color enhancement feature c_enhanced, which preserves color discrimination. AdaptiveThreshold generates an adaptive threshold t based on In_x and generates a color mask c_mask by masking c_confidence according to t. MultiScaleColorFusion processes c_enhanced through three color branches of small, medium, and large scales, and then concatenates and fuses the results of the three branches to obtain the color fusion feature c_fused. OcclusionAwareAttention is used to correct the color reliability of c_fused based on c_mask. FinalFusion is used to fuse x_attn and c_path_out to obtain the color fusion feature y_attn2.

6. The fish detection method based on the improved YOLOv8 network according to claim 1, characterized in that, EnhancedBCFPN includes: Align channel alignment layer, EnhancedBiFPNLayer enhanced bidirectional feature pyramid layer, and ShapeEnhance shape-aware enhancement layer. Align is used to perform channel alignment on the three inputs P3_in~P5_in of EnhancedBCFPN to obtain the corresponding alignment features P3a~P5a; where P3_in is the output of EnhancedC2f_PPA; P4_in is the output of the C2f structure in stage three of the backbone network, and P5_in is the output of the SPPF structure in stage four of the backbone network; EnhancedBiFPNLayer performs bidirectional feature extraction based on P3a~P5a from top to bottom and bottom to top, and combines it with dynamic weighted fusion between features to obtain the corresponding cross-scale fusion features P3BU~P5BU; ShapeEnhance performs shape post-correction on P3BU~P5BU to obtain the corresponding cross-scale interaction features P3_out~P5_out.

7. The fish detection method based on the improved YOLOv8 network according to claim 6, characterized in that, The bottom-up data processing within EnhancedBiFPNLayer includes: upsampling P5a to obtain the upsampled feature P5a_up; dynamically weighted fusion of P5a_up and P4a to obtain the fused feature P4td; depthwise separable convolution of P4td to refine the feature P4TD; upsampling P4TD to obtain the upsampled feature P4TD_up; dynamically weighted fusion of P4TD_up and P3a to obtain the fused feature P3td; and depthwise separable convolution of P3td to refine the feature P3BU. The top-down data processing within EnhancedBiFPNLayer includes: downsampling P3BU to obtain the downsampled feature P3BU_down; dynamically weighting and fusing P3BU_down, P4a, and P4TD to obtain the fused feature P4bu; performing depthwise separable convolution on P4bu to refine the feature and obtain P4BU; downsampling P4BU to obtain the downsampled feature P4BU_down; dynamically weighting and fusing P4BU_down and P5a to obtain the fused feature P5bu; and performing depthwise separable convolution on P5bu to refine the feature and obtain P5BU. Among them, dynamic weighted fusion applies corresponding dynamic weights to its input, and first performs coarse fusion, then refinement, and then enhancement to obtain its output; depthwise separable convolution passes its input through channel-wise convolution, point-wise convolution, batch normalization, and SiLU activation function in sequence to obtain its output. Or / and, ShapeEnhance sequentially passes PiBU through two layers of orientation-aware convolution, batch normalization, and SiLU activation function to obtain the shape-aware feature PiBU_shape, and then stacks PiBU and PiBU_shape to obtain Pi_out; i∈{3,4,5}.

8. The fish detection method based on the improved YOLOv8 network according to claim 1, characterized in that, It also includes: training the YOLOv8-Fish network based on a sample dataset to obtain a trained YOLOv8-Fish network; The methods for constructing the sample dataset include: S101 uses a high-definition camera to capture raw videos of the fishway in different scenarios. Video and from it at fixed intervals Δ t Extract frame images to form the original dataset. a 0; S102, regarding the original dataset a 0. Image sizes were standardized, and manual annotation was performed using annotation tools to ensure that each image had annotation content, resulting in a standard dataset. a 1; The annotation content includes: the bounding rectangle of the fish body, and five key points of the fish body: head, neck, body center, tail root, and tail tip; S103, for labeled datasets a 1. Perform data augmentation to expand the sample and obtain an expanded dataset. a 2. And used as a sample dataset; data augmentation is performed in random combination and random order as general augmentation, occlusion augmentation, overlap augmentation, color change augmentation, water ripple augmentation, and motion blur augmentation.

9. The fish detection method based on the improved YOLOv8 network according to claim 1, characterized in that, It also includes: performing confidence filtering and non-maximum suppression on the prediction results output by the trained YOLOv8-Fish network in sequence, and then mapping the coordinates back to the size of the image to be identified to obtain the detection result; Among them, camera calibration and distortion correction are performed when mapping the coordinates back to the size of the image to be identified; Or / and, it also includes: sequentially performing fish temporal consistency processing, confidence filtering, and non-maximum suppression on the prediction results output by the trained YOLOv8-Fish network, and then mapping the coordinates back to the size of the image to be identified, thus obtaining the detection result; The fish time-series consistency processing includes: S501 copies the keypoints predicted in the current frame into a cached version that does not backpropagate gradients and appends it to the historical sequence. Then, it extracts the most recent frames from the historical sequence through window pruning and performs motion pattern detection on them to obtain the probability distribution of the running mode. Finally, it obtains three constraint strength factors through adaptive transformation. S502, the keypoints predicted in the current frame and the confidence are processed in three-way temporal consistency to obtain the corresponding three-way consistency features, and the corresponding three-way consistency weights are obtained by passing them through the Softmax activation function. Then, the three-way consistency weights and the three-way consistency features are weighted and summed to obtain the weighted feature x_tc. S503, first, the three constraint strength factors are summarized into the overall constraint strength and normalized to the stable range of the constraint. Then, not only is it weighted with keypoints to obtain the original branch feature k_raw, but it is also weighted with x_tc to obtain the constraint branch feature k_tc. After that, k_raw and k_tc are superimposed to obtain the correction result. In this process, camera calibration and distortion correction are performed when mapping the coordinates back to the size of the image to be identified.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the fish detection method based on the improved YOLOv8 network as described in any one of claims 1-9.