A water algae detection method, device, equipment and medium based on a diffusion model

By using a diffusion model-based algae detection method, pre-trained encoding and denoising networks are employed to process algae detection images, solving the inaccuracy problem caused by light and debris interference in algae detection and achieving accurate detection and rapid response for algae exceeding the standard.

CN119941696BActive Publication Date: 2026-05-29BEIJING DECK SMART TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING DECK SMART TECH CO LTD
Filing Date
2025-01-20
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing technologies for detecting algae in urban garden water bodies are inaccurate because the images captured by the surveillance cameras are affected by factors such as light and debris on the water surface.

Method used

An algae detection method based on a diffusion model is adopted. The original image is encoded and denoised by a pre-trained encoding network and a denoising network. The algae detection network is used for classification to achieve accurate detection of algae exceeding or not exceeding the standard.

Benefits of technology

It improves the accuracy and response speed of algae detection, provides direct decision-making basis, and helps to take timely measures to deal with water quality problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119941696B_ABST
    Figure CN119941696B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of intelligent garden management, in particular to a water algae detection method and device based on a diffusion model, equipment and a medium. The method comprises the following steps: acquiring an original image captured by a water algae detection area, inputting the original image into a pre-trained encoding network for encoding to obtain an encoding image output by the encoding network; inputting the encoding image and standard Gaussian noise into a pre-trained denoising network to obtain a quality-enhanced image output by the denoising network; and inputting the quality-enhanced image into a pre-trained water algae detection network to obtain a classification result output by the water algae detection network, wherein the classification result is that water algae is over standard or not over standard. The application can realize accurate detection of over-standard water algae in water.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of intelligent garden management technology, and in particular to a method, device, equipment and medium for algae detection based on a diffusion model. Background Technology

[0002] In recent years, my country has accelerated the construction of various parks and scenic areas, and related supporting facilities have been gradually improved, providing good places for surrounding residents to relax, exercise, and play. However, excessive algae growth in urban park water bodies not only affects aesthetics but may also release toxins, harming human health and the ecological environment.

[0003] With the continuous popularization and in-depth development of smart garden applications, the use of visual data collected by park surveillance cameras and artificial intelligence algorithms to identify the algae content in water bodies can greatly reduce the cost of collecting test samples, improve the efficiency of garden management, promote the construction of smart cities, and drive the development of ecological civilization.

[0004] However, when using visual technology to detect algae, the images captured by the monitoring camera are subject to interference from many factors such as light and debris on the water surface, resulting in low image quality and inaccurate detection. Summary of the Invention

[0005] To improve the accuracy of algae detection in urban garden water bodies, this application provides an algae detection method, apparatus, equipment, and medium based on a diffusion model.

[0006] Firstly, this application provides a method for algae detection based on a diffusion model, employing the following technical solution:

[0007] A diffusion-based algae detection method includes:

[0008] The original image of the algae detection area is acquired, and the original image is input into a pre-trained encoding network for encoding to obtain the encoded image output by the encoding network.

[0009] The encoded image and standard Gaussian noise are input into a pre-trained denoising network to obtain a quality-enhanced image output by the denoising network.

[0010] The enhanced image is input into a pre-trained algae detection network to obtain the classification result output by the algae detection network, which is either algae exceeding the standard or algae not exceeding the standard.

[0011] By adopting the above technical solution, the original image is directly derived from the algae detection area, enabling real-time monitoring of water quality and improving response speed. The pre-trained encoding network can extract and encode key information (such as algae characteristics and water quality status) from the original image into a low-dimensional representation, i.e., an encoded image. This reduces the amount of data while retaining key information for subsequent processing. The encoded image provides a more easily processed input for the denoising network, helping to remove redundant and noise information from the image. By inputting the encoded image along with standard Gaussian noise into the pre-trained denoising network, noise in the image can be removed, improving image quality. Using the encoded image as a denoising guide ensures that the quality-enhanced image output by the denoising network accurately corresponds to the content captured in the original image. The pre-trained algae detection network can accurately determine whether algae exceed the standard based on the features in the quality-enhanced image. The classification results provide direct decision-making basis for water quality management personnel, helping to take timely measures to address water quality issues. This application can achieve accurate detection of algae exceeding the standard in water bodies.

[0012] In a preferred embodiment, this application can be further configured such that the pre-training process of the encoding network and the denoising network includes:

