Microcystis algal bloom monitoring and early warning method based on YOLOv5 and LSTM
By improving the YOLOv5 model and combining it with LSTM, a microcystis detection model was constructed, which solved the problems of low detection efficiency and insufficient accuracy of traditional methods, and realized accurate monitoring and early warning of microcystis blooms.
Patent Information
- Application Number
- CN202511529396.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-24
- Publication Date
- 2026-01-13
AI Technical Summary
Traditional methods for detecting and counting Microcystis algae are inefficient and susceptible to human error. YOLOv5 does not extract enough features in the identification and counting of Microcystis algae, resulting in low model detection accuracy. Therefore, it cannot be used for the accurate monitoring and early warning of Microcystis algae blooms.
A method for monitoring and early warning of Microcystis blooms based on YOLOv5 and LSTM is constructed. By introducing a Microcystis detection model with a full-dimensional dynamic convolution module, a hybrid local channel attention module, and a multi-level adaptive spatial feature fusion structure, and combining it with an LSTM model to process long-term series data, the method can achieve accurate detection of Microcystis cells and prediction of future density.
It enables accurate detection and identification of Microcystis algae under complex water quality conditions, solving the problems of insufficient feature extraction and low detection accuracy, and can efficiently and accurately carry out early warning and prevention of Microcystis algae blooms.
Smart Images

