WO2023015843A1 - Anomaly detection method and apparatus, electronic device, computer readable storage medium, computer program, and computer program product - Google Patents

Anomaly detection method and apparatus, electronic device, computer readable storage medium, computer program, and computer program product Download PDF

Info

Publication number
WO2023015843A1
WO2023015843A1 PCT/CN2022/071448 CN2022071448W WO2023015843A1 WO 2023015843 A1 WO2023015843 A1 WO 2023015843A1 CN 2022071448 W CN2022071448 W CN 2022071448W WO 2023015843 A1 WO2023015843 A1 WO 2023015843A1
Authority
WO
WIPO (PCT)
Prior art keywords
image
abnormal
sample
detection
normal
Prior art date
Application number
PCT/CN2022/071448
Other languages
French (fr)
Chinese (zh)
Inventor
杨凯
尤志远
崔磊
Original Assignee
上海商汤智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 上海商汤智能科技有限公司 filed Critical 上海商汤智能科技有限公司
Publication of WO2023015843A1 publication Critical patent/WO2023015843A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/24Classification techniques
    • G06F18/243Classification techniques relating to the number of classes
    • G06F18/2433Single-class perspective, e.g. one-against-all classification; Novelty detection; Outlier detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/21Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
    • G06F18/214Generating training patterns; Bootstrap methods, e.g. bagging or boosting