[0013] Collect multiple high-quality images captured by a high-definition camera device, as well as multiple interfering images with the same shooting area corresponding to each high-quality image;

[0014] The high-quality image and the interference image are paired one by one to obtain multiple training samples with complete pairing. Each training sample includes a high-quality image and an interference image with the same shooting area.

[0015] The neural network is trained using the multiple training samples to obtain the trained encoding network and denoising network.

[0016] By adopting the above technical solution, high-quality images captured by high-definition cameras and corresponding interference images of the region are collected and paired as training samples. This allows us to make full use of these diverse image data to train the neural network, enabling it to learn to extract key features from interference images and remove noise, thereby generating enhanced denoised images.

[0017] In a preferred embodiment, this application can be further configured such that: the step of training the neural network using the plurality of training samples to obtain the trained encoding network and denoising network includes:

[0018] A noise-adding step is performed on each high-quality image in the plurality of training samples to obtain a noise image after noise addition on each high-quality image. Each noise image is sampled to obtain a noise sample. The noise-adding step includes: starting from the initial step, gradually adding Gaussian noise to the current high-quality image and recording the noise distribution added in each step until a preset step is reached.

[0019] Two neural networks are trained using the interference images and noise samples corresponding to the high-quality images from the multiple training samples to obtain the trained encoding network and denoising network.

[0020] By adopting the above technical solution, Gaussian noise is gradually added to high-quality images and the noise distribution at each step is recorded. Then, these noisy images (i.e., noisy images) and their corresponding noise samples are used to train the neural network together with the interference images. This enables the encoding network to learn to extract effective features from noisy images, while the denoising network can accurately predict and remove noise from the images. This not only enhances the robustness of the neural network to noise, but also improves its ability to extract useful information from complex environments, thereby ensuring the high performance of the trained encoding network and denoising network in the algae detection task.

[0021] In a preferred embodiment, this application can be further configured as follows: training two neural networks using noise samples corresponding to interfering images and high-quality images from the plurality of training samples to obtain a trained encoding network and a denoising network includes:

[0022] Starting from the preset step, the process gradually moves forward to the initial step. In each step, denoising and parameter update operations are performed. After the initial step is completed, the trained encoding network and denoising network are obtained.

[0023] The denoising operation includes: encoding the interference image input in the current step using a first neural network to obtain a current encoded image; inputting the noise sample input in the current step, the current step, and the current encoded interference image into a second neural network to predict the noise distribution to be removed in the current step; updating the noise sample input in the current step using the noise distribution to be removed; and using the updated noise sample as the input of the second neural network in the next step of the current step.

[0024] The parameter update operation includes: calculating the difference between the noise distribution added in the current step and the noise distribution to be removed based on the loss function as the loss function value of the current step, and updating the parameters of the first neural network and the second neural network based on the loss function value.

[0025] By adopting the above technical solution, the network gradually advances from the preset step to the initial step, and performs denoising and parameter update operations in each step. This allows for the progressive optimization of the performance of the encoding and denoising networks. In the denoising operation, the first neural network encodes the interfering image into the current encoded image, while the second neural network uses the current encoded image and noise samples to predict the distribution of noise to be removed and updates the noise samples accordingly. The parameter update operation updates the parameters of the two neural networks based on the loss function value. This progressive iterative training method not only improves the network's sensitivity to noise and its ability to remove noise, but also ensures the stability and accuracy of the network when processing complex interfering images through fine parameter adjustments, ultimately resulting in high-performance encoding and denoising networks.

[0026] In a preferred example, this application can be further configured such that the loss function includes:

[0027] ;

[0028] in, This represents the loss function value at the current step. This indicates the noise distribution added in the current step. Indicates the current step. This represents the noise sample in the current step. Indicates the currently encoded interference image. This indicates the distribution of noise to be removed in the current step; The KL distance represents the difference between the noise distribution added in the current step and the noise distribution to be removed.

[0029] By adopting the above technical solution and minimizing the loss function, the network can gradually learn to predict and remove noise in images more accurately, while maintaining effective encoding of key information, thereby improving the accuracy of the model.

[0030] In a preferred embodiment, this application can be further configured such that the pre-training process of the algae detection network includes:

[0031] Collect multiple algae sample images, including negative sample images representing algae exceeding the standard and positive sample images representing algae not exceeding the standard;

