Crab detection and counting method and device based on instance segmentation, medium and product

By applying the instance segmentation method in aquaculture and using multi-scale feature extraction and fusion modules, the accuracy problem of crab detection and counting in high-density scenes is solved, and accurate detection and counting of crabs are achieved, which is suitable for aquatic products. Modern and intelligent management of breeding.

CN118799716APending Publication Date: 2024-10-18CHINA AGRI UNIV
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202410780883.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-18
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

In high-density aquaculture scenarios, existing computer vision methods based on convolutional neural networks are difficult to quickly and accurately identify and segment crab outlines, causing the accuracy of crab detection and counting to be affected.

Method used

Using a method based on instance segmentation, the pre-trained instance segmentation model includes a multi-scale feature extraction module, a feature fusion module and a detection head, and a new structure of deformable convolution and multi-scale feature fusion is used to accurately detect and detect crabs. segmentation.

Benefits of technology

It achieves accurate detection and counting of crabs, improves detection accuracy and robustness in high-density scenarios, and is suitable for modern and intelligent management of aquaculture.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118799716A_ABST
    Figure CN118799716A_ABST
Patent Text Reader

Abstract

The invention discloses a crab detection and counting method and device based on instance segmentation, a medium and a product, and relates to the technical field of crab detection and counting, a pre-trained instance segmentation model comprises a deformable convolution-based multi-scale feature extraction module, a feature fusion module and a detection head which are connected in sequence, the multi-scale feature extraction module is used for performing feature extraction on the to-be-processed image to obtain multi-scale features, the feature fusion module is used for fusing the multi-scale features to obtain fused features, and the detection head is used for detecting crabs in the to-be-processed image based on the fused features. The pre-trained instance segmentation model is used to detect crabs in the to-be-processed image, the number of crabs in the to-be-processed image is obtained, and accurate detection and counting of crabs can be realized by adopting the pre-trained instance segmentation model of a novel structure in which deformable convolution and multi-scale feature fusion are introduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of crab detection and counting, and in particular to a crab detection and counting method, device, medium and product based on instance segmentation. Background Art

[0002] In aquaculture, crab detection and counting are the key to fishery resource assessment and sustainable development, and can provide scientific and effective guidance for biomass estimation, survival rate analysis and density control in aquaculture. At present, crab detection and counting are mainly carried out by manual visual inspection, which is not only inefficient, but also its accuracy is affected by human subjective factors. Therefore, a non-invasive, fast and accurate crab detection and counting method is particularly important to further accelerate the realization of modernization and intelligent aquaculture.

[0003] Computer vision methods based on convolutional neural networks can detect and track underwater crabs and are widely used in crab behavior analysis, biomass estimation, and anomaly detection. However, in high-density aquaculture scenarios, due to frequent overlap or occlusion of crabs, current computer vision methods based on convolutional neural networks are difficult to quickly and accurately identify and segment crab outlines. Based on this, in the crab detection and counting tasks, how to use machine vision and deep learning methods to accurately detect and segment crabs in multiple postures in order to accurately count crabs is an urgent problem to be solved. Summary of the invention

[0004] The purpose of the present invention is to provide a crab detection and counting method, device, medium and product based on instance segmentation, which can realize accurate detection and counting of crabs.

[0005] To achieve the above object, the present invention provides the following solutions:

[0006] A crab detection and counting method based on instance segmentation, comprising:

[0007] Acquire an image to be processed; the image to be processed includes a plurality of crabs to be counted;

[0008] The image to be processed is taken as input, and crabs in the image to be processed are detected using a pre-trained instance segmentation model to obtain the number of crabs in the image to be processed; the pre-trained instance segmentation model includes a multi-scale feature extraction module based on deformable convolution, a feature fusion module and a detection head connected in sequence; the multi-scale feature extraction module is used to extract features from the image to be processed to obtain multi-scale features; the feature fusion module is used to fuse the multi-scale features to obtain fused features; the detection head is used to detect crabs in the image to be processed based on the fused features.

[0009] In some embodiments, the multi-scale feature extraction module includes a first network layer, a second network layer, a third network layer, a fourth network layer and a fifth network layer connected in sequence; the first network layer and the second network layer are both CBL modules; the third network layer, the fourth network layer and the fifth network layer all include a CBL module, a DConv-C2f module and a CBL module connected in sequence; the DConv-C2f module is obtained by replacing the convolution layer in the C2f module with a deformable convolution layer; the first scale feature output by the third network layer, the second scale feature output by the fourth network layer and the third scale feature output by the fifth network layer constitute the multi-scale feature;

