Pitaya counting method based on YOLOv8

By replacing the backbone network and adding CA attention mechanism in the YOLOv8 model, combined with the ByteTracker tracker, the problems of slow inference speed and large parameters of the dragon fruit counting model are solved, and efficient and accurate dragon fruit counting is achieved, which is suitable for mobile device deployment. , reducing the intensity and labor costs of fruit farmers.

CN119274054AActive Publication Date: 2025-01-07SOUTH CHINA AGRICULTURAL UNIVERSITY +1
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411293067.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-14
Publication Date
2025-01-07
Estimated Expiration
2044-09-14

Smart Images

  • Figure CN119274054A_ABST
    Figure CN119274054A_ABST
Patent Text Reader

Abstract

The invention discloses a pitaya counting method based on YOLOv8. The pitaya counting method comprises the following steps: firstly, making a pitaya detection image data set through pitaya image acquisition, pitaya image scaling, pitaya image labeling and pitaya image and labeling file division; then acquiring a pitaya video by using video shooting equipment; constructing a pitaya counting model which comprises an improved detector, a tracker and a counter; training and testing an improved detector in the pitaya counting model by using the pitaya detection image data set; and finally, counting the pitaya fruits in the collected pitaya video by using a pitaya counting model. The invention aims to improve the reasoning speed of the model and reduce the parameter quantity of the model by improving the YOLOv8 model and realize efficient pitaya counting.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of fruit counting, and particularly relates to a pitaya counting method based on YOLOv8. Background Art

[0002] In agricultural production, fruit counting has always been a heavy and time-consuming task, especially for fruits such as pitaya that are grown in orchards with a large spread. By building a lightweight, efficient and accurate fruit counting model and installing it on mobile devices, it can help fruit farmers reduce their workload, improve counting efficiency, and save labor costs (Rahnemoonfar M, Sheppard C. Deep count: Fruit counting based on deep simulated learning [J]. Sensors, 2017, 17 (4).). The literature (Li P, Zheng J, Li P, et al. Tomato maturity detection and counting model based on MHSA-YOLOv8 [J]. Sensors, 2023, 23 (15).) proposed a fruit counting model based on YOLOv8, which uses a YOLOv8 detection model with an added MHSA attention mechanism. The addition of the MHSA attention mechanism can improve the detection accuracy, but at the same time it will reduce the inference speed of the model. Therefore, when using a YOLOv8-based model for fruit counting, an efficient attention mechanism is required, that is, an attention mechanism that expands the model's attention to effective information without reducing the model's reasoning speed (Hou Q, Zhou D, Feng J. Coordinate attention for efficient mobile network design [C] / / Proceedings of the 2021 IEEE / CVF Conference on Computer Vision and Pattern Recognition. 2021: 13708-13717.). In addition, the backbone network of the fruit counting model in the literature (Li P, Zheng J, Li P, et al. Tomato maturity detection and counting model based on MHSA-YOLOv8 [J]. Sensors, 2023, 23 (15).) is composed of convolutional modules with a large number of parameters, which is not easy to be installed on mobile devices. Therefore, it is of great theoretical significance and application value to study how to improve the YOLOv8 model to improve the model's reasoning speed and reduce the number of model parameters to achieve efficient dragon fruit counting. Summary of the invention

[0003] The main purpose of the invention is to overcome the shortcomings and deficiencies of the prior art, provide a pitaya counting method based on YOLOv8, reduce the workload of fruit farmers, improve the efficiency of pitaya counting, and save labor costs.

[0004] In order to achieve the above object, the present invention adopts the following technical solutions:

[0005] The present invention provides a pitaya counting method based on YOLOv8, comprising the following steps:

[0006] S1, creating a pitaya detection image dataset by acquiring pitaya images, scaling pitaya images, annotating pitaya images, and dividing pitaya images and annotation files;

[0007] S2, using video shooting equipment to collect dragon fruit video;

