Lightweight fish counting method based on directional bounding box
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-26
- Publication Date
- 2026-08-11
AI Technical Summary
[0005]以上文献通过先获取图像后进行预处理,再将预处理后的模型输入至训练模型中以获取检测结果,在过程中进行反复的上采样和下采样等操作增加了计算网络模型的工作量,在预测筛选时也会进一步增加计算压力,同时采用手持设备获取图像,由于鱼类在养殖池中运动方向是可旋转的,而对于不同的鱼类的不同方向上若不对旋转方向进行处理,将导致后续检测结果的可靠性,并且鱼类在养殖环境下容易出现重叠的情况,从而使得在鱼苗密集或互相遮挡时容易产生漏检或误检,导致需要反复拍摄,使得整体的计数效率较低,无法实现高效的实时监测
[0026]以上设置,通过置信度筛选能够保留有效的鱼体目标,通过旋转非极大值抑制处理能够尽可能选出符合的鱼体目标且抑制掉不符合的目标,提高了计数结果的准确性的效率。
Smart Images

Figure CN122550563A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of aquaculture technology, specifically to a lightweight fish counting method based on directional bounding boxes. Background Technology
[0002] Aquaculture is developing towards large-scale, intensive, and intelligent operations. Among these, fish counting is a fundamental task in aquaculture management. Accurate fish counts are of great significance for precise feed delivery and stocking density control. Therefore, how to achieve efficient and accurate fish counting in actual aquaculture environments has become one of the key technical issues in the field of smart fisheries.
[0003] Traditional fish counting methods primarily rely on manual counting or mechanical sampling. Manual counting is not only labor-intensive and inefficient, but also susceptible to subjective factors and visual fatigue, leading to significant statistical errors. Mechanical sampling, on the other hand, cannot provide continuous real-time monitoring and may harm individual fish. Therefore, non-invasive automated technologies are gradually replacing traditional counting methods. In particular, the use of horizontal bounding boxes to label and locate fish targets has become widely adopted. However, existing technologies often struggle to accurately fit the target outline and tend to introduce significant background areas. Furthermore, increasing detection accuracy increases the number of parameters and computational load, significantly impacting monitoring efficiency.
[0004] For example, patent document with patent application number 202210602746.4 and publication date of August 5, 2022 discloses a fish fry counting method and device based on a lightweight network. The method uses a handheld device's camera to capture fish fry images of a target area, preprocesses the fish fry images, inputs the preprocessed fish fry images into a pre-trained lightweight network model to obtain fish fry detection results, and statistically counts the fish fry detection results of the target area to obtain the final counting result.
[0005] The above literature describes a process where images are acquired and preprocessed before being input into a training model to obtain detection results. This process involves repeated upsampling and downsampling, increasing the workload of the computational network model and further increasing computational pressure during prediction and screening. Furthermore, using handheld devices to acquire images presents challenges. Since fish in aquaculture ponds can rotate, failing to address the rotation direction for different fish species in different directions can compromise the reliability of subsequent detection results. Additionally, fish in aquaculture environments are prone to overlapping, leading to missed or false detections when fry are densely packed or obscuring each other. This necessitates repeated image capture, resulting in low overall counting efficiency and hindering efficient real-time monitoring. Summary of the Invention
[0006] This invention provides a lightweight fish counting method based on oriented bounding boxes, which can accurately detect and count fish even in complex aquaculture environments, and has low model parameter and computational load, and high real-time monitoring efficiency.
[0007] To achieve the above objectives, the technical solution provided by this invention is: a lightweight fish counting method based on oriented bounding boxes, comprising the following steps: S1. Obtain fish image frames in the aquaculture environment, preprocess the fish image frames, and obtain the input features of the fish body; S2. Use directional bounding boxes to annotate the fish targets in the preprocessed fish images. The annotated fish targets are used to construct a fish sample dataset. The directional bounding boxes are used to characterize the position, size and orientation information of the fish targets. The fish size is directionally annotated according to the orientation information. S3. Based on YOLOv8n, construct the SDL-Fish fish counting model. The SDL-Fish fish counting model includes a backbone network, a neck feature fusion network, and a detection head. The backbone network extracts basic features from the input features of the fish body through convolution, nonlinear mapping, and random depth. The neck feature fusion network selects different convolution kernels according to the current distribution of basic features and outputs features after convolution. The detection head is used to detect the output features according to different directional information and output the detection results. S4. Train the SDL-Fish fish counting model using the fish sample dataset to obtain the trained SDL-Fish fish counting model. S5. The trained SDL-Fish fish counting model is compressed using the LAMP pruning strategy to obtain the compressed SDL-Fish fish counting model. S6. Input the real-time acquired fish image frames into the compressed SDL-Fish fish counting model, output the detection results of the fish targets, and obtain the fish counting results based on the output detection results. The detection structure includes category information, orientation bounding box parameters, and orientation parameters.
[0008] The above method first acquires fish image frames through the device and improves sample quality through preprocessing to obtain high-quality fish input features. Then, it uses target location, size, and orientation information, and uses the orientation information to directionally label the size information of the fish targets, thereby unifying the orientation information of different fish. This allows the bounding boxes to fit the fish contour along the main axis, reducing background redundancy and overlap between adjacent targets, thus facilitating subsequent recognition. Oriented bounding boxes are used to label fish targets and construct a fish sample dataset, which reduces background redundancy and overlap interference between adjacent targets. Then, an SDL-Fish fish counting model is built based on YOLOv8n. In the SDL-Fish fish counting model, the backbone network extracts basic features at different levels through convolution, non-linear mapping, and random depth. The depthwise convolutional unit is used to extract the spatial local information of the input features, and the non-linear mapping is used to convert the input features into spatial local information. By mapping features to different subspaces, both shallow texture information and deep semantic information can be extracted, reducing environmental influences. Dynamic convolution on the neck layer can adaptively emphasize more discriminative feature components during multi-scale feature fusion, improving the model's detection stability under changes in fish scale, pose, and complex lighting conditions. Adding orientation information to the detection head allows the detected results to be further determined based on the orientation information, thus making the detection results correlated with the orientation information and further improving the detection accuracy. This allows the SDL-Fish fish counting model to remain lightweight while reducing the impact of the aquaculture environment on model construction. The SDL-Fish fish counting model is then trained using a fish sample dataset to make the model more accurate. Finally, the trained SDL-Fish fish counting model is compressed using the LAMP pruning strategy to reduce the number of model parameters and computational cost, resulting in accurate fish counting results.
[0009] Furthermore, the oriented bounding box mentioned in step S2 is represented as: ; x and y represent the horizontal and vertical coordinates of the oriented bounding box, respectively; w and h represent the width and height of the oriented bounding box, respectively; and θ represents the orientation information of the oriented bounding box, i.e., the rotation angle of the oriented bounding box relative to the horizontal axis. The range of values for the rotation angle is constrained as follows: ; The constraint relationship between w and h is: w ≥ h.
[0010] The above settings represent the oriented bounding box through five dimensions, resulting in higher accuracy. At the same time, by limiting the rotation angle and the constraint relationship between w and h, the long side is uniformly represented as the width, which simplifies the expression and reduces the difficulty of subsequent model learning.
[0011] Furthermore, in step S3, the backbone network adopts a StarNet staged hierarchical structure. The input fish sample dataset enters the Stem layer of the backbone network, where the backbone network performs preliminary feature extraction on the fish sample dataset and obtains the Stem layer output feature mapping F based on the fish sample dataset. stem As shown in formula (4), (4); X represents the input fish sample dataset; Conv() represents convolution calculation; Represents batch normalization; ReLU6() represents the activation function that limits the activation value to the range [0,6]. Meanwhile, the backbone network adopts a channel increment strategy at different stages, obtaining the number of channels C in the next stage by using the number of channels in each stage and the channel expansion coefficient. i+1 As shown in formula (5), (5); C i α represents the number of channels in the i-th stage, and α represents the preset channel expansion coefficient.
[0012] The above settings employ a StarNet phased hierarchical structure for the backbone network and use the Stem layer to perform preliminary feature extraction on the input fish sample dataset to obtain the output feature map. This allows for the extraction of more features while maintaining a lightweight architecture. Furthermore, the use of a channel increment strategy enables accurate extraction of fish body features with a small number of parameters.
[0013] Furthermore, each stage of the StarNet phased hierarchical structure includes a convolutional layer and a StarBlock module. The StarBlock module maps the input features to different subspaces, performs element-wise multiplication on the features in different subspaces, and superimposes and fuses the output features of the (l+1)th layer with the original input features. The output features of the (l+1)th layer are calculated based on the input features of the lth layer, as shown in formula (6). (F) l+1 =F l +Drop(MLP(Conv(F)) l )))(6; F l Let F be the input feature of the l-th layer. l+1 This is represented as the output feature of the (l+1)th layer; Represents a multilayer perceptron mapping. This indicates a random depth operation.
[0014] The above settings, through the StarBlock module, map the input features to different subspaces and perform element-wise multiplication operations accordingly, thereby increasing the interaction between different subspaces.
[0015] Furthermore, the neck feature fusion network described in step S3 adopts the C2f-Dynamic module. The C2f-Dynamic module integrates a dynamic convolution mechanism on the basis of the C2f structure. Attention weights are obtained through the C2f-Dynamic module, and dynamic weights and dynamic biases related to the input features are obtained through the attention weights. Dynamic convolutions are generated according to the input feature mapping, as shown in formula (11). y=g(W(x) T *x+b(x))(11); x represents the basic feature mapping of the input, W(x) represents the dynamic weights related to the basic features of the input, and b(x) represents the dynamic biases related to the basic features of the input.
[0016] The above method obtains attention weights through the C2f-Dynamic module, and obtains dynamic weights and dynamic biases related to the input features through the attention weights. This enables the dynamic convolution to adaptively adjust as the parameters change, enhancing the model's adaptability to problems such as changes in fish pose or fish occlusion.
[0017] Furthermore, in step S3, global average pooling is performed on the input basic features through the C2f-Dynamic module to extract global statistical information of the input basic features; then, weight coefficients corresponding to multiple candidate convolutional kernels are generated through two fully connected mapping layers and nonlinear activation functions; finally, the weight coefficients are normalized through the SoftMax function to obtain the dynamic weights W(x) and dynamic biases b(x) of the candidate convolutional kernels. The C2f-Dynamic module adaptively selects the candidate convolutional kernels through attention weights.
[0018] The above method performs global average pooling and statistics on the input basic features, generates candidate convolution kernels and determines dynamic weights and dynamic biases through mapping and nonlinearity, and adaptively selects candidate convolution kernels through attention weights, so that the model can be adjusted according to the complexity of the input features, reducing unnecessary parameters and computation.
[0019] Furthermore, the detection head mentioned in step S3 is a lightweight multi-branch LMBD detection head, which includes a shared convolutional sequence, a group normalization unit, and a parallel prediction unit. The group normalization unit performs normalization processing on the input features, as shown in formula (14). (14); x n,c,h,wThis represents the feature element within the corresponding channel. Represented as the normalized eigenvalues, μ g This is represented as the mean of the features within the corresponding group. ε represents the variance of the features within the corresponding group, and ε represents the numerical stability constant. The standardized input features are mapped by the SiLu activation function and then input into the parallel prediction unit.
[0020] The above settings, by setting up a lightweight multi-branch detector head for LMBD and standardizing the input features, avoid large computational loads and are less likely to lose small target features. Then, by mapping the standardized input features through the SiLu activation function, the nonlinear features can be better represented.
[0021] Furthermore, in step S5, the LAMP pruning strategy assigns importance scores to each weight and prunes the low-contribution weights in the trained SDL-Fish fish counting model based on the importance score results, thus forming a compressed SDL-Fish fish counting model.
[0022] The above settings determine the contribution of each weight by scoring it according to its contribution level, and prune the paths of weights with low contributions, thereby reducing the computational load of the entire model.
[0023] Furthermore, the LAMP pruning strategy in step S5 includes: Importance scores are calculated based on the weight of path u, as shown in formula (15). (15); W[u] represents the weight of path u. It is represented as the sum of squared weights of path u and its subsequent paths.
[0024] The above settings reduce the introduction of parameters by scoring the importance of the path weights, and the weight calculation can improve the accuracy of the model and reduce the model storage size.
[0025] Furthermore, in step S6, the detection results of the output fish targets are subjected to confidence screening and rotational nonmaximum suppression processing, and the fish targets are retained for quantity statistics, finally obtaining the fish count results.
[0026] The above settings, through confidence filtering, can retain valid fish targets, and through rotational nonmaximum suppression, can select as many matching fish targets as possible while suppressing non-matching targets, thus improving the efficiency and accuracy of the counting results. Attached Figure Description
[0027] Figure 1 This is a flowchart of the present invention.
[0028] Figure 2 This is a schematic diagram of the SDL-Fish fish counting model of the present invention.
[0029] Figure 3 This is a schematic diagram illustrating the acquisition of fish image frames according to the present invention. Detailed Implementation
[0030] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0031] like Figures 1 to 3 As shown, a lightweight fish counting method based on oriented bounding boxes includes the following steps: S1. Obtain fish image frames in the aquaculture environment, preprocess the fish frames, and obtain the input features of the fish body; S2. Use directional bounding boxes to annotate the fish targets in the preprocessed fish images. The annotated fish targets are used to construct a fish sample dataset. The directional bounding boxes are used to characterize the position, size and orientation information of the fish targets. The orientation information is the rotation angle of the bounding box relative to the horizontal reference axis. The fish size is directionally annotated by the rotation angle information so that it fits the fish contour along the main axis of the fish. S3. Based on YOLOv8n, construct the SDL-Fish fish counting model. The SDL-Fish fish counting model includes a backbone network, a neck feature fusion network, and a detection head. The backbone network extracts basic features from the input features of the fish body through convolution, nonlinear mapping, and random depth. The neck feature fusion network is used to select different convolution kernels according to the current distribution of basic features and then output features. The detection head is used to detect the output features according to different directional information and output the detection results. S4. Train the SDL-Fish fish counting model using the fish sample dataset to obtain the trained SDL-Fish fish counting model. S5. The LAMP pruning strategy is used to compress the trained SDL-Fish fish counting model. By scoring the importance of each weight, the low-contribution weights in the trained SDL-Fish fish counting model are pruned according to the importance score results to obtain the compressed SDL-Fish fish counting model. The compressed SDL-Fish fish counting model is then used to obtain the deployed SDL-Fish fish counting model. S6. Input the real-time acquired fish image frames into the deployed SDL-Fish fish counting model, output the detection results of fish targets, and obtain the fish counting results based on the output detection results. The detection structure includes category information, directional bounding box parameters, and orientation parameters.
[0032] In step S1, fish image frames are acquired by an image acquisition device set above the aquaculture pond. The image acquisition device covers the main activity area of the fish from a top-down perspective. The image acquisition device continuously captures the activity of the fish in the aquaculture pond. The acquired fish images or fish videos are processed by frame extraction, and blurry frames and highly repetitive frames are removed to form the original fish image frames. The data collected includes complex scenes such as dense fish schools, changes in posture, water surface reflections, and partial occlusions. All complex scenes cover different lighting conditions, including natural light, low light, and artificial lighting. In this embodiment, the image acquisition device is an industrial camera.
[0033] The preprocessing described in step S1 includes image size unification, brightness and contrast adjustment, scale transformation, flip enhancement, rotation perturbation, and normalization operations. By performing the above operations on the original fish image frame, the preprocessed input features of the fish body are obtained, as shown in formula (1). I'=φ(I)(1; Where φ() represents the preprocessing mapping consisting of image size unification, brightness and contrast adjustment, scale transformation, flip enhancement, rotation perturbation and normalization, I represents the original fish image frame, and I' represents the input features of the preprocessed fish body. Step S1 can reduce the impact of fish body overlap, perspective distortion, and local occlusion on subsequent counting results under side-view conditions, ensuring that the acquired data is clear, and also providing a stable data foundation for subsequent sample annotation, model training, and model validation.
[0034] In step S2, the oriented bounding box is used to represent the position, size, and orientation information of the fish target. The parameterized form of the oriented bounding box can be expressed as: ; Where x and y represent the x-coordinate and y-coordinate of the oriented bounding box, respectively; w and h represent the width and height of the oriented bounding box, respectively; and θ represents the rotation angle of the oriented bounding box relative to the horizontal axis. The range of values for the rotation angle is constrained as follows: ; The constraint relationship between w and h is: w ≥ h; When the width and height correspondence of the directional bounding box are inconsistent, a consistency transformation can be performed on the width, height, and angle to ensure the uniqueness of the directional bounding box representation. In this embodiment, when w < h, parameter changes can be performed, as shown in formula (8). (w,h,θ)←(h,w,θ+π / 2)(2); Here, ← represents the parameter replacement operation; by using directional bounding boxes for annotation, the main axis of the fish body is made to fit the outline of the fish body, reducing background redundancy and inter-box overlap between adjacent targets, thereby improving the detection and counting accuracy in dense fish schools and pose change scenarios.
[0035] In step S3, the SDL-Fish fish counting model addresses issues such as reflective interference, weak texture targets, scale variations, and fish occlusion in aquaculture environments by improving the backbone network, feature fusion structure, detection head, and model compression method. The SDL-Fish fish counting model is built on the basis of YOLOv8n, adding a StarNet structure to the YOLOv8n backbone network, a C2f-Dynamic structure to the YOLOv8n neck network, and an LMBD mechanism to the YOLOv8n detection head.
[0036] like Figure 2 As shown, the SDL-Fish fish counting model includes a backbone network, a neck feature fusion network, and a detection head. The backbone network is used to extract the basic features of fish image frames, the neck structure is used to fuse basic features at different levels, and the detection head is used to output the predicted category, location, and orientation of the fish target. The processing flow of the SDL-Fish fish counting model can be represented as follows: Y=ψ head (ψ) neck (ψ) backbone (I'))); Where Y represents the model output, ψ backbone ( ) represents the backbone network feature extraction mapping, ψ neck ( ) represents the neck feature fusion mapping, ψ head ( ) represents the output mapping of the detection head, and I' represents the preprocessed image; In this embodiment, the backbone network adopts the StarNet staged hierarchical structure. The input fish image frame enters the Stem layer of the backbone network. The Stem layer is used to perform initial convolution mapping and downsampling processing on the input fish image. Based on the preprocessed fish body features I', the initial feature map output by the Stem layer can be obtained, as shown in formula (3). F0=δ(BN(Conv(I')))(3); Where F0 represents the initial feature map output by the Stem layer, δ() represents the non-linear activation function, Conv() represents the convolution calculation, and BN() represents the batch normalization operation.
[0037] The backbone network performs preliminary feature extraction on the input features of the fish body and obtains the Stem layer output feature map F based on the input features of the fish body. stem As shown in formula (1), (4); Where X represents the input fish sample dataset; Conv() represents convolution calculation; BN() represents batch normalization operation; ReLU6() represents the activation function that limits the activation values to the range [0,6].
[0038] Meanwhile, the backbone network employs a channel increment strategy and a resolution decrement strategy at different stages, obtaining the number of channels C for the next stage through the number of channels and the channel expansion coefficient at each stage. i+1 As shown in formula (5), (5); Among them, C i This represents the number of channels in the i-th stage, and α represents the preset channel expansion coefficient. Within each stage, the StarNet structure uses StarBlock as the basic feature extraction unit. StarBlock includes a depthwise convolution unit, a feature projection unit, a star operation unit, and a residual update unit. The depthwise convolution unit is used to extract the spatial local information of the input features, the feature projection unit is used to map the input features to different subspaces, the star operation unit is used to perform element-wise multiplication operations on the features of different subspaces, and the residual update unit is used to superimpose and fuse the transformed features with the original input features. The output features of the (l+1)th layer are calculated based on the input features of the lth layer, as shown in formula (6). (F) l+1 =F l +Drop(MLP(Conv(F)) l )))(6; Among them, F l Let F be the input feature of the l-th layer. l+1 This is represented as the output feature of the (l+1)th layer; Represents a multilayer perceptron mapping. Indicates a random depth operation; The star operation unit enhances the higher-order interaction between basic features by performing element-wise multiplication on the basic features from different mapping branches. The star operation output features are obtained by performing element-wise multiplication on the output of the projection branch, as shown in formula (7). Z = Z1⊙Z2(7) Where Z represents the output feature of the star operation, Z1 represents the output of the first projection branch, Z2 represents the output of the second projection branch, and ⊙ represents the element-wise multiplication operation. Through the above calculations, the StarNet backbone network can enhance the ability to extract target features under conditions of weak texture fish, high water surface reflectivity, and complex background while maintaining lightweight design.
[0039] In this embodiment, the neck feature fusion network adopts the C2f-Dynamic module. The C2f-Dynamic module integrates a dynamic convolution mechanism on the basis of the C2f structure. The C2f-Dynamic module includes an input splitting unit, a Bottleneck transform unit, a dynamic convolution unit, and a fusion output unit. The input splitting unit is used to divide the input features into at least two processing paths, one of which retains the original or shallowly transformed features, as shown in formula (8). F in →(F) a F b (8); Among them, F in Represented as input features, F a F represents the feature of preserving branches. b Represented as depth transform branch features; The input splitting unit enters the Bottleneck transform unit via another path for further processing; The dynamic convolutional unit includes an attention weight calculation submodule, a convolutional kernel aggregation submodule, and a dynamic convolution output submodule. The dynamic convolutional unit first performs global average pooling on the input features to extract global statistical information of the input features. Then, it generates weight coefficients corresponding to multiple candidate convolutional kernels through two fully connected mapping layers and a non-linear activation function. Finally, it normalizes the weight coefficients through the SoftMax function to obtain the attention weight set of the candidate convolutional kernels. In this embodiment, the dynamic weights related to the input features are obtained by the number of convolution kernels, as shown in formula (9); (9); Among them, W k Represented as the preset k-th candidate convolution kernel, π k (x) represents the attention weight corresponding to the k-th candidate convolutional kernel, and K represents the total number of candidate convolutional kernels; The dynamic bias associated with the input features is obtained by the number of convolution kernels, as shown in Equation (10); (10); Among them, b k Represented as the preset k-th candidate bias term, π k (x) represents the attention weight corresponding to the k-th candidate convolutional kernel, and K represents the total number of candidate convolutional kernels; The constraints that the attention weights satisfy are: ; The dynamic convolutional unit obtains dynamic weights and dynamic biases related to the input features through attention weights, and generates the output y of the dynamic convolution based on the basic feature mapping of the input, as shown in formula (11). y=g(W(x) T *x+b(x))(11); Where x represents the basic feature mapping of the input, W(x) represents the dynamic weight associated with the basic input features, and b(x) represents the dynamic bias associated with the basic input features. In this embodiment, the C2f-Dynamic module performs global average pooling on the basic input features to extract global statistical information of the basic input features. Then, two fully connected layers and a non-linear activation function are used to generate weight coefficients corresponding to multiple candidate convolutional kernels. Finally, the SoftMax function is used to normalize the weight coefficients to obtain the dynamic weights W(x) and dynamic biases b(x) of the candidate convolutional kernels. The C2f-Dynamic module adaptively selects the candidate convolutional kernels through attention weights.
[0040] Through the above structure, the C2f-Dynamic module can adaptively select different combinations of convolution kernels according to the distribution of the current input features, so that the convolution parameters change dynamically with the input content. After the dynamic convolution processing is completed, the dynamic branch output features and the retained branch features are concatenated by channels, and the final result is output through the convolution fusion unit based on the retained branch features and the dynamic branch output features, as shown in formula (12). F out =Conv([F a ,F d ])(12); Among them, F out Represented as the output feature of the C2f-Dynamic module, F a F represents the output feature of the preserved branch. d The dynamic branch output feature is represented by y in the above formula (11), where [ , ] represents the channel dimension splicing; In this way, the C2f-Dynamic module can adaptively emphasize more discriminative feature components during multi-scale feature fusion, thereby improving the detection stability of the model under fish scale changes, pose changes and complex lighting scenarios.
[0041] In step S3, the detection head is an LMBD lightweight multi-branch detection head, which is used to classify, predict the position and orientation of fish targets, and improve the detection stability in scenarios with dense fish, partial occlusion and posture changes while maintaining low computational complexity. The LMBD lightweight multi-branch detection head includes a shared convolutional sequence, a group normalization unit, and a parallel prediction unit. The shared convolutional processing unit performs a unified convolutional transformation on the input feature map and reuses the same set of convolutional parameters in multiple detection paths to reduce the number of parameters and computational overhead caused by redundant convolutional operations, as shown in formula (13). F s =Conv sh (F)(13); Among them, F s Represented as shared convolutional output features, Conv sh () represents the convolution operation, and F represents the input features of the detection head; Since the statistical properties of feature maps at different scales differ, a group normalization unit is introduced after the shared convolution. The group normalization unit standardizes the input features, as shown in formula (14). (14); Where, x n,c,h,w Let w represent the width and h of the bounding box, and c represent the c-th channel of the feature map. Represented as the normalized eigenvalues, μ g σ represents the mean of the features within the corresponding group. g 2 It is represented by the variance of the corresponding group feature, and ε is the preset numerical stability constant; The normalized output can be expressed as: ; Among them, y i This represents the group normalized output, where γ represents the preset learnable scaling parameter and β represents the preset learnable translation parameter. After normalization, the enhanced intermediate features are obtained by SiLU activation function. The activated features are then input into a parallel prediction unit, which includes a classification prediction branch, a bounding box regression branch, and a direction prediction branch.
[0042] In this embodiment, let the feature transformation of the j-th detection branch be H. j (), then the fusion output of the detection head can be expressed as: ; Where P represents the final detection output feature, β j Let F represent the fusion weight of the j-th detection branch, M represent the total number of detection branches, and F represent the fusion weight of the j-th detection branch. s This is represented as shared convolutional output features; For the k-th candidate target, the detection result is... It can be represented as: ; in, This represents the prediction result for the k-th candidate target. This is represented as the target category confidence score. Represented as the x-coordinate of the prediction box. Represented as the ordinate of the predicted bounding box. This is represented as the width of the prediction box. Represented as the height of the predicted bounding box. This represents the rotation angle of the prediction box.
[0043] Based on the output of the detection head, the candidate targets are decoded into oriented bounding boxes to obtain the predicted oriented bounding box set of the fish targets. : ; By combining shared convolution, group normalization, SiLU activation, and multiple output branches, the LMBD detector head can improve the classification, localization, and orientation prediction capabilities of fish targets with lower computational overhead.
[0044] In step S4, the preprocessed fish image frames are input into the model, and supervised learning is performed on the model output based on the annotation results. This allows the model to gradually learn the category features, location features, and orientation features of the fish target. The training process includes forward propagation, loss calculation, and parameter update. The loss term may include category prediction loss, bounding box regression loss, and angle regression loss. The overall loss function can be expressed as: L=λ1L cls +λ2L box +λ L ang ; Among them, L cls Represented as category prediction loss, L box Represented as bounding box regression loss, L ang This is represented as the angle regression loss, where λ1, λ2, and λ3 represent the pre-defined weight coefficients of each loss term. Through the above joint optimization method, it can be ensured that the model can simultaneously complete fish target identification, location localization and orientation estimation. After training, an SDL-Fish fish counting model suitable for complex aquaculture environments is obtained.
[0045] To further reduce the storage overhead and inference latency of the SDL-Fish fish counting model, the LAMP pruning strategy is used to prune and compress the model in step S5 after the model training is completed. The LAMP pruning strategy is a pruning method based on layer adaptive magnitude. Its core idea is to uniformly evaluate the importance of each layer parameter and prioritize the removal of redundant parameters with lower contribution, thereby reducing the model complexity while maintaining detection performance as much as possible. In this embodiment, the LAMP pruning strategy first sorts the weight parameters in the layer to be pruned according to their absolute values. Let the sorted weight parameters be {w1, w2, ..., w...} i If the importance score Si of the i-th parameter is}, then it can be expressed as: ; Among them, w i This represents the i-th weight parameter after sorting, and n represents the total number of parameters in the current layer; In step S5, the LAMP pruning strategy calculates an importance score (score(u;W)) based on the weight of path u, as shown in formula (15). (15); Where W[u] represents the weight of path u, It is represented as the sum of squared weights of path u and its subsequent paths; The above scoring method considers not only the magnitude of the parameter itself but also its cumulative energy relationship in the ranking sequence, thereby achieving a unified and normalized evaluation of the importance of parameters at different layers. Pruning is performed from low to high importance scores. High-importance pruning is performed by deleting the paths corresponding to weight parameters with lower contributions, thus forming a compressed SDL-Fish fish counting model. Compared with the traditional pruning method of setting thresholds independently layer by layer, the LAMP pruning strategy can coordinate the pruning ratio of different layers at a global scale, reducing the over-compression of key feature extraction layers and decision layers. After pruning, the model is fine-tuned to recover some of the performance loss caused by parameter deletion and maintain the detection accuracy of the model in fish detection and counting tasks.
[0046] In step S5, to further reduce the storage overhead and inference latency of the model, the SDL-Fish model is pruned and compressed using the LAMP pruning strategy after training. At the same time, the pruned and compressed SDL-Fish model can be deployed on an edge computing device. In this embodiment, the edge computing device can be an embedded computing platform.
[0047] In step S6, the edge device first receives real-time fish image frames and performs the same preprocessing operation as in the training phase on the fish image frames: X = φ(I); The input tensor is then fed into the backbone network of the SDL-Fish fish computation model, where the StarNet backbone network extracts feature maps at different levels. The shallow features mainly preserve the fish body edges, contours, and local texture information, while the deep features mainly represent the fish body semantic information and discrimination information in complex backgrounds. After fusing the multi-layer features through the C2f-Dynamic module in the neck network, multi-scale fusion features for target detection are obtained. During the detection phase, the LMBD detection head outputs category prediction, location prediction, and orientation prediction results based on multi-scale fusion features. For the k-th candidate target, the prediction result can be expressed as: ; Based on the output of the detection head, the candidate targets are decoded into oriented bounding boxes to obtain the set of predicted oriented bounding boxes for the fish targets: ; In this embodiment, all candidate boxes are first preliminarily filtered based on a confidence threshold, retaining only candidate targets with a confidence level greater than a preset threshold. The preset total number of candidate targets is K, and the preset confidence threshold is τ. The set of retained candidate boxes can then be represented as: ; To reduce the duplicate counting problem caused by overlapping prediction boxes, rotational nonmaximum suppression (RONSS) is further applied to the candidate box set Ω. RONSS filters overlapping candidate boxes based on the rotational intersection-union ratio (ROU) between oriented bounding boxes. For two oriented bounding boxes... Its rotational intersection-union ratio can be expressed as: ; Where RIoU() represents the intersection-union ratio function, and Area() represents the area of the intersection or union region. This is represented as the intersection of two oriented bounding boxes. Represented as the union of two oriented bounding boxes; when When the confidence level exceeds a preset threshold, candidate boxes with lower confidence are deleted. After rotational non-maximum suppression, the final set of detection boxes is obtained. Ω * ; In this embodiment, the fish count result is obtained by counting the number of targets in the final set of detection boxes. If the final number of retained detection boxes is N, the fish count result can be expressed as: ; In this embodiment, detection is performed on a single type of fish target. Therefore, each final retained directional bounding box can correspond to a fish target, thereby realizing the fish count.
[0048] For real-time video stream input scenarios, the above inference, filtering, and counting processes can be performed frame by frame, and the detection results of each frame can be output to the edge device or the host computer interface. To reduce the impact of local occlusion, sudden changes in reflection, or instantaneous detection jitter in individual frames on the counting results, short-term smoothing processing can also be performed on the counting results of consecutive frames.
[0049] Let the current frame count result be N. tThe smoothed counting result is Then it can be expressed as: ; in, This represents the smoothed count result of the previous frame, where α represents the preset smoothing coefficient, and satisfies... 0 < α < 1; t represents the time frame index; Through the above reasoning and post-processing, the SDL-Fish model can achieve real-time detection of fish targets and fish quantity statistics in complex aquaculture environments.
[0050] The working principle of this invention is as follows: First, fish images or video frames from the aquaculture environment are acquired and preprocessed to obtain input features. Simultaneously, fish targets are labeled using five-parameter oriented bounding boxes to construct a sample dataset. Then, an SDL-Fish counting model is constructed based on YOLOv8n. Fish features are extracted in stages through the StarNet backbone network, and a channel increment strategy is adopted to maintain lightweight operation. The C2f-Dynamic module integrates a dynamic convolution mechanism to adaptively generate convolution kernel weights and biases based on the input features. Then, the features are standardized and the prediction results are output through group normalization and SiLu activation function in the LMBD lightweight multi-branch detection head. After training the model with the labeled sample dataset, the LAMP pruning strategy is used to score the importance of each path weight and remove low-contribution weights. Finally, real-time acquired fish images or video streams are input into the deployed model. After confidence filtering and rotation non-maximum suppression processing, low-quality detection boxes are filtered out, thereby statistically analyzing the fish targets and obtaining the final fish counting results.
Claims
1. A lightweight fish counting method based on oriented bounding box, characterized in that: Includes the following steps: S1. Obtain fish image frames in the aquaculture environment, preprocess the fish image frames, and obtain the input features of the fish body; S2. Use directional bounding boxes to annotate the fish targets in the preprocessed fish images. The annotated fish targets are used to construct a fish sample dataset. The directional bounding boxes are used to characterize the position, size and orientation information of the fish targets. The fish size is directionally annotated according to the orientation information. S3. Based on YOLOv8n, construct the SDL-Fish fish counting model. The SDL-Fish fish counting model includes a backbone network, a neck feature fusion network, and a detection head. The backbone network extracts basic features from the input features of the fish body through convolution, nonlinear mapping, and random depth. The neck feature fusion network selects different convolution kernels according to the current distribution of basic features and outputs features after convolution. The detection head is used to detect the output features according to different directional information and output the detection results. S4. Train the SDL-Fish fish counting model using the fish sample dataset to obtain the trained SDL-Fish fish counting model. S5. The trained SDL-Fish fish counting model is compressed using the LAMP pruning strategy to obtain the compressed SDL-Fish fish counting model. S6. Input the real-time acquired fish image frames into the compressed SDL-Fish fish counting model, output the detection results of the fish targets, and obtain the fish counting results based on the output detection results. The detection structure includes category information, orientation bounding box parameters, and orientation parameters.
2. The lightweight fish counting method based on the oriented bounding box according to claim 1, wherein: The oriented bounding box mentioned in step S2 is represented as follows: ; x and y represent the horizontal and vertical coordinates of the oriented bounding box, respectively; w and h represent the width and height of the oriented bounding box, respectively; and θ represents the orientation information of the oriented bounding box, i.e., the rotation angle of the oriented bounding box relative to the horizontal axis. The range of values for the rotation angle is constrained as follows: ; The constraint relationship between w and h is: w ≥ h.
3. The lightweight fish counting method based on the oriented bounding box of claim 1, wherein: The backbone network described in step S3 adopts a StarNet staged hierarchical structure. The input fish sample dataset enters the Stem layer of the backbone network, where the backbone network performs preliminary feature extraction on the fish sample dataset and obtains the Stem layer output feature mapping F based on the fish sample dataset. stem As shown in formula (4), (4); X represents the input fish sample dataset; Conv() represents convolution computation; BN() represents batch normalization operation; ReLU6() represents the activation function that limits the activation values to the range [0,6]. Meanwhile, the backbone network adopts the channel increasing strategy at different stages, and the channel number C of the next stage is obtained through the channel number of each stage and the channel expansion coefficient i+1 As shown in equation (5), (5); wherein C i represents the number of channels of the i-th stage, and a represents a preset channel expansion coefficient.
4. The lightweight fish counting method based on the oriented bounding box of claim 3, wherein: Each stage of the StarNet phased hierarchical structure includes a convolutional layer and a StarBlock module. The StarBlock module maps the input features to different subspaces, performs element-wise multiplication on the features in different subspaces, and then superimposes and fuses the output features of the (l+1)th layer with the original input features. The output features of the (l+1)th layer are calculated based on the input features of the lth layer, as shown in formula (6). (F l+1 =F l +Drop(MLP(Conv(F l )))(6); F l Let F be the input feature of the l-th layer. l+1 This is represented as the output feature of the (l+1)th layer; Represents a multilayer perceptron mapping. This indicates a random depth operation.
5. The lightweight fish counting method based on the oriented bounding box of claim 1, wherein: The neck feature fusion network described in step S3 uses a C2f-Dynamic module. The C2f-Dynamic module integrates a dynamic convolution mechanism on the basis of the C2f structure. Attention weights are obtained through the C2f-Dynamic module, and dynamic weights and dynamic biases related to the input features are obtained through the attention weights. Dynamic convolutions are generated according to the input feature mapping, as shown in formula (11). y = g(W(x) T *x + b(x) (11) x represents the basic feature mapping of the input, W(x) represents the dynamic weights related to the basic features of the input, and b(x) represents the dynamic biases related to the basic features of the input.
6. The lightweight fish counting method based on the oriented bounding box of claim 1, wherein: In step S3, global average pooling is performed on the input basic features through the C2f-Dynamic module to extract global statistical information of the input basic features; then, weight coefficients corresponding to multiple candidate convolution kernels are generated through two fully connected mapping layers and non-linear activation functions; finally, the weight coefficients are normalized through the SoftMax function to obtain the dynamic weights W(x) and dynamic biases b(x) of the candidate convolution kernels. The C2f-Dynamic module adaptively selects the candidate convolution kernels through attention weights.
7. A lightweight fish counting method based on oriented bounding boxes according to claim 1, characterized in that: The detection head mentioned in step S3 is a lightweight multi-branch LMBD detection head, which includes a shared convolutional sequence, a group normalization unit, and a parallel prediction unit. The group normalization unit performs normalization processing on the input features, as shown in formula (14). (14); x n,c,h,w This represents the feature element within the corresponding channel. Represented as the normalized eigenvalues, μ g σ represents the mean of the features within the corresponding group. g 2 ε represents the variance of the features within the corresponding group, and ε represents the numerical stability constant. The standardized input features are mapped by the SiLu activation function and then input into the parallel prediction unit.
8. The lightweight fish counting method based on the oriented bounding box of claim 1, wherein: By assigning importance scores to each weight, the low-contribution weights in the trained SDL-Fish fish counting model are pruned based on the importance score results, resulting in a compressed SDL-Fish fish counting model.
9. The lightweight fish counting method based on the oriented bounding box of claim 8, wherein: The LAMP pruning strategy in step S5 includes: scoring the importance of path u based on its weight, as shown in formula (15). (15); where W[u] denotes the weight of path u, denotes the sum of the square of the weights of path u and its subsequent paths.
10. The lightweight fish counting method based on the oriented bounding box of claim 1, wherein: In step S6, the detection results of the output fish targets are subjected to confidence screening and rotational nonmaximum suppression processing. The fish targets are retained for quantity statistics, and finally the fish count results are obtained.
Citation Information
Patent Citations
Fry counting method and device based on lightweight network
CN114862831A