[0032] Each algae sample image is labeled, and the label includes whether the algae exceed the standard or not;

[0033] The algae detection network was trained using multiple labeled algae sample images.

[0034] By adopting the above technical solution and training the classification network with actual sample data containing positive and negative sample images, the recognition accuracy and generalization ability of the algae detection network are significantly improved, providing strong technical support for water quality monitoring and water environment protection.

[0035] Secondly, this application provides an algae detection device based on a diffusion model, which adopts the following technical solution:

[0036] An algae detection device based on a diffusion model includes:

[0037] The encoding module is used to encode the received raw image of the algae detection area using a pre-trained encoding network to obtain an encoded image;

[0038] A denoising module is used to receive the encoded image and standard Gaussian noise, and output a quality-enhanced image using a pre-trained denoising network;

[0039] The algae detection module is used to detect the quality-enhanced image using a pre-trained algae detection network to obtain a classification result, which is either algae exceeding the standard or algae not exceeding the standard.

[0040] Thirdly, this application provides an electronic device that adopts the following technical solution:

[0041] One or more processors;

[0042] Memory;

[0043] At least one application, wherein the at least one application is stored in memory and configured to be executed by at least one processor, the at least one application being configured to: execute the diffusion-based algae detection method as described in any of the first aspects.

[0044] Fourthly, this application provides a computer-readable storage medium, which adopts the following technical solution:

[0045] A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the algae detection method based on a diffusion model as described in any of the first aspects.

[0046] In summary, this application includes the following beneficial technical effects:

[0047] In this application, the original image is directly derived from the algae detection area, enabling real-time monitoring of water quality and improving response speed. The pre-trained encoding network extracts and encodes key information (such as algae characteristics and water quality status) from the original image into a low-dimensional representation, i.e., an encoded image. This reduces the amount of data while retaining key information for subsequent processing. The encoded image provides a more easily processed input for the denoising network, helping to remove redundant and noise information from the image. By inputting the encoded image along with standard Gaussian noise into the pre-trained denoising network, noise in the image can be removed, improving image quality. Using the encoded image as a denoising guide ensures that the quality-enhanced image output by the denoising network accurately corresponds to the content captured in the original image. The pre-trained algae detection network can accurately determine whether algae exceed the standard based on the features in the quality-enhanced image. The classification results provide direct decision-making basis for water quality management personnel, helping to take timely measures to address water quality issues. This application can achieve accurate detection of algae exceeding the standard in water bodies. Attached Figure Description

[0048] Figure 1 This is a schematic flowchart of a diffusion-based algae detection method provided in an embodiment of this application;

[0049] Figure 2 This is a schematic diagram of the original diffusion model provided in the embodiments of this application;

[0050] Figure 3 This is a model architecture diagram provided in the embodiments of this application;

[0051] Figure 4 This is a schematic diagram of the structure of an algae detection device based on a diffusion model provided in an embodiment of this application;

[0052] Figure 5 This is a schematic diagram illustrating the application of an algae detection device based on a diffusion model, as provided in an embodiment of this application.

[0053] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0054] The following is in conjunction with the appendix Figure 1 -Appendix Figure 6 This application will be described in further detail.

[0055] This specific embodiment is merely an explanation of this application and is not intended to limit it. After reading this specification, those skilled in the art can make modifications to this embodiment without contributing any inventive step, but such modifications are protected by patent law as long as they fall within the scope of the claims of this application.

[0056] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0057] Furthermore, the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this article, unless otherwise specified, generally indicates that the preceding and following related objects have an "or" relationship.

[0058] It should be noted that, in the optional embodiments of this application, the data related to object information, when applied to specific products or technologies, requires the permission or consent of the object. Furthermore, the collection, use, and processing of this data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. In other words, if the embodiments of this application involve data related to an object, it must be obtained with the object's authorization and consent, the authorization and consent of relevant departments, and in accordance with the relevant laws, regulations, and standards of the country and region. If the embodiments involve personal information, the acquisition of all personal information requires the individual's consent. If sensitive information is involved, the separate consent of the information subject is required. The embodiments also need to be implemented with the object's authorization and consent.

[0059] This application provides an algae detection method based on a diffusion model, such as... Figure 1 As shown, the method provided in this embodiment is executed by an electronic device, which can be a server or a terminal device. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be integrated into the algae detection device based on the diffusion model, or it can be a smartphone, tablet, laptop, desktop computer, etc., but is not limited to these. The terminal device and the server can be directly or indirectly connected through wired or wireless communication, and this embodiment does not impose any limitations.