[0010] The feature fusion module includes a first fusion layer, a second fusion layer, a third fusion layer, a fourth fusion layer and a fifth fusion layer; the input end of the first fusion layer is respectively connected to the third network layer and the fourth network layer, and the first scale feature and the second scale feature are fused through the first fusion layer to obtain a first fusion feature; the input end of the second fusion layer is respectively connected to the fourth network layer, the fifth network layer and the first fusion layer, and the second scale feature, the third scale feature and the first fusion feature are fused through the second fusion layer to obtain a second fusion feature; the input end of the third fusion layer is respectively connected to the fifth network layer and the second fusion layer, and the The third scale feature and the second fusion feature are fused through the third fusion layer to obtain a third fusion feature; the input end of the fourth fusion layer is connected to the second fusion layer and the third fusion layer respectively, and the second fusion feature and the third fusion feature are fused through the fourth fusion layer to obtain a fourth fusion feature; the input end of the fifth fusion layer is connected to the first fusion layer, the second fusion layer and the fourth fusion layer respectively, and the first fusion feature, the second fusion feature and the fourth fusion feature are fused through the fifth fusion layer to obtain a fifth fusion feature; the third fusion feature, the fourth fusion feature and the fifth fusion feature constitute the fused feature;

[0011] The detection head includes an attention module, a first decoupling detector, a second decoupling detector, a fusion unit and a mask extractor; the output end of the attention module is respectively connected to the input end of the first decoupling detector, the input end of the second decoupling detector and the input end of the mask extractor; the output end of the first decoupling detector and the output end of the second decoupling detector are both connected to the input end of the fusion unit; the attention module is used to process the third fusion feature, the fourth fusion feature and the fifth fusion feature respectively to obtain a first processed feature, a second processed feature and a third processed feature; the first decoupling detector is used to generate a first target bounding box based on the first processed feature; the second decoupling detector is used to generate a second target bounding box based on the second processed feature; the fusion unit is used to fuse the first target bounding box and the second target bounding box to obtain a target bounding box, each of which includes a crab; the mask extractor is used to generate a target mask based on the third processed feature, and each of the target masks corresponds to one target bounding box.

[0012] In some embodiments, the first fusion layer, the second fusion layer, the third fusion layer, the fourth fusion layer and the fifth fusion layer all include a first Concat layer, a first branch, a second branch and a second Concat layer; the output end of the first Concat layer is respectively connected to the input end of the first branch and the input end of the second branch; the output end of the first branch and the output end of the second branch are both connected to the input end of the second Concat layer;

[0013] The first branch includes a 1×1 convolution block; the second branch includes a 1×1 convolution block and a plurality of 3×3 convolution blocks connected in sequence.

[0014] In some embodiments, before taking the image to be processed as input and using a pre-trained instance segmentation model to detect crabs in the image to be processed to obtain the number of crabs in the image to be processed, the method further includes:

[0015] Acquire a data set; the data set includes a plurality of sample images to be processed and a label corresponding to each of the sample images to be processed; the label is a target bounding box and a target mask of each crab in the sample images to be processed;

[0016] Build an initial instance segmentation model;

[0017] Based on the loss function, the initial instance segmentation model is trained using the data set to obtain a pre-trained instance segmentation model; the loss function includes crab classification loss, bounding box regression loss, mask loss and bounding box distribution focus loss.

[0018] In some embodiments, obtaining a data set specifically includes:

[0019] Taking multiple shots of several crabs in different postures to obtain multiple images;

[0020] Preprocessing each of the captured images to obtain a plurality of sample images to be processed; the preprocessing includes at least one of image cropping, image rotation, image mirroring, image denoising and image enhancement;

[0021] The crabs in each of the sample images to be processed are labeled to obtain a label corresponding to the sample image to be processed; all of the sample images to be processed and the label corresponding to each of the sample images to be processed constitute a data set.

[0022] In some embodiments, the crab classification loss adopts VariFocal Loss; the bounding box regression loss adopts Wise IoU; the mask loss adopts Binary Cross Entropy Loss; and the bounding box distribution focal loss adopts DistributionFocal Loss.

[0023] A computer device comprises: a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-mentioned crab detection and counting method based on instance segmentation.

[0024] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the above-mentioned crab detection and counting method based on instance segmentation.

[0025] A computer program product comprises a computer program, which implements the steps of the above-mentioned crab detection and counting method based on instance segmentation when executed by a processor.

[0026] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:

[0027] The present invention provides a crab detection and counting method, device, medium and product based on instance segmentation. The pre-trained instance segmentation model comprises a multi-scale feature extraction module based on deformable convolution, a feature fusion module and a detection head which are connected in sequence. The multi-scale feature extraction module is used to extract features of a to-be-processed image to obtain multi-scale features. The feature fusion module is used to fuse the multi-scale features to obtain fused features. The detection head is used to detect crabs in the to-be-processed image based on the fused features. Thus, the pre-trained instance segmentation model is used to detect crabs in the to-be-processed image to obtain the number of crabs in the to-be-processed image. By adopting the pre-trained instance segmentation model with a novel structure introducing deformable convolution and multi-scale feature fusion, accurate detection and counting of crabs can be achieved. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0029] Figure 1 A schematic diagram of a method flow of a crab detection and counting method based on instance segmentation provided in Example 1 of the present invention.

