Diffusion model-based algae detection method, device, equipment and medium
Through the diffusion model-based algae detection method, the key information in the algae detection image is extracted and enhanced, and the problem of inaccurate algae detection in the prior art is solved, and accurate detection and real-time monitoring of the excessive algae in water bodies is achieved.
Patent Information
- Application Number
- CN202510080623.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-20
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2045-01-20
AI Technical Summary
In the prior art, when detecting algae in urban garden water bodies, the images collected by the surveillance camera are disturbed by factors such as light and debris on the water surface, resulting in low quality of the sample image and inaccurate detection.
The algae detection method based on the diffusion model is used to extract key information from the original image through the pre-trained coding network, combine it with the standard Gaussian noise input denoising network to improve the image quality, and input the quality enhancement image to the algae detection network for classification to determine whether the algae exceeds the standard.
Real-time monitoring of algae detection areas is achieved, the accuracy and response speed of detection are improved, and direct decision-making basis is provided, which helps to take timely measures to deal with water quality problems.
Smart Images

Figure CN119941696A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of intelligent garden management, and in particular to an algae detection method, device, equipment and medium based on a diffusion model. Background Art
[0002] In recent years, my country has accelerated the construction of various parks and scenic spots, and the relevant supporting facilities have been gradually improved, providing surrounding residents with a good place to relax, exercise, and have fun. The excessive growth of algae in urban garden water bodies not only affects the appearance, but also may release toxins, endangering human health and the ecological environment.
[0003] With the continuous popularization and in-depth development of smart garden applications, using visual data collected by park surveillance cameras and using artificial intelligence algorithms to identify the algae content in water bodies can greatly reduce the cost of collecting test samples, improve garden management efficiency, promote urban smart construction, and promote the development of ecological civilization.
[0004] However, when using visual technology to complete algae detection, the image quality of the sample is not high due to the interference of many factors such as light and water surface debris in the images collected by the surveillance camera, resulting in inaccurate detection. Summary of the invention
[0005] In order to improve the accuracy of algae detection in urban garden water bodies, the present application provides an algae detection method, device, equipment and medium based on a diffusion model.
[0006] In the first aspect, the present application provides a method for detecting algae based on a diffusion model, which adopts the following technical solutions: A method for detecting algae based on a diffusion model, comprising: Obtaining an original image taken in the algae detection area, inputting the original image into a pre-trained encoding network for encoding, and obtaining an encoded image output by the encoding network; Inputting the encoded image and standard Gaussian noise into a pre-trained denoising network to obtain a quality enhanced image output by the denoising network; The quality enhanced image is input into a pre-trained algae detection network to obtain a classification result output by the algae detection network, where the classification result is that the algae exceeds the standard or that the algae does not exceed the standard.
[0007] By adopting the above technical scheme, the original image is directly derived from the algae detection area, which can realize real-time monitoring of water quality and improve response speed; the pre-trained encoding network can extract and encode key information in the original image (such as algae characteristics, water quality conditions, etc.) into a low-dimensional representation, that is, an encoded image, which not only reduces the amount of data but also retains key information for subsequent processing. The encoded image provides a more easily processed input for the denoising network, which helps to remove redundant and noise information in the image. By inputting the encoded image together with standard Gaussian noise into the pre-trained denoising network, the noise in the image can be removed and the image quality can be improved. The encoded image is used as a denoising guide so that the quality enhanced image output by the denoising network accurately corresponds to the shooting content of the original image. The pre-trained algae detection network can accurately determine whether the algae exceeds the standard based on the characteristics in the quality enhanced image. The classification result provides a direct decision-making basis for water quality management personnel, which helps to take timely measures to deal with water quality problems. The present application can achieve accurate detection of algae exceeding the standard in water bodies.
[0008] In a preferred example, the present application can be further configured as follows: the pre-training process of the encoding network and the denoising network includes: Collecting a plurality of high-quality images captured by a high-definition camera device, and a plurality of interference images corresponding to the same shooting area as each high-quality image; Pairing the high-quality image and the interference image one by one to obtain a plurality of paired training samples, each training sample including 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 a trained encoding network and a denoising network.
[0009] By adopting the above technical solution, high-quality images taken by high-definition cameras and interference images of corresponding areas are collected and paired as training samples, and these diverse image data can be fully utilized to train the neural network, so that it can learn to extract key features from interference images and remove noise, thereby generating enhanced denoised images.
[0010] In a preferred example, the present application may be further configured as follows: the method of using the plurality of training samples to train a neural network to obtain a trained encoding network and a denoising network includes: Performing a noise adding step on each high-quality image in the plurality of training samples to obtain a noise image after noise addition to each high-quality image, and sampling each noise image to obtain a noise sample; wherein the noise adding step comprises: starting from an initial step, gradually adding Gaussian noise to the current high-quality image, and recording the distribution of the noise added in each step until a preset step is reached; Two neural networks are trained using the interference images in the multiple training samples and the noise samples corresponding to the high-quality images to obtain a trained encoding network and a denoising network.
[0011] By adopting the above technical solution, Gaussian noise is gradually added to the high-quality image and the noise distribution of 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 in the image. 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 algae detection tasks.
[0012] In a preferred example, the present application can be further configured as follows: the two neural networks are trained using the interference images in the multiple training samples and the noise samples corresponding to the high-quality images to obtain the trained encoding network and denoising network, including: Starting from the preset step, gradually moving forward to the initial step, in each step, performing a denoising operation and a parameter updating operation, and obtaining a trained encoding network and a denoising network after the initial step is completed; The denoising operation includes: using a first neural network to encode the interference image input at the current step to obtain a current encoded image; inputting the noise sample input at the current step, the current step and the current encoded interference image into a second neural network, predicting the distribution of noise to be removed at the current step, and updating the noise sample input at 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 updating operation includes: calculating the difference between the noise distribution added in the current step and the noise distribution to be removed as the loss function value of the current step based on the loss function, and updating the parameters of the first neural network and the second neural network based on the loss function value.
[0013] By adopting the above technical solution, the performance of the encoding network and the denoising network can be gradually optimized by gradually advancing from the preset step to the initial step and performing denoising operations and parameter updating operations in each step. In the denoising operation, the first neural network encodes the interference image into the current encoded image, and the second neural network uses the current encoded image and the noise sample to predict the noise distribution to be removed, and updates the noise sample accordingly. The parameter updating operation updates the parameters of the two neural networks based on the loss function value. This step-by-step iterative training method not only improves the network's sensitivity and removal ability to noise, but also ensures the stability and accuracy of the network when processing complex interference images through fine parameter adjustment, thereby ultimately obtaining a high-performance encoding network and denoising network.
[0014] In a preferred example, the present application can be further configured as follows: the loss function includes: ; in, Represents the loss function value of the current step, represents the noise distribution added in the current step, Indicates the current step, represents the noise sample of the current step, represents the current coded interference image, Represents the noise distribution to be removed at the current step; Represents the KL distance, which is used to represent the difference between the noise distribution added in the current step and the noise distribution to be removed.
[0015] By adopting the above technical solutions and minimizing the loss function, the network can gradually learn to more accurately predict and remove noise in the image while maintaining effective encoding of key information, thereby improving the accuracy of the model.
[0016] In a preferred example, the present application can be further configured as follows: the pre-training process of the algae detection network includes: Collecting a plurality of algae sample images, wherein the plurality of algae sample images include negative sample images indicating that the algae exceed the standard and positive sample images indicating that the algae do not exceed the standard; Annotating each algae sample image, wherein the annotation includes whether the algae exceeds the standard or whether the algae does not exceed the standard; A trained algae detection network is obtained by training with multiple labeled algae sample images.
[0017] By adopting the above technical solution and using actual sample data containing positive and negative sample images to train the classification network, 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.
[0018] In a second aspect, the present application provides an algae detection device based on a diffusion model, which adopts the following technical solution: A device for detecting algae based on a diffusion model, comprising: An encoding module, used for encoding the received original image of the algae detection area using a pre-trained encoding network to obtain an encoded image; A denoising module, configured 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 that the algae exceeds the standard or the algae does not exceed the standard.
[0019] In a third aspect, the present application provides an electronic device, which adopts the following technical solution: one or more processors; Memory; At least one application, wherein the at least one application is stored in a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute the algae detection method based on the diffusion model as described in any one of the first aspects.
[0020] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium stores a computer program thereon, which, when executed in a computer, causes the computer to execute the algae detection method based on the diffusion model as described in any one of the first aspects.
[0021] In summary, this application includes the following beneficial technical effects: In the present application, the original image is directly derived from the algae detection area, which can realize real-time monitoring of water quality and improve response speed; the pre-trained encoding network can extract and encode key information in the original image (such as algae characteristics, water quality conditions, etc.) into a low-dimensional representation, namely an encoded image, which not only reduces the amount of data but also retains key information for subsequent processing. The encoded image provides a more easily processed input for the denoising network, which helps to remove redundant and noise information in the image. By inputting the encoded image together with standard Gaussian noise into the pre-trained denoising network, the noise in the image can be removed and the image quality can be improved. The encoded image is used as a denoising guide so that the quality enhanced image output by the denoising network accurately corresponds to the shooting content of the original image. The pre-trained algae detection network can accurately determine whether the algae exceeds the standard based on the features in the quality enhanced image. The classification result provides a direct decision-making basis for water quality management personnel, which helps to take timely measures to deal with water quality problems. The present application can achieve accurate detection of algae exceeding the standard in water bodies. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 is a flow chart of an algae detection method based on a diffusion model provided in an embodiment of the present application; Figure 2 It is a schematic diagram of the principle of the original diffusion model provided in the embodiment of the present application; Figure 3 It is a model architecture diagram provided in the embodiment of the present application; Figure 4 is a structural schematic diagram of an algae detection device based on a diffusion model provided in an embodiment of the present application; Figure 5 is an application schematic diagram of an algae detection device based on a diffusion model provided in an embodiment of the present application; Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] The following is combined with Figure 1 -Attached Figure 6 This application is described in further detail.
[0024] This specific embodiment is merely an explanation of the present application and is not a limitation of the present application. After reading this specification, those skilled in the art may make modifications to the present embodiment without any creative contribution as needed, but such modifications are protected by the patent law as long as they are within the scope of the claims of the present application.
[0025] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0026] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.
[0027] It should be noted that in the optional embodiments of the present application, the object information and other related data involved, when the embodiments in the present application are applied to specific products or technologies, need to obtain the permission or consent of the object, and the collection, use and processing of the relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. In other words, if the embodiments of the present application involve data related to the object, it needs to be obtained with the authorization and consent of the object, the authorization and consent of the relevant departments, and in compliance with the relevant laws, regulations and standards of the country and region. If personal information is involved in the embodiments, the acquisition of all personal information needs to obtain the consent of the individual. If sensitive information is involved, the separate consent of the information subject needs to be obtained. The embodiments also need to be implemented with the authorization and consent of the object.
[0028] The present application embodiment provides a method for detecting algae based on a diffusion model. Figure 1 As shown, the method provided in the embodiment of the present application is performed by an electronic device, which can be a server or a terminal device, wherein the server can be an independent physical server, or 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 in the algae detection device based on the diffusion model, or can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, and the embodiment of the present application does not limit this.
[0029] The algae detection method based on the diffusion model provided in the present application adopts the basic architecture of the diffusion model (Denoising Diffusion Probabilistic Models, DDPM), and the diffusion model consists of a forward process and a reverse process. The method provided in the present application includes steps S101 to S103, wherein: S101, obtaining an original image taken in the algae detection area, inputting the original image into a pre-trained encoding network for encoding, and obtaining an encoded image output by the encoding network.
[0030] Specifically, in order to achieve real-time detection of algae in water bodies, monitoring equipment (monitoring cameras) are set up in the area to be detected to obtain the original image containing the water body. However, due to the influence of factors such as light and environment, the collected original image is not clear enough and there are interference factors. Direct image recognition is performed on the original image, and the identified algae is not accurate enough. Therefore, the algae detection method based on the diffusion model provided in this application can improve the accuracy of algae recognition by enhancing the image quality of the original image and then identifying the high-quality image. Among them, the acquisition frequency of the original image by the monitoring equipment can be flexibly set according to actual experience.
[0031] The network structure of the encoding network can be flexibly selected by technicians according to the actual hardware environment and business requirements. The optional encoding structures include: Resnet18, Resnet34, Resnet50, and ViT.
[0032] S102, inputting the encoded image and standard Gaussian noise into a pre-trained denoising network to obtain a quality enhanced image output by the denoising network.
[0033] Specifically, the images generated by the original diffusion model are random and diverse, and are quite different from the sample images input to the diffusion model. The original diffusion model consists of a forward process and a reverse process, see Figure 2 , which shows the principle diagram of the original diffusion model. The forward process includes: given an image as observation data x0, by continuously adding Gaussian noise, a series of hidden variables x are generated 1:T , and finally get x T Obey the standard Gaussian distribution, where the Gaussian noise added in each step is a known standard Gaussian noise. The reverse process includes: from the standard Gaussian distribution x T A noise is sampled as the initial data, and then Gaussian noise is continuously subtracted at each step, and finally x0 is restored, where the Gaussian noise subtracted at each step is 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 goal. The optimization goal is to make the quantity to be solved (the noise distribution to be removed) predicted in the reverse process and the Gaussian noise added in the forward process as close as possible.
[0034] This embodiment uses two deep neural networks (encoding network and denoising network). The encoding network is used to encode the original image, and the denoising network is used to calculate the noise distribution to be removed at each step of the reverse process. After the model is trained, the reverse process is directly used to optimize the sample image, that is, the original image to be optimized and standard Gaussian noise are input, and the noise is continuously removed through multiple steps to output a quality-enhanced image. The encoded image is obtained by encoding the original image, which can provide guidance in the denoising network, so that the reverse process of the modified diffusion model outputs an image corresponding to the original image and with higher quality for algae detection.
[0035] S103, inputting the quality enhanced image into a pre-trained algae detection network to obtain a classification result output by the algae detection network, where the classification result is that the algae exceeds the standard or the algae does not exceed the standard.
[0036] Specifically, the pre-training process of the algae detection network includes: collecting multiple algae sample images, the algae sample images include negative sample images representing that the algae exceeds the standard and positive sample images representing that the algae does not exceed the standard, labeling each algae sample image, the labeling includes that the algae exceeds the standard or that the algae does not exceed the standard; using the labeled multiple algae sample images for training to obtain a trained algae detection network. Optionally, the source of the algae sample images can be manually collected, the number of algae sample images can be 4000, of which 2000 are positive and negative sample images, and training is performed using a convolutional neural network. The number of training iterations can be set to 200, and finally a trained algae detection network is obtained.
[0037] When the classification result shows that the algae exceeds the standard, a warning signal is sent to the terminal device of the manager. When the classification result shows that the algae does not exceed the standard, no operation is performed and the algae detection continues.
[0038] In this embodiment, the original image comes directly from the algae detection area, which can realize real-time monitoring of water quality and improve response speed; the pre-trained encoding network can extract and encode key information in the original image (such as algae characteristics, water quality conditions, etc.) into a low-dimensional representation, that is, an encoded image, which not only reduces the amount of data but also retains key information for subsequent processing. The encoded image provides a more easily processed input for the denoising network, which helps to remove redundant and noise information in the image. By inputting the encoded image and standard Gaussian noise into the pre-trained denoising network, the noise in the image can be removed and the image quality can be improved. The encoded image is used as a denoising guide so that the quality enhanced image output by the denoising network accurately corresponds to the shooting content of the original image. The pre-trained algae detection network can accurately determine whether the algae exceeds the standard based on the characteristics in the quality enhanced image. The classification result provides a direct decision-making basis for water quality management personnel, which helps to take timely measures to deal with water quality problems. The present application can achieve accurate detection of algae exceeding the standard in water bodies.
[0039] In a possible implementation of the embodiment of the present application, the pre-training process of the encoding network and the denoising network includes: Collecting a plurality of high-quality images captured by a high-definition camera device, and a plurality of interference images corresponding to the same shooting area as each high-quality image; Pairing the high-quality images and the interference images one by one to obtain a plurality of paired training samples, each training sample including a high-quality image and an interference image with the same shooting area; The neural network is trained using multiple training samples to obtain a trained encoding network and a denoising network.
[0040] In this embodiment, high-quality images and interference images are used as training data and can be collected manually in a real water environment. High-quality images are images with no debris and clear pictures. Each high-quality image corresponds to a preset number of interference images. The interference image is consistent with the shooting area of the high-quality image. The interference image is a non-high-quality image with interference factors. The interference image can be shot at a different angle, different light, different distance, etc. from the high-quality image. A high-quality image and its corresponding interference image are combined into a training sample. Optionally, the training data can be collected from the real water 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, forming a total of 10,000 training samples. These training samples are used to train the encoding network and the denoising network.
[0041] This embodiment collects and pairs high-quality images taken by a high-definition camera with interference images of corresponding areas as training samples, and can fully utilize these diverse image data to train the neural network, so that it learns to extract key features from the interference images and remove noise, thereby generating an enhanced denoised image.
[0042] A possible implementation of the embodiment of the present application is to train a neural network using multiple training samples to obtain a trained encoding network and a denoising network, including: Performing a denoising step on each high-quality image in a plurality of training samples to obtain a noise image after denoising each high-quality image, and sampling each noise image to obtain a noise sample; wherein the denoising step includes: starting from an initial step, gradually adding Gaussian noise to the current high-quality image, and recording the distribution of the noise added in each step until a preset step is reached; The two neural networks are trained using interference images in multiple training samples and noise samples corresponding to high-quality images to obtain trained encoding networks and denoising networks.
[0043] This embodiment transforms the inverse process based on the diffusion model, so that the model can learn how to remove interference factors in the sample image and generate a high-quality image to be detected.
[0044] See also Figure 3 , which shows the model architecture diagram provided by this embodiment. The forward process uses a high-quality sample image as input data, and after multiple diffusion steps, a Gaussian noise is added in each step. The noise sample sampled from the noise-added noise image is a 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, the encoding network ( Figure 3 EN network in) and denoising network ( Figure 3 The DN network in Fig. 1 is used to encode the sample image to be processed (i.e., the interference image). The denoising network is used to calculate the noise distribution that needs to be removed at each step. The inverse process takes standard Gaussian noise and the encoded interference image as input, and generates a quality-enhanced image by gradually removing the noise.
[0045] This embodiment gradually adds Gaussian noise to the high-quality image and records the noise distribution of each step, and then uses these noisy images (i.e., noisy images) and their corresponding noise samples to train the neural network together with the interference images, so that the encoding network can learn to extract effective features from the noisy image, while the denoising network can accurately predict and remove the noise in the image, which 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.
[0046] A possible implementation of the embodiment of the present application is to train two neural networks using interference images in multiple training samples and noise samples corresponding to high-quality images to obtain trained encoding networks and denoising networks, including: Starting from the preset step, it gradually moves forward to the initial step. In each step, the denoising operation and parameter update operation are performed. After the initial step is completed, the trained encoding network and denoising network are obtained. The denoising operation includes: using the first neural network to encode the interference image input at the current step to obtain the current encoded image; inputting the noise sample input at the current step, the current step and the current encoded interference image into the second neural network, predicting the distribution of noise to be removed at the current step, updating the noise sample input at 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 updating 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.
[0047] Among them, after the first neural network training is completed, the encoding network is obtained, and after the second neural network training is completed, the denoising network is obtained.
[0048] In this embodiment, the reverse process uses the interference 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.
[0049] Denoising operation: Take the tth step (x t to x t-1) as an example, the interference image to be processed is encoded using the code to obtain EN(y), and then the noise sample x input in the current step is t , current step t, current coded interference image EN(y) is input into the DN network to obtain the noise distribution DN to be removed in the current step θ , remove DN from the noise samples of the current step θ , get the new data distribution x t-1 , the new data distribution x t-1 As noise samples, they are input into the second neural network in the next step.
[0050] Parameter update operation: Calculate the loss function value of the current step based on the loss function expression, and update the parameters of the first neural network and the second neural network based on the loss function value.
[0051] The denoising operation and parameter updating operation are repeated until the original high-quality image is restored (i.e., the initial step is completed). After the training is completed, the EN network and DN network that can be used for image restoration are obtained.
[0052] This embodiment can gradually optimize the performance of the encoding network and the denoising network by gradually advancing from the preset step to the initial step and performing denoising operations and parameter updating operations in each step. In the denoising operation, the first neural network encodes the interference image into the current encoded image, and the second neural network uses the current encoded image and the noise sample to predict the noise distribution to be removed, and updates the noise sample accordingly. The parameter updating operation updates the parameters of the two neural networks based on the loss function value. This step-by-step iterative training method not only improves the network's sensitivity and removal ability to noise, but also ensures the stability and accuracy of the network when processing complex interference images through fine parameter adjustment, thereby ultimately obtaining a high-performance encoding network and denoising network.
[0053] A possible implementation of the embodiment of the present application is a loss function, including: ; in, Represents the loss function value of the current step, represents the noise distribution added in the current step, Indicates the current step, represents the noise sample of the current step, represents the current coded interference image, Represents the noise distribution to be removed at the current step; Represents the KL distance, which is used to represent the difference between the noise distribution added in the current step and the noise distribution to be removed.
[0054] Specifically, based on the loss function value, an optimization algorithm (such as stochastic gradient descent SGD, Adam, RMSprop, etc.) can be used to update the parameters of the neural network according to the gradient.
[0055] By minimizing the loss function, the network can gradually learn to more accurately predict and remove noise in the image while maintaining effective encoding of key information, thereby improving the accuracy of the model.
[0056] In a possible implementation of the embodiment of the present application, the pre-training process of the algae detection network includes: Collecting a plurality of algae sample images, wherein the plurality of algae sample images include negative sample images indicating that the algae exceed the standard and positive sample images indicating that the algae do not exceed the standard; Label each algae sample image, including whether the algae exceeds the standard or not; A trained algae detection network is obtained by training with multiple labeled algae sample images.
[0057] In this embodiment, the network architecture of the algae detection network can be selected from: Resnet18, Resnet34, Resnet50, ViT, etc., and trained using an artificially collected algae sample image data set to obtain a classification network for outputting whether the algae content exceeds the standard.
[0058] This embodiment uses actual sample data containing positive and negative sample images to train the classification network, which significantly improves the recognition accuracy and generalization ability of the algae detection network, and provides strong technical support for water quality monitoring and water environment protection.
[0059] The above embodiment introduces an algae detection method based on a diffusion model from the perspective of method flow, and the following embodiment introduces an algae detection device based on a diffusion model from the perspective of a device. For details, please refer to the following embodiment.
[0060] The present application embodiment provides an algae detection device based on a diffusion model, such as Figure 4 As shown, the device may include: 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; A denoising module 402, for receiving the encoded image and standard Gaussian noise, and outputting a quality enhanced image using a pre-trained denoising network; The algae detection module 403 is used to detect the quality enhanced image using a pre-trained algae detection network to obtain a classification result, and the classification result is that the algae exceeds the standard or the algae does not exceed the standard.
[0061] During the model training process, Resnet50 can be used as the basic architecture of the EN encoding network, and the DN denoising network adopts the MLP architecture. It is trained according to the aforementioned diffusion method to generate parameterized EN networks and DN networks. Resnet18 is used as the basic architecture of the CN classification network, and 200 epochs are trained to generate a parameterized classification network. The encoding network is encapsulated into an encoding module, the denoising network is encapsulated into a denoising module, and the algae detection network is encapsulated into an algae detection module, wherein one or more networks can be encapsulated in the same module, which is not limited in this embodiment. The encoding module, the denoising module and the algae detection module are encapsulated into an algae detection device based on a diffusion model, and a warning module can also be provided in the device for sending a prompt signal. A surveillance camera is provided in the algae detection area, such as a park scenic area. The single-frame image collected by the surveillance camera is resized and input into the device, and the device outputs whether the algae content in the water body displayed by the image exceeds the standard.
[0062] The operating environment of the algae detection device based on the diffusion model can be: Intel i9-10900X processor, NVIDIA GeForce RTX 3090 GPU, 128G memory, deployment of Python 3.6 and Pytorch 1.4.0. After field verification, the algae detection device based on the diffusion model provided in this embodiment takes about 6 seconds to identify once. The test results in Wenyu River Park in Beijing show that the device can accurately detect algae exceeding the standard with an accuracy rate of up to 75%.
[0063] Figure 5 An application schematic diagram of an algae detection device based on a diffusion model provided in an embodiment of the present application is shown. Standard Gaussian noise and a collected original image are input into the device, the EN network encodes the original image, the encoded image and the standard Gaussian noise are input into the DN network for denoising to obtain a quality enhanced image, and the CN network classifies the quality enhanced image and outputs the classification result.
[0064] 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 body by using the image data collected by the surveillance cameras in the park scenic area. Compared with the traditional method, the sample collection cost is almost negligible, saving a lot of cost. By modifying the diffusion model, it can enhance the specific input image instead of randomly generating the image. The enhanced image 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.
[0065] An electronic device is provided in an embodiment of the present application, such as Figure 6 As shown, Figure 6The electronic device 600 shown includes: a processor 601 and a memory 603. The processor 601 and the memory 603 are connected, such as through a bus 602. Optionally, the electronic device 600 may also include a transceiver 604. It should be noted that in actual applications, the transceiver 604 is not limited to one, and the structure of the electronic device 600 does not constitute a limitation on the embodiments of the present application.
[0066] 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 may implement or execute 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 computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0067] The bus 602 may include a path to transmit information between the above components. The bus 602 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 602 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but it does not mean that there is only one bus or only one type of bus.
[0068] The memory 603 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.
[0069] The memory 603 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 601. The processor 601 is used to execute the application code stored in the memory 603 to implement the contents shown in the above-mentioned algae detection method embodiment based on the diffusion model.
[0070] Figure 6 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0071] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer-readable storage medium is run on a computer, the computer can execute the contents shown in the aforementioned embodiment of the algae detection method based on the diffusion model.
[0072] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0073] The above are only some implementation methods of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for detecting algae based on a diffusion model, characterized in that: include: Obtaining an original image taken in the algae detection area, inputting the original image into a pre-trained encoding network for encoding, and obtaining an encoded image output by the encoding network; Inputting the encoded image and standard Gaussian noise into a pre-trained denoising network to obtain a quality enhanced image output by the denoising network; The quality enhanced image is input into a pre-trained algae detection network to obtain a classification result output by the algae detection network, where the classification result is that the algae exceeds the standard or that the algae does not exceed the standard.
2. The algae detection method based on diffusion model according to claim 1 is characterized in that: The pre-training process of the encoding network and the denoising network includes: Collecting a plurality of high-quality images captured by a high-definition camera device, and a plurality of interference images corresponding to the same shooting area as each high-quality image; Pairing the high-quality image and the interference image one by one to obtain a plurality of paired training samples, each training sample including 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 a trained encoding network and a denoising network.
3. The algae detection method based on diffusion model according to claim 2 is characterized in that: The step of training the neural network using the plurality of training samples to obtain a trained encoding network and a denoising network includes: Performing a noise adding step on each high-quality image in the plurality of training samples to obtain a noise image after noise addition to each high-quality image, and sampling each noise image to obtain a noise sample; wherein the noise adding step comprises: starting from an initial step, gradually adding Gaussian noise to the current high-quality image, and recording the distribution of the noise added in each step until a preset step is reached; Two neural networks are trained using the interference images in the multiple training samples and the noise samples corresponding to the high-quality images to obtain a trained encoding network and a denoising network.
4. The algae detection method based on diffusion model according to claim 3 is characterized in that: The method of training two neural networks using the interference images in the plurality of training samples and the noise samples corresponding to the high-quality images to obtain the trained encoding network and denoising network includes: Starting from the preset step, gradually moving forward to the initial step, in each step, performing a denoising operation and a parameter updating operation, and obtaining a trained encoding network and a denoising network after the initial step is completed; The denoising operation includes: using a first neural network to encode the interference image input at the current step to obtain a current encoded image; inputting the noise sample input at the current step, the current step and the current encoded interference image into a second neural network, predicting the distribution of noise to be removed at the current step, and updating the noise sample input at 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 updating operation includes: calculating the difference between the noise distribution added in the current step and the noise distribution to be removed as the loss function value of the current step based on the loss function, and updating the parameters of the first neural network and the second neural network based on the loss function value.
5. The algae detection method based on diffusion model according to claim 4 is characterized in that: The loss function includes: ; in, Represents the loss function value of the current step, represents the noise distribution added in the current step, Indicates the current step, represents the noise sample of the current step, represents the current coded interference image, Represents the noise distribution to be removed at the current step; Represents the KL distance, which is used to represent the difference between the noise distribution added in the current step and the noise distribution to be removed.
6. The algae detection method based on diffusion model according to claim 1, characterized in that: The pre-training process of the algae detection network includes: Collecting a plurality of algae sample images, wherein the plurality of algae sample images include negative sample images indicating that the algae exceed the standard and positive sample images indicating that the algae do not exceed the standard; Annotating each algae sample image, wherein the annotation includes whether the algae exceeds the standard or whether the algae does not exceed the standard; A trained algae detection network is obtained by training with multiple labeled algae sample images.
7. An algae detection device based on a diffusion model, characterized in that: include: An encoding module, used for encoding the received original image of the algae detection area using a pre-trained encoding network to obtain an encoded image; A denoising module, configured 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 that the algae exceeds the standard or the algae does not exceed the standard.
8. 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 a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute the algae detection method based on the diffusion model according to any one of claims 1-6.
9. 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 caused to execute the algae detection method based on the diffusion model according to any one of claims 1 to 6.
Citation Information
Patent Citations
Image enhancement method, target identification method, equipment and medium
CN116205820A
Image mixed rain removal method and system based on depth-guided diffusion model
CN117455809A
Data generation method based on generative artificial intelligence model and block chain network
CN117591880A
Blue-green algae distribution map generation method and device based on diffusion model, and server
CN118968317A
Adaptive underwater image enhancement algorithm
CN119090747A