Abnormal image detection method and device, electronic equipment and storage medium
By acquiring the target image and local images, VAE is used for reconstruction processing and global and local losses are calculated. Combined with KL divergence loss, the problem of not being able to identify image anomalies in existing technologies is solved, and high-quality image generation and anomaly detection are achieved.
Patent Information
- Application Number
- CN202410620289.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-17
- Publication Date
- 2025-11-18
AI Technical Summary
Existing technologies cannot effectively determine whether a reconstructed image is an abnormal image, which may result in quality problems in the generated image.
By acquiring the target image and local images, performing reconstruction processing, calculating global and local losses, and determining whether the image is an anomalous image based on the loss and value, using VAE for encoding and decoding to generate latent representation vectors, and combining KL divergence loss for loss calculation.
It improves the accuracy of abnormal image detection and the quality of image reconstruction, effectively identifying abnormal images and ensuring the quality of generated images.
Smart Images

Figure CN120976602A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of anomaly detection, and particularly relates to an abnormal image detection method and device, an electronic device and a storage medium. BACKGROUND
[0002] In the related scheme, a face image is cropped from a received image to obtain a target image; each part region of the face image is recognized, and an image corresponding to each part region is cropped from the face image to obtain a plurality of local images; the target image is input into a global portrait generation model to obtain a reconstructed target image; the local images are input into corresponding local portrait generation models to obtain a plurality of reconstructed local images; and the reconstructed target image and each reconstructed local image are fused to obtain a final target image. The method for obtaining the target image in the related scheme can obtain a high-quality image that is clear, beautiful and texture realistic, but cannot determine whether the final target image is an abnormal image. SUMMARY
[0003] The present disclosure provides an abnormal image detection method and device, an electronic device and a storage medium.
[0004] According to a first aspect of the present disclosure, an abnormal image detection method is provided, comprising:
[0005] obtaining a target image and a local image, the local image being at least part of the target image;
[0006] performing reconstruction processing on the target image and the local image to obtain a reconstructed target image and a reconstructed local image;
[0007] obtaining a global loss between the target image and the reconstructed target image according to a first difference value between a pixel value of each pixel point in the target image and a pixel value of a corresponding pixel point in the reconstructed target image, and obtaining a local loss between the local image and the reconstructed local image according to a second difference value between a pixel value of each pixel point in the local image and a pixel value of a corresponding pixel point in the reconstructed local image;
[0008] in response to a sum value of the global loss and the local loss being greater than a preset threshold, determining that the target image is an abnormal image.
[0009] In some embodiments of the present disclosure, performing reconstruction processing on the target image and the local image to obtain a reconstructed target image and a reconstructed local image comprises:
[0010] encoding the target image and the local image to obtain a first mean vector and a first standard deviation vector of the target image and a second mean vector and a second standard deviation vector of the local image;
[0011] sampling from a preset Gaussian distribution to obtain a first random noise vector and a second random noise vector;
[0012] obtaining a latent representation vector of the target image based on the first standard deviation vector, the first random noise vector and the first mean vector, and obtaining a latent representation vector of the local image based on the second standard deviation vector, the second random noise vector and the second mean vector, the latent representation vector of the target image being used to indicate a low-dimensional representation of the target image, and the latent representation vector of the local image being used to indicate a low-dimensional representation of the local image;
[0013] performing reconstruction processing on the latent representation vector of the target image and the latent representation vector of the local image to obtain a reconstructed target image and a reconstructed local image.
[0014] In some embodiments of the present disclosure, obtaining a latent representation vector of the target image based on the first standard deviation vector, the first random noise vector and the first mean vector, and obtaining a latent representation vector of the local image based on the second standard deviation vector, the second random noise vector and the second mean vector, comprises:
[0015] multiplying the first standard deviation vector and the first random noise vector to obtain a first product;
[0016] adding the first product and the first mean vector to obtain the latent representation vector of the target image;
[0017] and,
[0018] multiplying the second standard deviation vector and the second random noise vector to obtain a second product;
[0019] adding the second product and the second mean vector to obtain the latent representation vector of the local image.
[0020] In some embodiments of the present disclosure, the global loss between the target image and the reconstructed target image is obtained according to first difference values of pixel values of each pixel point in the target image and corresponding pixel points in the reconstructed target image, and the local loss between the local image and the reconstructed local image is obtained according to second difference values of pixel values of each pixel point in the local image and corresponding pixel points in the reconstructed local image, comprising:
[0021] accumulate squares of first difference values between pixel values of all pixel points in the target image and corresponding pixel points in the reconstructed target image to obtain a first sum value; and accumulate squares of second difference values between pixel values of all pixel points in the local image and corresponding pixel points in the reconstructed local image to obtain a second sum value;
[0022] determine the square root of the first sum value as a global loss between the target image and the reconstructed target image; and determine the square root of the second sum value as a local loss between the local image and the reconstructed local image.
[0023] In some embodiments of the present disclosure, after reconstructing the latent representation vector of the target image and the latent representation vector of the local image to obtain the reconstructed target image and the reconstructed local image, the abnormal image detection method provided by the present disclosure further comprises:
[0024] obtain a KL divergence loss between the target image and the reconstructed target image according to the mean and standard deviation in the latent representation vector of the target image, and obtain a KL divergence loss between the local image and the reconstructed local image according to the mean and standard deviation in the latent representation vector of the local image, wherein the latent representation vector of the target image is used to indicate a low-dimensional representation of the target image, and the latent representation vector of the local image is used to indicate a low-dimensional representation of the local image.
[0025] add the temporary global loss between the target image and the reconstructed target image to the KL divergence loss between the target image and the reconstructed target image to obtain a global loss between the target image and the reconstructed target image; and add the temporary local loss between the local image and the reconstructed local image to the KL divergence loss between the local image and the reconstructed local image to obtain a local loss between the local image and the reconstructed local image.
[0026] In some embodiments of the present disclosure, the KL divergence loss between the target image and the reconstructed target image is obtained according to the mean and standard deviation in the latent representation vector of the target image, and the KL divergence loss between the local image and the reconstructed local image is obtained according to the mean and standard deviation in the latent representation vector of the local image, comprising:
[0027] sample and fit the latent representation vector of the target image to obtain the mean and standard deviation of all values in the latent representation vector of the target image; and sample and fit the latent representation vector of the local image to obtain the mean and standard deviation of all values in the latent representation vector of the local image.
[0028] determine the KL divergence loss of the target image by using the mean and the standard deviation of all values in the latent representation vector of the target image and the mean and the standard deviation of a preset Gaussian distribution; and determine the KL divergence loss of each local image in the target image by using the mean and the standard deviation of all values in the latent representation vector of the local image and the mean and the standard deviation of a preset Gaussian distribution.
[0029] In some embodiments of the present disclosure, the global loss between the target image and the reconstructed target image is added to the KL divergence loss between the target image and the reconstructed target image to obtain the global loss between the target image and the reconstructed target image; and the global loss between the local image and the reconstructed local image is added to the KL divergence loss between the local image and the reconstructed local image to obtain the local loss between the local image and the reconstructed local image. After that, the abnormal image detection method provided by the present disclosure further comprises:
[0030] multiply the global loss between the target image and the reconstructed target image by a first preset coefficient to obtain a first product value; and multiply the local loss between the local image and the reconstructed local image by a second preset coefficient to obtain a second product value;
[0031] add the first product value and the second product value to obtain the sum of the global loss and the local loss.
[0032] According to a second aspect of the present disclosure, an abnormal image detection device is provided, comprising:
[0033] a first acquisition unit configured to acquire a target image and a local image, the local image being at least a part of the target image;
[0034] a reconstruction unit configured to perform reconstruction processing on the target image and the local image to obtain a reconstructed target image and a reconstructed local image;
[0035] a second acquisition unit configured to obtain a global loss between the target image and the reconstructed target image according to a first difference value between a pixel value of each pixel point in the target image and a pixel value of a corresponding pixel point in the reconstructed target image; and obtain a local loss between the local image and the reconstructed local image according to a second difference value between a pixel value of each pixel point in the local image and a pixel value of a corresponding pixel point in the reconstructed local image;
[0036] a determination unit configured to determine that the target image is an abnormal image in response to the sum of the global loss and the local loss being greater than a preset threshold.
[0037] According to a third aspect of the present disclosure, an electronic device is provided, comprising:
[0038] at least one processor; and
[0039] a memory communicatively connected to the at least one processor; wherein
[0040] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of the first aspect.
[0041] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to perform the method of the first aspect.
[0042] The present disclosure provides an abnormal image detection method and device, electronic equipment and storage medium. The abnormal image detection method comprises: obtaining a target image and a local image, the local image being at least part of the target image; performing reconstruction processing on the target image and the local image to obtain a reconstructed target image and a reconstructed local image; obtaining a global loss between the target image and the reconstructed target image according to a first difference value between a pixel value of each pixel point in the target image and a pixel value of a corresponding pixel point in the reconstructed target image; and obtaining a local loss between the local image and the reconstructed local image according to a second difference value between a pixel value of each pixel point in the local image and a pixel value of a corresponding pixel point in the reconstructed local image; and determining that the target image is an abnormal image in response to a sum value of the global loss and the local loss being greater than a preset threshold.
[0043] According to the scheme of the present disclosure, by obtaining a target image and a local image, the local image being at least part of the target image; performing reconstruction processing on the target image and the local image to obtain a reconstructed target image and a reconstructed local image, the target image can be reconstructed while taking into account the local image; obtaining a global loss between the target image and the reconstructed target image according to a first difference value between a pixel value of each pixel point in the target image and a pixel value of a corresponding pixel point in the reconstructed target image; and obtaining a local loss between the local image and the reconstructed local image according to a second difference value between a pixel value of each pixel point in the local image and a pixel value of a corresponding pixel point in the reconstructed local image; by determining whether the sum value of the global loss of the target image and the local loss is greater than a preset threshold, it is determined whether the target image is an abnormal image.
[0044] It should be understood that the matters described in this section are not intended to identify key or essential features of the embodiments of the application, nor are they used to limit the scope of the application. Other features of the application will be apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0045] The accompanying drawings are used to better understand the present scheme and do not limit the present disclosure. Among them:
[0046] Figure 1 A flowchart of an abnormal image detection method provided by an embodiment of the present disclosure is shown in the figure.
[0047] Figure 2 A structure diagram of a traditional VAE provided by an embodiment of the present disclosure is shown in the figure.
[0048] Figure 3 A flowchart of a method for obtaining a reconstructed target image and a reconstructed local image provided by an embodiment of the present disclosure is shown in the figure.
[0049] Figure 4 A structure diagram of a VAE provided by an embodiment of the present disclosure is shown in the figure.
[0050] Figure 5 A flowchart of a method for obtaining a global loss and a local loss provided by an embodiment of the present disclosure is shown in the figure.
[0051] Figure 6 A flowchart of an abnormal image detection method provided by an application example of the present disclosure is shown in the figure.
[0052] Figure 7 A structure diagram of an abnormal image detection device provided by an embodiment of the present disclosure is shown in the figure.
[0053] Figure 8 A schematic block diagram of an example electronic device provided by an embodiment of the present disclosure is shown in the figure. DETAILED DESCRIPTION
[0054] Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, which include various details of the embodiments of the present disclosure to help understanding, and should be considered as merely exemplary. Therefore, those skilled in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Also, in order to be clear and concise, the description below omits the description of well-known functions and structures.
[0055] An abnormal image detection method provided by an embodiment of the present disclosure, the method can be applied to a processor integrated with an image processing function, and the execution subject of the method can be a processor integrated with an image processing function, such as a graphical processing unit (GPU).
[0056] As shown in Figure 1 The method for detecting abnormal images provided by the embodiments of the present disclosure includes the following steps:
[0057] Step 101, obtaining a target image and a local image, the local image being at least a part of the target image;
[0058] In an embodiment, the target image can be obtained by an image collector, which can be a digital camera or a camera.
[0059] In an embodiment, the target image can also be obtained from a public image dataset.
[0060] In an embodiment, after obtaining the target image, in order to improve the accuracy of the detection result of the abnormal image, the target image should also be preprocessed.
[0061] In an embodiment, the preprocessing of the target image at least includes normalizing the target image and adjusting the size of the target image.
[0062] In an embodiment, the normalization of the target image can be achieved by mapping the pixel value of each pixel point of the target image to between 0 and 1.
[0063] In an embodiment, the size of the target image can be adjusted by image editing software, or the size of the target image can be adjusted by writing code using a programming language.
[0064] In an embodiment, the shape of the local image can be square or circular, and in the embodiments of the present disclosure, a square is taken as an example.
[0065] In an embodiment, the local image is a square region with a fixed aspect ratio.
[0066] In an embodiment, a plurality of images with different aspect ratios can be cropped from the target image to obtain at least one local image.
[0067] In an embodiment, a plurality of images with the same aspect ratio can also be cropped from the target image to obtain at least one local image.
[0068] In an embodiment, when the width and height of the at least one image cropped from the target image are the same as the width and height of the target image, the at least one local image obtained is the same as the target image.
[0069] In an embodiment, the aspect ratio can be determined as the aspect ratio of the abnormal region, such as a scratch which is usually of an elongated type, and the aspect ratio is determined as [1:16], and the generated elongated square can more accurately encompass the abnormal region.
[0070] Step 102: Reconstruct the target image and the local image to obtain the reconstructed target image and the reconstructed local image;
[0071] In one embodiment, by reconstructing the target image and the local image, the reconstructed target image and the reconstructed local image are of higher quality, and new target images and local images can be generated.
[0072] In one embodiment, the target image and the local image can be reconstructed using a VAE to obtain the reconstructed target image and the reconstructed local image.
[0073] In one embodiment, such as Figure 2 As shown, VAE includes an encoder and a decoder. The encoder is used to map the target image or local image to a low-dimensional latent space and generate a latent probability distribution to obtain a latent representation vector. The decoder is used to map the latent representation vector back to the high-dimensional space where the target image or local image is located and generate the target image or local image.
[0074] Step 103: Based on the first difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image, obtain the global loss between the target image and the reconstructed target image; and based on the second difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image, obtain the local loss between the local image and the reconstructed local image.
[0075] In one embodiment, the global loss is used to measure the difference between the target image before and after reconstruction, and the local loss is used to measure the difference between the local image before and after reconstruction.
[0076] In one embodiment, the global loss can be obtained by acquiring the reconstruction loss of the target image before and after reconstruction, and the local loss can be obtained by acquiring the reconstruction loss of the local image before and after reconstruction.
[0077] In one embodiment, the global loss can be determined based on the difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image; the local loss can be determined based on the difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image.
[0078] In an embodiment, since the Kullback-Leibler (KL) divergence loss is also generated in the reconstruction process of the target image and the local image, the loss determined based on the difference between the pixel value of each pixel point in the target image and the pixel value of the corresponding pixel point in the reconstructed target image can also be regarded as a temporary global loss, and then the sum or weighted sum of the temporary global loss and the KL divergence loss can be regarded as the global loss. Correspondingly, the loss determined based on the difference between the pixel value of each pixel point in the local image and the pixel value of the corresponding pixel point in the reconstructed local image can also be regarded as a temporary local loss, and then the sum or weighted sum of the temporary local loss and the KL divergence loss can be regarded as the local loss.
[0079] In an embodiment, the smaller the global loss is, the closer the reconstructed target image is to the target image, and the smaller the local loss is, the closer the reconstructed local image is to the local image.
[0080] In an embodiment, according to the first difference between the pixel value of each pixel point in the target image and the pixel value of the corresponding pixel point in the reconstructed target image, the global loss between the target image and the reconstructed target image can be calculated by using the mean square error; and according to the second difference between the pixel value of each pixel point in the local image and the pixel value of the corresponding pixel point in the reconstructed local image, the local loss between the local image and the reconstructed local image can be calculated by using the mean square error.
[0081] In an embodiment, according to the first difference between the pixel value of each pixel point in the target image and the pixel value of the corresponding pixel point in the reconstructed target image, the global loss between the target image and the reconstructed target image can also be calculated by using the Euclidean distance; and according to the second difference between the pixel value of each pixel point in the local image and the pixel value of the corresponding pixel point in the reconstructed local image, the local loss between the local image and the reconstructed local image can also be calculated by using the Euclidean distance.
[0082] In step 104, in response to the sum of the global loss and the local loss being greater than a preset threshold value, the target image is determined as an abnormal image.
[0083] In an embodiment, the preset threshold value is an experience value for determining the target image as an abnormal image in a related abnormal image detection method.
[0084] In an embodiment, by determining the target image whose sum of the global loss and the local loss is greater than the preset threshold value as an abnormal image, the accuracy of the abnormal image detection result can be improved.
[0085] The abnormal image detection method provided in this disclosure includes: acquiring a target image; cropping at least one image from the target image to obtain at least one local image; reconstructing the target image and the local image to obtain a reconstructed target image and a reconstructed local image; obtaining a global loss between the target image and the reconstructed target image based on a first difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image; and obtaining a local loss between the local image and the reconstructed local image based on a second difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image; and determining the target image as an abnormal image in response to the sum of the global loss and the local loss being greater than a preset threshold.
[0086] According to the scheme of this disclosure, a target image and a local image are acquired, wherein the local image is at least a portion of the target image; the target image and the local image are reconstructed to obtain a reconstructed target image and a reconstructed local image, which can consider the local image while reconstructing the target image; a global loss between the target image and the reconstructed target image is obtained based on a first difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image; and a local loss between the local image and the reconstructed local image is obtained based on a second difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image; and whether the target image is an abnormal image is determined by whether the sum of the global loss and the local loss of the target image is greater than a preset threshold.
[0087] In one embodiment, at least one region conforming to a preset ratio can be determined according to a preset ratio;
[0088] In one embodiment, there may be one or more preset ratios.
[0089] In one embodiment, the size of the preset ratio can be the same as the size of the abnormal region ratio.
[0090] In one embodiment, the preset ratio is the same, but the at least one region that conforms to the preset ratio can be different. For example, if the preset ratio is [3:4], the size of the at least one region that conforms to the preset ratio can be 30*40 or 60*80.
[0091] In one embodiment, at least one region-sized image can be cropped from the target image according to the region size to obtain at least one local image.
[0092] In one embodiment, an image identical to an image within at least one region of the target image may also be obtained from an image outside the target image to obtain at least one local image.
[0093] In one embodiment, at least one local image can be the same local image in the target image, or it can be a different local image in the target image.
[0094] In one embodiment, at least one local image may have overlapping regions in each local image.
[0095] In one embodiment, such as Figure 3 As shown, step 102 includes:
[0096] Step 301: Encode the target image and the local image to obtain the first mean vector and the first standard deviation vector of the target image and the second mean vector and the second standard deviation vector of the local image;
[0097] In one embodiment, the dimensions of the first mean vector and the first standard deviation vector are the same as the dimensions of the latent space of the target image; the dimensions of the second mean vector and the second standard deviation vector are the same as the dimensions of the latent space of the local image.
[0098] In one embodiment, the dimensions of the target image latent space and the dimensions of the local image latent space are preset.
[0099] In one embodiment, the values in the first mean vector are used to indicate the mean of the target image in the corresponding dimension of the latent space, such as the first value in the first mean vector indicating the mean of the target image in the first dimension of the latent space, and the values in the first standard deviation vector are used to indicate the standard deviation of the target image in the corresponding dimension of the latent space, such as the first value in the first standard deviation vector indicating the standard deviation of the target image in the first dimension of the latent space.
[0100] In one embodiment, the target image and local images can be encoded using an encoder in a VAE to obtain a first mean vector and a first standard deviation vector of the target image, and a second mean vector and a second standard deviation vector of the local images.
[0101] In one embodiment, the encoder in the VAE can be a multi-layer neural network consisting of convolutional layers, fully connected layers, etc.
[0102] Step 302: Sample from the preset Gaussian distribution to obtain the first random noise vector and the second random noise vector;
[0103] In one embodiment, the preset Gaussian distribution refers to the standard normal distribution, that is, a normal distribution with a mean of 0 and a variance of 1.
[0104] In one embodiment, a preset Gaussian distribution is used to provide a perturbation, increasing randomness.
[0105] In one embodiment, the first random noise vector and the second random noise vector are used to add randomness to the reconstructed target image and the reconstructed local image, respectively.
[0106] Step 303: Based on the first standard deviation vector, the first random noise vector, and the first mean vector, obtain the latent representation vector of the target image; and based on the second standard deviation vector, the second random noise vector, and the second mean vector, obtain the latent representation vector of the local image;
[0107] In one embodiment, the latent representation vector of the target image is used to indicate the low-dimensional representation of the target image, and the latent representation vector of the local image is used to indicate the low-dimensional representation of the local image.
[0108] In one embodiment, since the first random noise vector and the second random noise vector are different, the resulting latent representation vector of the target image and the latent representation vector of the local image are also different.
[0109] Step 304: Reconstruct the latent representation vector of the target image and the latent representation vector of the local image to obtain the reconstructed target image and the reconstructed local image.
[0110] In one embodiment, the latent representation vector of the target image and the latent representation vector of the local image can be reconstructed using the decoder in the VAE to obtain the reconstructed target image and the reconstructed local image.
[0111] In one embodiment, the decoder in the VAE is a multi-layer neural network that is symmetrical to the encoder structure.
[0112] In one embodiment, such as Figure 4 As shown, different decoders are used to reconstruct the global and local images.
[0113] In one embodiment, step 303 includes:
[0114] Multiply the first standard deviation vector and the first random noise vector to obtain the first product;
[0115] The first product is summed with the first mean vector to obtain the latent representation vector of the target image;
[0116] and,
[0117] Multiply the second standard deviation vector and the second random noise vector to obtain the second product;
[0118] The second product is summed with the second mean vector to obtain the latent representation vector of the target image.
[0119] In one embodiment, the latent representation vector of the target image is used to represent the features of the target image in the latent space of the target image, and the latent representation vector of the local image is used to represent the features of the local image in the latent space of the local image.
[0120] In one embodiment, such as Figure 5 As shown, step 103 includes:
[0121] Step 501: Accumulate the squares of the first differences between the pixel values of all pixels in the target image and the corresponding pixel values in the reconstructed target image to obtain a first sum; and accumulate the squares of the second differences between the pixel values of all pixels in the local image and the corresponding pixel values in the reconstructed local image to obtain a second sum.
[0122] In one embodiment, the target image and the reconstructed target image can be converted into grayscale images or red-green-blue (RGB) images to obtain binary or triple arrays of the target image and the reconstructed target image. The pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image can be obtained from the binary or triple arrays corresponding to the target image and the reconstructed target image. Similarly, the local image and the reconstructed local image can be converted into grayscale images or RGB images to obtain binary or triple arrays of the local image and the reconstructed local image. The pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image can be obtained from the binary or triple arrays corresponding to the local image and the reconstructed local image.
[0123] In one embodiment, if the target image and the reconstructed target image are converted into grayscale images to obtain a binary array of the target image and the reconstructed target image, then the difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image is determined as a first difference, which is also a binary array; if the local image and the reconstructed local image are converted into grayscale images to obtain a binary array of the local image and the reconstructed local image, then the difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image is determined as a second difference, which is also a binary array.
[0124] In one embodiment, if the target image and the reconstructed target image are converted into RGB images to obtain a triple array of the target image and the reconstructed target image, then the difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image is determined as the first difference, which is also a triple array; if the local image and the reconstructed local image are converted into RGB images to obtain a triple array of the local image and the reconstructed local image, then the difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image is determined as the second difference, which is also a triple array.
[0125] In one embodiment, when the first difference is a binary array or a ternary array, the sum of the squares of each value in each first difference is accumulated to obtain a first sum; and the sum of the squares of the second differences of all pixels in the local image is accumulated to obtain a second sum.
[0126] Step 502: Determine the first sum after square root as the global loss between the target image and the reconstructed target image; and determine the second sum after square root as the local loss between the local image and the reconstructed local image.
[0127] In one embodiment, the global loss is used to measure the difference between the target image before and after reconstruction, and the local loss is used to measure the difference between the local image before and after reconstruction.
[0128] In one embodiment, by determining the first sum after square root as the global loss between the target image and the reconstructed target image, and by determining the second sum after square root as the local loss between the local image and the reconstructed local image, the difference between the target image and the reconstructed target image, and the difference between the local image and the reconstructed local image can be measured more intuitively.
[0129] In one embodiment, after reconstructing the latent representation vector of the target image and the latent representation vector of the local image to obtain the reconstructed target image and the reconstructed local image, the anomaly image detection method further includes:
[0130] The KL divergence loss between the target image and the reconstructed target image is obtained based on the mean and standard deviation of the latent representation vector of the target image; and the KL divergence loss between the local image and the reconstructed local image is obtained based on the mean and standard deviation of the latent representation vector of the local image. The latent representation vector of the target image is used to indicate the low-dimensional representation of the target image, and the latent representation vector of the local image is used to indicate the low-dimensional representation of the local image.
[0131] In one embodiment, the KL divergence loss is used to measure the difference between the latent probability distribution and the prior distribution.
[0132] In one embodiment, the prior distribution typically refers to the standard normal distribution.
[0133] In one embodiment, the mean and standard deviation in the latent representation vector refer to the mean and standard deviation of all values in the latent representation vector.
[0134] The temporary global loss between the target image and the reconstructed target image is added to the KL divergence loss between the target image and the reconstructed target image to obtain the global loss between the target image and the reconstructed target image; and the temporary local loss between the local image and the reconstructed local image is added to the KL divergence loss between the local image and the reconstructed local image to obtain the local loss between the local image and the reconstructed local image.
[0135] In one embodiment, each local image corresponds to a temporary local loss and a KL divergence loss. Therefore, the local loss between a local image and the reconstructed local image refers to the sum of the local losses between all local images and the reconstructed local image.
[0136] In one embodiment, the KL divergence loss between the target image and the reconstructed target image is obtained based on the mean and standard deviation of the latent representation vector of the target image; and the KL divergence loss between the local image and the reconstructed local image is obtained based on the mean and standard deviation of the latent representation vector of the local image, including:
[0137] The latent representation vector of the target image is sampled and fitted to obtain the mean and standard deviation of all values in the latent representation vector of the target image; and the latent representation vector of the local image is sampled and fitted to obtain the mean and standard deviation of all values in the latent representation vector of the local image.
[0138] In one embodiment, by sampling and fitting the values in the latent representation vector of the target image, the probability distribution that the values in the latent representation vector of the target image conform to is determined, and the mean and standard deviation of all values in the latent representation vector of the target image are obtained; and by sampling and fitting the values in the latent representation vector of the local image, the probability distribution that the values in the latent representation vector of the local image conform to is determined, and the mean and standard deviation of all values in the latent representation vector of the local image are obtained.
[0139] The KL divergence loss of the target image is determined by using the mean and standard deviation of all values in the latent representation vector of the target image and the mean and standard deviation of a preset Gaussian distribution; and the KL divergence loss of each local image in the target image is determined by using the mean and standard deviation of all values in the latent representation vector of the local image and the mean and standard deviation of a preset Gaussian distribution.
[0140] In one embodiment, the preset Gaussian distribution is typically a standard normal distribution, i.e., the mean and standard deviation of the preset Gaussian distribution are 0 and 1, respectively.
[0141] In one embodiment, the sum of the squares of the mean and the squares of the standard deviations of all values in the latent representation vector of the target image is determined by using the mean and standard deviations of all values in the latent representation vector of the target image and the mean and standard deviations of a preset Gaussian distribution. The difference between this sum and the logarithm of the standard deviation is the KL divergence loss of the target image.
[0142] In one embodiment, the same method is used to determine the KL divergence loss for each local image in the target image.
[0143] In one embodiment, the abnormal image detection method further includes: adding the global temporary loss between the target image and the reconstructed target image to the KL divergence loss between the target image and the reconstructed target image to obtain the global loss between the target image and the reconstructed target image; and adding the temporary local loss between the local image and the reconstructed local image to the KL divergence loss between the local image and the reconstructed local image to obtain the local loss between the local image and the reconstructed local image.
[0144] The global loss between the target image and the reconstructed target image is multiplied by a first preset coefficient to obtain a first product value; and the local loss between the local image and the reconstructed local image is multiplied by a second preset coefficient to obtain a second product value.
[0145] In one embodiment, the first preset coefficient and the second preset coefficient are preset values.
[0146] In one embodiment, the sum of the first preset coefficient and the second preset coefficient is 1, such as the first preset coefficient being 0.68 and the second preset coefficient being 0.32.
[0147] Add the first product value to the second product value to obtain the sum of the global loss and the local loss.
[0148] In one embodiment, by adding the first product value to the second product value, the sum of the global loss and the local loss can be obtained, which can achieve the analysis of local images while analyzing the target image.
[0149] According to the scheme disclosed herein:
[0150] First, a target image and a local image are acquired, wherein the local image is at least a portion of the target image. The target image and the local image are then reconstructed to obtain a reconstructed target image and a reconstructed local image. This reconstruction process considers both the target image and the local image simultaneously. A global loss between the target image and the reconstructed target image is obtained based on a first difference between the pixel value of each pixel in the target image and the corresponding pixel value in the reconstructed target image. A local loss between the local image and the reconstructed local image is obtained based on a second difference between the pixel value of each pixel in the local image and the corresponding pixel value in the reconstructed local image. Finally, whether the target image is an abnormal image is determined by checking whether the sum of the global loss and the local loss is greater than a preset threshold.
[0151] Secondly, by adding the first product value to the second product value, the sum of the global loss and the local loss can be obtained, which can take into account the loss of the local image when analyzing the loss of the target image.
[0152] The following specific application examples further illustrate the abnormal image detection method provided in this disclosure.
[0153] Figure 6 A flowchart illustrating an abnormal image detection method provided as an application example of this disclosure is shown below. Figure 6 As shown in the example, the abnormal image detection method provided in this disclosure includes the following steps:
[0154] Step 601: Obtain the target image and a local image, wherein the local image is at least a portion of the target image;
[0155] Step 602: Encode the target image and the local image to obtain the first mean vector and the first standard deviation vector of the target image and the second mean vector and the second standard deviation vector of the local image;
[0156] Step 603: Sample from the preset Gaussian distribution to obtain the first random noise vector and the second random noise vector;
[0157] Step 604: Multiply the first standard deviation vector and the first random noise vector, and add them to the first mean vector to obtain the latent representation vector of the target image; and multiply the second standard deviation vector and the second random noise vector, and add them to the second mean vector to obtain the latent representation vector of the local image.
[0158] In one embodiment, the latent representation vector of the target image is used to indicate the low-dimensional representation of the target image, and the latent representation vector of the local image is used to indicate the low-dimensional representation of the local image.
[0159] Step 605: Reconstruct the latent representation vector of the target image and the latent representation vector of the local image to obtain the reconstructed target image and the reconstructed local image;
[0160] Step 606: Accumulate the squares of the first differences between the pixel values of all pixels in the target image and the corresponding pixel values in the reconstructed target image to obtain a first sum; and accumulate the squares of the second differences between the pixel values of all pixels in the local image and the corresponding pixel values in the reconstructed local image to obtain a second sum.
[0161] Step 607: Determine the first sum after square root extraction as the global loss between the target image and the reconstructed target image; and determine the second sum after square root extraction as the local loss between the local image and the reconstructed local image;
[0162] Step 608: Based on the mean and standard deviation in the latent representation vector of the target image, obtain the KL divergence loss between the target image and the reconstructed target image; and based on the mean and standard deviation in the latent representation vector of the local image, obtain the KL divergence loss between the local image and the reconstructed local image.
[0163] In one embodiment, the KL divergence loss between the target image and the reconstructed target image is obtained based on the mean and standard deviation of the latent representation vector of the target image; and the KL divergence loss between the local image and the reconstructed local image is obtained based on the mean and standard deviation of the latent representation vector of the local image, including:
[0164] The latent representation vector of the target image is sampled and fitted to obtain the mean and standard deviation of all values in the latent representation vector of the target image; and the latent representation vector of the local image is sampled and fitted to obtain the mean and standard deviation of all values in the latent representation vector of the local image.
[0165] The KL divergence loss of the target image is determined by using the mean and standard deviation of all values in the latent representation vector of the target image and the mean and standard deviation of a preset Gaussian distribution; and the KL divergence loss of each local image in the target image is determined by using the mean and standard deviation of all values in the latent representation vector of the local image and the mean and standard deviation of a preset Gaussian distribution.
[0166] Step 609: Add the temporary global loss between the target image and the reconstructed target image to the KL divergence loss between the target image and the reconstructed target image to obtain the global loss between the target image and the reconstructed target image; and add the temporary local loss between the local image and the reconstructed local image to the KL divergence loss between the local image and the reconstructed local image to obtain the local loss between the local image and the reconstructed local image.
[0167] Step 610: Multiply the global loss between the target image and the reconstructed target image by a first preset coefficient to obtain a first product value; and multiply the local loss between the local image and the reconstructed local image by a second preset coefficient to obtain a second product value;
[0168] Step 611: Add the first product value to the second product value to obtain the sum of the global loss and the local loss.
[0169] Step 612: In response to the sum of the global loss and the local loss being greater than a preset threshold, the target image is determined to be an abnormal image.
[0170] Corresponding to the above-described abnormal image detection method, this invention also proposes an abnormal image detection device. Since the device embodiments of this invention correspond to the method embodiments described above, details not disclosed in the device embodiments can be referred to in the method embodiments, and will not be repeated here.
[0171] Figure 7 This is a schematic diagram of the structure of an abnormal image detection device provided in an embodiment of the present disclosure, as shown below. Figure 7 As shown, the abnormal image detection device 700 includes:
[0172] The first acquisition unit 701 is used to acquire a target image and a local image, wherein the local image is at least a portion of the target image;
[0173] The reconstruction unit 702 is used to perform reconstruction processing on the target image and the local image to obtain the reconstructed target image and the reconstructed local image.
[0174] The second acquisition unit 703 is used to obtain the global loss between the target image and the reconstructed target image based on the first difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image; and to obtain the local loss between the local image and the reconstructed local image based on the second difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image.
[0175] The determination unit 704 is configured to determine the target image as an abnormal image in response to the sum of the global loss and the local loss being greater than a preset threshold.
[0176] In one embodiment, the reconstruction unit 702 is specifically used for:
[0177] The target image and the local image are encoded to obtain a first mean vector and a first standard deviation vector of the target image, and a second mean vector and a second standard deviation vector of the local image;
[0178] Sample from a preset Gaussian distribution to obtain a first random noise vector and a second random noise vector;
[0179] Based on the first standard deviation vector, the first random noise vector, and the first mean vector, a latent representation vector of the target image is obtained; and based on the second standard deviation vector, the second random noise vector, and the second mean vector, a latent representation vector of the local image is obtained. The latent representation vector of the target image is used to indicate the low-dimensional representation of the target image, and the latent representation vector of the local image is used to indicate the low-dimensional representation of the local image.
[0180] The latent representation vectors of the target image and the local image are reconstructed to obtain the reconstructed target image and the reconstructed local image.
[0181] In one embodiment, the reconstruction unit 702 is specifically used for:
[0182] Multiply the first standard deviation vector and the first random noise vector to obtain the first product;
[0183] The first product is summed with the first mean vector to obtain the latent representation vector of the target image;
[0184] and,
[0185] Multiply the second standard deviation vector and the second random noise vector to obtain the second product;
[0186] The second product is summed with the second mean vector to obtain the latent representation vector of the local image.
[0187] In one embodiment, the second acquisition unit 703 is specifically used for:
[0188] The first sum is obtained by accumulating the squares of the first differences between the pixel values of all pixels in the target image and the corresponding pixel values in the reconstructed target image; and the second sum is obtained by accumulating the squares of the second differences between the pixel values of all pixels in the local image and the corresponding pixel values in the reconstructed local image.
[0189] The first sum after square root is determined to be the global loss between the target image and the reconstructed target image; and the second sum after square root is determined to be the local loss between the local image and the reconstructed local image.
[0190] In one embodiment, the abnormal image detection device 700 further includes a global loss and local loss determination unit, which is used to:
[0191] The KL divergence loss between the target image and the reconstructed target image is obtained based on the mean and standard deviation of the latent representation vector of the target image; and the KL divergence loss between the local image and the reconstructed local image is obtained based on the mean and standard deviation of the latent representation vector of the local image. The latent representation vector of the target image is used to indicate the low-dimensional representation of the target image, and the latent representation vector of the local image is used to indicate the low-dimensional representation of the local image.
[0192] The temporary global loss between the target image and the reconstructed target image is added to the KL divergence loss between the target image and the reconstructed target image to obtain the global loss between the target image and the reconstructed target image; and the temporary local loss between the local image and the reconstructed local image is added to the KL divergence loss between the local image and the reconstructed local image to obtain the local loss between the local image and the reconstructed local image.
[0193] In one embodiment, the second acquisition unit 703 is specifically used for:
[0194] The latent representation vector of the target image is sampled and fitted to obtain the mean and standard deviation of all values in the latent representation vector of the target image; and the latent representation vector of the local image is sampled and fitted to obtain the mean and standard deviation of all values in the latent representation vector of the local image.
[0195] The KL divergence loss of the target image is determined by using the mean and standard deviation of all values in the latent representation vector of the target image and the mean and standard deviation of a preset Gaussian distribution; and the KL divergence loss of each local image in the target image is determined by using the mean and standard deviation of all values in the latent representation vector of the local image and the mean and standard deviation of a preset Gaussian distribution.
[0196] In one embodiment, the abnormal image detection device 700 further includes a loss adjustment unit, which is used for:
[0197] The global loss between the target image and the reconstructed target image is multiplied by a first preset coefficient to obtain a first product value; and the local loss between the local image and the reconstructed local image is multiplied by a second preset coefficient to obtain a second product value.
[0198] Add the first product value to the second product value to obtain the sum of the global loss and the local loss.
[0199] It should be noted that the foregoing explanation of the method embodiments also applies to the apparatus of this embodiment, and the principle is the same, so it is not limited in this embodiment.
[0200] According to embodiments of the present disclosure, the present disclosure also provides an electronic device and a non-transitory computer-readable storage medium storing computer instructions.
[0201] Specifically, this disclosure provides an electronic device, including:
[0202] At least one processor; and
[0203] A memory that is communicatively connected to at least one processor; wherein,
[0204] The memory stores instructions that can be executed by at least one processor, which enables the at least one processor to perform the steps of the aforementioned abnormal image detection method.
[0205] This disclosure provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to perform the steps of the aforementioned abnormal image detection method.
[0206] Figure 8 A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, in-vehicle devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0207] like Figure 8As shown, the electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes based on a computer program stored in ROM (Read-Only Memory) 802 or a computer program loaded from storage unit 808 into RAM (Random Access Memory) 803. The RAM 803 can also store various programs and data required for the operation of the device 800. The computing unit 801, ROM 802, and RAM 803 are interconnected via a bus 804. An I / O (Input / Output) interface 805 is also connected to the bus 804.
[0208] Multiple components in device 800 are connected to I / O interface 805, including: input unit 806, such as keyboard, mouse, etc.; output unit 807, such as various types of monitors, speakers, etc.; storage unit 808, such as disk, optical disk, etc.; and communication unit 809, such as network card, modem, wireless transceiver, etc. Communication unit 809 allows device 800 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0209] The computing unit 801 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, CPUs (Central Processing Units), GPUs (Graphics Processing Units), various special-purpose AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSPs (Digital Signal Processors), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as the anomaly image detection method. For example, in some embodiments, the anomaly image detection method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the methods described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the aforementioned abnormal image detection method by any other suitable means (e.g., by means of firmware).
[0210] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application-Specific Standard Products), SOCs (System-on-Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0211] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0212] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0213] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0214] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. An abnormal image detection method, characterized in that, include: Acquire a target image and a partial image, wherein the partial image is at least a portion of the target image; The target image and the local image are reconstructed to obtain the reconstructed target image and the reconstructed local image. The global loss between the target image and the reconstructed target image is obtained based on the first difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image; and the local loss between the local image and the reconstructed local image is obtained based on the second difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image. If the sum of the global loss and the local loss is greater than a preset threshold, the target image is determined to be an abnormal image.
2. The method according to claim 1, characterized in that, The step of reconstructing the target image and the local image to obtain the reconstructed target image and the reconstructed local image includes: The target image and the local image are encoded to obtain a first mean vector and a first standard deviation vector of the target image, and a second mean vector and a second standard deviation vector of the local image; Sample from a preset Gaussian distribution to obtain a first random noise vector and a second random noise vector; Based on the first standard deviation vector, the first random noise vector, and the first mean vector, a latent representation vector of the target image is obtained; and based on the second standard deviation vector, the second random noise vector, and the second mean vector, a latent representation vector of the local image is obtained. The latent representation vector of the target image is used to indicate the low-dimensional representation of the target image, and the latent representation vector of the local image is used to indicate the low-dimensional representation of the local image. The latent representation vectors of the target image and the local image are reconstructed to obtain the reconstructed target image and the reconstructed local image.
3. The method according to claim 2, characterized in that, The step of obtaining the latent representation vector of the target image based on the first standard deviation vector, the first random noise vector, and the first mean vector; and obtaining the latent representation vector of the local image based on the second standard deviation vector, the second random noise vector, and the second mean vector, includes: Multiply the first standard deviation vector and the first random noise vector to obtain the first product; The first product is summed with the first mean vector to obtain the latent representation vector of the target image; and, Multiply the second standard deviation vector and the second random noise vector to obtain the second product; The second product is summed with the second mean vector to obtain the latent representation vector of the local image.
4. The method according to claim 1, characterized in that, The step of obtaining the global loss between the target image and the reconstructed target image based on the first difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image; and obtaining the local loss between the local image and the reconstructed local image based on the second difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image, includes: The first sum is obtained by accumulating the squares of the first differences between the pixel values of all pixels in the target image and the corresponding pixel values in the reconstructed target image; and the second sum is obtained by accumulating the squares of the second differences between the pixel values of all pixels in the local image and the corresponding pixel values in the reconstructed local image. The first sum after square root determination is the global loss between the target image and the reconstructed target image; and the second sum after square root determination is the local loss between the local image and the reconstructed local image.
5. The method according to claim 2, characterized in that, After reconstructing the latent representation vector of the target image and the latent representation vector of the local image to obtain the reconstructed target image and the reconstructed local image, the method further includes: The KL divergence loss between the target image and the reconstructed target image is obtained based on the mean and standard deviation of the latent representation vector of the target image; and the KL divergence loss between the local image and the reconstructed local image is obtained based on the mean and standard deviation of the latent representation vector of the local image. The latent representation vector of the target image is used to indicate the low-dimensional representation of the target image, and the latent representation vector of the local image is used to indicate the low-dimensional representation of the local image. The temporary global loss between the target image and the reconstructed target image is added to the KL divergence loss between the target image and the reconstructed target image to obtain the global loss between the target image and the reconstructed target image; and the temporary local loss between the local image and the reconstructed local image is added to the KL divergence loss between the local image and the reconstructed local image to obtain the local loss between the local image and the reconstructed local image.
6. The method according to claim 5, characterized in that, The step of obtaining the KL divergence loss between the target image and the reconstructed target image based on the mean and standard deviation of the latent representation vector of the target image; and obtaining the KL divergence loss between the local image and the reconstructed local image based on the mean and standard deviation of the latent representation vector of the local image, includes: The latent representation vector of the target image is sampled and fitted to obtain the mean and standard deviation of all values in the latent representation vector of the target image; and the latent representation vector of the local image is sampled and fitted to obtain the mean and standard deviation of all values in the latent representation vector of the local image. The KL divergence loss of the target image is determined by using the mean and standard deviation of all values in the latent representation vector of the target image and the mean and standard deviation of a preset Gaussian distribution; and the KL divergence loss of each local image in the target image is determined by using the mean and standard deviation of all values in the latent representation vector of the local image and the mean and standard deviation of a preset Gaussian distribution.
7. The method according to claim 5, characterized in that, The method further includes, after adding the global loss between the target image and the reconstructed target image to the KL divergence loss between the target image and the reconstructed target image to obtain the global loss between the target image and the reconstructed target image; and adding the global loss between the local image and the reconstructed local image to the KL divergence loss between the local image and the reconstructed local image to obtain the local loss between the local image and the reconstructed local image, the method further includes: The global loss between the target image and the reconstructed target image is multiplied by a first preset coefficient to obtain a first product value; and the local loss between the local image and the reconstructed local image is multiplied by a second preset coefficient to obtain a second product value. Add the first product value to the second product value to obtain the sum of the global loss and the local loss.
8. An abnormal image detection device, characterized in that, include: The first acquisition unit is used to acquire a target image and a local image, wherein the local image is at least a portion of the target image; The reconstruction unit is used to perform reconstruction processing on the target image and the local image to obtain the reconstructed target image and the reconstructed local image. The second acquisition unit is used to obtain the global loss between the target image and the reconstructed target image based on the first difference between the pixel value of each pixel in the target image and the pixel value of the corresponding pixel in the reconstructed target image; and to obtain the local loss between the local image and the reconstructed local image based on the second difference between the pixel value of each pixel in the local image and the pixel value of the corresponding pixel in the reconstructed local image. A determining unit is configured to determine the target image as an abnormal image in response to the sum of the global loss and the local loss being greater than a preset threshold.
9. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1 to 7.