Improved YOLOv8 fish image recognition method based on transfer learning

By adopting the improved YOLOv8 method based on transfer learning in fish image recognition technology, a specific convolution module and attention mechanism are introduced, and combined with multiple loss functions, the problem of existing technology's large dependence on computing resources and sensitivity to lighting changes is solved. Achieve more efficient and robust fish image recognition.

CN119445348AInactive Publication Date: 2025-02-14SHAOXING CAOEJIANG DAZHA INVESTMENT DEV CO LTD +2
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202411438377.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-15
Publication Date
2025-02-14
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing fish image recognition technology is highly dependent on computing resources and is sensitive to background noise and light changes, affecting the stability and accuracy of recognition.

Method used

Using the improved YOLOv8 method based on transfer learning, the backbone network and neck network are optimized by introducing SPD convolution module, Ghost module, global attention module and variable kernel convolution module, and combined with multiple loss functions, the model is pre-trained and optimized. Parameter training.

Benefits of technology

It improves the accuracy of feature extraction and recognition, reduces the demand for computing resources, enhances the robustness and adaptability of the model, significantly improves the learning efficiency and recognition accuracy, and reduces data dependence.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119445348A_ABST
    Figure CN119445348A_ABST
Patent Text Reader

Abstract

The invention discloses an improved YOLOv8 fish image recognition method based on transfer learning, and the method comprises the following steps: collecting a fish image data set, and carrying out the preprocessing of the data set; correspondingly marking category names on the fish image data set according to fish categories, and dividing the fish image data set into a training set, a verification set and a test set in proportion; a standard YOLOv8 model is improved; all fish images in the ImageNet data set are adopted to pre-train the improved YOLOv8 model, and obtained weight parameters are migrated to the model; performing optimization parameter training on the improved YOLOv8 model after transfer learning by using the training set and the verification set; and performing target detection on the test set through the optimized improved YOLOv8 model, and outputting a fish identification result. According to the method, the feature extraction and recognition precision is effectively improved, the computing resource demand is reduced, and the robustness and adaptability of the model are enhanced; according to the method, the learning efficiency and the recognition precision of the model are remarkably improved, data dependence is reduced, and the model has high generalization ability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the research field of fish identification and detection, and in particular to an improved YOLOv8 fish image recognition method based on transfer learning. Background Art

[0002] As the global marine environment changes, it is particularly important to develop efficient and automated fish identification technology. This not only helps ecological conservation organizations monitor marine biodiversity and support fishery management, but also helps optimize fishing quotas and protect endangered species. In water conservancy projects, such as fishway design, effective fish identification technology can also ensure the smooth migration of fish and reduce the impact of facilities such as dams on the ecology.

[0003] In recent years, fish image recognition technology has achieved rapid development in the transition from morphology to deep learning technology, especially with the widespread application of convolutional neural networks (CNN) and recurrent neural networks (RNN). They can effectively and accurately identify specific fish from complex backgrounds by analyzing large-scale image datasets, significantly improving the accuracy and efficiency of recognition. However, these advanced technologies rely heavily on computing resources and dedicated hardware, which limits their widespread deployment in practical applications.

[0004] YOLOv8, as the latest generation of object detection models, has achieved significant improvements in both speed and accuracy. Compared with previous generations of models, it performs well in real-time applications by optimizing feature extraction networks and shortening inference time. However, YOLOv8 still relies on a large amount of high-quality training data and meticulous model parameter tuning. In addition, its sensitivity to background noise and illumination changes may affect its recognition stability and accuracy. Summary of the invention

[0005] The object of the present invention is to provide an improved YOLOv8 fish image recognition method based on transfer learning, so as to solve the aforementioned problems existing in the prior art.

[0006] In order to achieve the above object, the technical solution adopted by the present invention is as follows:

[0007] An improved YOLOv8 fish image recognition method based on transfer learning includes the following steps:

[0008] S100, collecting fish image data sets and preprocessing the data sets;

[0009] S200, labeling the fish image dataset with species names according to the species of the fish, and dividing the dataset into a training set, a validation set, and a test set in proportion;

[0010] S300, improves the standard YOLOv8 model, mainly including the CBS convolution module, C2f fusion module and GAM attention module in the backbone network, the CBS convolution module in the neck network, and the loss function in the head network;

[0011] S400, pre-train the improved YOLOv8 model using all fish images in the ImageNet dataset, and transfer the obtained weight parameters to the model;

[0012] S500, using the training set and the validation set to optimize the parameters of the improved YOLOv8 model after transfer learning;

[0013] S600. Use the optimized improved YOLOv8 model to perform target detection on the test set and output the fish recognition results.

[0014] Preferably, the 20 species of fish in the ImageNet data set contain 1,300 pictures of each species, and a total of 26,000 pictures are used as image samples, which are normalized to unify the size of the images and construct a fish recognition data set; then the data set is divided into a training set, a validation set, and a test set in a ratio of 7:2:1.

[0015] Preferably, the specific method of step S300 includes the following steps:

[0016] S310, replace the original CBS convolution module in the backbone network with the SPD convolution module to reduce the loss of fine-grained information during the model processing;

[0017] S320, replacing the C2f fusion module in the backbone network with a Ghost module with a smaller number of parameters, generating more feature maps at a lower computational cost, avoiding redundant features, and significantly reducing the amount of computation;

[0018] S330, integrating the global attention mechanism (GAM) in the backbone network to enhance the ability to capture fish characteristics from two dimensions: channel and space;

[0019] S340, embed the variable kernel convolution (AKConv) into the neck network, adaptively adjust the convolution kernel shape, and more accurately capture the contour features of fish;

[0020] S350, combine the cross entropy loss, DFL loss and CI oU loss to construct a comprehensive loss function as a criterion for optimizing model parameters, thereby continuously improving the performance of the model.

[0021] Preferably, the specific method of step S310 includes the following steps:

[0022] S311, extract the size of H×W×C 1The intermediate feature map X is split according to the ratio s. The specific formula is as follows:

[0023] f 0,0 =X[0:H:s,0:W:s],f 1,0 =X[1:H:s,0:W;s],....

[0024] f s-1,0 =X[s-1:H:s,0:W:s];

[0025] f 0,1 =X[0:H:s,1:W:s],f 1,1 ,....

[0026] f s-1,1 =X[s-1:H:s,1:W:s]; ....

[0028] f 0,s-1 =X[0:H:s,s-1:W:s],f 1,s-1 ,....

[0029] f s-1,s-1 =X[s-1:H:s,s-1:W:s].

[0030] In the above formula, H is the dimension of height; W is the dimension of width; s is the scaling factor;

[0031] S312. In the channel dimension, concatenate the obtained sub-maps to obtain a feature map X′, whose size is H / s×W / s×s 2 C 1 ;

[0032] S313, use a convolutional layer with a step size of 1 to convert X' into X", whose size is H / s×W / s×C 2 .

[0033] Preferably, the specific method of step S320 includes the following steps:

[0034] S321, use point-by-point convolution to generate a small number of low-cost feature maps. The specific formula is as follows:

[0035]

[0036] In the above formula, X is the size of H×W×C in Input feature map of Y 1 The size is H×W×C 1 The output feature map of W 1×1 is a 1×1 convolution kernel of size C 1 ×C in ; Cin is the number of channels of the input feature map; C 1 is the number of channels of the output feature map; H is the height of the feature map; W is the width of the feature map;

[0037] S322, perform independent spatial convolution on each input channel in the feature map generated in step S321 through depthwise separable convolution. The specific formula is as follows:

[0038]

[0039] In the above formula, Y 1 is the feature map generated in S321; Y dw The size is H×W×C 1 The feature map after the depth convolution; W dw is of size k d ×k d ×C 1 The depth of the convolution kernel; k d is the size of the depth convolution kernel;

[0040] S323, then use point-by-point convolution to mix the outputs of each channel. The specific formula is as follows:

[0041]

[0042] In the above formula, Y 2 The size is H×W×C 2 The final output feature map of The size is C 2 ×C 1 Point-by-point convolution kernel; C 2 is the channel of the output feature map;

[0043] Step S324, concatenate the feature maps generated in step S321 and step S323, the specific formula is as follows:

[0044] Y out =concat(Y 1 , Y 2 , axis = channel)

[0045] In the above formula, Y out The size after splicing is H×W×(C 1 +C 2 )’s final output feature map; concat is the feature map concatenated in the channel dimension.

[0046] Preferably, the specific method of step S330 includes the following steps:

[0047] S331. The specific formula of the global attention mechanism (GAM) is as follows:

[0048]

[0049] In the above formula, Y in is the input image feature, Y out is the output result, M c is the channel function, M s is the spatial attention function.

[0050] Preferably, the specific method of step S340 includes the following steps:

[0051] S341. Obtain the offset corresponding to the convolution kernel of size (B, 2N, H, W) through convolution operation. The specific formula is as follows:

[0052] offset = Conv2d(X)

[0053] In the above formula, X is the input feature map; B is the batch size; N is the size of the convolution kernel; H is the height of the input feature map; W is the width of the input feature map; C is the number of channels in the input feature map; Conv2d represents the convolution operation; 2N means that each position has a horizontal and vertical offset;

[0054] S342, the original coordinate P O With the offset coordinate P n Add together to get the updated coordinates P new , the specific formula is as follows:

[0055] P new =P o +P n

[0056] S343, the updated coordinates P new Interpolation and re-interpolation are performed to obtain the corresponding eigenvalue Γ. The specific formula is as follows:

[0057] Γ=Resample(Γ in , P new )

[0058] In the above formula, Resample represents the interpolation and reset operation.

[0059] Preferably, the specific method of step S350 includes the following steps:

[0060] S351. Calculate the cross entropy loss. The specific formula is as follows:

[0061]

[0062] In the above formula, N is the total number of samples; i represents the i-th sample; L iis the loss value of the i-th sample; M is the number of categories; y ic is the actual label of sample i in category c. When the true category of sample i is equal to c, the value is 1, otherwise it is 0; p ic is the predicted probability that sample i belongs to category c; log(p ic ) is the probability of taking the logarithm, which is used to calculate the cross entropy;

[0063] S352. Calculate the DFL loss. The specific formula is as follows:

[0064]

[0065] In the above formula, M is the total number of categories or the total number of discrete distributions of positions predicted by the model; ω ij is the loss weight term, which represents the weight of sample i in the jth category (or position bucket); p ij is the predicted probability of sample i in category (or position bucket) j;

[0066] S353. Calculate CIoU loss. The specific formula is as follows:

[0067]

[0068] In the above formula, IoU is the intersection over union ratio; b and b gt represents the center point of the two rectangular boxes; ρ is the Euclidean distance between the two rectangular boxes; d is the diagonal distance of the enclosed area of ​​the two rectangular boxes; αv is the penalty term; v is usually equal to Where ω and h are the width and height of the prediction box, respectively, and ω gt and h gt are the width and height of the true box, respectively, used to measure the consistency of the relative proportions of the two rectangular boxes; α is the weight coefficient, which is used to adjust the impact of the penalty term in the overall loss;

[0069] S354. Calculate the comprehensive loss. The specific formula is as follows:

[0070] L Total =λ 1 L+λ 2 L DEL +λ 3 L CIoU

[0071] In the above formula, λ 1 , 2 and λ 3 is a weight hyperparameter used to adjust the weight of different loss terms.

[0072] Preferably, the specific method of step S400 includes the following steps:

[0073] S410, extracting all fish images contained in the ImageNet dataset, and marking the fish images with corresponding labels;

[0074] S420, performing normalization processing on the extracted fish images, adjusting the size and proportion of the images to unify the size of the images;

[0075] S430, using the processed fish image dataset, pre-training the improved YOLOv8 model, and optimizing the model parameters through multiple iterative training until the loss function converges and the model performance reaches a stable state;

[0076] S440, migrating the optimal model weights obtained during the pre-training process to the original improved YOLOv8 model.

[0077] Preferably, the specific method of step S500 includes the following steps:

[0078] S510, using the training set to optimize the parameters of the improved YOLOv8 model after transfer learning, for a total of 100 iterations;

[0079] S520, verify the model through the validation set to obtain the improved YOLOv8 model after the trained transfer learning.

[0080] The beneficial effects of the present invention are:

[0081] The invention discloses an improved YOLOv8 fish image recognition method based on transfer learning, comprising the following steps: collecting a fish image data set, and preprocessing the data set; marking the fish image data set with species names according to the species of fish, and dividing the fish image data set into a training set, a validation set and a test set in proportion; improving a standard YOLOv8 model, the content of which mainly includes a CBS convolution module, a C2f fusion module and a GAM attention module in a backbone network, a CBS convolution module in a neck network, and a loss function in a head network; pre-training the improved YOLOv8 model using all fish images in an ImageNet data set, and migrating the obtained weight parameters to the model; optimizing parameter training of the improved YOLOv8 model after transfer learning using a training set and a validation set; performing target detection on a test set through the optimized improved YOLOv8 model, and outputting a fish recognition result.

[0082] (1) The present invention proposes an improved YOLOv8 fish image recognition method based on transfer learning. Compared with other methods, by introducing the SPD convolution module, the lightweight Ghost module, the global attention module and the variable kernel convolution module, the accuracy of feature extraction and recognition is effectively improved, while the computing resource requirements are reduced and the robustness and adaptability of the model are enhanced.

[0083] (2) The present invention significantly improves the learning efficiency and recognition accuracy of the model by applying the transfer learning method, reduces data dependence, and enables the model to have stronger generalization ability.

[0084] (3) The present invention optimizes classification accuracy and geometric alignment by adopting a multivariate loss function strategy, significantly enhancing the recognition ability of the model in complex scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0085] Figure 1 The present invention relates to a schematic diagram of a standard YOLOv8 target detection model;

[0086] Figure 2 Schematic diagram of an improved YOLOv8 target detection model in an embodiment of the present invention;

[0087] Figure 3 Schematic diagram of the structure of the SPD convolution module in an embodiment of the present invention;

[0088] Figure 4 is a schematic diagram of the structure of a lightweight Ghost module in an embodiment of the present invention;

[0089] Figure 5 Schematic diagram of the internal principle structure of the GAM attention module in an embodiment of the present invention;

[0090] Figure 6 is a schematic diagram of the structure of an AK convolution module in an embodiment of the present invention;

[0091] Figure 7 It is a flow chart of an improved YOLOv8 fish image recognition method based on transfer learning in the present invention. DETAILED DESCRIPTION

[0092] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation methods described herein are only used to explain the present invention and are not used to limit the present invention.

[0093] An improved YOLOv8 fish image recognition method based on transfer learning includes the following steps:

[0094] S100: Collect fish image datasets and preprocess the datasets.

[0095] In this embodiment, a fish recognition dataset is constructed based on the ImageNet public dataset, and is normalized to unify the size of the images.

[0096] S200, labeling the fish image dataset with species names according to the species of fish, and dividing it into a training set, a validation set, and a test set in proportion.

[0097] In this embodiment, the specific method of step S100 includes the following steps:

[0098] S110, 20 species of fish in the ImageNet public dataset, each species of fish contains 1,300 pictures, a total of 26,000 pictures as image samples, and the image samples are normalized to unify the image size to construct a fish recognition dataset.

[0099] Preferably, the specific method of step S200 includes the following steps:

[0100] S210. Label the 20 fish species in the fish identification dataset, including anemone fish, barracuda, silver salmon, crayfish, eel, electric ray, gar, goldfish, great white shark, hammerhead shark, lionfish, pufferfish, rock mermaid, sea slug, sea snake, stingray, sturgeon, tench, tiger shark and water snake.

[0101] S220, dividing the fish identification data set into a training set, a validation set, and a test set in a ratio of 7:2:1, that is, each fish in the training set has 910 images, each fish in the validation set has 260 images, and each fish in the test set has 130 images.

[0102] S300 improves the standard YOLOv8 model, mainly including the CBS convolution module, C2f fusion module and GAM attention module in the backbone network, the CBS convolution module in the neck network, and the loss function in the head network.

[0103] S400, use all fish images in the ImageNet dataset to pre-train the improved YOLOv8 model, and migrate the obtained weight parameters to the model.

[0104] S500, using the training set and the validation set to optimize the parameters of the improved YOLOv8 model after transfer learning. It should be noted that the iterations are 100 times in total. The model is then validated by the validation set to obtain a trained model.

[0105] S600. Use the optimized improved YOLOv8 model to perform target detection on the test set and output the fish recognition results.

[0106] Preferably, the 20 species of fish in the ImageNet data set contain 1,300 pictures of each species, and a total of 26,000 pictures are used as image samples, which are normalized to unify the size of the images and construct a fish recognition data set; then the data set is divided into a training set, a validation set, and a test set in a ratio of 7:2:1.

[0107] Preferably, the specific method of step S300 includes the following steps:

[0108] In this embodiment, the schematic diagram of the standard YOLOv8 target detection model is as follows Figure 1 As shown, the schematic diagram of the improved YOLOv8 target detection model is as follows Figure 2 shown.

[0109] S310. Replace the original CBS convolution module in the backbone network with the SPD convolution module to reduce the loss of fine-grained information during the model processing.

[0110] S320, replace the C2f fusion module in the backbone network with a Ghost module with a smaller parameter amount, generate more feature maps at a lower computational cost, avoid redundant features, and significantly reduce the amount of computation.

[0111] S330. Integrate the global attention mechanism (GAM) in the backbone network to enhance the ability to capture fish characteristics from two dimensions: channel and space.

[0112] S340, embed the variable kernel convolution (AKConv) into the neck network, adaptively adjust the convolution kernel shape, and more accurately capture the contour features of fish.