Definitions

  • the present disclosure relates to machine vision technology, and in particular to an anomaly detection method, device, electronic equipment, computer-readable storage medium, computer program and computer program product.
  • an abnormality detection model is obtained through deep learning algorithm training to detect abnormal images. Deep learning algorithms often require a large number of high-quality training samples. However, the current learning methods based on normal samples and learning methods based on abnormal samples have different model structures and learning strategies. Therefore, the current deep learning methods are not suitable for different types of training samples. The compatibility of the model is poor, resulting in a single training sample that can be used, which not only reduces the flexibility of anomaly detection, but also reduces the accuracy of anomaly detection.
  • Embodiments of the present disclosure provide an anomaly detection method, device, electronic equipment, computer-readable storage medium, computer program and computer program product, which can improve the accuracy and flexibility of anomaly detection.
  • An embodiment of the present disclosure provides an anomaly detection method, including: using a first sample set to train an initial detection network to obtain a detection network; the first sample set is a positive sample set; During the abnormal detection process of the image to be detected, a second sample set is obtained based on the detected normal image set and abnormal image set, and the second sample set is an incremental sample set including positive samples and negative samples; wherein, the The negative samples are abnormal images with abnormalities in the image; using the second sample set, the detection network is updated and trained to obtain an updated detection network.
  • An embodiment of the present disclosure provides an abnormality detection device, including: a first training part configured to use a first sample set to train an initial detection network to obtain a detection network; the first sample set is a positive sample set; The acquisition part is configured to obtain a second sample set based on the detected normal image set and abnormal image set during the process of the detection network performing anomaly detection on a plurality of images to be detected, and the second sample set contains positive Incremental sample sets of samples and negative samples; wherein, the negative samples are abnormal images with abnormalities in the image; the second training part is configured to use the second sample set to perform update training on the detection network, Get the updated detection network.
  • An embodiment of the present disclosure provides an electronic device, including: a memory configured to store executable instructions; a processor configured to implement the above abnormality detection method when executing the executable instructions stored in the memory.
  • An embodiment of the present disclosure provides a computer-readable storage medium, which stores a computer program and is used to realize the above abnormality detection method when executed by a processor.
  • An embodiment of the present disclosure provides a computer program, including computer readable codes.
  • a processor in the computer device executes the above-mentioned anomaly detection method. step.
  • An embodiment of the present disclosure provides a computer program product, including computer program instructions, where the computer program instructions cause a computer to execute the steps in the above anomaly detection method.
  • the positive sample set is used to train the initial detection network to obtain the detection network.
  • a positive sample and a negative sample are obtained.
  • the incremental sample set of where the negative sample is an abnormal image with abnormalities in the image, and the incremental sample set including positive samples and negative samples is used to update and train the detection network to obtain the updated detection network.
  • the updated detection network is more suitable for the actual detection scene, and the detection accuracy of the updated detection network is higher, so that when using the updated detection network to detect abnormalities in the image to be detected, the detection results obtained are more accurate; at the same time, due to Incremental samples include positive samples and negative samples, so the updated detection network can be trained using incremental samples of positive samples and negative samples, so that the detection network can be compatible with different situations such as positive samples and negative samples. , improving the versatility and flexibility of anomaly detection.
  • FIG. 1 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure
  • FIG. 2 is a schematic diagram of an exemplary negative sample set including 3 negative samples provided by an embodiment of the present disclosure
  • FIG. 3 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure
  • FIG. 4 is a schematic flow diagram of obtaining a multi-scale feature sequence of a target image I provided by an embodiment of the present disclosure
  • FIG. 5 is a schematic diagram of a reconstructed network structure of an encoder-decoder structure provided by an embodiment of the present disclosure
  • FIG. 6 is a schematic flowchart of an exemplary process for obtaining image reconstruction features provided by an embodiment of the present disclosure
  • Fig. 7 is a schematic diagram of the effect of an abnormality detection image A' obtained by exemplary abnormality detection on a target image A provided by an embodiment of the present disclosure
  • FIG. 8 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure.
  • FIG. 9 is a schematic flow diagram of obtaining the training loss corresponding to the positive sample by reconstructing the sample feature difference sequence between the sample feature sequence and the multi-scale sample feature sequence provided by the embodiment of the present disclosure
  • FIG. 10 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure.
  • FIG. 11 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure.
  • FIG. 12 is an optional schematic flowchart of an abnormality detection method provided by an embodiment of the present disclosure.
  • FIG. 13 is a schematic flowchart of an exemplary updated reconstructed network provided by an embodiment of the present disclosure
  • FIG. 14 is a schematic structural diagram of an abnormality detection device provided by an embodiment of the present disclosure.
  • FIG. 15 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure.
  • first ⁇ second ⁇ third is only used to distinguish similar objects, and does not represent a specific ordering of objects. Understandably, “first ⁇ second ⁇ third” Where permitted, the specific order or sequencing may be interchanged such that the embodiments of the disclosure described herein can be practiced in sequences other than those illustrated or described herein.
  • the embodiment of the present disclosure provides an anomaly detection method, which can improve the accuracy and flexibility of anomaly detection.
  • the anomaly detection method provided by the embodiments of the present disclosure is applied to electronic equipment.
  • the electronic device provided by the embodiment of the present disclosure can be implemented as AR glasses, notebook computer, tablet computer, desktop computer, set-top box, mobile device (for example, mobile phone, portable music player, personal digital assistant, dedicated message device, portable game device)
  • mobile device for example, mobile phone, portable music player, personal digital assistant, dedicated message device, portable game device
  • Various types of user terminals can also be implemented as servers.
  • FIG. 1 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 1 .
  • the first sample set is a positive sample set.
  • the anomaly detection method in the embodiments of the present disclosure is applicable to the scene where anomalies are discovered through image detection. For example, by performing anomaly detection on product images on the production line, abnormal products, such as defective products, etc. are found; or, for batch images Anomaly detection is performed, and scenes such as abnormal images that do not conform to the preset overall specification are found, which can be selected according to the actual situation, which is not limited by the embodiments of the present disclosure.
  • the positive sample set contains at least one positive sample.
  • a positive sample is a sample in which every pixel in the image is normal; an image with an abnormal part in the image is called an abnormal image, and the opposite of the positive sample is a negative sample, which is actually an abnormal image.
  • Fig. 2 shows a negative sample set that contains 3 negative samples, wherein: negative sample 2-1 is a germinated seed image, negative sample 2-2 is a toothbrush image with abnormal bristles at the tip of the brush head, negative sample 2-3 are images of nuts with breakage. 2-10, 2-20 and 2-30 in FIG. 2 respectively show the regions containing abnormalities (ie abnormal pixels) in the negative samples 2-1, 2-2 and 2-3.
  • the electronic device may use a positive sample set including at least one positive sample to continuously train the initial detection network until a trained detection network is obtained.
  • the initial detection network may be composed of an initial feature extraction network and an initial reconstruction network, and the electronic device may perform continuous training on the initial feature extraction network and the initial reconstruction network simultaneously or separately to obtain a trained feature extraction network and an initial reconstruction network.
  • the trained reconstruction network is used, and the obtained trained feature extraction network and the trained reconstruction network are used as the obtained detection network.
  • the initial detection network can also be composed of a pre-trained feature extraction network and an initial reconstruction network, and the electronic device can only perform continuous training on the initial reconstruction network to obtain a trained reconstruction network, and The pre-trained feature extraction network and the trained reconstruction network are used as the obtained detection network.
  • the electronic device may use a deep convolutional neural network (Convolutional Neural Network, CNN) network including multiple feature extraction layers, such as ResNet-34, as the feature extraction network.
  • CNN Convolutional Neural Network
  • the reconstructed network may be implemented by a neural network with an encoder-decoder (Transformer) structure.
  • Transformer is a deep neural network with a global attention mechanism, which first appeared in the field of natural language processing. In recent years, Transformer has gradually been widely used in computer vision tasks due to its powerful representation capabilities. At present, the application of Transformer has not been involved in the anomaly detection scenario, but the embodiments of the present disclosure can extend the application of Transformer to the anomaly detection scenario, and use Transformer to capture the global attention of the input sequence to strengthen the semantic information of the reconstruction network. Deep understanding enables the reconstruction network to realize feature reconstruction on the premise of understanding the deep semantic features of the image.
  • a second sample set is obtained based on the detected normal image set and abnormal image set, and the second sample set is an incremental sample including positive samples and negative samples set; where the negative samples are abnormal images with abnormalities in the image.
  • the image to be detected may be any image, for example, may be the product image on the above-mentioned production line, which is not limited in the embodiment of the present disclosure.
  • the electronic device can acquire the image of the item to be detected as the image to be detected through the image acquisition device, for example, collect the image of the product produced on the production line to obtain the image to be detected, so as to pass the method of the embodiment of the present disclosure Anomaly detection is performed on the image to be detected, so as to determine whether the object to be detected is abnormal; or, the electronic device can also directly obtain the image to be detected from other devices.
  • the electronic device may acquire one image to be detected at a time, or may acquire multiple images to be detected at a time, which is not limited in this embodiment of the present disclosure.
  • the electronic device can use the detection model trained by the positive sample set to perform anomaly detection on multiple images to be detected to obtain a normal image set and an abnormal image set, and based on the obtained normal image set and abnormal image set , to obtain an incremental sample set consisting of a normal image set and an abnormal image set, wherein the normal image set contains at least one normal image, and the abnormal image set contains at least one abnormal image.
  • the electronic device may use all detected normal images as a normal image set, and use all detected abnormal images as an abnormal image set. In some embodiments, the electronic device may also select some normal images and abnormal images from all detected normal images and all abnormal images, so as to obtain a normal image set and an abnormal image set, which is not limited in this embodiment of the present disclosure .
  • the electronic device can use the incremental sample set including positive samples and negative samples, and continue to update and train the obtained detection network until the final loss reaches the preset loss threshold. detection network, and use the trained detection network as an updated detection network.
  • FIG. 3 is an optional schematic flowchart of the anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 3 .
  • the updated detection network includes: an updated feature extraction network and an updated reconstruction network.
  • the target image may be any image, for example, may be the image of the above-mentioned product on the production line, which is not limited in the embodiment of the present disclosure.
  • the electronic device when the updated detection network includes: the updated feature extraction network and the updated reconstruction network, can use the updated feature extraction network to perform feature extraction of different scales on the target image Extract to obtain multiple features of different scales of the target image at multiple scales; fuse multiple features of different scales to obtain multi-scale features; perform shape transformation on multi-scale features, and convert multi-dimensional feature information into In sequence form, a multi-scale feature sequence is obtained.
  • the electronic device can use the updated ResNet-34 to perform multi-scale feature extraction on the target image, and use the underlying feature extraction layer of ResNet-34 to obtain the representation of the target image.
  • Visual features such as color, boundary division, contrast, brightness, etc.
  • electronic devices use the apparent features and high-level semantic information of the target image as multiple Features of different scales are combined to obtain multi-scale features.
  • i represents the i-th network layer of the CNN network.
  • the electronic device can first adjust the features of different sizes to the same size, such as adjusting to the size H ⁇ W, and then perform feature fusion on the four adjusted features to obtain multi-scale features, as shown in formula (1):
  • R represents the resizing operation
  • the electronic device can perform shape transformation on the multi-scale features, so as to transform the multi-scale features into a sequence form, which is used as an input for the subsequent reconstruction network.
  • the electronic device can merge the dimensions of H ⁇ W corresponding to each channel to realize the shape transformation of the multi-scale feature , get H ⁇ W C-dimensional multi-scale feature vectors as multi-scale feature sequences.
  • the multi-scale feature sequence can be a feature word sequence containing any form of word vector, such as word2vec sequence, GloVe sequence, one-hot encoding sequence, etc., which can be selected according to the actual situation, and the embodiment of the present disclosure is not limited .
  • the electronic device can use the sequence-to-sequence (Sequence to Sequence) conversion model as the updated reconstruction network, use the multi-scale feature sequence in the form of sequence as the guidance information, and combine the guidance information with the preset inquiry
  • the word sequence is reconstructed to obtain the reconstructed feature sequence, and then anomaly detection is realized based on the reconstructed feature sequence.
  • the updated reconstructed network may be implemented by a neural network with an encoder-decoder (Transformer) structure. It should be noted that the updated reconstructed network has the same structure as the reconstructed network trained with the positive sample set, but the network parameters are different.
  • the multi-scale feature sequence f s is reconstructed directly through the reconstruction network of the Transformer structure, a single-input and single-output reconstructed feature sequence will be obtained in, R stands for Refactoring Operations.
  • this single-input-single-output method tends to cause the reconstruction network to only learn simple identity mappings, and it is difficult to understand the task goals that need to be learned from the input samples.
  • the embodiment of the present disclosure introduces a learnable query word sequence, uses the query word sequence and the multi-scale feature sequence as dual inputs of the reconstruction network to perform feature reconstruction, and obtains the reconstructed feature sequence.
  • the reconstructed feature sequence obtained by the double-input single-output method in the embodiment of the present disclosure can be expressed as Among them, q represents a preset query word sequence, and the preset query word sequence has the same dimension as the multi-scale feature sequence.
  • the query word sequence is a vector sequence that can be learned.
  • the electronic device can initialize the vectors in the query word sequence at the start-up stage of the model training of the reconstructed network, and iteratively update the initial query word sequence during the process of training the reconstructed network, and finally obtain the preset sequence of query words.
  • the electronic device encodes the multi-scale feature sequence based on the encoder part in the reconstruction network of the Transformer structure to obtain the coded sequence.
  • the electronic device can use the coding sequence as the guidance information for reconstructing the decoder part of the network, which is used to guide the decoding process of the encoder, so that based on the coding sequence, the decoder can decode and reconstruct the preset query word sequence , to get the reconstructed feature sequence.
  • the reconstruction network of the Transformer structure may be shown in FIG. 5 , including an encoder obtained by stacking N encoding modules and a decoder obtained by stacking N decoding modules.
  • each of the N coding modules includes a multi-head self-attention (Multi-head Attention) layer, a feed-forward network (Feed Forward Network, FFN) and a residual and normalization (ADD&Normalize) layer.
  • the feedforward network may be a fully connected neural network.
  • the electronic device inputs the multi-scale feature sequence obtained in Figure 4 into the encoder, and converts it into Q vector, K vector and V vector for attention calculation through three preset weight matrices Vector, and then through the multi-head self-attention layer, calculate the attention value according to the Q vector, K vector and V vector, and pass the residual and normalization layer according to the calculated attention value, as well as the original Q vector, K vector and The V vector performs residual calculation and normalization processing, and performs linear and nonlinear transformation on the processing results through the feedforward network, and then passes through the residual and normalization layer to obtain the coding sequence corresponding to the multi-scale feature sequence, and convert the coding sequence to Enter the decoder.
  • the attention value calculation and residual normalization processing are performed on the preset query word sequence, and the encoding output by the encoder
  • the sequence is combined with the processing results of the preset query word sequence, and the attention value is calculated again to obtain the combined attention value, and the residual and normalization is performed by combining the processing results of the preset query word sequence and the combined attention value. Normalization processing, and then through the feedforward network and the residual normalization network, the reconstructed feature sequence is obtained.
  • the electronic device can also use the property of Transformer permutation invariance to add position information to each layer of the multi-head self-attention layer, for example, it can be sinusoidal position information, so as to pass
  • the location information further improves the reconstruction network's ability to understand semantics.
  • the selection can be made according to the actual situation, which is not limited in the embodiment of the present disclosure.
  • the electronic device uses the multi-scale feature sequence extracted from the image as guidance information, and performs double-input feature reconstruction on the learnable query word sequence, which can make the reconstruction network combine the semantics in the query word sequence, Decoding reconstruction is performed on the basis of deep semantic understanding, so as to improve the accuracy of reconstructed features, and then improve the accuracy of anomaly detection.
  • the electronic device can perform feature extraction and feature fusion of different scales on the target image through the updated feature extraction network to obtain multi-scale features;
  • the shape of the feature is transformed to obtain a multi-scale feature sequence, and then the multi-scale feature sequence and the initial query word sequence are reconstructed through the updated reconstruction network to obtain the reconstructed feature sequence.
  • the electronic device can perform shape transformation on the reconstructed feature sequence in the form of a sequence to obtain the reconstructed feature.
  • the multi-scale feature sequence represents the original features in the target image
  • the reconstructed feature sequence represents the features reconstructed based on the original features.
  • the electronic device can compare the reconstruction feature sequence with the multi-scale feature sequence Difference, which determines the sequence of feature differences for the target image.
  • each feature difference in the feature difference sequence may include corresponding pixel position information and a difference value in the target image.
  • the electronic device can determine the difference value at each pixel position in the target image through the feature difference, and use the feature difference to represent the reconstruction effect of the reconstruction network on each pixel of the target image.
  • the electronic device may calculate a feature difference between the reconstructed features and the multi-scale features.
  • the electronic device can calculate the feature difference between the reconstructed feature and the multi-scale feature through formula (2), as follows:
  • f(u,i) is a multi-scale feature, is the reconstructed feature;
  • u is the index coordinate of the spatial position, for example, it can be the coordinates of each position in the H ⁇ W feature map of multi-scale features or reconstructed features.
  • i is the index of the feature channel.
  • the electronic device can use the formula (2) to subtract the multi-scale features and the reconstructed features to obtain the feature difference d(u,i) at each position.
  • the electronic device may also perform difference calculation according to the multi-scale feature sequence and the reconstructed feature sequence to obtain a feature difference sequence.
  • the electronic The device can determine the abnormal score at each pixel position based on the reconstruction effect at each pixel position represented by the feature difference, and the abnormal score is used to indicate whether the corresponding pixel is an abnormal pixel. Based on the anomaly score, the electronic device distinguishes and draws normal pixels and abnormal pixel points respectively, and obtains an abnormality detection image corresponding to the target image. In this way, abnormal regions can be automatically marked in anomaly detection images.
  • the electronic device can compare the abnormality score of each pixel position with the preset scoring interval, and determine The target pixel value corresponding to each pixel location.
  • the electronic device draws an abnormality detection image according to the target pixel value corresponding to each pixel position.
  • the electronic device when the abnormality score at each pixel position is less than or equal to the preset scoring threshold, the electronic device draws the pixel value corresponding to the pixel position as the first value; the abnormality score at each pixel position is greater than In the case of a preset scoring threshold, the electronic device draws the pixel value corresponding to the pixel position as a second value; until the pixel position of the target image is drawn, an abnormality detection image is obtained; for example, for a target image A, the electronic device An abnormality score of the target image A can be obtained, and an abnormality detection image A' is drawn according to the abnormality score, so as to use the abnormality detection image A' to represent whether the target image A is a normal image or an abnormal image.
  • FIG. 7 is a schematic diagram of an abnormality detection image A' obtained after abnormality detection of a target image A provided by an embodiment of the present disclosure; as shown in FIG. 7 , when the target image A is a toothbrush image Next, the drawn anomaly detection image is toothbrush image A', and, as shown in image A, in the case of abnormal bristles at the tip of the brush head, in the drawn toothbrush image A', the area where the bristles at the tip of the brush head is 7- The pixel color (pixel value) of 10 is different from the pixel color of the region 7-20 where other bristles are located, which indicates that the target image A is an abnormal image.
  • FIG. 8 is an optional schematic flow chart of the anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 8 .
  • the electronic device can obtain the multi-scale feature sequence of the positive sample through the initial detection network, and reconstruct it according to the multi-scale feature sequence and the preset query word sequence to obtain the The reconstructed feature sequence of the positive sample, and by comparing the difference between the reconstructed feature sequence and the multi-scale feature sequence, determine the feature difference sequence of the positive sample, which is hereinafter referred to as the first feature difference sequence.
  • the initial detection network and the updated detection network have the same network structure, but different network parameters. Therefore, the process of the electronic device obtaining the first feature difference sequence corresponding to the positive sample is the same as the above S104-S106.
  • S1012 Determine the training loss corresponding to the positive sample according to the first feature difference sequence and the normal loss function; wherein, the normal loss function indicates that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample.
  • the electronic device when it obtains the first feature difference sequence, it may use a normal loss function to calculate the training loss corresponding to the positive sample.
  • the normal loss function may include a regression loss function; for example, it may be smooth (Smooth) L1 loss, MSE loss, etc., which can be selected according to actual conditions, and are not limited in this embodiment of the present disclosure.
  • the electronic device can use the smooth L1 loss as a normal loss function to calculate the training loss corresponding to the positive sample, as shown in formula (3), as follows:
  • FIG. 9 shows that in the case of a positive sample, the training loss corresponding to the positive sample is obtained through the first feature difference sequence of the positive sample.
  • the electronic device can calculate the gap between the original feature and the reconstructed feature through the normal loss function to evaluate the reconstruction ability of the initial detection network for the positive sample, so that the initial detection network can support the use of positive samples training.
  • the electronic device when it obtains the training loss corresponding to the positive sample, it can adjust the network parameters of the initial detection network based on the training loss corresponding to the positive sample, and complete the training process of using the positive sample in the current round.
  • the electronic device can continue to use the positive samples in the positive sample set to iteratively train the initial detection network until the final loss is less than the preset loss threshold to obtain the detection network.
  • the preset loss threshold may be set according to actual needs, which is not limited in the embodiments of the present disclosure.
  • the initial detection network can be composed of a pre-trained feature extraction network and an initial reconstruction network; based on this, the electronic device can perform an initial reconstruction on the initial reconstruction network according to the obtained first feature difference sequence and normal loss function Training, and when the final loss is less than the preset loss threshold, the reconstruction network is obtained, so as to obtain the detection network composed of the pre-trained feature extraction network and the obtained reconstruction network.
  • the initial detection network can be composed of an initial feature extraction network and an initial reconstruction network
  • the electronic device can calculate the initial The training loss corresponding to the feature extraction network.
  • the first feature difference sequence is obtained according to the obtained multi-scale features and reconstruction features
  • the initial reconstruction is determined according to the first feature difference sequence and the normal loss function corresponding to the initial reconstruction network.
  • the training loss corresponding to the network, and the training loss corresponding to the initial feature extraction network is used to adjust the initial feature extraction network, and the training loss corresponding to the initial reconstruction network is used to train and adjust the initial reconstruction network until the initial feature extraction is obtained
  • the feature extraction network and the reconstruction network are obtained, so that the feature extraction network and reconstruction network are obtained.
  • a detection network composed of a structural network.
  • the electronic device may also train the initial feature extraction network and the initial reconstruction network separately, and the training method is the same as the above-mentioned method.
  • FIG. 10 is an optional flowchart of the anomaly detection method provided by the embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 10 .
  • S201 Use a detection network to perform anomaly detection on each image to be detected, and obtain an anomaly score at each pixel position of each image to be detected.
  • the electronic device can use the detection network to perform feature processing on the image to be detected at different scales to obtain a multi-scale feature sequence, and to obtain multi-scale feature sequences and preset questions.
  • the query word sequence is reconstructed to obtain the reconstructed feature sequence, and according to the reconstructed feature sequence and the obtained multi-scale feature sequence, the feature difference at each pixel position of the image to be detected is determined, and according to the feature difference, determine The anomaly score of each pixel position of the image to be detected is obtained.
  • the electronic device can draw an abnormality detection image corresponding to the image to be detected according to the abnormality score at each pixel position of the image to be detected and the preset scoring threshold , and determine whether the image to be detected is an abnormal image or a normal image according to the corresponding abnormal detection image; in this way, the electronic device can divide multiple detected images to be detected into a normal image set and an abnormal image set, thus obtaining A normal image set contains at least one normal image, and an abnormal image set contains at least one abnormal image.
  • the electronic device may take the image to be detected as an abnormal image when the abnormality detection image corresponding to each image to be detected is represented as an abnormal image, and traverse After a plurality of images to be detected, an abnormal image set containing at least one abnormal image is obtained; The detected image is used as a normal image, and after traversing through multiple images to be detected, a normal image set containing at least one normal image is obtained; in this way, an abnormal image set and a normal image set can be obtained.
  • the electronic device may stop detecting the image to be detected when the number of detected images to be detected reaches a preset number, and according to each detected image to be detected Anomaly detection images corresponding to the images to be detected, divide multiple images to be detected into normal image sets and abnormal image sets; in this way, a sufficient number of normal images and abnormal images can be obtained, which is conducive to subsequent updates with higher detection accuracy After the detection network.
  • the electronic device may also, when the number of abnormal images in the obtained abnormal image set reaches a preset number, or when the number of normal images in the obtained normal image set reaches a preset number In the case, stop the detection of the image to be detected, and divide the multiple images to be detected into a normal image set and an abnormal image set according to the abnormal detection image corresponding to each image to be detected in the multiple images to be detected that have been detected; In this way, a sufficient number of abnormal images and normal images can be obtained, which is conducive to obtaining an updated detection network with higher detection accuracy.
  • the electronic device may also, in the obtained abnormal image set, the abnormal images corresponding to the first maximum abnormal score belonging to the first preset value range of the preset abnormal threshold (hereinafter referred to as abnormal suspicious images ) reaches the preset number (the first maximum abnormal score corresponding to each abnormal image is: the maximum abnormal score among the abnormal scores of all pixels in the abnormal image), or, in the obtained normal image set, the corresponding
  • the number of normal images hereinafter referred to as normal suspicious images
  • the second maximum abnormality score belongs to the second preset value range of the preset abnormality threshold reaches the preset number (the second maximum abnormality corresponding to each normal image
  • the score is: the maximum abnormal score in the abnormal scores of all pixels in the normal image), stop the detection of the image to be detected, and according to the abnormal detection image corresponding to each image to be detected in the multiple images to be detected that have been detected, Divide multiple images to be detected into a normal image set and an abnormal image set; in this way, a sufficient number of normal suspicious images or abnormal
  • the first preset numerical range of the preset abnormal threshold and the second preset numerical range of the preset abnormal threshold are ranges composed of values close to the preset abnormal threshold, which can be set according to actual needs.
  • the first maximum abnormality score corresponding to the abnormal image is usually lower than the preset abnormality threshold
  • the second maximum abnormality score corresponding to the normal image is usually higher than the preset abnormality threshold, for example, when the preset abnormality threshold is In the case of 5, the first preset value range may be [4.5,5), and the second preset value range may be (5,5.5].
  • the electronic device may also obtain a preset number of abnormal images in the set of abnormal images; and, in the obtained set of normal images, the number of normal suspicious images reaches a preset number In the case of a large number, stop the detection of the image to be detected, and divide the multiple images to be detected into a normal image set and an abnormal image according to the abnormal detection image corresponding to each image to be detected in the multiple images to be detected that have been detected In this way, a sufficient number of normal suspicious images and abnormal suspicious images can be obtained, which is conducive to obtaining an updated detection network with higher detection accuracy.
  • obtaining the second sample set based on the detected normal image set and abnormal image set in S102 above may be implemented through S1021-S1022.
  • the electronic device can determine the image to be verified according to all normal images and abnormal images contained in the obtained normal image set and abnormal image set, and obtain the first positive sample and negative sample according to the verification result. Two sample sets.
  • the electronic device may automatically verify the image to be verified, or may verify the image to be verified according to the received verification operation of the user, which is not limited in the embodiment of the present disclosure.
  • the electronic device may use all normal images and abnormal images included in the normal image set and the abnormal image set as images to be verified for verification.
  • the electronic device may also select some normal images and some abnormal images from the normal image set and the abnormal image set as images to be verified for verification.
  • the above S1022 can be implemented by using S301-S304:
  • the electronic device When the electronic device obtains the abnormal image set, for each abnormal image in the abnormal image set, it can determine a maximum abnormal score from the abnormal scores of all pixels in the abnormal image as the first maximum abnormal score.
  • the electronic device When the electronic device obtains the normal image set, for each normal image in the normal image set, it can determine a maximum abnormality score as the second maximum abnormality score from the abnormality scores of all pixels in the normal image.
  • the electronic device when the electronic device selects the first maximum abnormal score, it can determine whether the selected first maximum abnormal score is within the first preset value range of the preset abnormal threshold, and within the selected If the first maximum abnormality score is within the first preset value range of the preset abnormality threshold, the abnormal image is used as the image to be verified.
  • the first preset numerical range of the preset abnormal threshold is a range consisting of values close to the preset abnormal threshold, which can be set according to actual needs, which is not limited in the embodiments of the present disclosure.
  • the first maximum abnormality score corresponding to the abnormal image is usually lower than the preset abnormality threshold.
  • the preset abnormality threshold is 5
  • the first preset value range may be [4.5,5 ); then in the case where the first maximum abnormal score determined from the abnormal scores of all pixels of an abnormal image B is 4.5, it means that the first maximum abnormal score corresponding to the abnormal image B belongs to the first preset value range [4.5,5), then the abnormal image B can be used as the image to be verified.
  • the electronic device When the electronic device obtains a normal image set, for each normal image in the normal image set, it can determine a maximum abnormal score from the abnormal scores of all pixels in the normal image as the second maximum abnormal score , and determine whether the selected second maximum abnormal score is within the second preset numerical range of the preset abnormal threshold, and if the selected second maximum abnormal score is within the second preset numerical range of the preset abnormal threshold In this case, the normal image is used as the image to be verified.
  • the second preset numerical range of the preset abnormal threshold is also a range consisting of values close to the preset abnormal threshold, which can be set according to actual needs.
  • the second maximum abnormality score corresponding to a normal image is usually higher than the preset abnormality threshold. For example, when the preset abnormality threshold is 5, the second preset value range may be (5,5.5 ]; then in the case that the second maximum abnormality score determined from the abnormality scores of all pixels of a normal image C is 5.1, it means that the second maximum abnormality score corresponding to the normal image C belongs to the second preset value range (5,5.5], the normal image C can be used as the image to be verified.
  • FIG. 11 is an optional schematic flow chart of the anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 11 .
  • S401 Perform verification on at least one abnormal image and at least one normal image respectively to obtain respective verification results; the images to be verified include: at least one abnormal image and at least one normal image.
  • the electronic device can verify each image in the abnormal image set and the normal image set to determine whether the abnormality detection result of the image is correct, and obtain the verification result of the image, and the verification result represents The detection result of this image is correct or incorrect.
  • the electronic device sets labeling information for the abnormal image to indicate that the abnormal image is a negative sample, and obtains a negative sample; for a normal image with a correct verification result, the electronic device sets the normal image Set the label information that characterizes the normal image as a positive sample, and obtain a positive sample for subsequent update training of the detection network.
  • the electronic device will judge whether the abnormal image is an abnormal image or a normal image, and mark the abnormal image with correct annotation information according to the judgment result; and, for the verification result
  • the electronic device will judge whether the normal images are abnormal images or normal images, and mark the normal images with correct labeling information according to the judgment results; for all abnormal images with wrong verification results, and all verification results
  • the electronic device can obtain positive samples and negative samples according to the correctly labeled label information.
  • the electronic device may use all the obtained negative samples and positive samples as the second sample set for updating and training the detection network.
  • FIG. 12 is an optional schematic flow chart of the anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 12 .
  • the electronic device when the electronic device uses the positive samples in the second sample set to train the detection network, it can perform feature processing and reconstruction on the currently acquired positive samples through the method in FIG. 6 above, and Use the above formula (2) to calculate the degree of feature difference and other processing to obtain the first feature difference or the first feature difference sequence corresponding to the positive sample, and then use the normal loss function to calculate the first training loss corresponding to the positive sample, which is used for Detect the network to adjust the network parameters.
  • the process of S1031 is the same as the content of the above S1011-S1012.
  • the electronic device when it uses the negative samples in the second sample set to train the detection network, it can obtain negative samples from the second sample set, and the preset negative samples corresponding to the negative samples actual value.
  • the real value of the preset negative sample may be annotation information in the form of a pixel-level label or an image-level label, wherein the pixel-level label may be annotation information for each pixel in the negative sample, and is used to label each pixel It is a normal pixel or an abnormal pixel; the image-level label can be annotation information for the entire image, and is used to mark whether there is an abnormality in the entire image.
  • the image-level label corresponding to the image containing some abnormal pixels may be a label representing the abnormality of the entire image.
  • the electronic device can perform feature processing and reconstruction on the negative samples through the above-mentioned method in FIG. Two feature difference sequences; furthermore, the electronic device calculates the difference between the second feature difference or the second feature difference sequence and the real value of the preset negative sample through the abnormal loss function, and obtains the second training loss corresponding to the negative sample, so that It is used to adjust the network parameters of the detection network.
  • the electronic device adjusts the network parameters of the detection network based on the first training loss corresponding to the positive samples or the second training loss corresponding to the negative samples, and completes the training process of using positive samples or negative samples in the current round. Afterwards, the electronic device can continue to use the positive samples and negative samples in the incremental samples to iteratively train the detection network until the preset training conditions are met, such as when the final loss is less than the preset loss threshold, the updated detection network.
  • the detection network may be composed of a pre-trained feature extraction network and a reconstruction network, and the electronic device may only train the reconstruction network to obtain the pre-trained An updated detection network composed of a well-trained feature extraction network and an updated reconstruction network; and, the detection network can also be composed of a feature extraction network and a reconstruction network, and the electronic device can simultaneously use the feature extraction network and the reconstruction network Training is performed, or the feature extraction network and the reconstruction network are trained separately to obtain an updated detection network composed of an updated feature extraction network and an updated reconstruction network.
  • the process of the electronic device using the second sample set to train the detection network is the same as the process of the above S1013, the only difference is that the samples used are different, and the training losses corresponding to the obtained samples are different.
  • the electronic device may use different abnormal loss functions to calculate the second training loss corresponding to the negative samples.
  • the overall characteristics that the abnormal loss function needs to meet are: the reconstructed feature sequence corresponding to the abnormal part in the negative sample is pushed away from the abnormal part, and the negative sample The reconstructed feature sequence corresponding to the normal part of is closer to the normal part.
  • the preset real value of the negative sample includes: a pixel-level real value, that is, a pixel-level label;
  • the abnormal loss function includes: a pixel-level loss function.
  • the electronic device trains and adjusts the detection network based on the second feature difference sequence of the negative sample, the preset real value of the negative sample, and the abnormal loss function until an updated detection network whose final loss is less than the preset loss threshold can be obtained.
  • the electronic device can use the second feature difference sequence to represent each The feature difference vector at each pixel position is converted into a scalar in the channel dimension, so that each pixel position corresponds to only one scalar feature difference measure; 2) Based on the feature difference measure, pixel-level real value and pixel-level loss function, the detection network Perform training adjustments until an updated detection network with a final loss smaller than a preset loss threshold is obtained.
  • the pixel-level loss function is a loss function with the above-mentioned "pull-in-pull-away" characteristic, and its design goal can be: using the pixel-level loss function, the normal pixel in the negative sample corresponds to the feature The difference measure is reduced to shorten the distance between the reconstructed features of the normal pixels and the original features, such as multi-scale features; at the same time, the feature difference measure at the corresponding position of the abnormal pixels in the negative sample is increased, that is, pushing The distance between the reconstructed feature of the far outlier pixel and the original feature.
  • the pixel-level loss function includes: a normal pixel loss part and an abnormal pixel loss part.
  • the electronic device can perform a weighted average on the feature difference measure of the normal pixel based on the normal pixel loss part to obtain the normal pixel loss;
  • the electronic device can perform a weighted average on the feature difference measure of the abnormal pixel based on the abnormal pixel loss part to obtain the abnormal pixel loss.
  • the normal pixel loss is positively correlated with the feature difference measure of the normal pixel point
  • the abnormal pixel point loss is negatively correlated with the feature difference measure of the abnormal pixel point, so as to achieve the reconstruction feature of the normal pixel point and the original feature. distance, and the effect of pushing away the distance between the reconstructed feature of the abnormal pixel and the original feature.
  • the electronic device can use the pixel-level loss function to evaluate the reconstruction ability of the detection network for negative samples of pixel-level labels, so that the reconstruction features of the detection network for normal pixels are close to the original features, and for abnormal The reconstructed features of pixels are far away from the original features, so that they are compatible with the training of negative samples of pixel-level labels, improve the flexibility and accuracy of the detection network using different types of samples for training, and then improve the flexibility and accuracy of anomaly detection based on the detection network. accuracy.
  • the electronic device in the process of scalarizing the feature difference vectors at each pixel position, the electronic device equally averages the feature difference vectors corresponding to different feature channels.
  • different feature channels may contribute differently to abnormalities. Therefore, electronic devices can also perform weight analysis on the feature difference vector corresponding to each feature channel through the classification network to combine different weights for pixel-level loss. The calculation of the function further improves the accuracy.
  • the electronic device trains and adjusts the detection network based on the second feature difference sequence, the preset true value of the negative sample, and the abnormal loss function until an updated detection network with a final loss less than the preset loss threshold is obtained
  • the process can include:
  • the classification network uses the classification network to classify the pixel positions of the second feature difference sequence, and obtain the sample classification probability at each pixel position; 4) Based on the sample classification probability at each pixel position, the pixel-level true value and the classification loss function to obtain the current classification loss; 5) based on the feature difference measure, the pixel-level real value and the pixel-level loss function, the first current loss is obtained; 6) based on the current classification loss and the first current loss, the detection network and the classification network are The training is adjusted until the updated classification network and the updated detection network with the final loss less than the preset loss threshold are obtained.
  • each feature difference vector in the second feature difference can be represented by d(u) of C dimension
  • the electronic device Each d(u) can be classified by formula (4), and the probability that each d(u) belongs to abnormality or defect can be obtained as the sample classification probability at the corresponding pixel position u, so as to obtain the
  • the sample classification probability is as follows:
  • p(u) is the sample classification probability at pixel position u.
  • the electronic device can use the classification network to perform classification prediction in combination with the feature differences corresponding to each feature channel in the C-dimensional channel, and obtain the sample classification probability at each pixel position.
  • the classification network can be FFN (Feed Forward Network), or other network models with classification functions, which can be selected according to actual conditions, and are not limited in this embodiment of the present disclosure.
  • FFN Field Forward Network
  • the difference vectors of each dimension in each feature difference vector can be combined to obtain the sample classification probability at each pixel position, and the second is based on the sample classification probability weight. Calculation of the current loss, so as to further improve the accuracy of training the detection network using the first current loss, and further improve the accuracy of anomaly detection using the updated detection network.
  • the preset real value of the negative sample includes: an image-level real value, that is, an image-level pixel label; and the abnormal loss function includes: an image-level loss function.
  • the electronic device trains and adjusts the detection network based on the second feature difference sequence, the preset true value of the negative sample, and the abnormal loss function until an updated detection network whose final loss is less than the preset loss threshold can be obtained.
  • the process may include:
  • the image-level loss function includes: a normal image loss part and an abnormal image loss part.
  • the electronic device measures the average difference of features based on the normal image loss part, and determines it as a normal image loss; the image-level true value corresponding to a negative sample
  • the electronic device obtains the abnormal image loss based on the abnormal image loss part and the feature average difference measure.
  • the feature average difference measure of normal images is positively correlated with normal image loss
  • the feature average difference measure of abnormal images is negatively correlated with abnormal image loss.
  • the electronic device determines the second current loss based on the normal image loss or the abnormal image loss; based on the second current loss and the preset loss threshold, the detection network is trained and adjusted until an updated detection network whose final loss is less than the preset loss threshold is obtained .
  • the image-level loss function is a loss function with the above-mentioned "pull-in-pull-away" characteristic, and its design goal can be: use the image-level loss function to reduce the average difference measure of the features corresponding to the normal image, so as to The distance between the reconstructed features of the normal image and the original features is shortened; at the same time, the average difference measure of the features corresponding to the abnormal image is increased, that is, the distance between the reconstructed features of the abnormal image and the original features is pushed farther.
  • the electronic device can evaluate the reconstruction ability of the detection network for negative samples of image-level labels through the image-level loss function, so that the reconstruction features of the detection network for normal images are close to the original features, and the negative samples The reconstructed features are far away from the original features, so that they are compatible with the training of negative samples of image-level labels, improve the flexibility and accuracy of the updated detection network using different types of samples for training, and then improve the anomaly detection based on the updated detection network. flexibility and accuracy.
  • the method for the electronic device to calculate the abnormality score at each pixel position may be: the feature difference at each pixel position Perform channel averaging to obtain the intermediate anomaly score at each pixel location; use the intermediate anomaly score as the anomaly score.
  • the electronic device can perform channel averaging on the feature difference at each pixel position in the image to be detected or the target image to obtain the intermediate abnormality score at each pixel position, and use the intermediate abnormality score as the abnormality score, as shown in the formula As shown in (5), as follows:
  • d'(u,i) is the feature difference at each pixel position
  • C is the number of feature channels corresponding to each feature difference in the feature difference sequence
  • s(u) is the The intermediate anomaly score obtained by channel-averaging the feature differences on , that is, the anomaly score at each pixel position in the image to be detected or the target image output by the detection network that does not include the classification network.
  • the method for the electronic device to calculate the abnormality score at each pixel position may be: perform channel averaging on the feature difference at each pixel position, and obtain each The intermediate anomaly score at the pixel position; the classification network is used to classify the feature difference at each pixel position at the pixel position to obtain the classification probability; the classification probability is multiplied by the intermediate anomaly score to obtain the Exception score.
  • the electronic device uses the classification probability as a weight to weight the intermediate anomaly score to obtain the anomaly score at each pixel position.
  • the classification probability as a weight to weight the intermediate anomaly score to obtain the anomaly score at each pixel position.
  • the detection network makes the detection network compatible with the two learning methods of positive sample learning and incremental abnormal sample learning, thereby improving the compatibility and flexibility of the detection network.
  • FIG. 13 is a schematic flowchart of an updated detection network provided by an embodiment of the present disclosure. The technical solution of the embodiment of the present disclosure will be described below through a detailed embodiment with reference to FIG. 13 .
  • the initial detection network is continuously trained through the preset positive sample set until a trained detection network is obtained.
  • the electronic device takes multiple images to be detected generated on the production line as production line data sets, input them into the detection network trained in the cold start phase, and collect the output corresponding to each image to be detected output by the detection network.
  • Anomaly detection image using the abnormal detection image as the collected detection result, and determining whether the corresponding image to be detected is a normal image or an abnormal image according to the collected detection result, so as to divide the detected multiple images to be detected into a normal image set and the abnormal image set, and the normal image set is used as a normal sample, and the abnormal image set is used as an abnormal sample; after that, both the normal sample and the abnormal sample are verified, and the verified normal sample and abnormal sample with label information are obtained,
  • the normal samples (positive samples) with labeled information and the abnormal samples (negative samples) with labeled information are used together as the incremental data set (incremental sample set), and the incremental data set is used to train the cold start stage.
  • the detection network continues to train continuously until the trained and updated detection network is obtained, and the detection network obtained in the cold start stage is updated with the updated detection network, so that the updated detection network is used to continue to process the images generated on the production line. detection.
  • the anomaly detection method provided by the embodiments of the present disclosure can be applied to an intelligent artificial intelligence (AI) training platform, anomaly detection, online automatic training and improvement of anomaly detection, and the like.
  • AI intelligent artificial intelligence
  • FIG. 14 is a schematic structural diagram of the abnormality detection device provided by the embodiment of the present disclosure; as shown in FIG. 14 , the abnormality detection device 500 includes: a first training part 501 configured to adopt the This episode trains the initial detection network to obtain a detection network; the first sample set is a positive sample set; the acquisition part 502 is configured to perform abnormal detection on multiple images to be detected by the detection network based on The detected normal image set and abnormal image set are used to obtain a second sample set, which is an incremental sample set including positive samples and negative samples; wherein, the negative sample is an abnormal image in which there is anomaly in the image ; The second training part 503 is configured to use the second sample set to perform update training on the detection network to obtain an updated detection network. .
  • the first training part 501 is further configured to use the initial detection network to detect the positive samples in the first sample set, and obtain the first A feature difference sequence; according to the first feature difference sequence and a normal loss function, determine the training loss corresponding to the positive sample; based on the training loss, train and adjust the initial detection network until the final loss obtained is less than When the loss threshold is preset, the detection network is obtained; wherein, the normal loss function represents that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample.
  • the acquisition part 502 is further configured to determine an image to be verified from the detected normal image set and the abnormal image set; and verify the image to be verified to obtain The second sample set.
  • the image to be verified includes: at least one abnormal image and at least one normal image; At least one normal image is verified separately to obtain respective verification results; the abnormal image with the correct verification result is used as the negative sample, and the normal image with the correct verification result is used as the positive sample; Correctly annotate the abnormal image with the wrong character of the verification result and the normal image with the wrong character of the verification result to obtain the positive sample and the negative sample; determine the set of the negative sample and the positive sample as the set Describe the second sample set.
  • the abnormality detection device 500 further includes: a detection part; the detection part is further configured to use the first sample set to train the initial detection network, and after obtaining the detection network, use the The detection network performs anomaly detection on each image to be detected, and obtains an abnormality score on each pixel position of each image to be detected; based on the anomaly score, draws an abnormality detection image corresponding to each image to be detected ;
  • the acquiring part 502 is further configured to obtain the normal image set and the abnormal image set among the plurality of images to be detected according to the abnormality detection image.
  • the acquisition part 502 is further configured to, when the abnormality detection image representation corresponding to each image to be detected, and each image to be detected is an abnormal image, the Each image to be detected is used as an abnormal image, and after traversing the multiple images to be detected, the abnormal image set including at least one abnormal image is obtained; the abnormality detection image representation corresponding to each image to be detected, When each of the images to be detected is a normal image, each of the images to be detected is regarded as a normal image, and after traversing the plurality of images to be detected, the normal image set containing at least one normal image is obtained .
  • the acquiring part 502 is further configured to determine, from each abnormal image in the abnormal image set, the first maximum abnormal score among the abnormal scores at each pixel position; From each normal image in the normal image set, determine a second maximum abnormality score that is the largest among the abnormality scores at each pixel position; the first maximum abnormality score belongs to a first preset value of a preset abnormality threshold at the first maximum abnormality score range, determine that the abnormal image corresponding to the first maximum abnormality score belongs to the image to be verified; in the case that the second maximum abnormality score belongs to the second preset value range of the preset abnormality threshold, It is determined that the normal image corresponding to the second maximum abnormality score belongs to the image to be verified.
  • the acquiring part 502 is further configured to determine all images in the normal image set and the abnormal image set as the images to be verified.
  • the second training part 502 is further configured to use the detection network to obtain The first feature difference sequence corresponding to the positive sample, and according to the first feature difference sequence and the normal loss function, determine the first training loss corresponding to the positive sample; when using the negative sample in the second sample set , when the detection network is trained, the detection network is used to obtain the second feature difference sequence corresponding to the negative sample, and according to the second feature difference sequence, the preset true value and abnormality of the negative sample A loss function, determining the second training loss corresponding to the negative sample; based on the first training loss and the second training loss, respectively training and adjusting the detection network until the obtained final loss is less than the preset loss threshold, the updated detection network is obtained; wherein, the normal loss function represents that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample; the abnormal loss function represents the abnormality in the negative sample The reconstructed feature sequence corresponding to the part is pushed away from the abnormal part, and the reconstructed feature sequence corresponding to the normal part in
  • the updated detection network includes: an updated feature extraction network and an updated reconstruction network; the detection part is further configured to use the second sample set to The detection network is updated and trained, and after the updated detection network is obtained, the updated feature extraction network is used to perform feature processing of different scales on the target image to obtain a multi-scale feature sequence; using the updated reconstruction network, reconstructing the multi-scale feature sequence and the preset query word sequence to obtain a reconstructed feature sequence; according to the reconstructed feature sequence and the multi-scale feature sequence, determine each of the target images A feature difference at a pixel position; based on the feature difference, determining an abnormality score at each pixel position, and drawing an abnormality detection image corresponding to the target image based on the abnormality score.
  • a "part" may be a part of a circuit, a part of a processor, a part of a program or software, etc., of course it may also be a unit, a module or a non-modular one.
  • FIG. 15 is a schematic structural diagram of the electronic device provided by the embodiment of the present disclosure.
  • the electronic device 2 includes: a memory 21 and a processor 22, wherein the memory 21 and the processing The device 22 is connected through a communication bus 23; the memory 21 is configured to store executable instructions (executable computer programs); the processor 22 is configured to execute the executable instructions stored in the memory 21 to realize the implementation provided by the embodiments of the present disclosure.
  • the method for example, the anomaly detection method provided by the embodiment of the present disclosure.
  • the embodiment of the present disclosure provides a computer-readable storage medium storing a computer program for implementing the method provided by the embodiment of the present disclosure, for example, the anomaly detection method provided by the embodiment of the present disclosure when executed by the processor 22 .
  • An embodiment of the present disclosure provides a computer program, including computer readable codes.
  • a processor in the computer device executes the above-mentioned anomaly detection method. step.
  • An embodiment of the present disclosure provides a computer program product, including computer program instructions, where the computer program instructions cause a computer to execute the steps in the above anomaly detection method.
  • the storage medium may be a tangible device capable of holding and storing instructions used by the instruction execution device, and may be a volatile storage medium or a non-volatile storage medium.
  • a computer readable storage medium may be, for example, but is not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing.
  • Computer-readable storage media include: portable computer diskettes, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), or flash memory), static random access memory (SRAM), compact disc read only memory (CD-ROM), digital versatile disc (DVD), memory stick, floppy disk, mechanically encoded device, such as a printer with instructions stored thereon A hole card or a raised structure in a groove, and any suitable combination of the above.
  • RAM random access memory
  • ROM read-only memory
  • EPROM erasable programmable read-only memory
  • flash memory static random access memory
  • SRAM static random access memory
  • CD-ROM compact disc read only memory
  • DVD digital versatile disc
  • memory stick floppy disk
  • mechanically encoded device such as a printer with instructions stored thereon
  • a hole card or a raised structure in a groove and any suitable combination of the above.
  • computer-readable storage media are not to be construed as transient signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., pulses of light through fiber optic cables), or transmitted electrical signals.
  • executable instructions may take the form of programs, software, software modules, scripts, or code written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages) , and it may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other part suitable for use in a computing environment.
  • executable instructions may, but do not necessarily correspond to files in a file system, may be stored as part of a file that holds other programs or data, for example, in a Hyper Text Markup Language (HTML) document in one or more scripts, in a single file dedicated to the program in question, or in multiple cooperating files (for example, files that store one or more modules, subroutines, or sections of code).
  • HTML Hyper Text Markup Language
  • executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or alternatively, on multiple computing devices distributed across multiple sites and interconnected by a communication network. to execute.
  • the initial detection network is trained with the positive sample set, and the detection network is obtained.
  • the detection network is obtained.
  • An incremental sample set of samples and negative samples, where the negative sample is an abnormal image with abnormalities in the image, and the incremental sample set including positive samples and negative samples is used to update and train the detection network to obtain an updated detection network , therefore, the obtained updated detection network is more suitable for the detection scene of the actual production line. more accurate; at the same time, since the incremental samples include positive samples and negative samples, the updated detection network obtained can be trained using incremental samples of positive samples and negative samples, so that the detection network can be compatible with positive samples and negative samples. Different situations such as negative samples improve the versatility and flexibility of anomaly detection.
  • the embodiment of the present disclosure discloses an abnormality detection method, device, electronic equipment, computer-readable storage medium, computer program and computer program product.
  • the method includes: using the first sample set to train the initial detection network to obtain the detection network; the first sample set is a positive sample set; during the process of abnormal detection of multiple images to be detected by the detection network, Based on the detected normal image set and abnormal image set, a second sample set is obtained, and the second sample set is an incremental sample set including a positive sample and a negative sample; wherein, the negative sample is an abnormality in the image
  • An image using the second sample set to update and train the detection network to obtain an updated detection network.

