Pixel-wise Gradient Uncertainty for Convolutional Neural Networks
  applied to Out-of-Distribution Segmentation
In recent years, deep neural networks have defined the state-of-the-art in
semantic segmentation where their predictions are constrained to a predefined
set of semantic classes. They are to be deployed in applications such as
automated driving, although their categorically confined expressive power runs
contrary to such open world scenarios. Thus, the detection and segmentation of
objects from outside their predefined semantic space, i.e., out-of-distribution
(OoD) objects, is of highest interest. Since uncertainty estimation methods
like softmax entropy or Bayesian models are sensitive to erroneous predictions,
these methods are a natural baseline for OoD detection. Here, we present a
method for obtaining uncertainty scores from pixel-wise loss gradients which
can be computed efficiently during inference. Our approach is simple to
implement for a large class of models, does not require any additional training
or auxiliary data and can be readily used on pre-trained segmentation models.
Our experiments show the ability of our method to identify wrong pixel
classifications and to estimate prediction quality at negligible computational
overhead. In particular, we observe superior performance in terms of OoD
segmentation to comparable baselines on the SegmentMeIfYouCan benchmark,
clearly outperforming other methods.
Kira Maag, Tobias Riedlinger
Pixel-wise Gradient Uncertainty for Convolutional Neural Networks applied to Out-of-Distribution Segmentation

###### Abstract

In recent years, deep neural networks have defined the state-of-the-art in semantic segmentation where their predictions are constrained to a predefined set of semantic classes. They are to be deployed in applications such as automated driving, although their categorically confined expressive power runs contrary to such open world scenarios. Thus, the detection and segmentation of objects from outside their predefined semantic space, i.e., out-of-distribution (OoD) objects, is of highest interest. Since uncertainty estimation methods like softmax entropy or Bayesian models are sensitive to erroneous predictions, these methods are a natural baseline for OoD detection. Here, we present a method for obtaining uncertainty scores from pixel-wise loss gradients which can be computed efficiently during inference. Our approach is simple to implement for a large class of models, does not require any additional training or auxiliary data and can be readily used on pre-trained segmentation models. Our experiments show the ability of our method to identify wrong pixel classifications and to estimate prediction quality. In particular, we observe superior performance in terms of OoD segmentation to comparable baselines on the SegmentMelfYouCan benchmark, clearly outperforming methods which are similarly flexible to implement.

+
Footnote †: * equal contribution

## 1 Introduction

Semantic segmentation decomposes the pixels of an input image into segments which are assigned to a fixed and pre-defined set of semantic classes. In recent years, deep neural networks (DNNs) have performed excellently in this task (Chen et al., 2018; Wang et al., 2021), providing comprehensive and precise information about the given scene. However, in safety relevant applications like automated driving where semantic segmentation is used in open world scenarios, DNNs often fail to function properly on unseen objects for which the network has not been trained, see for example the bobby car in Figure 1 (top). These objects from outside the network's semantic space are called of out-of-distribution (OoD) objects. It is of highest interest that the DNN identifies these objects and abstains from deciding on the semantic class for those pixels covered by the OoD object. Another case are OoD objects which might belong to a known class, however, appearing differently to substantial significance from other objects of the same class seen during training. Consequently, the respective predictions are prone to error. For these objects, as for classical OoD objects, marking them as OoD is preferable to the likely case of misclassification which may happen with high confidence. Furthermore, this additional classification task should not substantially degrade the semantic segmentation performance itself outside the OoD region. The computer

Figure 1: _Top_: Semantic segmentation by a state-of-the-art deep neural network. _Bottom_: Gradient uncertainty heatmap obtained by our method.
vision tasks of identifying and segmenting those objects is captured by the notion of OoD segmentation [3, 14].

The recent contributions to the emerging field of OoD segmentation are mostly focused on OoD training, i.e., the incorporation of additional training data (not necessarily from the real world), sometimes obtained by large reconstruction models [1, 13]. Another line of research is the use of uncertainty quantification methods such as Bayesian models [15] or maximum softmax probability [16]. Gradient-based uncertainties are considered for OoD detection in the classification task by Oberdiek et al. [17], Huang et al. [20] and Lee et al. [21] and up to now, have not been applied to OoD segmentation. Grathwohl et al. [20] show that gradient norms perform well in discriminating between in- and out-of-distribution. Moreover, gradient-based features are studied by Riedlinger et al. [2] for object detection to estimate the prediction quality. Hornauer and Belagiannis [2] investigate loss gradients w.r.t. feature activations in monocular depth estimation and show correlations of gradient magnitude with depth estimation accuracy.

