# Normalizing Flows for Out-of-Distribution Detection: Application to Coronary Artery Segmentation
## 1 Introduction
Regular confidence methods do not provide a reason why the output confidence is low, and the class separation learnt by the model is highly dependent on the target task and on the model architecture. Normalizing Flow (NF) models on the other hand can be trained explicitly to model input data probability densities. Given a downstream target task \(T\), if only its input data is employed for building the NF model, then estimating the likelihood of input samples for the target task can be obtained through the NF model. Input samples with low probabilities can be flagged as out-of-distribution and the target model's output should be considered unreliable, as it would operate outside its training distribution. An NF model can also be built by stacking the input samples with their expected GT output. This way, the NF model can be placed downstream of the target task and act as an Audit model, detecting cases where the previous model provided faulty predictions. In either scenario, the NF is a separate model and therefore imposes no constraints on the model responsible for the target task. NFs are a class of generative models which can perform exact log-likelihood computation. They have been employed in various setups, for instance:* Image generation[10; 11]: Being reversible models, random samples from the prior distribution can be transformed into the data domain, therefore obtaining new synthetic datapoints. * Prior for variational inference: Instead of employing a fixed distribution (usually the normal distribution) in the KL term for ELBO maximization in variational inference, NF can be employed to model a much more expressive prior distribution. In a variational auto-encoder (VAE), this allows the encoder to better capture input patterns by not placing a fixed constraint on its computed embeddings. [PERSON] and [PERSON] [12] employed such a method for character-level language modeling and polyphonic music generation. * Out-of-Distribution (OoD) detection: As log-likelihood values can be exactly and efficiently computed, NF may be good candidates in outlier detection [13]. NF can usually operate efficiently in both directions: forward (or inference) direction, where input samples \(x\) from the input domain \(X\) are transformed into embeddings \(z\) which are likely under a chosen distribution \(Z\). At each layer, the input is modified towards \(Z\) and the _logDet_ value (i.e., \(\ln\left(\left|\det\left(\frac{\partial f}{\partial x}\right)\right|\right)\), where \(f\) is the NF) is summed with the current layer contribution. The backward (or generative) direction employs the bijection property of the NF to transform an embedding \(z\) into a synthetic sample \(x_{new}\). Refs. [14; 15] offer an introduction and review into the current approaches used in the NF framework. In this paper, we present an approach based on NF for the OoD detection of coronary lumen segmentations. NF models which are built from coupling layers as proposed in [10; 11] tend to focus on local pixel correlations instead of the global semantic meaning [13; 16] and, as a result, OoD samples may in fact produce larger log-probability values than in-distribution data. We investigate the usage of a new type of coupling layer, which employs reversible \(1\times 1\) convolutions in which the filter parameters are computed based on the passed-through components. We compare the proposed architecture against a Glow-like architecture on the task of detecting mismatched pairs of CCTA lumen images and their corresponding lumen segmentations. The coronary lumen images and masks are 3D volumes stacked along the channel axis. We also employ synthetic perturbations on the binary masks and use the perturbed samples as explicit outliers to further shape the learnt probability density of \"correct\" image-mask pairs. The end goal is to flag those samples for which the given segmentation does not properly match with the lumen image.