[0008] S3. Construct a pitaya counting model, including an improved detector, a tracker and a counter; the improved detector is constructed based on the existing YOLOv8 model and is used to detect pitaya fruits; the tracker is an existing ByteTracker tracker, which is used to track pitaya fruits; the counter is a renamed existing counter, which is used to output a pitaya counting result dictionary;

[0009] S4. Use the pitaya detection image dataset to train and test the improved detector in the pitaya counting model;

[0010] S5. Apply the pitaya counting model to count the pitaya fruits in the collected pitaya video.

[0011] As a preferred technical solution, the steps of preparing a pitaya detection image data set are as follows:

[0012] S101, dragon fruit image acquisition: determine the number of dragon fruit categories and fruit category names according to demand; use an image acquisition device to acquire the dragon fruit image in the natural environment of the orchard and save it in a folder;

[0013] S102, pitaya image scaling: scaling the pitaya images in the folder to 3*W*H pixel size, where W is the width of the scaled image and H is the height of the scaled image;

[0014] S103, pitaya image annotation: select the scaled pitaya image in the folder and annotate the real fruit category name, and save the annotation file;

[0015] S104, pitaya image and annotation file division: the processed pitaya images and their corresponding annotation files are randomly divided into a training set, a test set and a validation set in proportion to obtain a pitaya detection image dataset.

[0016] As a preferred technical solution, the dragon fruit counting model is constructed as follows:

[0017] S301, constructing an improved detector: constructing an original detector based on the existing YOLOv8 model, including a backbone network, a neck network and a head network; improving the original detector by lightweighting the backbone network and adding an attention mechanism to the neck network, thereby obtaining an improved detector in the pitaya counting model;

[0018] S302, calling and initializing the ByteTracker tracker: calling and initializing the existing ByteTracker tracker, and then using the tracker to calculate the output of the improved detector;

[0019] S303, rename the existing counter as Counter and call it.

[0020] As a preferred technical solution, the lightweighting of the backbone network refers to combining the CBRM block and the Shuffle_Block block in the existing ShuffleNetv2 network to replace the backbone network of the original detector.

[0021] As a preferred technical solution, the adding of the attention mechanism to the neck network refers to adding the CA attention mechanism after the Bottleneck block in each C2f block in the neck network of the original detector.

[0022] As a preferred technical solution, the training and testing of the improved detector in the pitaya counting model is specifically as follows:

[0023] S401. Improved detector in training dragon fruit counting model:

[0024] The training set images and the validation set images are converted into training set image tensors and validation set image tensors respectively, the training set annotation files and the validation set annotation files are converted into training set true label tensor lists and validation set true label tensor lists respectively, and the training set image tensors and the validation set image tensors are normalized to obtain normalized training set image tensors and normalized validation set image tensors respectively;

[0025] Set the training batch size, momentum, learning rate and number of training iterations, and use the obtained normalized training set image tensor and normalized validation set image tensor as well as the training set true label tensor list and validation set true label tensor list for training; after the training is completed, automatically save the optimal model parameter tensor to the parameter file;

[0026] S402. Test the improved detector in the dragon fruit counting model:

[0027] Convert the test set image into a test set image tensor, convert the test set annotation file into a list of true label tensors of the test set, and normalize the test set image tensor to obtain a normalized test set image tensor;

[0028] Load the current optimal model parameter tensor in the saved parameter file to the improved detector in the constructed dragon fruit counting model;

[0029] The normalized test set image tensor is used as the input of the improved detector in the dragon fruit counting model loaded with the current optimal model parameter tensor to obtain the predicted label tensor list of the test set images;

[0030] Accuracy, average precision, recall, inference speed and number of model parameters are used as evaluation indicators, and the performance of the improved detector in the pitaya counting model is evaluated using the true label tensor list and the obtained predicted label tensor list of the pitaya image.

[0031] As a preferred technical solution, the pitaya fruits in the collected pitaya video are counted, specifically:

[0032] S501, converting the video to be counted into a tensor, and loading the tensor and the current optimal model parameter tensor in the saved parameter file into the constructed pitaya counting model;

[0033] S502: Obtain a final counting result dictionary through a pitaya counting model.

[0034] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0035] The pitaya counting model constructed by the present invention includes an improved detector, a tracker and a counter, which can realize the detection and counting of pitaya. On the one hand, because the backbone network combining the CBRM block and the Shuffle_Block block is used in the improved detector, compared with the original detector, the improved detector of the present invention not only has fewer model parameters but also has a faster detection speed. On the other hand, because the CA attention mechanism is added after the Bottleneck block in each C2f block in the neck network of the improved detector, the improved detector of the present invention can not only obtain information between channels, but also consider direction-related position information, which is helpful to better locate and identify pitaya fruits. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 This is an overall flow chart of a dragon fruit counting method based on YOLOv8.

[0037] Figure 2 Schematic diagram of the structure of the CountMD counting model.

[0038] Figure 3 Detector Impr Schematic diagram of the improved detector structure.

[0039] Figure 4 Schematic diagram of the structure of C2f-CA.

[0040] Figure 5 This is the effect diagram of dragon fruit counting. DETAILED DESCRIPTION

[0041] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention are described in further detail below.

[0042] Example 1

[0043] like Figure 1 As shown, a pitaya counting method based on YOLOv8 includes the following steps:

[0044] S1. Create a dragon fruit detection image dataset.

[0045] S2. Use video shooting equipment to capture dragon fruit videos.

[0046] S3. Construct CountMD counting model.

[0047] S4. Train and test the Detector in the CountMD counting model Impr Improved detector.

[0048] S5. Apply the CountMD counting model.

[0049] Furthermore, in step S1, a pitaya detection image dataset is prepared, and the steps are as follows:

[0050] S101, dragon fruit image acquisition: In this embodiment, the number of fruit categories is determined to be nmCPt=3, and the fruit category name is neCPt={unripe fruit, pigmented fruit, ripe fruit}, i.e., unripe fruit, pigmented fruit, and ripe fruit; 1694 dragon fruit images in jpg format with a resolution of 3904*2928 are taken in the natural environment of the orchard using a smart phone. Next, rename the image file in OIm to Among them, NOIm j OIm jThe file name does not include the extension; then, create a pitaya folder, create a pitaya-ori folder in it, and store the 1694 dragon fruit images OIm in the pitaya-ori folder.

[0051] S102, pitaya image scaling: In this embodiment, a pitaya-zoom folder is created in the pitaya folder, and the Torchvision library in Python is used to scale the 1694 images OIm in the pitaya-ori folder, and the size of the images is scaled to 3*640*640 pixels. Then, the 1694 images generated after scaling are The image is stored in the pitaya-zoom folder, where the non-extension part of the file name of the image SIm is NOIm.

[0052] S103, pitaya image labeling: In this embodiment, the specific steps of pitaya image labeling are as follows: (1) Create a labelstxt folder in the pitaya folder. (2) Open the labelImg tool and use it to open the pitaya-zoom folder, and label the 1694 scaled images SIm in the folder one by one, that is, ①k∈{1,…,nTBSI j}: Drag the mouse to frame the pitaya fruit k with a rectangular frame, and enter the fruit category name of the pitaya fruit k in labelImg, where nTBSI j Image SIm j Then, labelImg will automatically calculate the category index (tix) of pitaya fruit k. j [k], coordinates of the center of the rectangle ((tx0) j [k],(ty0) j [k]), rectangular frame width (tw) j [k] and rectangle height (th) j [k], where (tix) j [k]∈{0,…,2}. ② For image SIm j After the above operation ① is performed, a file named NOIm is automatically created by labelImg j And the annotation file LTx with the extension txt j Save to the labelstxt folder. (3) Close the labelImg tool. Annotation files for all 1694 images SIm.