[0030] Figure 2 A schematic diagram of the deployment of high-definition cameras provided in Example 1 of the present invention.

[0031] Figure 3 A schematic diagram of the network structure of the pre-trained instance segmentation model provided in Example 1 of the present invention.

[0032] Figure 4 A schematic diagram of the network structure of a multi-scale feature extraction module based on deformable convolution provided in Example 1 of the present invention.

[0033] Explanation of symbols:

[0034] 1-HD camera; 2-Edge computing terminal. DETAILED DESCRIPTION

[0035] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0036] The purpose of the present invention is to provide a crab detection and counting method, device, medium and product based on instance segmentation, which can realize accurate detection and counting of crabs.

[0037] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0038] Example 1

[0039] like Figure 1 As shown, a crab detection and counting method based on instance segmentation in this embodiment includes:

[0040] S1: Acquire an image to be processed; the image to be processed includes a plurality of crabs to be counted.

[0041] This embodiment can detect and count multiple crabs in the river crab breeding box, such as Figure 2 As shown, at this time, the image acquisition system is set in the river crab breeding box, which is a rectangular parallelepiped with a diameter of 3 meters and a height of 1.5 meters. In order to avoid unnecessary crab occlusion, a high-definition camera 1 with a frame rate of 25fps (1920*1080) is set in each river crab breeding box. The high-definition camera 1 is deployed at a height of about 2 meters in the river crab breeding box, which is equivalent to being deployed on the top of the river crab breeding box, so that the high-definition camera 1 can shoot the crabs in the river crab breeding box from the top, that is, the image acquisition system can use a high-definition camera 1 with a frame rate of 25fps (1920*1080), which is installed on the top of the river crab breeding box, and shoots the crabs in the river crab breeding box from the top. The video captured by the high-definition camera 1 is stored in the memory card of the high-definition camera 1, and is regularly downloaded from the memory card to the computer to obtain the image to be processed. This embodiment also includes an edge computing terminal 2, which is connected to the high-definition camera 1 in communication, and is used to obtain the image to be processed obtained by the high-definition camera 1, execute the crab detection and counting method of this embodiment, and obtain the number of crabs. Since the shooting was carried out in the actual factory area, the occlusion and reflection of light on the water surface in the image data to be processed also need to be taken into account.

[0042] S2: Taking the image to be processed as input, using a pre-trained instance segmentation model to detect crabs in the image to be processed to obtain the number of crabs in the image to be processed; the pre-trained instance segmentation model includes a multi-scale feature extraction module based on deformable convolution, a feature fusion module and a detection head connected in sequence; the multi-scale feature extraction module is used to extract features from the image to be processed to obtain multi-scale features; the feature fusion module is used to fuse the multi-scale features to obtain fused features; the detection head is used to detect crabs in the image to be processed based on the fused features.

[0043] The target detection and segmentation model is particularly dependent on computer performance. It is of great practical significance to build a lightweight and real-time multi-posture crab detection and counting model. In order to achieve this goal, this embodiment designs an instance segmentation model based on the improvement of YOLOv8. A feature fusion module is introduced into the instance segmentation model to fuse multi-scale features. By selecting a lightweight YOLOv8 architecture as the basis and designing an efficient feature fusion module, the model parameters and computational complexity are reduced to build a lightweight and real-time instance segmentation model. Subsequently, the pre-trained instance segmentation model is used to detect crabs in the image to be processed, so as to count the crabs in the image to be processed, thereby obtaining the number of crabs in the image to be processed.

[0044] like Figure 3 As shown, the pre-trained instance segmentation model used in this embodiment includes a multi-scale feature extraction module based on deformable convolution, a feature fusion module and a detection head which are connected in sequence. The multi-scale feature extraction module is used to extract features from the input image to obtain multi-scale features. The feature fusion module is used to fuse the multi-scale features to obtain fused features. The detection head is used to detect crabs based on the fused features.

[0045] The multi-scale feature extraction module of this embodiment is a feature extraction network based on deformable convolution, which is a feature extraction network obtained by improving YOLOv8. The multi-scale feature extraction module includes a first network layer P1, a second network layer P2, a third network layer P3, a fourth network layer P4 and a fifth network layer P5 connected in sequence. The first scale feature output by the third network layer, the second scale feature output by the fourth network layer and the third scale feature output by the fifth network layer constitute the multi-scale feature output by the multi-scale feature extraction module.

[0046] The first network layer and the second network layer are both CBL modules, which include a convolutional layer (Conv), a batch normalization layer (BN), and a Sigmoid linear activation function layer (SiLU) connected in sequence.

[0047] like Figure 4As shown, the third network layer, the fourth network layer and the fifth network layer each include a CBL module, a DConv-C2f module and a CBL module connected in sequence. The CBL module includes a convolutional layer (Conv), a batch normalization layer (BN) and a Sigmoid linear activation function layer (SiLU) connected in sequence. The DConv-C2f module is obtained by replacing the convolution layer in the C2f module with a deformable convolution layer (DConv). Specifically, the convolution layer in the Bottleneck in the lightweight C2f module in the YOLOv8 network is replaced with a deformable convolution layer to obtain a Bottleneck-DConv. The DConv-C2f module includes N Bottleneck-DConvs connected in sequence. At this time, in the DConv-C2f module, the feature map output by the CBL module before the DConv-C2f module is separated by Split and flows into the Concat layer and multiple Bottleneck-DConvs respectively. Multiple gradient flow information (i.e., the feature map output by the CBL module before the DConv-C2f module and the feature map output by each Bottleneck-DConv) is fused through the Concat layer.

[0048] DConv adds offsets and weights to make the sampling closer to the size and shape of crabs. The offset is obtained by adding a convolution kernel with the same spatial resolution and expansion as the current layer to the input feature map and performing convolution learning. For the output feature map F of DConv, each position x0 satisfies the following formula:

[0049]

[0050] In formula (1), x0 represents each position on the input feature map I; x n Indicates the location of the enumeration R; R indicates the size and expansion of the receptive field; w indicates the sampling weight; Δx n Indicates the offset; Δm n Represents the modulation scalar.

[0051] The multi-scale feature extraction module of this embodiment is provided with a DConv-C2f module, which is composed of a lightweight C2f module and DConv in the YOLOv8 network. Specifically, DConv is added to the C2f module, and multiple gradient flow branches are superimposed and multiple gradient flow information is fused through the Concat layer, thereby enhancing the receptive field and feature expression ability of the network, so that the multi-scale feature extraction module can better capture the feature information of the target (i.e., crabs) at different scales, thereby improving the accuracy and robustness of crab detection.

