# Normalizing Flows for Out-of-Distribution Detection: Application to Coronary Artery Segmentation
## 2 Methods
### NF Architectures
The applied bias is broadcasted to all spatial positions, therefore is it the same across the width, height and depth of the resulting tensor, meaning that the layer is no longer capable to reproduce masked pixel values as revealed in [13]. The same (sample specific) convolution kernel is applied at all spatial positions, in contrast to the element-wise computation done in (1). This behavior is similar to classical CNNs, with the exception that now the filter weights are not the same for all samples. Equation (2) describes the layer's operation, with simplified notation: \(*\) means \(1\times 1\) Convolution with kernel \(k\) and \(+\) is a broadcasting sum. \(k\) is computed by a CNN and has shape \(c_{modif}\)-by-\(c_{modif}\), where \(c_{modif}\) is the number of channels which are updated. \(b\) is a vector of \(c_{modif}\) elements. The CNN responsible for computing \(k\) and \(b\) is described in Table 3.  
\[y_{a} =x_{a} \tag{2}\] \[y_{b} =x_{a}*k(x_{a})+b(x_{a})\]  
It is observed that the layer is self-conditioned, i.e., it does not employ an external conditioning network or another parallel flow as in [23; 24], since the lumen binary mask and the angiographic image were not treated separately, but were concatenated on the channel axis. This is possible because the mask and the image should be highly correlated spatially in order to achieve high log-probability. A new NF architecture was designed employing the above coupling layer. The first stage is a sequence of Additive Coupling Layers with checkerboard masking. According to [13], these layers will focus mainly on local pixel correlations, but this is equivalent to the functioning of the first layers in classical CNNs, where the receptive field-of-view is small and the filters tend to search for simple patterns such as corners, edges, textures, etc. As opposed to affine couplings, additive couplings are volume preserving, i.e., they do not contribute directly to logDet and final \(\log(p(x))\), but indirectly through the upstream layers. The next stages consist of cascades of coupling layers, as described in Figure 2 and Table 4. In contrast to a classical CNN, where filters of shape 3 \(\times\) 3 (or larger) and strides larger than 1 are used (either in convolutional or max pool layers) to increase the effective field-of-view (FoV), in our architecture the FoV in these stages is increased solely by the squeeze operations. After squeezing, a 1 \(\times\) 1 \(\times\) 1 patch of pixels is formed from a patch of 2 \(\times\) 2 \(\times\) 2 pixels which were flattened spatially into the channel dimension. Therefore, the FoV doubles on each spatial axis for each squeeze step. This allows 1 \(\times\) 1 Convolutions to operate on increasingly larger FoV, similar to the functioning of a classical CNN, while still retaining the capability of efficient forward/backward NF computation. There are enough squeeze operations so that the resolution on the last stage decays to 1 \(\times\) 1. Naturally, we restrict the input spatial dimensions to be powers of 2. One possible disadvantage is that after each squeeze operation, the number of channels \(c_{i}\) (at stage \(i\)) increases exponentially with the number of squeezed dimensions (see Table 4). This directly impacts the proposed coupling layer's runtime and complexity, since it must produce matrix \(k\) whose size scales with the square of \(c_{i}\). In addition, inference and sampling involve computing the determinant and inverse of \(k\), respectively. One workaround to alleviate this issue is to modify the splitting layers so that the tensors are not split in half along the channel axis anymore, but instead only a quarter is retained for the rest of the computation graph while the other 75% of channels are factored out. This can be applied especially in the first stages, where the embeddings mostly describe texture. After such a split, the input to the next squeeze has only \(c_{i}/4\) channels, half that of a regular split.