[0053] S104, pitaya image and annotation file division: In this embodiment, the specific steps of pitaya image and annotation file division are as follows: first, create a pitaya1 folder, and create three folders in the pitaya1 folder: train, test, and val, which are used to store training set images and annotation files, test set images and annotation files, and validation set images and annotation files, respectively. Secondly, create images folders in the train, test, and val folders to store jpg format files, and labels folders to store txt format files. Let the division ratio of image SIm and annotation file LTx be P tr :P te :P va =7:2:1. Next, using the random library in Python, the 1694 images SIm in the pitaya-zoom folder in step S102 are divided into training set images TrI = {TrI1, ..., TrI 1185}, test set image TeI={TeI1,…,TeI 340} and validation set images VaI={VaI1,…,VaI 169}, where 1185 = |TrI|, 340 = |TeI| and 169 = |VaI| are the number of images in the training set, test set and validation set respectively. Then, Sim = TrI∪TeI∪VaI, 1694 = 1185+340+169, where [1185,340,169] = [7,2,1]*(1694 / (7+2+1)). Move the training set image TrI to the images folder under the train folder, move the test set image TeI to the images folder under the test folder, and move the validation set image VaI to the images folder under the val folder. Divide the label file LTx in the labelstxt folder into the training set label files LrT = {LrT1,…,LrT 1185}, test set annotation file LeT = {LeT1,…,LeT 340} and the validation set annotation file LaT = {LaT1,…,LaT 169}, where 1185 = |LrT|, 340 = |LeT| and 169 = |LaT| are the number of labeled files in the training set, test set and validation set, respectively. Then, LTx = LrT∪LeT∪LaT. Move the training set label file LrT to the labels folder under the train folder, move the test set label file LeT to the labels folder under the test folder, and move the validation set label file LaT to the labels folder under the val folder. Let TrD = {(TrI1,LrT1),…,(TrI 1185 ,LrT 1185 )} is the training set, TeD={(TeI1,LeT1),…,(TeI 340 ,LeT 340 )} is the test set, VaD={(VaI1,LaT1),…,(VaI 169 ,LaT 169 )} is the validation set. Then, the dragon fruit detection image dataset is: PtD = TrD∪TeD∪VaD.

[0054] In step S2 of the present application, the video shooting device is not limited to traditional video cameras, cameras and other shooting devices, as long as the device has the function of video shooting and recording is included; the format of the captured video is not limited to mp4, 3gp, and mov. In this embodiment, a smart phone is used to collect dragon fruit videos in the natural environment of the orchard, and a total of nmPV=1 segment of dragon fruit videos in mp4 format PV={PV 1},in For the first video, is the tth frame in the first video segment, and 256 is the number of frames in the first video segment.

[0055] Furthermore, the specific steps for S3 to build the CountMD counting model are as follows: Build Detector Impr Improve the detector, call and initialize the ByteTracker tracker, and rename the existing counter to Counter and call it. The constructed CountMD counting model can be expressed as CountR = CountMD (TInput, ω CtM ), where CountMD is the model name, TInput is the input tensor of the CountMD model, ω CtM is the model parameter tensor to be trained, and CountR is the model's counting result dictionary.

[0056] S301. Build Detector ImprImproved detector: In this example, the original detector Detector is constructed based on the YOLOv8 model developed by the Ultralytics team (https: / / github.com / ultralytics / ultralytics) yolov8 , where Detector yolov8 Contains BackBone network yolov8 , Neck network yolov8 and Head Network yolov8 , and then by improving Detector yolov8 To construct the improved detector LsTLP=Detector in the CountMD counting model Impr (TInput,ω DI ), where Detector Impr is the name of the improved detector, TInput is the input tensor of the improved detector, ω DI is the parameter tensor of the improved detector to be trained, and LsTLP is the list of predicted label tensors of the improved detector, such as Figure 3 As shown, specifically:

[0057] (1) For the original detector Detector yolov8 BackBone yolov8 Lightweight to get BackBone Impr :

[0058] The CBRM block and Shuffle_Block block in the existing ShuffleNetv2 network are combined to obtain BackBone Impr In this embodiment, the ShuffleNetv2 network in the document (Ma N, Zhang X, Zheng HT, et al. ShuffleNet V2: Practical guidelines for efficient CNN architecture design [C] / / Proceedings of the 15th European Conference on Computer Vision. 2018: 122-138.) is used.

[0059] (2) For the original detector Detector yolov8 Neck Network yolov8 Improved to get Neck Impr :

[0060] First, the neck network yolov8The C2f block in is improved to a C2f-CA block, such as Figure 4 As shown in Figure 1, by adding the CA attention mechanism to the Bottleneck block in the C2f block, the n Bottleneck blocks in the C2f block are improved to Bottleneck-CA blocks, while the convolutional blocks, Split blocks, and connection function blocks in the C2f block remain unchanged. yolov8 Each C2f block in is replaced by a C2f-CA block, and Neck yolov8 The connection function block, upsampling function block, and convolution block in remain unchanged. In this embodiment, the CA attention mechanism in the literature (Hou Q, Zhou D, Feng J. Coordinate attention for efficient mobile network design [C] / / Proceedings of the 2021 IEEE / CVF Conference on Computer Vision and Pattern Recognition. 2021: 13708-13717.) is adopted.

[0061] Therefore, the improved detector Detector in the CountMD counting model of this application Impr It can be expressed as: Detector Impr (TInput,ω DI )=Head yolov8 (Neck Impr (BackBone Impr (TInput,ω BI ),ω NI ),ω H ), where ω BI BackBone Impr The parameter tensor of ω NI It's Neck Impr The parameter tensor of ω H It's Head yolov8 Then, Detector Impr The model parameter tensor to be trained is ω DI =[ω BI ,ω NI ,ω H ].

[0062] S302, call and initialize the ByteTracker tracker: In this embodiment: First, according to the method in the document (Zhang Y, Sun P, Jiang Y, et al. ByteTrack: Multi-object tracking by associating every detection box [C] / / Proceedings of the 17th European Conference on Computer Vision. 2022: 1-21.), create a ByteTracker tracker and initialize it using the method in the document, where the initialization control parameters include image size img_size = 640, confidence conf = 0.25 and intersection-over-union ratio iou = 0.7, and the corresponding values ​​are set with reference to the document; then, the improved detector Detector Impr The output LsTLP is used as the input of the ByteTracker tracker, and the output TTOut is calculated by the ByteTracker tracker, which is expressed as TTOut=ByteTracker(LsTLP).

[0063] S303, rename the existing counter to Counter and call: In this embodiment: First, download the code from the URL https: / / github.com / Umar-Saeed-97 / Vehicle-Count, and rename the existing counter in the code to Counter. Secondly, use the output TTOut of the ByteTracker tracker as the input of the Counter. Then, use the trajectory drawing module of the Counter counter to draw the motion trajectory of each tracked pitaya fruit in TTOut. Then, use the video counting processing module of the Counter counter to process TTOut and obtain the model's counting result dictionary CountR, which is expressed as: where nneCPt k is the predicted neCPt k The number of dragon fruits of the category.

[0064] Finally, the CountMD counting model is obtained, such as Figure 2 As shown, it is expressed as: CountMD(TInput,ω CtM )=Counter(ByteTracker(Detector Impr (TInput,ω DI ))),ω CtMThe parameters that need to be trained for the CountMD counting model.

[0065] Furthermore, train and test the Detector in the CountMD counting model Impr Improve the detector, specifically:

[0066] S401. Train Detector in CountMD counting model Impr Improved detector:

[0067] (1) In this embodiment: First, the 1185 training set images TrI and the 169 validation set images VaI in step S104 are converted into training set image tensors TTrI and validation set image tensors TVaI, respectively, and the 1185 training set annotation files LrT and the 169 validation set annotation files LaT in step S104 are converted into training set true label tensor lists LsTLTr and validation set true label tensor lists LsTLTa, respectively. Then, the tensors TTrI and TVaI are normalized to obtain normalized training set image tensors TNTrI and normalized validation set image tensors TNVaI, respectively.

[0068] (2) In this embodiment, the training batch size is set to batchsize = 16, momentum momentum = 0.973, learning rate lr = 0.01, and training iteration number epochs = 150. The TNTrI, TNVaI, LsTLTr and LsTLTa obtained in step S401 (1) are input into the training module of the improved detector in the CountMD counting model for training. After the training is completed, the training module automatically converts the optimal model parameter tensor ω DI Save to the best.pt parameter file.

[0069] S402. Test the Detector in the CountMD counting model Impr Improved detector:

[0070] (1) In this embodiment: First, the 340 test set images TeI in step S104 are converted into test set image tensors TTeI, and the 340 test set annotation files LeT in step S104 are converted into test set true label tensor lists LsTLTe. Then, the tensor TTeI is normalized to obtain a normalized test set image tensor TNTeI.

[0071] (2) The current optimal model parameter tensor ω in the saved best.pt parameter file DI Load into the Detector constructed in step S301 Impr Improved detector.

[0072] (3) The normalized test set image tensor TNTeI is used as the tensor ω loaded with the current optimal model parameters DI Detector Impr Improve the detector input. By LsTLP = Detector Impr (TInput,ω DI ) gets the predicted label tensor list of the test set image TeI.

[0073] (4) Accuracy, average precision, recall, inference speed and model parameter count are used as evaluation indicators, and the true label tensor list LsTLTe and the obtained predicted label tensor list LsTLP of the pitaya image are used to evaluate the Detector Impr Improve the detector for performance evaluation. As shown in Table 1, Detector Impr The parameter size is 5.9M, the inference speed is 2.0ms, the accuracy is 86.5%, the recall rate is 84.6%, and the average precision is 90.1%.

[0074] Table 1 Based on Detector Impr Evaluation of pitaya fruit detection performance

[0075] Evaluation Metrics Evaluation index value Accuracy / % 86.5 Recall / % 84.6 Average accuracy / % 90.1 Model parameter quantity / M 5.9 Inference speed / ms 2.0

[0076] Furthermore, the specific steps of applying the CountMD counting model in S5 are:

[0077] S501, convert the video PV to be counted into a tensor, and compare the tensor with the current optimal model parameter tensor ω in the saved best.pt parameter file DI Load into the CountMD counting model constructed in step S3.

[0078] S502, through CountR = CountMD (TInput, ω CtM ) to obtain the final counting result dictionary. The effect of using the CountMD counting model to count the dragon fruits in the video PV is as follows Figure 5 As shown in the figure, the counting results are ripe fruit: 3, unripe fruit: 4, pigmented fruit: 1.

Claims

1. A pitaya counting method based on YOLOv8, characterized in that: The steps include: S1, creating a pitaya detection image dataset by acquiring pitaya images, scaling pitaya images, annotating pitaya images, and dividing pitaya images and annotation files; S2, using video shooting equipment to collect dragon fruit video; S3. Construct a pitaya counting model, including an improved detector, a tracker and a counter; the improved detector is constructed based on the existing YOLOv8 model and is used to detect pitaya fruits; the tracker is an existing ByteTracker tracker, which is used to track pitaya fruits; the counter is a renamed existing counter, which is used to output a pitaya counting result dictionary; S4. Use the pitaya detection image dataset to train and test the improved detector in the pitaya counting model; S5. Apply the pitaya counting model to count the pitaya fruits in the collected pitaya video.

