\section{Conclusion}
In this paper, with propose to use an additional, class-agnostic, object detector to filter and aggregate an anomaly score from ObsNet\xspace pixel-wise error map. Our strategy helps to better disentangle in from out-of-distribution objects. 
\section{Introduction}\label{sec:introduction}

Lately, an ever increasing number of safety-critical systems, such as autonomous driving, 
are looking into leveraging Deep Neural Networks (DNNs) for the perception of the environment and as well as for subsequent decisions. Despite some success, DNNs still remain unreliable for real world deployment and often over-confident even they are incorrect on both In-Distribution~\cite{guo_2017} and Out-Of-Distribution (OOD) data~\cite{nguyen2015deep,hein2019relu}. In this work, we aim at detecting OOD objects for 2D object segmentation. In this context, we consider as OOD the objects belonging to a class that is unknown by the perception system, i.e., a class that is not defined nor present in the training data.

Most methods dealing with \textit{unknown-unknown} are based on ensembles\cite{Lakshminarayanan_2017,maddox2019simple,franchi2019tradi,mehrtash2020pep}, pseudo-ensembles~\cite{KendallGal_2017,wen2020batchensemble,franchi2020encoding,durasov2021masksembles}, or deterministic approaches for computing uncertainty~\cite{hendrycks17baseline,postels2019sampling, van2020uncertainty,liu2020simpleSNGP}. However, most of them cannot simultaneously satisfy the real world requirements of high performance and real-time inference, typically trading one for the other. Recent works inspired by practices from system validation and monitoring, advance two-stage strategies to detect anomalies in semantic segmentation~\cite{besnier2021learning,besnier2021triggering}. An Observer Network is trained to analyze and predict the confidence of a main perception network. Observer-based approaches have been shown to find a good balance between accuracy and computational efficiency~\cite{besnier2021learning,besnier2021triggering}. In this work we build on top on observer-based approaches to leverage their properties.

We argue that pixel-wise error map (as shown in ~\cite{besnier2021learning,besnier2021triggering,KendallGal_2017, corbiere2019addressing}) by itself is sub-optimal for anomaly detection in segmentation because these maps lack clarity. Due to the difficulty of fine-grained prediction, most boundaries between two classes as well as small or distant objects are considered uncertain. Therefore, the focus of interest in the image, i.e. the OOD object, is drowned into this noise. The resulting error map does not provide precisely delimited spatial information: we know there is an error on the image but we struggle to accurately locate the corresponding OOD object. In other words, while we can get uncertainty estimates and predictions at pixel-level, extending them to objects is not obvious and we cannot find automatically objects far from the training distribution. As an example, an image depicting a crowd of pedestrian with lot of boundaries has, on average, higher anomaly score than an image with only one OOD object in the middle of a road.

In this paper, we propose to reduce the granularity of the task in order to improve the relevance of the error map. To this end, we use a class agnostic, instance segmentation network. With this additional prediction, we first filter background errors, and then aggregate uncertainty in an instance-aware manner \autoref{fig:architecture_instance}. Ultimately, we only want to highlight object instances with high errors. With this pragmatic and practical solution we can sort objects by anomaly score and then discard all objects close to the training distribution and keep those that are far from the training distribution.

\begin{figure}
\renewcommand{\captionfont}{\small}
\renewcommand{\captionlabelfont}{\bf}
    \centering
    \includegraphics[width=\linewidth]{images/archi.png}
    \caption{\textbf{Overview of our instance aware pipeline.} The image is fed into the instance, the semantic and the observer network (from top to bottom). On the middle, the ObsNet\xspace prediction is filter by the class-agnostic instance prediction and the remaining error is then aggregate object-wise. Finally, in the right of the figure, we show in red, the objects far from the training distribution.}
    \label{fig:architecture_instance}
\vspace{-0.45cm}
\end{figure}

\section{Proposed Method}\label{section:method}