[0060] The algae detection method based on a diffusion model provided in this application adopts the basic architecture of a diffusion model (Denoising Diffusion Probabilistic Models, DDPM), which consists of a forward process and a reverse process. The method provided in this application includes steps S101-S103, wherein:

[0061] S101. Obtain the original image of the algae detection area, input the original image into the pre-trained encoding network for encoding, and obtain the encoded image output by the encoding network.

[0062] Specifically, to achieve real-time detection of algae in water bodies, monitoring equipment (cameras) is installed in the areas to be monitored to acquire raw images containing water. However, due to factors such as lighting and environment, the acquired raw images are not clear enough and contain interference. Directly performing image recognition on the raw images results in inaccurate algae identification. Therefore, the algae detection method based on a diffusion model provided in this application improves the accuracy of algae identification by enhancing the image quality of the raw images and then identifying high-quality images. The acquisition frequency of the monitoring equipment for the raw images can be flexibly set based on practical experience.

[0063] The network structure of the coding network can be flexibly selected by technicians according to the actual hardware environment and business needs. The available coding structures include: Resnet18, Resnet34, Resnet50, and ViT.

[0064] S102. Input the encoded image and standard Gaussian noise into the pre-trained denoising network to obtain the quality-enhanced image output by the denoising network.

[0065] Specifically, the images generated by the original diffusion model exhibit randomness and diversity, differing significantly from the sample images input to the diffusion model. The original diffusion model consists of a forward process and a backward process; see [link to relevant documentation]. Figure 2 It illustrates the principle of the original diffusion model. The forward process includes: given an image as observation data x0, a series of hidden variables x are generated by continuously adding Gaussian noise. 1:T The final result x T It follows a standard Gaussian distribution, where the Gaussian noise added at each step is a known standard Gaussian noise. The reverse process includes: from the standard Gaussian distribution x... TThe algorithm samples noise as initial data, then continuously subtracts Gaussian noise at each step to finally reconstruct x0. The Gaussian noise subtracted at each step represents the quantity to be solved. The original diffusion model is solved by finding the variational lower bound and performing a series of simplifications to obtain the final optimization objective. The optimization objective is to make the quantity to be solved (the noise distribution to be removed) predicted in the inverse process as close as possible to the Gaussian noise added in the forward process.

[0066] This embodiment utilizes two deep neural networks (an encoding network and a denoising network). The encoding network encodes the original image, while the denoising network calculates the noise distribution to be removed at each step of the inverse process. After the model is trained, the inverse process is directly used to optimize the sample image. Specifically, the input is the original image to be optimized and standard Gaussian noise; through multiple steps of noise removal, an enhanced image is output. The encoded image, obtained from the original image, provides guidance in the denoising network, enabling the modified diffusion model to output a higher-quality image corresponding to the original image for algae detection.

[0067] S103. Input the quality-enhanced image into the pre-trained algae detection network to obtain the classification result output by the algae detection network, which is either algae exceeding the standard or algae not exceeding the standard.

[0068] Specifically, the pre-training process of the algae detection network includes: collecting multiple algae sample images, including negative sample images representing excessive algae and positive sample images representing normal algae levels; labeling each algae sample image with the label indicating whether algae exceed the standard or not; and training the algae detection network using the labeled algae sample images. Optionally, the algae sample images can be manually collected, with a maximum of 4000 images (2000 positive and 2000 negative). A convolutional neural network is used for training, with the number of training iterations set to 200, ultimately resulting in the trained algae detection network.

[0069] When the classification result indicates that the algae exceed the standard, an alert signal is sent to the management personnel's terminal device. When the classification result indicates that the algae do not exceed the standard, no operation is performed, and algae monitoring continues.