Landscapes

  • Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Artificial Intelligence (AREA)
  • Evolutionary Biology (AREA)
  • Evolutionary Computation (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Image Analysis (AREA)

Abstract

An anomaly detection method and apparatus, an electronic device, a computer readable storage medium, a computer program, and a computer program product. The method comprises: training an initial detection network using a first sample set, to obtain a detection network, the first sample set being a positive sample set (S101); during a process in which the detection network performs anomaly detection on a plurality of images to be detected, obtaining a second sample set on the basis of a detected normal image set and abnormal image set, the second sample set being an incremental sample set comprising a positive sample and a negative sample, wherein the negative sample is an abnormal image, in which an anomaly exists, among the images (S102); and updating and training the detection network using the second sample set, to obtain an updated detection network (S103). According to the method, the accuracy and flexibility of anomaly detection can be improved.

Description

异常检测方法、装置、电子设备、计算机可读存储介质、计算机程序及计算机程序产品Anomaly detection method, device, electronic device, computer readable storage medium, computer program and computer program product
相关申请的交叉引用Cross References to Related Applications
本公开基于申请号为202110932191.5、申请日为2021年08月13日、申请名称为“异常检测方法、装置、电子设备及计算机可读存储介质”的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本公开作为参考。This disclosure is based on the Chinese patent application with the application number 202110932191.5, the application date is August 13, 2021, and the application name is "Anomaly detection method, device, electronic equipment and computer-readable storage medium", and requires the Chinese patent application Priority, the entire content of the Chinese patent application is hereby incorporated by reference into this disclosure.
技术领域technical field
本公开涉及机器视觉技术,尤其涉及一种异常检测方法、装置、电子设备、计算机可读存储介质、计算机程序及计算机程序产品。The present disclosure relates to machine vision technology, and in particular to an anomaly detection method, device, electronic equipment, computer-readable storage medium, computer program and computer program product.
背景技术Background technique
近年来,深度学习算法在各个领域都取得了巨大的进展,也在很多工业视觉检测领域取得了落地。相关技术通过深度学习算法训练得到异常检测模型用于异常图像的检测。深度学习算法往往需要大量的、高质量的训练样本,然而,目前基于正常样本学习方式与基于异常样本学习方式所适用的模型结构以及学习策略不同,因此目前的深度学习方法对于不同类型的训练样本的兼容能力较差,导致所能使用的训练样本较为单一,这样不仅降低了异常检测的灵活性,也降低了异常检测的准确性。In recent years, deep learning algorithms have made great progress in various fields, and have also achieved landing in many industrial visual inspection fields. In related technologies, an abnormality detection model is obtained through deep learning algorithm training to detect abnormal images. Deep learning algorithms often require a large number of high-quality training samples. However, the current learning methods based on normal samples and learning methods based on abnormal samples have different model structures and learning strategies. Therefore, the current deep learning methods are not suitable for different types of training samples. The compatibility of the model is poor, resulting in a single training sample that can be used, which not only reduces the flexibility of anomaly detection, but also reduces the accuracy of anomaly detection.
发明内容Contents of the invention
本公开实施例提供一种异常检测方法、装置、电子设备、计算机可读存储介质、计算机程序及计算机程序产品,能够提高异常检测的准确性与灵活性。Embodiments of the present disclosure provide an anomaly detection method, device, electronic equipment, computer-readable storage medium, computer program and computer program product, which can improve the accuracy and flexibility of anomaly detection.
本公开实施例的技术方案是这样实现的:The technical scheme of the embodiment of the present disclosure is realized in this way:
本公开实施例提供一种异常检测方法,包括:采用第一样本集对初始检测网络进行训练,得到检测网络;所述第一样本集为正样本集;在所述检测网络对多张待检测图像进行异常检测过程中,基于检测出的正常图像集和异常图像集,得到第二样本集,所述第二样本集为包含正样本和负样本的增量样本集;其中,所述负样本为图像中存在异常的异常图像;采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络。An embodiment of the present disclosure provides an anomaly detection method, including: using a first sample set to train an initial detection network to obtain a detection network; the first sample set is a positive sample set; During the abnormal detection process of the image to be detected, a second sample set is obtained based on the detected normal image set and abnormal image set, and the second sample set is an incremental sample set including positive samples and negative samples; wherein, the The negative samples are abnormal images with abnormalities in the image; using the second sample set, the detection network is updated and trained to obtain an updated detection network.
本公开实施例提供一种异常检测装置,包括:第一训练部分,被配置为采用第一样本集对初始检测网络进行训练,得到检测网络;所述第一样本集为正样本集;获取部分,被配置为在所述检测网络对多张待检测图像进行异常检测过程中,基于检测出的正常图像集和异常图像集,得到第二样本集,所述第二样本集为包含正样本和负样本的增量样本集;其中,所述负样本为图像中存在异常的异常图像;第二训练部分,被配置为采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络。An embodiment of the present disclosure provides an abnormality detection device, including: a first training part configured to use a first sample set to train an initial detection network to obtain a detection network; the first sample set is a positive sample set; The acquisition part is configured to obtain a second sample set based on the detected normal image set and abnormal image set during the process of the detection network performing anomaly detection on a plurality of images to be detected, and the second sample set contains positive Incremental sample sets of samples and negative samples; wherein, the negative samples are abnormal images with abnormalities in the image; the second training part is configured to use the second sample set to perform update training on the detection network, Get the updated detection network.
本公开实施例提供一种电子设备,包括:存储器,被配置为存储可执行指令;处理器,被配置为执行所述存储器中存储的可执行指令时,实现上述的异常检测方法。An embodiment of the present disclosure provides an electronic device, including: a memory configured to store executable instructions; a processor configured to implement the above abnormality detection method when executing the executable instructions stored in the memory.
本公开实施例提供一种计算机可读存储介质,存储有计算机程序,用于被处理器执行时,实现上述的异常检测方法。An embodiment of the present disclosure provides a computer-readable storage medium, which stores a computer program and is used to realize the above abnormality detection method when executed by a processor.
本公开实施例提供一种计算机程序,包括计算机可读代码,在所述计算机可读代码在电子设备中运行的情况下,所述计算机设备中的处理器执行用于实现上述异常检测方法中的步骤。An embodiment of the present disclosure provides a computer program, including computer readable codes. When the computer readable codes run in an electronic device, a processor in the computer device executes the above-mentioned anomaly detection method. step.
本公开实施例提供一种计算机程序产品,包括计算机程序指令,该计算机程序指令使得计算机执行上述异常检测方法中的步骤。An embodiment of the present disclosure provides a computer program product, including computer program instructions, where the computer program instructions cause a computer to execute the steps in the above anomaly detection method.
本公开实施例具有以下有益效果:Embodiments of the present disclosure have the following beneficial effects:
采用正样本集对初始检测网络进行训练,得到检测网络,在检测网络对多张待检测图像进行异常检测的过程中,基于检测出的正常图像集和异常图像集,得到包含正样本和负样本的增量样本集,其中,负样本为图像中存在异常的异常图像,并采用包含正样本和负样本的增量样本集,对检测网络进行更新训练,得到更新后的检测网络,所以,得到的更新后的检测网络更加适应实际检测场景,更新后的检测网络的检测精度更高,使得后续在使用更新后的检测网络对待检测图像进行异常检测时,得到的检测结果更准确;同时,由于增量样本中包括了正样本和负样本,所以得到的更新后的检测网络可以是采用正样本和负样本的增量样本训练得到的,使得检测网络能够兼容正样本和负样本等不同的情况,提升了异常检测的通用性与灵活性。The positive sample set is used to train the initial detection network to obtain the detection network. In the process of abnormal detection of multiple images to be detected by the detection network, based on the detected normal image set and abnormal image set, a positive sample and a negative sample are obtained. The incremental sample set of , where the negative sample is an abnormal image with abnormalities in the image, and the incremental sample set including positive samples and negative samples is used to update and train the detection network to obtain the updated detection network. Therefore, we get The updated detection network is more suitable for the actual detection scene, and the detection accuracy of the updated detection network is higher, so that when using the updated detection network to detect abnormalities in the image to be detected, the detection results obtained are more accurate; at the same time, due to Incremental samples include positive samples and negative samples, so the updated detection network can be trained using incremental samples of positive samples and negative samples, so that the detection network can be compatible with different situations such as positive samples and negative samples. , improving the versatility and flexibility of anomaly detection.
附图说明Description of drawings
图1为本公开实施例提供的异常检测方法的一个可选的流程示意图;FIG. 1 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure;
图2为本公开实施例提供的示例性地包含3个负样本的负样本集的示意图;FIG. 2 is a schematic diagram of an exemplary negative sample set including 3 negative samples provided by an embodiment of the present disclosure;
图3为本公开实施例提供的异常检测方法的一个可选的流程示意图;FIG. 3 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure;
图4为本公开实施例提供的得到目标图像I的多尺度特征序列的流程示意图;FIG. 4 is a schematic flow diagram of obtaining a multi-scale feature sequence of a target image I provided by an embodiment of the present disclosure;
图5是本公开实施例提供的编码器-解码器结构的重构网络结构示意图;FIG. 5 is a schematic diagram of a reconstructed network structure of an encoder-decoder structure provided by an embodiment of the present disclosure;
图6为本公开实施例提供的示例性地得到图像的重构特征的流程示意图;FIG. 6 is a schematic flowchart of an exemplary process for obtaining image reconstruction features provided by an embodiment of the present disclosure;
图7为本公开实施例提供的示例性地对目标图像A进行异常检测后得到的异常检测图像A’的效果示意图;Fig. 7 is a schematic diagram of the effect of an abnormality detection image A' obtained by exemplary abnormality detection on a target image A provided by an embodiment of the present disclosure;
图8为本公开实施例提供的异常检测方法的一个可选的流程示意图;FIG. 8 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure;
图9为本公开实施例提供的通过重构样本特征序列与多尺度样本特征序列之间的样本特征差异序列,得到正样本对应的训练损失的流程示意图;9 is a schematic flow diagram of obtaining the training loss corresponding to the positive sample by reconstructing the sample feature difference sequence between the sample feature sequence and the multi-scale sample feature sequence provided by the embodiment of the present disclosure;
图10为本公开实施例提供的异常检测方法的一个可选的流程示意图;FIG. 10 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure;
图11为本公开实施例提供的异常检测方法的一个可选的流程示意图;FIG. 11 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure;
图12为本公开实施例提供的异常检测方法的一个可选的流程示意图;FIG. 12 is an optional schematic flowchart of an abnormality detection method provided by an embodiment of the present disclosure;
图13为本公开实施例提供的示例性地得到更新后的重构网络的一个流程示意图;FIG. 13 is a schematic flowchart of an exemplary updated reconstructed network provided by an embodiment of the present disclosure;
图14为本公开实施例提供的异常检测装置的结构示意图;FIG. 14 is a schematic structural diagram of an abnormality detection device provided by an embodiment of the present disclosure;
图15为本公开实施例提供的电子设备的结构示意图。FIG. 15 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure.
具体实施方式Detailed ways
为了使本公开的目的、技术方案和优点更加清楚,下面将结合附图对本公开作进一步地详细描述,所描述的实施例不应视为对本公开的限制,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本公开保护的范围。In order to make the purpose, technical solutions and advantages of the present disclosure clearer, the present disclosure will be further described in detail below in conjunction with the accompanying drawings. All other embodiments obtained under the premise of creative labor belong to the protection scope of the present disclosure.
在以下的描述中,涉及到“一些实施例”,其描述了所有可能实施例的子集,但是可以理解,“一些实施例”可以是所有可能实施例的相同子集或不同子集,并且可以在不冲突的情况下相互结合。In the following description, references to "some embodiments" describe a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or a different subset of all possible embodiments, and Can be combined with each other without conflict.
在以下的描述中,所涉及的术语“第一\第二\第三”仅仅是是区别类似的对象,不代表针对对象的特定排序,可以理解地,“第一\第二\第三”在允许的情况下可以互换特定的顺序或先后次序,以使这里描述的本公开实施例能够以除了在这里图示或描述的以外的顺序实施。In the following description, the term "first\second\third" is only used to distinguish similar objects, and does not represent a specific ordering of objects. Understandably, "first\second\third" Where permitted, the specific order or sequencing may be interchanged such that the embodiments of the disclosure described herein can be practiced in sequences other than those illustrated or described herein.
除非另有定义,本文所使用的所有的技术和科学术语与属于本公开的技术领域的技术 人员通常理解的含义相同。本文中所使用的术语只是为了描述本公开实施例的目的,不是旨在限制本公开。Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure belongs. The terms used herein are only for the purpose of describing the embodiments of the present disclosure, and are not intended to limit the present disclosure.
本公开实施例提供一种异常检测方法,能够提高异常检测的准确性与灵活性。本公开实施例提供的异常检测方法应用于电子设备。本公开实施例提供的电子设备可以实施为AR眼镜、笔记本电脑,平板电脑,台式计算机,机顶盒,移动设备(例如,移动电话,便携式音乐播放器,个人数字助理,专用消息设备,便携式游戏设备)等各种类型的用户终端,也可以实施为服务器。The embodiment of the present disclosure provides an anomaly detection method, which can improve the accuracy and flexibility of anomaly detection. The anomaly detection method provided by the embodiments of the present disclosure is applied to electronic equipment. The electronic device provided by the embodiment of the present disclosure can be implemented as AR glasses, notebook computer, tablet computer, desktop computer, set-top box, mobile device (for example, mobile phone, portable music player, personal digital assistant, dedicated message device, portable game device) Various types of user terminals can also be implemented as servers.
图1是本公开实施例提供的异常检测方法的一个可选的流程示意图,将结合图1示出的步骤进行说明。FIG. 1 is a schematic flowchart of an optional anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 1 .
S101、采用第一样本集对初始检测网络进行训练,得到检测网络;第一样本集为正样本集。S101. Using the first sample set to train the initial detection network to obtain the detection network; the first sample set is a positive sample set.
本公开实施例中的异常检测方法适用于通过图像检测方式发现异常的场景,示例性地,通过对生产线上的产品图像进行异常检测,发现异常产品,如残次品等;或者,对批量图像进行异常检测,发现其中不符合预设整体规范的异常图像等场景,可根据实际情况进行选择,本公开实施例不作限定。The anomaly detection method in the embodiments of the present disclosure is applicable to the scene where anomalies are discovered through image detection. For example, by performing anomaly detection on product images on the production line, abnormal products, such as defective products, etc. are found; or, for batch images Anomaly detection is performed, and scenes such as abnormal images that do not conform to the preset overall specification are found, which can be selected according to the actual situation, which is not limited by the embodiments of the present disclosure.
本公开实施例中,正样本集中包含了至少一张正样本。正样本为图像中的每个像素都正常的样本;而图像中存在异常部分的图像称为异常图像,且与正样本相对的是负样本,负样本实际为异常图像。示例性地,图2示出了包含3个负样本的负样本集,其中:负样本2-1为发芽的种子图像、负样本2-2为刷头尖端处刷毛异常的牙刷图像、负样本2-3为存在破损的坚果图像。图2中通过2-10、2-20与2-30分别示出了负样本2-1、负样本2-2与负样本2-3中包含异常(即异常像素)的区域。In the embodiment of the present disclosure, the positive sample set contains at least one positive sample. A positive sample is a sample in which every pixel in the image is normal; an image with an abnormal part in the image is called an abnormal image, and the opposite of the positive sample is a negative sample, which is actually an abnormal image. Exemplarily, Fig. 2 shows a negative sample set that contains 3 negative samples, wherein: negative sample 2-1 is a germinated seed image, negative sample 2-2 is a toothbrush image with abnormal bristles at the tip of the brush head, negative sample 2-3 are images of nuts with breakage. 2-10, 2-20 and 2-30 in FIG. 2 respectively show the regions containing abnormalities (ie abnormal pixels) in the negative samples 2-1, 2-2 and 2-3.
本公开实施例中,电子设备可以采用包含至少一张正样本的正样本集,对初始检测网络进行持续训练,直至得到训练好的检测网络。In the embodiment of the present disclosure, the electronic device may use a positive sample set including at least one positive sample to continuously train the initial detection network until a trained detection network is obtained.
在一些实施例中,初始检测网络可以由初始特征提取网络和初始重构网络组成,电子设备可以对初始特征提取网络和初始重构网络同时或分别进行持续训练,得到训练好的特征提取网络和训练好的重构网络,并将得到的训练好的特征提取网络和训练好的重构网络,作为得到的检测网络。在另一些实施例中,初始检测网络也可以由预先训练好的特征提取网络和初始重构网络组成,电子设备可以只对初始重构网络进行持续训练,从而得到训练好的重构网络,并将预先训练好的特征提取网络和训练好的重构网络,作为得到的检测网络。In some embodiments, the initial detection network may be composed of an initial feature extraction network and an initial reconstruction network, and the electronic device may perform continuous training on the initial feature extraction network and the initial reconstruction network simultaneously or separately to obtain a trained feature extraction network and an initial reconstruction network. The trained reconstruction network is used, and the obtained trained feature extraction network and the trained reconstruction network are used as the obtained detection network. In other embodiments, the initial detection network can also be composed of a pre-trained feature extraction network and an initial reconstruction network, and the electronic device can only perform continuous training on the initial reconstruction network to obtain a trained reconstruction network, and The pre-trained feature extraction network and the trained reconstruction network are used as the obtained detection network.
在一些实施例中,电子设备可以将包含多重特征提取层的深度卷积神经网络(Convolutional Neural Network,CNN)网络,如ResNet-34作为特征提取网络。In some embodiments, the electronic device may use a deep convolutional neural network (Convolutional Neural Network, CNN) network including multiple feature extraction layers, such as ResNet-34, as the feature extraction network.
在一些实施例中,重构网络可以通过编码器-解码器(Transformer)结构的神经网络来实现。其中,Transformer是一种具有全局注意机制的深层神经网络,最早出现在自然语言处理领域。近年来,Transformer以其强大的表示能力逐渐被广泛应用于计算机视觉任务中。目前,异常检测场景中还未涉及Transformer的应用,而本公开实施例可以将Transformer的应用扩展到异常检测场景中,利用Transformer对于输入序列的全局注意力的捕捉,加强重构网络对语义信息的深层次理解,使得重构网络可以在理解图像深层语义特征的前提下实现特征重构。In some embodiments, the reconstructed network may be implemented by a neural network with an encoder-decoder (Transformer) structure. Among them, Transformer is a deep neural network with a global attention mechanism, which first appeared in the field of natural language processing. In recent years, Transformer has gradually been widely used in computer vision tasks due to its powerful representation capabilities. At present, the application of Transformer has not been involved in the anomaly detection scenario, but the embodiments of the present disclosure can extend the application of Transformer to the anomaly detection scenario, and use Transformer to capture the global attention of the input sequence to strengthen the semantic information of the reconstruction network. Deep understanding enables the reconstruction network to realize feature reconstruction on the premise of understanding the deep semantic features of the image.
S102、在检测网络对多张待检测图像进行异常检测过程中,基于检测出的正常图像集和异常图像集,得到第二样本集,第二样本集为包含正样本和负样本的增量样本集;其中,负样本为图像中存在异常的异常图像。S102. During the abnormality detection process of multiple images to be detected by the detection network, a second sample set is obtained based on the detected normal image set and abnormal image set, and the second sample set is an incremental sample including positive samples and negative samples set; where the negative samples are abnormal images with abnormalities in the image.
本公开实施例中,待检测图像可以是任何图像,例如,可以是上述的生产线上的产品图像,本公开实施例对此不作限定。在一些实施例中,电子设备可以通过图像采集设备,获取待检测物品的图像作为待检测图像,例如,对产线生产的产品进行图像采集,得到待 检测图像,以通过本公开实施例的方法对待检测图像进行异常检测,从而确定待检测物品是否存在异常;或者,电子设备也可以直接从其他设备处得到待检测图像。电子设备可以一次获取一张待检测图像,也可以一次获取多张待检测图像,本公开实施例对此不作限定。In the embodiment of the present disclosure, the image to be detected may be any image, for example, may be the product image on the above-mentioned production line, which is not limited in the embodiment of the present disclosure. In some embodiments, the electronic device can acquire the image of the item to be detected as the image to be detected through the image acquisition device, for example, collect the image of the product produced on the production line to obtain the image to be detected, so as to pass the method of the embodiment of the present disclosure Anomaly detection is performed on the image to be detected, so as to determine whether the object to be detected is abnormal; or, the electronic device can also directly obtain the image to be detected from other devices. The electronic device may acquire one image to be detected at a time, or may acquire multiple images to be detected at a time, which is not limited in this embodiment of the present disclosure.
本公开实施例中,电子设备可以采用由正样本集训练好的检测模型,对多张待检测图像进行异常检测,得到正常图像集和异常图像集,并根据得到的正常图像集和异常图像集,得到由正常图像集和异常图像集组成的增量样本集,其中,正常图像集中包含至少一张正常图像,异常图像集中包含至少一张异常图像。In the embodiment of the present disclosure, the electronic device can use the detection model trained by the positive sample set to perform anomaly detection on multiple images to be detected to obtain a normal image set and an abnormal image set, and based on the obtained normal image set and abnormal image set , to obtain an incremental sample set consisting of a normal image set and an abnormal image set, wherein the normal image set contains at least one normal image, and the abnormal image set contains at least one abnormal image.
在一些实施例中,电子设备可以将检测得到的所有正常图像作为正常图像集,以及,将检测得到的所有异常图像作为异常图像集。在一些实施例中,电子设备也可以从检测得到的所有正常图像和所有异常图像中,挑选出部分正常图像和异常图像,从而得到正常图像集和异常图像集,本公开实施例对此不作限定。In some embodiments, the electronic device may use all detected normal images as a normal image set, and use all detected abnormal images as an abnormal image set. In some embodiments, the electronic device may also select some normal images and abnormal images from all detected normal images and all abnormal images, so as to obtain a normal image set and an abnormal image set, which is not limited in this embodiment of the present disclosure .
S103、采用第二样本集,对检测网络进行更新训练,得到更新后的检测网络。S103. Using the second sample set, update and train the detection network to obtain an updated detection network.
本公开实施例中,电子设备可以采用包含正样本和负样本的增量样本集,对得到的检测网络继续进行更新训练,直到最终得到的损失达到预设损失阈值的情况下,得到训练好的检测网络,并将该训练好的检测网络作为更新后的检测网络。In the embodiment of the present disclosure, the electronic device can use the incremental sample set including positive samples and negative samples, and continue to update and train the obtained detection network until the final loss reaches the preset loss threshold. detection network, and use the trained detection network as an updated detection network.
在一些实施例中,在上述S103之后,还可以执行S104-S107;图3是本公开实施例提供的异常检测方法的一个可选的流程示意图,将结合图3示出的步骤进行说明。In some embodiments, after the above S103, S104-S107 may also be executed; FIG. 3 is an optional schematic flowchart of the anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 3 .
S104、采用更新后的特征提取网络,对目标图像进行不同尺度的特征处理,得到多尺度特征序列;更新后的检测网络包括:更新后的特征提取网络和更新后的重构网络。S104. Using the updated feature extraction network, perform feature processing of different scales on the target image to obtain a multi-scale feature sequence; the updated detection network includes: an updated feature extraction network and an updated reconstruction network.
本公开实施例中,目标图像可以是任何图像,例如,可以是上述的生产线上的产品的图像,本公开实施例对此不作限定。In the embodiment of the present disclosure, the target image may be any image, for example, may be the image of the above-mentioned product on the production line, which is not limited in the embodiment of the present disclosure.
本公开实施例中,在更新后的检测网络包括:更新后的特征提取网络和更新后的重构网络的情况下,电子设备可以采用更新后的特征提取网络,对目标图像进行不同尺度的特征提取,得到目标图像在多种尺度下的多个不同尺度的特征;并将多个不同尺度的特征进行融合,得到多尺度特征;对多尺度特征进行形状变换,将多维度的特征信息转换为序列形式,得到多尺度特征序列。例如,在采用ResNet-34作为特征提取网络的情况下,电子设备可以采用更新后的ResNet-34,对目标图像进行多重尺度的特征提取,利用ResNet-34的底层特征提取层得到目标图像的表观特征,如颜色,边界划分,对比度,亮度等等,利用ResNet-34的高层提取层输出目标图像的高层次的语义信息;电子设备将目标图像的表观特征与高层次的语义信息作为多个不同尺度的特征,进行特征融合,得到多尺度特征。In the embodiment of the present disclosure, when the updated detection network includes: the updated feature extraction network and the updated reconstruction network, the electronic device can use the updated feature extraction network to perform feature extraction of different scales on the target image Extract to obtain multiple features of different scales of the target image at multiple scales; fuse multiple features of different scales to obtain multi-scale features; perform shape transformation on multi-scale features, and convert multi-dimensional feature information into In sequence form, a multi-scale feature sequence is obtained. For example, in the case of using ResNet-34 as the feature extraction network, the electronic device can use the updated ResNet-34 to perform multi-scale feature extraction on the target image, and use the underlying feature extraction layer of ResNet-34 to obtain the representation of the target image. Visual features, such as color, boundary division, contrast, brightness, etc., use the high-level extraction layer of ResNet-34 to output high-level semantic information of the target image; electronic devices use the apparent features and high-level semantic information of the target image as multiple Features of different scales are combined to obtain multi-scale features.
示例性地,如图4所示,电子设备通过更新后的CNN网络作为特征提取网络,对目标图像I进行4种尺度的特征提取,得到4个尺度的特征B(I),其中,
Figure PCTCN2022071448-appb-000001
B(I)=f 1,f 2,f 3,f 4。这里,
Figure PCTCN2022071448-appb-000002
i表征CNN网络的第i个网络层。从图4中可以看出,不同网络层提取出的尺度特征的特征尺寸不同。电子设备可以先将不同尺寸的特征调整至同一尺寸,如调整至尺寸H×W,然后对调整尺寸后的4个特征进行特征融合,得到多尺度特征,如公式(1)所示:
Exemplarily, as shown in FIG. 4 , the electronic device uses the updated CNN network as a feature extraction network to perform feature extraction of four scales on the target image I to obtain features B(I) of four scales, where,
Figure PCTCN2022071448-appb-000001
B(I)=f 1 , f 2 , f 3 , f 4 . here,
Figure PCTCN2022071448-appb-000002
i represents the i-th network layer of the CNN network. It can be seen from Figure 4 that the scale features extracted by different network layers have different feature sizes. The electronic device can first adjust the features of different sizes to the same size, such as adjusting to the size H×W, and then perform feature fusion on the four adjusted features to obtain multi-scale features, as shown in formula (1):
Figure PCTCN2022071448-appb-000003
Figure PCTCN2022071448-appb-000003
公式(1)中,R代表调整尺寸的操作,C=∑ iC i代表多尺度特征f的特征通道。可以看出,本公开实施例中,由不同特征提取层得到的多个不同尺度的特征具有不同水平的感受野,对目标图像中可能存在的不同程度的异常区域非常敏感,因此,基于多尺度特征进行异常检测更有助于提高异常检测的准确性。 In formula (1), R represents the resizing operation, and C = ∑ i C i represents the feature channel of the multi-scale feature f. It can be seen that in the embodiments of the present disclosure, multiple features of different scales obtained from different feature extraction layers have different levels of receptive fields, and are very sensitive to different degrees of abnormal regions that may exist in the target image. Therefore, based on the multi-scale Anomaly detection using features is more helpful to improve the accuracy of anomaly detection.
本公开实施例中,电子设备可以对多尺度特征进行形状变换,从而将多尺度特征转化为序列的形式,作为后续重构网络的输入。在一些实施例中,如图4所示,对于维度为H×W×C的多尺度特征f,电子设备可以对每个通道对应的H×W进行维度合并,实 现对多尺度特征的形状变换,得到H×W个C维的多尺度特征向量,作为多尺度特征序列。In the embodiment of the present disclosure, the electronic device can perform shape transformation on the multi-scale features, so as to transform the multi-scale features into a sequence form, which is used as an input for the subsequent reconstruction network. In some embodiments, as shown in Figure 4, for a multi-scale feature f with a dimension of H×W×C, the electronic device can merge the dimensions of H×W corresponding to each channel to realize the shape transformation of the multi-scale feature , get H×W C-dimensional multi-scale feature vectors as multi-scale feature sequences.
在一些实施例中,多尺度特征序列可以是包含任意形式词向量的特征词序列,如word2vec序列,GloVe序列,one-hot编码序列等等,可根据实际情况进行选择,本公开实施例不作限定。In some embodiments, the multi-scale feature sequence can be a feature word sequence containing any form of word vector, such as word2vec sequence, GloVe sequence, one-hot encoding sequence, etc., which can be selected according to the actual situation, and the embodiment of the present disclosure is not limited .
S105、采用更新后的重构网络,对多尺度特征序列和预设的问询词序列进行重构,得到重构特征序列。S105. Using the updated reconstruction network, reconstruct the multi-scale feature sequence and the preset query word sequence to obtain the reconstructed feature sequence.
本公开实施例中,电子设备可以以序列到序列(Sequence to Sequence)的转换模型为更新后的重构网络,以序列形式的多尺度特征序列为指导信息,结合指导信息对预设的问询词序列进行重构,得到重构特征序列,进而基于重构特征序列实现异常检测。In the embodiment of the present disclosure, the electronic device can use the sequence-to-sequence (Sequence to Sequence) conversion model as the updated reconstruction network, use the multi-scale feature sequence in the form of sequence as the guidance information, and combine the guidance information with the preset inquiry The word sequence is reconstructed to obtain the reconstructed feature sequence, and then anomaly detection is realized based on the reconstructed feature sequence.
在一些实施例中,更新后的重构网络可以通过编码器-解码器(Transformer)结构的神经网络来实现。需要说明的是,更新后的重构网络与采用正样本集训练得到的重构网络的结构相同,但网络参数不同。在一些实施例中,如果直接通过Transformer结构的重构网络对多尺度特征序列f s进行重构,会得到单输入单输出的重构特征序列
Figure PCTCN2022071448-appb-000004
其中,
Figure PCTCN2022071448-appb-000005
R表示重构操作。然而这种单输入单输出的方法容易导致重构网络仅能学习到简单的恒等映射,难以从输入的样本中理解到需要学习的任务目标,这样无论输入的是正常样本还是异常样本,模型都只能将对输入的样本进行简单的恒等映射进行输出,无法习得对异常图像的鉴别能力。因此,本公开实施例引入可学习的问询词序列,以问询词序列与多尺度特征序列作为重构网络的双输入来进行特征重构,得到重构特征序列。
In some embodiments, the updated reconstructed network may be implemented by a neural network with an encoder-decoder (Transformer) structure. It should be noted that the updated reconstructed network has the same structure as the reconstructed network trained with the positive sample set, but the network parameters are different. In some embodiments, if the multi-scale feature sequence f s is reconstructed directly through the reconstruction network of the Transformer structure, a single-input and single-output reconstructed feature sequence will be obtained
Figure PCTCN2022071448-appb-000004
in,
Figure PCTCN2022071448-appb-000005
R stands for Refactoring Operations. However, this single-input-single-output method tends to cause the reconstruction network to only learn simple identity mappings, and it is difficult to understand the task goals that need to be learned from the input samples. In this way, no matter whether the input is a normal sample or an abnormal sample, the model Both can only output the simple identity mapping of the input samples, and cannot learn the ability to distinguish abnormal images. Therefore, the embodiment of the present disclosure introduces a learnable query word sequence, uses the query word sequence and the multi-scale feature sequence as dual inputs of the reconstruction network to perform feature reconstruction, and obtains the reconstructed feature sequence.
在一些实施例中,本公开实施例中通过双输入单输出方法得到的重构特征序列可以表示为
Figure PCTCN2022071448-appb-000006
其中,q表示预设的问询词序列,预设的问询词序列与多尺度特征序列具有相同的维度。
In some embodiments, the reconstructed feature sequence obtained by the double-input single-output method in the embodiment of the present disclosure can be expressed as
Figure PCTCN2022071448-appb-000006
Among them, q represents a preset query word sequence, and the preset query word sequence has the same dimension as the multi-scale feature sequence.
本公开实施例中,问询词序列是一种可学习得到的向量序列。电子设备可以在重构网络的模型训练的启动阶段,对问询词序列中的向量进行初始化,并在训练重构网络的过程中迭代地对初始问询词序列进行更新,最终得到预设的问询词序列。In the embodiment of the present disclosure, the query word sequence is a vector sequence that can be learned. The electronic device can initialize the vectors in the query word sequence at the start-up stage of the model training of the reconstructed network, and iteratively update the initial query word sequence during the process of training the reconstructed network, and finally obtain the preset sequence of query words.
本公开实施例中,电子设备基于Transformer结构的重构网络中的编码器部分,对多尺度特征序列进行编码,得到编码序列。电子设备可以以编码序列作为重构网络中的解码器部分的指导信息,用于对编码器的解码过程进行指导,从而基于编码序列,通过解码器对预设的问询词序列进行解码重构,得到重构特征序列。In the embodiment of the present disclosure, the electronic device encodes the multi-scale feature sequence based on the encoder part in the reconstruction network of the Transformer structure to obtain the coded sequence. The electronic device can use the coding sequence as the guidance information for reconstructing the decoder part of the network, which is used to guide the decoding process of the encoder, so that based on the coding sequence, the decoder can decode and reconstruct the preset query word sequence , to get the reconstructed feature sequence.
在一些实施例中,Transformer结构的重构网络可以如图5所示,包含由N个编码模块堆叠得到的编码器,以及由N个解码模块堆叠得到的解码器。其中,N个编码模块中的每个编码模块包含多头自注意力(Multi-head Attention)层、前馈网络(Feed Forward Network,FFN)以及残差与归一化(ADD&Normalize)层。示例性地,前馈网络可以是全连接神经网络。In some embodiments, the reconstruction network of the Transformer structure may be shown in FIG. 5 , including an encoder obtained by stacking N encoding modules and a decoder obtained by stacking N decoding modules. Among them, each of the N coding modules includes a multi-head self-attention (Multi-head Attention) layer, a feed-forward network (Feed Forward Network, FFN) and a residual and normalization (ADD&Normalize) layer. Exemplarily, the feedforward network may be a fully connected neural network.
示例性地,如图5所示,电子设备将图4中得到的多尺度特征序列输入编码器中,通过三个预设权值矩阵转换为用于注意力计算的Q向量、K向量和V向量,进而通过多头自注意力层,根据Q向量,K向量和V向量计算注意力值,并通过残差与归一化层根据计算得到的注意力值,以及原始的Q向量、K向量和V向量进行残差计算与归一化处理,通过前馈网络对处理结果进行线性与非线性变换,再经过一次残差与归一化层,得到多尺度特征序列对应的编码序列,将编码序列输入解码器。进而,在解码器中,通过多头自注意力层和残差与归一化层,对预设的问询词序列进行注意力值计算与残差归一化处理,并将编码器输出的编码序列与预设的问询词序列的处理结果进行合并,再次进行注意力值计算,得到合并注意力值,并结合预设的问询词序列的处理结果与合并注意力值进行残差与归一 化处理,再通过前馈网络与残差归一化网络,得到重构特征序列。Exemplarily, as shown in Figure 5, the electronic device inputs the multi-scale feature sequence obtained in Figure 4 into the encoder, and converts it into Q vector, K vector and V vector for attention calculation through three preset weight matrices Vector, and then through the multi-head self-attention layer, calculate the attention value according to the Q vector, K vector and V vector, and pass the residual and normalization layer according to the calculated attention value, as well as the original Q vector, K vector and The V vector performs residual calculation and normalization processing, and performs linear and nonlinear transformation on the processing results through the feedforward network, and then passes through the residual and normalization layer to obtain the coding sequence corresponding to the multi-scale feature sequence, and convert the coding sequence to Enter the decoder. Furthermore, in the decoder, through the multi-head self-attention layer and the residual and normalization layer, the attention value calculation and residual normalization processing are performed on the preset query word sequence, and the encoding output by the encoder The sequence is combined with the processing results of the preset query word sequence, and the attention value is calculated again to obtain the combined attention value, and the residual and normalization is performed by combining the processing results of the preset query word sequence and the combined attention value. Normalization processing, and then through the feedforward network and the residual normalization network, the reconstructed feature sequence is obtained.
在一些实施例中,如图5所示,电子设备还可以利用Transformer置换不变的特性,在多头自注意力层的每层中加入位置信息,示例性地,可以是正弦位置信息,以通过位置信息进一步提高重构网络对语义的理解能力。可根据实际情况进行选择,本公开实施例不作限定。In some embodiments, as shown in FIG. 5 , the electronic device can also use the property of Transformer permutation invariance to add position information to each layer of the multi-head self-attention layer, for example, it can be sinusoidal position information, so as to pass The location information further improves the reconstruction network's ability to understand semantics. The selection can be made according to the actual situation, which is not limited in the embodiment of the present disclosure.
这里,电子设备将从图像中提取得到的多尺度特征序列作为指导信息,对可学习的问询词序列进行双输入方式的特征重构,可以使得重构网络结合问询词序列中的语义,在深层语义理解的基础上进行解码重构,从而提高重构特征的准确性,进而提高异常检测的准确性。Here, the electronic device uses the multi-scale feature sequence extracted from the image as guidance information, and performs double-input feature reconstruction on the learnable query word sequence, which can make the reconstruction network combine the semantics in the query word sequence, Decoding reconstruction is performed on the basis of deep semantic understanding, so as to improve the accuracy of reconstructed features, and then improve the accuracy of anomaly detection.
上述S104-S105的过程可以采用图6表示,如图6所示,电子设备可以通过更新后的特征提取网络,对目标图像进行不同尺度的特征提取与特征融合,得到多尺度特征;对多尺度特征进行形状变换,得到多尺度特征序列,进而通过更新后的重构网络对多尺度特征序列与初始问询词序列进行重构,得到重构特征序列。进一步的,电子设备可以对序列形式的重构特征序列进行形状变换,得到重构特征。The above process of S104-S105 can be shown in Figure 6. As shown in Figure 6, the electronic device can perform feature extraction and feature fusion of different scales on the target image through the updated feature extraction network to obtain multi-scale features; The shape of the feature is transformed to obtain a multi-scale feature sequence, and then the multi-scale feature sequence and the initial query word sequence are reconstructed through the updated reconstruction network to obtain the reconstructed feature sequence. Further, the electronic device can perform shape transformation on the reconstructed feature sequence in the form of a sequence to obtain the reconstructed feature.
S106、根据重构特征序列与多尺度特征序列,确定目标图像的每个像素位置上的特征差异。S106. Determine the feature difference at each pixel position of the target image according to the reconstructed feature sequence and the multi-scale feature sequence.
本公开实施例中,多尺度特征序列表征目标图像中的原始特征,重构特征序列表征基于原始特征进行重构得到的特征,电子设备可以通过对比重构特征序列与多尺度特征序列之间的差异,确定目标图像的特征差异序列。In the embodiment of the present disclosure, the multi-scale feature sequence represents the original features in the target image, and the reconstructed feature sequence represents the features reconstructed based on the original features. The electronic device can compare the reconstruction feature sequence with the multi-scale feature sequence Difference, which determines the sequence of feature differences for the target image.
本公开实施例中,特征差异序列中的每个特征差异可以包含目标图像中对应的像素位置信息以及差异值。电子设备可以通过特征差异,确定目标图像中每个像素位置上的差异值,以特征差异表征重构网络对目标图像每个像素点的重构效果。In the embodiment of the present disclosure, each feature difference in the feature difference sequence may include corresponding pixel position information and a difference value in the target image. The electronic device can determine the difference value at each pixel position in the target image through the feature difference, and use the feature difference to represent the reconstruction effect of the reconstruction network on each pixel of the target image.
在一些实施例中,电子设备可以计算重构特征与多尺度特征之间的特征差异。示例性地,电子设备可通过公式(2),计算重构特征与多尺度特征之间的特征差异,如下:In some embodiments, the electronic device may calculate a feature difference between the reconstructed features and the multi-scale features. Exemplarily, the electronic device can calculate the feature difference between the reconstructed feature and the multi-scale feature through formula (2), as follows:
Figure PCTCN2022071448-appb-000007
Figure PCTCN2022071448-appb-000007
公式(2)中,f(u,i)为多尺度特征,
Figure PCTCN2022071448-appb-000008
为重构特征;u为空间位置的索引坐标,示例性地,可以是多尺度特征或重构特征的H×W大小的特征地图中每个位置的坐标。i为特征通道的索引。电子设备可以通过公式(2),对多尺度特征与重构特征进行对位相减,得到每个位置上的特征差异d(u,i)。
In formula (2), f(u,i) is a multi-scale feature,
Figure PCTCN2022071448-appb-000008
is the reconstructed feature; u is the index coordinate of the spatial position, for example, it can be the coordinates of each position in the H×W feature map of multi-scale features or reconstructed features. i is the index of the feature channel. The electronic device can use the formula (2) to subtract the multi-scale features and the reconstructed features to obtain the feature difference d(u,i) at each position.
在一些实施例中,电子设备也可以根据多尺度特征序列与重构特征序列进行差异计算,得到特征差异序列。In some embodiments, the electronic device may also perform difference calculation according to the multi-scale feature sequence and the reconstructed feature sequence to obtain a feature difference sequence.
S107、基于特征差异,确定每个像素位置上的异常评分,并基于异常评分,绘制目标图像对应的异常检测图像。S107. Determine an abnormality score at each pixel position based on the feature difference, and draw an abnormality detection image corresponding to the target image based on the abnormality score.
本公开实施例中,由于重构网络具有对正常图像或正常像素点的重构特征与原始特征相接近,同时对异常图像或异常像素点的重构特征与原始特征相远离的特性,因此电子设备可以基于特征差异所表征的每个像素位置上的重构效果,确定每个像素位置上的异常评分,异常评分用于表征对应像素点是否为异常像素点。电子设备基于异常评分,分别对正常像素点与异常像素点进行区别绘制,得到目标图像对应的异常检测图像。这样,就可以在异常检测图像中自动标记出异常区域。In the embodiment of the present disclosure, since the reconstruction network has the characteristics that the reconstructed features of normal images or normal pixels are close to the original features, while the reconstructed features of abnormal images or abnormal pixels are far away from the original features, so the electronic The device can determine the abnormal score at each pixel position based on the reconstruction effect at each pixel position represented by the feature difference, and the abnormal score is used to indicate whether the corresponding pixel is an abnormal pixel. Based on the anomaly score, the electronic device distinguishes and draws normal pixels and abnormal pixel points respectively, and obtains an abnormality detection image corresponding to the target image. In this way, abnormal regions can be automatically marked in anomaly detection images.
在一些实施例中,电子设备可以将每个像素位置的异常评分与预设评分区间进行对比,根据异常评分落入的目标评分区间,以及预设评分区间与预设像素值的对应关系,确定每个像素位置对应的目标像素值。电子设备根据每个像素位置对应的目标像素值绘制出异常检测图像。In some embodiments, the electronic device can compare the abnormality score of each pixel position with the preset scoring interval, and determine The target pixel value corresponding to each pixel location. The electronic device draws an abnormality detection image according to the target pixel value corresponding to each pixel position.
示例性地,在每个像素位置上的异常评分小于或者等于预设评分阈值的情况下,电子 设备将该像素位置对应的像素值绘制为第一值;在每个像素位置上的异常评分大于预设评分阈值的情况下,电子设备将该像素位置对应的像素值绘制为第二值;直至将目标图像的像素位置绘制完成时,得到异常检测图像;例如,对于一目标图像A,电子设备可以得到目标图像A的异常评分,并根据该异常评分,绘制出异常检测图像A’,以采用异常检测图像A’来表征目标图像A是否为正常图像或异常图像。示例性地,图7为本公开实施例提供的示例性地对目标图像A进行异常检测后得到的异常检测图像A’的效果示意图;如图7所示,在目标图像A为牙刷图像的情况下,绘制的异常检测图像为牙刷图像A’,并且,如图像A所示,在刷头尖端处刷毛异常的情况下,绘制出的牙刷图像A’中,刷头尖端处刷毛所在区域7-10的像素颜色(像素值)与其他部分的刷毛所在区域7-20的像素颜色不同,以此表征目标图像A为异常图像。Exemplarily, when the abnormality score at each pixel position is less than or equal to the preset scoring threshold, the electronic device draws the pixel value corresponding to the pixel position as the first value; the abnormality score at each pixel position is greater than In the case of a preset scoring threshold, the electronic device draws the pixel value corresponding to the pixel position as a second value; until the pixel position of the target image is drawn, an abnormality detection image is obtained; for example, for a target image A, the electronic device An abnormality score of the target image A can be obtained, and an abnormality detection image A' is drawn according to the abnormality score, so as to use the abnormality detection image A' to represent whether the target image A is a normal image or an abnormal image. Exemplarily, FIG. 7 is a schematic diagram of an abnormality detection image A' obtained after abnormality detection of a target image A provided by an embodiment of the present disclosure; as shown in FIG. 7 , when the target image A is a toothbrush image Next, the drawn anomaly detection image is toothbrush image A', and, as shown in image A, in the case of abnormal bristles at the tip of the brush head, in the drawn toothbrush image A', the area where the bristles at the tip of the brush head is 7- The pixel color (pixel value) of 10 is different from the pixel color of the region 7-20 where other bristles are located, which indicates that the target image A is an abnormal image.
在一些实施例中,对于上述S101可以通过S1011-S1013实现;图8是本公开实施例提供的异常检测方法的一个可选的流程示意图,将结合图8示出的步骤进行说明。In some embodiments, the above S101 may be implemented through S1011-S1013; FIG. 8 is an optional schematic flow chart of the anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 8 .
S1011、采用初始检测网络对第一样本集中的正样本进行检测,得到正样本对应的第一特征差异序列。S1011. Use the initial detection network to detect the positive samples in the first sample set, and obtain a first feature difference sequence corresponding to the positive samples.
本公开实施例中,对于每张正样本,电子设备可以通过初始检测网络得到该正样本的多尺度特征序列,并根据该多尺度特征序列和预设的问询词序列进行重构,得到该正样本的重构特征序列,并通过对比重构特征序列与多尺度特征序列之间的差异,确定该正样本的特征差异序列,以下称为第一特征差异序列。需要说明的是,初始检测网络与更新后的检测网络的网络结构相同,而网络参数不同,所以,电子设备得到正样本对应的第一特征差异序列的过程,与上述S104-S106部分相同。In the embodiment of the present disclosure, for each positive sample, the electronic device can obtain the multi-scale feature sequence of the positive sample through the initial detection network, and reconstruct it according to the multi-scale feature sequence and the preset query word sequence to obtain the The reconstructed feature sequence of the positive sample, and by comparing the difference between the reconstructed feature sequence and the multi-scale feature sequence, determine the feature difference sequence of the positive sample, which is hereinafter referred to as the first feature difference sequence. It should be noted that the initial detection network and the updated detection network have the same network structure, but different network parameters. Therefore, the process of the electronic device obtaining the first feature difference sequence corresponding to the positive sample is the same as the above S104-S106.
S1012、根据第一特征差异序列和正常损失函数,确定出正样本对应的训练损失;其中,正常损失函数表征正样本对应的重构特征序列拉近正样本。S1012. Determine the training loss corresponding to the positive sample according to the first feature difference sequence and the normal loss function; wherein, the normal loss function indicates that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample.
本公开实施例中,电子设备在得到第一特征差异序列的情况下,可以采用正常损失函数计算出正样本对应的训练损失。In the embodiment of the present disclosure, when the electronic device obtains the first feature difference sequence, it may use a normal loss function to calculate the training loss corresponding to the positive sample.
在一些实施例中,正常损失函数可以包括回归损失函数;示例性地,可以是平滑(Smooth)L1损失、MSE损失等等,可根据实际情况进行选择,本公开实施例不作限定。示例性的,电子设备可以将平滑L1损失作为正常损失函数来计算正样本对应的训练损失,如公式(3)所示,如下:In some embodiments, the normal loss function may include a regression loss function; for example, it may be smooth (Smooth) L1 loss, MSE loss, etc., which can be selected according to actual conditions, and are not limited in this embodiment of the present disclosure. Exemplarily, the electronic device can use the smooth L1 loss as a normal loss function to calculate the training loss corresponding to the positive sample, as shown in formula (3), as follows:
Figure PCTCN2022071448-appb-000009
Figure PCTCN2022071448-appb-000009
公式(3)中,
Figure PCTCN2022071448-appb-000010
代表第一特征差异或第一特征差异序列,L nor代表正样本对应的训练损失。
In formula (3),
Figure PCTCN2022071448-appb-000010
Represents the first feature difference or the first feature difference sequence, and L nor represents the training loss corresponding to the positive sample.
在一些实施例中,图9示出了在正样本情况下,通过正样本的第一特征差异序列得到正样本对应的训练损失的情况。In some embodiments, FIG. 9 shows that in the case of a positive sample, the training loss corresponding to the positive sample is obtained through the first feature difference sequence of the positive sample.
可以理解的是,电子设备可以通过正常损失函数,计算原始特征与重构特征之间的差距,来对初始检测网络针对正样本的重构能力进行评估,从而使得初始检测网络能够支持使用正样本的训练。It can be understood that the electronic device can calculate the gap between the original feature and the reconstructed feature through the normal loss function to evaluate the reconstruction ability of the initial detection network for the positive sample, so that the initial detection network can support the use of positive samples training.
S1013、基于训练损失,对初始检测网络进行训练调整,直至得到的最终损失小于预设损失阈值时,得到检测网络。S1013. Based on the training loss, train and adjust the initial detection network until the obtained final loss is less than the preset loss threshold, and obtain the detection network.
本公开实施例中,电子设备在得到正样本对应的训练损失的情况下,可以基于正样本对应的训练损失,对初始检测网络进行网络参数的调整,完成当前轮使用正样本的训练过程。电子设备可以继续使用正样本集中的正样本,对初始检测网络进行迭代训练,直至最终得到的损失小于预设损失阈值的情况下,得到检测网络。In the embodiment of the present disclosure, when the electronic device obtains the training loss corresponding to the positive sample, it can adjust the network parameters of the initial detection network based on the training loss corresponding to the positive sample, and complete the training process of using the positive sample in the current round. The electronic device can continue to use the positive samples in the positive sample set to iteratively train the initial detection network until the final loss is less than the preset loss threshold to obtain the detection network.
本公开实施例中,预设损失阈值可以根据实际需要设定,本公开实施例对此不作限定。In the embodiments of the present disclosure, the preset loss threshold may be set according to actual needs, which is not limited in the embodiments of the present disclosure.
在一些实施例中,初始检测网络可以由预先训练好的特征提取网络和初始重构网络组 成;基于此,电子设备可以根据得到的第一特征差异序列和正常损失函数,对初始重构网络进行训练,并在最终得到的损失小于预设损失阈值的情况下,得到重构网络,从而得到由预先训练好的特征提取网络与得到的重构网络所组成的检测网络。In some embodiments, the initial detection network can be composed of a pre-trained feature extraction network and an initial reconstruction network; based on this, the electronic device can perform an initial reconstruction on the initial reconstruction network according to the obtained first feature difference sequence and normal loss function Training, and when the final loss is less than the preset loss threshold, the reconstruction network is obtained, so as to obtain the detection network composed of the pre-trained feature extraction network and the obtained reconstruction network.
在另一些实施例中,初始检测网络可以由初始特征提取网络和初始重构网络组成,电子设备可以根据初始特征提取网络提取的多尺度特征,与初始特征提取网络对应的损失函数,计算出初始特征提取网络对应的训练损失,同时,根据得到的多尺度特征与重构特征得到第一特征差异序列,并根据第一特征差异序列和初始重构网络对应的正常损失函数,确定出初始重构网络对应的训练损失,并采用初始特征提取网络对应的训练损失,对初始特征提取网络进行调整,以及采用初始重构网络对应的训练损失,对初始重构网络进行训练调整,直至得到初始特征提取网络对应的最终损失小于对应的预设损失阈值,且初始重构网络对应的最终损失小于对应的预设损失阈值的情况下,得到特征提取网络与重构网络,从而得到由特征提取网络与重构网络组成的检测网络。在一些实施例中,电子设备也可以对初始特征提取网络和初始重构网络分别进行训练,训练方法与上述的方法相同。In other embodiments, the initial detection network can be composed of an initial feature extraction network and an initial reconstruction network, and the electronic device can calculate the initial The training loss corresponding to the feature extraction network. At the same time, the first feature difference sequence is obtained according to the obtained multi-scale features and reconstruction features, and the initial reconstruction is determined according to the first feature difference sequence and the normal loss function corresponding to the initial reconstruction network. The training loss corresponding to the network, and the training loss corresponding to the initial feature extraction network is used to adjust the initial feature extraction network, and the training loss corresponding to the initial reconstruction network is used to train and adjust the initial reconstruction network until the initial feature extraction is obtained When the final loss corresponding to the network is less than the corresponding preset loss threshold, and the final loss corresponding to the initial reconstruction network is less than the corresponding preset loss threshold, the feature extraction network and the reconstruction network are obtained, so that the feature extraction network and reconstruction network are obtained. A detection network composed of a structural network. In some embodiments, the electronic device may also train the initial feature extraction network and the initial reconstruction network separately, and the training method is the same as the above-mentioned method.
在一些实施例中,在上述S101之后,还可以执行S201-S203;图10是本公开实施例提供的异常检测方法的一个可选的流程示意图,将结合图10示出的步骤进行说明。In some embodiments, after the above S101, S201-S203 may also be executed; FIG. 10 is an optional flowchart of the anomaly detection method provided by the embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 10 .
S201、采用检测网络对每张待检测图像进行异常检测,得到每张待检测图像的每个像素位置上的异常评分。S201. Use a detection network to perform anomaly detection on each image to be detected, and obtain an anomaly score at each pixel position of each image to be detected.
本公开实施例中,对于每张待检测图像,电子设备可以采用检测网络对该张待检测图像进行不同尺度的特征处理,得到多尺度特征序列,并对得到的多尺度特征序列和预设问询词序列进行重构,得到重构特征序列,并根据重构特征序列与得到的多尺度特征序列,确定出该张待检测图像的每个像素位置上的特征差异,根据该特征差异,确定出该张待检测图像的每个像素位置上的异常评分。In the embodiment of the present disclosure, for each image to be detected, the electronic device can use the detection network to perform feature processing on the image to be detected at different scales to obtain a multi-scale feature sequence, and to obtain multi-scale feature sequences and preset questions. The query word sequence is reconstructed to obtain the reconstructed feature sequence, and according to the reconstructed feature sequence and the obtained multi-scale feature sequence, the feature difference at each pixel position of the image to be detected is determined, and according to the feature difference, determine The anomaly score of each pixel position of the image to be detected is obtained.
S202、基于异常评分,绘制每张待检测图像对应的异常检测图像。S202. Draw an abnormality detection image corresponding to each image to be detected based on the abnormality score.
S203、根据异常检测图像,得到多张待检测图像中的正常图像集和异常图像集。S203. Obtain a normal image set and an abnormal image set among the plurality of images to be detected according to the abnormality detection image.
本公开实施例中,对于每张待检测图像,电子设备可以根据该张待检测图像的每个像素位置上的异常评分,以及预设评分阈值,绘制与该张待检测图像对应的异常检测图像,并根据对应的异常检测图像确定该张待检测图像是否为异常图像或正常图像;通过此方式,电子设备可以将多张检测过的待检测图像划分为正常图像集和异常图像集,从而得到包含至少一张正常图像的正常图像集,以及包含至少一张异常图像的异常图像集。In the embodiment of the present disclosure, for each image to be detected, the electronic device can draw an abnormality detection image corresponding to the image to be detected according to the abnormality score at each pixel position of the image to be detected and the preset scoring threshold , and determine whether the image to be detected is an abnormal image or a normal image according to the corresponding abnormal detection image; in this way, the electronic device can divide multiple detected images to be detected into a normal image set and an abnormal image set, thus obtaining A normal image set contains at least one normal image, and an abnormal image set contains at least one abnormal image.
在本公开的一些实施例中,电子设备可以在每张待检测图像对应的异常检测图像表征,该张待检测图像为异常图像的情况下,将该张待检测图像作为异常图像,并在遍历多张待检测图像后,得到包含至少一张异常图像的异常图像集;以及,在每张待检测图像对应的异常检测图像表征,该张待检测图像为正常图像的情况下,将该张待检测图像作为正常图像,并在遍历多张待检测图像后,得到包含至少一张正常图像的正常图像集;通过此方式可以得到异常图像集和正常图像集。In some embodiments of the present disclosure, the electronic device may take the image to be detected as an abnormal image when the abnormality detection image corresponding to each image to be detected is represented as an abnormal image, and traverse After a plurality of images to be detected, an abnormal image set containing at least one abnormal image is obtained; The detected image is used as a normal image, and after traversing through multiple images to be detected, a normal image set containing at least one normal image is obtained; in this way, an abnormal image set and a normal image set can be obtained.
在本公开的一些实施例中,电子设备可以在已检测过的待检测图像的数量达到预设数量的情况下,停止对待检测图像的检测,并根据已检测过的多张待检测图像中每张待检测图像所对应的异常检测图像,将多张待检测图像划分为正常图像集和异常图像集;如此,可以获得足够数量的正常图像和异常图像,有利于后续得到检测精度更高的更新后的检测网络。在本公开的一些实施例中,电子设备还可以在得到的异常图像集中的异常图像的数量达到预设数量的情况下,或者,在得到的正常图像集中的正常图像的数量达到预设数量的情况下,停止对待检测图像的检测,并根据已检测过的多张待检测图像中每张待检测图像所对应的异常检测图像,将多张待检测图像划分为正常图像集和异常图像集;如此,可以获得足够数量的异常图像和正常图像,有利于后续得到检测精度更高的更新后的检测网络。In some embodiments of the present disclosure, the electronic device may stop detecting the image to be detected when the number of detected images to be detected reaches a preset number, and according to each detected image to be detected Anomaly detection images corresponding to the images to be detected, divide multiple images to be detected into normal image sets and abnormal image sets; in this way, a sufficient number of normal images and abnormal images can be obtained, which is conducive to subsequent updates with higher detection accuracy After the detection network. In some embodiments of the present disclosure, the electronic device may also, when the number of abnormal images in the obtained abnormal image set reaches a preset number, or when the number of normal images in the obtained normal image set reaches a preset number In the case, stop the detection of the image to be detected, and divide the multiple images to be detected into a normal image set and an abnormal image set according to the abnormal detection image corresponding to each image to be detected in the multiple images to be detected that have been detected; In this way, a sufficient number of abnormal images and normal images can be obtained, which is conducive to obtaining an updated detection network with higher detection accuracy.
在本公开的一些实施例中,电子设备还可以在得到的异常图像集中,对应的第一最大异常评分属于预设异常阈值的第一预设数值范围内的异常图像(以下称为异常可疑图像)的数量达到预设数量的情况下(每个异常图像对应的第一最大异常评分为:该异常图像中所有像素的异常评分中最大的异常评分),或者,在得到的正常图像集中,对应的第二最大异常评分属于预设异常阈值的第二预设数值范围内的正常图像(以下称为正常可疑图像)的数量达到预设数量的情况下(每个正常图像对应的第二最大异常评分为:该正常图像中所有像素的异常评分中最大的异常评分),停止对待检测图像的检测,并根据已检测过的多张待检测图像中每张待检测图像所对应的异常检测图像,将多张待检测图像划分为正常图像集和异常图像集;如此,可以得到足够数量的正常可疑图像或异常可疑图像,有利于后续得到检测精度更高的更新后的检测网络。需要说明的是,预设异常阈值的第一预设数值范围和预设异常阈值的第二预设数值范围,均是由接近预设异常阈值的数值组成的范围,可以根据实际需要设定。本公开的一些实施例中,异常图像对应的第一最大异常评分通常低于预设异常阈值,正常图像对应的第二最大异常评分通常高于预设异常阈值,例如,在预设异常阈值为5的情况下,第一预设数值范围可以为[4.5,5),第二预设数值范围可以为(5,5.5]。In some embodiments of the present disclosure, the electronic device may also, in the obtained abnormal image set, the abnormal images corresponding to the first maximum abnormal score belonging to the first preset value range of the preset abnormal threshold (hereinafter referred to as abnormal suspicious images ) reaches the preset number (the first maximum abnormal score corresponding to each abnormal image is: the maximum abnormal score among the abnormal scores of all pixels in the abnormal image), or, in the obtained normal image set, the corresponding When the number of normal images (hereinafter referred to as normal suspicious images) whose second maximum abnormality score belongs to the second preset value range of the preset abnormality threshold reaches the preset number (the second maximum abnormality corresponding to each normal image The score is: the maximum abnormal score in the abnormal scores of all pixels in the normal image), stop the detection of the image to be detected, and according to the abnormal detection image corresponding to each image to be detected in the multiple images to be detected that have been detected, Divide multiple images to be detected into a normal image set and an abnormal image set; in this way, a sufficient number of normal suspicious images or abnormal suspicious images can be obtained, which is conducive to obtaining an updated detection network with higher detection accuracy. It should be noted that the first preset numerical range of the preset abnormal threshold and the second preset numerical range of the preset abnormal threshold are ranges composed of values close to the preset abnormal threshold, which can be set according to actual needs. In some embodiments of the present disclosure, the first maximum abnormality score corresponding to the abnormal image is usually lower than the preset abnormality threshold, and the second maximum abnormality score corresponding to the normal image is usually higher than the preset abnormality threshold, for example, when the preset abnormality threshold is In the case of 5, the first preset value range may be [4.5,5), and the second preset value range may be (5,5.5].
在本公开的一些实施例中,电子设备还可以在得到的异常图像集中,异常可疑图像的数量达到预设数量的情况下;并且,在得到的正常图像集中,正常可疑图像的数量达到预设数量的情况下,停止对待检测图像的检测,并根据已检测过的多张待检测图像中每张待检测图像所对应的异常检测图像,将多张待检测图像划分为正常图像集和异常图像集;如此,可以得到足够数量的正常可疑图像与异常可疑图像,有利于后续得到检测精度更高的更新后的检测网络。In some embodiments of the present disclosure, the electronic device may also obtain a preset number of abnormal images in the set of abnormal images; and, in the obtained set of normal images, the number of normal suspicious images reaches a preset number In the case of a large number, stop the detection of the image to be detected, and divide the multiple images to be detected into a normal image set and an abnormal image according to the abnormal detection image corresponding to each image to be detected in the multiple images to be detected that have been detected In this way, a sufficient number of normal suspicious images and abnormal suspicious images can be obtained, which is conducive to obtaining an updated detection network with higher detection accuracy.
在一些实施例中,对于上述S102中的基于检测出的正常图像集和异常图像集,得到第二样本集,可以通过S1021-S1022实现。In some embodiments, obtaining the second sample set based on the detected normal image set and abnormal image set in S102 above may be implemented through S1021-S1022.
S1021、从检测出的正常图像集和异常图像集中,确定待核验图像。S1021. Determine images to be verified from the detected normal image set and abnormal image set.
S1022、对待核验图像进行核验,得到第二样本集。S1022. Perform verification on the image to be verified to obtain a second sample set.
本公开实施例中,电子设备可以根据得到的正常图像集和异常图像集中包含的所有正常图像和异常图像,确定出待核验图像进行核验,并根据核验结果得到由正样本和负样本组成的第二样本集。In the embodiment of the present disclosure, the electronic device can determine the image to be verified according to all normal images and abnormal images contained in the obtained normal image set and abnormal image set, and obtain the first positive sample and negative sample according to the verification result. Two sample sets.
本公开实施例中,电子设备可以对待核验图像进行自动核验,或者,也可以根据接收到的用户的核验操作,对待核验图像进行核验,本公开实施例对此不作限定。In the embodiment of the present disclosure, the electronic device may automatically verify the image to be verified, or may verify the image to be verified according to the received verification operation of the user, which is not limited in the embodiment of the present disclosure.
在一些实施例中,电子设备可以将正常图像集和异常图像集中包含的所有正常图像和异常图像,均作为待核验图像进行核验。In some embodiments, the electronic device may use all normal images and abnormal images included in the normal image set and the abnormal image set as images to be verified for verification.
在一些实施例中,电子设备也可以从正常图像集和异常图像集中选出部分正常图像和部分异常图像,作为待核验图像进行核验。示例性地,上述S1022可以采用S301-S304实现:In some embodiments, the electronic device may also select some normal images and some abnormal images from the normal image set and the abnormal image set as images to be verified for verification. Exemplarily, the above S1022 can be implemented by using S301-S304:
S301、从异常图像集中的每个异常图像中,确定每个像素位置上的异常评分中最大的第一最大异常评分。S301. From each abnormal image in the abnormal image set, determine the first maximum abnormal score among the abnormal scores at each pixel position.
电子设备在得到异常图像集的情况下,对于异常图像集中的每一张异常图像,可以从该张异常图像中所有像素的异常评分中,确定出一个最大的异常评分作为第一最大异常评分。When the electronic device obtains the abnormal image set, for each abnormal image in the abnormal image set, it can determine a maximum abnormal score from the abnormal scores of all pixels in the abnormal image as the first maximum abnormal score.
S302、从正常图像集中的每个正常图像中,确定每个像素位置上的异常评分中最大的第二最大异常评分。S302. From each normal image in the normal image set, determine the second largest abnormality score among the abnormality scores at each pixel position.
电子设备在得到正常图像集的情况下,对于正常图像集中的每一张正常图像,可以从该张正常图像中所有像素的异常评分中,确定出一个最大的异常评分作为第二最大异常评分。When the electronic device obtains the normal image set, for each normal image in the normal image set, it can determine a maximum abnormality score as the second maximum abnormality score from the abnormality scores of all pixels in the normal image.
S303、在第一最大异常评分属于预设异常阈值的第一预设数值范围的情况下,确定第一最大异常评分对应的异常图像属于待核验图像。S303. When the first maximum abnormality score belongs to the first preset value range of the preset abnormality threshold, determine that the abnormal image corresponding to the first maximum abnormality score belongs to the image to be verified.
对于一张异常图像,电子设备在选出第一最大异常评分的情况下,可以确定选出的第一最大异常评分是否在预设异常阈值的第一预设数值范围内,并在选出的第一最大异常评分在预设异常阈值的第一预设数值范围内的情况下,将该张异常图像作为待核验图像。For an abnormal image, when the electronic device selects the first maximum abnormal score, it can determine whether the selected first maximum abnormal score is within the first preset value range of the preset abnormal threshold, and within the selected If the first maximum abnormality score is within the first preset value range of the preset abnormality threshold, the abnormal image is used as the image to be verified.
本公开的一些实施例中,预设异常阈值的第一预设数值范围是由接近预设异常阈值的数值组成的范围,可以根据实际需要设定,本公开实施例对此不作限定。本公开的一些实施例中,异常图像对应的第一最大异常评分通常低于预设异常阈值,例如,在预设异常阈值为5的情况下,第一预设数值范围可以为[4.5,5);则在从一张异常图像B的所有像素的异常评分中,确定出的第一最大异常评分为4.5的情况下,说明异常图像B对应的第一最大异常评分属于第一预设数值范围[4.5,5),则可将异常图像B作为待核验图像。In some embodiments of the present disclosure, the first preset numerical range of the preset abnormal threshold is a range consisting of values close to the preset abnormal threshold, which can be set according to actual needs, which is not limited in the embodiments of the present disclosure. In some embodiments of the present disclosure, the first maximum abnormality score corresponding to the abnormal image is usually lower than the preset abnormality threshold. For example, when the preset abnormality threshold is 5, the first preset value range may be [4.5,5 ); then in the case where the first maximum abnormal score determined from the abnormal scores of all pixels of an abnormal image B is 4.5, it means that the first maximum abnormal score corresponding to the abnormal image B belongs to the first preset value range [4.5,5), then the abnormal image B can be used as the image to be verified.
S304、在第二最大异常评分属于预设异常阈值的第二预设数值范围的情况下,确定第二最大异常评分对应的正常图像属于待核验图像。S304. When the second maximum abnormality score belongs to the second preset value range of the preset abnormality threshold, determine that the normal image corresponding to the second maximum abnormality score belongs to the image to be verified.
电子设备在得到正常图像集合的情况下,对于正常图像集合中的每一张正常图像,可以从该张正常图像中所有像素的异常评分中,确定出一个最大的异常评分作为第二最大异常评分,并确定选出的第二最大异常评分是否在预设异常阈值的第二预设数值范围内,并在选出的第二最大异常评分在预设异常阈值的第二预设数值范围内的情况下,将该张正常图像作为待核验图像。When the electronic device obtains a normal image set, for each normal image in the normal image set, it can determine a maximum abnormal score from the abnormal scores of all pixels in the normal image as the second maximum abnormal score , and determine whether the selected second maximum abnormal score is within the second preset numerical range of the preset abnormal threshold, and if the selected second maximum abnormal score is within the second preset numerical range of the preset abnormal threshold In this case, the normal image is used as the image to be verified.
本公开的一些实施例中,预设异常阈值的第二预设数值范围也是由接近预设异常阈值的数值组成的范围,可以根据实际需要设定。本公开的一些实施例中,正常图像对应的第二最大异常评分通常高于预设异常阈值,例如,在预设异常阈值为5的情况下,第二预设数值范围可以为(5,5.5];则在从一张正常图像C的所有像素的异常评分中,确定出的第二最大异常评分为5.1的情况下,说明正常图像C对应的第二最大异常评分属于第二预设数值范围(5,5.5],则可将正常图像C作为待核验图像。In some embodiments of the present disclosure, the second preset numerical range of the preset abnormal threshold is also a range consisting of values close to the preset abnormal threshold, which can be set according to actual needs. In some embodiments of the present disclosure, the second maximum abnormality score corresponding to a normal image is usually higher than the preset abnormality threshold. For example, when the preset abnormality threshold is 5, the second preset value range may be (5,5.5 ]; then in the case that the second maximum abnormality score determined from the abnormality scores of all pixels of a normal image C is 5.1, it means that the second maximum abnormality score corresponding to the normal image C belongs to the second preset value range (5,5.5], the normal image C can be used as the image to be verified.
在一些实施例中,上述S1022可以通过S401-S404实现;图11是本公开实施例提供的异常检测方法的一个可选的流程示意图,将结合图11示出的步骤进行说明。In some embodiments, the above S1022 may be implemented through S401-S404; FIG. 11 is an optional schematic flow chart of the anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 11 .
S401、对至少一张异常图像和至少一张正常图像分别进行核验,得到各自的核验结果;待核验图像中包括:至少一张异常图像和至少一张正常图像。S401. Perform verification on at least one abnormal image and at least one normal image respectively to obtain respective verification results; the images to be verified include: at least one abnormal image and at least one normal image.
本公开实施例中,电子设备可以对异常图像集和正常图像集中的每张图像进行核验,以确定该张图像的异常检测结果是否正确,并得到该张图像的核验结果,且该核验结果表征该张图像的检测结果正确或错误。In the embodiment of the present disclosure, the electronic device can verify each image in the abnormal image set and the normal image set to determine whether the abnormality detection result of the image is correct, and obtain the verification result of the image, and the verification result represents The detection result of this image is correct or incorrect.
S402、将核验结果表征正确的异常图像作为负样本,并将核验结果表征正确的正常图像作为正样本。S402. Use the abnormal image whose verification result represents correctly as a negative sample, and use the normal image whose verification result represents correctly as a positive sample.
本公开实施例中,对于核验结果正确的异常图像,电子设备为该异常图像设置表征该异常图像为负样本的标注信息,得到负样本;对于核验结果正确的正常图像,电子设备为该正常图像设置表征该正常图像为正样本的标注信息,得到正样本,以用于后续对检测网络进行更新训练。In the embodiment of the present disclosure, for an abnormal image with a correct verification result, the electronic device sets labeling information for the abnormal image to indicate that the abnormal image is a negative sample, and obtains a negative sample; for a normal image with a correct verification result, the electronic device sets the normal image Set the label information that characterizes the normal image as a positive sample, and obtain a positive sample for subsequent update training of the detection network.
S403、对核验结果表征错误的异常图像,以及核验结果表征错误的正常图像进行正确标注,得到正样本和负样本。S403. Correctly annotate the abnormal images with wrong representations of the verification results and the normal images with wrong representations of the verification results to obtain positive samples and negative samples.
本公开实施例中,对于核验结果错误的异常图像,电子设备会判断该异常图像是否为异常图像或正常图像,并根据判断结果对该异常图像进行正确的标注信息的标注;以及,对于核验结果错误的正常图像,电子设备会判断该正常图像是否为异常图像或正常图像,并根据判断结果对该正常图像进行正确的标注信息的标注;在对所有核验结果错误的异常图像,以及所有核验结果错误的正常图像均进行正确标注之后,电子设备可以根据正确标注的标注信息,得到正样本和负样本。In the embodiment of the present disclosure, for an abnormal image with an incorrect verification result, the electronic device will judge whether the abnormal image is an abnormal image or a normal image, and mark the abnormal image with correct annotation information according to the judgment result; and, for the verification result For wrong normal images, the electronic device will judge whether the normal images are abnormal images or normal images, and mark the normal images with correct labeling information according to the judgment results; for all abnormal images with wrong verification results, and all verification results After the wrong normal images are correctly labeled, the electronic device can obtain positive samples and negative samples according to the correctly labeled label information.
S404、将负样本和正样本的集合,确定为第二样本集。S404. Determine a set of negative samples and positive samples as a second sample set.
本公开实施例中,电子设备可以将得到的所有负样本和正样本,作为第二样本集,以用于对检测网络进行更新训练。In the embodiment of the present disclosure, the electronic device may use all the obtained negative samples and positive samples as the second sample set for updating and training the detection network.
在一些实施例中,上述S103可以通过S1031-S1033实现;图12是本公开实施例提供的异常检测方法的一个可选的流程示意图,将结合图12示出的步骤进行说明。In some embodiments, the above S103 may be implemented through S1031-S1033; FIG. 12 is an optional schematic flow chart of the anomaly detection method provided by an embodiment of the present disclosure, which will be described in conjunction with the steps shown in FIG. 12 .
S1031、在采用第二样本集中的正样本,对检测网络进行训练的情况下,采用检测网络得到正样本对应的第一特征差异序列,并根据第一特征差异序列和正常损失函数,确定出正样本对应的第一训练损失;正常损失函数表征正样本对应的重构特征序列拉近正样本。S1031. In the case of using the positive samples in the second sample set to train the detection network, use the detection network to obtain the first feature difference sequence corresponding to the positive sample, and determine the positive The first training loss corresponding to the sample; the normal loss function represents that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample.
本公开实施例中,电子设备可以在采用第二样本集中的正样本,对检测网络进行训练的情况下,可以通过上述图6中的方法对当前获取的正样本进行特征处理与重构,以及采用上述公式(2)进行特征差异度计算等处理,得到正样本对应的第一特征差异或第一特征差异序列,进而采用正常损失函数计算出正样本对应的第一训练损失,以用于对检测网络进行网络参数的调整。需要说明的是,S1031的过程与上述S1011-S1012部分的内容相同。In the embodiment of the present disclosure, when the electronic device uses the positive samples in the second sample set to train the detection network, it can perform feature processing and reconstruction on the currently acquired positive samples through the method in FIG. 6 above, and Use the above formula (2) to calculate the degree of feature difference and other processing to obtain the first feature difference or the first feature difference sequence corresponding to the positive sample, and then use the normal loss function to calculate the first training loss corresponding to the positive sample, which is used for Detect the network to adjust the network parameters. It should be noted that the process of S1031 is the same as the content of the above S1011-S1012.
S1032、在采用第二样本集中的负样本,对检测网络进行训练的情况下,采用检测网络得到负样本对应的第二特征差异序列,并根据第二特征差异序列、预设的负样本的真实值和异常损失函数,确定出负样本对应的第二训练损失。S1032. In the case of using the negative samples in the second sample set to train the detection network, use the detection network to obtain the second feature difference sequence corresponding to the negative sample, and according to the second feature difference sequence and the true value of the preset negative sample value and the abnormal loss function to determine the second training loss corresponding to the negative sample.
本公开实施例中,电子设备可以在采用第二样本集中的负样本,对检测网络进行训练的情况下,可以从第二样本集中获取负样本,以及,负样本对应的预设的负样本的真实值。示例性地,预设的负样本的真实值可以是像素级标签或图像级标签形式的标注信息,其中,像素级标签可以是针对负样本中每个像素的标注信息,用于标注每个像素为正常像素或异常像素;图像级标签可以是针对整个图像的标注信息,用于标注整个图像中是否存在异常。示例性地,包含部分异常像素的图像所对应的图像级标签可以是表征整张图像异常的标签。In the embodiment of the present disclosure, when the electronic device uses the negative samples in the second sample set to train the detection network, it can obtain negative samples from the second sample set, and the preset negative samples corresponding to the negative samples actual value. Exemplarily, the real value of the preset negative sample may be annotation information in the form of a pixel-level label or an image-level label, wherein the pixel-level label may be annotation information for each pixel in the negative sample, and is used to label each pixel It is a normal pixel or an abnormal pixel; the image-level label can be annotation information for the entire image, and is used to mark whether there is an abnormality in the entire image. Exemplarily, the image-level label corresponding to the image containing some abnormal pixels may be a label representing the abnormality of the entire image.
本公开实施中,电子设备可以通过上述图6中的方法对负样本进行特征处理与重构,以及采用上述公式(2)进行差异度计算等处理,得到负样本对应的第二特征差异或第二特征差异序列;进而,电子设备通过异常损失函数,计算第二特征差异或第二特征差异序列与预设的负样本的真实值之间的差异,得到负样本对应的第二训练损失,以用于对检测网络进行网络参数的调整。In the implementation of the present disclosure, the electronic device can perform feature processing and reconstruction on the negative samples through the above-mentioned method in FIG. Two feature difference sequences; furthermore, the electronic device calculates the difference between the second feature difference or the second feature difference sequence and the real value of the preset negative sample through the abnormal loss function, and obtains the second training loss corresponding to the negative sample, so that It is used to adjust the network parameters of the detection network.
S1033、基于第一训练损失和第二训练损失,分别对检测网络进行训练调整,直至得到的最终损失小于预设损失阈值时,得到更新后的检测网络;其中,异常损失函数表征负样本中的异常部分对应的重构特征序列推离异常部分,以及负样本中的正常部分对应的重构特征序列拉近正常部分。S1033. Based on the first training loss and the second training loss, respectively train and adjust the detection network until the obtained final loss is less than the preset loss threshold, and obtain an updated detection network; wherein, the abnormal loss function represents the negative sample The reconstructed feature sequence corresponding to the abnormal part is pushed away from the abnormal part, and the reconstructed feature sequence corresponding to the normal part in the negative sample is pulled closer to the normal part.
本公开实施例中,电子设备基于正样本对应的第一训练损失或负样本对应的第二训练损失,对检测网络进行网络参数的调整,完成当前轮使用正样本或负样本的训练过程。之后,电子设备可以继续使用增量样本中的正样本与负样本,对检测网络进行迭代训练,直至满足预设训练条件的情况下,如最终损失小于预设损失阈值的情况下,得到更新后的检测网络。In the embodiment of the present disclosure, the electronic device adjusts the network parameters of the detection network based on the first training loss corresponding to the positive samples or the second training loss corresponding to the negative samples, and completes the training process of using positive samples or negative samples in the current round. Afterwards, the electronic device can continue to use the positive samples and negative samples in the incremental samples to iteratively train the detection network until the preset training conditions are met, such as when the final loss is less than the preset loss threshold, the updated detection network.
需要说明的是,本公开实施例中,如上述S1013部分所述,检测网络可以由预先训练好的特征提取网络,以及重构网络组成,电子设备可以只对重构网络进行训练,得到由预先好的训练特征提取网络和更新后的重构网络组成的更新后的检测网络;以及,检测网络也可以由特征提取网络和重构网络组成,电子设备可以通过对特征提取网络和重构网络同时进行训练,或者,对特征提取网络和重构网络分别进行训练,得到由更新后的特征提取网络和更新后的重构网络组成的更新后的检测网络。电子设备采用第二样本集对检测网络进行训练的过程,与上述S1013部分的过程相同,不同之处仅在于所采用的样本不同,以及得到的样本所对应的训练损失不同。It should be noted that, in the embodiment of the present disclosure, as described in the above-mentioned part S1013, the detection network may be composed of a pre-trained feature extraction network and a reconstruction network, and the electronic device may only train the reconstruction network to obtain the pre-trained An updated detection network composed of a well-trained feature extraction network and an updated reconstruction network; and, the detection network can also be composed of a feature extraction network and a reconstruction network, and the electronic device can simultaneously use the feature extraction network and the reconstruction network Training is performed, or the feature extraction network and the reconstruction network are trained separately to obtain an updated detection network composed of an updated feature extraction network and an updated reconstruction network. The process of the electronic device using the second sample set to train the detection network is the same as the process of the above S1013, the only difference is that the samples used are different, and the training losses corresponding to the obtained samples are different.
在一些实施例中,对于不同类型的预设的负样本的真实值,如像素级标签或图像级标签,电子设备可以通过不同的异常损失函数来计算负样本对应的第二训练损失。需要说明的是,对于不同类型的预设的负样本的真实值,异常损失函数需要符合的总体特性为:表征负样本中的异常部分对应的重构特征序列推离异常部分,以及负样本中的正常部分对应的重构特征序列拉近正常部分。In some embodiments, for different types of real values of preset negative samples, such as pixel-level labels or image-level labels, the electronic device may use different abnormal loss functions to calculate the second training loss corresponding to the negative samples. It should be noted that, for the real values of different types of preset negative samples, the overall characteristics that the abnormal loss function needs to meet are: the reconstructed feature sequence corresponding to the abnormal part in the negative sample is pushed away from the abnormal part, and the negative sample The reconstructed feature sequence corresponding to the normal part of is closer to the normal part.
在一些实施例中,预设的负样本的真实值包括:像素级的真实值,即像素级标签;异常损失函数包括:像素级损失函数。电子设备基于负样本的第二特征差异序列、预设的负样本的真实值和异常损失函数,对检测网络进行训练调整,直至得到最终损失小于预设损失阈值的更新后的检测网络的过程可以包括:In some embodiments, the preset real value of the negative sample includes: a pixel-level real value, that is, a pixel-level label; the abnormal loss function includes: a pixel-level loss function. The electronic device trains and adjusts the detection network based on the second feature difference sequence of the negative sample, the preset real value of the negative sample, and the abnormal loss function until an updated detection network whose final loss is less than the preset loss threshold can be obtained. include:
1)对负样本的第二特征差异序列进行通道维度的标量化处理,得到每个像素位置上的特征差异度量。这里,在负样本的真实值为预设的像素级的真实值的情况下,以通过第二特征差异序列进行异常损失函数的计算为例,电子设备可以将第二特征差异序列中,表征每个像素位置上的特征差异向量转换为通道维度的标量,使得每个像素位置只对应一个标量的特征差异度量;2)基于特征差异度量、像素级的真实值和像素级损失函数,对检测网络进行训练调整,直至得到最终损失小于预设损失阈值的更新后的检测网络。1) Carry out scalarization processing of the channel dimension on the second feature difference sequence of the negative sample, and obtain the feature difference measure at each pixel position. Here, in the case where the actual value of the negative sample is the preset pixel-level actual value, taking the calculation of the abnormal loss function through the second feature difference sequence as an example, the electronic device can use the second feature difference sequence to represent each The feature difference vector at each pixel position is converted into a scalar in the channel dimension, so that each pixel position corresponds to only one scalar feature difference measure; 2) Based on the feature difference measure, pixel-level real value and pixel-level loss function, the detection network Perform training adjustments until an updated detection network with a final loss smaller than a preset loss threshold is obtained.
在一些实施例中,像素级损失函数为具有上述“拉近-推离”特性的损失函数,其设计目标可以为:利用像素级损失函数,将负样本中的正常像素点对应位置上的特征差异度量减小,以拉近正常像素点的重构特征与原始特征,如多尺度特征之间的距离;同时,将负样本中的异常像素点对应位置上的特征差异度量增大,即推远异常像素点的重构特征与原始特征之间的距离。In some embodiments, the pixel-level loss function is a loss function with the above-mentioned "pull-in-pull-away" characteristic, and its design goal can be: using the pixel-level loss function, the normal pixel in the negative sample corresponds to the feature The difference measure is reduced to shorten the distance between the reconstructed features of the normal pixels and the original features, such as multi-scale features; at the same time, the feature difference measure at the corresponding position of the abnormal pixels in the negative sample is increased, that is, pushing The distance between the reconstructed feature of the far outlier pixel and the original feature.
在一些实施例中,像素级损失函数包括:正常像素损失部分和异常像素损失部分。在一个负样本对应的像素级的真实值表征像素点为正常像素点的情况下,电子设备可以基于正常像素损失部分,对正常像素点的特征差异度量进行加权平均,得到正常像素点损失;在一个负样本对应的像素级的真实值表征像素点为异常像素点的情况下,电子设备可以基于异常像素损失部分,对异常像素点的特征差异度量进行加权平均,得到异常像素点损失。其中,正常像素点损失与正常像素点的特征差异度量成正相关,异常像素点损失与异常像素点的特征差异度量成负相关,从而达到拉近正常像素点的重构特征与原始特征之间的距离,以及推远异常像素点的重构特征与原始特征之间的距离的效果。In some embodiments, the pixel-level loss function includes: a normal pixel loss part and an abnormal pixel loss part. In the case that the pixel-level true value corresponding to a negative sample indicates that the pixel is a normal pixel, the electronic device can perform a weighted average on the feature difference measure of the normal pixel based on the normal pixel loss part to obtain the normal pixel loss; When the pixel-level real value corresponding to a negative sample indicates that the pixel is an abnormal pixel, the electronic device can perform a weighted average on the feature difference measure of the abnormal pixel based on the abnormal pixel loss part to obtain the abnormal pixel loss. Among them, the normal pixel loss is positively correlated with the feature difference measure of the normal pixel point, and the abnormal pixel point loss is negatively correlated with the feature difference measure of the abnormal pixel point, so as to achieve the reconstruction feature of the normal pixel point and the original feature. distance, and the effect of pushing away the distance between the reconstructed feature of the abnormal pixel and the original feature.
可以理解的是,电子设备可以通过像素级损失函数,来对检测网络针对像素级标签的负样本的重构能力进行评估,从而使得检测网络对正常像素点的重构特征接近原始特征,对异常像素点的重构特征远离原始特征,从而兼容对于像素级标签的负样本的训练,提高检测网络使用不同类型样本进行训练的灵活性和准确性,进而提高基于检测网络进行异常检测的灵活性与准确性。It is understandable that the electronic device can use the pixel-level loss function to evaluate the reconstruction ability of the detection network for negative samples of pixel-level labels, so that the reconstruction features of the detection network for normal pixels are close to the original features, and for abnormal The reconstructed features of pixels are far away from the original features, so that they are compatible with the training of negative samples of pixel-level labels, improve the flexibility and accuracy of the detection network using different types of samples for training, and then improve the flexibility and accuracy of anomaly detection based on the detection network. accuracy.
在本公开的一些实施例中,电子设备在对每个像素位置上的特征差异向量进行标量化的过程中,是同等地对不同特征通道对应的特征差异向量进行平均化处理的。实际应用中,不同的特征通道对于异常的贡献可能是不同的,因此,电子设备还可以通过分类网络,对每个特征通道对应的特征差异向量进行权重分析,以结合不同的权重进行像素级损失函数的计算,进一步提高准确性。在此种情况下,电子设备基于第二特征差异序列、预设的负样本的真实值和异常损失函数,对检测网络进行训练调整,直至得到最终损失小于预设损失阈值的更新后的检测网络的过程可以包括:In some embodiments of the present disclosure, in the process of scalarizing the feature difference vectors at each pixel position, the electronic device equally averages the feature difference vectors corresponding to different feature channels. In practical applications, different feature channels may contribute differently to abnormalities. Therefore, electronic devices can also perform weight analysis on the feature difference vector corresponding to each feature channel through the classification network to combine different weights for pixel-level loss. The calculation of the function further improves the accuracy. In this case, the electronic device trains and adjusts the detection network based on the second feature difference sequence, the preset true value of the negative sample, and the abnormal loss function until an updated detection network with a final loss less than the preset loss threshold is obtained The process can include:
3)采用分类网络,对第二特征差异序列进行像素位置的分类,得到每个像素位置上的样本分类概率;4)基于每个像素位置上的样本分类概率、像素级的真实值和分类损失函数,得到当前分类损失;5)基于特征差异度量、像素级的真实值和像素级损失函数,得到第一当前损失;6)基于当前分类损失和第一当前损失,对检测网络和分类网络进行训练调整,直至得到最终损失小于预设损失阈值的更新后的分类网络和更新后的检测网络。3) Use the classification network to classify the pixel positions of the second feature difference sequence, and obtain the sample classification probability at each pixel position; 4) Based on the sample classification probability at each pixel position, the pixel-level true value and the classification loss function to obtain the current classification loss; 5) based on the feature difference measure, the pixel-level real value and the pixel-level loss function, the first current loss is obtained; 6) based on the current classification loss and the first current loss, the detection network and the classification network are The training is adjusted until the updated classification network and the updated detection network with the final loss less than the preset loss threshold are obtained.
在一些实施例中,对于H×W×C维的第二特征差异d(u,i),第二特征差异中的每个特征差异向量可以通过C维的d(u)来表示,电子设备可以通过公式(4),对每个d(u)进行分类,得到每个d(u)属于异常或缺陷的概率,作为对应像素位置u上的样本分类概率,从而得到每个像素位置上的样本分类概率,如下:In some embodiments, for the second feature difference d(u,i) of H×W×C dimension, each feature difference vector in the second feature difference can be represented by d(u) of C dimension, the electronic device Each d(u) can be classified by formula (4), and the probability that each d(u) belongs to abnormality or defect can be obtained as the sample classification probability at the corresponding pixel position u, so as to obtain the The sample classification probability is as follows:
p(u)=C(d(u))                 (4)p(u)=C(d(u)) (4)
公式(4)中,p(u)为像素位置u上的样本分类概率。这样,对于每个C维的特征差异向量,电子设备可以利用分类网络,结合C维通道中各个特征通道对应的特征差异进行分类预测,得到每个像素位置上的样本分类概率。In formula (4), p(u) is the sample classification probability at pixel position u. In this way, for each C-dimensional feature difference vector, the electronic device can use the classification network to perform classification prediction in combination with the feature differences corresponding to each feature channel in the C-dimensional channel, and obtain the sample classification probability at each pixel position.
在一些实施例中,分类网络可以是FFN(Feed Forward Network),也可以是其他具有分类功能的网络模型,可根据实际情况进行选择,本公开实施例不作限定。In some embodiments, the classification network can be FFN (Feed Forward Network), or other network models with classification functions, which can be selected according to actual conditions, and are not limited in this embodiment of the present disclosure.
可以理解的是,通过引入分类网络对第二特征差异序列进行分类预测,可以结合每个特征差异向量中各个维度的差异向量得到每个像素位置上的样本分类概率,基于样本分类概率权重进行第一当前损失的计算,从而进一步提高使用第一当前损失对检测网络进行训练的准确性,进而提高使用更新后的检测网络进行异常检测的准确性。It can be understood that, by introducing a classification network to classify and predict the second feature difference sequence, the difference vectors of each dimension in each feature difference vector can be combined to obtain the sample classification probability at each pixel position, and the second is based on the sample classification probability weight. Calculation of the current loss, so as to further improve the accuracy of training the detection network using the first current loss, and further improve the accuracy of anomaly detection using the updated detection network.
在一些实施例中,预设的负样本的真实值包括:图像级的真实值,即图像级像素标签;异常损失函数包括:图像级损失函数。电子设备基于第二特征差异序列、预设的负样本的真实值和异常损失函数,对检测网络进行训练调整,直至得到最终损失小于预设损失阈值的更新后的检测网络的过程可以包括:In some embodiments, the preset real value of the negative sample includes: an image-level real value, that is, an image-level pixel label; and the abnormal loss function includes: an image-level loss function. The electronic device trains and adjusts the detection network based on the second feature difference sequence, the preset true value of the negative sample, and the abnormal loss function until an updated detection network whose final loss is less than the preset loss threshold can be obtained. The process may include:
7)对第二特征差异序列进行通道维度的标量化处理,得到每个像素位置上的特征差异度量;8)从每个像素位置上的特征差异度量中,确定数值最大的K个最大特征差异度量;K为大于1的正整数;9)对K个最大特征差异度量进行平均,得到特征平均差异度量;10)基于特征平均差异度量、图像级的真实值和图像级损失函数,对检测网络进行训练调整,直至得到最终损失小于预设损失阈值的更新后的检测网络。7) Carry out scalarization processing of the channel dimension on the second feature difference sequence to obtain the feature difference measure at each pixel position; 8) From the feature difference measure at each pixel position, determine the K largest feature differences with the largest value measure; K is a positive integer greater than 1; 9) Average the K largest feature difference measures to obtain the feature average difference measure; 10) Based on the feature average difference measure, image-level real value and image-level loss function, the detection network Perform training adjustments until an updated detection network with a final loss smaller than a preset loss threshold is obtained.
在一些实施例中,图像级损失函数包括:正常图像损失部分和异常图像损失部分。在一个负样本对应的图像级的真实值表征图像为正常图像的情况下,电子设备基于正常图像损失部分,将特征平均差异度量,确定为正常图像损失;在一个负样本对应的图像级的真实值表征图像为负图像的情况下,电子设备基于异常图像损失部分和特征平均差异度量,得到异常图像损失。其中,正常图像的特征平均差异度量与正常图像损失成正相关,异常图像的特征平均差异度量与异常图像损失成负相关。电子设备基于正常图像损失或异常图像损失,确定第二当前损失;基于第二当前损失和预设损失阈值,对检测网络进行训练调整,直至得到最终损失小于预设损失阈值的更新后的检测网络。In some embodiments, the image-level loss function includes: a normal image loss part and an abnormal image loss part. In the case that the image-level true value corresponding to a negative sample indicates that the image is a normal image, the electronic device measures the average difference of features based on the normal image loss part, and determines it as a normal image loss; the image-level true value corresponding to a negative sample When the value characterizes the image as a negative image, the electronic device obtains the abnormal image loss based on the abnormal image loss part and the feature average difference measure. Among them, the feature average difference measure of normal images is positively correlated with normal image loss, and the feature average difference measure of abnormal images is negatively correlated with abnormal image loss. The electronic device determines the second current loss based on the normal image loss or the abnormal image loss; based on the second current loss and the preset loss threshold, the detection network is trained and adjusted until an updated detection network whose final loss is less than the preset loss threshold is obtained .
在一些实施例中,图像级损失函数为具有上述“拉近-推离”特性的损失函数,其设计目标可以为:利用图像级损失函数,将正常图像对应的特征平均差异度量减小,以拉近正常图像的重构特征与原始特征之间的距离;同时,将异常图像对应的特征平均差异度量增大,即推远异常图像的重构特征与原始特征之间的距离。In some embodiments, the image-level loss function is a loss function with the above-mentioned "pull-in-pull-away" characteristic, and its design goal can be: use the image-level loss function to reduce the average difference measure of the features corresponding to the normal image, so as to The distance between the reconstructed features of the normal image and the original features is shortened; at the same time, the average difference measure of the features corresponding to the abnormal image is increased, that is, the distance between the reconstructed features of the abnormal image and the original features is pushed farther.
可以理解的是,电子设备可以通过图像级损失函数,来对检测网络针对图像级标签的负样本的重构能力进行评估,从而使得检测网络对正常图像的重构特征接近原始特征,对负样本的重构特征远离原始特征,从而兼容对于图像级标签的负样本的训练,提高更新后的检测网络使用不同类型样本进行训练的灵活性和准确性,进而提高基于更新后的检测网络进行异常检测的灵活性与准确性。It is understandable that the electronic device can evaluate the reconstruction ability of the detection network for negative samples of image-level labels through the image-level loss function, so that the reconstruction features of the detection network for normal images are close to the original features, and the negative samples The reconstructed features are far away from the original features, so that they are compatible with the training of negative samples of image-level labels, improve the flexibility and accuracy of the updated detection network using different types of samples for training, and then improve the anomaly detection based on the updated detection network. flexibility and accuracy.
在一些实施例中,在未使用分类网络训练得到检测网络或更新后的检测网络的情况下,电子设备计算每个像素位置上的异常评分的方法可以为:对每个像素位置上的特征差异进行通道平均,得到每个像素位置上的中间异常评分;将中间异常评分作为异常评分。In some embodiments, when the detection network or the updated detection network is obtained without using the classification network training, the method for the electronic device to calculate the abnormality score at each pixel position may be: the feature difference at each pixel position Perform channel averaging to obtain the intermediate anomaly score at each pixel location; use the intermediate anomaly score as the anomaly score.
在一些实施例中,电子设备可以对待检测图像或目标图像中每个像素位置上的特征差异进行通道平均,得到每个像素位置上的中间异常评分,并将中间异常评分作为异常评分, 如公式(5)所示,如下:In some embodiments, the electronic device can perform channel averaging on the feature difference at each pixel position in the image to be detected or the target image to obtain the intermediate abnormality score at each pixel position, and use the intermediate abnormality score as the abnormality score, as shown in the formula As shown in (5), as follows:
Figure PCTCN2022071448-appb-000011
Figure PCTCN2022071448-appb-000011
公式(5)中,d'(u,i)为每个像素位置上的特征差异,C为特征差异序列中每个特征差异对应的特征通道数,s(u)为通过对每个像素位置上的特征差异进行通道平均得到的中间异常评分,也即不包含分类网络的检测网络所输出的待检测图像或目标图像中各个像素位置上的异常评分。In formula (5), d'(u,i) is the feature difference at each pixel position, C is the number of feature channels corresponding to each feature difference in the feature difference sequence, and s(u) is the The intermediate anomaly score obtained by channel-averaging the feature differences on , that is, the anomaly score at each pixel position in the image to be detected or the target image output by the detection network that does not include the classification network.
在一些实施例中,在使用分类网络训练得到检测网络的情况下,电子设备计算每个像素位置上的异常评分的方法可以为:对每个像素位置上的特征差异进行通道平均,得到每个像素位置上的中间异常评分;采用分类网络,对每个像素位置上的特征差异进行像素位置上的分类,得到分类概率;将分类概率与中间异常评分进行相乘,得到每个像素位置上的异常评分。In some embodiments, in the case of using the classification network training to obtain the detection network, the method for the electronic device to calculate the abnormality score at each pixel position may be: perform channel averaging on the feature difference at each pixel position, and obtain each The intermediate anomaly score at the pixel position; the classification network is used to classify the feature difference at each pixel position at the pixel position to obtain the classification probability; the classification probability is multiplied by the intermediate anomaly score to obtain the Exception score.
在一些实施例中,电子设备将分类概率作为权重,与中间异常评分进行加权,得到每个像素位置上的异常评分。示例性地,如公式(6)所示:In some embodiments, the electronic device uses the classification probability as a weight to weight the intermediate anomaly score to obtain the anomaly score at each pixel position. Exemplarily, as shown in formula (6):
Figure PCTCN2022071448-appb-000012
Figure PCTCN2022071448-appb-000012
本公开实施例中,在采用正样本,得到训练好的检测网络的基础上,还采用包含负样本和正样本的增量样本对训练好的检测网络继续进行训练,直到得到训练好的更新后的检测网络,使得检测网络可以兼容正样本学习和增量的异常样本学习这两种学习方式,从而提高了检测网络的兼容性和灵活性。In the embodiment of the present disclosure, on the basis of using positive samples to obtain a trained detection network, incremental samples including negative samples and positive samples are also used to continue training the trained detection network until the trained updated The detection network makes the detection network compatible with the two learning methods of positive sample learning and incremental abnormal sample learning, thereby improving the compatibility and flexibility of the detection network.
图13是本公开实施例提供的得到更新后的检测网络的一个流程示意图,以下将结合图13,通过一个详细的实施例对本公开实施例的技术方案进行说明。FIG. 13 is a schematic flowchart of an updated detection network provided by an embodiment of the present disclosure. The technical solution of the embodiment of the present disclosure will be described below through a detailed embodiment with reference to FIG. 13 .
电子设备在冷启动阶段,通过预设的正样本集对初始检测网络进行持续训练,直到得到训练好的检测网络。在部署增量训练阶段,电子设备将生产线上生成的多张待检测图像作为产线数据集,输入在冷启动阶段训练好的检测网络中,并收集检测网络输出的每张待检测图像对应的异常检测图像,将异常检测图像作为收集的检测结果,并根据收集的检测结果确定出对应的待检测图像是否为正常图像或异常图像,从而将已检测的多张待检测图像划分为正常图像集和异常图像集,并将正常图像集作为正常样本,将异常图像集作为异常样本;之后,对正常样本和异常样本均进行核验,并得到核验后的带有标注信息的正常样本和异常样本,并将带有标注信息的正常样本(正样本)和带有标注信息的异常样本(负样本)共同作为增量数据集(增量样本集),采用增量数据集对冷启动阶段训练好的检测网络继续进行持续训练,直到得到训练好的更新后的检测网络,并采用更新后的检测网络更新冷启动阶段所得到的检测网络,从而采用更新后的检测网络继续对生产线上生成的图像进行检测。In the cold start phase of the electronic device, the initial detection network is continuously trained through the preset positive sample set until a trained detection network is obtained. In the deployment incremental training phase, the electronic device takes multiple images to be detected generated on the production line as production line data sets, input them into the detection network trained in the cold start phase, and collect the output corresponding to each image to be detected output by the detection network. Anomaly detection image, using the abnormal detection image as the collected detection result, and determining whether the corresponding image to be detected is a normal image or an abnormal image according to the collected detection result, so as to divide the detected multiple images to be detected into a normal image set and the abnormal image set, and the normal image set is used as a normal sample, and the abnormal image set is used as an abnormal sample; after that, both the normal sample and the abnormal sample are verified, and the verified normal sample and abnormal sample with label information are obtained, The normal samples (positive samples) with labeled information and the abnormal samples (negative samples) with labeled information are used together as the incremental data set (incremental sample set), and the incremental data set is used to train the cold start stage. The detection network continues to train continuously until the trained and updated detection network is obtained, and the detection network obtained in the cold start stage is updated with the updated detection network, so that the updated detection network is used to continue to process the images generated on the production line. detection.
本公开实施例提供的异常检测方法,可以应用于智能人工智能(Artificial Intelligence,AI)训练平台、异常检测和异常检测在线自动训练提升等方面。The anomaly detection method provided by the embodiments of the present disclosure can be applied to an intelligent artificial intelligence (AI) training platform, anomaly detection, online automatic training and improvement of anomaly detection, and the like.
本公开还提供一种检测装置,图14为本公开实施例提供的异常检测装置的结构示意图;如图14所示,异常检测装置500包括:第一训练部分501,被配置为采用第一样本集对初始检测网络进行训练,得到检测网络;所述第一样本集为正样本集;获取部分502,被配置为在所述检测网络对多张待检测图像进行异常检测过程中,基于检测出的正常图像集和异常图像集,得到第二样本集,所述第二样本集为包含正样本和负样本的增量样本集;其中,所述负样本为图像中存在异常的异常图像;第二训练部分503,被配置为采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络。。The present disclosure also provides a detection device. FIG. 14 is a schematic structural diagram of the abnormality detection device provided by the embodiment of the present disclosure; as shown in FIG. 14 , the abnormality detection device 500 includes: a first training part 501 configured to adopt the This episode trains the initial detection network to obtain a detection network; the first sample set is a positive sample set; the acquisition part 502 is configured to perform abnormal detection on multiple images to be detected by the detection network based on The detected normal image set and abnormal image set are used to obtain a second sample set, which is an incremental sample set including positive samples and negative samples; wherein, the negative sample is an abnormal image in which there is anomaly in the image ; The second training part 503 is configured to use the second sample set to perform update training on the detection network to obtain an updated detection network. .
在本公开的一些实施例中,所述第一训练部分501,还被配置为采用所述初始检测网 络对所述第一样本集中的正样本进行检测,得到所述正样本对应的第一特征差异序列;根据所述第一特征差异序列和正常损失函数,确定出所述正样本对应的训练损失;基于所述训练损失,对所述初始检测网络进行训练调整,直至得到的最终损失小于预设损失阈值时,得到所述检测网络;其中,所述正常损失函数表征所述正样本对应的重构特征序列拉近所述正样本。In some embodiments of the present disclosure, the first training part 501 is further configured to use the initial detection network to detect the positive samples in the first sample set, and obtain the first A feature difference sequence; according to the first feature difference sequence and a normal loss function, determine the training loss corresponding to the positive sample; based on the training loss, train and adjust the initial detection network until the final loss obtained is less than When the loss threshold is preset, the detection network is obtained; wherein, the normal loss function represents that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample.
在本公开的一些实施例中,所述获取部分502,还被配置为从检测出的所述正常图像集和所述异常图像集中,确定待核验图像;对所述待核验图像进行核验,得到所述第二样本集。In some embodiments of the present disclosure, the acquisition part 502 is further configured to determine an image to be verified from the detected normal image set and the abnormal image set; and verify the image to be verified to obtain The second sample set.
在本公开的一些实施例中,所述待核验图像中包括:至少一张异常图像和至少一张正常图像;所述获取部分502,还被配置为对所述至少一张异常图像和所述至少一张正常图像分别进行核验,得到各自的核验结果;将所述核验结果表征正确的异常图像作为所述负样本,并将所述核验结果表征正确的正常图像作为所述正样本;对所述核验结果表征错误的异常图像,以及所述核验结果表征错误的正常图像进行正确标注,得到所述正样本和所述负样本;将所述负样本和所述正样本的集合,确定为所述第二样本集。In some embodiments of the present disclosure, the image to be verified includes: at least one abnormal image and at least one normal image; At least one normal image is verified separately to obtain respective verification results; the abnormal image with the correct verification result is used as the negative sample, and the normal image with the correct verification result is used as the positive sample; Correctly annotate the abnormal image with the wrong character of the verification result and the normal image with the wrong character of the verification result to obtain the positive sample and the negative sample; determine the set of the negative sample and the positive sample as the set Describe the second sample set.
在本公开的一些实施例中,所述异常检测装置500还包括:检测部分;所述检测部分,还被配置为采用第一样本集对初始检测网络进行训练,得到检测网络之后,采用所述检测网络对每张待检测图像进行异常检测,得到所述每张待检测图像的每个像素位置上的异常评分;基于所述异常评分,绘制所述每张待检测图像对应的异常检测图像;所述获取部分502,还被配置为根据所述异常检测图像,得到多张待检测图像中的所述正常图像集和所述异常图像集。In some embodiments of the present disclosure, the abnormality detection device 500 further includes: a detection part; the detection part is further configured to use the first sample set to train the initial detection network, and after obtaining the detection network, use the The detection network performs anomaly detection on each image to be detected, and obtains an abnormality score on each pixel position of each image to be detected; based on the anomaly score, draws an abnormality detection image corresponding to each image to be detected ; The acquiring part 502 is further configured to obtain the normal image set and the abnormal image set among the plurality of images to be detected according to the abnormality detection image.
在本公开的一些实施例中,所述获取部分502,还被配置为在所述每张待检测图像对应的异常检测图像表征,所述每张待检测图像为异常图像的情况下,将所述每张待检测图像作为异常图像,在遍历所述多张待检测图像后,得到包含至少一张异常图像的所述异常图像集;在所述每张待检测图像对应的异常检测图像表征,所述每张待检测图像为正常图像的情况下,将所述每张待检测图像作为正常图像,在遍历所述多张待检测图像后,得到包含至少一张正常图像的所述正常图像集。In some embodiments of the present disclosure, the acquisition part 502 is further configured to, when the abnormality detection image representation corresponding to each image to be detected, and each image to be detected is an abnormal image, the Each image to be detected is used as an abnormal image, and after traversing the multiple images to be detected, the abnormal image set including at least one abnormal image is obtained; the abnormality detection image representation corresponding to each image to be detected, When each of the images to be detected is a normal image, each of the images to be detected is regarded as a normal image, and after traversing the plurality of images to be detected, the normal image set containing at least one normal image is obtained .
在本公开的一些实施例中,所述获取部分502,还被配置为从所述异常图像集中的每个异常图像中,确定每个像素位置上的异常评分中最大的第一最大异常评分;从所述正常图像集中的每个正常图像中,确定每个像素位置上的异常评分中最大的第二最大异常评分;在所述第一最大异常评分属于预设异常阈值的第一预设数值范围的情况下,确定所述第一最大异常评分对应的异常图像属于所述待核验图像;在所述第二最大异常评分属于所述预设异常阈值的第二预设数值范围的情况下,确定所述第二最大异常评分对应的正常图像属于所述待核验图像。In some embodiments of the present disclosure, the acquiring part 502 is further configured to determine, from each abnormal image in the abnormal image set, the first maximum abnormal score among the abnormal scores at each pixel position; From each normal image in the normal image set, determine a second maximum abnormality score that is the largest among the abnormality scores at each pixel position; the first maximum abnormality score belongs to a first preset value of a preset abnormality threshold at the first maximum abnormality score range, determine that the abnormal image corresponding to the first maximum abnormality score belongs to the image to be verified; in the case that the second maximum abnormality score belongs to the second preset value range of the preset abnormality threshold, It is determined that the normal image corresponding to the second maximum abnormality score belongs to the image to be verified.
在本公开的一些实施例中,所述获取部分502,还被配置为将所述正常图像集和所述异常图像集中的全部图像,确定为所述待核验图像。In some embodiments of the present disclosure, the acquiring part 502 is further configured to determine all images in the normal image set and the abnormal image set as the images to be verified.
在本公开的一些实施例中,所述第二训练部分502,还被配置为在采用所述第二样本集中的正样本,对所述检测网络进行训练的情况下,采用所述检测网络得到所述正样本对应的第一特征差异序列,并根据所述第一特征差异序列和正常损失函数,确定出所述正样本对应的第一训练损失;在采用所述第二样本集中的负样本,对所述检测网络进行训练的情况下,采用所述检测网络得到所述负样本对应的第二特征差异序列,并根据所述第二特征差异序列、预设的负样本的真实值和异常损失函数,确定出所述负样本对应的第二训练损失;基于所述第一训练损失和所述第二训练损失,分别对所述检测网络进行训练调整,直至得到的最终损失小于预设损失阈值时,得到所述更新后的检测网络;其中,所述正常损失函数表征所述正样本对应的重构特征序列拉近所述正样本;所述异常损失函数表征所述负样本中的异常部分对应的重构特征序列推离所述异常部分,以及所述负样本中的正常 部分对应的重构特征序列拉近所述正常部分。In some embodiments of the present disclosure, the second training part 502 is further configured to use the detection network to obtain The first feature difference sequence corresponding to the positive sample, and according to the first feature difference sequence and the normal loss function, determine the first training loss corresponding to the positive sample; when using the negative sample in the second sample set , when the detection network is trained, the detection network is used to obtain the second feature difference sequence corresponding to the negative sample, and according to the second feature difference sequence, the preset true value and abnormality of the negative sample A loss function, determining the second training loss corresponding to the negative sample; based on the first training loss and the second training loss, respectively training and adjusting the detection network until the obtained final loss is less than the preset loss threshold, the updated detection network is obtained; wherein, the normal loss function represents that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample; the abnormal loss function represents the abnormality in the negative sample The reconstructed feature sequence corresponding to the part is pushed away from the abnormal part, and the reconstructed feature sequence corresponding to the normal part in the negative sample is pulled closer to the normal part.
在本公开的一些实施例中,所述更新后的检测网络包括:更新后的特征提取网络和更新后的重构网络;所述检测部分,还被配置为采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络之后,采用所述更新后的特征提取网络,对目标图像进行不同尺度的特征处理,得到多尺度特征序列;采用所述更新后的重构网络,对所述多尺度特征序列和预设的问询词序列进行重构,得到重构特征序列;根据所述重构特征序列与所述多尺度特征序列,确定所述目标图像的每个像素位置上的特征差异;基于所述特征差异,确定所述每个像素位置上的异常评分,并基于所述异常评分,绘制所述目标图像对应的异常检测图像。In some embodiments of the present disclosure, the updated detection network includes: an updated feature extraction network and an updated reconstruction network; the detection part is further configured to use the second sample set to The detection network is updated and trained, and after the updated detection network is obtained, the updated feature extraction network is used to perform feature processing of different scales on the target image to obtain a multi-scale feature sequence; using the updated reconstruction network, reconstructing the multi-scale feature sequence and the preset query word sequence to obtain a reconstructed feature sequence; according to the reconstructed feature sequence and the multi-scale feature sequence, determine each of the target images A feature difference at a pixel position; based on the feature difference, determining an abnormality score at each pixel position, and drawing an abnormality detection image corresponding to the target image based on the abnormality score.
在本公开实施例以及其他的实施例中,“部分”可以是部分电路、部分处理器、部分程序或软件等等,当然也可以是单元,还可以是模块也可以是非模块化的。In the embodiments of the present disclosure and other embodiments, a "part" may be a part of a circuit, a part of a processor, a part of a program or software, etc., of course it may also be a unit, a module or a non-modular one.
本公开实施例还提供一种电子设备,图15为本公开实施例提供的电子设备的结构示意图,如图15所示,电子设备2包括:存储器21和处理器22,其中,存储器21和处理器22通过通信总线23连接;存储器21,被配置为存储可执行指令(可执行计算机程序);处理器22,被配置为执行存储器21中存储的可执行指令时,实现本公开实施例提供的方法,例如,本公开实施例提供的异常检测方法。The embodiment of the present disclosure also provides an electronic device. FIG. 15 is a schematic structural diagram of the electronic device provided by the embodiment of the present disclosure. As shown in FIG. 15 , the electronic device 2 includes: a memory 21 and a processor 22, wherein the memory 21 and the processing The device 22 is connected through a communication bus 23; the memory 21 is configured to store executable instructions (executable computer programs); the processor 22 is configured to execute the executable instructions stored in the memory 21 to realize the implementation provided by the embodiments of the present disclosure. The method, for example, the anomaly detection method provided by the embodiment of the present disclosure.
本公开实施例提供一种计算机可读存储介质,存储有计算机程序,用于被处理器22执行时,实现本公开实施例提供的方法,例如,本公开实施例提供的异常检测方法。The embodiment of the present disclosure provides a computer-readable storage medium storing a computer program for implementing the method provided by the embodiment of the present disclosure, for example, the anomaly detection method provided by the embodiment of the present disclosure when executed by the processor 22 .
本公开实施例提供一种计算机程序,包括计算机可读代码,在所述计算机可读代码在电子设备中运行的情况下,所述计算机设备中的处理器执行用于实现上述异常检测方法中的步骤。An embodiment of the present disclosure provides a computer program, including computer readable codes. When the computer readable codes run in an electronic device, a processor in the computer device executes the above-mentioned anomaly detection method. step.
本公开实施例提供一种计算机程序产品,包括计算机程序指令,该计算机程序指令使得计算机执行上述异常检测方法中的步骤。An embodiment of the present disclosure provides a computer program product, including computer program instructions, where the computer program instructions cause a computer to execute the steps in the above anomaly detection method.
在本公开的一些实施例中,存储介质可以是可以保持和存储由指令执行设备使用的指令的有形设备,可为易失性存储介质或非易失性存储介质。计算机可读存储介质例如可以是(但不限于)电存储设备、磁存储设备、光存储设备、电磁存储设备、半导体存储设备或者上述的任意合适的组合。计算机可读存储介质的更具体的例子(非穷举的列表)包括:便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、静态随机存取存储器(SRAM)、便携式压缩盘只读存储器(CD-ROM)、数字多功能盘(DVD)、记忆棒、软盘、机械编码设备、例如其上存储有指令的打孔卡或凹槽内凸起结构、以及上述的任意合适的组合。这里所使用的计算机可读存储介质不被解释为瞬时信号本身,诸如无线电波或者其他自由传播的电磁波、通过波导或其他传输媒介传播的电磁波(例如,通过光纤电缆的光脉冲)、或者通过电线传输的电信号。In some embodiments of the present disclosure, the storage medium may be a tangible device capable of holding and storing instructions used by the instruction execution device, and may be a volatile storage medium or a non-volatile storage medium. A computer readable storage medium may be, for example, but is not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer diskettes, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), or flash memory), static random access memory (SRAM), compact disc read only memory (CD-ROM), digital versatile disc (DVD), memory stick, floppy disk, mechanically encoded device, such as a printer with instructions stored thereon A hole card or a raised structure in a groove, and any suitable combination of the above. As used herein, computer-readable storage media are not to be construed as transient signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., pulses of light through fiber optic cables), or transmitted electrical signals.
在本公开的一些实施例中,可执行指令可以采用程序、软件、软件模块、脚本或代码的形式,按任意形式的编程语言(包括编译或解释语言,或者声明性或过程性语言)来编写,并且其可按任意形式部署,包括被部署为独立的程序或者被部署为模块、组件、子例程或者适合在计算环境中使用的其它部分。In some embodiments of the present disclosure, executable instructions may take the form of programs, software, software modules, scripts, or code written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages) , and it may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other part suitable for use in a computing environment.
作为示例,可执行指令可以但不一定对应于文件系统中的文件,可以可被存储在保存其它程序或数据的文件的一部分,例如,存储在超文本标记语言(HTML,Hyper Text Markup Language)文档中的一个或多个脚本中,存储在专用于所讨论的程序的单个文件中,或者,存储在多个协同文件(例如,存储一个或多个模块、子程序或代码部分的文件)中。As an example, executable instructions may, but do not necessarily correspond to files in a file system, may be stored as part of a file that holds other programs or data, for example, in a Hyper Text Markup Language (HTML) document in one or more scripts, in a single file dedicated to the program in question, or in multiple cooperating files (for example, files that store one or more modules, subroutines, or sections of code).
作为示例,可执行指令可被部署为在一个计算设备上执行,或者在位于一个地点的多个计算设备上执行,又或者,在分布在多个地点且通过通信网络互连的多个计算设备上执行。As an example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or alternatively, on multiple computing devices distributed across multiple sites and interconnected by a communication network. to execute.
综上所述,采用正样本集对初始检测网络进行训练,得到检测网络,在检测网络对多张待检测图像进行异常检测过程中,基于检测出的正常图像集和异常图像集,得到包含正样本和负样本的增量样本集,其中,负样本为图像中存在异常的异常图像,并采用包含正样本和负样本的增量样本集,对检测网络进行更新训练,得到更新后的检测网络,所以,得到的更新后的检测网络更加适应实际生产线的检测场景,更新后的检测网络的检测精度更高,使得后续在使用更新后的检测网络对待检测图像进行异常检测时,得到的检测结果更准确;同时,由于增量样本中包括了正样本和负样本,所以得到的更新后的检测网络可以是采用正样本和负样本的增量样本训练得到的,使得检测网络能够兼容正样本和负样本等不同的情况,提升了异常检测的通用性与灵活性。To sum up, the initial detection network is trained with the positive sample set, and the detection network is obtained. In the process of abnormal detection of multiple images to be detected by the detection network, based on the detected normal image set and abnormal image set, the detection network is obtained. An incremental sample set of samples and negative samples, where the negative sample is an abnormal image with abnormalities in the image, and the incremental sample set including positive samples and negative samples is used to update and train the detection network to obtain an updated detection network , therefore, the obtained updated detection network is more suitable for the detection scene of the actual production line. more accurate; at the same time, since the incremental samples include positive samples and negative samples, the updated detection network obtained can be trained using incremental samples of positive samples and negative samples, so that the detection network can be compatible with positive samples and negative samples. Different situations such as negative samples improve the versatility and flexibility of anomaly detection.
以上所述,仅为本公开的实施例而已,并非用于限定本公开的保护范围。凡在本公开的精神和范围之内所作的任何修改、等同替换和改进等,均包含在本公开的保护范围之内。The above descriptions are merely examples of the present disclosure, and are not intended to limit the protection scope of the present disclosure. Any modifications, equivalent replacements and improvements made within the spirit and scope of the present disclosure are included in the protection scope of the present disclosure.
工业实用性Industrial Applicability
本公开实施例公开了一种异常检测方法、装置、电子设备、计算机可读存储介质、计算机程序及计算机程序产品。该方法包括:采用第一样本集对初始检测网络进行训练,得到检测网络;所述第一样本集为正样本集;在所述检测网络对多张待检测图像进行异常检测过程中,基于检测出的正常图像集和异常图像集,得到第二样本集,所述第二样本集为包含正样本和负样本的增量样本集;其中,所述负样本为图像中存在异常的异常图像;采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络。通过本公开,能够提高异常检测的准确性与灵活性。The embodiment of the present disclosure discloses an abnormality detection method, device, electronic equipment, computer-readable storage medium, computer program and computer program product. The method includes: using the first sample set to train the initial detection network to obtain the detection network; the first sample set is a positive sample set; during the process of abnormal detection of multiple images to be detected by the detection network, Based on the detected normal image set and abnormal image set, a second sample set is obtained, and the second sample set is an incremental sample set including a positive sample and a negative sample; wherein, the negative sample is an abnormality in the image An image: using the second sample set to update and train the detection network to obtain an updated detection network. Through the present disclosure, the accuracy and flexibility of anomaly detection can be improved.

