Litchi variety identification method and litchi variety identification system
By improving the YOLOv11 network structure and building Hadoop and Flink clusters, the problem of insufficient accuracy and speed of litchi variety identification devices is solved, and efficient and accurate litchi variety identification is achieved.
Patent Information
- Application Number
- CN202510197154.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-07-18
AI Technical Summary
The existing litchi variety identification devices have problems such as poor accuracy and slow recognition speed, which is difficult to meet the performance requirements of intelligent detection of litchi quality.
Using the improved YOLOv11 network structure, the SPPFCSPC module is built by adding SimAM attention mechanism to the C2f module and combining SPPF and CSP modules to build a SPPFCSPC module to improve feature extraction capabilities, and a Hadoop and Flink cluster is built on Vwmare Workstation for parallel inference to realize lychee image recognition.
It improves the accuracy and recognition speed of lychee variety recognition, can effectively deal with complex patterns and scenarios, and meets the needs of efficient identification.
Smart Images

Figure CN120340019A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of litchi automatic identification, and in particular to a litchi variety identification method and a litchi variety identification system. Background Art
[0002] Lychee is an important cash crop widely cultivated in southern China and one of the specialty fruits in tropical and subtropical regions. Lychee fruit is rich in nutrition and has a unique flavor. It has always been loved by people because of its extremely high edible and medicinal value. Lychee variety resources are extremely rich. According to incomplete statistics, there are more than 600 varieties of lychees, with a wide variety of species and great similarity between varieties. A problem that arises in the production and research of lychees is the confusion in the naming of lychee cultivars. In many cases, this confusion is caused by human misidentification or different dialects and translation from Chinese to English. Therefore, many retailers, exporters, importers and consumers will misidentify certain lychees, which will lead to the situation where cheap lychee varieties are easily impersonated or mixed with high-end lychee varieties during the production and sales process.
[0003] Deep learning technology has demonstrated outstanding capabilities in image recognition, pattern classification and other fields, and is widely used in the agricultural field for pest and disease detection, fruit maturity judgment and variety classification. There are also devices in the prior art that use image recognition algorithms to automatically judge litchi varieties, but these devices still have the defects of poor accuracy and slow recognition speed, which makes it difficult to meet the performance requirements of intelligent detection of litchi quality.
[0004] Therefore, it is necessary to improve the existing litchi variety identification method to overcome the defects of the prior art. Summary of the invention
[0005] The present invention aims at the defects in the prior art. One of the purposes of this application is to provide a method for identifying litchi varieties. The method can effectively improve the recognition accuracy of litchi varieties with complex patterns and complex scenes, and has a high recognition speed, so as to realize efficient recognition of litchi varieties.
[0006] In order to achieve the above object, the present invention adopts the following technical solution:
[0007] The present invention provides a litchi variety identification method, comprising:
[0008] Collecting image data of litchi of different varieties, preprocessing the collected image data, and dividing the preprocessed image data into a training set and a test set;
[0009] The YOLOv11 network structure is introduced. The SimAM attention mechanism is added to the feature concatenation part of the C2f module to construct the C2f_SimAM attention module, and the C2PSA module of the backbone network of the YOLOv11 network structure is replaced.
[0010] By combining the SPPF module and the CSP module, the SPPFCSPC module is constructed into the backbone network of the YOLOv11 network structure, and the pooling layer of the YOLOv11 network structure is improved to obtain the improved YOLOv11 network structure.
[0011] The improved YOLOv11 network structure is trained and tested using the training set and the test set to obtain the optimal litchi variety recognition model, which is named the SSL_YOLOv11 model.
[0012] A virtual machine is configured on Vwmare Workstation, and a Hadoop cluster, an HDFS distributed file system, a Yarn resource scheduler, and a Flink cluster are built on the virtual machine. The litchi data to be tested is stored in the HDFS distributed file system.
[0013] The optimal litchi variety recognition model is deployed to the computing nodes of Vwmare Workstation. The litchi data to be tested read is divided into multiple subtasks by improving the operators of Flink, and parallel inference is performed on different computing nodes to achieve litchi image recognition.
[0014] In a preferred technical solution of the present invention, the adding the SimAM attention mechanism to the feature concatenation part of the C2f module to construct the C2f_SimAM attention module and replacing the C2PSA module of the backbone network of the YOLOv11 network structure includes:
[0015] Construct the C2f_SimAM attention module: The feature map of the C2f module is divided into two parts, one part is the directly transmitted feature, and the other part is the feature processed by several convolutional layers; during the process of the feature processed by the convolutional layers, multiple residual connections or feature concatenations are used to enhance the feature expression ability; then, the features processed multiple times are concatenated with the directly transmitted feature, SimAM is applied to all the concatenated features of the C2f module, and the weights calculated by SimAM are used to adjust the concatenated features, and finally the enhanced features are output to complete the construction of the C2f_SimAM attention module.
[0016] Among them, SimAM designs a full three-dimensional attention weight, considering both the spatial and channel dimensions at the same time, and its attention weight calculation formula is:
[0017]
[0018] wherein, in the formula is the normalization of s i,j ; ∈ is a constant used to prevent division-by-zero errors;
[0019] Replace the C2PSA module in the backbone network of YOLOv11 with the constructed improved C2f_SimAM module to realize the application of the C2f_SimAM module in the neural network structure of YOLOv11.
[0020] In a preferred technical solution of the present invention, by combining the SPPF module and the CSP module, the SPPFCSPC module is constructed into the backbone network of the YOLOv11 network structure, and the pooling layer of the YOLOv11 network structure is improved to obtain the improved YOLOv11 network structure, including:
[0021] Construct the SPPFCSPC module, including: inside the YOLOv11 network, by means of SPP, perform multiple MaxPool operations in parallel during convolution to perform multi-scale pooling on the input features; use the CSP module to perform partial connection on the pooled features; combine the feature maps obtained by multi-scale pooling of the SPPF module with the operations of partial connection and feature fusion of the CSP module to construct the SPPFCSPC module;
[0022] Add the constructed SPPFCSPC module to the backbone layer of YOLOv11;
[0023] After adding, modify the relevant parameters according to the network operation requirements to ensure the adaptation of the SPPFCSPC module to the network, and obtain the improved YOLOv11 network structure.
[0024] In a preferred technical solution of the present invention, the combination of the feature maps obtained by multi-scale pooling of the SPPF module with the operations of partial connection and feature fusion of the CSP module includes:
[0025] Identify the feature sources: Before performing cross-stage feature fusion, first determine the feature maps participating in the fusion;
[0026] Plan the connection method: Select the key features for connection according to the importance, relevance of the features and the impact on the model performance;
[0027] Achieve effective fusion: After determining the connected features, splice and fuse these selected features from different stages; Balance the computational complexity and feature retention: During the fusion process, continuously evaluate the change in computational complexity and the retention of important features, and ensure that key features are not lost while reducing the computational complexity by adjusting the number of connected features and the parameter settings of the convolutional layers, etc.
[0028] In a preferred technical solution of the present invention, training and testing the improved YOLOv11 network structure using a training set and a test set to obtain an optimal litchi variety recognition model includes:
[0029] From the collected litchi image dataset, divide the training set and the test set according to a preset ratio of 8:2; among them, the training set is used for learning model parameters, and the test set is used for evaluating the performance of the model;
[0030] Input the image data in the training set into the improved YOLOv11 network structure model for training; during the training process, continuously adjust the model parameters, such as weights and biases, through optimization algorithms (such as stochastic gradient descent and its variants, etc.) to improve the model's fitting ability for litchi image features;
[0031] Input the images in the test set into the trained model, and calculate the accuracy, recall rate, and F1 value of the model prediction results to evaluate the generalization ability of the model;
[0032] Adjust the model according to the evaluation results to obtain an optimal litchi variety recognition model, and name it the SSL_YOLOv11 model.
[0033] In a preferred technical solution of the present invention, adjusting the model according to the evaluation results to obtain an optimal litchi variety recognition model includes:
[0034] If the performance of the model on the test set does not meet the expectations, analyze the problems existing in the model according to the evaluation, and adjust the hyperparameters and structure of the network specifically, including: modifying the number of network layers, increasing or decreasing the number of convolutional layers, pooling layers, etc.; optimizing the activation function, selecting an activation function suitable for the litchi variety recognition task, such as ReLU, LeakyReLU, etc.; introducing a regularization strategy to prevent the model from overfitting to further improve the performance of the model;
[0035] Repeat the process of training, evaluation, and optimization, continuously adjust the model through multiple iterations, and select the model with the best performance on the test set.
[0036] In a preferred technical solution of the present invention, configuring virtual machines on Vwmare Workstation, building a Hadoop cluster, an HDFS distributed file system, a Yarn resource scheduler, and a Flink cluster on the virtual machines, and storing the litchi data to be measured in the HDFS distributed file system includes:
[0037] Create 3 Linux virtual machines in the VwmareWorkstation software;
[0038] Install Hadoop on three virtual machines respectively, and configure the core configuration files of the Hadoop cluster, including hadoop-env.sh, core-site.xml, hdfs-site.xml, mapred-site.xml, and yarn-site.xml. After the configuration is completed, start the Hadoop cluster, and check whether the cluster starts normally through relevant commands to ensure that all components of the Hadoop cluster are in a normal running state.
[0039] After the Hadoop cluster is started, perform initialization operations on HDFS, create necessary directory structures, and set the permissions of HDFS through the command-line tools or relevant APIs of Hadoop to ensure the security and accessibility of data.
[0040] In the yarn-site.xml configuration file, set the resource scheduling policy of Yarn, such as CapacityScheduler or FairScheduler, etc., and reasonably allocate cluster resources according to actual needs to ensure that each task can run efficiently. Start the Yarn service, and check whether the ResourceManager and NodeManager of Yarn are working properly through commands to ensure that the resource scheduler can schedule cluster resources normally.
[0041] Install Flink on three virtual machines, configure the relevant environment variables of Flink, modify the configuration file of Flink, set the relevant parameters of the Flink cluster, start the Flink cluster, and check the running status of the JobManager and TaskManager to ensure that the Flink cluster is working properly.
[0042] Install other libraries required by the Python script on each working node of the Flink cluster to provide support for subsequent execution of relevant tasks.
[0043] After sorting out the litchi image data to be tested, upload the data to the corresponding directory created in HDFS before through the command-line tools of Hadoop (such as the hadoop fs - put command) or relevant file upload interfaces. After the upload is completed, check whether the data is successfully stored in the HDFS distributed file system through the commands or relevant tools of Hadoop to ensure that the data can be accessed and processed by subsequent tasks.
[0044] In the preferred technical solution of the present invention, deploying the optimal litchi variety recognition model to the computing nodes of VwmareWorkstation, dividing the read litchi data to be tested into multiple subtasks through improved Flink operators, and performing parallel inference on different computing nodes to achieve litchi image recognition, including:
[0045] Convert the optimized litchi variety recognition model obtained from training into the ONNX format, and deploy the model converted into the ONNX format to 3 Linux virtual machines in Vwmare Workstation;
[0046] Use PyFlink of Flink to create a Flink task. In the Flink task, read the image dataset to be classified from HDFS (Hadoop Distributed File System) through the FileSource API;
[0047] Improve the parallelism operator of Flink, introduce the Partitioner interface to achieve dynamic partitioning; based on the variety labels of litchi images, decide to allocate the read image dataset to different partitions; each partition will be processed by a subtask;
[0048] By improving the custom operator of Flink, customize the Yolov11ModelInference function, configure the replicas and parameters of the SSL_YOLOv11 model in this function to ensure that the model can run correctly during inference; perform parallel inference on the images assigned to each subtask, summarize the inference results of each subtask, and write the summarized results to HDFS for convenient viewing and analysis of the recognition results later.
[0049] In a preferred technical solution of the present invention, the collection of litchi image data of different varieties, preprocessing of the collected image data, and division of the preprocessed image data into a training set and a test set include:
[0050] Under different shooting environments, shoot the image data of litchi;
[0051] Screen the captured image data, remove low-quality images, and classify and label the screened images according to varieties;
[0052] Perform data augmentation on the classified litchi images;
[0053] According to a preset ratio of 8:2, divide the augmented image dataset into a training set and a test set, where 80% of the images are randomly selected as the training set; the remaining 20% of the images are used as the test set.
[0054] The second object of the present invention is to provide a litchi variety recognition system, which is used to implement the litchi variety recognition method as described above.
[0055] The beneficial effects of the present invention at least include:
[0056] A method for identifying litchi varieties provided by the present invention includes: collecting litchi image data of different varieties, preprocessing the collected image data, and dividing the preprocessed image data into a training set and a test set; introducing the YOLOv11 network structure, adding a SimAM attention mechanism to the feature splicing part of the C2f module to construct a C2f_SimAM attention module, and replacing the C2PSA module of the backbone network of the YOLOv11 network structure; by combining the SPPF module and the CSP module, constructing an SPPFCSPC module into the backbone network of the YOLOv11 network structure, improving the pooling layer of the YOLOv11 network structure to obtain an improved YOLOv11 network structure; using the training set and the test set to train and test the improved YOLOv11 network structure to obtain an optimal litchi variety recognition model; configuring a virtual machine on Vwmare Workstation, building a Hadoop cluster, an HDFS distributed file system, a Yarn resource scheduler, and a Flink cluster on the virtual machine, and storing the litchi data to be measured in the HDFS distributed file system; deploying the optimal litchi variety recognition model to the computing nodes of Vwmare Workstation, dividing the read litchi data to be measured into multiple subtasks through an improved operator of Flink, and performing parallel inference on different computing nodes to achieve litchi image recognition. This method introduces a SimAM attention mechanism and constructs a C2f_SimAM attention module to replace the C2PSA module. The fully three-dimensional attention weights designed by SimAM consider both spatial and channel dimensions, weight the features after splicing of the C2f module, highlight the key features related to litchi variety recognition, suppress the interference of irrelevant information, enable the model to more accurately identify litchi varieties, effectively handle the complex patterns of litchi, and improve the recognition accuracy. Combining the SPPF and CSP modules to construct an SPPFCSPC module to improve the pooling layer. The multi-scale feature extraction ability of SPPF can capture the shape, texture and other features of litchi at different scales, and the efficient gradient transfer characteristic of CSP ensures the effective transfer of important features in the network. The combination of the two enables the model to more comprehensively and accurately extract litchi features, thereby improving the recognition accuracy. It also uses a Flink cluster for parallel inference. The parallel computing method makes full use of the cluster computing resources, greatly shortening the inference time of the model for a large number of litchi images. Compared with the traditional serial processing method, the recognition speed is significantly improved, meeting the requirements of efficient recognition. Description of the Drawings
[0057] Figure 1 is a flowchart of the litchi variety recognition method provided by the present application;
[0058] Figure 2 is a schematic diagram of the recognition results of different litchi varieties provided by the embodiments of the present application. Detailed Embodiments
[0059] The preferred embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to make the present invention more thorough and complete, and to fully convey the scope of the present invention to those skilled in the art.
[0060] In the description of the present invention, the orientation or positional relationship indicated by terms such as "upper", "lower", "left", and "right" is based on the orientation or positional relationship shown in the drawings, and is only for the convenience of describing the present invention rather than requiring the present invention to be constructed and operated in a specific orientation. Therefore, it should not be construed as a limitation of the present invention.
[0061] The terms used in the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The singular forms "a", "the", and "the" used in the present invention and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0062] In the prior art, there are devices that use image recognition algorithms to automatically determine the variety of lychees, but these devices still have the defects of poor accuracy and slow recognition speed, and it is difficult to meet the performance requirements of intelligent detection of lychee quality.
[0063] Based on this, the present application provides a method for identifying lychee varieties.
[0064] See Figure 1 - Figure 2 As shown, in view of the disadvantages existing in the prior art, the present invention provides a method for identifying lychee varieties, including:
[0065] S100. Collect image data of different varieties of lychees, preprocess the collected image data, and divide the preprocessed image data into a training set and a test set;
[0066] Specifically, the steps of S100 are as follows in detail:
[0067] Under different shooting environments, shoot the image data of lychees;
[0068] Screen the captured image data, remove low-quality images, and classify and label the screened images according to varieties;
[0069] For the classified litchi images, data augmentation is performed; the litchi images in this embodiment mainly come from the Litchi Expo Center in Conghua District, Guangzhou City, Guangdong Province, ensuring the diversity and representativeness of the data and covering a variety of litchi varieties. Select the acquisition device. Use a mobile phone or a single-lens reflex camera for shooting to ensure clear image data. The shooting environment includes sunny and cloudy days. For ten different varieties of litchi, such as Baitangying, Feizixiao, Guanyinlv, etc., different lighting conditions and shooting angles are selected for shooting to increase the diversity of the target data. A total of 8,220 photos are taken, with about 800 images for each variety. Classify and store the data. According to the litchi photos of different varieties, the captured images are classified and stored in a hard disk device to form an original data set. Manually screen the 8,220 collected images to remove images with low resolution, too high exposure intensity or too dark light, and incomplete litchi, improving the quality of the data set. Classify and label the data. The screened images are classified and labeled according to the variety for subsequent data processing and model training. For the classified litchi images, perform a variety of image processing operations. Change the image hue and saturation to improve the color performance and enhance the visual effect; use the Gaussian function to blur the image to remove high-frequency noise and smooth the image; expand the data set scale through methods such as rotation, scaling, cropping, and Mixup image fusion. After data augmentation, the original data set is expanded to 10,092, with approximately 1,000 images for each variety.
[0070] According to the preset ratio of 8:2, the enhanced image data set is divided into a training set and a test set. Among them, 80% of the images are randomly selected as the training set to train the improved YOLOv11 model, enabling the model to learn the characteristics of litchi varieties; the remaining 20% of the images are used as the test set to evaluate the performance of the model and test the generalization ability of the model.
[0071] S200: Introduce the YOLOv11 network structure, add the SimAM attention mechanism to the feature splicing part of the C2f module, construct the C2f_SimAM attention module, and replace the C2PSA module in the backbone network of the YOLOv11 network structure;
[0072] Further, step S200 specifically includes:
[0073] Construct the C2f_SimAM attention module: The feature map of the C2f module is divided into two parts, one is the directly transmitted feature, and the other is the feature processed by several convolutional layers; during the process of the feature processed by the convolutional layer, multiple residual connections or feature splicing are used to enhance the feature expression ability; then, the features after multiple processes are spliced with the directly transmitted feature, apply SimAM to all the spliced features of the C2f module, and use the weights calculated by SimAM to adjust the spliced features, and finally output the enhanced features to complete the construction of the C2f_SimAM attention module;
[0074] Among them, SimAM designs a full three-dimensional attention weight, considering both spatial and channel dimensions simultaneously. The calculation formula for its attention weight is as follows:
[0075]
[0076] Wherein, is the normalization of s i,j (In the implementation of SimAM, it is approximated by the mean and standard deviation of s_(i,j) in the entire litchi feature map or a local region of the litchi image). ∈ is a very small constant (such as 1e-4) used to prevent division-by-zero errors. This formula is actually a variant of the sigmoid function, which is used to map s_(i,j) to the interval (0,1) as the attention weight.
[0077] Replace the C2PSA module in the backbone network of YOLOv11 with the constructed improved C2f_SimAM module to realize the application of the C2f_SimAM module in the neural network structure of YOLOv11.
[0078] The replacement process is as follows: Locate the C2PSA module. In the backbone network of the YOLOv11 network structure, find the location and corresponding code part of the C2PSA module. Replacement operation. Replace the original C2PSA module with the constructed C2f_SimAM attention module according to the connection method and parameter setting requirements of the network structure. Modify relevant parameters. After the replacement, modify the corresponding parameters according to the characteristics of the C2f_SimAM module and the requirements of the entire network. In a specific embodiment, set from to -1, repeats to 2, and args to [1024, True] to ensure that the new module can operate normally in the network and cooperate with other modules to improve the network's ability to extract and recognize litchi variety features.
[0079] S300. By combining the SPPF module and the CSP module, construct the SPPFCSPC module into the backbone network of the YOLOv11 network structure, improve the pooling layer of the YOLOv11 network structure, and obtain the improved YOLOv11 network structure;
[0080] Step S300 is specifically as follows:
[0081] Construct the SPPFCSPC module, including: inside the YOLOv11 network, by means of SPP, perform multiple MaxPool operations in parallel during convolution to perform multi-scale pooling on the input features. This operation performs multi-scale pooling processing on the input features, which can extract spatial feature information from different scales, and then generate a feature map of a fixed size. In this way, the model can capture information at different scales, laying a foundation for subsequent processing of images of different sizes, and at the same time retaining as much spatial structure information as possible.
[0082] Use the CSP module to perform partial connection on the pooled features; combine the operation of partial connection and feature fusion of the feature map obtained by multi-scale pooling of the SPPF module with the CSP module to construct the SPPFCSPC module; the CSP module realizes the effective fusion of cross-stage features by selectively connecting features at different stages. In this process, both the computational amount is reduced, and it is ensured that important features can continue to flow, avoiding information loss. The constructed SPPFCSPC module has both the multi-scale feature extraction ability of SPPF and the efficient gradient transfer characteristics of CSP, which can effectively improve the accuracy of the network for litchi variety detection.
[0083] Add the constructed SPPFCSPC module to the backbone layer of YOLOv11, specifically behind the C3k2 module. This location is carefully selected so that the improved network structure can give full play to the advantages of the SPPFCSPC module when processing litchi images, optimizing the network's ability to extract and process litchi variety features.
[0084] After adding, modify the relevant parameters according to the network operation requirements to ensure the adaptation of the SPPFCSPC module to the network, and obtain the improved YOLOv11 network structure. After adding the SPPFCSPC module, the parameters need to be adjusted. Set the from parameter to -1, the repeats parameter to 1, and the args parameter to
[512] . The setting of these parameters will affect the operation mode and effect of the module in the network. Reasonable parameter adjustment helps to improve the performance of the entire network, ensuring that the improved YOLOv11 network structure can better adapt to the litchi variety recognition task. After completing the addition and parameter modification of the SPPFCSPC module and working together with other parts in the original YOLOv11 network structure, the improved YOLOv11 network structure is obtained. The improved network has a stronger multi-scale feature processing ability in the pooling layer. Through the mutual cooperation of the SPPFCSPC module and other components, the network's ability to extract and analyze litchi image features is enhanced, thereby improving the accuracy and efficiency of litchi variety detection.
[0085] Further, the operation of partially connecting and feature fusing the feature maps obtained by multi-scale pooling of the SPPF module with the CSP module includes:
[0086] Clarify the feature sources: Before performing cross-stage feature fusion, first determine the feature maps participating in the fusion.
[0087] Plan the connection method: According to the importance, relevance of the features, and the degree of influence on the model performance, select the key features for connection; specifically include: From the results of different-scale pooling operations, select those features that make significant contributions to the identification of litchi varieties, such as the parts closely related to the key features of litchi shape, texture, color, etc., and then connect them with the features output by the convolution operation. This can avoid connecting too many redundant features, thereby reducing the computational amount.
[0088] Achieve effective fusion: After determining the connected features, splice and fuse these selected features from different stages; for example: in the SPPFCSPC module, the results of each pooling operation are feature-spliced with the output of the convolution operation to combine features from different sources. Then, the spliced features are further processed through a convolutional layer, including a 1×1 and a 3×3 convolutional layer. These convolutional operations can further integrate and refine the features of litchi images from different sources, enhance the robustness of feature expression, and achieve effective cross-stage feature fusion.
[0089] Balance the computational amount and feature retention: During the fusion process, continuously evaluate the change in the computational amount and the retention of important features, and ensure that while reducing the computational amount, key features are not lost by adjusting the number of connected features and the parameter settings of the convolutional layer, etc. If it is found that the computational amount is still large, some relatively unimportant feature connections can be appropriately reduced; if it is found that some important features are lost during the fusion process, the connection strategy or convolutional operation needs to be adjusted to ensure that important features can flow smoothly in the network and maintain the accuracy of the model for litchi variety identification.
[0090] S400. Use the training set and the test set to train and test the improved YOLOv11 network structure to obtain the optimal litchi variety identification model.
[0091] Step S400 specifically includes:
[0092] From the collected litchi image dataset, divide the training set and the test set according to a preset ratio of 8:2; among them, the training set is used for learning the model parameters, and the test set is used for evaluating the model performance.
[0093] Input the image data in the training set into the improved YOLOv11 network structure model for training; during the training process, continuously adjust the model's parameters, such as weights and biases, through optimization algorithms (such as stochastic gradient descent and its variants) to improve the model's fitting ability for litchi image features;
[0094] Input the images in the test set into the trained model, and calculate the accuracy, recall rate, and F1 value of the model's prediction results to evaluate the model's generalization ability; among them, the accuracy reflects the proportion of the model correctly identifying litchi varieties; the recall rate measures the ability of the model to correctly identify all target litchi varieties; the F1 value comprehensively considers the accuracy and recall rate, and more comprehensively evaluates the model's performance. Comprehensively evaluate the model's generalization ability through these indicators, that is, the model's performance on unknown data.
[0095] Adjust the model according to the evaluation results to obtain the optimal litchi variety recognition model.
[0096] Furthermore, the adjusting the model according to the evaluation results to obtain the optimal litchi variety recognition model includes:
[0097] If the performance of the model on the test set does not meet the expectations, analyze the problems existing in the model according to the evaluation indicators, and adjust the hyperparameters and structure of the network accordingly. Modify the number of network layers, increase or decrease the number of convolutional layers, pooling layers, etc.; optimize the activation function, select an activation function more suitable for the litchi variety recognition task, such as ReLU, LeakyReLU, etc.; introduce regularization strategies, such as L1 and L2 regularization, Dropout, etc., to prevent the model from overfitting, so as to further improve the model's performance. Iterate and optimize multiple times. Repeat the process of training, evaluation, and optimization. Through multiple iterations, continuously adjust the model, and select the model with the best performance on the test set, and name it the SSL_YOLOv11 model. This model is the optimal litchi variety recognition model.
[0098] S500. Equip a virtual machine on Vwmare Workstation, and build a Hadoop cluster, HDFS distributed file system, Yarn resource scheduler, and Flink cluster on the virtual machine, and store the litchi data to be tested in the HDFS distributed file system;
[0099] The specific steps of step S500 are as follows:
[0100] In the Vwmare Workstation software, create 3 Linux virtual machines; allocate memory for each virtual machine, with one set to 8G and the other two set to 4G. This is to ensure that the subsequent cluster components have sufficient resources to support when running. Set the master node and slave nodes, clarify the roles of each virtual machine in the cluster, and prepare for the construction of a master-slave architecture cluster.
[0101] Install Hadoop on three virtual machines respectively. During the installation process, relevant environment variables of Hadoop need to be configured, such as HADOOP_HOME, etc., to ensure that the system can correctly find the installation path of Hadoop for subsequent operations. Configure the core configuration files of the Hadoop cluster, including hadoop-env.sh, core-site.xml, hdfs-site.xml, mapred-site.xml, and yarn-site.xml, etc. In these files, set the basic parameters of the Hadoop cluster, such as the access address of the file system, the data storage path, the resource scheduling method, etc. After the configuration is completed, start the Hadoop cluster and check whether the cluster starts normally through relevant commands to ensure that all components of the Hadoop cluster (such as NameNode, DataNode, etc.) are in a normal running state.
[0102] After the Hadoop cluster is started, perform initialization operations on HDFS, create necessary directory structures, such as the directory for storing the litchi data to be tested. Set the permissions of HDFS through the command-line tools or relevant APIs of Hadoop to ensure the security and accessibility of the data. For example, set the read and write permissions of users for the data directory.
[0103] Yarn resource scheduler settings: In the yarn-site.xml configuration file, set the resource scheduling policy of Yarn, such as CapacityScheduler or FairScheduler, etc., and reasonably allocate cluster resources according to actual needs to ensure that each task can run efficiently. Start the Yarn service and check whether the ResourceManager and NodeManager of Yarn are working properly through commands to ensure that the resource scheduler can correctly schedule cluster resources;
[0104] Flink cluster deployment: Install Flink on three virtual machines and configure the relevant environment variables of Flink. Set Flink to the FlinkonYarn mode. In this mode, Flink can automatically schedule resources with the help of Yarn to improve the cluster processing efficiency. Modify the configuration file of Flink (such as flink-conf.yaml) and set the relevant parameters of the Flink cluster, such as the number of JobManager and TaskManager, memory allocation, etc. Start the Flink cluster and check the running status of JobManager and TaskManager to ensure that the Flink cluster is working properly. Install other libraries relied on in the Python script on each working node of the Flink cluster, such as onnxruntime, numpy, Pillow, etc., to provide support for subsequent execution of relevant tasks.
[0105] After organizing the litchi image data to be tested, upload the data to the corresponding directory created in HDFS before through the command-line tool of Hadoop (such as the hadoop fs-put command) or the relevant file upload interface. After the upload is completed, check whether the data is successfully stored in the HDFS distributed file system through the commands or relevant tools of Hadoop to ensure that the data can be accessed and processed by subsequent tasks.
[0106] S600. Deploy the optimal litchi variety recognition model to the computing nodes of Vwmare Workstation, divide the read litchi data to be tested into multiple subtasks through the improved Flink operators, and perform parallel inference on different computing nodes to achieve litchi image recognition.
[0107] Step S600 specifically includes: The step of deploying the optimal litchi variety recognition model to the computing nodes of Vwmare Workstation, dividing the read litchi data to be tested into multiple subtasks through the improved Flink operators, and performing parallel inference on different computing nodes to achieve litchi image recognition includes:
[0108] Convert the trained optimal litchi variety recognition model into the ONNX format, and deploy the model converted into the ONNX format to 3 Linux virtual machines in Vwmare Workstation;
[0109] Use PyFlink of Flink to create a Flink task. PyFlink is a programming interface provided by Flink for Python developers, which facilitates users to write Flink application programs in the Python language. In the Flink task, read the image dataset to be classified from HDFS (Hadoop Distributed File System) through the FileSource API. HDFS is a distributed file system used to store large-scale data. The FileSource API can efficiently read the byte stream of image data from HDFS and transfer it to the input stream of the Flink job, providing a data source for subsequent processing.
[0110] Improve the parallelism operator of Flink, introduce the Partitioner interface to achieve dynamic partitioning; based on the variety labels of litchi images, decide to allocate the read image dataset to different partitions; where each partition will be processed by a subtask;
[0111] By improving the custom operator of Flink and customizing the Yolov11ModelInference function, configure the replicas and parameters of the SSL_YOLOv11 model in this function to ensure that the model can run correctly during inference; perform parallel inference on the images assigned to each subtask, summarize the inference results of each subtask, and write the summarized results to HDFS for convenient viewing and analysis of the recognition results later.
[0112] Embodiment 2
[0113] This embodiment provides a litchi variety recognition system for implementing the litchi variety recognition method as described above.
[0114] This system can efficiently and accurately recognize litchi varieties and can utilize the parallel computing power of the Flink cluster. The system deploys the optimal model to each computing node, divides the read litchi data to be measured into multiple subtasks by improving the Flink operator, and performs parallel inference on different computing nodes. This parallel processing method greatly shortens the inference time of the model for a large number of litchi images. Compared with the traditional serial processing method, it significantly improves the recognition speed and can meet the requirements for rapid litchi variety recognition in actual production.
[0115] The above are only the preferred embodiments of the present invention and are not used to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A litchi variety identification method, characterized in that, Including: Collect image data of different varieties of lychees, preprocess the collected image data, and divide the preprocessed image data into a training set and a test set; Introduce the YOLOv11 network structure, add the SimAM attention mechanism to the feature splicing part of the C2f module, construct the C2f_SimAM attention module, and replace the C2PSA module in the backbone network of the YOLOv11 network structure; By combining the SPPF module and the CSP module, construct the SPPFCSPC module into the backbone network of the YOLOv11 network structure, and improve the pooling layer of the YOLOv11 network structure to obtain the improved YOLOv11 network structure; Use the training set and the test set to train and test the improved YOLOv11 network structure to obtain the optimal lychee variety recognition model; Equip a virtual machine on Vwmare Workstation, build a Hadoop cluster, an HDFS distributed file system, a Yarn resource scheduler, and a Flink cluster on the virtual machine, and store the to-be-tested lychee data in the HDFS distributed file system; Deploy the optimal lychee variety recognition model to the computing nodes of Vwmare Workstation, divide the read to-be-tested lychee data into multiple subtasks through improving the operators of Flink, and perform parallel inference on different computing nodes to achieve lychee image recognition.
2. The lychee variety recognition method according to claim 1, wherein: The adding the SimAM attention mechanism to the feature splicing part of the C2f module, constructing the C2f_SimAM attention module, and replacing the C2PSA module in the backbone network of the YOLOv11 network structure includes: Construct the C2f_SimAM attention module: The feature map of the C2f module is divided into two parts, one part is the directly transmitted feature, and the other part is the feature processed by several convolutional layers; during the process of the feature processed by the convolutional layers, multiple residual connections or feature splicing are used to enhance the feature expression ability; then, the features processed multiple times are spliced with the directly transmitted feature, apply SimAM to all the spliced features of the C2f module, adjust the spliced features with the weights calculated by SimAM, and finally output the enhanced features to complete the construction of the C2f_SimAM attention module; Among them, SimAM designs a full three-dimensional attention weight, considering both the spatial and channel dimensions at the same time, and its attention weight calculation formula is: where, in the formula is the normalization of s i,j ; ∈ is a constant used to prevent division-by-zero errors Replace the C2PSA module in the backbone network of YOLOv11 with the constructed improved C2f_SimAM module to realize the application of the C2f_SimAM module in the neural network structure of YOLOv11.
3. The lychee variety recognition method according to claim 1, wherein: The constructing the SPPFCSPC module into the backbone network of the YOLOv11 network structure by combining the SPPF module and the CSP module, and improving the pooling layer of the YOLOv11 network structure to obtain the improved YOLOv11 network structure includes: Construct the SPPFCSPC module, including: inside the YOLOv11 network, by means of SPP, perform multiple MaxPool operations in parallel during convolution to perform multi-scale pooling on the input features; use the CSP module to perform partial connection on the pooled features; combine the feature maps obtained by multi-scale pooling of the SPPF module with the operations of partial connection and feature fusion of the CSP module to construct the SPPFCSPC module; Add the constructed SPPFCSPC module to the backbone layer of YOLOv11; After adding, modify the relevant parameters according to the network operation requirements to ensure the adaptation of the SPPFCSPC module to the network, and obtain the improved YOLOv11 network structure.
4. The litchi variety recognition method according to claim 3, wherein: The combination of the operation of partially connecting and feature fusing the feature maps obtained by multi-scale pooling of the SPPF module with the CSP module includes: Clarify the feature source: Before performing cross-stage feature fusion, first determine the feature maps participating in the fusion; Plan the connection method: Select the key features for connection according to the importance, relevance of the features and the degree of influence on the model performance; Achieve effective fusion: After determining the connected features, splice and fuse these selected features at different stages; Balance the computational amount and feature retention: During the fusion process, continuously evaluate the change in the computational amount and the retention of important features, and ensure that key features are not lost while reducing the computational amount by adjusting the number of connected features and the parameter settings of the convolutional layer, etc.
5. The litchi variety recognition method according to claim 1, wherein: The training and testing of the improved YOLOv11 network structure using the training set and the testing set to obtain the optimal litchi variety recognition model includes: From the collected litchi image dataset, divide the training set and the testing set according to a preset ratio of 8:2; among them, the training set is used for learning the model parameters, and the testing set is used for evaluating the performance of the model; Input the image data in the training set into the improved YOLOv11 network structure model for training; during the training process, continuously adjust the model parameters through an optimization algorithm to improve the fitting ability of the model to the litchi image features; Input the images in the testing set into the trained model, and calculate the accuracy, recall rate, and F1 value of the model prediction results to evaluate the generalization ability of the model; Adjust the model according to the evaluation results to obtain the optimal litchi variety recognition model.
6. The litchi variety recognition method according to claim 1, wherein: The adjustment of the model according to the evaluation results to obtain the optimal litchi variety recognition model includes: If the performance of the model on the testing set does not meet the expectations, analyze the problems existing in the model according to the evaluation, and adjust the hyperparameters and structure of the network, specifically including: modifying the number of network layers, increasing or decreasing the number of convolutional layers, pooling layers, etc.; optimizing the activation function and selecting an activation function suitable for the litchi variety recognition task; introducing a regularization strategy to prevent the model from overfitting to further improve the performance of the model; Repeat the process of training, evaluation, and optimization. Through multiple iterations, continuously adjust the model and select the model with the best performance on the test set.
7. The litchi variety identification method according to claim 1, characterized in that: Equip a virtual machine on Vwmare Workstation, and build a Hadoop cluster, HDFS distributed file system, Yarn resource scheduler, and Flink cluster on the virtual machine. Store the litchi data to be measured in the HDFS distributed file system, including: Create 3 Linux virtual machines in the Vwmare Workstation software; Install Hadoop on the 3 virtual machines respectively, and configure the core configuration files of the Hadoop cluster, including hadoop-env.sh, core-site.xml, hdfs-site.xml, mapred-site.xml, and yarn-site.xml; after completion of the configuration, start the Hadoop cluster, and check whether the cluster starts normally through relevant commands; After the Hadoop cluster is started, perform initialization operations on HDFS, create the necessary directory structure, and set the permissions of HDFS through the command-line tools or relevant APIs of Hadoop to ensure the security and accessibility of the data; In the yarn-site.xml configuration file, set the resource scheduling policy of Yarn, allocate cluster resources according to actual needs, and ensure that each task can run efficiently; start the Yarn service, and check whether the ResourceManager and NodeManager of Yarn are working properly through commands to ensure that the resource scheduler can normally schedule the cluster resources; Install Flink on the 3 virtual machines, configure the relevant environment variables of Flink, modify the configuration file of Flink, set the relevant parameters of the Flink cluster, start the Flink cluster, and check the running status of the JobManager and TaskManager to ensure that the Flink cluster is working properly; Install other libraries relied on in the Python script on each working node of the Flink cluster to provide support for subsequent execution of relevant tasks; After sorting out the litchi image data to be measured, upload the data to the corresponding directory created in HDFS before through the command-line tool of Hadoop; after the upload is completed, check whether the data is successfully stored in the HDFS distributed file system through the commands or relevant tools of Hadoop to ensure that the data can be accessed and processed by subsequent tasks.
8. The litchi variety identification method according to claim 7, characterized in that: Deploy the optimal litchi variety identification model to the computing nodes of Vwmare Workstation, divide the read litchi data to be measured into multiple subtasks through improving the operators of Flink, and perform parallel inference on different computing nodes to achieve litchi image recognition, including: Convert the optimized litchi variety recognition model obtained from training into the ONNX format, and deploy the model converted to the ONNX format to 3 Linux virtual machines in Vwmare Workstation; Use PyFlink of Flink to create a Flink task. In the Flink task, read the image dataset to be classified from HDFS through the FileSource API; Improve the parallelism operator of Flink, introduce the Partitioner interface to achieve dynamic partitioning; based on the variety labels of litchi images, decide to allocate the read image dataset to different partitions; each partition will be processed by a subtask; By improving the custom operator of Flink, customize the Yolov11 ModelInference function, configure the replicas and parameters of the optimized litchi variety recognition model in this function to ensure that the model can run correctly during inference; perform parallel inference on the images assigned to each subtask, summarize the inference results of each subtask, and write the summarized results to HDFS for convenient viewing and analysis of the recognition results later.
9. The litchi variety recognition method according to any one of claims 1-8, characterized in that: The collection of litchi image data of different varieties, the preprocessing of the collected image data, and the division of the preprocessed image data into a training set and a test set include: Under different shooting environments, shoot the image data of litchi; Screen the captured image data, remove low-quality images, and classify and label the screened images according to varieties; Perform data augmentation on the classified litchi images; Divide the augmented image dataset into a training set and a test set according to a preset ratio of 8:2, where 80% of the images are randomly selected as the training set; the remaining 20% of the images are used as the test set.
10. A litchi variety identification system, characterized in that: For implementing the litchi variety recognition method according to any one of claims 1-9.
Citation Information
Cited By
Litchi crown image parallel segmentation method based on Hadoop and U-Net unmanned aerial vehicle remote sensing
CN116645376A
Crop variety identification method and device and storage medium
CN121438088A
Litchi fruit detection method and device based on improved YOLOv8n
CN121982706A