[0070] In this embodiment, the original image is directly derived from the algae detection area, enabling real-time monitoring of water quality and improving response speed. The pre-trained encoding network extracts and encodes key information (such as algae characteristics and water quality status) from the original image into a low-dimensional representation, i.e., an encoded image. This reduces the amount of data while retaining key information for subsequent processing. The encoded image provides a more easily processed input for the denoising network, helping to remove redundant and noise information from the image. By inputting the encoded image along with standard Gaussian noise into the pre-trained denoising network, noise in the image can be removed, improving image quality. Using the encoded image as a denoising guide ensures that the quality-enhanced image output by the denoising network accurately corresponds to the content captured in the original image. The pre-trained algae detection network can accurately determine whether algae exceed the standard based on the features in the quality-enhanced image. The classification results provide direct decision-making basis for water quality management personnel, helping to take timely measures to address water quality issues. This application can achieve accurate detection of algae exceeding the standard in water bodies.

[0071] One possible implementation of this application embodiment includes the pre-training process of the encoding network and the denoising network, comprising:

[0072] Collect multiple high-quality images captured by a high-definition camera device, as well as multiple interfering images with the same shooting area corresponding to each high-quality image;

[0073] High-quality images and interference images are paired one by one to obtain multiple training samples with complete pairing. Each training sample includes a high-quality image and an interference image with the same shooting area.

[0074] The neural network is trained using multiple training samples to obtain the trained encoding network and denoising network.

[0075] In this embodiment, high-quality images and interference images are used as training data and can be manually collected in a real aquatic environment. High-quality images are clear images without obstructions. Each high-quality image corresponds to a preset number of interference images. The interference images are taken in the same area as the high-quality images and are non-high-quality images with interfering factors. Interference images can be taken from different angles, under different lighting conditions, or at different distances than the high-quality images. A high-quality image and its corresponding interference image are combined to form a training sample. Optionally, the training data can be collected from the real aquatic environment of Wenyu River Park in Beijing. The number of high-quality sample images in the training data can be 2000, and the preset number of interference images corresponding to each high-quality image can be 5, resulting in 10000 training samples. These training samples are used to train the encoding network and the denoising network.

[0076] This embodiment collects and pairs high-quality images captured by a high-definition camera with corresponding interference images of the area as training samples. It can make full use of these diverse image data to train the neural network, enabling it to learn to extract key features from the interference images and remove noise, thereby generating enhanced denoised images.

[0077] One possible implementation of this application embodiment involves training a neural network using multiple training samples to obtain a trained encoding network and a denoising network, including:

[0078] A noise-adding step is performed on each high-quality image in multiple training samples to obtain a noise image after noise addition for each high-quality image. Each noise image is sampled to obtain a noise sample. The noise-adding step includes: starting from the initial step, Gaussian noise is gradually added to the current high-quality image, and the distribution of noise added in each step is recorded until a preset step is reached.

[0079] Two neural networks are trained using interfering images from multiple training samples and noise samples corresponding to high-quality images, resulting in a trained encoding network and a denoising network.

[0080] This embodiment modifies the inverse process based on the diffusion model, enabling the model to learn how to remove interference factors from sample images and generate high-quality images to be detected.