Claims (24)

  1. 一种异常检测方法,包括:An anomaly detection method comprising:
    采用第一样本集对初始检测网络进行训练,得到检测网络;所述第一样本集为正样本集;Using the first sample set to train the initial detection network to obtain the detection network; the first sample set is a positive sample set;
    在所述检测网络对多张待检测图像进行异常检测过程中,基于检测出的正常图像集和异常图像集,得到第二样本集,所述第二样本集为包含正样本和负样本的增量样本集;其中,所述负样本为图像中存在异常的异常图像;In the process of the detection network performing anomaly detection on multiple images to be detected, a second sample set is obtained based on the detected normal image set and abnormal image set, and the second sample set is an augmented sample set containing positive samples and negative samples. Quantitative sample set; Wherein, described negative sample is the abnormal image that there is abnormality in the image;
    采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络。Using the second sample set, update and train the detection network to obtain an updated detection network.
  2. 根据权利要求1所述的方法,其中,所述采用第一正样本集对初始检测网络进行训练,得到检测网络,包括:The method according to claim 1, wherein said using the first positive sample set to train the initial detection network to obtain the detection network comprises:
    采用所述初始检测网络对所述第一样本集中的正样本进行检测,得到所述正样本对应的第一特征差异序列;Using the initial detection network to detect positive samples in the first sample set to obtain a first feature difference sequence corresponding to the positive samples;
    根据所述第一特征差异序列和正常损失函数,确定出所述正样本对应的训练损失;determining a training loss corresponding to the positive sample according to the first feature difference sequence and a normal loss function;
    基于所述训练损失,对所述初始检测网络进行训练调整,直至得到的最终损失小于预设损失阈值时,得到所述检测网络;Based on the training loss, the initial detection network is trained and adjusted until the obtained final loss is less than a preset loss threshold, and the detection network is obtained;
    其中,所述正常损失函数表征所述正样本对应的重构特征序列拉近所述正样本。Wherein, the normal loss function characterizes that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample.
  3. 根据权利要求1或2所述的方法,其中,所述基于检测出的正常图像集和异常图像集,得到第二样本集,包括:The method according to claim 1 or 2, wherein said obtaining a second sample set based on the detected normal image set and abnormal image set includes:
    从检测出的所述正常图像集和所述异常图像集中,确定待核验图像;Determining an image to be verified from the detected normal image set and the abnormal image set;
    对所述待核验图像进行核验,得到所述第二样本集。Verifying the image to be verified to obtain the second sample set.
  4. 根据权利要求3所述的方法,其中,所述待核验图像中包括:至少一张异常图像和至少一张正常图像;所述对所述待核验图像进行核验,得到所述第二样本集,包括:The method according to claim 3, wherein the image to be verified includes: at least one abnormal image and at least one normal image; the second sample set is obtained by verifying the image to be verified, include:
    对所述至少一张异常图像和所述至少一张正常图像分别进行核验,得到各自的核验结果;Verifying the at least one abnormal image and the at least one normal image respectively to obtain respective verification results;
    将所述核验结果表征正确的异常图像作为所述负样本,并将所述核验结果表征正确的正常图像作为所述正样本;taking the abnormal image whose verification result is correctly represented as the negative sample, and using the normal image whose verification result is correctly represented as the positive sample;
    对所述核验结果表征错误的异常图像,以及所述核验结果表征错误的正常图像进行正确标注,得到所述正样本和所述负样本;Correctly annotating the abnormal image with wrong representation of the verification result and the normal image with wrong representation of the verification result to obtain the positive sample and the negative sample;
    将所述负样本和所述正样本的集合,确定为所述第二样本集。A set of the negative samples and the positive samples is determined as the second sample set.
  5. 根据权利要求1-4任一项所述的方法,其中,所述采用第一样本集对初始检测网络进行训练,得到检测网络之后,所述方法还包括:The method according to any one of claims 1-4, wherein the first sample set is used to train the initial detection network, and after obtaining the detection network, the method further includes:
    采用所述检测网络对每张待检测图像进行异常检测,得到所述每张待检测图像的每个像素位置上的异常评分;Using the detection network to perform anomaly detection on each image to be detected, to obtain an abnormality score at each pixel position of each image to be detected;
    基于所述异常评分,绘制所述每张待检测图像对应的异常检测图像;Drawing an abnormality detection image corresponding to each image to be detected based on the abnormality score;
    根据所述异常检测图像,得到多张待检测图像中的所述正常图像集和所述异常图像集。According to the abnormality detection image, the normal image set and the abnormal image set among the plurality of images to be detected are obtained.
  6. 根据权利要求5的方法,其中,所述根据所述异常检测图像,得到多张待检测图像中的所述正常图像集和所述异常图像集,包括:The method according to claim 5, wherein said obtaining said normal image set and said abnormal image set in a plurality of images to be detected according to said abnormality detection image comprises:
    在所述每张待检测图像对应的异常检测图像表征,所述每张待检测图像为异常图像的情况下,将所述每张待检测图像作为异常图像,在遍历所述多张待检测图像后,得到包含至少一张异常图像的所述异常图像集;The abnormality detection image corresponding to each of the images to be detected is represented, and in the case that each of the images to be detected is an abnormal image, each of the images to be detected is regarded as an abnormal image, and after traversing the plurality of images to be detected After that, the abnormal image set containing at least one abnormal image is obtained;
    在所述每张待检测图像对应的异常检测图像表征,所述每张待检测图像为正常图像的情况下,将所述每张待检测图像作为正常图像,在遍历所述多张待检测图像后,得到包含至少一张正常图像的所述正常图像集。In the case that the abnormality detection image corresponding to each of the images to be detected is represented, and each of the images to be detected is a normal image, each of the images to be detected is regarded as a normal image, and after traversing the plurality of images to be detected After that, the normal image set including at least one normal image is obtained.
  7. 根据权利要求3所述的方法,其中,所述从检测出的所述正常图像集和所述异常 图像集中,确定待核验图像,包括:The method according to claim 3, wherein, determining the image to be verified from the detected normal image set and the abnormal image set includes:
    从所述异常图像集中的每个异常图像中,确定每个像素位置上的异常评分中最大的第一最大异常评分;From each of the abnormal images in the set of abnormal images, determining a first maximum abnormal score among the abnormal scores at each pixel position;
    从所述正常图像集中的每个正常图像中,确定每个像素位置上的异常评分中最大的第二最大异常评分;From each normal image in said set of normal images, determining a second maximum anomaly score among the anomaly scores at each pixel location;
    在所述第一最大异常评分属于预设异常阈值的第一预设数值范围的情况下,确定所述第一最大异常评分对应的异常图像属于所述待核验图像;When the first maximum abnormality score belongs to a first preset value range of a preset abnormality threshold, it is determined that the abnormal image corresponding to the first maximum abnormality score belongs to the image to be verified;
    在所述第二最大异常评分属于所述预设异常阈值的第二预设数值范围的情况下,确定所述第二最大异常评分对应的正常图像属于所述待核验图像。If the second maximum abnormality score belongs to the second preset value range of the preset abnormality threshold, it is determined that the normal image corresponding to the second maximum abnormality score belongs to the image to be verified.
  8. 根据权利要求3所述的方法,其中,所述从检测出的所述正常图像集和所述异常图像集中,确定待核验图像,包括:The method according to claim 3, wherein said determining the image to be verified from the detected normal image set and the abnormal image set comprises:
    将所述正常图像集和所述异常图像集中的全部图像,确定为所述待核验图像。All images in the normal image set and the abnormal image set are determined as the images to be verified.
  9. 根据权利要求1-8任一项所述的方法,其中,所述采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络,包括:The method according to any one of claims 1-8, wherein, using the second sample set, performing update training on the detection network to obtain an updated detection network, comprising:
    在采用所述第二样本集中的正样本,对所述检测网络进行训练的情况下,采用所述检测网络得到所述正样本对应的第一特征差异序列,并根据所述第一特征差异序列和正常损失函数,确定出所述正样本对应的第一训练损失;In the case of using the positive samples in the second sample set to train the detection network, using the detection network to obtain the first feature difference sequence corresponding to the positive sample, and according to the first feature difference sequence and a normal loss function to determine the first training loss corresponding to the positive sample;
    在采用所述第二样本集中的负样本,对所述检测网络进行训练的情况下,采用所述检测网络得到所述负样本对应的第二特征差异序列,并根据所述第二特征差异序列、预设的负样本的真实值和异常损失函数,确定出所述负样本对应的第二训练损失;In the case of using the negative samples in the second sample set to train the detection network, using the detection network to obtain the second feature difference sequence corresponding to the negative sample, and according to the second feature difference sequence , the actual value of the preset negative sample and the abnormal loss function, and determine the second training loss corresponding to the negative sample;
    基于所述第一训练损失和所述第二训练损失,分别对所述检测网络进行训练调整,直至得到的最终损失小于预设损失阈值时,得到所述更新后的检测网络;Based on the first training loss and the second training loss, respectively train and adjust the detection network until the obtained final loss is less than a preset loss threshold, and obtain the updated detection network;
    其中,所述正常损失函数表征所述正样本对应的重构特征序列拉近所述正样本;所述异常损失函数表征所述负样本中的异常部分对应的重构特征序列推离所述异常部分,以及所述负样本中的正常部分对应的重构特征序列拉近所述正常部分。Wherein, the normal loss function represents that the reconstructed feature sequence corresponding to the positive sample is pulled closer to the positive sample; the abnormal loss function represents that the reconstructed feature sequence corresponding to the abnormal part in the negative sample is pushed away from the abnormal part, and the reconstructed feature sequence corresponding to the normal part in the negative sample pulls the normal part closer.
  10. 根据权利要求1-9任一项所述的方法,其中,所述更新后的检测网络包括:更新后的特征提取网络和更新后的重构网络;The method according to any one of claims 1-9, wherein the updated detection network comprises: an updated feature extraction network and an updated reconstruction network;
    所述采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络之后,所述方法还包括:The said second sample set is used to update and train the detection network, and after obtaining the updated detection network, the method further includes:
    采用所述更新后的特征提取网络,对目标图像进行不同尺度的特征处理,得到多尺度特征序列;Using the updated feature extraction network to perform feature processing of different scales on the target image to obtain a multi-scale feature sequence;
    采用所述更新后的重构网络,对所述多尺度特征序列和预设的问询词序列进行重构,得到重构特征序列;Using the updated reconstruction network to reconstruct the multi-scale feature sequence and the preset query word sequence to obtain a reconstructed feature sequence;
    根据所述重构特征序列与所述多尺度特征序列,确定所述目标图像的每个像素位置上的特征差异;determining the feature difference at each pixel position of the target image according to the reconstructed feature sequence and the multi-scale feature sequence;
    基于所述特征差异,确定所述每个像素位置上的异常评分,并基于所述异常评分,绘制所述目标图像对应的异常检测图像。An abnormality score at each pixel position is determined based on the feature difference, and an abnormality detection image corresponding to the target image is drawn based on the abnormality score.
  11. 一种异常检测装置,包括:An anomaly detection device, comprising:
    第一训练部分,被配置为采用第一样本集对初始检测网络进行训练,得到检测网络;所述第一样本集为正样本集;The first training part is configured to use the first sample set to train the initial detection network to obtain the detection network; the first sample set is a positive sample set;
    获取部分,被配置为在所述检测网络对多张待检测图像进行异常检测过程中,基于检测出的正常图像集和异常图像集,得到第二样本集,所述第二样本集为包含正样本和负样本的增量样本集;其中,所述负样本为图像中存在异常的异常图像;The acquisition part is configured to obtain a second sample set based on the detected normal image set and abnormal image set during the process of the detection network performing anomaly detection on a plurality of images to be detected, and the second sample set contains positive An incremental sample set of samples and negative samples; wherein, the negative samples are abnormal images with abnormalities in the image;
    第二训练部分,被配置为采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络。The second training part is configured to use the second sample set to perform update training on the detection network to obtain an updated detection network.
  12. 根据权利要求11所述的装置,其中,所述第一训练部分,还被配置为采用所述初始检测网络对所述第一样本集中的正样本进行检测,得到所述正样本对应的第一特征差异序列;根据所述第一特征差异序列和正常损失函数,确定出所述正样本对应的训练损失;基于所述训练损失,对所述初始检测网络进行训练调整,直至得到的最终损失小于预设损失阈值时,得到所述检测网络;其中,所述正常损失函数表征所述正样本对应的重构特征序列拉近所述正样本。The device according to claim 11, wherein the first training part is further configured to use the initial detection network to detect the positive samples in the first sample set, and obtain the first positive sample corresponding to the positive sample. A feature difference sequence; according to the first feature difference sequence and a normal loss function, determine the training loss corresponding to the positive sample; based on the training loss, train and adjust the initial detection network until the final loss is obtained When it is less than the preset loss threshold, the detection network is obtained; wherein, the normal loss function indicates that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample.
  13. 根据权利要求11或12所述的装置,其中,所述获取部分,还被配置为从检测出的所述正常图像集和所述异常图像集中,确定待核验图像;对所述待核验图像进行核验,得到所述第二样本集。The device according to claim 11 or 12, wherein the acquisition part is further configured to determine an image to be verified from the detected normal image set and the abnormal image set; verify, and obtain the second sample set.
  14. 根据权利要求13所述的装置,其中,所述待核验图像中包括:至少一张异常图像和至少一张正常图像;所述获取部分,还被配置为对所述至少一张异常图像和所述至少一张正常图像分别进行核验,得到各自的核验结果;将所述核验结果表征正确的异常图像作为所述负样本,并将所述核验结果表征正确的正常图像作为所述正样本;对所述核验结果表征错误的异常图像,以及所述核验结果表征错误的正常图像进行正确标注,得到所述正样本和所述负样本;将所述负样本和所述正样本的集合,确定为所述第二样本集。The device according to claim 13, wherein the image to be verified includes: at least one abnormal image and at least one normal image; The at least one normal image is verified separately to obtain respective verification results; the abnormal image with the correct verification result as the negative sample, and the normal image with the correct verification result as the positive sample; An abnormal image whose verification result represents an error, and a normal image whose verification result represents an error are correctly marked to obtain the positive sample and the negative sample; the set of the negative sample and the positive sample is determined as The second sample set.
  15. 根据权利要求11-14任一项所述的装置,其中,所述异常检测装置还包括:检测部分;所述检测部分,被配置为在采用第一样本集对初始检测网络进行训练,得到检测网络之后,采用所述检测网络对每张待检测图像进行异常检测,得到所述每张待检测图像的每个像素位置上的异常评分;基于所述异常评分,绘制所述每张待检测图像对应的异常检测图像;所述获取部分,还被配置为根据所述异常检测图像,得到多张待检测图像中的所述正常图像集和所述异常图像集。The device according to any one of claims 11-14, wherein the abnormality detection device further comprises: a detection part; the detection part is configured to use the first sample set to train the initial detection network to obtain After the detection network, use the detection network to perform anomaly detection on each image to be detected, and obtain an abnormality score on each pixel position of each image to be detected; based on the abnormality score, draw each image to be detected An abnormality detection image corresponding to the image; the acquiring part is further configured to obtain the normal image set and the abnormal image set among the plurality of images to be detected according to the abnormality detection image.
  16. 根据权利要求15所述的装置,其中,所述获取部分,还被配置为在所述每张待检测图像对应的异常检测图像表征,所述每张待检测图像为异常图像的情况下,将所述每张待检测图像作为异常图像,在遍历所述多张待检测图像后,得到包含至少一张异常图像的所述异常图像集;在所述每张待检测图像对应的异常检测图像表征,所述每张待检测图像为正常图像的情况下,将所述每张待检测图像作为正常图像,在遍历所述多张待检测图像后,得到包含至少一张正常图像的所述正常图像集。The device according to claim 15, wherein the acquisition part is further configured to, when the abnormality detection image representation corresponding to each image to be detected is that each image to be detected is an abnormal image, the Each of the images to be detected is used as an abnormal image, and after traversing the plurality of images to be detected, the abnormal image set containing at least one abnormal image is obtained; the abnormality detection image corresponding to each image to be detected is represented , when each of the images to be detected is a normal image, each of the images to be detected is regarded as a normal image, and after traversing the multiple images to be detected, the normal image containing at least one normal image is obtained set.
  17. 根据权利要求13所述的装置,其中,所述获取部分,还被配置为从所述异常图像集中的每个异常图像中,确定每个像素位置上的异常评分中最大的第一最大异常评分;从所述正常图像集中的每个正常图像中,确定每个像素位置上的异常评分中最大的第二最大异常评分;在所述第一最大异常评分属于预设异常阈值的第一预设数值范围的情况下,确定所述第一最大异常评分对应的异常图像属于所述待核验图像;在所述第二最大异常评分属于所述预设异常阈值的第二预设数值范围的情况下,确定所述第二最大异常评分对应的正常图像属于所述待核验图像。The apparatus according to claim 13, wherein the acquiring part is further configured to determine, from each abnormal image in the abnormal image set, the first maximum abnormal score that is the largest among the abnormal scores at each pixel position ; from each normal image in the set of normal images, determine the second maximum anomaly score that is the largest among the anomaly scores at each pixel location; where the first maximum anomaly score belongs to a first preset of a preset anomaly threshold In the case of a numerical range, it is determined that the abnormal image corresponding to the first maximum abnormal score belongs to the image to be verified; in the case of the second maximum abnormal score belonging to the second preset numerical range of the preset abnormal threshold , determining that the normal image corresponding to the second maximum abnormality score belongs to the image to be verified.
  18. 根据权利要求13所述的装置,其中,所述获取部分,还被配置为将所述正常图像集和所述异常图像集中的全部图像,确定为所述待核验图像。The apparatus according to claim 13, wherein the acquisition part is further configured to determine all images in the normal image set and the abnormal image set as the images to be verified.
  19. 根据权利要求11-18任一项所述的装置,其中,所述第二训练部分,还被配置为在采用所述第二样本集中的正样本,对所述检测网络进行训练的情况下,采用所述检测网络得到所述正样本对应的第一特征差异序列,并根据所述第一特征差异序列和正常损失函数,确定出所述正样本对应的第一训练损失;在采用所述第二样本集中的负样本,对所述检测网络进行训练的情况下,采用所述检测网络得到所述负样本对应的第二特征差异序列,并根据所述第二特征差异序列、预设的负样本的真实值和异常损失函数,确定出所述负样本对应的第二训练损失;基于所述第一训练损失和所述第二训练损失,分别对所述检测网络进行训练调整,直至得到的最终损失小于预设损失阈值时,得到所述更新后的检测网络;其中,所述正常损失函数表征所述正样本对应的重构特征序列拉近所述正样本;所述异常 损失函数表征所述负样本中的异常部分对应的重构特征序列推离所述异常部分,以及所述负样本中的正常部分对应的重构特征序列拉近所述正常部分。The device according to any one of claims 11-18, wherein the second training part is further configured to, when using the positive samples in the second sample set to train the detection network, Obtaining the first feature difference sequence corresponding to the positive sample by using the detection network, and determining the first training loss corresponding to the positive sample according to the first feature difference sequence and a normal loss function; For the negative samples in the two-sample set, when the detection network is trained, the detection network is used to obtain the second feature difference sequence corresponding to the negative sample, and according to the second feature difference sequence, the preset negative The actual value of the sample and the abnormal loss function determine the second training loss corresponding to the negative sample; based on the first training loss and the second training loss, the detection network is trained and adjusted until the obtained When the final loss is less than the preset loss threshold, the updated detection network is obtained; wherein, the normal loss function represents that the reconstructed feature sequence corresponding to the positive sample is closer to the positive sample; the abnormal loss function represents the The reconstructed feature sequence corresponding to the abnormal part in the negative sample is pushed away from the abnormal part, and the reconstructed feature sequence corresponding to the normal part in the negative sample is pulled closer to the normal part.
  20. 根据权利要求11-19任一项所述的装置,其中,所述更新后的检测网络包括:更新后的特征提取网络和更新后的重构网络;所述检测部分,还被配置为在采用所述第二样本集,对所述检测网络进行更新训练,得到更新后的检测网络之后,采用所述更新后的特征提取网络,对目标图像进行不同尺度的特征处理,得到多尺度特征序列;采用所述更新后的重构网络,对所述多尺度特征序列和预设的问询词序列进行重构,得到重构特征序列;根据所述重构特征序列与所述多尺度特征序列,确定所述目标图像的每个像素位置上的特征差异;基于所述特征差异,确定所述每个像素位置上的异常评分,并基于所述异常评分,绘制所述目标图像对应的异常检测图像。The device according to any one of claims 11-19, wherein the updated detection network comprises: an updated feature extraction network and an updated reconstruction network; the detection part is further configured to use In the second sample set, the detection network is updated and trained, and after the updated detection network is obtained, the updated feature extraction network is used to perform feature processing of different scales on the target image to obtain a multi-scale feature sequence; Using the updated reconstruction network to reconstruct the multi-scale feature sequence and the preset query word sequence to obtain a reconstructed feature sequence; according to the reconstructed feature sequence and the multi-scale feature sequence, determining a feature difference at each pixel position of the target image; determining an abnormality score at each pixel position based on the feature difference, and drawing an abnormality detection image corresponding to the target image based on the abnormality score .
  21. 一种电子设备,包括:An electronic device comprising:
    存储器,被配置为存储可执行指令;memory configured to store executable instructions;
    处理器,被配置为执行所述存储器中存储的可执行指令时,实现权利要求1至10任一项所述的方法。A processor configured to implement the method according to any one of claims 1 to 10 when executing the executable instructions stored in the memory.
  22. 一种计算机可读存储介质,存储有计算机程序,被配置为被处理器执行时,实现权利要求1至10任一项所述的方法。A computer-readable storage medium storing a computer program configured to implement the method according to any one of claims 1 to 10 when executed by a processor.
  23. 一种计算机程序,包括计算机可读代码,在所述计算机可读代码在电子设备中运行的情况下,所述计算机设备中的处理器执行用于实现如权利要求1至10任一项所述的异常检测方法的步骤。A computer program, comprising computer-readable codes, when the computer-readable codes run in an electronic device, a processor in the computer device executes the program to implement any one of claims 1 to 10 The steps of the anomaly detection method.
  24. 一种计算机程序产品,包括计算机程序指令,该计算机程序指令使得计算机执行如权利要求1至10任一项所述的异常检测方法的步骤。A computer program product, comprising computer program instructions, the computer program instructions cause a computer to execute the steps of the anomaly detection method according to any one of claims 1 to 10.