In this work, we introduce a new method for uncertainty quantification in semantic segmentation and OoD segmentation based on gradient information. Magnitude features of gradients can be computed at inference time and provide information about the uncertainty propagated in the corresponding forward pass. These features represent pixel-wise uncertainty scores applicable to prediction quality estimation and OoD segmentation. An exemplary gradient uncertainty heatmap can be found in Figure 1 (bottom). Such uncertainty scores have shown improved performance for the quality estimation task in image classification compared to uncertainties contained in the softmax output of DNNs [1]. In addition, instance-wise gradient uncertainty outperforms sampling methods like Monte-Carlo (MC) Dropout [10] and Ensembles [1] in object detection [11]. Calculating gradient uncertainty scores does not require any re-training of the DNN or computationally expensive sampling. Instead, only one backpropagation step for the gradients with respect to the final convolutional network layer is performed per inference to produce gradient scores. Note, that more than one backpropagation step can be performed if deeper gradients need to be computed and other parameters of the model are considered. An overview of our approach is shown in Figure 2.

An application to dense predictions such as semantic segmentation has escaped previous research. Single backpropagation steps per pixel on high-resolution input images quickly become infeasible given that \(10^{6}\) gradients have to be calculated. To overcome this issue, we present a new approach to exactly compute the pixel-wise gradient scores in a batched and parallel manner applicable to a large class of segmentation architectures. We use these gradient scores to estimate the model uncertainty on pixel-level and also the prediction quality on segment-level. Segments are connected components of pixels belonging to the same class predicted by the semantic segmentation network. Finally, the gradient uncertainty heatmaps are investigated for OoD segmentation where high uncertainties indicate possible OoD objects.

We only assume a pre-trained semantic segmentation network as our method is applicable to a wide range of architectures. In our tests, we employ a state-of-the-art segmentation network [3] trained on Cityscapes [15] evaluating in-distribution uncertainty estimation and on four OoD segmentation datasets, namely LostAndFound [13], Fishyscapes [1], RoadAnomaly21 and RoadObstacle21 [2], demonstrating OoD detection performance. The source code of our method is publicly available at [https://github.com/tobiasriedlinger/uncertainty-gradients-seg](https://github.com/tobiasriedlinger/uncertainty-gradients-seg). Our contributions are summarized as follows:

* We introduce a new method for uncertainty quantification in semantic segmentation. Our gradient-based approach is applicable to a wide range of segmentation architectures.
* For the first time, we show an efficient way of computing gradients in semantic segmentation on the pixel-level in a parallel manner making our method less computationally expensive than sampling-based methods.
* For the first time, we demonstrate the robustness of gradient-based uncertainty quantification with respect to predictive error detection and OoD segmentation. For the OoD segmentation task, we achieve area under precision-recall curve values of up to \(69.3\%\) on the LostAndFound benchmark outperforming a variety of methods that have substantially larger requirements.

The paper is structured as follows. We discuss the related work on uncertainty quantification and OoD segmentation in section 2. In section 3, we introduce our method of computing pixel-wise gradient uncertainty scores. Numerical results are shown in section 4, followed by concluding remarks in section 5.

## 2 Related Work

### Uncertainty Quantification

Bayesian approaches [12] are widely used to estimate model uncertainty. The well-known approximation, MC Dropout [10], has proven to be practically efficient in uncertainty estimation and is also
applied to semantic segmentation [11]. In addition, this method is considered to filter out predictions with low reliability [20]. Blum et al. [19] benchmarked pixel-wise uncertainty estimation methods based on Bayesian models or the network's softmax output. Hoebel et al. [20] extracted uncertainty information on pixel-level by using the maximum softmax probability and MC Dropout. Prediction quality evaluation approaches are introduced by DeVries and Taylor [21] and Huang et al. [2016] working on single objects per image. These methods are based on additional CNNs acting as post-processing mechanism. Rottmann et al. [20] present the concepts of meta classification (false positive detection) and meta regression (performance estimation) on segment-level using features as input extracted from the segmentation network's softmax output. This line of research has been extended by a temporal component [14] and transferred to object detection [15, 16] as well as to instance segmentation [14, 17].

While MC Dropout as a sampling approach is computationally expensive to create pixel-wise uncertainties, our method computes only the gradients of the last layer during a single inference run and can be applied to a wide range of semantic segmentation networks without architectural changes. Compared with the work by Rottmann et al. [20], our gradient information can extend the features extracted from the segmentation network's softmax output to enhance the segment-wise quality estimation.

### OOD Segmentation

Uncertainty quantification methods demonstrate high uncertainty for erroneous predictions, so they can intuitively serve for OOD detection as well. For instance, this can be accomplished via maximum softmax (probability) [10], MC Dropout [13] or ensembles [12] which capture model uncertainty by averaging predictions over multiple sets of parameters. Another line of research is OOD detection training, relying on the exploitation of additional training data, not necessarily from the real world, but disjoint from the original training data [1, 14, 15, 16, 17, 18]. In this regard, an external reconstruction model followed by a discrepancy network are considered by Biase et al. [20], Lis et al. [20] and Vojir et al. [20] and normalizing flows are leveraged by Blum et al. [19] and Grcic et al. [20]. Liang et al. [2018] as well as Lee et al. [2018] perform small adversarial perturbations on the input images to improve the separation of in- and out-of-distribution samples.

Specialized training approaches for OOD detection are based on different kinds of re-training with additional data and often require generative models. Meanwhile, our method does not require OOD data, re-training or complex auxiliary models. Moreover, we do not run a full backward pass as is required for the computation of adversarial samples. In fact we found that it is often sufficient to only compute the gradients of the last convolutional layer. Our method is more related to classical uncertainty quantification approaches like maximum softmax, MC Dropout and ensembles. Note that the latter two are based on sampling and thus, much more computationally expensive compared to single inference.

## 3 Method Description

In the following, we consider a neural network with parameters \(\theta\) yielding classification probabilities

\[\hat{\pi}(x,\theta)=(\hat{\pi}_{1},\dots,\hat{\pi}_{C}) \tag{1}\]

over \(C\) semantic categories when presented with input \(x\). During training on paired data \((x,y)\) where \(y\in\{1,\dots,C\}\) is the semantic label given to \(x\), such a model is commonly trained by minimizing some kind of loss function \(\mathcal{L}\) between \(y\) and the predicted probability distribution \(\hat{\pi}(x,\theta)\) using gradient descent on \(\theta\). The gradient step \(\nabla_{\theta}\mathcal{L}(\hat{\pi}(x,\theta)\|y)\) then indicates the direction and strength of training feedback obtained by \((x,y)\). Asymptotically (in the amount of data and training steps taken), the expectation

\[\mathbb{E}_{(X,Y)\sim P}[\nabla_{\theta}\mathcal{L}(\hat{\pi}(X,\theta)\|Y)] \tag{2}\]

of the gradient w.r.t. the data generating distribution \(P\) will vanish since \(\theta\) sits at a local minimum of \(\mathcal{L}\). We assume, that strong models which achieve high test accuracy can be seen as an approximation of such a parameter configuration \(\theta\). Such a model has small gradients on in-distribution data which is close to samples \((x,y)\) in the training data. Samples that differ from training data will receive larger feedback. Like-wise, we assume large training gradients from OOD samples that are far away from the effective support of \(P\).

In order to quantify uncertainty about the prediction \(\hat{\pi}(x,\theta)\), we replace the label \(y\) from above by some auxiliary label for which we make two concrete choices in our method. On the one hand, we replace \(y\) by the class prediction one-hot vector \(y_{k}^{oh}=\delta_{k\hat{c}}\) with \(\hat{c}=\operatorname*{arg\,max}_{k=1,\dots,C}\hat{\pi}_{k}\) and the Kronecker symbol \(\delta_{ij}\). This quantity correlates strongly with training labels on in-distribution data. On the other hand, we regard a uniform, all-warm label \(y_{k}^{uni}=1/C\) for \(k=1,\dots,C\) as a replacement for \(y\). To motivate the latter choice, we consider that classification models are oftentimes trained on the categorical cross entropy loss

\[\mathcal{L}(\hat{\pi}\|y)=-\sum_{k=1}^{C}y_{k}\log(\hat{\pi}_{k}). \tag{3}\]

Since the gradient of this loss function is linear in the label \(y\), a uniform choice will return the average gradient per class
which should be high on OoD data where all possible labels are similarly unlikely. The magnitude of \(\nabla_{\theta}\mathcal{L}(\hat{\pi}\|y)\) serves as uncertainty / OoD score. In the following, we explain how to compute such scores for pixel-wise classification models.

### Efficient Computation in Semantic Segmentation

We regard a generic segmentation architecture utilizing a final convolution as the pixel-wise classification mechanism. In the following, we also assume that the segmentation model is trained via the commonly-used pixel-wise cross entropy loss \(\mathcal{L}_{ab}(\phi(\theta)|y)\) (cf. eq. (3)) over each pixel \((a,b)\) with feature map activations \(\phi(\theta)\). Pixel-wise probabilities are obtained by applying the softmax function \(\Sigma\) to each output pixel, i.e., \(\hat{\pi}_{ab,k}=\Sigma^{k}\left(\phi_{ab}(\theta)\right)\). With eq. (3), we find for the loss gradient

\[\nabla_{\theta}\mathcal{L}_{ab}(\Sigma(\phi(\theta))\|y)=\sum_{k=1}^{C}\Sigma^ {k}(\phi_{ab})(1-y_{k})\cdot\nabla_{\theta}\phi_{ab}^{k}(\theta). \tag{4}\]

Here, \(\theta\) is any set of parameters within the neural network. Detailed derivations of this and the following formulas of this section are provided in Appendix A. Here, \(\phi\) is the convolution result of a pre-convolution feature map \(\psi\) (see Figure 2) against a filter bank \(K\) which assumes the role of \(\theta\). \(K\) has parameters \((K_{e}^{h})_{fg}\) where \(e\) and \(h\) indicate in- and out-going channels respectively and \(f\) and \(g\) index the spatial filter position. The features \(\phi\) are linear in both, \(K\) and \(\psi\), and depend on bias parameters \(\beta\) in the form

\[\phi_{ab}^{d}=(K*\psi)_{ab}^{d}+\beta^{d}=\sum_{j=1}^{\kappa}\sum_{p,q=-s}^{s} (K_{j}^{d})_{pq}\psi_{a+p,b+q}^{j}+\beta^{d}. \tag{5}\]

We denote by \(\kappa\) the total number of in-going channels and \(s\) is the spatial extent to either side of the filter \(K_{j}^{d}\) which has total size \((2s+1)\times(2s+1)\). Explicitly for the last layer gradients we find

\[\frac{\partial\phi_{ab}^{d}}{\partial(K_{e}^{h})_{fg}}=\delta_{dh}\psi_{a+f,b +g}^{e}. \tag{6}\]

Together with eq. (4), we obtain an explicit formula for computing the correct backpropagation gradients of the loss on pixel-level for our choices of auxiliary labels which we state in the following paragraph. The computation of the loss gradient can be traced in Figure 2.

If we take the predicted class \(\hat{c}\) as a one-hot label per pixel as auxiliary labels, i.e., \(y^{oh}\), we obtain for the last layer gradients

\[\frac{\partial\mathcal{L}_{ab}(\Sigma(\phi)\|y^{oh})}{\partial K_{e}^{h}}= \Sigma^{h}(\phi_{ab})\cdot(1-\delta_{h\hat{c}})\cdot\psi_{ab}^{e} \tag{7}\]

which depends on quantities that are easily accessible during a forward pass through the network. Note, that the filter bank \(K\) for \((1\times 1)\)-convolutions does not require spatial indices which is a common situation in segmentation networks. Similarly, we find for the uniform label \(y_{j}^{uni}=1/C\)

\[\frac{\partial\mathcal{L}_{ab}(\Sigma(\phi)\|y^{uni})}{\partial K_{e}^{h}}= \frac{C-1}{C}\Sigma^{h}(\phi_{ab})\psi_{ab}^{e}. \tag{8}\]

Therefore, pixel-wise gradient norms are simple to implement and particularly efficient to compute for the last layer of the segmentation model. In the subsection A.2, we cover formulas for the more general case of deeper gradients as well.

### Uncertainty Scores

We obtain pixel-wise scores (still depending on \(a\) and \(b\)) by computing the partial norm \(\|\nabla_{K}\mathcal{L}_{ab}\|_{p}\) of this tensor over the indices \(e\) and \(h\) for some fixed value of \(p\). This can again be done in a memory efficient way by the natural decomposition \(\partial\mathcal{L}/\partial K_{e}^{h}=S^{h}\cdot\psi^{e}\). In addition to their use in error detection, these scores can be used in order to detect OoD objects in the input, i.e., instances of categories not present in the training distribution of the segmentation network. We identify OoD regions with pixels that have a gradient score higher than some threshold and find connected components like the one shown in Figure 1 (bottom). Different values of \(p\) are studied in the supplementary material. We also consider values \(0<p<1\) in addition to positive integer values. Note, that such choices do not strictly define the geometry of a vector space norm, however, \(\|\cdot\|_{p}\) may still serve as a notion of magnitude and generates a partial ordering. The tensorized multiplications required in eqs. (7) and (8) are far less computationally expensive than a forward pass through the DNN. This means that computationally, this method is preferable over prediction sampling like MC Dropout or ensembles. We abbreviate our method using

Figure 2: Schematic illustration of the computation of pixel-wise gradient norms for a semantic segmentation network with a final \((1\times 1)\)-convolution. Auxiliary labels may be derived from the softmax prediction or supplied in any other way (e.g., as a uniform all-warm label). We circumvent direct back propagation per pixel by utilizing eqs. (7), (8).
the **pixel**-wise **gradient** norms obtained from eqs. (7) and (8) by \(\mathrm{PGN}_{oh}\) and \(\mathrm{PGN}_{uni}\), respectively. The particular value of \(p\) is denoted by superscript, e.g., \(\mathrm{PGN}_{oh}^{p=0.3}\) for the (\(p=0.3\))-seminorm of gradients obtained from \(y^{oh}\).

## 4 Experiments

In this section, we present the experimental setting first and then evaluate the uncertainty estimation quality of our method on pixel and segment level. Last, we apply our gradient-based method to OoD segmentation and show some visual results.

### Experimental Setting

DatasetsWe perform our tests on the Cityscapes [11] dataset for semantic segmentation in street scenes and on four OoD segmentation datasets, i.e., LostAndFound [13], Fishyscapes [12], RoadAnomaly21 and RoadObstacle21 [1]1. The Cityscapes dataset consists of \(2{,}975\) training and \(500\) validation images of dense urban traffic in \(18\) and \(3\) different German towns, respectively. The LostAndFound dataset contains \(1{,}203\) validation images with annotations for the road surface and the OoD objects, i.e., small obstacles on German roads in front of the ego-car. In [1] this dataset is filtered (LostAndFound test-NoKnown) as children and bicycles are considered as OoD objects, although they are included in the Cityscapes training set. The Fishyscapes LostAndFound dataset is based on the LostAndFound dataset and refines the pixel-wise annotations, i.e., it is distinguished between OoD objects, background (Cityscapes classes) and void (anything else). Moreover frames that do not contain OoD objects as well as sequences with children and bikes are removed resulting in \(100\) validation images (and \(275\) non-public test images). The RoadObstacle21 dataset (\(412\) test images) is comparable to the LostAndFound dataset as all obstacles appear on the road. However, the RoadObstacle21 dataset contains more diversity in the OoD objects as well as in the situations (night, snowy conditions and dirty roads) compared to the LostAndFound dataset where all sequences are recorded under good weather conditions. In the RoadAnomaly21 dataset the objects (anomalies) appear anywhere on the image which makes it comparable to the Fishyscapes LostAndFound dataset. While the latter dataset consists of frames extracted from a small number of different scenes, every image of the RoadAnomaly21 dataset (\(100\) test images) shows a unique scene and a wider variety of anomalous objects.

Footnote 1: Benchmark: ([http://segmentmeifyoucan.com/](http://segmentmeifyoucan.com/))

Segmentation NetworksWe consider a state-of-the-art DeepLabv3+ network [1] with two different backbones, WideResNet38 [22] and SEResNeXt50 [20]. The network with each respective backbone is trained on Cityscapes achieving a mean IoU value of \(90.58\%\) for the WideResNet38 backbone and \(80.76\%\) for the SEResNeXt50 on the Cityscapes validation set. We use one and the same model trained exclusively on the Cityscapes dataset for both tasks, the uncertainty estimation and the OoD segmentation, as our method does not need to be re-trained on OoD data. Therefore, our method leaves the entire segmentation performance of the base model completely intact.

### Numerical Results

In our experiments, we apply different \(p\)-norms, \(p\in\{0.1,0.3,0.5,1,2\}\), to our calculated gradients, see subsection 3.2. As we provide only a selection of results in the following, we refer to Appendix D for an ablation study on different values for \(p\) and to Appendix E for further results where the gradients of deeper layers are computed.

Pixel-wise Uncertainty EvaluationIn order to assess the correlation of uncertainty and prediction errors on the pixel level, we resort to the commonly used sparsification graphs [23]. Sparsification graphs normalized w.r.t. the optimal oracle (sparsification error) can be compared in terms of the so-called area under the sparsification error curve (AuSE). The closer the uncertainty estimation is to the oracle in terms of Brier score evaluation, i.e., the smaller the AuSE, the better the uncertainty eliminates false predictions by the model.

The AuSE metric is capable of grading the uncertainty ranking, however, does not address the statistics in terms of given confidence. Therefore, we resort to an evaluation of calibration in terms of expected calibration error (ECE, [11]) to assess the statistical reliability of the uncertainty measure.

As baseline methods we consider quantities that can be obtained without modifying the segmentation model (like MC Dropout) or retraining (like deep ensembles) and which do not need additional data (like re-calibration confidences). Our choices fall on the uncertainty ranking provided by the maximum softmax probabilities native to the segmentation

\begin{table}
\begin{tabular}{l|c c|c c} \hline \hline  & \multicolumn{2}{c|}{WideResNet} & \multicolumn{2}{c}{SEResNeXt} \\ \hline  & ECE \(\downarrow\) & AuSE \(\downarrow\) & ECE \(\downarrow\) & AuSE \(\downarrow\) \\ \hline Maximum Softmax & \(0.0017\) & \(0.0277\) & \(0.0032\) & \(0.0327\) \\ Entropy & \(0.0063\) & \(0.0642\) & \(0.0066\) & \(0.0623\) \\ \(\mathrm{PGN}_{oh}^{p=2}\) (ours) & \(0.0019\) & \(0.0268\) & \(0.0039\) & \(0.0365\) \\ \(\mathrm{PGN}_{uni}^{p=0.1}\) (ours) & \(0.0186\) & \(0.0784\) & \(0.0346\) & \(0.0427\) \\ \hline \hline \end{tabular}
\end{table}
Table 1: Pixel-wise uncertainty evaluation results for both backbone architectures and the Cityscapes dataset in terms of ECE and AuSE.
model as well as the softmax entropy. An evaluation of calibration errors requires normalized scores, so we will normalize our gradient scores according to the highest value obtained on the test data for the computation of ECE.

The resulting metrics are compiled in Table 1 for both architectures evaluated on the Cityscapes val split. We see that both, the uncertainty ranking and the calibration of \(\text{PGN}_{oh}\) are roughly on par with the stronger maximum softmax baseline. Generally, we see the trend that \(\text{PGN}_{uni}\) has higher calibration error by one order of magnitude and higher sparsification errors of up to \(5.2\) percentage points (pp) which may indicate that this kind of score is less indicative of in-distribution errors. Note, that although there is no immediate reason for \(\text{PGN}_{oh}\) to be calibrated in any way, we find calibration errors that are competitive on pixel-level with those of the maximum softmax.

Segment-wise Prediction Quality EstimationTo reduce the number of false positive predictions and to estimate the prediction quality, we use meta classification and meta regression introduced by [14]. As input for the post-processing models, the authors use information from the network's softmax output which characterize uncertainty and geometry of a given segment like the segment size. The degree of randomness in semantic segmentation prediction is quantified by pixel-wise quantities, like entropy and probability margin. To obtain segment-wise features from these quantities, they are aggregated over segments via average pooling. These features used in [14] serve as a baseline in our tests (called MetaSeg).

Similarly, we construct segment-wise features from our pixel-wise gradient \(p\)-norms for \(p\in\{0.1,0.3,0.5,1,2\}\). We compute the mean and the variance of these pixel-wise values over a given segment. These features per segment are considered also for the inner and the boundary since the gradient scores may be higher on the boundary of a segment, see Figure 1 (bottom). The inner of the segment consists of all pixels whose eight neighboring pixels are also elements of the same segment. Furthermore, we define some relative mean and variance features over the inner and boundary which characterizes the degree of fractality. These hand-crafted quantities form a structured dataset where the columns correspond to features and the rows to predicted segments which serve as input to the post-processing models. Details on the construction of these features can be found in Appendix B.

We determine the prediction accuracy of semantic segmentation networks with respect to the ground truth via the segment-wise intersection over union (IoU, [12]). On the one hand, we perform the direct prediction of the IoU (meta regression) which serves as prediction quality estimate. On the other hand, we discriminate between \(\text{IoU}=0\) (false positive) and \(\text{IoU}>0\) (true positive) (meta classification). We use linear classification and regression models.

For the evaluation, we use AuROC (area under the receiver operating characteristic) for meta classification and the determination coefficient \(R^{2}\) for meta regression. As baselines, we employ the maximum softmax probability [14], the entropy and the MetaSeg framework. A comparison of these methods and our approach for the Cityscapes dataset is given in Figure 3. For the evaluation, we separate the gradient features obtained by one-hot (\(\text{PGN}_{oh}\)) and by uniform (\(\text{PGN}_{uni}\)) labels. Also, we consider using all gradient features (PGN) as input to the meta models. With PGN, we outperform the maximum softmax and the entropy baselines as well as the MetaSeg performance with the only exception of meta classification for the SEResNeXt backbone where MetaSeg achieves a marginal \(0.41\) pp higher AuROC value than ours. Moreover, we enhance the MetaSeg performance for both networks and both tasks combining the MetaSeg features with PGN by up to \(1.02\) pp for meta classification and up to \(3.98\) pp for meta regression. This indicates that gradient features contain information which is orthogonal to the information contained in the softmax output. In particular, the highest AuROC value of \(93.31\%\) achieved for the WideResNet backbone, shows the capability of our approach to estimate the prediction quality and filter out false positive predictions on the segment-level.

Figure 3: Segment-wise uncertainty evaluation results for both backbone architectures and the Cityscapes dataset in terms of classification AuROC and regression \(R^{2}\) values. From left to right: maximum softmax, mean entropy, MetaSeg (MS) approach, gradient features obtained by predictive one-hot labels (\(\text{PGN}_{oh}\)), gradient features obtained by uniform labels (\(\text{PGN}_{uni}\)), all gradient features in combination (PGN), MetaSeg in combination with our gradient features.
OoD SegmentationOur results in OoD segmentation are based on the evaluation protocol of the SegmentMelfY-ouCan benchmark[1]. Evaluation on the pixel-level involves the threshold-independent area under precision-recall curve (AuPRC) and the false positive rate at the point of \(0.95\) true positive rate (FPR\({}_{05}\)). The latter constitutes an interpretable choice of operating point for each method where a minimum true positive fraction is dictated. On segment-level, an adjusted version of the mean intersection over union (sIoU) which represents the accuracy of the segmentation obtained by thresholding at a particular point, positive predictive value (PPV or Precision) playing the role of binary instance-wise accuracy and the \(F_{1}\)-score. The latter segment-wise metrics are averaged over thresholds between \(0.25\) and \(0.75\) with a step size of \(0.05\) leading to the quantities \(\overline{\text{sIoU}}\), \(\overline{\text{PPV}}\) and \(\overline{F_{1}}\).

In contrast to the previous evaluations on predictive errors, we do not report here results for both of our models, rather we compare gradient scores as an OoD score as such against other methods on the benchmark and report the best result obtained for both, \(\text{PGN}_{oh}\) and \(\text{PGN}_{uni}\). As baselines, we include the same methods as for error detection before since these constitute a reasonable comparison in addition to some of the well-established methods of estimating epistemic uncertainty like MC Dropout and deep ensemble. Note, that the standard entropy baseline is not featured in the official leaderboard, so we report our own results obtained by the softmax entropy with the WideResNet backbone which performed better. We include a full table of methods in Appendix C and find that our method is in several cases competitive with some of the stronger methods utilizing adversarial examples, auxiliary data or significant alterations of the model architecture.

The results verified by the official benchmark are compiled in Table 2 and Table 3. Across the board, PGN shows strong performance, almost exclusively delivering the best or second-best results with few exceptions. The only prominent exception is in the segment-based PPV metric on LostAndFound test-NoKnown where both, \(\text{PGN}_{oh}\) and \(\text{PGN}_{uni}\) come in behind the maximum softmax and entropy baseline. Meanwhile, the segmentation accuracy in terms of sIoU, as well as the \(F_{1}\) score which is the harmonic mean of Recall and Precision are far superior to these two baselines. This indicates still better OoD segmentation quality and in particular better Recall achieved by \(\text{PGN}\). Gradient scores perform perhaps the least convincingly on the RoadObstacle21 benchmark, where in three cases only the second-best performance is achieved. Overall however, we conclude strong performance of our method in terms of out-of-distribution segmentation across different datasets. We find a slight trend of \(\text{PGN}_{oh}\) performing better in the Obstacle track which can be seen to be closer to in-distribution data in semantic segmentation for autonomous driving. This connection would be consistent with our finding in actual in-distribution errors, while \(\text{PGN}_{uni}\) performs better on the Anomaly track which is more clearly out-of-distribution for street scene recognition. In several cases, our method even beats some of the stronger OoD segmentation methods utilizing, for example on RoadAnomaly21, adversarial samples (ODIN/Mahalanobis by over \(9\) pp in AuPRC), OoD data (Void Classifier by over \(6\) pp AuPRC) or generative models (JSRNet/Embedding Density by over \(5\) pp AuPRC and Image Resynthesis by over \(10\) pp in \(\overline{\text{PPV}}\)).

Figure 4 shows segmentation predictions of the pre-trained DeepLabv3+ network with the WideResNet38 backbone together with its corresponding \(\text{PGN}_{uni}^{p=0.5}\)-heatmap. The two panels on the left show an in-distribution prediction on Cityscapes where uncertainty is mainly concentrated around segmentation boundaries which are always subject to high

\begin{table}
\begin{tabular}{c|c c|c c c|c c|c c c} \hline \hline  & \multicolumn{4}{c|}{LostAndFound test-NoKnown} & \multicolumn{4}{c}{RoadObstacle21} \\ \hline  & AuPRC \(\uparrow\) & \(\text{FPR}_{05}\downarrow\) & \(\overline{\text{sIoU}}\uparrow\) & \(\overline{\text{PPV}}\uparrow\) & \(\overline{F_{1}}\uparrow\) & AuPRC \(\uparrow\) & \(\text{FPR}_{05}\downarrow\) & \(\overline{\text{sIoU}}\uparrow\) & \(\overline{\text{PPV}}\uparrow\) & \(\overline{F_{1}}\uparrow\) \\ \hline Ensemble & \(2.9\) & \(82.0\) & \(6.7\) & \(7.6\) & \(2.7\) & \(1.1\) & \(77.2\) & \(8.6\) & \(4.7\) & \(1.3\) \\ MC Dropout & \(36.8\) & \(35.6\) & \(17.4\) & \(34.7\) & \(13.0\) & \(4.9\) & \(50.3\) & \(5.5\) & \(5.8\) & \(1.1\) \\ \hline Maximum Softmax & \(30.1\) & \(33.2\) & \(14.2\) & \(62.2\) & \(10.3\) & \(15.7\) & \(16.6\) & \(19.7\) & \(15.9\) & \(6.3\) \\ Entropy & \(52.0\) & \(30.0\) & \(40.4\) & \(53.8\) & \(42.4\) & \(20.6\) & \(16.3\) & \(21.4\) & \(19.5\) & \(10.4\) \\ \hline \(\text{PGN}_{oh}^{p=0.5}\) & \(64.9\) & \(18.4\) & \(48.3\) & \(50.0\) & \(46.9\) & \(18.8\) & \(14.8\) & \(22.1\) & \(16.5\) & \(9.2\) \\ \(\text{PGN}_{uni}^{p=0.5}\) & \(69.3\) & \(9.8\) & \(50.0\) & \(44.8\) & \(45.4\) & \(16.5\) & \(19.7\) & \(19.5\) & \(14.8\) & \(7.4\) \\ \hline \hline \end{tabular}
\end{table}
Table 2: OoD segmentation results for the LostAndFound and the RoadObstacle21 dataset.

Figure 4: Semantic segmentation prediction and our gradient uncertainty heatmap (\(\text{PGN}_{uni}^{p=0.5}\)) for the Cityscapes dataset (_left_) and the RoadAnomaly21 dataset (_right_) for the WideResNet backbone.
prediction uncertainty. Moreover, we see some false predictions in the far distance around the street crossing which can be found as a region of high gradient norm in the heatmap. In the two panels to the right, we see an OoD prediction from the RoadAnomaly21 dataset of a sloth crossing the street which is classified as part vegetation, terrain and person. The outline of the segmented sloth can be seen brightly in the gradient norm heatmap to the right indicating clear separation.

LimitationsWhile our method performs well in terms of segment-wise error detection and raises accuracy compared with previous methods, we declare that our method is merely on-par with other uncertainty quantification methods for pixel-level considerations. Moreover, there have been submissions to the SegmentMelfYouCan benchmark which significantly outperform our method, however, due to the simplicity and flexibility of our method this comes at no surprise. Note, that there are some light architectural restrictions when it comes to our method in that it is required for the final layer to be a convolution.

## 5 Conclusion

In this work, we presented an efficient method of computing gradient uncertainty scores for a wide class of deep semantic segmentation models. Moreover, we appreciate a low computational cost associated with them. Our experiments show that large gradient norms obtained by our method statistically correspond to erroneous predictions already on the pixel-level and can be normalized such that they yield similarly calibrated confidence measures as the maximum softmax score of the model. On a segment-level our method shows considerable improvement in terms of error detection. Gradient scores can be utilized to segment out-of-distribution objects significantly better than any other softmax- or output-based method on the SegmentMelfYouCan benchmark and has competitive results with a variety of methods, in several cases clearly outperforming all of them. We hope that our contributions in this work and the insights into the computation of pixel-wise gradient feedback for segmentation models will inspire future work in uncertainty quantification and pixel-wise loss analysis.

## Acknowledgements

We thank Hanno Gottschalk and Matthias Rottmann for discussion and useful advice. This work is supported by the Ministry of Culture and Science of the German state of North Rhine-Westphalia as part of the KI-Starter research funding program. The research leading to these results is funded by the German Federal Ministry for Economic Affairs and Climate Action within the project "KI Delta Learning" (grant no. 19A19013Q). The authors would like to thank the consortium for the successful cooperation. The authors gratefully acknowledge the Gauss Centre for Supercomputing e.V. www.gauss-centre.eu for funding this project by providing computing time through the John von Neumann Institute for Computing (NIC) on the GCS Supercomputer JUWELS at Julich Supercomputing Centre (JSC).