\subsection{Observer Networks}
Our work builds upon ObsNet\xspace \cite{besnier2021learning,besnier2021triggering} that we briefly describe here. Observer networks are a two-stage method to detect pixels-wise errors and OOD. \cite{besnier2021triggering} designed two principles to train efficiently an auxiliary network. They improve the architecture by decoupling the OOD detector from the segmentation branch and by observing the whole network via residual connections. Secondly, they generate blind spots in the segmentation network with \textit{local adversarial attacks} ($LAA$) at a random location of the image, mimicking an OOD object. ObsNet\xspace ($Obs$) outputs a pixels-wise error map corresponding to the probability that the semantic segmentation network ($Seg$) fails to predict the correct class $y$:

\begin{equation}
    Obs(\boldsymbol{x}, Seg_r(\boldsymbol{x}))\approx Pr[ Seg(\boldsymbol{x}) \neq y ],
\end{equation}
where $x$ is the input image and $Seg_r$ the skip connections from intermediate feature maps of segmentation network $Seg$.

\subsection{Instance Anomaly Detection}
To this end, we upgrade the semantic segmentation framework with instance hints. We use an additional class agnostic instance segmentation prediction. This detector ($Det$) produces a binary mask by mapping each object in the image.

Then, the idea is to separate the observer's prediction map into two categories. The background (classes of \emph{stuff}) and the instance (classes of \emph{things}) in the same way as the panoptic segmentation. Background errors correspond to global ambiguities in the scene at different scales: error at the decision boundary between two classes, prediction error between the road and the sidewalk or complexity of the leaves of a tree. In contrast, an instance error corresponds to an object far from the train distribution. 

\subsection{Uncertainty Aggregation and Filtering}
In order to obtain a unique error score for each instance (similar to the well-known objectness score in object detection), we aggregate the per-pixel uncertainty within the predicted object mask to a unique value. In practice, given an image $\boldsymbol{x} \in \mathbb{R}^{3 \times H \times W}$, we predict for each detected object $o_i$ an anomaly score $a_{i} \in \mathbb{R}$:

\begin{equation}\label{eq:anomalyscore}
    a_{i} = \frac{1}{M} \sum_{h=0}^{H}\sum_{w=0}^{W}{u^{(h,w)} \odot m^{(h,w)}_{i}},
\end{equation}
where $u = Obs(\boldsymbol{x}, Seg_r(\boldsymbol{x})) \in \mathbb{R}^{H \times W}$ is the pixel-wise error map of ObsNet\xspace; $m_{i} \in \mathbb{R}^{H \times W}$ is the binary mask of an instance $o_i$ in the set of the detector prediction $Det(\boldsymbol{x})=\{m_i\}$; $M=\sum_{h,w=0}^{H \times W}{m_i}$ the area of the instance $o_i$; and $\odot$ is the element-wise product. We also filter predicted instance masks $m_i$ by size, in order to remove very small detected objects ($<16^2$ pixels) in the image. 

This strategy shows several benefits. We can discover instances in the dataset that do not match with the training distribution, useful for active learning or object discovery. We can also localize where the anomaly is in the image, which is a primary requirement for safety-critical applications such as autonomous driving. In \autoref{fig:filter_uncertainty}, we show that our framework is able to detect several instances in the images, and the ObsNet\xspace succeeds in discriminating in-distribution objects from out-of-distribution ones. 

\section{Related Work}\label{section:related_work}
The widespread DNN adoption in this field has led to a fresh wave of approaches to improve OOD detection by input reconstruction \cite{schlegl2017unsupervised, baur2018deep, lis2019detecting, xia2020synthesize}, predictive uncertainty \cite{Gal2016Dropout,KendallGal_2017, malinin2018}, ensembles \cite{Lakshminarayanan_2017,franchi2019tradi,durasov2021masksembles}, adversarial attacks \cite{Liang2018, lee2018simple}, using a void or background class \cite{ren2015faster, liu2016ssd} or dataset \cite{bevandic2019simultaneous, hendrycks2018deep, malinin2018}, \etc., to name just a few. 