PCT/CN2022/071448 2021-08-13 2022-01-11 Anomaly detection method and apparatus, electronic device, computer readable storage medium, computer program, and computer program product WO2023015843A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110932191.5 2021-08-13
CN202110932191.5A CN113688889A (en) 2021-08-13 2021-08-13 Abnormality detection method, abnormality detection device, electronic apparatus, and computer-readable storage medium

Publications (1)

Publication Number Publication Date
WO2023015843A1 true WO2023015843A1 (en) 2023-02-16

Family

ID=78579883

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/071448 WO2023015843A1 (en) 2021-08-13 2022-01-11 Anomaly detection method and apparatus, electronic device, computer readable storage medium, computer program, and computer program product

Country Status (2)

Country Link
CN (1) CN113688889A (en)
WO (1) WO2023015843A1 (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116542290A (en) * 2023-06-25 2023-08-04 城云科技(中国)有限公司 Information prediction model construction method, device and application based on multi-source multi-dimensional data
CN117493220A (en) * 2024-01-03 2024-02-02 安徽思高智能科技有限公司 RPA flow operation abnormity detection method, device and storage device
CN117724935A (en) * 2024-02-06 2024-03-19 山东大学 Multi-index abnormality detection method and system for software system
CN117808816A (en) * 2024-03-01 2024-04-02 腾讯科技(深圳)有限公司 Image anomaly detection method and device and electronic equipment

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113688889A (en) * 2021-08-13 2021-11-23 上海商汤智能科技有限公司 Abnormality detection method, abnormality detection device, electronic apparatus, and computer-readable storage medium
CN114445748A (en) * 2022-01-28 2022-05-06 深圳市中云慧通科技有限公司 Video human body feature detection and linkage alarm method and storage medium
CN114549445A (en) * 2022-02-16 2022-05-27 上海商汤智能科技有限公司 Image detection and related model training method, related device, equipment and medium
CN114419619B (en) * 2022-03-29 2022-06-10 北京小蝇科技有限责任公司 Erythrocyte detection and classification method and device, computer storage medium and electronic equipment
CN114627102B (en) * 2022-03-31 2024-02-13 苏州浪潮智能科技有限公司 Image anomaly detection method, device and system and readable storage medium
CN115082400A (en) * 2022-06-21 2022-09-20 北京字跳网络技术有限公司 Image processing method and device, computer equipment and readable storage medium
CN114996536B (en) * 2022-08-08 2022-11-15 深圳市信润富联数字科技有限公司 Maintenance scheme query method, device, equipment and computer readable storage medium
CN115984285B (en) * 2023-03-21 2023-07-04 上海仙工智能科技有限公司 Method and system for detecting library bit state based on generation countermeasure network and storage medium
CN116403077B (en) * 2023-06-07 2023-08-15 中国科学院自动化研究所 Abnormality detection model training method, abnormality detection device and electronic equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107491790A (en) * 2017-08-25 2017-12-19 北京图森未来科技有限公司 A kind of neural network training method and device
CN110705630A (en) * 2019-09-27 2020-01-17 聚时科技(上海)有限公司 Semi-supervised learning type target detection neural network training method, device and application
US20200125923A1 (en) * 2018-10-17 2020-04-23 Mitsubishi Electric Research Laboratories, Inc. System and Method for Detecting Anomalies in Video using a Similarity Function Trained by Machine Learning
CN111709907A (en) * 2020-04-26 2020-09-25 江南大学 Cloth defect detection method based on One-Class deep support vector description
CN113688889A (en) * 2021-08-13 2021-11-23 上海商汤智能科技有限公司 Abnormality detection method, abnormality detection device, electronic apparatus, and computer-readable storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107491790A (en) * 2017-08-25 2017-12-19 北京图森未来科技有限公司 A kind of neural network training method and device
US20200125923A1 (en) * 2018-10-17 2020-04-23 Mitsubishi Electric Research Laboratories, Inc. System and Method for Detecting Anomalies in Video using a Similarity Function Trained by Machine Learning
CN110705630A (en) * 2019-09-27 2020-01-17 聚时科技(上海)有限公司 Semi-supervised learning type target detection neural network training method, device and application
CN111709907A (en) * 2020-04-26 2020-09-25 江南大学 Cloth defect detection method based on One-Class deep support vector description
CN113688889A (en) * 2021-08-13 2021-11-23 上海商汤智能科技有限公司 Abnormality detection method, abnormality detection device, electronic apparatus, and computer-readable storage medium

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116542290A (en) * 2023-06-25 2023-08-04 城云科技(中国)有限公司 Information prediction model construction method, device and application based on multi-source multi-dimensional data
CN116542290B (en) * 2023-06-25 2023-09-08 城云科技(中国)有限公司 Information prediction model construction method, device and application based on multi-source multi-dimensional data
CN117493220A (en) * 2024-01-03 2024-02-02 安徽思高智能科技有限公司 RPA flow operation abnormity detection method, device and storage device
CN117493220B (en) * 2024-01-03 2024-03-26 安徽思高智能科技有限公司 RPA flow operation abnormity detection method, device and storage device
CN117724935A (en) * 2024-02-06 2024-03-19 山东大学 Multi-index abnormality detection method and system for software system
CN117724935B (en) * 2024-02-06 2024-06-07 山东大学 Multi-index abnormality detection method and system for software system
CN117808816A (en) * 2024-03-01 2024-04-02 腾讯科技(深圳)有限公司 Image anomaly detection method and device and electronic equipment

Also Published As

Publication number Publication date
CN113688889A (en) 2021-11-23

Similar Documents

Publication Publication Date Title
WO2023015843A1 (en) Anomaly detection method and apparatus, electronic device, computer readable storage medium, computer program, and computer program product
KR102401942B1 (en) Method and apparatus for evaluating translation quality
CN108985358B (en) Emotion recognition method, device, equipment and storage medium
CN110750959A (en) Text information processing method, model training method and related device
CN114511906A (en) Cross-modal dynamic convolution-based video multi-modal emotion recognition method and device and computer equipment
CN110852107B (en) Relation extraction method, device and storage medium
CN112364810A (en) Video classification method and device, computer readable storage medium and electronic equipment
CN110059637B (en) Face alignment detection method and device
CN113688890A (en) Abnormality detection method, abnormality detection device, electronic apparatus, and computer-readable storage medium
CN115618045A (en) Visual question answering method, device and storage medium
CN110399547B (en) Method, apparatus, device and storage medium for updating model parameters
CN116050496A (en) Determination method and device, medium and equipment of picture description information generation model
CN116091836A (en) Multi-mode visual language understanding and positioning method, device, terminal and medium
CN113902256A (en) Method for training label prediction model, label prediction method and device
US20230014904A1 (en) Searchable data structure for electronic documents
CN114281948A (en) Summary determination method and related equipment thereof
CN117292146A (en) Industrial scene-oriented method, system and application method for constructing multi-mode large language model
CN117113270A (en) Knowledge fusion multi-mode interaction method and device based on improved alignment method
CN117152815A (en) Student activity accompanying data analysis method, device and equipment
CN112084788A (en) Automatic marking method and system for implicit emotional tendency of image captions
CN114419514B (en) Data processing method, device, computer equipment and storage medium
CN113761209B (en) Text splicing method and device, electronic equipment and storage medium
CN115809438A (en) Multi-modal emotion analysis method, system, device and storage medium
CN115544210A (en) Model training and event extraction method based on event extraction of continuous learning
CN113688844A (en) Neural network training method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE