Systems and computer-implemented methods for identifying anomalies in an object and training methods therefor

A system identifies anomalies in an image of an object. An input image of the object containing zero or more anomalies is supplied to an image encoder. The image encoder generates an image model. The image model is applied to an image decoder that forms a substitute non-anomalous image of the object. Differences between the input image and the substitute non-anomalous image identify zero or more areas of the input image that contain the zero or more the anomalies. The system implements a flow-based model and has been trained using (a) a set of augmented anomaly-free images of the object applied at the image encoder and (b) a reconstruction loss calculated based on a norm of differences between each augmented anomaly-free image of the object and a corresponding output image from the image decoder.

FIELD

The present technology relates to the field of computer assisted image inspection. In particular, the present technology introduces systems and computer-implemented methods for identifying anomalies in an object and methods for training the systems.

BACKGROUND

Unsupervised and semi-supervised visual anomaly detection and classification, used for example in manufacturing applications, pose very challenging problems. Some problems are related to the fact that, in most circumstances, labeling image data is cost prohibitive. Other problems are related to the fact that many defects in manufactured goods are very small and difficult to detect using visual anomaly detection mechanisms. Also, the nature of the defects tends to change over time and new types of defects may frequently occur. Consequently, conventional imaging solutions either require huge amounts of expensive labeled data that may actually be inaccurate. Also, conventional imaging solutions frequently become obsolete as new types of defects are discovered. Models used by these conventional imaging solutions need to be taken out of service and replaced with updated models. Such solutions are not scalable, are costly, and are therefore not sustainable in practice.

Even though the recent developments identified above may provide benefits, improvements are still desirable.

SUMMARY

Embodiments of the present technology have been developed based on developers' appreciation of shortcomings associated with the prior art.

In particular, such shortcomings may comprise high costs of labeling image data, lack of updatability to cater for new types of defects, and/or lack of scalability.

In one aspect, various implementations of the present technology provide a computer-implemented method for identifying anomalies in an object, comprising:supplying, to an image encoder of a system, an input image of the object, the input image of the object containing zero or more anomalies;generating, at the image encoder, an image model; andapplying the generated image model to an image decoder of the system, the image decoder forming a substitute non-anomalous image of the object, differences between the input image of the object and the substitute non-anomalous image of the object identifying zero or more areas of the input image of the object that contain the zero or more the anomalies;the system implementing a flow-based model; andthe system having been trained using (a) a set of augmented anomaly-free images of the object applied at the image encoder and (b) a reconstruction loss calculated based on a norm of differences between each augmented anomaly-free image of the object and a corresponding output image from the image decoder.

In some implementations of the present technology, each anomaly free image of the object used for training the system is augmented by adding thereto an alteration selected from a random noise, a random cropping, a random rotation, a random set of white patches, a random set of black patches and a combination thereof.

In some implementations of the present technology, the flow-based model is a generative normalizing flow-based model.

In some implementations of the present technology, the method further comprises generating an anomaly map identifying the zero or more areas of the input image of the object that contain the zero or more anomalies.

In some implementations of the present technology, the anomaly map is a heat-map in which distinct colors or shades reflect corresponding anomaly probabilities in the input image of the object.

In some implementations of the present technology, the flow-based model forms a Gaussian model in which errors have a null mean and a predetermined standard deviation; and the system has been trained in unsupervised mode by supplying the set of augmented anomaly-free images of the object to the image encoder and by using the mean and the standard deviation of the flow-based model.

In some implementations of the present technology, the system has been trained further by calculating a log-likelihood loss based on the mean and standard deviation of the flow-based model.

In some implementations of the present technology, the log-likelihood loss is calculated in part based on a ratio of an output of a current layer of the flow-based model over an output of a previous layer of the flow-based model; and the system has been trained further by calculating a regularization loss based on a ratio of the output of the previous layer of the flow-based model over the output of the current layer of the flow-based model.

In some implementations of the present technology, the flow-based model comprises one or more modes defined in a latent space of the flow-based model, each mode of the flow-based model corresponding to one of one or more anomaly types, each mode having a corresponding mean and a corresponding standard deviation; and the system has been trained in semi-supervised mode by supplying to the image encoder the set of augmented anomaly-free images of the object, by supplying to the image encoder one or more sets of augmented anomalous images corresponding to the one or more anomaly types, and by calculating the means and standard deviations corresponding to the one or more modes of the flow-based model.

In some implementations of the present technology, the method further comprises supplying labels to an anomaly encoder, each label corresponding to a respective image among the one or more sets of augmented anomalous images, each label identifying a related anomaly type, the anomaly encoder calculating the means and standard deviations corresponding to the one or more modes of the flow-based model based on the label; and supplying the labels to a classifier supplied, the classifier calculating a classification loss for each of the anomaly types; the system having been trained further using the classification losses.

In some implementations of the present technology, the method further comprises supplying a content of the latent space to the classifier; and using, at the classifier, the content of the latent space to classify each of the one or more anomaly types.

In some implementations of the present technology, the method further comprises supplying to the image encoder one or more additional sets of augmented anomalous images corresponding to one or more additional anomaly types; supplying additional labels to the anomaly encoder, each additional label corresponding to a respective image among the one or more additional sets of augmented anomalous images, each additional label identifying a related additional anomaly type; calculating, at the anomaly encoder, a new version of the vector containing the mean for each of the one or more flow-based model modes defined for the one of more anomaly types, the vector further containing a mean for each of one or more additional flow-based model modes defined for the one or more additional anomaly types; calculating, at the anomaly encoder, a new version of the vector containing the standard deviation for each of the one or more flow-based model modes defined for the one of more anomaly types, the vector further containing a standard deviation for each of one or more additional flow-based model modes defined for the one or more additional anomaly types; supplying, to the latent space, a statistically sufficient sample of information contained in the vectors containing the mean and the standard deviation for each of the one or more flow-based model modes defined for the one of more anomaly types; and retraining the system using the one or more additional sets of augmented anomalous images and the means and standard deviations of the one or more modes and of the one or more additional modes of the flow-based model.

In some implementations of the present technology, the retraining of the system further comprises: supplying the additional labels to the classifier; supplying a content of the latent space to the classifier; using, at the classifier, the content of the latent space to classify each of the one or more additional anomaly types; and calculating, at the classifier, a classification loss for each of the additional anomaly types.

In some implementations of the present technology, each of the one or more anomaly types is selected from a scratch, a crack, a color, a spot, a hole, a discoloration, and a combination thereof.

In some implementations of the present technology, the image encoder maps pixels of the input image of the object into the image model; the image model is placed in a latent space of the flow-based model; and the image decoder maps the image model from the latent space into pixels of the substitute non-anomalous image of the object.

In some implementations of the present technology, the image encoder implements a first function; the image decoder implements a second function, the second function being an inverse of the first function; and the image encoder and the image decoder share a common set of weights.

In another aspect, various implementations of the present technology provide a system implementing a flow-based model for identifying anomalies in an object, comprising:an image encoder adapted to receive an input image of the object, the input image of the object containing zero or more anomalies, the image encoder being further adapted to generate an image model, andan image decoder adapted to form a substitute non-anomalous image of the object, differences between the input image of the object and the substitute non-anomalous image of the object identifying zero or more areas of the input image of the object that contain the zero or more anomalies;the system having been trained using (a) a set of augmented anomaly-free images of the object applied at the image encoder and (b) a reconstruction loss calculated based on a norm of differences between each augmented anomaly-free image of the object and a corresponding output image from the image decoder.

In some implementations of the present technology, the system further comprises an input interface operatively connected to the image encoder and adapted to receive the input image of the object from an image source; and an output interface operatively connected to the image decoder and adapted to transmit the substitute non-anomalous image of the object to an image receiver.

In some implementations of the present technology, the system further comprises an anomaly encoder adapted to receive labels, each label corresponding a respective image among one or more sets of augmented anomalous images corresponding to one or more anomaly types, each label identifying a related anomaly type, the anomaly encoder using the labels to calculate a mean and a standard deviation corresponding to each one or more modes of the flow-based model defined for each of the one or more anomaly types; a classifier adapted to receive the labels and to calculate a classification loss for each of the anomaly types; and a training engine adapted to train the system.

In some implementations of the present technology, the training engine is adapted to train the system using: the set of augmented anomaly-free images of the object; the reconstruction loss value; the one or more sets of augmented anomalous images corresponding to the one or more anomaly types; the mean and the standard deviation corresponding to each of the one or more modes defined in a latent space of the flow-based model; a log-likelihood loss calculated, for each of the anomaly types, based on the respective mean and standard deviation of the flow-based model and on a ratio of an output of a current layer of the flow-based model over an output of a previous layer of the flow-based model; and a regularization loss calculated based on a ratio of the output of the previous layer of the flow-based model over the output of the current layer of the flow-based model.

In the context of the present specification, unless expressly provided otherwise, a computer system may refer, but is not limited to, an “electronic device”, an “operation system”, a “system”, a “computer-based system”, a “controller unit”, a “monitoring device”, a “control device” and/or any combination thereof appropriate to the relevant task at hand.

In the context of the present specification, unless expressly provided otherwise, the expression “computer-readable medium” and “memory” are intended to include media of any nature and kind whatsoever, non-limiting examples of which include RAM, ROM, disks (CD-ROMs, DVDs, floppy disks, hard disk drives, etc.), USB keys, flash memory cards, solid state-drives, and tape drives. Still in the context of the present specification, “a” computer-readable medium and “the” computer-readable medium should not be construed as being the same computer-readable medium. To the contrary, and whenever appropriate, “a” computer-readable medium and “the” computer-readable medium may also be construed as a first computer-readable medium and a second computer-readable medium.

It should also be noted that, unless otherwise explicitly specified herein, the drawings are not to scale.

DETAILED DESCRIPTION

Software modules, or simply modules which are implied to be software, may be represented herein as any combination of flowchart elements or other elements indicating performance of process steps and/or textual description. Such modules may be executed by hardware that is expressly or implicitly shown. Moreover, it should be understood that such modules may include for example, but without being limitative, computer program logic, computer program instructions, software, stack, firmware, hardware circuitry or a combination thereof which provides the required capabilities.

In one embodiment, the present technology may operate in unsupervised mode for identifying image anomalies. A system has been trained using a set of anomaly-free images of an object. Having learned a rich representation of the non-anomalous object, the system is able to receive an input image of a particular object that may contain anomalies, generate an image model and regenerate a substitute non-anomalous image of the object. An anomaly map, for example a heat-map, may be generated by comparing the input image and the regenerated image. Areas in the anomaly map that are associated with high probabilities represent parts of the object that most likely contain anomalies. The anomaly map may thus localize the anomalies defect while providing a confidence level for the detection of anomalies.

In another embodiment, the present technology may operate in semi-supervised mode. The system is trained in unsupervised mode using the set of anomaly-free images of the object, in the manner expressed in the previous paragraph. A classification head is added to the system. The classification head having been trained in supervised mode using a small label dataset of anomalous images of the object, it may predict with increased performance and accuracy a type of an anomaly in the input image of the particular object, directly from the generated image model. In an embodiment, the size of the label dataset may be much smaller than the set of anomaly-free images used for training in unsupervised mode. Therefore, this semi-supervised technique may be used both for anomaly detection with localization and for anomaly-type classification.

In a further embodiment, the present technology may use a continuous mode for training the system, both in the unsupervised and semi-supervised embodiments. Use of the continuous mode may allow the system to adapt to changes in the types of anomalies that may impact the imaged object.

FIG.1is a block diagram of an anomaly detection system100adapted to be trained in unsupervised mode in accordance with an embodiment of the present technology. The system100includes an image encoder105that receives input images110and forms an image model for each input image110. The image models are placed in a latent space115. In more details, a neural network is used to extract a compact set of image features, smaller than the size of the original images, to form the image models placed in the latent space115. In a non-limiting embodiment, the neural network may be based on a normalizing flow structure. Other non-limiting examples of techniques that may be used to place the image models in the latent space115may be found in Kobyzev, Ivan, Simon Prince, and Marcus Brubaker. “Normalizing flows: An introduction and review of current methods”, IEEE Transactions on Pattern Analysis and Machine Intelligence (2020), and in Kingma, Durk P., and Prafulla Dhariwal. “Glow: Generative flow with invertible 1×1 convolutions”, Advances in neural information processing systems (2018). An image decoder120produces regenerated images125based on the image models placed in the latent space115.

In an embodiment, the image encoder105implements an encoding function geand the image decoder120implements a decoding function ge−1, which is an inverse of the encoding function ge. In the same or another embodiment, the image encoder105and the image decoder120are both constructed using a neural network and both share identical sets of weights.

The system100implements a single mode model, for example a flow-based model which, in an embodiment, is a generative normalizing flow-based model. The flow-based model may have a Gaussian distribution in which errors have null mean μ0and a predetermined standard deviation σ0.

The system100may be trained to detect anomalies on an image of an object. To this end, the image encoder105may be supplied with a plurality of input images110that are anomaly-free versions of the object. For example and without limitation, thousands or tens of thousands of such images may be used to train the system100. The input images110may be augmented by the addition of alterations intended to enrich the flow-based model. Such alterations may comprise, without limitation, a random noise, a random cropping, a random rotation, a random set of white patches, a random set of black patches, and any combination thereof. Having been trained using augmented images, the system100will be more tolerant, at inference time, to the presence of noise in images of the object.

Where x′ is an augmented version of an original input image x. As expressed in equation (1), the system100calculates the reconstruction loss130based on a norm of differences between the original input image x and a reconstruction of its augmented version x′. Useful examples of the calculation of the norm may be found for example at https://mathworld.wolfram.com/L2-Norm.html.

The system100may also calculate a log-likelihood loss135based on a ratio of an output of a current layer of the flow-based model over an output of a previous layer of the flow-based model, as shown in equations (2) and (3):

Where x is the input image, z is a latent variable, pθ(x) is a probability contribution of x, pθ(z) is a probability contribution of z, and

Lreg=∑i=1K⁢⁢log⁢det⁡(dhi-1dhi)(4)
is the derivative of an output of a layer hiwith respect to an output of a previous layer hi−1of the neural network, which is formed of K layers.

The system100may further calculate a regularization loss (not shown), which includes in part a reverse of the log-likelihood loss135. The regularization loss is calculated as shown in equation (4):

The system100is trained using the reconstruction loss130and may further be trained using the log-likelihood loss135and the regularization loss, following which the system100is ready to identify anomalies in a particular object similar to the anomaly-free object. This training process is sometimes called “optimization through backpropagation”, a technique that has been used for training various types of neural networks. In this process, the gradient of the loss with respect to each layer in the neural network is computed and is used to update the corresponding weights in that layer. More information may be found in https://en.wikipedia.org/wiki/Backpropagation. It may also be noted that several open-source deep-learning libraries are currently available. These libraries package various types of optimization algorithms that may be used as a part of the present technology. In a non-limiting embodiment, a PyTorch library (https://en.wikipedia.org/wiki/PyTorch) may be used to implement and train the system100.

FIG.2is a block diagram of an anomaly detection system200adapted to be trained in semi-supervised mode in accordance with an embodiment of the present technology. The system200includes all components of the system100, which are not described further except where these components may include additional functions. The system200implements a multi-mode model, having one mode for each of one or more anomaly types that might be found in instances of the object. Non-limiting examples of anomaly types may include one or a combination of a scratch, a crack, a color, a spot, a hole, and a discoloration present in some instances of the object. Generally speaking, these anomalies will have been detected in an industrial context where the object is produced or tested and where anomalies of these types have occurred. The system200is particularly efficient in identifying anomalies defined in the one or more anomaly types.

To this end, one or more sets of anomalous images of the object are supplied to the image encoder105. These images contain anomalies corresponding to one or more known anomaly types for the object. The images containing the anomalies may be augmented, in the same manner as described hereinabove, before being supplied to the image encoder105. In some embodiments, a small number of anomalous images may be supplied to the image encoder105, for example 10 to 20 images or so for each anomaly type. The system200also includes a supplier240of anomaly type labels. The supplier240may provide labels to an anomaly encoder245, which is another neural network that gets trained end-to-end with the rest of the system100. Each label provided to the anomaly encoder245corresponds to a given one of the anomalous images of the object and identifies a related anomaly type.

Using the labels, the anomaly encoder245generates a vector250containing a mean {μ0, μ1, . . . , μn} for each of the one of more anomaly types and another vector255containing a standard deviation {σ0, σ1, . . . , σn} for each of the one of more anomaly types. The mean and standard deviations are predicted by the anomaly encoder245. The anomaly encoder245takes a given anomaly type as an input, and outputs the mean and standard deviation for the given anomaly type. During the training, the anomaly encoder245parametrizes the probability contribution pθof equations (2) and (3) using these mean and standard deviation values. A log-likelihood loss135may be calculated for each of the modes.

The system200may be trained in the same manner as expressed in relation to the system100and may further be trained using the one or more sets of anomalous images supplied to the image encoder105, also using the means of the vectors250and255supplied to the latent space in the calculation of the log likelihood loss135. The system200may define one of more flow-based models for the one of more anomaly types. Hence, the anomalous images are mapped to the latent space115and the labels are mapped to the vectors250and255.

Additionally, the system200may comprise a classifier260that is supplied with the labels from the supplier240and with at least some of the content of the latent space115. The classifier260may use the content of the latent space115to generate classification information for each anomaly type. The latent space115contains a set of extracted features at the output of the encoder105. The classifier260may take these features as input and pass them through another neural network (not shown) that classifies each anomaly type. This neural network is also trained end-to-end with the rest of the system200at the training time.

The classifier260may further use the labels identifying the one or more anomaly types to calculate a classification loss265for each of the anomaly types. The system200may further be trained using the one or more classification losses265calculated for the one or more anomaly types. The classification loss265may, for example and without limitation, be calculated as expressed in https://en.wikipedia.org/wiki/Cross_entropy, the disclosure of which is incorporated by reference herein.

FIG.3is a block diagram of an anomaly detection system300adapted to be trained in semi-supervised mode and retrained using a continuous learning feature in accordance with an embodiment of the present technology. The system300includes all components of the systems100and200, which are not described further except where these components may include additional functions. Like the system200, the system300also implements a multi-mode model, having one mode for each of one or more anomaly types that may be present in the object. The system300may initially be trained in semi-supervised mode in the same manner as expressed in relation to the description of the system200, following which a trained model comprising encoded original anomaly types is present in the latent space115.

In the industrial context where the object is produced or tested, new anomaly types may be detected after a few weeks or a few months of production. When new anomaly types are identified for the object, one or more new sets of anomalous images of the object are supplied to the image encoder105. These images contain anomalies corresponding to one or more new anomaly types for the object. The images containing the new anomalies may also be augmented before being supplied to the image encoder105. The supplier240provides new labels to the anomaly encoder245, each new label corresponding to a given one of the new anomalous images of the object and identifying a related new anomaly type.

The anomaly encoder245generates a new version of the vector250containing a mean {μ0, μ1, . . . , μn} for each of the original and new anomaly types and a new version of the vector255containing a standard deviation {σ0, σ1, . . . , σn} for each of the original and new anomaly types.

The system300further includes a sampler370that collects sufficient information from the vectors250and255to statistically represent at least the original anomaly types. Collecting sufficient information from the vectors250and255to statistically represent the new anomaly types is also contemplated. In an embodiment, this information may be randomly sampled. The information obtained by the sampler370and related to the original anomaly types is provided to the latent space115. A log-likelihood loss135is calculated for each of the new anomaly types, for example using equations (2) and/or (3), in view of retraining the system300. The one or more new sets of images of the object that contain new anomalies a supplied the image encoder105to populate the latent space105.

Other components of the system300operate in the same manner as in the case of the system200. Following retraining of the system300, the model in the latent space115provides substantially the same level of detection accuracy for both the original and the new anomaly types.

FIG.4is a block diagram showing interactions between the anomaly detection system100,200,300ofFIGS.1,2and3, respectively, and a training engine400in accordance with an embodiment of the present technology. Although not shown onFIGS.1,2and3, a training engine400operates in cooperation with the system100,200or300while it is being trained. Figuratively speaking, the components of the systems100,200and300may be viewed as being in an operational plane while the training engine400may be viewed as being in a training plane superimposed on the operational plane. The training engine400is not used for generating image models or for forming substitute non-anomalous images. Otherwise stated, the training engine400is not used at inference time.

The training engine400obtains values for the reconstruction loss130, the log likelihood loss135and the regularization loss from the systems100,200or300. The training engine400may also obtain values for the classification loss265from the systems200or300. The training engine may further obtain, from the sampler370, information obtained by sampling the vectors250and255related to known anomaly types. Sufficient information is obtained by sampling the vectors250and255to statistically represent at least the original anomaly types. Collecting sufficient information from the vectors250and255to statistically represent the new anomaly types is also contemplated. In response, the training engine400provides training to the systems100,200and300. Impacts of the training is implemented in the latent space115of the systems100,200and300.

FIG.5is the anomaly detection system100,200or300of any one ofFIGS.1,2and3in use for identifying anomalies in an object in accordance with an embodiment of the present technology. In operation, the systems100,200and300are used in the same manner for identifying zero or more anomalies in an input image150of the object, with performance levels that may vary according to the type of training used in these systems.

The image encoder105converts the input image150into an image model placed in the latent space115. The latent space115has been trained to include a trained model of the object, the trained model consisting of a single-mode model (system100) or a multi-mode model (systems200and300), as expressed hereinabove. The decoder120converts the image model to produce a regenerated image155, which is a substitute non-anomalous image of the object.

A post-processor160may compare the input image150and the regenerated image155to produce an anomaly map identifying zero of more areas of the input image150of the object that contain the zero or more anomalies. In a non-limiting embodiment, the anomaly map may be presented as a heat-map in which distinct colors or shades reflect corresponding anomaly probabilities in the input image150of the object. For example and without limitation, heuristics may be used to detect the zero or more anomalies present in the input image150. As such, an anomaly may be detected when an area of the heat-map shows color or illumination values that are higher than a detection threshold.

FIG.6is a sequence diagram showing operations of a method for identifying anomalies in an object in accordance with an embodiment of the present technology. In an embodiment, the method may be a computer-implemented method. OnFIG.6, a sequence500comprises a plurality of operations, some of which may be executed in variable order, some of the operations possibly being executed concurrently, some of the operations being optional. Initially, the system100,200or300has been trained using (a) a set of augmented anomaly-free images of the object applied at the image encoder and (b) a reconstruction loss calculated based on a norm of differences between each augmented anomaly-free image of the object and a corresponding output image from the image decoder. The system200or300may further have been trained using one or more sets of augmented anomalous images and using corresponding labels.

The sequence500may begin at operation510by supplying, to the image encoder105, an input image150of the object, the input image150of the object containing zero or more anomalies. At operation520, the image encoder105generates an image model. Operation520may include one or more sub-operations502and504. In sub-operation502, the image encoder105maps pixels of the input image150of the object into the image model. At sub-operation504, the image encoder105places the image model in the latent space115.

The generated image model to is applied to the image decoder120at operation530. Then at operation540, the image decoder120forms the regenerated image155, which is a substitute non-anomalous image of the object. Operation540may include sub-operation542, in which the image decoder120maps the image model from the latent space115into pixels of the substitute non-anomalous image of the object.

Optionally, the sequence500may include a post-processing operation that generates an anomaly map identifying the zero or more areas of the input image of the object that contain the zero or more anomalies. The anomaly map may identify zero or more areas of the input image of the object that contain the zero or more the anomalies. In an embodiment, the anomaly map is a heat-map in which distinct colors or shades reflect corresponding anomaly probabilities in the input image of the object.

FIG.7is a sequence diagram showing operations of a method for training the anomaly detection system ofFIG.1in an object in accordance with an embodiment of the present technology. OnFIG.7, a sequence600comprises a plurality of operations, some of which may be executed in variable order, some of the operations possibly being executed concurrently, some of the operations being optional. The sequence600includes operations aimed at training the system100in unsupervised mode. Of course, the systems200and300may be also be trained in unsupervised mode, although such training mode would not allow to use the full potential of these systems.

At operation610, a set of anomaly-free images is supplied to the image encoder105. The anomaly-free images may be augmented by adding an alteration to each of a plurality of anomaly free images110of the object that are used for training the system100. Each anomaly-free image may be augmented, for example and without limitation, by adding thereto one or more alterations such as a random noise, a random cropping, a random rotation, a random set of white patches and a random set of black patches.

The system100is then trained, at operation620, using the set of augmented anomaly-free images of the object a mean and a standard deviation of the flow-based model. In an embodiment, the flow-based model may be in the form of a Gaussian model in which errors have a null mean and a predetermined standard deviation. Operation620may include one or more sub-operations620,622,624and626.

At sub-operation622, a reconstruction loss may be calculated based on a norm of differences between each augmented anomaly-free image of the object and a corresponding output image from an image decoder. At sub-operation624, a loss likelihood may be calculated based on a ratio of an output of a current layer of the flow-based model over an output of a previous layer of the flow-based model. At sub-operation626, a regularization loss may be calculated based on a ratio of the output of the previous layer of the flow-based model over the output of the current layer of the flow-based model. Generally speaking, the training engine400may use one of more of these loss values in training the system100, forming a trained model in the latent space115.

FIGS.8aand8bare a sequence diagram showing operations of a method for training the anomaly detection system ofFIG.2or3in an object in accordance with an embodiment of the present technology. OnFIGS.8aand8b, a sequence700comprises a plurality of operations, some of which may be executed in variable order, some of the operations possibly being executed concurrently, some of the operations being optional. The sequence700includes operations aimed at training the systems200and300in semi-unsupervised mode.

As shown onFIG.8a, a set of augmented anomaly-free images is formed, at operation710, by adding an alteration to each anomaly free image of the object used for training the system200or300. Operation710may be the same or equivalent to operation610ofFIG.7. A set of augmented anomalous images is supplied to the image encoder105for each of one or more anomaly types at operation720. At operation730, labels are supplied to the anomaly encoder245, each label corresponding to one of the anomalous images and identifying a related anomaly type. Non-limiting examples of anomaly types may include one or a combination of a scratch, a crack, a color, a spot, a hole, and a discoloration. Given that one or more anomaly types are defined, the resulting flow-based model may comprise one or more modes, each mode of the flow-based model corresponding to one of one or more anomaly types, each mode having a corresponding mean and a corresponding standard deviation. At operation740, the anomaly encoder245calculates a vector containing a mean for each of one or more flow-based model modes defined to correspond to the one of more anomaly types. Similarly, at operation750, the anomaly encoder245calculates another vector containing a standard deviation for each of the one or more flow-based model modes defined for the one of more anomaly types.

Continuing onFIG.8b, the system200or300is trained in semi-supervised mode at operation760, using the set of augmented anomaly-free images of the object and the one or more sets of augmented anomalous images applied to the image encoder105, the training also using the means and standard deviations of the one or more modes of the flow-based model. Operation760may include one or more sub-operations762,764,766,768,772,774and776.

At sub-operation762, a reconstruction loss may be calculated based on a norm of differences between each augmented anomaly-free image of the object and a corresponding output image from an image decoder. A loss likelihood may be calculated at sub-operation764based on a ratio of an output of a current layer of the flow-based model over an output of a previous layer of the flow-based model. A regularization loss may be calculated at sub-operation766based on a ratio of the output of the previous layer of the flow-based model over the output of the current layer of the flow-based model

At sub-operation768, the labels may be supplied to the classifier260. At sub-operation772, the classifier260may be supplied with a content of the latent space115. The classifier260may use the content of the latent space115to classify each of the one or more anomaly types at sub-operation774. At sub-operation776, the classifier260may calculate a classification loss for each of the anomaly types.

As expressed in the description of the sequence600, the training engine400may use one of more of the loss values calculated at operation760and in its sub-operations for training the system200or300, forming a trained model in the latent space115. The training engine400may further use classification values obtained from the classifier260in training the system200or300.

FIGS.9aand9bare a sequence diagram showing operations of a method for retraining the anomaly detection system ofFIG.3in an object in accordance with an embodiment of the present technology. OnFIGS.9aand9b, a sequence800comprises a plurality of operations, some of which may be executed in variable order, some of the operations possibly being executed concurrently, some of the operations being optional. The sequence800includes operations aimed at retraining the system300after it has been initially trained using the operations of the sequence700.

As shown onFIG.9a, at operation810, an additional set of augmented anomalous images is supplied to the image encoder105for each of one or more additional anomaly types. At operation820, the anomaly encoder245is supplied with additional labels, each additional label corresponding to one of the anomalous images of the additional sets and identifying an additional anomaly type. Usually, the additional anomaly types will differ from those used in the initial training of the system300. However, retraining of the system300will operate correctly in case some anomaly types are repeated in the set of additional anomaly types.

At operation830, the anomaly encoder245calculates a vector containing a mean for each of the one or more flow-based model modes defined to correspond to the one of more anomaly types and to each of one or more additional flow-based model modes defined for the one or more additional anomaly types. Similarly, at operation840, the anomaly encoder245calculates another vector containing a standard deviation for each of the one or more flow-based model modes defined to correspond to the one of more anomaly types and to each of one or more additional flow-based model modes defined for the one or more additional anomaly types.

Continuing onFIG.9b, at operation850, a statistically sufficient sample of information contained in the vectors that contain the mean and the standard deviation for each of the one or more flow-based model modes defined for the one of more anomaly types and, optionally, for each of the one or more additional flow-based model modes defined for the one or more additional anomaly types is supplied to the latent space115. The system300is retrained at operation860using the one or more additional sets of augmented anomalous images applied to the image encoder105, the training also using and the means and standard deviations of the one or more modes of the flow-based model. In an embodiment, operation860may be similar or equivalent to operation760and may include some or all of the same sub-operations762,764,766,768,772,774and776. In particular, operation860may include one or more sub-operations862,864,866and868.

At sub-operation862, the additional labels may be supplied to the classifier260. At sub-operation864, the classifier260may be supplied with a content of the latent space115. The classifier260may use the content of the latent space115to classify each of the one or more additional anomaly types at sub-operation866. At sub-operation868, the classifier260may calculate a classification loss for each of the additional anomaly types.

As expressed in the description of the previous sequences, the training engine400may use one of more of the loss values calculated at operation860and in its sub-operations for retraining the system300by updating the trained model in the latent space115. In an embodiment, the various operations of the sequence800may be executed to retrain the system300without causing any downtime of the system300.

While the sequence800has been described in relation to the flow-based model as described in relation to the systems100,200and300, the same or equivalent continuous training method may be applied to other systems that are designed to identify anomalies in an image of an object. The technology used in the sequence800may be generalized to apply to other systems in which an anomaly encoder forms a model of the object in a latent space, for example and without limitation the flow-based model of the systems100,200and300, a generative adversarial network model or a variational autoencoder model. In at least some embodiments, classification information for each of the one or more anomaly types and for each of the one or more additional anomaly types may be used when forming and updating the model of the object in the latent space.

Each of the operations of the sequences500,600,700and/or800may be configured to be processed by one or more processors, the one or more processors being coupled to a memory device. For example,FIG.10is a block diagram showing internal components of the anomaly detection system100,200or300according to any one ofFIGS.1,2and3in accordance with an embodiment of the present technology. The system100,200or300comprises a processor or a plurality of cooperating processors (represented as a processor170for simplicity), a memory device or a plurality of memory devices (represented as a memory device175for simplicity), an input/output device or a plurality of input/output devices (represented as an input/output device180for simplicity), allowing the system100,200or300to receive the input images110and150from an image source185, to transmit the regenerated images125and155to an image receiver190and, optionally, to communicate with the post-processor160. Separate input devices and output devices (not shown) may be present instead of the input/output device180. The processor170is operatively connected to the memory device175and to the input/output device180. The memory device175includes a storage176for storing parameters, including for example the latent space115. The memory device175may comprise a non-transitory computer-readable medium177for storing instructions that are executable by the processor175to cause the processor170to execute the various functions and features of the system100,200or300, including the operations of the sequences500,600,700and/or800.

The training engine400may be implemented jointly with the system100,200or300, sharing the same processor170and the same memory device175, which may be further adapted to perform the various features of the training engine400introduced in the description ofFIG.4. Alternatively, the training engine400may be implemented in a separate physical entity having its own processor and memory device, also including an input/output device allowing interoperability with the system100,200or300.

FIG.11illustrates a first object having anomalies and a heat-map displaying anomaly probabilities on the first object, the heat-map being generated accordance with an embodiment of the present technology. The object on the left-hand side ofFIG.11is a capsule on which some markings (a logo, letters and digits) have not been properly printed or have been partially erased. On the right-hand side, the heat-map reproduces an outline of the capsule, generally with dark shades or colors. Lighter areas of the heat-map reveal high probabilities of anomalies on the image of the capsule. There is good consistency between the heat-map and the visible defects on the capsule.

FIG.12illustrates a second object having anomalies and a heat-map displaying anomaly probabilities on the second object, the heat-map being generated accordance with an embodiment of the present technology. The object on the left-hand side ofFIG.12is an acorn on showing an elongated scratch as well as shorter scratches on each side thereof. On the right-hand side, the heat-map reproduces an outline of the acorns, generally with dark shades or colors. Lighter areas of the heat-map reveal high probabilities of anomalies on the image of the acorn. There is good consistency between the heat-map and the visible defects on the acorn.

FIG.13illustrates a third object having anomalies and a heat-map displaying anomaly probabilities on the third object, the heat-map being generated accordance with an embodiment of the present technology. The object on the left-hand side ofFIG.13is a pill having a plurality of dark spots on its surface. On the right-hand side, the heat-map reproduces an outline of the pill, generally with dark shades or colors. Lighter areas of the heat-map reveal high probabilities of anomalies on the image of the pill. There is good consistency between the heat-map and the visible defects on the pill.

FIG.14illustrates a fourth object having anomalies and a heat-map displaying anomaly probabilities on the fourth object for a set of anomaly types, the heat-map being generated accordance with an embodiment of the present technology. The object on the left-hand side ofFIG.14is a metallic nut having a plurality of anomalies. It may be observed that two main anomalies are present, respectively on the left part and on the right part of the metallic nut. The right-hand side ofFIG.14shows the heat-map reproducing an outline of the metallic nut, generally with dark shades or colors. Lighter areas of the heat-map reveal high probabilities of anomalies on the image of the metallic nut. There is good consistency between the heat-map and the visible defects on the metallic nut. The heat-map may have been obtained following training of either of the systems200or300with a set of anomaly types including at least the anomalies present on the left and right parts of the metallic nut.

FIG.15illustrates the fourth object ofFIG.14having new anomalies and a heat-map displaying anomaly probabilities on the fourth object for another set of anomaly types, the heat-map being generated accordance with an embodiment of the present technology. The metallic nut shown on the left-hand side ofFIG.15shows, on its left part, an anomaly that is similar to the anomaly shown on the left part of the metallic nut ofFIG.14. The metallic nut ofFIG.15however shows, on its right part, a new type of anomaly. The right-hand side ofFIG.15shows the heat-map reproducing an outline of the metallic nut, generally with dark shades or colors. Lighter areas of the heat-map reveal high probabilities of anomalies on the image of the metallic nut. There is good consistency between the heat-map and the visible defects on the metallic nut. In particular, the heat-maps ofFIGS.14and15may have been obtained following training of the system300, initially with a first set of anomaly types including the anomalies present on the left and right parts of the metallic nut ofFIG.14, the system300being later retrained with a second set of anomaly types including new anomaly present on the right part of the metallic nut ofFIG.15.

Experimental results have been obtained using the anomaly detection system300. For each of many repetitions of the experiments, the model of the system300was initially trained with a first set including 6 anomaly types and then retrained with a second set including 6 new anomaly types. There was no overlap between the anomaly types of the first and second sets.

While conventional anomaly detection technologies lose performance in the detection of old anomaly types after being retrained with newer anomaly types, the experimental results obtained using the system300show a 30% improvement in the anomaly detection performance for the first set when the model was retrained with the second set. When compared with conventional image detection technologies, anomaly detection accuracy was improved by 28% for the second set. An amount of memory consumed by the latent space was reduced by approximately 50%. At inference time, anomaly detection was about twice as fast as when using conventional image detection technologies.

While the above-described implementations have been described and shown with reference to particular steps performed in a particular order, it will be understood that these steps may be combined, sub-divided, or re-ordered without departing from the teachings of the present technology. At least some of the steps may be executed in parallel or in series. Accordingly, the order and grouping of the steps is not a limitation of the present technology.

It should be expressly understood that not all technical effects mentioned herein need to be enjoyed in each and every embodiment of the present technology.