[0081] See Figure 3 The diagram illustrates the model architecture provided in this embodiment. The forward process uses high-quality sample images as input data and undergoes multiple diffusion steps, adding Gaussian noise at each step. The noise samples obtained from the noise-added image are standard Gaussian noise. In the forward process, the initial step is x0 to x1, and the preset step is x... T-1 To x T The reverse process introduces two neural networks, an encoding network (…). Figure 3 EN network in the middle) and denoising network ( Figure 3 The DN network in the diagram represents the noise distribution. The encoding network encodes the sample image to be processed (i.e., the interference image). The denoising network calculates the noise distribution to be removed at each step. The reverse process takes standard Gaussian noise and the encoded interference image as input, and generates a quality-enhanced image by progressively removing noise.

[0082] This embodiment adds Gaussian noise to high-quality images step by step and records the noise distribution at each step. Then, it uses these noisy images (i.e., noisy images) and their corresponding noise samples to train a neural network together with the interference images. This enables the encoding network to learn to extract effective features from noisy images, while the denoising network can accurately predict and remove noise from the images. This not only enhances the robustness of the neural network to noise but also improves its ability to extract useful information from complex environments, thereby ensuring the high performance of the trained encoding network and denoising network in the algae detection task.

[0083] One possible implementation of this application involves training two neural networks using interfering images from multiple training samples and noise samples corresponding to high-quality images, to obtain a trained encoding network and a denoising network, including:

[0084] Starting from the preset step, the process gradually moves forward to the initial step. In each step, denoising and parameter update operations are performed. After the initial step is completed, the trained encoding network and denoising network are obtained.

[0085] The denoising operation includes: encoding the interference image input in the current step using a first neural network to obtain the current encoded image; inputting the noise sample input in the current step, the current step, and the current encoded interference image into a second neural network to predict the noise distribution to be removed in the current step; updating the noise sample input in the current step using the noise distribution to be removed; and using the updated noise sample as the input of the second neural network in the next step of the current step.

[0086] The parameter update operation includes: calculating the difference between the noise distribution added in the current step and the noise distribution to be removed based on the loss function as the loss function value of the current step, and updating the parameters of the first neural network and the second neural network based on the loss function value.

[0087] The first neural network is trained to obtain the encoding network, and the second neural network is trained to obtain the denoising network.

[0088] In this embodiment, the reverse process takes the interfering image in the current training sample and the standard Gaussian noise obtained in the forward process as input, and gradually removes the noise to restore the high-quality image in the training sample.

[0089] Denoising operation: with step t (x t To x t-1 Taking the noise sample x as an example, the interference image to be processed is encoded to obtain EN(y), and then the noise sample x input in the current step is used. t The current step t and the current encoded interference image EN(y) are input into the DN network to obtain the noise distribution DN to be removed in the current step. θRemove DN from the noise samples in the current step. θ To obtain a new data distribution x t-1 The new data distribution x t-1 The noise samples are then input into the second neural network for the next step.

[0090] Parameter update operation: Calculate the loss function value for the current step based on the loss function expression, and update the parameters of the first and second neural networks based on the loss function value.

[0091] Repeat the denoising and parameter update operations until the original high-quality image is restored (i.e., the initial step is completed). After training, the EN and DN networks that can be used for image inpainting are obtained.

[0092] This embodiment progressively optimizes the performance of the encoding and denoising networks by advancing from a preset step to the initial step and performing denoising and parameter update operations at each step. In the denoising operation, the first neural network encodes the interfering image into the current encoded image, while the second neural network uses the current encoded image and noise samples to predict the distribution of noise to be removed and updates the noise samples accordingly. The parameter update operation updates the parameters of the two neural networks based on the loss function value. This progressive iterative training method not only improves the network's sensitivity to noise and its ability to remove noise, but also ensures the stability and accuracy of the network when processing complex interfering images through fine parameter adjustment, thus ultimately obtaining a high-performance encoding and denoising network.

[0093] One possible implementation of this application embodiment includes a loss function comprising:

[0094] ;

[0095] in, This represents the loss function value at the current step. This indicates the noise distribution added in the current step. Indicates the current step. This represents the noise sample in the current step. Indicates the currently encoded interference image. This indicates the distribution of noise to be removed in the current step; The KL distance represents the difference between the noise distribution added in the current step and the noise distribution to be removed.

[0096] Specifically, based on the loss function value, optimization algorithms (such as stochastic gradient descent SGD, Adam, RMSprop, etc.) can be used to update the parameters of the neural network according to the gradient.

[0097] In this embodiment, by minimizing the loss function, the network can gradually learn to predict and remove noise in images more accurately, while maintaining effective encoding of key information, thereby improving the accuracy of the model.

[0098] One possible implementation of this application embodiment, the pre-training process of the algae detection network, includes:

[0099] Multiple algae sample images were collected, including negative sample images representing algae exceeding the standard and positive sample images representing algae not exceeding the standard.

[0100] Each algae sample image is labeled, including whether the algae exceed the standard or not;

[0101] The algae detection network was trained using multiple labeled algae sample images.

[0102] In this embodiment, the network architecture of the algae detection network can be selected from Resnet18, Resnet34, Resnet50, ViT, etc. It is trained using a dataset of manually collected algae sample images to obtain a classification network for outputting whether the algae content exceeds the standard.

[0103] This embodiment uses actual sample data containing both positive and negative sample images to train a classification network, which significantly improves the recognition accuracy and generalization ability of the algae detection network, providing strong technical support for water quality monitoring and water environment protection.

[0104] The above embodiments describe a diffusion-based algae detection method from the perspective of process flow. The following embodiments describe a diffusion-based algae detection device from the perspective of apparatus. For details, please refer to the following embodiments.

[0105] This application provides an algae detection device based on a diffusion model, such as... Figure 4 As shown, the device may include:

[0106] The encoding module 401 is used to encode the received original image of the algae detection area using a pre-trained encoding network to obtain an encoded image;

[0107] The denoising module 402 is used to receive the encoded image and standard Gaussian noise, and output a quality-enhanced image using a pre-trained denoising network.

[0108] The algae detection module 403 is used to detect and classify the enhanced image using a pre-trained algae detection network, with the classification result being either algae exceeding the standard or algae not exceeding the standard.

[0109] During model training, ResNet50 can be used as the basic architecture for the EN encoding network, and the DN denoising network can adopt an MLP architecture, trained according to the aforementioned diffusion method to generate parameterized EN and DN networks. ResNet18 is used as the basic architecture for the CN classification network, trained for 200 epochs to generate a parameterized classification network. The encoding network is encapsulated into an encoding module, the denoising network into a denoising module, and the algae detection network into an algae detection module. One or more networks can be encapsulated in the same module; this embodiment is not limited to this. The encoding module, denoising module, and algae detection module are encapsulated into an algae detection device based on a diffusion model. The device can also include an alert module for sending alert signals. If a monitoring camera is installed in the algae detection area, such as in a park or scenic area, the single-frame image captured by the monitoring camera is resized and input into the device. The device outputs an image showing whether the algae content in the water exceeds the standard.

[0110] The algae detection device based on the diffusion model can operate in the following environment: Intel i9-10900X processor, NVIDIA GeForce RTX 3090 GPU, 128GB RAM, and Python 3.6 and PyTorch 1.4.0. Field verification shows that the algae detection device based on the diffusion model provided in this embodiment takes approximately 6 seconds to identify an algae in one test. Test results in Wenyuhe Park, Beijing, show that the device can accurately detect algae exceeding the standard with an accuracy rate of up to 75%.

[0111] Figure 5 The diagram illustrates the application of the diffusion-based algae detection device provided in this embodiment. Standard Gaussian noise and the acquired original image are input into the device. The EN network encodes the original image. The encoded image and standard Gaussian noise are input into the DN network for denoising to obtain a quality-enhanced image. The CN network classifies the quality-enhanced image and outputs the classification result.

[0112] The algae detection device based on the diffusion model provided in this embodiment can make a basic judgment on the algae content in the water by using image data collected by surveillance cameras in parks and scenic areas. Compared with traditional methods, the sample collection cost is almost negligible, saving a lot of costs. By modifying the diffusion model, it can enhance specific input images instead of randomly generating images. The enhanced images can improve the accuracy of algae detection, improve the efficiency of garden management, promote the construction of smart cities, and promote the development of ecological civilization.

[0113] This application provides an electronic device, such as... Figure 6 As shown, Figure 6The illustrated electronic device 600 includes a processor 601 and a memory 603. The processor 601 and the memory 603 are connected, for example, via a bus 602. Optionally, the electronic device 600 may also include a transceiver 604. It should be noted that in practical applications, the transceiver 604 is not limited to one type, and the structure of this electronic device 600 does not constitute a limitation on the embodiments of this application.

[0114] Processor 601 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 601 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0115] Bus 602 may include a pathway for transmitting information between the aforementioned components. Bus 602 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 602 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 6 The symbol is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0116] The memory 603 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto.

[0117] The memory 603 stores the application code that executes the solution of this application, and its execution is controlled by the processor 601. The processor 601 executes the application code stored in the memory 603 to implement the content shown in the aforementioned embodiment of the algae detection method based on the diffusion model.

[0118] Figure 6 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0119] This application provides a computer-readable storage medium storing a computer program that, when run on a computer, enables the computer to execute the contents shown in the aforementioned embodiments of the algae detection method based on a diffusion model.

[0120] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0121] The above are only some embodiments of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.

Claims

1. A method for detecting algae based on a diffusion model, characterized in that, include: The original image of the algae detection area is acquired, and the original image is input into a pre-trained encoding network for encoding to obtain the encoded image output by the encoding network. The encoded image and standard Gaussian noise are input into a pre-trained denoising network to obtain a quality-enhanced image output by the denoising network. The enhanced image is input into a pre-trained algae detection network to obtain the classification result output by the algae detection network, which is either algae exceeding the standard or algae not exceeding the standard. The pre-training process of the encoding network and the denoising network includes: Collect multiple high-quality images captured by a high-definition camera device, as well as multiple interfering images with the same shooting area corresponding to each high-quality image; The high-quality image and the interference image are paired one by one to obtain multiple training samples with complete pairing. Each training sample includes a high-quality image and an interference image with the same shooting area. The neural network is trained using the multiple training samples to obtain the trained encoding network and denoising network; The step of training the neural network using the multiple training samples to obtain the trained encoding network and denoising network includes: A noise-adding step is performed on each high-quality image in the plurality of training samples to obtain a noise image after noise addition on each high-quality image. Each noise image is sampled to obtain a noise sample. The noise-adding step includes: starting from the initial step, gradually adding Gaussian noise to the current high-quality image and recording the noise distribution added in each step until a preset step is reached. Two neural networks are trained using the interference images and noise samples corresponding to the high-quality images from the multiple training samples to obtain the trained encoding network and denoising network.