\noindent\textbf{Bayesian approaches and ensembles.} BNNs~\cite{neal2012bayesian,Blundell2015} can capture predictive uncertainty from learned distributions over network weights, but don't scale well~\cite{dusenberry2020efficient} and approximate solutions are preferred in practice. Deep Ensembles (DE)~\cite{Lakshminarayanan_2017} is a highly effective, yet costly approach, that trains an ensemble of DNNs with different initialization seeds. Efficient or pseudo-ensemble approaches are a pragmatic alternative to DE that bypass training of multiple networks and generate predictions from different random subsets of neurons~\cite{Gal2016, srivastava2014dropout,durasov2021masksembles} or from networks sampled from approximate weight distributions~\cite{maddox2019simple,franchi2019tradi,mehrtash2020pep, wen2020batchensemble,franchi2020encoding}. However they all require multiple forward passes and/or storage of additional networks in memory.

\noindent\textbf{Learning to predict errors.} Inspired by early approaches from model calibration literature~\cite{platt1999probabilistic, zadrozny2001obtaining, zadrozny2002transforming, naeini2015obtaining, naeini2016binary}, a number of methods propose endowing the task network with an error prediction branch allowing self-assessment of predictive performance. This branch can be trained jointly with the main network~\cite{devries2018learning, yoo2019learning}, however better learning stability and results are achieved with two-stage sequential training~\cite{corbiere2019addressing, hecker2018failure,besnier2021learning,Samson_2019_ICCV}.

\noindent\textbf{OOD in object detection.} 
Compared to classification and segmentation, OOD identification for 2D object detection is more challenging (mix of classification and regression predictions) and is less explored. Here, ensembles and pseudo-ensembles are often used for predictive uncertainty~\cite{miller2019evaluating,haussmann2020scalable, azevedo2020stochastic,rahman2020online}. Spatial uncertainty can be computed with slight changes in popular architectures and losses \cite{Choi_2019_ICCV,Harakeh2021EstimatingAE,choi2021active}. Other works leverage sampling-free approaches for both spatial and class uncertainty for real-time applications~\cite{Gasperini_2022}. OOD detection itself has started to be addressed only recently by generating outliers in the feature space~\cite{du2022towards} or by ``seeing'' unknown objects from videos in the wild~\cite{du2022stud}.

\section{Experiments}\label{section:results}
\begin{figure}
\renewcommand{\captionfont}{\small}
\renewcommand{\captionlabelfont}{\bf}
\centering
\includegraphics[width=\linewidth]{images/histo.png}
\caption{\textbf{Histogram on CamVid OOD}. Anomaly score from obsnet and detection from mask RcNN trained on the pan-distribution. We show here some examples of well-detected objects and predicted as in distribution in blue (left). While objects detected with high anomaly score (right) are considered as OOD in orange.}
\label{fig:histogram}
\vspace{-0.3cm}
\end{figure}

\begin{figure*}
\renewcommand{\captionfont}{\small}
\renewcommand{\captionlabelfont}{\bf}
\centering
\includegraphics[width=\linewidth, height=5.5cm]{images/qualitative_results.png}
\caption{\textbf{Qualitative results on the StreetHazards (top row), BDD Anomaly (mid) and CamVid (bot).} From left to right, the input image; the semantic segmentation; the instance segmentation; the pixel-wise error and the instance-wise error. We can see that our method is able to detect numerous objects and disentangle in-distribution objects ($a_{i}<.5$ in green) from out-of-distribution objects ($a_{i}>.5$ in red).}
\label{fig:qualitative_results}
\vspace{-0.5cm}
\end{figure*}

We assess experimentally the effectiveness of our observer network coupled with an class-agnostic instance detector and compare it against several baselines.


\subsection{Datasets \& Metrics}
We conducts experiments on the \textbf{CamVid OOD} \cite{besnier2021learning}, \textbf{StreetHazards} \cite{hendrycks_benchmark_2019} and \textbf{BDD Anomaly} \cite{bdd100k} datasets of urban streets scenes with anomalies in the test set. Anomalies correspond to OOD objects, not seen during training.

To evaluate each method on these datasets, we select four metrics to detect misclassified and out-of-distribution examples: \textbf{fpr95tpr}~\cite{Liang2018}, \textbf{Area Under the Receiver Operating Characteristic curve (AuRoc)}~\cite{hendrycks17baseline}, \textbf{Area under the Precision-Recall Curve (AuPR)}~\cite{hendrycks17baseline} and \textbf{Mean Average Prediction ($mAP_\delta$)}. We compute the latter metric where we discard object smaller than $\delta^2$ pixels.

For each metric, we report the result where an object is considered as well detected if the predicted mask has $IoU > .5$ with the ground truth. We assign to each detected object the anomaly score computed as \autoref{eq:anomalyscore}. We use a Bayesian SegNet \cite{badrinarayanan2015segnet}, \cite{kendall2015bayesian} as the main network for CamVid and a DeepLabv3+~\cite{Chen_2018_ECCV} for BDD Anomaly and StreetHazards. The ObsNet\xspace follows the same architecture as the corresponding segmentation network. 

For our instance segmentation module, we select two Mask R-CNN variants~\cite{He_2017_ICCV}: one trained on CityScapes~\cite{Cordts2016Cityscapes}, reported as In-Distribution Detector, and one trained on MS-COCO~\cite{Lin_2014}, reported as Pan-Distribution. We do not leverage the class predicted but only the instance mask. Moreover, we use an additional oracle: we take every connected region of the same class in the annotation as one instance of an object, we report this \textit{detector} as GT-detector.

We compare our method against two other methods. \textbf{MCP}~\cite{hendrycks17baseline}: Maximum Class Prediction; one minus the maximum of the prediction. And \textbf{MC Dropout\xspace}~\cite{Gal2016Dropout}: The entropy of the mean softmax prediction with dropout; we use 50 forward passes for all the experiences.

\subsection{Benefit of the instance module}\label{subsection:instance-wise-ablation}
To validate the benefit of the instance detector, we first check that filtering the pixel-wise error map with the instance detector helps for pixel OOD detection, see \autoref{tab_camvid_pixels}. Using an instance detector improves significantly the performance of ObsNet\xspace. Moreover, this experiment shows that keeping raw error map is sub-optimal because many pixels with high anomaly score do not correspond to an OOD object but actually belong to the background of the images, whereas they can easily be filtered out by our instance scheme.

\begin{table}
\renewcommand{\figurename}{Table}
\renewcommand{\captionlabelfont}{\bf}
\renewcommand{\captionfont}{\small} 
 \centering
  \begin{tabular}{l@{\hspace{-0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}} \toprule
    Method                               & fpr95tpr$\downarrow$     & AuPR\_error $\uparrow$   &  AuRoc $\uparrow$  \\ \hline        
    Softmax~\cite{hendrycks17baseline}   & 70.0                     & 11.45                   & 76.7                \\  
    ObsNet\xspace                              & 40.5                     & 22.72                   & 87.9                \\ 
    ObsNet\xspace + \textit{in-detector}             & 31.3                     & 49.4                    & 92.3                \\   
    ObsNet\xspace + \textit{pan-detector}            &  8.7                     & 70.1                    & 97.3                \\   
    ObsNet\xspace + \textit{gt-detector}             &  \textbf{1.0}            & \textbf{90.5}           & \textbf{99.7}       \\   
    \bottomrule                                                                                             
  \end{tabular}
  \caption{\textbf{Pixel-wise evaluation on CamVid OOD}. We consider OOD pixels only as the positive class.}
  \label{tab_camvid_pixels}
  \vspace{-0.5cm}
\end{table}

\subsection{Instance-Wise Results}\label{subsection:instance-wise_results}

Here, we compare our methods for object detection on \autoref{tab_camvid_instance}, \autoref{tab_bdd_instance} and \autoref{tab_streethazards_instance}. We can observe that for each dataset the results are quite different. This is due to the scale of the anomalies and the number of them in each the dataset. In \autoref{tab_camvid_instance}, all anomalies are above 64² pixels, which can explain why the metrics drastically improve as we discard smaller detected objects. In \autoref{tab_streethazards_instance}, most of the objects are in fact anomalies, which is why mAP is high, even for the object below 32² pixels. Finally, even if on average \textit{pan-detector} outperforms \textit{in-detector}, this is not always the case in \autoref{tab_bdd_instance}. Indeed, \textit{pan-detector} can detect more objects, and among them smaller in-distribution objects, that can hurt performances. Overall, 
ObsNet\xspace outperforms baseline methods, regardless of the detector.

\begin{table}
\renewcommand{\figurename}{Table}
\renewcommand{\captionlabelfont}{\bf}
\renewcommand{\captionfont}{\small} 
 \centering
  \begin{tabular}{l@{\hspace{0.1cm}}l@{\hspace{-0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}} \toprule
    Det      &  Method                               & $fpr95_{32}\downarrow$ &  $Roc_{32} \uparrow$   & $mAP_0$  & $mAP_{32}$  \\ \hline        
             &  Softmax~\cite{hendrycks17baseline}   & *                       &  56.7                  & 7.7               & 55.2    \\  
    In       &  MC Dropout\xspace~\cite{Gal2016Dropout}     & *                       &  58.3                  & 8.4               & 58.5    \\
             &  ObsNet\xspace                              & *                       &  \textbf{60.5}         & \textbf{9.9}  & \textbf{63.7}   \\ \hdashline 
             &  Softmax~\cite{hendrycks17baseline}   & 57.2                    &  79.4                  & 4.8               & 62.1    \\  
    Pan      &  MC Dropout\xspace~\cite{Gal2016Dropout}     & 52.8                    &  84.6                  & 6.9               & 70.8    \\
             &  ObsNet\xspace                              & \textbf{46.4}           &  \textbf{89.6}         & \textbf{11.3}     & \textbf{81.4}     \\ \hdashline
             &  Softmax~\cite{hendrycks17baseline}   & 43.3                    &  80.4                  & 10.8              & 72.1    \\  
    GT       &  MC Dropout\xspace~\cite{Gal2016Dropout}     & 32.1                    &  85.5                  & 13.5              & 79.2    \\
             &  ObsNet\xspace                              & \textbf{27.2}           &  \textbf{94.3}         & \textbf{22.3}     & \textbf{92.0}   \\ 
    \bottomrule                                                                                             
  \end{tabular}
  \caption{\textbf{Instance-wise evaluation on CamVid OOD}. We consider OOD examples only as the positive class. *not enough OOD objects have been detected by the detector to compute the metrics}
  \label{tab_camvid_instance}
  \vspace{-0.4cm}
\end{table}

\begin{table}
\renewcommand{\figurename}{Table}
\renewcommand{\captionlabelfont}{\bf}
\renewcommand{\captionfont}{\small} 
 \centering
  \begin{tabular}{l@{\hspace{0.1cm}}l@{\hspace{-0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}} \toprule
    Det   &  Method                                   & $fpr95_{32}\downarrow$ &  $Roc_{32} \uparrow$   & $mAP_0 $  & $mAP_{32}$ \\ \hline        
             &  Softmax~\cite{hendrycks17baseline}   &  *                        &  52.5                  &  9.5           &    13.3            \\  
    In       &  MC Dropout\xspace~\cite{Gal2016Dropout}     &  *                        &  52.6                  &  9.5           &    13.3               \\
             &  ObsNet\xspace                              &  *                        &  \textbf{55.8}         &  \textbf{9.9}  &    \textbf{16.8}     \\\hdashline      
             &  Softmax~\cite{hendrycks17baseline}   &  *                        &  63.0                  &  5.9           &    16.8            \\  
    Pan      &  MC Dropout\xspace~\cite{Gal2016Dropout}     &  *                        &  62.2                  &  6.0           &    17.0            \\
             &  ObsNet\xspace                              &  *                        &  \textbf{64.5}         &  \textbf{6.9}  &    \textbf{20.1}          \\ \hdashline      
             &  Softmax~\cite{hendrycks17baseline}   &  65.6                     &  81.9                  &  22.7          &    37.8              \\  
    GT       &  MC Dropout\xspace~\cite{Gal2016Dropout}     &  61.9                     &  82.5                  &  23.0          &    39.1              \\
             &  ObsNet\xspace                              &  \textbf{53.3}            &  \textbf{86.8}         &  \textbf{27.1} &    \textbf{50.7}  \\ \bottomrule  
  \end{tabular}
  \caption{\textbf{Instance-wise evaluation on BDD Anomaly}. We consider OOD examples only as the positive class.}
  \label{tab_bdd_instance}
  \vspace{-0.2cm}
\end{table}

\begin{table}
\renewcommand{\figurename}{Table}
\renewcommand{\captionlabelfont}{\bf}
\renewcommand{\captionfont}{\small} 
 \centering
  \begin{tabular}{l@{\hspace{0.1cm}}l@{\hspace{-0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}c@{\hspace{0.1cm}}} \toprule
    Det      &  Method                               & $fpr95_{48}\downarrow$ &  $Roc_{48} \uparrow$   & $mAP_{16} $  & $mAP_{48}$          \\ \hline      
             &  Softmax~\cite{hendrycks17baseline}   & *                    &  \textbf{50.4}         & 80.0             &  \textbf{81.9}    \\
    In       &  MC Dropout\xspace~\cite{Gal2016Dropout}     & *                    &  50.3                  & 80.0             &  81.2             \\
             &  ObsNet\xspace                              & *                    &  \textbf{50.4}         & \textbf{80.1}    &  \textbf{81.9}    \\\hdashline 
             &  Softmax~\cite{hendrycks17baseline}   & *                    &  53.7                  & 57.6             &  77.7                \\  
    Pan      &  MC Dropout\xspace~\cite{Gal2016Dropout}     & *                    &  53.6                  & \textbf{57.7}    &  77.6                \\
             &  ObsNet\xspace                              & *                    &  \textbf{54.1}         & 56.9             &  \textbf{77.8}          \\ \hdashline
             &  Softmax~\cite{hendrycks17baseline}   & 80.0                 &  85.2                  & 88.9             &  99.0                          \\  
    GT       &  MC Dropout\xspace~\cite{Gal2016Dropout}     & 74.5                 &  86.0                  & 86.9             &  99.0                          \\
             &  ObsNet\xspace                              & \textbf{72.6}        &  \textbf{87.5}         & \textbf{89.0}    &  \textbf{99.2}       \\ \bottomrule  
  \end{tabular}
  \caption{\textbf{Instance-wise evaluation on StreetHazards}. We consider OOD examples only as the positive class.}
  \label{tab_streethazards_instance}
  \vspace{-0.4cm}
\end{table}

In \autoref{fig:histogram}, we report the histogram of objects detected by our detector, ranked by our framework. We can well disentangle in-distribution objects as cars, bicycles, or pedestrians, from OOD objects (animals).

We illustrate a few qualitative results in \autoref{fig:qualitative_results}. ObsNet\xspace emphasizes OOD objects with higher anomaly scores compared to in-distribution objects. Its predicted error maps are generally clearer and more accurate.