[0113] S350, combine the cross entropy loss, DFL loss and CIoU loss to construct a comprehensive loss function as a criterion for optimizing model parameters, thereby continuously improving the performance of the model.

[0114] Preferably, the specific method of step S310 includes the following steps:

[0115] S311, extract the size of H×W×C 1 The intermediate feature map X is split according to the ratio s. The specific formula is as follows:

[0116] f 0,0 =X[0:H:s,0:W:s],f 1,0 =X[1:H:s,0:W:s],....

[0117] f s-1,0 =X[s-1:H:s,0:W:s];

[0118] f 0,1=X[0:H:s,1:W:s],f 1,1 ,....

[0119] f s-1,1 =X[s-1:H:s,1:W:s]; ....

[0121] f 0,s-1 =X[0:H:s,s-1:W:s],f 1,s-1 ,....

[0122] f s-1,s-1 =X[s-1:H:s,s-1:W:s].

[0123] In the above formula, H is the height dimension; W is the width dimension; s is the scaling factor.

[0124] Extract the size of H×W×C 1 The intermediate feature map X is split according to the ratio s = 2 to obtain a size of H / 2×W / 2×C 1 The four subgraphs f 0,0 、f 1,0 、f 0,1 and f 1,1 Among them, the SPD convolution module structure is as follows Figure 3 shown.

[0125] S312. In the channel dimension, concatenate the obtained sub-maps to obtain a feature map X′, whose size is H / s×W / s×s 2 C 1 ;

[0126] In this embodiment, in the channel dimension, the obtained sub-maps are concatenated to obtain a feature map X′, whose size is H / 2×W / 2×4C 1 .

[0127] S313, use a convolutional layer with a step size of 1 to convert X' into X", whose size is H / s×W / s×C 2 .

[0128] In this embodiment, X′ is converted into X″ through a convolutional layer with a stride of 1, H / 2×W / 2×C 2 , where C 2 <4C 1 .

[0129] Preferably, the specific method of step S320 includes the following steps:

[0130] The structural diagram of the lightweight Ghost module in step S320 is as follows: Figure 4 As shown, the specific method includes the following steps:

[0131] S321, use point-by-point convolution to generate a small number of low-cost feature maps. The specific formula is as follows:

[0132]

[0133] In the above formula, X is the size of H×W×C in Input feature map of Y 1 The size is H×W×C 1 The output feature map of W 1×1 is a 1×1 convolution kernel of size C 1 ×C in ; C in is the number of channels of the input feature map; C 1 is the number of channels of the output feature map; H is the height of the feature map; W is the width of the feature map.

[0134] S322, perform independent spatial convolution on each input channel in the feature map generated in step S321 through depthwise separable convolution. The specific formula is as follows:

[0135]

[0136] In the above formula, Y 1 is the feature map generated in S321; Y dw The size is H×W×C 1 The feature map after the depth convolution; W dw is of size k d ×k d ×C 1 The depth of the convolution kernel; k d is the size of the depth convolution kernel;

[0137] S323, then use point-by-point convolution to mix the outputs of each channel. The specific formula is as follows:

[0138]

[0139] In the above formula, Y 2 The size is H×W×C 2 The final output feature map of The size is C 2 ×C 1 Point-by-point convolution kernel; C 2 is the channel of the output feature map;

[0140] Step S324, concatenate the feature maps generated in step S321 and step S323, the specific formula is as follows:

[0141] Y out =concat(Y 1, Y 2 , axis = channel)

[0142] In the above formula, Y out The size after splicing is H×W×(C 1 +C 2 )’s final output feature map; concat is the feature map concatenated in the channel dimension.

[0143] Preferably, the specific method of step S330 includes the following steps:

[0144] S331. The specific formula of the global attention mechanism (GAM) is as follows:

[0145]

[0146] In the above formula, Y in is the input image feature, Y out is the output result, M c is the channel function, M s is the spatial attention function.

[0147] Preferably, the specific method of step S340 includes the following steps:

[0148] The structural diagram of the AK convolution module in step S340 is as follows: Figure 6 As shown, the specific method includes the following steps:

[0149] S341. Obtain the offset corresponding to the convolution kernel of size (B, 2N, H, W) through convolution operation. The specific formula is as follows:

[0150] offset = Conv2d(X)

[0151] In the above formula, X is the input feature map; B is the batch size; N is the size of the convolution kernel; H is the height of the input feature map; W is the width of the input feature map; C is the number of channels in the input feature map; Conv2d represents the convolution operation; 2N means that each position has a horizontal and vertical offset.

[0152] S342, the original coordinate P o With the offset coordinate P n Add together to get the updated coordinates P new , the specific formula is as follows:

[0153] P new =P o +P n

[0154] S343, the updated coordinates P newInterpolation and re-interpolation are performed to obtain the corresponding eigenvalue Γ. The specific formula is as follows:

[0155] Γ=Resample(Γ in , P new )

[0156] In the above formula, Resample represents the interpolation and reset operation.

[0157] Preferably, the specific method of step S350 includes the following steps:

[0158] S351. Calculate the cross entropy loss. The specific formula is as follows:

[0159]

[0160] In the above formula, N is the total number of samples; i represents the i-th sample; L i is the loss value of the i-th sample; M is the number of categories; y ic is the actual label of sample i in category c. When the true category of sample i is equal to c, the value is 1, otherwise it is 0; p ic is the predicted probability that sample i belongs to category c; log(p ic ) is the probability of taking the logarithm, which is used to calculate the cross entropy;

[0161] S352. Calculate the DFL loss. The specific formula is as follows:

[0162]

[0163] In the above formula, M is the total number of categories or the total number of discrete distributions of positions predicted by the model; ω ij is the loss weight term, which represents the weight of sample i in the jth category (or position bucket); p ij is the predicted probability of sample i in category (or position bucket) j.

[0164] S353. Calculate CIoU loss. The specific formula is as follows:

[0165]

[0166] In the above formula, IoU is the intersection over union ratio; b and b gt represents the center point of the two rectangular boxes; ρ is the Euclidean distance between the two rectangular boxes; d is the diagonal distance of the enclosed area of ​​the two rectangular boxes; αv is the penalty term; v is usually equal to Where ω and h are the width and height of the prediction box, respectively, and ω gt and h gt are the width and height of the true box, respectively, used to measure the consistency of the relative proportions of the two rectangular boxes; α is the weight coefficient, which is used to adjust the impact of the penalty term in the overall loss;

[0167] S354. Calculate the comprehensive loss. The specific formula is as follows:

[0168] L Total =λ 1 L+λ 2 L DEL +λ 3 L CIoU

[0169] In the above formula, λ 1 , 2 and λ 3 is a weight hyperparameter used to adjust the weight of different loss terms.

[0170] Preferably, the specific method of step S400 includes the following steps:

[0171] S410, extracting all fish images from the ImageNet dataset, and marking the fish images with corresponding labels.

[0172] S420, performing normalization processing on the extracted fish images, adjusting the size and proportion of the images to unify the size of the images;

[0173] S430. Pre-train the improved YOLOv8 model using the processed fish image dataset, and optimize the model parameters through multiple iterative training until the loss function converges and the model performance reaches a stable state.

[0174] S440, migrating the optimal model weights obtained during the pre-training process to the original improved YOLOv8 model.

[0175] Preferably, the specific method of step S500 includes the following steps:

[0176] S510, using the training set to optimize parameter training of the improved YOLOv8 model after transfer learning, for a total of 100 iterations.

[0177] S520, verify the model through the validation set to obtain the improved YOLOv8 model after the trained transfer learning.

[0178] By adopting the above technical solution disclosed in the present invention, the following beneficial effects are obtained:

[0179] The invention discloses an improved YOLOv8 fish image recognition method based on transfer learning, comprising the following steps: collecting a fish image data set, and preprocessing the data set; marking the fish image data set with species names according to the species of fish, and dividing the fish image data set into a training set, a validation set and a test set in proportion; improving a standard YOLOv8 model, the content of which mainly includes a CBS convolution module, a C2f fusion module and a GAM attention module in a backbone network, a CBS convolution module in a neck network, and a loss function in a head network; pre-training the improved YOLOv8 model using all fish images in an ImageNet data set, and migrating the obtained weight parameters to the model; optimizing parameter training of the improved YOLOv8 model after transfer learning using a training set and a validation set; performing target detection on a test set through the optimized improved YOLOv8 model, and outputting a fish recognition result.

[0180] (1) The present invention proposes an improved YOLOv8 fish image recognition method based on transfer learning. Compared with other methods, by introducing the SPD convolution module, the lightweight Ghost module, the global attention module and the variable kernel convolution module, the accuracy of feature extraction and recognition is effectively improved, while the computing resource requirements are reduced and the robustness and adaptability of the model are enhanced.

[0181] (2) The present invention significantly improves the learning efficiency and recognition accuracy of the model by applying the transfer learning method, reduces data dependence, and enables the model to have stronger generalization ability.

[0182] (3) The present invention optimizes classification accuracy and geometric alignment by adopting a multivariate loss function strategy, significantly enhancing the recognition ability of the model in complex scenarios.