[0052] The feature fusion module (i.e. Figure 3 The feature fusion layer in ( ) is an efficient feature fusion network that can enhance feature expression. The feature fusion module includes a first fusion layer, a second fusion layer, a third fusion layer, a fourth fusion layer and a fifth fusion layer. The input end of the first fusion layer is connected to the third network layer and the fourth network layer respectively. The first scale feature output by the third network layer and the second scale feature output by the fourth network layer are fused through the first fusion layer to obtain the first fusion feature. The input end of the second fusion layer is connected to the fourth network layer, the fifth network layer and the first fusion layer respectively. The second scale feature output by the fourth network layer, the third scale feature output by the fifth network layer and the first fusion feature output by the first fusion layer are fused through the second fusion layer to obtain the second fusion feature. The input end of the third fusion layer is connected to the fifth network layer and the second fusion layer respectively. The third scale feature output by the fifth network layer and the second fusion feature output by the second fusion layer are fused through the third fusion layer to obtain the third fusion feature. The input end of the fourth fusion layer is connected to the second fusion layer and the third fusion layer respectively. The second fusion feature output by the second fusion layer and the third fusion feature output by the third fusion layer are fused through the fourth fusion layer to obtain the fourth fusion feature. The input end of the fifth fusion layer is connected to the first fusion layer, the second fusion layer and the fourth fusion layer respectively, and the first fusion feature output by the first fusion layer, the second fusion feature output by the second fusion layer and the fourth fusion feature output by the fourth fusion layer are fused through the fifth fusion layer to obtain the fifth fusion feature. The third fusion feature, the fourth fusion feature and the fifth fusion feature constitute the fused feature output by the feature fusion module.

[0053] Each fusion layer (i.e. Figure 3 The multi-scale fusion module in the above example is divided into two gradient flow branches. Each gradient flow branch passes through a 1*1 convolution block to reduce the number of channels. The 1*1 convolution block includes a convolution layer, a batch normalization layer, and a Relu linear activation function layer. One of the gradient flow branches will pass through N stacked 3*3 convolution blocks. Finally, the features obtained by the two gradient flow branches are fused using the Concat layer to obtain the final fused feature map (i.e., fused features).

[0054] The first fusion layer, the second fusion layer, the third fusion layer, the fourth fusion layer and the fifth fusion layer all include the first Concat layer, the first branch, the second branch and the second Concat layer. The input end of the first Concat layer is the input end of the multi-scale fusion module. The output end of the first Concat layer is respectively connected to the input end of the first branch and the input end of the second branch. The output end of the first branch and the output end of the second branch are both connected to the input end of the second Concat layer. The output end of the second Concat layer is the output end of the multi-scale fusion module.

[0055] The first branch includes a 1×1 convolution block, which includes a 1×1 convolution layer (Conv), a batch normalization layer (BN), and an activation function layer (Relu) connected in sequence.

[0056] The second branch includes a 1×1 convolution block and several 3×3 convolution blocks connected in sequence, specifically including a 1×1 convolution block, a Rep 3×3 convolution block and several 3×3 convolution blocks connected in sequence, the 1×1 convolution block includes a 1×1 convolution layer (Conv), a batch normalization layer (BN) and an activation function layer (Relu) connected in sequence, the Rep 3×3 convolution block includes a 3×3 convolution layer (Conv) and a batch normalization layer (BN) connected in sequence during model training, the Rep 3×3 convolution block includes a 1×1 convolution layer (Conv) and a batch normalization layer (BN) during model inference, and the 3×3 convolution block includes a 3×3 convolution layer (Conv), a batch normalization layer (BN) and an activation function layer (Relu) connected in sequence.

[0057] The feature fusion module of this embodiment is a feature pyramid network that takes into account both speed and accuracy, and is used to fuse multi-scale features of the previous network layer and the current network layer. The feature fusion module uses five fusion layers to fuse feature information of corresponding scales of the third network layer P3, the fourth network layer P4 and the fifth network layer P5, including cross-layer and cross-scale connections, and fuses features through an efficient layer aggregation network structure to obtain richer feature information. The output of each layer in the feature pyramid has feature information of different scales, and it allows the number of channels of feature maps of different scales to be controlled.

[0058] The detection head of this embodiment is a detection head with an attention mechanism, and the detection head includes an attention module, a first decoupling detector, a second decoupling detector, a fusion unit and a mask extractor. The input end of the attention module is the input end of the detection head, the output end of the attention module is respectively connected to the input end of the first decoupling detector, the input end of the second decoupling detector and the input end of the mask extractor, and the output end of the first decoupling detector and the output end of the second decoupling detector are both connected to the input end of the fusion unit. The attention module is used to process the third fusion feature, the fourth fusion feature and the fifth fusion feature respectively to obtain the first processed feature, the second processed feature and the third processed feature, the first decoupling detector is used to generate a first target bounding box based on the first processed feature, the second decoupling detector is used to generate a second target bounding box based on the second processed feature, the fusion unit is used to fuse the first target bounding box and the second target bounding box to obtain a target bounding box, each target bounding box includes a crab, and the mask extractor is used to generate a target mask based on the third processed feature, and each target mask corresponds to a target bounding box.

[0059] In order to improve the feature extraction capability of the detection head, an attention module is designed in this embodiment. The attention mechanism in the attention module can adopt Sqneeze and Excitation Module (SE), which can reduce the computational complexity of the model as much as possible when introducing the model due to its fast and efficient computing performance, and improve the inference time.

[0060] The decoupled detector (i.e., the first decoupled detector and the second decoupled detector) can separate regression parameters and classification parameters, which are used to improve the performance of the end-to-end detector (i.e., the pre-trained instance segmentation model) and accelerate the model convergence speed. The decoupled detector includes a classification branch, a regression branch, and a bounding box extraction branch. The classification branch, the regression branch, and the bounding box extraction branch all include a 1×1 convolution layer, two 3×3 convolution layers, and a 1×1 convolution layer connected in sequence. The classification branch is used to identify crabs, that is, to determine whether it is background or crab, and obtain crab recognition results. The regression branch is used to predict the position of the target bounding box, and the bounding box extraction branch is used to predict the position of the target bounding box. Among them, the position of the target bounding box can be represented by the center coordinates, width, and height of the target bounding box.

[0061] The fusion unit is used to calculate the average value of the crab recognition result of the classification branch of the first decoupling detector and the crab recognition result of the classification branch of the second decoupling detector to obtain the crab recognition result. The fusion unit is also used to calculate the target bounding box position prediction result of the regression branch of the first decoupling detector, the target bounding box position prediction result of the bounding box extraction branch of the first decoupling detector, the target bounding box position prediction result of the regression branch of the second decoupling detector, and the target bounding box position prediction result of the bounding box extraction branch of the second decoupling detector to obtain the target bounding box position prediction result. It should be noted that during model training, the crab recognition result output by the fusion unit will be used to calculate the total loss. During model inference, the crab recognition result output by the fusion unit can be directly ignored.

[0062] The mask extractor adopts a prototype network.

[0063] The detection head of this embodiment includes two decoupled detectors and a mask extractor, the two decoupled detectors are used to generate target bounding boxes, and the mask extractor is used to generate target masks. The number of crabs is determined by counting the number of target bounding boxes or the number of target masks to obtain the final output counting result.

[0064] The pre-trained instance segmentation model used in this embodiment relates to a framework that integrates deformable convolution, efficient feature fusion, attention mechanism and decoupling detector. An efficient and lightweight DConv is introduced into the multi-scale feature extraction module of the pre-trained instance segmentation model, that is, DConv is added to enhance the C2f module, thereby improving the accuracy of crab segmentation in dense space transformation. An efficient feature fusion module that integrates multi-scale feature information is introduced into the pre-trained instance segmentation model, and an efficient feature pyramid is used to aggregate feature maps of different scales with context information. The instance segmentation accuracy is improved by enhancing the representation of feature information. A detection head with an attention mechanism is designed to detect and segment crabs in real time. An attention module is added between the efficient feature pyramid network and the decoupling detector to improve the perception of the region of interest, thereby enabling accurate detection and counting of crabs in aquaculture scenarios.

[0065] Before the image to be processed is used as input and the crabs in the image to be processed are detected using the pre-trained instance segmentation model to obtain the number of crabs in the image to be processed, the crab detection and counting method of this embodiment further includes:

[0066] (1) Obtain a data set, where the data set includes a plurality of sample images to be processed and a label corresponding to each sample image to be processed, where the label is a target bounding box and a target mask of each crab in the sample image to be processed.

[0067] The dataset construction includes video acquisition, image preprocessing and image annotation. Image annotation refers to the crab instances in the annotated image. Video acquisition is to shoot the crabs in the river crab breeding box from the top of the river crab breeding box through a high-definition camera 1 with a frame rate of 25fps (1920*1080). The obtained video is stored in the memory card of the high-definition camera 1. The video shot by the high-definition camera 1 can be obtained in real time by connecting to the high-definition camera 1 through a wired network to obtain the captured image. Image preprocessing includes cropping, rotating, mirroring, Gaussian denoising and image enhancement of the captured image to obtain the sample image to be processed. Data annotation is performed on the sample image to be processed. Manual annotation can be assisted by software such as Labelme to annotate the crab contour and complete the pixel-level annotation of the crab instance in the image. The annotation file obtained by annotation stores the object category (i.e., crab), image size, target bounding box and target mask required in the instance segmentation task in the form of a dictionary. The target bounding box is the bounding box surrounding the target. The target mask is a binary sequence corresponding to the bounding box surrounding the target, representing the bounding box surrounding the target.

[0068] Then, a data set is obtained, specifically including: photographing a number of crabs in different postures for multiple times to obtain a number of photographed images; preprocessing each photographed image to obtain a number of sample images to be processed, wherein the preprocessing includes at least one of image cropping, image rotation, image mirroring, image denoising and image enhancement; labeling the crabs in each sample image to be processed to obtain a label corresponding to the sample image to be processed, and all the sample images to be processed and the label corresponding to each sample image to be processed constitute a data set.

[0069] (2) Build an initial instance segmentation model.

[0070] In this embodiment, the structure of the initial instance segmentation model is the same as that of the pre-trained instance segmentation model.

[0071] (3) Based on the loss function, the dataset is used to train the initial instance segmentation model to obtain a pre-trained instance segmentation model. The loss functions include crab classification loss, bounding box regression loss, mask loss, and bounding box distribution focus loss.

[0072] The data set produced in this embodiment can be divided into a training set and a validation set with a division ratio of 7:3. The training set is used to train the model, and the validation set is used to evaluate the performance of the model.

[0073] The initial instance segmentation model is trained using the data set to obtain a pre-trained instance segmentation model, specifically including: using the data set to train the initial instance segmentation model to obtain a trained model, calculating the total loss of the trained model based on the loss function, if the total loss is less than a preset value, ending the iteration and using the trained model as the pre-trained instance segmentation model, otherwise, continuing the iteration and using the trained model as the initial instance segmentation model of the next iteration.

[0074] In this embodiment, the loss function used in model training includes the crab classification loss L cls , bounding box regression loss L box , mask loss L mask and the bounding box distribution focal loss L dfl , the loss function is defined as follows:

[0075]

[0076] In formula (2), Loss is the total loss; λ, ω,μ are the crab classification loss L cls , bounding box regression loss L bos , mask loss L mask and the bounding box distribution focal loss L dfl The weight coefficient of the weight coefficient can be customized according to user needs. As an example, λ, ω,μ are set to 0.5, 7.5, 3.75, and 1.5, respectively.

[0077] In this embodiment, the crab classification loss can use VariFocal Loss, the bounding box regression loss can use WiseIoU, the mask loss can use Binary Cross Entropy Loss, and the bounding box distribution focal loss can use Distribution Focal Loss, that is, L cls is the VariFocal Loss (VFL) for semantic classification, L box is the Wise IoU (WIoU) for bounding box prediction, L mask is the Binary Cross Entropy Loss (BCELoss) for mask prediction, L dfl It is the Distribution Focal Loss (DFL) for bounding box position optimization.

[0078] VFL is defined as follows:

[0079]

[0080] In formula (3), p represents the confidence of the target category predicted by the model, that is, the probability that the model believes that an object belongs to the target category (crab); q represents the true confidence, which is used to measure the calibration of the model prediction and is determined according to the label; α represents the adjustable scaling factor added to the negative loss term to solve the problem of unbalanced sample distribution; γ represents the adjustable focus parameter, which controls the attention to error-prone samples (samples whose confidence of the target category predicted by the model is close to 0 or 1).

[0081] WIoU is defined as follows:

[0082]

[0083] In formula (4), x and y represent the center coordinates of the predicted target bounding box respectively; gt and gt Respectively represent the center coordinates of the real target bounding box, determined according to the label; W g and H g They represent the width and height of the predicted minimum target bounding box, respectively. The superscript * indicates that it is separated from the computational graph (i.e., the image output by the pre-trained instance segmentation model).

[0084] BCE Loss is defined as follows:

[0085]

[0086] In formula (5), N represents the total number of target masks included in an image; y i represents the true label value of the i-th target mask, determined according to the label; It represents the confidence of the i-th target mask predicted by the model, and the probability that the model considers the i-th target mask to be the true target mask.

[0087] DFL is defined as follows:

[0088] L dfl =-((y i+1 -y)log(P i )+(yy i )log(P i+1 )); (6)

[0089] In formula (6), y i+1 and i All belong to {y0,y1,...y n},{y0,y1,...y n} represent the discretized coordinate values ​​of the predicted target bounding box; y represents the corresponding coordinate value in the real target bounding box, which is determined according to the label; P i Represents the i-th coordinate value y in the target bounding box predicted by the model i The probability of the i-th coordinate value belonging to the true target bounding box; P i+1 Represents the i+1th coordinate value y in the target bounding box predicted by the model i+1 The probability of the i+1th coordinate value belonging to the true target bounding box.

[0090] This embodiment can also use a validation set to evaluate model performance, specifically using mean absolute error (MAE) and root mean square error (RMSE) as evaluation indicators. MAE measures model accuracy by calculating the average error between the predicted value and the true value, and RMSE measures model accuracy by calculating the deviation between the predicted value and the true value. MAE and RMSE are defined as follows:

[0091]

[0092]

[0093] In the above formula, N is the number of sample images to be processed; x i represents the true value of the number of crabs in the i-th sample to be processed image; Represents the predicted value of the number of crabs in the i-th sample to be processed image.

[0094] The present embodiment provides a crab detection and counting method based on instance segmentation, which relates to the field of aquaculture, obtains crab image data, uses a dynamic convolutional neural network (i.e., a multi-scale feature extraction module) that adaptively optimizes the convolution scale and the perception field size to extract multi-scale features of crabs in different postures, and realizes the fusion of multi-scale feature information through an efficient feature fusion module that fuses multi-scale feature information. The target bounding box and target mask of the target are predicted from the image region of interest through a detection head with an attention module, and the number of crabs in the image is estimated according to the result of instance segmentation. The multi-scale feature information of crabs in multiple postures and the fusion of multi-scale feature information are extracted through a dynamic convolutional neural network, and a lightweight neural network model is used to improve the accuracy and real-time performance of crab detection and counting. The method can be deployed in an actual production environment, and provides an intelligent tool for crab biomass estimation in factory farming, and can realize all-weather and full-process intelligent farming management of crab farming.

[0095] Example 2

[0096] A computer device comprises: a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of a crab detection and counting method based on instance segmentation described in Example 1.

[0097] Example 3

[0098] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of a crab detection and counting method based on instance segmentation described in embodiment 1.

[0099] Example 4

[0100] A computer program product includes a computer program, which, when executed by a processor, implements the steps of a crab detection and counting method based on instance segmentation described in embodiment 1.

[0101] Example 5

[0102] A computer device, which may be a database. The computer device includes a processor, a memory, an input / output interface (I / O for short) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store pending transactions. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a crab detection and counting method based on instance segmentation in Example 1 is implemented.

[0103] It should be noted that the object information (including but not limited to object device information, object personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the present invention are all information and data authorized by the object or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.

[0104] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided by the present invention can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided by the present invention may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited thereto. The processor involved in each embodiment provided by the present invention may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited thereto.

[0105] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, 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.

[0106] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of ​​the present invention. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A crab detection and counting method based on instance segmentation, It is characterized in that include: Get the image to be processed; The image to be processed includes a plurality of crabs to be counted; The image to be processed is taken as input, and crabs in the image to be processed are detected using a pre-trained instance segmentation model to obtain the number of crabs in the image to be processed; the pre-trained instance segmentation model includes a multi-scale feature extraction module based on deformable convolution, a feature fusion module and a detection head connected in sequence; the multi-scale feature extraction module is used to extract features from the image to be processed to obtain multi-scale features; the feature fusion module is used to fuse the multi-scale features to obtain fused features; the detection head is used to detect crabs in the image to be processed based on the fused features.

2. The crab detection and counting method based on instance segmentation according to claim 1, It is characterized in that The multi-scale feature extraction module includes a first network layer, a second network layer, a third network layer, a fourth network layer and a fifth network layer connected in sequence; the first network layer and the second network layer are both CBL modules; the third network layer, the fourth network layer and the fifth network layer all include a CBL module, a DConv-C2f module and a CBL module connected in sequence; the DConv-C2f module is obtained by replacing the convolution layer in the C2f module with a deformable convolution layer; the first scale feature output by the third network layer, the second scale feature output by the fourth network layer and the third scale feature output by the fifth network layer constitute the multi-scale feature; The feature fusion module includes a first fusion layer, a second fusion layer, a third fusion layer, a fourth fusion layer and a fifth fusion layer; the input end of the first fusion layer is connected to the third network layer and the fourth network layer respectively, and the first scale feature and the second scale feature are fused through the first fusion layer to obtain a first fusion feature; The input end of the second fusion layer is respectively connected to the fourth network layer, the fifth network layer and the first fusion layer, and the second scale feature, the third scale feature and the first fusion feature are fused through the second fusion layer to obtain a second fusion feature; the input end of the third fusion layer is respectively connected to the fifth network layer and the second fusion layer, and the third scale feature and the second fusion feature are fused through the third fusion layer to obtain a third fusion feature; The input end of the fourth fusion layer is connected to the second fusion layer and the third fusion layer respectively, and the second fusion feature and the third fusion feature are fused through the fourth fusion layer to obtain a fourth fusion feature; The input end of the fifth fusion layer is connected to the first fusion layer, the second fusion layer and the fourth fusion layer respectively, the first fusion feature, the second fusion feature and the fourth fusion feature are fused through the fifth fusion layer to obtain a fifth fusion feature; the third fusion feature, the fourth fusion feature and the fifth fusion feature constitute the fused feature; The detection head includes an attention module, a first decoupling detector, a second decoupling detector, a fusion unit and a mask extractor; the output end of the attention module is respectively connected to the input end of the first decoupling detector, the input end of the second decoupling detector and the input end of the mask extractor; the output end of the first decoupling detector and the output end of the second decoupling detector are both connected to the input end of the fusion unit; the attention module is used to process the third fused feature, the fourth fused feature and the fifth fused feature respectively to obtain a first processed feature, a second processed feature and a third processed feature; The first decoupled detector is used to generate a first object bounding box based on the first processed features; The second decoupled detector is used to generate a second target bounding box based on the second processed feature; the fusion unit is used to fuse the first target bounding box and the second target bounding box to obtain a target bounding box, each of which includes a crab; the mask extractor is used to generate a target mask based on the third processed feature, each of which corresponds to a target bounding box.

3. The crab detection and counting method based on instance segmentation according to claim 2, It is characterized in that The first fusion layer, the second fusion layer, the third fusion layer, the fourth fusion layer and the fifth fusion layer all include a first Concat layer, a first branch, a second branch and a second Concat layer; the output end of the first Concat layer is respectively connected to the input end of the first branch and the input end of the second branch; the output end of the first branch and the output end of the second branch are both connected to the input end of the second Concat layer; The first branch includes a 1×1 convolution block; the second branch includes a 1×1 convolution block and a plurality of 3×3 convolution blocks connected in sequence.

4. The crab detection and counting method based on instance segmentation according to claim 2, It is characterized in that Before taking the image to be processed as input and detecting crabs in the image to be processed using a pre-trained instance segmentation model to obtain the number of crabs in the image to be processed, the method further includes: Acquire a data set; the data set includes a plurality of sample images to be processed and a label corresponding to each of the sample images to be processed; the label is a target bounding box and a target mask of each crab in the sample images to be processed; Build an initial instance segmentation model; Based on the loss function, the initial instance segmentation model is trained using the data set to obtain a pre-trained instance segmentation model; the loss function includes crab classification loss, bounding box regression loss, mask loss and bounding box distribution focus loss.

5. The crab detection and counting method based on instance segmentation according to claim 4, It is characterized in that Get the dataset, including: Taking multiple shots of several crabs in different postures to obtain multiple images; Preprocessing each of the captured images to obtain a plurality of sample images to be processed; the preprocessing includes at least one of image cropping, image rotation, image mirroring, image denoising and image enhancement; The crabs in each of the sample images to be processed are labeled to obtain a label corresponding to the sample image to be processed; all of the sample images to be processed and the label corresponding to each of the sample images to be processed constitute a data set.

6. The crab detection and counting method based on instance segmentation according to claim 4, It is characterized in that The crab classification loss adopts VariFocal Loss; the bounding box regression loss adopts Wise IoU; the mask loss adopts Binary Cross Entropy Loss; and the bounding box distribution focal loss adopts Distribution FocalLoss.

7. A computer device, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of a crab detection and counting method based on instance segmentation as described in any one of claims 1 to 6.

8. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the crab detection and counting method based on instance segmentation described in any one of claims 1 to 6 are implemented.

9. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the crab detection and counting method based on instance segmentation described in any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Underwater crab quality nonlinear estimation method, system, equipment, medium and product

    CN119762464A

  • Fish detection method, device and equipment based on underwater robot and storage medium

    CN120108003A

  • Fish detection methods, devices, equipment, and storage media based on underwater robots

    CN120108003B

  • Deep learning-based pedestrian image target detection method, system and device, and storage medium

    CN120496173A

  • Deep learning-based pedestrian image target detection method, system, device and storage medium

    CN120496173B