2. A pitaya counting method based on YOLOv8 according to claim 1, characterized in that, The steps of making a pitaya detection image data set are as follows: S101, dragon fruit image acquisition: determine the number of dragon fruit categories and fruit category names according to demand; use an image acquisition device to acquire the dragon fruit image in the natural environment of the orchard and save it in a folder; S102, pitaya image scaling: scaling the pitaya images in the folder to 3*W*H pixel size, where W is the width of the scaled image and H is the height of the scaled image; S103, pitaya image annotation: select the scaled pitaya image in the folder and annotate the real fruit category name, and save the annotation file; S104, pitaya image and annotation file division: the processed pitaya images and their corresponding annotation files are randomly divided into a training set, a test set and a validation set in proportion to obtain a pitaya detection image dataset.

3. A pitaya counting method based on YOLOv8 according to claim 1, characterized in that, The dragon fruit counting model is constructed as follows: S301, constructing an improved detector: constructing an original detector based on the existing YOLOv8 model, including a backbone network, a neck network and a head network; improving the original detector by lightweighting the backbone network and adding an attention mechanism to the neck network, thereby obtaining an improved detector in the pitaya counting model; S302, calling and initializing the ByteTracker tracker: calling and initializing the existing ByteTracker tracker, and then using the tracker to calculate the output of the improved detector; S303, rename the existing counter as Counter and call it.

4. A pitaya counting method based on YOLOv8 according to claim 3, characterized in that, The lightweighting of the backbone network refers to combining the CBRM block and the Shuffle_Block block in the existing ShuffleNetv2 network to replace the backbone network of the original detector.

5. A pitaya counting method based on YOLOv8 according to claim 3, characterized in that, Adding the attention mechanism to the neck network refers to adding the CA attention mechanism after the Bottleneck block in each C2f block in the neck network of the original detector.

6. A pitaya counting method based on YOLOv8 according to claim 1, characterized in that, The improved detector in the training and testing dragon fruit counting model is specifically: S401. Improved detector in training dragon fruit counting model: The training set images and the validation set images are converted into training set image tensors and validation set image tensors respectively, the training set annotation files and the validation set annotation files are converted into training set true label tensor lists and validation set true label tensor lists respectively, and the training set image tensors and the validation set image tensors are normalized to obtain normalized training set image tensors and normalized validation set image tensors respectively; Set the training batch size, momentum, learning rate and number of training iterations, and use the obtained normalized training set image tensor and normalized validation set image tensor as well as the training set true label tensor list and validation set true label tensor list for training; After training is completed, the optimal model parameter tensor is automatically saved to the parameter file; S402. Test the improved detector in the dragon fruit counting model: Convert the test set image into a test set image tensor, convert the test set annotation file into a list of true label tensors of the test set, and normalize the test set image tensor to obtain a normalized test set image tensor; Load the current optimal model parameter tensor in the saved parameter file to the improved detector in the constructed dragon fruit counting model; The normalized test set image tensor is used as the input of the improved detector in the dragon fruit counting model loaded with the current optimal model parameter tensor to obtain the predicted label tensor list of the test set images; Accuracy, average precision, recall, inference speed and number of model parameters are used as evaluation indicators, and the performance of the improved detector in the pitaya counting model is evaluated using the true label tensor list and the obtained predicted label tensor list of the pitaya image.

7. A pitaya counting method based on YOLOv8 according to claim 1, characterized in that, The method of counting the pitaya fruits in the collected pitaya video is specifically as follows: S501, converting the video to be counted into a tensor, and loading the tensor and the current optimal model parameter tensor in the saved parameter file into the constructed pitaya counting model; S502: Obtain a final counting result dictionary through a pitaya counting model.

Citation Information

Patent Citations

  • Improved YOLOv5n-based winter jujube detection and counting method deployed in Android system

    CN116309414A

  • Field fruit counting method and system based on video target tracking

    CN117036238A

  • Fire smoke detection method based on lightweight YOLOv8

    CN118196489A

  • Crop identification and leaf disease detection method and system

    CN118297877A