[0183] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be considered as the scope of protection of the present invention.

Claims

1. An improved YOLOv8 fish image recognition method based on transfer learning, characterized in that: The following steps are involved: S100, collecting fish image data sets and preprocessing the data sets; S200, labeling the fish image dataset with species names according to the species of the fish, and dividing the dataset into a training set, a validation set, and a test set in proportion; S300, improves the standard YOLOv8 model, mainly including the CBS convolution module, C2f fusion module and GAM attention module in the backbone network, the CBS convolution module in the neck network, and the loss function in the head network; S400, pre-training the improved YOLOv8 model using all fish images in the ImageNet dataset, and migrating the obtained weight parameters to the model; S500, using the training set and the validation set to perform parameter optimization training on the improved YOLOv8 model after transfer learning; S600, performing target detection on the test set through the optimized improved YOLOv8 model, and outputting fish recognition results.

2. The improved YOLOv8 fish image recognition method based on transfer learning according to claim 1, characterized in that, The 20 species of fish in the ImageNet dataset contain 1,300 images of each species, with a total of 26,000 images as image samples, which are normalized to unify the size of the images and construct a fish recognition dataset; the dataset is then divided into a training set, a validation set, and a test set in a ratio of 7:2:

1.

3. The improved YOLOv8 fish image recognition method based on transfer learning according to claim 2, characterized in that, The specific method of step S300 includes the following steps: S310, replacing the original CBS convolution module in the backbone network with the SPD convolution module to reduce the loss of fine-grained information during the model processing; S320, replacing the C2f fusion module in the backbone network with a Ghost module with a smaller number of parameters, generating more feature maps at a lower computational cost, avoiding redundant features, and significantly reducing the amount of computation; S330, integrating the global attention mechanism (GAM) in the backbone network to enhance the ability to capture fish characteristics from two dimensions: channel and space; S340, embed the variable kernel convolution (AKConv) into the neck network, adaptively adjust the convolution kernel shape, and more accurately capture the contour features of fish; S350, combine the cross entropy loss, DFL loss and CIoU loss to construct a comprehensive loss function as a criterion for optimizing model parameters, thereby continuously improving the performance of the model.

4. The improved YOL0v8 fish image recognition method based on transfer learning according to claim 3, characterized in that, The specific method of step S310 includes the following steps: S311, extract the intermediate feature map X of size H×W×C1, and split it according to the ratio S. The specific formula is as follows: f 0,0 =X[0:H:s,0:W:s],f 1,0 =X[1:H:s,0:W;s],.... f s-1,0 =X[s-1:H:s,0:W:s]; f 0,1 =X[0:H:s,1:W:s],f 1,1 ,.... f s-1,1 =X[s-1:H:s,1:W:s]; .... f 0,s-1 =X[0:H:s,s-1:W:s],f 1,s-1 ,.... f s-1,s-1 =X[s-1:H:s,s-1:W:s]. In the above formula, H is the dimension of height; W is the dimension of width; s is the scaling factor; S312. In the channel dimension, concatenate the obtained sub-maps to obtain a feature map X′, whose size is H / s×W / s×s 2 C1; S313. Use a convolutional layer with a step size of 1 to convert X′ into X″, whose size is H / s×W / s×C2.

5. The improved YOLOv8 fish image recognition method based on transfer learning according to claim 4, characterized in that, The specific method of step S320 includes the following steps: S321, use point-by-point convolution to generate a small number of low-cost feature maps. The specific formula is as follows: In the above formula, X is the size of H×W×C in Y1 is the input feature map of size H×W×C1; W 1×1 It is a 1×1 convolution kernel with a size of C1×C in ; C in is the number of channels of the input feature map; C1 is the number of channels of the output feature map; H is the height of the feature map; W is the width of the feature map; S322, perform independent spatial convolution on each input channel in the feature map generated in step S321 through depthwise separable convolution. The specific formula is as follows: In the above formula, Y1 is the feature map generated in S321; Y dw It is a feature map after deep convolution of size H×W×C1; W dw is of size k d ×k d ×C1 depth convolution kernel; k d is the size of the depth convolution kernel; S323, then use point-by-point convolution to mix the outputs of each channel. The specific formula is as follows: In the above formula, Y2 is the final output feature map of size H×W×C2; is a point-by-point convolution kernel of size C2×C1; C2 is the channel of the output feature map; The step S324, concatenating the feature maps generated in the step S321 and the step S323, has the following specific formula: Y out =comcat(Y1,Y2,axis=channel) In the above formula, Y out It is the final output feature map of size H×W×(C1+C2) after splicing; concat is the feature map spliced ​​in the channel dimension.