2. The algae detection method based on a diffusion model according to claim 1, characterized in that, The process of training two neural networks using noise samples corresponding to interfering images and high-quality images from the multiple training samples to obtain a trained encoding network and a denoising network includes: Starting from the preset step, the process gradually moves forward to the initial step. In each step, denoising and parameter update operations are performed. After the initial step is completed, the trained encoding network and denoising network are obtained. The denoising operation includes: encoding the interference image input in the current step using a first neural network to obtain a current encoded image; inputting the noise sample input in the current step, the current step, and the current encoded interference image into a second neural network to predict the noise distribution to be removed in the current step; updating the noise sample input in the current step using the noise distribution to be removed; and using the updated noise sample as the input of the second neural network in the next step of the current step. The parameter update operation includes: calculating the difference between the noise distribution added in the current step and the noise distribution to be removed based on the loss function as the loss function value of the current step, and updating the parameters of the first neural network and the second neural network based on the loss function value.

3. The algae detection method based on a diffusion model according to claim 2, characterized in that, The loss function includes: ; in, This represents the loss function value at the current step. This indicates the noise distribution added in the current step. Indicates the current step. This represents the noise sample in the current step. Indicates the currently encoded interference image. This indicates the distribution of noise to be removed in the current step; The KL distance represents the difference between the noise distribution added in the current step and the noise distribution to be removed.

4. The algae detection method based on a diffusion model according to claim 1, characterized in that, The pre-training process of the algae detection network includes: Collect multiple algae sample images, including negative sample images representing algae exceeding the standard and positive sample images representing algae not exceeding the standard; Each algae sample image is labeled, and the label includes whether the algae exceed the standard or not; The algae detection network was trained using multiple labeled algae sample images.

5. An algae detection device based on a diffusion model, characterized in that, include: The encoding module is used to encode the received raw image of the algae detection area using a pre-trained encoding network to obtain an encoded image; A denoising module is used to receive the encoded image and standard Gaussian noise, and output a quality-enhanced image using a pre-trained denoising network; The algae detection module is used to detect the quality-enhanced image using a pre-trained algae detection network to obtain a classification result, wherein the classification result is either algae exceeding the standard or algae not exceeding the standard. The device further includes a pre-training module, which, when performing the pre-training process of the encoding network and the denoising network, is specifically used for: Collect multiple high-quality images captured by a high-definition camera device, as well as multiple interfering images with the same shooting area corresponding to each high-quality image; The high-quality image and the interference image are paired one by one to obtain multiple training samples with complete pairing. Each training sample includes a high-quality image and an interference image with the same shooting area. The neural network is trained using the multiple training samples to obtain the trained encoding network and denoising network; When the pre-training module executes the process of training the neural network using the multiple training samples to obtain the trained encoding network and denoising network, it is specifically used for: A noise-adding step is performed on each high-quality image in the plurality of training samples to obtain a noise image after noise addition on each high-quality image. Each noise image is sampled to obtain a noise sample. The noise-adding step includes: starting from the initial step, gradually adding Gaussian noise to the current high-quality image and recording the noise distribution added in each step until a preset step is reached. Two neural networks are trained using the interference images and noise samples corresponding to the high-quality images from the multiple training samples to obtain the trained encoding network and denoising network.

6. An electronic device, characterized in that, include: At least one processor; Memory; At least one application, wherein the at least one application is stored in memory and configured to be executed by at least one processor, said at least one application being configured to: perform the diffusion-based algae detection method according to any one of claims 1-4.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed in a computer, the computer is instructed to perform the algae detection method based on the diffusion model as described in any one of claims 1-4.