A fish intelligent sorting method based on variable step-size learning rate optimization strategy
By adopting the optimization strategy of variable step learning rate in deep learning network and transfer learning of lightweight neural network ResNet18, the problem of difficulty in learning rate optimization in deep learning model weight training is solved, and the efficiency of fish classification is achieved and high precision.
Patent Information
- Application Number
- CN202411005139.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2044-07-25
Smart Images

Figure CN118781476B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of artificial intelligence, and in particular relates to a fish intelligent sorting method based on a variable step-size learning rate optimization strategy. Background Art
[0002] In machine vision, the essence of fish species classification is to classify the quality or type through the differences in some features of the samples. In recent years, deep learning has been widely used in fisheries, such as Zhao Ran's "Fish Image Classification Method, Device and Equipment" and Zhou Zhiyu's "An Underwater Fish Classification Method Based on MGO Optimization RVFL", which continuously adjust the weight of the model through the input of a large amount of data to complete the classification task. However, in the process of training the weights of the deep learning network model, the optimization of the learning rate usually relies on experience or adaptive optimization, which is easy to fall into the local optimal solution.
[0003] Due to the above limitations of the hyperparameter optimization method, a new learning rate optimization method is urgently needed to improve the accuracy and stability of the model. Summary of the invention
[0004] Aiming at the problem of slow speed and low accuracy of fish classification, the present invention proposes a fish intelligent sorting method based on variable step-length learning rate optimization strategy. Specifically, after constructing the data set, a lightweight neural network is selected for transfer learning, the model is fine-tuned, and finally the large interval fast positioning of the learning rate and the small interval precise optimization are used to determine the optimal learning rate, which can ensure the efficiency of classification while taking into account the accuracy of classification.
[0005] The technical solution of the present invention:
[0006] A fish intelligent sorting method based on variable step-size learning rate optimization strategy, the steps are as follows:
[0007] Step 1: Build a feature extraction network based on transfer learning
[0008] 1.1. Building a Dataset
[0009] Taking three kinds of fish A, B, and C and other species of mixed fish as the objects, we collected images of fish to construct a data set of four kinds of fish;
[0010] 1.2 Image Preprocessing
[0011] To ensure the standardization and detectability of image data features, it is necessary to preprocess the images in the dataset, unify the original images into RGB three-channel images with a size of 224*224 and perform normalization.
[0012] 1.3. Transfer learning of lightweight neural network models
[0013] In view of the urgent need for target classification and recognition in agricultural production and the difficulty of current hardware systems to effectively support the rapid operation of complex recognition algorithms, the lightweight neural network ResNet18 is selected as the basic model for transfer learning in terms of network model;
[0014] In order to solve the three types of fish classification problems, namely, A, B and C, based on the lightweight neural network ResNet18, the original fully connected layer output OutputSize of the lightweight neural network ResNet18 was set to 3 according to the number of corresponding fish categories, and the weight parameters of the network ResNet18 were retrained; at the same time, in order to prevent overfitting, the SGDM algorithm and the loss function with L2 regularization penalty term were selected to enhance the generalization performance of the network and obtain a convergent and stable objective function;
[0015] In the training process of the network structure, the learning rate setting has a direct impact on the model training cycle and accuracy. A learning rate that is too small will lead to slow model convergence, and a learning rate that is too large will cause the model to oscillate or diverge near the minimum point. The performance of the deep learning model depends to a large extent on the choice of learning rate. Therefore, this paper studies the optimization method of the learning rate parameter in order to achieve the highest accuracy with the least number of optimization times.
[0016] Step 2: Variable step size learning rate optimization strategy
[0017] The interval near the optimal learning rate is often accompanied by multiple better learning rate parameters. The use of traditional empirical values or equal step-size methods to set the learning rate is very likely to be limited to a local optimal solution, thus missing the global optimal learning rate. In addition, if traditional training methods want to obtain the global optimal solution, the step size needs to be reduced, which leads to a long training cycle and low efficiency. To address this problem, this paper analyzes the changing rules of the learning rate and the accuracy of the validation set, and proposes a variable step-size learning rate optimization strategy to maximize the accuracy. The core idea of this strategy is to use the idea of interval subdivision to characterize the accuracy coefficient of each interval by the training results of the interval, that is, if the target accuracy k is not reached, the training result is the best. m Previously, the intervals on both sides of the local optimal solution of this round of optimization interval were selected as the target intervals for the next round, and the optimization was cyclically performed until the target accuracy was reached, and the global optimal learning rate corresponding to the target accuracy was determined.
[0018] In order to quickly and accurately obtain the optimal learning rate parameters, this paper uses the validation set accuracy as an indicator to optimize the variable step learning rate to improve the efficiency of model training.
[0019] 2.1. Variable step learning rate (lr) selection rules
[0020] The overall range of learning rate (lr) is (0, 1]. Since the empirical range of commonly used learning rates is [1*10 -5, 0.1], so this paper focuses on the design of [1*10 -5 , 1] The selection of learning rate (lr): in [1*10 -5 In the interval (0.1, 0.1], the learning rate is selected by a method with a small variable step size. In the remaining interval (0.1, 1], a method with a large constant step size is used to select the learning rate.
[0021] 2.1.1 Rapid positioning in large areas
[0022] In the interval [1*10 -5 , 0.1] The learning rate (lr1) is selected by the variable step size. The learning rate selection formula is as follows:
[0023]
[0024] k2 is the maximum value of the overall learning rate interval, which is 1. The larger the parameter n is, the smaller the step size is. The parameter n is a positive integer and is selected in the range of [1, 5].
[0025] In the interval (0.1, 1], select the learning rate (lr2) with equal step size s1, and the formula is as follows:
[0026]
[0027] lr2=m*s1#(3)
[0028] k1 is the maximum value of the learning rate experience interval 0.1, k2 is the maximum value of the overall learning rate interval 1, parameter p is a positive integer 9, parameter m is a positive integer selected in the range of [2, 10].
[0029] 2.1.2. Accurate optimization of small intervals
[0030] The precise optimization of small intervals is based on the rapid positioning of large intervals. The network model is trained according to the various learning rates in the rapid positioning of large intervals as hyperparameters, and the learning rate lr corresponding to the maximum accuracy in the training results is b As the benchmark, select the learning rate lr on the left side of the benchmark l , the learning rate lr on the right r , respectively as the left and right values of the small interval, and perform precise optimization in this interval.
[0031] The small interval precise optimization takes s2 as the step size, and the learning rate selection formula is as follows:
[0032] When lr b -lr l ≤10k m hour,
[0033] s2=k m #(4)
[0034] lr1 * =lr l +S2#(5)
[0035] k m is the learning rate precision, lr1 * Get the updated learning rate.
[0036] When lr b -lr l ≥10k m hour,
[0037]
[0038] lr1 * =lr l +S2#(7)
[0039] The parameter p is a positive integer 9, lr1 * Get the updated learning rate.
[0040] Similarly, when lr r -lr b ≤10k m hour,
[0041] s2=k m #(8)
[0042] lr2 * =lr b +s2#(9)
[0043] k m is the learning rate precision, lr2 * Get the updated learning rate.
[0044] When lr r -lr b ≥10k m hour,
[0045]
[0046] lr2 * =lr b +s2#(11)
[0047] The parameter p is a positive integer 9, lr2 * Get the updated learning rate.
[0048] 2.2. Variable step learning rate (lr) optimization process
[0049] If the accuracy is less than 80% for three consecutive times or the interval learning rate is fully taken, the optimization round is interrupted and the next optimization round begins; the interval length is less than or equal to k mOr when the accuracy of the validation set is higher than 99%, the optimization ends and the best learning rate is output; the interval length is greater than k m Or when the accuracy of the validation set is lower than 99%, the optimization continues and the steps of precise optimization between small intervals are repeated.
[0050] Step 3: Output target classification results
[0051] The fish are classified with a threshold of 0.95. If the judgment result of a certain fish for a certain species is greater than 0.95, the fish is judged to be of the corresponding species. If the judgment results of a certain fish for Class A, Class B, and Class C are all less than 0.95, the fish is judged to be other interfering fish.
[0052] Beneficial effects of the invention: The invention adopts the ResNet lightweight network model and model training method for transfer learning, analyzes the influence of the learning rate parameter on the accuracy during network training, and proposes a variable step-length learning rate optimization strategy. It achieves high-precision and rapid sorting of target fish and other multi-species interfering fish, improves network training efficiency and accuracy, and provides a theoretical reference for hyperparameter setting in the model training process in the deep learning field. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 This is the ResNet18 network structure involved in the present invention.
[0054] Figure 2 It is a learning rate optimization flow chart involved in the present invention.
[0055] Figure 3 It is the model accuracy of transfer learning based on ResNet18 involved in the present invention.
[0056] Figure 4 It is the model loss function of transfer learning based on ResNet18 involved in the present invention. DETAILED DESCRIPTION
[0057] The specific implementation of the present invention is further described below in conjunction with the accompanying drawings and technical solutions.
[0058] Example
[0059] A fish intelligent sorting method based on a variable step-size learning rate optimization strategy is specifically implemented as follows: first, transfer learning is performed on the initial network model ResNet18, the fully connected layer of the initial network model is changed, and the fully connected layer with 3 neurons is replaced, and the weight parameters of the network are also retrained. After that, the large interval fast positioning of the learning rate and the small interval precise optimization are used to determine the optimal learning rate.
[0060] Step 1: Build a feature extraction network based on transfer learning
[0061] 1.1. Building a Dataset
[0062] In order to ensure the diversity of fish sample data, four fish data sets in complex background environments were constructed, taking three common economic fish species, sea bass, cod and sea bream, which are common in the Bohai Sea and the Yellow Sea, and other multi-species interfering fish as the objects. The training set, validation set and test set image data totaled 2,289 images. Among them, the test set had 320 images, and the remaining 1,969 image data were divided into 75% as the training set and 25% as the validation set.
[0063] 1.2 Image Preprocessing
[0064] To ensure the standardization and detectability of image data features, the original image needs to be preprocessed to unify the original image into a RGB three-channel image with a size of 224*224; the image is normalized and mapped to the interval [0, 1], and the mapping function is as follows:
[0065]
[0066] In the formula, x is the pixel value before normalization, max is the maximum value of the sample data, min is the minimum value of the sample data, and x * is the normalized pixel value.
[0067] 1.3. Transfer learning of lightweight neural network models
[0068] In view of the urgent need for target classification and recognition in agricultural production and the problem that the current hardware system is unable to effectively support the rapid operation of complex recognition algorithms, the lightweight network ResNet18 is selected as the basic model for transfer learning in terms of network model.
[0069] In order to solve the classification problem of three kinds of fish, namely sea bass, cod and sea bream, the fully connected layer of the network model was changed, replaced with a fully connected layer with 3 neurons, and the weight parameters of the network were retrained;
[0070] In order to prevent overfitting, the SGDM algorithm and the loss function with L2 regularization penalty term are selected to enhance the generalization performance of the network and obtain a convergent and stable objective function. In order to obtain better validation set accuracy, the training cycle is set to 20 rounds; the weight decay coefficient of the L2 regularization term is set to 1*10 -4 The number of batch samples is selected as 128 after experiments with other hyperparameters fixed.
[0071] Step 2: Optimizing the learning rate with variable step length
[0072] With target accuracy k m=0.005 as an example, the variable step size learning rate optimization is performed on the ResNet18 model. The specific steps and experimental results are as follows:
[0073] 2.1. Rapid positioning in large areas
[0074] The initial learning rate interval is (0, 1]. The learning rate is selected according to the learning rate selection rule. When the learning rate is 0.1, 0.2, and 0.3, the accuracy of the validation set is less than 80% for three consecutive times. This round of optimization is interrupted, and the intervals on both sides of the learning rate 0.01 with the highest accuracy are selected as the next round of optimization interval.
[0075] 2.2. Accurate optimization between small areas
[0076] According to the learning rate selection rule, a learning rate of 0.005 was selected in the interval [0.001, 0.01] for experimentation, and various learning rates were selected in the interval [0.01, 0.1) with a step size of 0.01 for experimentation. When the accuracy of the validation set was less than 80% for three consecutive times at the learning rates of 0.04, 0.05, and 0.06, the optimization round was interrupted, and the intervals on both sides of the learning rate of 0.01 with the highest accuracy were selected as the optimization intervals for the next round.
[0077] Experiments were conducted by selecting various learning rates in the interval [0.006, 0.02] with a step size of 0.005. When the learning rate obtained all values in the interval with a step size of 0.005, the optimization was stopped.
[0078] Experimental verification shows that when the variable step-size learning rate optimization strategy proposed in this paper is used to determine the optimal learning rate to be 0.01, the accuracy of the model based on ResNet18 transfer learning reaches 96.33%.
[0079] Model learning rate variable step size optimization for transfer learning based on ResNet18
[0080] The first round of experimental data
[0081]
[0082] Second round of experimental data
[0083]
[0084] The third round of experimental data
[0085]
[0086] To verify the effectiveness of the variable step learning rate optimization strategy under different target accuracy requirements, this paper conducts experimental verification on the ResNet18-based transfer learning model when the target accuracy is 0.001, 0.002, 0.003, 0.004, and 0.005, and compares the optimization times with the same target accuracy using the equal step learning rate. The comparison results are shown in the following table.
[0087] Comparison of the number of optimization times for model learning rate based on ResNet18 for transfer learning
[0088]
[0089] The higher the target accuracy requirement, the more significant the advantage of using a variable step-size learning rate optimization strategy in reducing the number of optimization times. The reduction in the number of global optimization times can be as high as 97.1% or more, and the reduction in the empirical interval can be as high as 73% or more. The optimal learning rate can be determined accurately and efficiently.
[0090] Step 3: Output target classification results
[0091] This paper uses 320 test set images to verify the model training effect of transfer learning based on the ResNet18 model, extracts the classification probability of the softmax layer and performs statistical analysis, and designs the algorithm with a threshold of 0.95 for the highest probability among the three classification labels. Based on the test result data, a four-category confusion matrix of sea bass, bream, cod, and other multi-species interfering fish is established and the precision and recall of each category are calculated. At the same time, the F1 metric is used to comprehensively evaluate the model. The calculation formulas for precision P (precision), recall R (recall) and F1 value are as follows:
[0092]
[0093] TP indicates the number of fish that are accurately predicted as a certain type of fish, FP indicates the number of fish that are not of that type of fish that are incorrectly predicted as that type of fish, and FN indicates the number of fish that are incorrectly predicted as that type of fish. F1 combines precision and recall to measure the quality of the model.
[0094] The description presented in the above exemplary embodiments is only used to illustrate the technical solution of the present invention, and is not intended to be exhaustive, nor is it intended to limit the present invention to the precise form described. Obviously, it is possible for a person of ordinary skill in the art to make many changes and variations based on the above teachings. The exemplary embodiments are selected and described to explain the specific principles of the present invention and its practical application, so that other technicians in the field can easily understand, implement and use the various exemplary embodiments of the present invention and its various selected forms and modified forms. The scope of protection of the present invention is intended to be defined by the attached claims and their equivalent forms.
Claims
1. A fish intelligent sorting method based on variable step-size learning rate optimization strategy, characterized in that: Here are the steps: Step 1: Build a feature extraction network based on transfer learning 1.
1. Building a Dataset Taking three kinds of fish A, B, and C and other species of mixed fish as the objects, we collected images of fish to construct a data set of four kinds of fish; 1.2 Image Preprocessing The images in the dataset are unified into RGB three-channel images with a size of 224*224 and normalized; 1.
3. Transfer learning of lightweight neural network models Select the lightweight neural network ResNet18 basic model for transfer learning; For the classification of three types of fish, A, B, and C, based on the lightweight neural network ResNet18, according to the number of corresponding fish categories, the original fully connected layer output OutputSize of the lightweight neural network ResNet18 is set to 3, and the weight parameters of the network ResNet18 are retrained; at the same time, in order to prevent overfitting, the SGDM algorithm and the loss function with L2 regularization penalty term are selected to enhance the generalization performance of the network and obtain a convergent and stable objective function; Step 2: Variable step size learning rate optimization strategy By analyzing the changing rules of learning rate and validation set accuracy, a variable step-size learning rate optimization strategy is proposed. The core idea of the variable step-size learning rate optimization strategy is to use the idea of interval subdivision to represent the accuracy coefficient of each interval by the training result of each interval. Specifically, m Previously, the two sides of the local optimal solution of the optimization interval in this round are selected as the target interval of the next round, and the optimization is cyclically performed until the target accuracy is reached, and the global optimal learning rate corresponding to the target accuracy is determined; Taking the accuracy of the validation set as an indicator, we optimized the variable step learning rate to improve the efficiency of model training. 2.
1. Variable step learning rate selection rules [1*10 -5 , 1] The learning rate is selected in the interval [1*10 -5 , 0.1] interval, the learning rate is selected by the learning rate selection method with a small variable step size; in the remaining interval (0.1, 1], the learning rate selection method with a larger equal step size is adopted; 2.1.1 Rapid positioning in large areas In the interval [1*10 -5 , 0.1], the learning rate is selected with a small step size, and the learning rate lr1 is selected with the following formula: k2 is the maximum value of the overall learning rate interval, which is 1. The larger the parameter n is, the smaller the step size is. The parameter n is a positive integer and is selected in the range of [1,5]. In the interval (0.1, 1], select the learning rate lr2 with a larger step size s1 of equal amplitude. The formula is as follows: lr2=m*s1(3) k1 is the maximum value of the learning rate experience interval 0.1, k2 is the maximum value of the learning rate overall interval 1, parameter p is a positive integer 9; parameter m is a positive integer selected in the range [2,10]; 2.1.
2. Accurate optimization of small intervals The precise optimization of small intervals is based on the rapid positioning of large intervals. The network model is trained according to the various learning rates in the rapid positioning of large intervals as hyperparameters, and the learning rate lr corresponding to the maximum accuracy in the training results is b As the benchmark, select the learning rate lr on the left side of the benchmark l , right learning rate lr r , respectively as the left and right values of the small interval, and perform precise optimization in this small interval; The precise optimization of the small interval takes s2 as the step size, and the learning rate selection formula is as follows: When lr b -lr l ≤10k m hour, s2=k m (4) lr1 * =lr l +s2(5) k m is the learning rate accuracy, an artificially set value, lr1 * Take the updated learning rate value; When lr b -lr l ≥10k m hour, lr1 * =lr l +s2(7) The parameter p is a positive integer 9, lr1 * Take the updated learning rate value; Similarly, when lr r -lr b ≤10k m hour, s2=k m (8) lr2 * =lr b +s2(9) k m is the learning rate precision, lr2 * Take the updated learning rate value; When lr r -lr b ≥10k m hour, lr2 * =lr b +s2(11) The parameter p is a positive integer 9, lr2 * Take the updated learning rate value; 2.
2. Variable step length learning rate optimization process If the accuracy is lower than 80% for three consecutive times or the interval learning rate is fully taken, the optimization round is interrupted and the next optimization round begins; The interval length is less than or equal to k m Or when the accuracy of the validation set is higher than 99%, the optimization ends and the best learning rate is output; the interval length is greater than k m Or when the accuracy of the validation set is lower than 99%, the optimization continues, and the steps of precise optimization between small intervals are repeated; Step 3: Output target classification results The fish are classified with a threshold of 0.
95. If the judgment result of a certain fish for a certain species is greater than 0.95, the fish is judged to be of the corresponding species. If the judgment results of a certain fish for Class A, Class B, and Class C are all less than 0.95, the fish is judged to be other interfering fish.
Citation Information
Patent Citations
Mushroom recognition method based on deep transfer learning model
CN111611924A
Method for detecting foreign matters in tilapia fillets based on fluorescence excitation
CN116740701A