Dead snail detection and counting method based on YOLOv5 and PyQt5
Through the combination of YOLOv5 and PyQt5, the rapid identification and counting of field snails is achieved, which solves the problem of low efficiency of identification and counting of dead snails in the existing technology, and provides an efficient and objective automated solution suitable for field snail breeding and scientific research. .
Patent Information
- Application Number
- CN202410863528.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-29
- Publication Date
- 2024-09-24
AI Technical Summary
The existing technology cannot quickly and accurately identify and count dead snails during the field snail breeding process, and relies on manual determination, which is subjective and inefficient, and cannot be objectively recorded.
The dead snail detection and counting method based on YOLOv5 and PyQt5 is used to collect field snail image data through industrial cameras, train the YOLOv5 visual detection model, and design a GUI interface to identify and count dead snails and live snails, realizing rapid AI detection and machine automated counting. .
It reduces the dependence on the operator's experience and achieves objective and rapid batch testing with high efficiency and low cost. It is suitable for snail breeding and scientific research applications, and avoids the use of water flow with high dissolved oxygen and the process of snails crawling by themselves.
Smart Images

Figure CN118692108A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of deep learning target detection, and specifically to a dead snail detection and counting method based on YOLOv5 and PyQt5. Background Art
[0002] Chinese round snail (Cipangopaludina chinensis) belongs to the genus Cipangopaludina, family Viviparidae, class Gastropoda. It is a common freshwater mollusk widely distributed in freshwater lakes, swamps, rice fields and other waters. It is also an important freshwater food ingredient in my country. Chinese round snails are delicious, nutritious, and have good health and medicinal effects. As people's living standards gradually improve, the number of edible snails has also increased year by year. In the process of collecting snails in snail farming, the snails that have not been sorted and screened contain many dead snails. The dead snails are mixed with normal snails and successfully flow into the market after being sold by downstream distributors, and then appear on the consumer's table. Dead snails have a strong pungent smell. Consumers who eat dead snails will not only affect their appetite, but also threaten human life safety in serious cases. In the field snail artificial breeding industry, the common methods for determining whether the cultivated field snails have died during the experiment are finger pressing and shaking. The finger pressing method involves pressing the operculum at the mouth of the field snail with a finger, and judging whether it is alive based on the rebound feedback of the operculum. The shaking method involves shaking the field snail with a human hand. The changes in the center of gravity of the shell and other organs are significantly different between living and dead snails, and judging whether it is alive based on the feedback of the shaking feel. Both of the above methods require the operator to have a lot of practical experience, and the judgment process is too subjective to be objectively recorded or compared.
[0003] Document number CN202320153161.9 is a device for screening out dead snails and empty shell snails, which uses the method of live snails crawling towards water with high dissolved oxygen content to separate dead snails from live snails. However, the process of relying on the snails to crawl on their own is too slow and inefficient; and the snails are easily stimulated by the outside world and shrink into their bodies and remain motionless. If the impact of the running water is large, more snails will remain in the shells during this process instead of protruding from the shells, making it difficult to determine whether they are truly dead snails. Summary of the invention
[0004] In view of the above problems, the present invention proposes a dead snail detection and counting method based on YOLOv5, which solves the current problem of rapid identification and counting of dead snails, realizes AI rapid detection and machine automated counting, and gets rid of the traditional manual identification of dead snails by naked eye and traditional manual counting.
[0005] A dead snail detection and counting method based on YOLOv5 and PyQt5, including a dead snail detection and counting method based on YOLOv5 and PyQt5, including a detection method and a counting method;
[0006] Among them: The detection methods include:
[0007] Step A1: Cleaning the snails: taking a number of adult Chinese round snail samples, performing a cleaning procedure to remove stains on the surface thereof, and wiping off the moisture on the surface thereof, thereby obtaining a number of clean snail samples.
[0008] Step A2: Strong light irradiation. Lay the cleaned snails in step 1 flat on a transparent plate, and use a light source to irradiate the snail samples on the transparent plate from bottom to top. The transparent plate is preferably made of highly transparent organic materials such as acrylic polycarbonate or high-strength tempered glass. The light source is preferably a cold light source to reduce the impact of temperature on the snail samples.
[0009] Step A3: Observe the position and identify dead snails. Under the transmission of light, observe whether there are cavitations, shrinkage of the snail meat, or edema of the snail body inside the snail sample. If so, the snail is dead; if the snail meat is firm and full, and the above phenomenon does not occur, it is a live snail.
[0010] Step A4: collecting image data of the snail sample through an industrial camera;
[0011] Preferably, the number of snails taken in the above step A1 can be determined according to the actual device material. As the illumination area of the LED light source increases, more snails can be detected. However, it is recommended that the illumination area should not be too large. Otherwise, the larger the area to be detected, the more image information the industrial camera needs to capture, which will result in a smaller area occupied by each snail. The smaller the detected target, the more likely it is that the detection accuracy will decrease.
[0012] In the above step A2, suitable shooting equipment and light source should be used. The light source should be a high-intensity concentrated LED light source with a power of more than 80W, a color temperature of 5000K-6000K, and a range of more than 1000 meters to ensure the clarity and accuracy of the image.
[0013] In the above step A4, characteristic images of dead and live snails are respectively captured and obtained as the initial sample data set. The obtained data set is feature labeled using the visual image calibration tool labelimg, and the target in the image is marked with a rectangular frame and labeled with a target label.
[0014] Counting methods include:
[0015] Step S1: According to the image data of step A4, train and establish a dead snail visual detection model based on YOLOv5, mark dead snails and live snails with different labels, and verify the model detection effect; Step S1 uses the YOLOv5 algorithm to build a dead snail detection model. The YOLOv5 algorithm uses a single-stage target detection network architecture, which can achieve real-time target detection while maintaining high accuracy. Compared with traditional algorithms, it can provide faster reasoning speed and has very superior lightweight characteristics. Since YOLOv5 uses a smaller feature map input, it is conducive to retaining the feature information of small targets, and YOLOv5 has good performance in detecting small targets.
[0016] Step S2: Perform network detection based on the detection results output by the model to count the number of dead and live snails. Use PyQt5 to design a user GUI interface, output the network detection results to the user interface, count the number of dead and live snails, and display the respective counting results in the interface.
[0017] Preferably, the step S1 comprises:
[0018] Step B1: Based on the image data in step A4, the initial data set is enhanced by flipping, mirroring, cropping, scaling, brightness adjustment, etc., and the initial data set is expanded to 5 times the original size.
[0019] Step B2: Use the visual image calibration tool labeilimg to label the dead and live snails in the image dataset with different labels to distinguish and mark them with specific boxes. Then, randomly sample and divide the expanded dataset into training set, validation set and test set in a ratio of 8:1:1. Store the processed raw data and labeled data in the set locations respectively.
[0020] Step B3: Configure the dataset configuration file dead_snail.yaml of the dead snail image dataset, fill in the training set and validation set paths, number of categories, and category labels. According to the configured dead_snail.yaml and the set hyperparameters, load the corresponding YOLOv5 network model for deep training.
[0021] Step B4: According to the convergence of the average precision of each category and the model loss value of the training output, determine whether to modify the hyperparameters and retrain until the model converges. When the model loss value curve and the average precision value curve gradually converge with the increase in the number of training rounds, the training is terminated and the corresponding weight file is generated.
[0022] Step B5: Load the generated weight file into the YOLOv5 model prediction network test.py, make predictions on the dead snail test set, mark the detected snails’ life or death, confidence and other information in the picture, and output the relevant prediction pictures.
[0023] The sample dataset image obtained in the above step B1 is in jpg image format. The Labelimg annotation software used generates a txt label file that follows the YOLO format. The original image and the annotated txt file generate the dead snail image dataset required for training the neural network.
[0024] The hyperparameters in step B3 above mainly include pre-training weights, training network model, configuration file data, training rounds epochs, processing batch size, graphics card calling device, input image size, number of workers, optimizer, maximum and minimum learning rate, which are adjusted according to the specific hardware device and model convergence situation.
[0025] The YOLOv5 network built using the Pytorch deep learning framework in the above step B4 mainly includes an input layer input, a backbone network backbone, a neck network neck and a prediction network head; the backbone network includes a CBP module, a C3 module and an SPP module; the neck network includes a CBS module, a C3 module and a PaNet module; the prediction network includes a detection head; the C3 module of the backbone network and the neck network are both composed of branch 1 and branch 2, branch 1 includes a convolutional layer, a batch normalization layer and a SiLU activation function, and branch 2 includes a convolutional layer, a batch normalization layer, a SiLU activation function and several Bottleneck structures.
[0026] In detail, after the Input layer preprocesses the image, it is spliced by random scaling, random cropping, and random arrangement through Mosaic data enhancement to make the distribution of small targets more even, and adaptive anchor box calculation and adaptive image scaling are added to further improve the detection speed and accuracy of the model. The backbone includes the Conv module, the C3 module, and the spatial pyramid pooling SPPF. The CSP module splits the feature map into two parts according to the channel dimension, one part goes through the normal network, and the other part is directly spliced with this feature map. Under the premise of ensuring the accuracy of network detection, the problem of excessive calculation of the entire network caused by gradient repetition can be reduced. The Neck part consists of the feature pyramid FPN and the path aggregation network PAN. The FPN structure conveys feature information from top to bottom, and PAN receives it and then conveys spatial information from bottom to top, and finally performs parameter aggregation, which effectively improves the feature fusion ability of the network. Prediction uses the GIoU loss function to predict the bounding box. The loss function consists of three parts: the positioning loss function (box_loss) used to calculate the error between the predicted box and the calibrated box, the confidence loss function (obj_loss) used to calculate the network confidence, and the classification loss function (cls_loss) used to calculate whether the classification of the anchor box and the corresponding calibration is correct. And weighted NMS is used to suppress non-maximum values to obtain the optimal target box. The loss function formula is as follows:
[0027]
[0028] Loss = L CIoU +L conf +L cls #(6)
[0029] In formula (1), IoU is the ratio of the intersection area of the real box and the predicted box to the union area. 2 (b,b gt ) is the Euclidean distance between the center point of the real box and the predicted box, b and b gt Represent the center points of the predicted box and the real box respectively, and C represents the diagonal length of the minimum closed box covering the predicted box and the real box. Among them, α can be used as a weight parameter, and v represents the aspect ratio. In formula (3), h gt and w gt is the length and width of the predicted box, w and h are the length and width of the real box. In formula (4), S is the side length of the feature map, and B is the number of anchor points of each unit in the feature map. Indicates whether the jth anchor in the i-th cell is responsible for the probability of falling into the bounding box of this region. Otherwise = 0; The definition and value of On the contrary; C ijis the confidence score of the jth anchor in the proposed i-th unit. C ij ∈[0,1]. noobj The balance coefficient is set to 0.5 during training. In formula (5), is the predicted category of the jth anchor in the ith unit, and is the true category. In formula (6), Loss is the total loss function, L CIoU is the CIoU function loss, L conf is the confidence loss, L cls is the classification loss.
[0030] Preferably, step S2 comprises:
[0031] Step C1: First, use PyQt5 to develop and design the GUI interface of the dead snail detection system. The specific method is as follows:
[0032] ① The entire GUI interface is designed into two parts, the left side is the human-computer interaction interface, and the right side is the original interface and the detection effect interface. The human-computer interaction interface contains 13 QPushButton controls for realizing the control model selection, input selection, IoU, confidence, inter-frame delay and its start and stop, automatic saving function and video start and stop function, 3 QTumbler sliding selection controls for sliding control of IoU, confidence and inter-frame delay to realize rough control; 13 QLabel label controls for displaying layout text, which are used to realize the static text display function of the interface; 2 QLabel label controls for displaying real-time images and detection effect interface;
[0033] ② Set the contents of 13 QPushButton controls to "model selection, input picture, turn on / off camera, input video, increase IoU by 0.01, decrease IoU by 0.01, increase confidence by 0.01, decrease confidence by 0.01, increase inter-frame delay by 1, decrease inter-frame delay by 1";
[0034] ③ Set the contents of the three QTumbler sliding selection controls to sliding control IoU, confidence and inter-frame delay. Set the positions and contents of the 13 QLabel controls used to display layout text, which are: "Dead snail detection system, settings, model selection, input selection, IoU, confidence, inter-frame delay, startup, automatic saving, result statistics and display interface";
[0035] ④ Fill the background of the two QLabel label controls used to display the original interface and the detection effect interface with white and set the position; initialize the content of 20 QLabel label controls used to display the detection results and counting results to empty, wait for the network to output the detection results, and update the content in real time.
[0036] Step C2: Combine the various controls in the above steps in the same interface, establish the dead snail detection system GUI interface, click the "Model Selection" button, read the dead snail visual detection model weight file trained and output in step B2, and the model determines whether the target in the picture is a dead snail or a live snail based on the input picture, video or real-time picture.
[0037] Step C3: The model generates a prediction frame for the target, and labels the location, life or death, confidence level and other information of the snails detected in the image, and outputs the corresponding prediction image.
[0038] Step C4: by converting the character format of the output label into a string format, and reading the corresponding number of label number 0 (i.e., dead snails) and label number 1 (i.e., live snails), using the sum function to add the dead snails and live snails respectively and output the result, the result is printed to the result statistics column in the GUI interface and displayed.
[0039] Compared with the prior art, the present invention has the following beneficial effects:
[0040] It reduces the reliance on the operator's experience and can objectively realize batch detection. It does not need to design additional molds, which is low-cost and reliable. It does not need to use water with high dissolved oxygen content, which saves resources and costs. It does not need to distinguish between dead and live snails by the snails crawling on their own. It relies on direct visual detection and real-time display through the GUI interface, which is more efficient and faster. It is not only suitable for the snail farming industry, but also for scientific research. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below; in all drawings, similar elements or parts are generally identified by similar figure marks; in the drawings, the elements or parts are not necessarily drawn according to the actual scale.
[0042] Figure 1 YOLOv5 network structure diagram for reference in the embodiments of the present invention;
[0043] Figure 2 A flow chart of a dead snail detection and counting method based on YOLOv5 and PyQt5 provided in an embodiment of the present invention;
[0044] Figure 3 A schematic diagram of obtaining dead snail samples provided by an embodiment of the present invention;
[0045] Figure 4 A schematic diagram of the recognition effect of the dead snail visual detection model provided in an embodiment of the present invention;
[0046] Figure 5 This is a schematic diagram of the GUI of a dead snail detection system based on YOLOv5 and PyQt5 provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0047] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present invention.
[0048] The following is combined with Figure 1 To Attachment Figure 5 , a dead snail detection and counting method based on YOLOv5 and PyQt5 proposed by the present invention is introduced, comprising the following steps:
[0049] Step 1: Take a 400mm×400mm transparent acrylic plate and several cleaned adult Chinese round snails, lay the snails flat on the transparent acrylic plate without stacking them, and use a high-intensity concentrated LED light source to illuminate the snails from bottom to top. By observing whether there are vacuoles in the body spiral layer of the snail, shrinkage of the snail meat, or edema of the snail body, we can identify whether it is a dead snail, and use an industrial camera to take pictures of the snails.
[0050] Specifically, since the high-intensity concentrated LED light source of the present invention is illuminated from the bottom to the top directly below the transparent acrylic plate, in order to prevent overexposure, the industrial camera needs to be placed 30cm-40cm away from the transparent acrylic plate and at about 45° to the horizontal line.
[0051] Step 2: Collect image data of two categories, dead snails and live snails, with a total of 1543 snail images through industrial cameras, and store the 1543 snail images in the images folder as original image data. Use Labelimg visual image annotation tool to calibrate all snail images in the images folder, generate txt annotation files in YOLO format, and generate train.txt, val.txt, and test.txt files to save the corresponding picture name list and the label position and category information therein. The generated file format divides each picture by line. Take the train.txt file as an example, in which each line sequentially saves the path of the picture divided into the training set, the position information of all the annotation boxes in the picture (x1, y1, x2, y2) and the category information. After the data set preparation is completed, it is used for the training of the YOLOv5 model.
[0052] Optionally, after generating a txt annotation file using the Labelimg visual image annotation tool, organize the file into the original images of images. In order to increase the richness of the dataset and enhance the generalization ability of the model, a data augmentation algorithm is used on the dataset to expand the original dataset by 5 times. The final dataset is 7715 images. The snail surface dataset is divided into training set, validation set and test set in a ratio of 8:1:1, with 6172 images for the training set, 772 images for the validation set and 771 images for the test set.
[0053] Specifically, the deep learning hardware configuration used in this embodiment is an industrial computer with Intel(R) Core(TM) i5-13500HX CPU + NVIDIA GeForce RTX 4060 (8GB) Laptop GPU; the software selects Windows 11 operating system; YOLOv5 network model; Python version 3.8.0; deep learning framework Pytorch 2.1.0; Opencv 4.8.1; and development environment CUDA 11.8.
[0054] The hyper parameters set in this embodiment are: the number of training epochs is 150, the number of batch sie threads is 32, the number of workers is 16, the maximum learning rate is 0.01, the minimum learning rate is 0.0001, and the optimizer type is SGD.
[0055] Step 3: Use the dead snail dataset described in step 2 to train a dead snail visual detection model based on YOLOv5. The network is implemented using the Pytorch deep learning framework and Python language. During the model training process, the key features of dead and live snails are extracted and the confidence and category labels corresponding to each target dead and live snail in the image are annotated. After 150 rounds of deep training, all weight files obtained from each epoch training are saved.
[0056] Specifically, the YOLOv5 model built in step 3 includes four parts: input end, backbone, neck, and head. Figure 1 shown.
[0057] (a) Input:
[0058] To address the problem of unbalanced proportions of large, medium and small objects in the data set, the Mosaic data enhancement method is used at the input end to randomly scale, crop and splice any four images before putting them into network training.
[0059] YOLOv5 detection is to select the target area according to the preset anchor box range. Therefore, before training, YOLOv5 can recalculate the anchors suitable for the data set through the clustering algorithm and replace the original anchors.
[0060] The adaptive image scaling function in YOLOv5 is designed to solve the problem of different input image sizes. The original image is uniformly scaled to a standard size before being fed into the network. However, in actual project use, many images have different aspect ratios. Therefore, after scaling and padding, the sizes of the black edges at both ends are different. If more padding is added, there will be information redundancy, which will affect the inference speed. Therefore, the minimum black edge is added to the original image adaptively. The specific calculation process is as follows: (1) Calculate the scaling ratio; (2) Calculate the size after scaling; (3) Calculate the black edge padding value.
[0061] (b) Backbone: mainly composed of CBS, C3 and SPPF.
[0062] The CBS module consists of three parts: convolution Conv, normalization BatchNorm, and activation function SiLU.
[0063] CSP is the C3 layer in Backbone. CSP contains multiple Bottleneck modules, which are residual modules used in deep networks. Bottleneck consists of two 1x1 convolutional layers and a 3x3 convolutional layer: the 1x1 convolutional layer reduces the dimension and then restores the dimension, so that the 3x3 convolution has fewer parameters and faster speed in the calculation process.
[0064] The SPPF structure is also known as spatial pyramid pooling, which can convert feature maps of any size into feature vectors of fixed size. The SSPF module concatenates x after CBS, y1 after one pooling, y2 after two poolings, and self.m(y2) after three poolings, and then extracts features using CBS. The main function of this module is to extract and fuse high-level features. During the fusion process, the author uses maximum pooling multiple times to extract as many high-level semantic features as possible.
[0065] (c) Neck: The network structure design of Neck follows the structure of FPN+PAN. FPN uses a top-down side connection to build high-level semantic feature maps at all scales, constructing the classic structure of feature pyramid. After FPN passes through multiple layers of the network, the underlying target information is already very vague, so PAN adds a bottom-up route to supplement and strengthen the positioning information.
[0066] (d)Head: Contains three detection heads of different scales
[0067] Bounding box loss function: YOLOv5 uses CIoU Loss as the loss function of the bounding box.
[0068] NMS non-maximum suppression: YOLOv5 first divides the image into several small images during detection, and then uses the NMS operation to filter out the annotation box prediction box with the highest score. The specific operation is as follows: first set a confidence threshold, filter out the prediction boxes that are less than this threshold, and then keep the prediction boxes with high confidence in the remaining prediction categories, and delete the rest of the prediction boxes.
[0069] Step 4: The model extracts the key features of dead and live snails in the training set and annotates the confidence and category labels of each target snail in the image. As the number of training rounds increases, the fluctuation of the loss value of the model training gradually stabilizes, the loss value curve converges, and the model training ends. The trained model generates the corresponding weight file last.pt and renames it to YOLOv5_dead_snail.pt. This weight file can be used to identify and detect dead snails.
[0070] Step 5: Develop and design the dead snail detection GUI user interface through PyQt5. When predicting the snail pictures, videos and real-time images through the prediction model weight YOLOv5_dead_snail.pt, first use the clear function to clear and initialize the result statistics interface, read each dead snail and live snail label and confidence output by the YOLOv5 network prediction, convert the character format label of the result into a string type, and finally use the sum function to add and output. The result shows the dead snail and live snail count statistics in the result statistics interface.
[0071] Specific as Figure 5 As shown in the figure, the dead snail detection GUI interface contains 13 QPushButton button controls for realizing the control model selection, input selection, IoU, confidence, inter-frame delay and its start and stop, automatic saving function and video start and stop function; 3 QTumbler sliding selection controls for sliding control of IoU, confidence and inter-frame delay to realize rough control; 13 QLabel label controls for displaying layout text to realize the static text display function of the interface; 2 QLabel label controls for displaying real-time images and detection effect interface.
[0072] Specifically, the contents of 13 QPushButton controls are set to "model selection, input image, open / close camera, input video, IoU increase by 0.01, IoU decrease by 0.01, confidence increase by 0.01, confidence decrease by 0.01, inter-frame delay increase by 1, inter-frame delay decrease by 1"; the contents of 3 QTumbler sliding selection controls are set to sliding control of IoU, confidence and inter-frame delay. The positions and contents of 13 QLabel controls used to display layout text are set to "dead snail detection system, settings, model selection, input selection, IoU, confidence, inter-frame delay, start, automatic save, result statistics and display interface"; the background of two QLabel controls used to display the original interface and the detection effect interface is filled with white and the position is set; the contents of 20 QLabel controls used to display detection results and counting results are initialized to empty, waiting for the network to output the detection results, and the content is updated in real time.
[0073] It should be understood that when used in this specification and the appended claims, the terms “include” and “comprises” indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof;
[0074] It should also be understood that the terms used in the present invention specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention; as used in the present invention specification and the appended claims, the singular forms "a", "an" and "the" are intended to include plural forms unless the context clearly indicates otherwise;
[0075] It should be further understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
Claims
1. A dead snail detection and counting method based on YOLOv5 and PyQt5, characterized in that: Includes detection methods and counting methods; Among them: The detection methods include: Step A1: Cleaning the snails, taking a number of adult Chinese round snail samples, performing a cleaning procedure to remove stains on the surface thereof, and wiping the surface moisture to obtain a number of clean snail samples; Step A2: strong light irradiation, lay the cleaned snails in step 1 flat on a transparent plate, and use a light source to irradiate the snail samples on the transparent plate from bottom to top; Step A3: Observe the position to identify dead snails. Under the transmission of light, observe whether there are cavitations, shrinkage of snail meat or edema of the snail body inside the snail sample. If such phenomena occur, the snail is dead. If the snail meat is firm and full, and the snail body does not have the above phenomena, it is a live snail. Step A4: collecting image data of the snail sample through an industrial camera; Counting methods include: Step S1: Based on the image data of step A4, a dead snail visual detection model based on YOLOv5 is trained and established, dead snails and live snails are marked with different labels, and the model detection effect is verified; Step S2: Perform network detection based on the detection results output by the model to count the dead and live snails. Use PyQt5 to design the user GUI interface. Output the network detection results to the user interface, count the dead and live snails, and then display the respective counting results in the interface.
2. A dead snail detection and counting method based on YOLOv5 and PyQt5 according to claim 1, characterized in that: The step S1 comprises: Step B1: Based on the image data in step A4, the initial data set is enhanced by flipping, mirroring, cropping, scaling, and brightness adjustment to expand the initial data set to 5 times the original size; Step B2: Use the visual image calibration tool labeilimg to label the dead and live snails in the image dataset with different labels to distinguish and mark them with specific boxes; then use random sampling to divide the expanded dataset into training set, validation set and test set in a ratio of 8:1:1; store the processed raw data and labeled data in set locations respectively; Step B3: Configure the dataset configuration file dead_snail.yaml of the dead snail image dataset, fill in the training set and validation set paths, the number of categories, and the category labels; load the corresponding YOLOv5 network model according to the configured dead_snail.yaml and the set hyperparameters for deep training; Step B4: According to the convergence of the average precision of each category and the model loss value of the training output, determine whether to modify the hyperparameters and retrain until the model converges; when the model loss value curve and the average precision value curve gradually converge with the increase in the number of training rounds, end the training and generate the corresponding weight file; Step B5: Load the generated weight file into the YOLOv5 model prediction network test.py, make predictions on the dead snail test set, mark the detected snails’ life or death, confidence and other information in the picture, and output the relevant prediction pictures.
3. A dead snail detection and counting method based on YOLOv5 and PyQt5 according to claim 1, characterized in that: The step S2 comprises: Step C1: First, use PyQt5 to develop and design the GUI interface of the dead snail detection system. The specific method is as follows: ① The entire GUI interface is designed into two parts, the left side is the human-computer interaction interface, and the right side is the original interface and the detection effect interface; the human-computer interaction interface contains 13 QPushButton button controls for realizing the control model selection, input selection, IoU, confidence, inter-frame delay and its start and stop, automatic saving function and video start and stop function, 3 QTumbler sliding selection controls for sliding control of IoU, confidence and inter-frame delay to realize rough control; 13 QLabel label controls for displaying layout text, which are used to realize the static text display function of the interface; 2 QLabel label controls for displaying real-time images and detection effect interface; ② Set the contents of 13 QPushButton controls to "model selection, input picture, open / close camera, input video, increase IoU by 0.01, decrease IoU by 0.01, increase confidence by 0.01, decrease confidence by 0.01, increase inter-frame delay by 1, decrease inter-frame delay by 1"; ③ Set the three QTumbler sliding selection controls to slide and adjust IoU, confidence and inter-frame delay; set the positions and contents of 13 QLabel controls used to display layout text, which are: "dead snail detection system, settings, model selection, input selection, IoU, confidence, inter-frame delay, startup, automatic saving, result statistics and display interface"; ④ Fill the background of two QLabel controls used to display the original interface and the detection effect interface with white and set the position; initialize the content of 20 QLabel controls used to display the detection results and counting results to empty, wait for the network to output the detection results, and update the content in real time; Step C2: Combine the various controls in the above steps in the same interface, establish the dead snail detection system GUI interface, click the "Model Selection" button, read the dead snail visual detection model weight file trained and output in step B2, and the model determines whether the target in the picture is a dead snail or a live snail based on the input picture, video or real-time picture; Step C3: The model generates a prediction frame for the target, and labels the location, life or death, confidence and other information of the snail detected in the picture, and outputs the corresponding prediction picture; Step C4: by converting the character format of the output label into a string format, and reading the corresponding number of label number 0 (i.e., dead snails) and label number 1 (i.e., live snails), using the sum function to add the dead snails and live snails respectively and output the result, the result is printed to the result statistics column in the GUI interface and displayed.