6. The improved YOLOv8 fish image recognition method based on transfer learning according to claim 5, characterized in that, The specific method of step S330 includes the following steps: S331. The specific formula of the global attention mechanism (GAM) is as follows: In the above formula, Y in is the input image feature, Y out is the output result, M c is the channel function, M s is the spatial attention function.

7. The improved YOLOv8 fish image recognition method based on transfer learning according to claim 6, characterized in that, The specific method of step S340 The following steps are involved: S341. Obtain the offset corresponding to the convolution kernel of size (B, 2N, H, W) through convolution operation. The specific formula is as follows: offset = Conv2d(X) In the above formula, X is the input feature map; B is the batch size; N is the size of the convolution kernel; H is the height of the input feature map; W is the width of the input feature map; C is the number of channels in the input feature map; Conv2d represents the convolution operation; 2N means that each position has a horizontal and vertical offset; S342, the original coordinate P o With the offset coordinate P n Add together to get the updated coordinates P new , the specific formula is as follows: P new =P O +P n S343, the updated coordinates P new Interpolation and re-interpolation are performed to obtain the corresponding eigenvalue Γ. The specific formula is as follows: C=Resample(C in ,P new ) In the above formula, Resample represents the interpolation and reset operation.

8. The improved YOLOv8 fish image recognition method based on transfer learning according to claim 7, characterized in that: The specific method of step S350 includes the following steps: S351. Calculate the cross entropy loss. The specific formula is as follows: In the above formula, N is the total number of samples; i represents the i-th sample; L i is the loss value of the i-th sample; M is the number of categories; y ic is the actual label of sample i in category c. When the true category of sample i is equal to c, the value is 1, otherwise it is 0; p ic is the predicted probability that sample i belongs to category c; log(p ic ) is the probability of taking the logarithm, which is used to calculate the cross entropy; S352. Calculate the DFL loss. The specific formula is as follows: In the above formula, M is the total number of categories or the total number of discrete distributions of positions predicted by the model; ω ij is the loss weight term, which represents the weight of sample i in the jth category (or position bucket); p ij is the predicted probability of sample i in category (or position bucket) j; S353. Calculate CIoU loss. The specific formula is as follows: In the above formula, IoU is the intersection over union ratio; b and b gt represents the center point of the two rectangular boxes; ρ is the Euclidean distance between the two rectangular boxes; d is the diagonal distance of the enclosed area of ​​the two rectangular boxes; αv is the penalty term; v is usually equal to Where ω and h are the width and height of the prediction box, respectively, and ω gt and h gt are the width and height of the true box, respectively, used to measure the consistency of the relative proportions of the two rectangular boxes; α is the weight coefficient, which is used to adjust the impact of the penalty term in the overall loss; S354. Calculate the comprehensive loss. The specific formula is as follows: L Total =λ1L+λ2L DEL +λ3L CIoU In the above formula, λ1, λ2, and λ3 are weight hyperparameters used to adjust the weights of different loss terms.

9. The improved YOLOv8 fish image recognition method based on transfer learning according to claim 8, characterized in that: The specific method of step S400 includes the following steps: S410, extracting all fish images contained in the ImageNet dataset, and marking the fish images with corresponding labels; S420, performing normalization processing on the extracted fish images, adjusting the size and proportion of the images to unify the sizes of the images; S430, using the processed fish image dataset, pre-training the improved YOLOv8 model, and optimizing the model parameters through multiple iterative training until the loss function converges and the model performance reaches a stable state; S440, migrating the optimal model weights obtained during the pre-training process to the original improved YOLOv8 model.

10. The improved YOLOv8 fish image recognition method based on transfer learning according to claim 9, characterized in that: The specific method of step S500 includes the following steps: S510, using the training set to optimize the parameters of the improved YOLOv8 model after transfer learning, for a total of 100 iterations; S520, verify the model through the validation set to obtain the trained improved YOLOv8 model after transfer learning.

Citation Information

Cited By

  • Drug mixture trace impurity identification and quantification method based on deep learning

    CN119694431A

  • Fry culture dynamic monitoring and feeding optimization method based on deep learning

    CN120146498A

  • Fishway fish passing real-time monitoring method and system based on YOLOv8 model

    CN120783293A

  • Device and method for intelligently investigating types and quantity of fishes

    CN121074619A

  • Intelligent device and method for investigating fish species and quantity

    CN121074619B