Figure CN121330671A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of water quality monitoring technology, and in particular to a method for monitoring and early warning of Microcystis blooms based on YOLOv5 and LSTM. Background Technology
[0002] Algal blooms not only lead to water hypoxia and decreased biodiversity, but also release algal toxins, endangering drinking water safety and aquaculture. Microcystis (Microcystis aeruginosa) is one such algae species. Microcystis Microcystis (MC) is one of the most common dominant algal species in cyanobacterial blooms. Its massive proliferation forms a surface bloom that blocks sunlight, inhibits photosynthesis in other aquatic plants, and the decomposition of dead MCBs consumes large amounts of dissolved oxygen, leading to anaerobic conditions in the water, causing fish and other aquatic organism deaths, and disrupting ecosystem stability. Furthermore, the toxins produced by MCBs can accumulate in the human body through drinking water and the food chain, posing a serious threat to human health.
[0003] Traditional methods for detecting and counting Microcystis algae mainly rely on microscopic observation and manual counting, which is time-consuming, labor-intensive, and susceptible to subjective factors. Water samples are pretreated through filtration, concentration, sedimentation, and staining. 0.1 mL of sample is then placed in a microscope counting frame, and the number of Microcystis algae in 100 fields of view is manually counted before being converted to the overall algal density of the sample. This method is inefficient, and human operation introduces significant measurement errors. Currently, with the rapid development of computer vision technology, deep learning-based automatic identification and counting methods have become a research hotspot. Among them, YOLOv5 has achieved a good balance between speed and accuracy, exhibiting excellent target detection capabilities and is widely used in industrial fields. However, due to the small size of Microcystis algae cells, directly applying YOLOv5 to Microcystis algae identification and counting suffers from insufficient feature extraction and low model detection accuracy, making it unsuitable for the accurate monitoring and early warning of Microcystis algae blooms. Summary of the Invention
[0004] This application addresses the aforementioned problems and technical needs by proposing a method for monitoring and early warning of Microcystis blooms based on YOLOv5 and LSTM. The technical solution of this application is as follows: A method for monitoring and early warning of Microcystis blooms based on YOLOv5 and LSTM includes the following steps: Obtain microscopic scanning images of water samples from the target water area; Microscopic scan images are input into a Microcystis detection model built based on the YOLOv5 model, which outputs the location and category of Microcystis cells in the microscopic scan images. The Microcystis detection model includes a backbone network, a neck network, and a head network. The backbone network extracts multi-scale features from the input microscopic scan images, the neck network fuses the multi-scale features output by the backbone network, and the head network performs recognition and prediction based on the fused features. The backbone network of the Microcystis detection model introduces a full-dimensional dynamic convolution module to enhance the multi-dimensional feature extraction capability, the neck network introduces a hybrid local channel attention module to improve feature discrimination in complex backgrounds, and the head network introduces a multi-level adaptive spatial feature fusion structure to enhance the detection performance of small targets. Based on the location and type of Microcystis cells in the microscopic scanning images, the density of Microcystis in the water sample was calculated; the types of Microcystis cells include single-celled Microcystis and Microcystis populations, and the Microcystis populations contain multiple single-celled Microcystis. The water quality parameters and Microcystis density of the current time and several consecutive historical times before it are input into a pre-trained LSTM prediction model to predict the Microcystis density in a predetermined future period and to issue an early warning when the Microcystis density exceeds the threshold of algal bloom density.
[0005] The further technical solution is that the backbone network of the Microcystis detection model includes a cascaded input layer, a convolutional layer, four multidimensional feature extraction modules and an SPPF module. Each multidimensional feature extraction module includes a cascaded full-dimensional dynamic convolutional module and a C2F module. The input microscopic scan image passes through the four multidimensional feature extraction modules in sequence and outputs four feature maps with progressively smaller sizes. Each multidimensional feature extraction module extracts the features of the corresponding size feature map in the spatial dimension, input channel dimension and output channel dimension.
[0006] The further technical solution is that a hybrid local channel attention module is introduced at the end of the neck network of the YOLOv5 model in the neck network of the microcystis detection model; after the neck network of the microcystis detection model performs cross-scale feature fusion on the four feature maps output by the backbone network, the feature is enhanced by the hybrid local channel attention module to obtain three fused feature maps and one enhanced feature map.
[0007] A further technical solution involves adding a 160×160 small target detection head to the adaptive spatial feature fusion detection head, thereby constructing a multi-level adaptive spatial feature fusion structure for the head network of the Microcystis detection model. The four detection heads of the head network of the Microcystis detection model respectively adjust the size of the three fusion feature maps and one enhancement feature map output by the neck network and then weight and fuse them to obtain four detection result maps of different sizes. The detection result maps contain the location and category information of Microcystis cells.
[0008] The further technical solution involves determining the density of Microcystis algae in a water sample, including: Based on the location and type of Microcystis cells in the microscopic scanning image, the area of each type of single-celled Microcystis is determined, and the average area of single-celled Microcystis is calculated based on the total number of all types of single-celled Microcystis. The area of each category of Microcystis population was determined, and the number of single-celled Microcystis contained in each Microcystis population was calculated based on the average area of single-celled Microcystis. The total number of single-celled Microcystis in the microscopic scanning image was obtained, and the density of Microcystis in the water sample was determined based on the volume of the water sample.
[0009] A further technical solution involves using a threshold segmentation algorithm to extract the outline of a Microcystis cell based on the location of any type of Microcystis cell in a microscopic scanning image and calculating the area of the outline.
[0010] The further technical solution involves training a Microcystis detection model that includes: Multiple microscopic scanning images of the target water area under different water quality conditions were acquired, and the Microcystis cells in each microscopic scanning image were labeled to construct a Microcystis image dataset. The Microcystis image dataset includes microscopic scanning images of the target water area under normal conditions and microscopic scanning images of the target water area during Microcystis blooms. Image enhancement was performed on the Microcystis image dataset. The enhanced Microcystis image dataset was then used for model training. The PIOU loss function and optimizer were used to adjust the model parameters until the model converged, thus obtaining the Microcystis detection model.
[0011] A further technical solution is to classify Microcystis cells in a microscopic scanning image by: using a labeling box to label Microcystis cells in the microscopic scanning image; when the distance between any Microcystis cell and all surrounding Microcystis cells is greater than the diameter of a single Microcystis cell, and the labeling boxes of any Microcystis cells do not overlap, the Microcystis cell is labeled as a single-celled Microcystis; otherwise, the Microcystis cell is labeled as a Microcystis population.
[0012] The further technical solution involves training an LSTM prediction model that includes: Obtain the water quality monitoring data sequence of the target water area within a predetermined historical time period. The water quality monitoring data at each historical moment includes water quality parameters and Microcystis density. The water quality parameters indicate the water quality status of the target water area. The water quality parameters and Microcystis density of historical time windows in the water quality monitoring data sequence are used as inputs to the LSTM neural network, and the Microcystis density of future time windows is used as the output of the LSTM neural network. The backpropagation algorithm is used to adjust the network parameters until the model performance requirements are met, and the LSTM prediction model is trained.
[0013] A further technical solution is to use a Kalman filter algorithm to smooth the prediction results before using the prediction results output by the LSTM prediction model for early warning judgment, so as to reduce the impact of random fluctuations.
[0014] The beneficial technical effects of this application are: This application discloses a method for monitoring and early warning of Microcystis blooms based on YOLOv5 and LSTM. By improving the traditional YOLOv5 model, a new Microcystis detection model is constructed, achieving accurate detection and identification even under conditions of small Microcystis cells and complex water quality. This solves the problems of insufficient feature extraction and low detection accuracy of the traditional YOLOv5 model in Microcystis identification and counting. Combining the LSTM model's ability to handle long-term dependencies in long-term data, the method effectively learns the temporal characteristics of historical water quality monitoring data and Microcystis density data, enabling efficient and accurate prediction of Microcystis population trends over a future period. This is of great significance for the early warning and control of Microcystis blooms.
[0015] To address the challenges posed by complex sample conditions in target water areas, including numerous impurities and overlapping algae that can lead to feature loss and missed or false detections, this application constructs a Microcystis detection model that incorporates omni-dimensional dynamic convolution (ODConv) into the backbone network of the traditional YOLOv5 model. This enhances the multi-dimensional feature extraction capability, effectively improving the feature extraction performance of the backbone network and reducing information loss.
[0016] Considering the diverse environments of algal water samples, resulting in complex backgrounds in the obtained microscopic scanning images, which are easily affected by interference information when extracting Microcystis target features, the Microcystis detection model constructed in this application introduces a mixed local channel attention (MLCA) module into the neck network of the traditional YOLOv5 model to improve feature discrimination against complex backgrounds, thereby enhancing the network's expressive performance and strengthening its ability to detect Microcystis features in microscopic scanning images. Considering the large target scale variations in the Microcystis image dataset, which leads to feature information conflicts between different scales, and the presence of numerous single-celled Microcystis with small target sizes, the Microcystis detection model constructed in this application adds a 160×160 small target detection head to the adaptive spatial feature fusion (ASFF) detection head of the traditional YOLOv5 model's head network. This further filters out conflicting information between different scales, solves the feature loss problem caused by cross-scale fusion, and enhances the head network's detection performance for small targets.
[0017] Furthermore, considering that Microcystis cells mainly consist of two types: unicellular Microcystis and Microcystis colonies, with unicellular Microcystis being approximately spherical in shape and Microcystis colonies composed of multiple unicellular Microcystis, all Microcystis cells were labeled as either unicellular Microcystis or Microcystis colonies when constructing the Microcystis image dataset. The Microcystis density was then calculated based on the area of unicellular Microcystis and Microcystis colonies during the analysis of the detection results. This method is logically simple, computationally inexpensive, and ensures real-time detection of Microcystis density, which is beneficial for efficient prediction of subsequent Microcystis density. Attached Figure Description
[0018] Figure 1 This is a flowchart of a method for monitoring and early warning of Microcystis blooms.
[0019] Figure 2 These are microscopic scan images of water samples.
[0020] Figure 3 This is a structural diagram of the Microcystis detection model.
[0021] Figure 4 This is an MLCA workflow diagram.
[0022] Figure 5 This is a diagram showing the annotated results of a microscopic scan image.
[0023] Figure 6 It is an outline extraction image of single-celled Microcystis and Microcystis colonies. Detailed Implementation
[0024] The specific embodiments of this application will be further described below with reference to the accompanying drawings.
[0025] This application discloses a method for monitoring and early warning of Microcystis blooms based on YOLOv5 and LSTM. Please refer to [link / reference]. Figure 1 The flowchart shown illustrates the specific steps of this method: Step 1: Collect a 0.1 mL water sample from the target water area. Use a high-precision microscopic imaging system to scan the algae sample in the 0.1 mL counting frame to obtain a microscopic scanning image of the water sample from the target water area, such as... Figure 2 As shown, the microscopic scanning image contains Microcystis cells as well as various impurities in the water.
[0026] Step 2: Input the microscopic scan image into the Microcystis detection model built based on the YOLOv5 model, and output the location and type of Microcystis cells in the microscopic scan image.
[0027] The Microcystis detection model comprises a backbone network, a neck network, and a head network. The backbone network extracts multi-scale features from the input microscopic scan image. The neck network fuses the multi-scale features output by the backbone network. The head network performs recognition and prediction based on the fused features. The backbone network of the Microcystis detection model introduces a full-dimensional dynamic convolution module to enhance the multi-dimensional feature extraction capability. The neck network of the Microcystis detection model introduces a hybrid local channel attention module to improve feature discrimination against complex backgrounds. The head network of the Microcystis detection model introduces a multi-level adaptive spatial feature fusion structure to enhance the detection performance for small-sized targets.
[0028] The network structure of the microcystis detection model is as follows: Figure 3 As shown, the backbone network of the Microcystis detection model includes a cascaded input layer, a convolutional layer, four multidimensional feature extraction modules, and an SPPF module. Each multidimensional feature extraction module includes a cascaded full-dimensional dynamic convolutional module and a C2F module. Figure 3 Backbone Network The four dashed boxes in the Bone diagram correspond to four multi-dimensional feature extraction modules, representing four layers from top to bottom. The entire system progressively extracts semantic features (such as Microcystis outlines, local structures, and overall semantics) from low to high levels by alternately stacking full-dimensional dynamic convolutional modules and C2F modules. Finally, after multi-scale pooling of the high-level features using SPPF (Spatial Pyramid Pooling - Fast), the features are concatenated to enhance the receptive field and fuse contextual information at different scales, outputting deep features that are then passed to the Neck network. The C2F module within the multi-dimensional feature extraction modules is the basic feature extraction unit, balancing computational cost and feature representation capability by combining convolution and residual structures. For specific processing details, please refer to existing technologies; this application will not elaborate further.
[0029] The input microscopic scan image is sequentially processed through four multidimensional feature extraction modules, which then output four feature maps of progressively smaller size. Figure 3The size of the feature maps output by the four multi-dimensional feature extraction modules from top to bottom gradually decreases. Each multi-dimensional feature extraction module extracts the features of the corresponding size feature map in the spatial dimension, input channel dimension, and output channel dimension.
[0030] Traditional YOLOv5's convolutional module is based on static convolution with only one kernel. However, in the detection of microscopic images of Microcystis algae, the sample conditions are often very complex, with many impurities in the water sample and overlapping algae, which easily leads to the loss of feature information and results in missed or false detections. By introducing full-dimensional dynamic convolution (ODConv), the feature extraction capability of the backbone network is improved, reducing information loss. ODConv simultaneously focuses on the dynamic dimensions of the spatial, input, and output channels, using a novel multi-dimensional attention mechanism to learn four attention types in the kernel space and apply them to the corresponding convolutional kernels. This achieves dynamic adaptation to input features, not only improving the feature extraction capability of convolutional operations but also effectively reducing the number of parameters.
[0031] ODConv consists of two parts: an adaptive parameter generation module and a dynamic convolution module. The specific processing steps are as follows: Input features... x After processing through a GAP layer, a fully connected (FC) layer, and a ReLU function, four output branches are generated. The first three branches are first processed by an FC layer to predict the spatial location of the convolutional kernel, the input channel weights, and the output channel weights, respectively, and then activated by a Sigmoid function to generate the output branches. , , The attention scalar is obtained by passing the fourth branch through the fully connected (FC) layer to predict the weights of different convolutional kernels, and finally passing it through the Softmax function. The formula for ODConv can be defined as:
[0032] in, x and y These represent the input and output features, respectively; × represents multiplication. Represents convolution operation; Attention scalar representing spatial dimension This represents the attention scalar representing the input channel dimension. This represents the attention scalar of the output channel dimension. express The attention scalar of the convolution kernel, i It is an integer parameter and .
[0033] Because algal water samples have diverse environments, the backgrounds of the acquired microscopic scanning images are relatively complex, making them susceptible to interference when extracting Microcystis features. To enhance the network's ability to detect Microcystis features, a hybrid local channel attention mechanism (MLCA) is introduced to improve the network's expression performance.
[0034] The neck network of the Microcystis detection model introduces a hybrid local channel attention module at the end of the neck network of the YOLOv5 model. After cross-scale feature fusion of the four feature maps output by the backbone network, the neck network of the Microcystis detection model uses the hybrid local channel attention module for feature enhancement, resulting in three fused feature maps and one enhanced feature map. Figure 3 As shown, the multi-scale features output by the backbone network are processed by C2F in the neck network, then upsampled to enhance resolution before being concatenated with the shallow features to achieve cross-scale feature fusion. The Hybrid Local Channel Attention (MLCA) module at the end extracts local and global information by incorporating channel attention and spatial attention mechanisms. It focuses on key regions through attention weights, suppresses background noise, and enhances effective features, thereby improving feature discrimination in complex backgrounds and increasing network detection accuracy. The traditional YOLOv5 model outputs only three feature maps, while the Microcystis detection model, by introducing the MLCA module, ultimately outputs four feature maps, with the newly added enhanced feature maps containing richer and more effective feature information.
[0035] The specific workflow of MLCA is as follows: Figure 4 As shown, the input feature vector (dimensions C, W, H) undergoes two pooling steps. First, local spatial features are extracted using Local Average Pooling (LAP), resulting in the output dimensions ks. Then, the input features are transformed through one-dimensional convolution (Conv1d) via two branches. The first branch performs global average pooling (GAP) to capture the entire feature map information, followed by one-dimensional convolution for reconstruction. The second branch directly reconstructs the features. Finally, the two branches fuse the feature information to obtain global contextual information, and unpooling (UNAP) restores the original dimensions of the two vectors, achieving mixed attention. The Conv1d kernel size k is proportional to the channel dimension C. When capturing local interaction information, only the relationship between each channel and its k neighboring channels is considered. The formula for calculating k is as follows:
[0036] in, C It is the number of channels. k It is the size of the convolution kernel. and `x` and `y` are hyperparameters, with a default value of 2.
[0037] In the detection of Microcystis images, the dataset exhibits significant variations in target scale, leading to feature information conflicts between different scale levels. Furthermore, the dataset contains numerous small, single-celled Microcystis algae. Traditional YOLOv5 models downsample the input images, filtering out some low-level features. Therefore, these small target image features are easily lost, resulting in poor small target detection performance.
[0038] To solve this problem, such as Figure 3 As shown, a 160×160 small target detection head is added to the adaptive spatial feature fusion (ASFF) detection head to construct the multi-level adaptive spatial feature fusion (MASFF) structure of the head network of the Microcystis detection model. Adding to the original three ASSF detection heads (e.g., 80×80, 40×40, 20×20), the head network of the Microcystis detection model contains a total of four detection heads, corresponding to... Figure 3 The MASFF1~MASFF4 detectors, with a resolution of 160×160, are designed for single-celled microcystis algae. They retain more details (such as cell edges and textures) through higher resolution feature maps, thus solving the problem of feature loss of small targets caused by downsampling. The other three detectors detect larger populations (microcystis algae populations) or background areas, achieving full coverage of targets at multiple scales.
[0039] The MASFF mechanism mainly consists of two steps: functional feature adjustment and adaptive feature fusion. Feature adjustment aims to resize the feature map to match the size of the detection head, ensuring its scale remains constant. Feature fusion involves weighting and fusing the weights of the four feature layers with the feature map. In the Microcystis detection model, the four detection heads of the head network weight and fuse the three fused feature maps and one enhanced feature map output from the neck network, respectively, after resizing to highlight the Microcystis target features. Convolution operations are then performed on the fused feature maps to obtain four detection result maps of different sizes, each containing the location and category information of the Microcystis cells. The four detection result maps output by the model at different sizes require post-processing to obtain the final predicted bounding box position, width, height, and category information of the Microcystis target. For specific post-processing procedures, please refer to existing technologies; this application will not elaborate further.
[0040] In one embodiment, the trained Microcystis detection model includes: (1) Obtain multiple microscopic scanning images of the target water area under different water quality conditions, and label the Microcystis cells in each microscopic scanning image to construct a Microcystis image dataset; the Microcystis image dataset includes microscopic scanning images of the target water area under normal conditions, as well as microscopic scanning images of the target water area during Microcystis bloom.
[0041] When constructing the Microcystis image dataset, microscopic scan images with fewer and more impurities in the samples can be extracted to enrich the dataset and enhance the training effect. Image annotation software (such as LabelImg) is used to classify each microscopic scan image in the selected Microcystis image dataset, selecting PascalVOC format to generate an XML format annotation file corresponding to each microscopic scan image.
[0042] The specific method for classifying Microcystis cells in microscopic scanning images is as follows: Microcystis cells in the microscopic scanning images are labeled using bounding boxes. When the distance between any Microcystis cell and all surrounding Microcystis cells is greater than the diameter of a single Microcystis cell, and the bounding boxes of any Microcystis cell do not overlap, the Microcystis cell is labeled as a single-celled Microcystis and marked as "Microcystis_1" on the image. Otherwise, the Microcystis cell is labeled as a Microcystis population and marked as "Microcystis_2" on the image. The final labeling result is as follows: Figure 5 As shown.
[0043] (2) Perform image enhancement on the Microcystis image dataset, use the enhanced Microcystis image dataset for model training, and use the PIOU loss function and optimizer to adjust the model parameters until the model converges, thereby training the Microcystis detection model.
[0044] The constructed Microcystis image dataset was randomly divided into training, validation, and test datasets in a 7:2:1 ratio. Image enhancement operations were performed on the training dataset to generate more images and improve the model's generalization ability. Specific image enhancement operations can be selected according to actual needs, including adding Gaussian noise, rotation, scaling, translation, mirroring, cropping, and color transformation.
[0045] During model training, considering that traditional YOLOv5 uses CIoU as the localization loss function, the CIoU loss function, by introducing an aspect ratio correction factor, addresses the issue of shape similarity measurement to some extent. However, CIoU often suffers from an increase in the predicted bounding box during regression, leading to slower convergence. To solve this problem, this application uses the PIoU loss function. PIoU incorporates a penalty factor P that adapts to the target size and a penalty function. This is used to guide the predicted bounding boxes to regress more effectively, thereby improving the model's convergence speed and enhancing the network's detection accuracy for occluded targets and multiple targets. The penalty factor P is defined as follows:
[0046] in, , , and It is the absolute value of the distance between the corresponding edges of the predicted bounding box and the labeled bounding box. and These are the width and height of the label box.
[0047] Penalty function The specific formula for calculating PIOU is as follows:
[0048]
[0049]
[0050] Where IOU represents the intersection-union ratio of the predicted bounding box and the labeled bounding box, L IOU It is the bounding box loss function, L PIOU It is the PIOU loss function.
[0051] Step 3: Calculate the density of Microcystis in the water sample based on the location and type of Microcystis cells in the microscopic scanning image; the types of Microcystis cells include single-celled Microcystis and Microcystis populations, and the Microcystis population contains multiple single-celled Microcystis.
[0052] Microcystis cells are approximately spherical, and commonly appear in samples as single cells or colonies. Single cells represent unicellular Microcystis, while colonies represent Microcystis populations. Therefore, single cells are labeled "Microcystis_1," and colonies are labeled "Microcystis_2." To accurately count all Microcystis cells in the microscopic scanning images of the samples and determine the Microcystis density in the water samples, the following steps were taken: Based on the location and type of Microcystis cells in the microscopic scanning image, the area of each type of single-celled Microcystis is determined, and the average area of single-celled Microcystis is calculated based on the total number of all types of single-celled Microcystis. The area of each type of Microcystis community is determined, and the number of single-celled Microcystis contained in each Microcystis community is calculated based on the average area of single-celled Microcystis, thus obtaining the total number of single-celled Microcystis in the microscopic scanning image. The density of Microcystis in the water sample is determined based on the volume of the water sample.
[0053] In one embodiment, the specific method for determining the area of a single-celled Microcystis or a Microcystis population is as follows: based on the position of any type of Microcystis cell in a microscopic scanning image, the outline of the Microcystis cell is extracted using a threshold segmentation algorithm, and the area of the outline is calculated.
[0054] Specifically, based on the X and Y coordinates of the single-celled Microcystis alginate labeled "Microcystis_1", a threshold segmentation algorithm in image processing was used to extract the contour of the single-celled Microcystis alginate. The contour of the single-celled Microcystis alginate is shown in the figure below. Figure 6 As shown in (a); calculate the area value corresponding to the contour; count the total number of single-celled Microcystis with the label "Microcystis_1" according to the method, and calculate the average area S. If the label "Microcystis_1" is not detected, give the default diameter R of the single-celled Microcystis and the area S corresponding to the diameter.
[0055] Based on the X and Y coordinates of the Microcystis colony labeled "Microcystis_2", the contour of the Microcystis colony was extracted using a threshold segmentation algorithm in image processing. The contour of the Microcystis colony is shown below. Figure 6 As shown in (b), calculate the area value corresponding to the outline, divide the area value by the average area S of the single-celled Microcystis, and obtain the number of single-celled Microcystis contained in the Microcystis population, thus realizing the counting of single-celled Microcystis in the Microcystis population.
[0056] Finally, the density of Microcystis in the collected water sample was calculated based on the volume of the water sample. The volume of the water sample used in this application was 0.1 mL. Algal density is an important indicator for measuring the amount of algae in a water body, and is generally expressed as the number of cells per unit volume, with the unit being: cells / L.
[0057] Step 4: Input the water quality parameters and Microcystis density of the current time and several consecutive historical times before it into the pre-trained LSTM prediction model to predict the Microcystis density in the future predetermined time period, and issue an early warning when the Microcystis density exceeds the algal bloom density threshold.
[0058] In one embodiment, the LSTM prediction model trained includes: (1) Obtain the water quality monitoring data sequence of the target water area within a predetermined historical period. The water quality monitoring data at each historical moment includes water quality parameters and microcystis density. The water quality parameters indicate the water quality of the target water area.
[0059] Sampling points in the target water area are pre-fixed, and sampling time is selected according to actual needs. This application collects water quality parameters from the sampling points in the target water area over the past three years, including dissolved oxygen, pH, turbidity, water temperature, conductivity, permanganate index, ammonia nitrogen, total phosphorus, and total nitrogen. Simultaneously, Microcystis density data for these sampling points during the same period are also collected. The raw water quality monitoring data are then cleaned and normalized. Data cleaning removes non-numerical values and null values to ensure data accuracy. Data normalization can be performed by selecting the normalization base based on the value range for different water quality parameters.
[0060] The preprocessed water quality monitoring data were arranged chronologically to form a long-term water quality monitoring data sequence, which served as the dataset for training the LSTM neural network. The dataset was divided into a training set, a validation set, and a test set in a 7:2:1 ratio. The training and validation sets were used to train the parameters of the LSTM neural network, while the test set was used to test the prediction accuracy of the network.
[0061] (2) The water quality parameters and Microcystis density of the historical time window of the water quality monitoring data sequence are used as the input of the LSTM neural network, and the Microcystis density of the future time window is used as the output of the LSTM neural network. The backpropagation algorithm is used to adjust the network parameters until the model performance requirements are met, and the LSTM prediction model is trained.
[0062] The lengths of the historical and future time windows used in the water quality monitoring data sequence during training can be pre-set according to actual needs. For example, if it is necessary to predict the density of Microcystis aeruginosa for the next 3 days based on the current time and the water quality monitoring data of the previous 3 days, then the historical time window is any consecutive 3 days in the water quality monitoring data sequence, and the future time window is the consecutive 3 days after the water quality monitoring data corresponding to the historical time window. However, it is necessary to ensure that both the historical and future time windows are within the time span of the water quality monitoring data sequence. The network parameters are adjusted through the backpropagation algorithm, enabling the LSTM neural network to learn the complex relationship between the quantity of Microcystis aeruginosa and the time series features. At the same time, strategies such as cross-validation are used to evaluate the model's performance, prevent overfitting, and optimize the model's prediction accuracy and generalization ability.
[0063] After model training, error analysis can be performed on the test set data to verify the predictive performance of the LSTM neural network. The prediction results on the test set are compared with the actual observed data, and the model's prediction accuracy is evaluated by calculating metrics such as root mean square error. The model meets performance requirements when the prediction accuracy reaches a predetermined accuracy threshold, which can be customized. If the prediction results are close to the actual observed data, and the calculated prediction accuracy is not lower than the predetermined accuracy threshold, it indicates that the LSTM neural network can effectively capture the time-series characteristics of Microcystis bloom changes and can be used for monitoring and early warning of Microcystis blooms. If the error analysis does not meet expectations, the model should be retrained.
[0064] The future time period predicted by the trained LSTM prediction model is the same as the length of the future time window used for model training, and the length of the current input time and multiple consecutive historical times before it is the same as the length of the historical time window.
[0065] Finally, before using the prediction results output by the LSTM prediction model for early warning judgment, a Kalman filter algorithm is used to smooth the prediction results to reduce noise interference and the impact of random fluctuations, thereby further improving prediction accuracy and reliability. The algal bloom density threshold used for early warning judgment is set based on historical observation data of the target water area. Specific early warning methods can include message reminders, light and sound alarms, etc., and this application does not impose any restrictions.
[0066] The above descriptions are merely preferred embodiments of this application, and this application is not limited to the above embodiments. It is understood that other improvements and variations that can be directly derived or conceived by those skilled in the art without departing from the spirit and concept of this application should be considered to be included within the protection scope of this application.
Claims
1. A method for monitoring and early warning of Microcystis blooms based on YOLOv5 and LSTM, characterized in that, The method for monitoring and early warning of Microcystis blooms includes: Obtain microscopic scanning images of water samples from the target water area; The microscopic scan image is input into a Microcystis detection model built based on the YOLOv5 model, and the model outputs the location and category of Microcystis cells in the microscopic scan image. The Microcystis detection model includes a backbone network, a neck network, and a head network. The backbone network extracts multi-scale features from the input microscopic scan image, the neck network fuses the multi-scale features output by the backbone network, and the head network performs recognition and prediction based on the fused features. The backbone network of the Microcystis detection model introduces a full-dimensional dynamic convolution module to enhance the multi-dimensional feature extraction capability, the neck network of the Microcystis detection model introduces a hybrid local channel attention module to improve the feature discrimination in complex backgrounds, and the head network of the Microcystis detection model introduces a multi-level adaptive spatial feature fusion structure to enhance the detection performance of small targets. Based on the location and type of Microcystis cells in the microscopic scanning images, the density of Microcystis in the water sample was calculated; the types of Microcystis cells include single-celled Microcystis and Microcystis populations, and the Microcystis populations contain multiple single-celled Microcystis. The water quality parameters and Microcystis density of the current time and several consecutive historical times before it are input into a pre-trained LSTM prediction model to predict the Microcystis density in a predetermined future period and to issue an early warning when the Microcystis density exceeds the threshold of algal bloom density.
2. The method for monitoring and early warning of Microcystis blooms according to claim 1, characterized in that, The backbone network of the Microcystis detection model includes a cascaded input layer, a convolutional layer, four multidimensional feature extraction modules, and an SPPF module. Each multidimensional feature extraction module includes a cascaded full-dimensional dynamic convolutional module and a C2F module. The input microscopic scan image passes through the four multidimensional feature extraction modules in sequence and outputs four feature maps with progressively smaller sizes. Each multidimensional feature extraction module extracts the features of the corresponding size feature map in the spatial dimension, input channel dimension, and output channel dimension.
3. The method for monitoring and early warning of Microcystis blooms according to claim 1, characterized in that, The neck network of the Microcystis detection model introduces a hybrid local channel attention module at the end of the neck network of the YOLOv5 model. After the neck network of the Microcystis detection model performs cross-scale feature fusion on the four feature maps output by the backbone network, it uses the hybrid local channel attention module to enhance the features, resulting in three fused feature maps and one enhanced feature map.
4. The method for monitoring and early warning of Microcystis blooms according to claim 1, characterized in that, A 160×160 small target detection head is added to the adaptive spatial feature fusion detection head to construct a multi-level adaptive spatial feature fusion structure for the head network of the Microcystis detection model. The four detection heads of the head network of the Microcystis detection model respectively adjust the size of the three fusion feature maps and one enhancement feature map output by the neck network and then perform weighted fusion to obtain four detection result maps of different sizes. The detection result maps contain the location and category information of Microcystis cells.
5. The method for monitoring and early warning of Microcystis blooms according to claim 1, characterized in that, Determining the density of Microcystis algae in a water sample includes: Based on the location and type of Microcystis cells in the microscopic scanning image, the area of each type of single-celled Microcystis is determined, and the average area of single-celled Microcystis is calculated based on the total number of all types of single-celled Microcystis. The area of each category of Microcystis population was determined, and the number of single-celled Microcystis contained in each Microcystis population was calculated based on the average area of single-celled Microcystis. The total number of single-celled Microcystis in the microscopic scanning image was obtained, and the density of Microcystis in the water sample was determined based on the volume of the water sample.
6. The method for monitoring and early warning of Microcystis blooms according to claim 5, characterized in that, Based on the location of any type of Microcystis cells in the microscopic scanning image, the contour of the Microcystis cells is extracted using a threshold segmentation algorithm, and the area of the contour is calculated.
7. The method for monitoring and early warning of Microcystis blooms according to claim 1, characterized in that, The trained Microcystis detection model includes: Multiple microscopic scanning images of the target water area under different water quality conditions were acquired, and the Microcystis cells in each microscopic scanning image were labeled to construct a Microcystis image dataset. The Microcystis image dataset includes microscopic scanning images of the target water area under normal conditions and microscopic scanning images of the target water area during a Microcystis bloom. Image enhancement was performed on the Microcystis image dataset. The enhanced Microcystis image dataset was then used for model training. The PIoU loss function and optimizer were used to adjust the model parameters until the model converged, thus obtaining the Microcystis detection model.
8. The method for monitoring and early warning of Microcystis blooms according to claim 7, characterized in that, The classification and labeling of Microcystis cells in microscopic scanning images includes: Microcystis cells in a microscopic scanning image are labeled using bounding boxes. When the distance between any microcystis cell and all surrounding microcystis cells is greater than the diameter of a single microcystis cell, and the bounding boxes of any microcystis cells do not overlap, the microcystis cell is labeled as a single-celled microcystis. Otherwise, the microcystis cell is labeled as a microcystis population.
9. The method for monitoring and early warning of Microcystis blooms according to claim 1, characterized in that, The LSTM prediction model obtained through training includes: Obtain the water quality monitoring data sequence of the target water area within a predetermined historical time period. The water quality monitoring data at each historical moment includes water quality parameters and Microcystis density. The water quality parameters indicate the water quality status of the target water area. The water quality parameters and Microcystis density of historical time windows in the water quality monitoring data sequence are used as inputs to the LSTM neural network, and the Microcystis density of future time windows is used as the output of the LSTM neural network. The backpropagation algorithm is used to adjust the network parameters until the model performance requirements are met, and the LSTM prediction model is trained.
10. The method for monitoring and early warning of Microcystis blooms according to claim 1, characterized in that, Before using the prediction results output by the LSTM prediction model for early warning judgment, the prediction results are smoothed by the Kalman filter algorithm to reduce the impact of random fluctuations.
