SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Haotian Zheng $^{1,2*}$  Qizhou Wang $^{1*}$  Zhen Fang $^{3}$  Xiaobo Xia $^{4}$
Feng Liu $^{5}$  Tongliang Liu $^{4}$  Bo Han $^{1\dagger}$
$^{2}$ School of Electronic Engineering, Xidian University
$^{3}$ Australian Artificial Intelligence Institute, University of Technology Sydney
$^{4}$ Sydney AI Centre, The University of Sydney
$^{5}$ School of Computing and Information Systems, The University of Melbourne
htzheng.xdu@gmail.com {csqzwang,bhanml}  $@$  comp.hkbu.edu.hk
zhen.fang@uts.edu.au xiaoboxia.uni@gmail.com
fengliu.ml@gmail.com tongliang.liu@sydney.edu.au
Out-of-distribution (OOD) detection discerns OOD data where the predictor cannot make valid predictions as in-distribution (ID) data, thereby increasing the reliability of open-world classification. However, it is typically hard to collect real out-of-distribution (OOD) data for training a predictor capable of discerning ID and OOD patterns. This obstacle gives rise to data generation-based learning methods, synthesizing OOD data via data generators for predictor training without requiring any real OOD data. Related methods typically pre-train a generator on ID data and adopt various selection procedures to find those data likely to be the OOD cases. However, generated data may still coincide with ID semantics, i.e., mistaken OOD generation remains, confusing the predictor between ID and OOD data. To this end, we suggest that generated data (with mistaken OOD generation) can be used to devise an auxiliary OOD detection task to facilitate real OOD detection. Specifically, we can ensure that learning from such an auxiliary task is beneficial if the ID and the OOD parts have disjoint supports, with the help of a well-designed training procedure for the predictor. Accordingly, we propose a powerful data generation-based learning method named Auxiliary Task-based OOD Learning (ATOL) that can relieve the mistaken OOD generation. We conduct extensive experiments under various OOD detection setups, demonstrating the effectiveness of our method against its advanced counterparts. The code is publicly available at: https://github.com/tmlr-group/ATOL.
Deep learning in the open world should not only make accurate predictions for in-distribution (ID) data meanwhile should detect out-of-distribution (OOD) data whose semantics are different from ID cases [15, 56, 22, 81, 85, 82]. It drives recent studies in OOD detection [43, 23, 33, 66, 80, 24], which is important for many safety-critical applications such as autonomous driving and medical analysis. Previous works have demonstrated that well-trained predictors can wrongly take many OOD data as ID cases [1, 15, 21, 48], motivating recent studies towards effective OOD detection.
(a) Mistaken Semantics
(b) Adverse Impacts
Figure 2: Illustration of our method. ATOL makes the predictor learn from the real task and our auxiliary task jointly via a well-designed learning procedure, leading to the separation between the OOD and ID cases. The predictor can benefit from such an auxiliary task for real OOD detection, relieving mistaken OOD generation.
Figure 1: Illustrations of mistaken OOD generation. Figure 1(a) indicates the generated OOD data (colored in red) may wrongly possess semantics of the real ID data (colored in green), e.g., generated data with the ID semantics of "Horse". Figure 1(b) demonstrates that the OOD performance of predictors are impaired by unreliable OOD data, described in Appendix E.2. With the proportion of OOD data possessing ID semantics increasing, the OOD performance (measured by FPR95) degrades.
In the literature, an effective learning scheme is to conduct model regularization with OOD data, making predictors achieve low-confidence predictions on such data [3, 16, 36, 42, 49, 75, 79]. Overall, they directly let the predictor learn to discern ID and OOD patterns, thus leading to improved performance in OOD detection. However, it is generally hard to access real OOD data [10, 11, 69, 70], hindering the practical usage scenarios for such a promising learning scheme.
Instead of collecting real OOD data, we can generate OOD data via data generators to benefit the predictor learning, motivating the data generation-based methods [31, 50, 55, 62, 67]. Generally speaking, existing works typically fit a data generator [12] on ID data (since real OOD data are inaccessible). Then, these strategies target on finding the OOD-like cases from generated data by adopting various selection procedures. For instance, Lee et al. [31] and Vernekar et al. [62] take boundary data that lie far from ID boundaries as OOD-like data; PourReza et al. [50] select those data generated in the early stage of generator training. However, since the generators are trained on ID data and these selection procedures can make mistakes, one may wrongly select data with ID semantics as OOD cases (cf., Figure 1(a)), i.e., mistaken OOD generation remains. It will misguide the predictors to confuse between ID and OOD data, making the detection results unreliable, as in Figure 1(b). Overall, it is hard to devise generator training procedures or data selection strategies to overcome mistaken OOD generation, thus hindering practical usages of previous data generation-based methods.
To this end, we suggest that generated data can be used to devise an auxiliary task, which can benefit real OOD detection even with data suffered from mistaken OOD generation. Specifically, such an auxiliary task is a crafted OOD detection task, thus containing ID and OOD parts of data (termed auxiliary ID and auxiliary OOD data, respectively). Then, two critical problems arise — how to make such an auxiliary OOD detection task learnable w.r.t. the predictor and how to ensure that the auxiliary OOD detection task is beneficial w.r.t. the real OOD detection. For the first question, we refer to the advanced OOD detection theories [11], suggesting that the auxiliary ID and the auxiliary OOD data should have the disjoint supports in the input space (i.e., without overlap w.r.t. ID and OOD distributions), cf., C1 (Condition 1 for short). For the second question, we justify that, for our predictor, if real and auxiliary ID data follow similar distributions, cf., C2, the auxiliary OOD data are reliable OOD data w.r.t. the real ID data. In summary, if C1 and C2 hold, we can ensure that learning from the auxiliary OOD detection task can benefit the real OOD detection, cf., Proposition 1.
Based on the auxiliary task, we propose Auxiliary Task-based OOD Learning (ATOL), an effective data generation-based OOD learning method. For C1, it is generally hard to directly ensure the disjoint supports between the auxiliary ID and auxiliary OOD data due to the high-dimensional input space. Instead, we manually craft two disjoint regions in the low-dimensional latent space (i.e., the input space of the generator). Then, with the generator having distance correlation between input
space and latent space [63], we can make the generated data that belong to two different regions in the latent space have the disjoint supports in the input space, assigning to the auxiliary ID and the auxiliary OOD parts, respectively. Furthermore, to fulfill C2, we propose a distribution alignment risk for the auxiliary and the real ID data, alongside the OOD detection risk to make the predictor benefit from the auxiliary OOD detection task. Following the above learning procedure, we can relieve the mistaken OOD generation issue and achieve improved performance over previous works in data generation-based OOD detection, cf., Figure 2 for a heuristic illustration.
To verify the effectiveness of ATOL, we conduct extensive experiments across representative OOD detection setups, demonstrating the superiority of our method over previous data generation-based methods, such as Vernekar et al. [62], with  $12.02\%$ ,  $18.32\%$ , and  $20.70\%$  improvements measured by average FPR95 on CIFAR-10, CIFAR-100, and ImageNet datasets. Moreover, compared with more advanced OOD detection methods (cf., Appendix F), such as Sun et al. [57], our ATOL can also have promising improvements, which reduce the average FPR95 by  $4.36\%$ ,  $15.03\%$ , and  $12.02\%$  on CIFAR-10, CIFAR-100, and ImageNet datasets.
Contributions. We summarize our main contributions into three folds:
- We focus on the mistaken OOD generation in data generation-based detection methods, which are largely overlooked in previous works. To this end, we introduce an auxiliary OOD detection task to combat the mistaken OOD generation and suggest a set of conditions in Section 3 to make such an auxiliary task useful.
- Our discussion about the auxiliary task leads to a practical learning method named ATOL. Over existing works in data generation-based methods, our ATOL introduces small costs of extra computations but is less susceptible to mistaken OOD generation.
- We conduct extensive experiments across representative OOD detection setups, demonstrating the superiority of our method over previous data generation-based methods. Our ATOL is also competitive over advanced works that use real OOD data for training, such as outlier exposure [16], verifying that the data generation-based methods are still worth studying.
Let  $\mathcal{X} \subseteq \mathbb{R}^n$  the input space,  $\mathcal{Y} = \{1, \dots, c\}$  the label space, and  $\mathbf{h} = \rho \circ \phi : \mathbb{R}^n \to \mathbb{R}^c$  the predictor, where  $\phi : \mathbb{R}^n \to \mathbb{R}^d$  is the feature extractor and  $\rho : \mathbb{R}^d \to \mathbb{R}^c$  is the classifier. We consider  $\mathcal{P}_{X,Y}^{\mathrm{ID}}$  and  $\mathcal{P}_X^{\mathrm{ID}}$  the joint and the marginal ID distribution defined over  $\mathcal{X} \times \mathcal{Y}$  and  $\mathcal{X}$ , respectively. We also denote  $\mathcal{P}_X^{\mathrm{OOD}}$  the marginal OOD distribution over  $\mathcal{X}$ . Then, the main goal of OOD detection is to find the proper predictor  $\mathbf{h}(\cdot)$  and the scoring function  $s(\cdot; \mathbf{h}) : \mathbb{R}^n \to \mathbb{R}$  such that the OOD detector
$$
f _ {\beta} (\mathbf {x}) = \left\{ \begin{array}{c l} \text {I D}, & \text {i f} s (\mathbf {x}; \mathbf {h}) \geq \beta , \\ \text {O O D}, & \text {i f} s (\mathbf {x}; \mathbf {h}) <   \beta , \end{array} \right. \tag {1}
$$
can detect OOD data with a high success rate, where  $\beta$  is a given threshold. To get a proper predictor  $\mathbf{h}(\cdot)$ , outlier exposure [16] proposes regularizing the predictor to produce low-confidence predictions for OOD data. Assuming the real ID data  $\mathbf{x}_{\mathrm{ID}}$  and label  $y_{\mathrm{ID}}$  are randomly drawn from  $\mathcal{P}_{X,Y}^{\mathrm{ID}}$ , then the learning objective of outlier exposure can be written as:
$$
\min  _ {\mathbf {h}} \mathbb {E} _ {\mathcal {P} _ {X, Y} ^ {\mathrm {I D}}} \left[ \ell_ {\mathrm {C E}} \left(\mathbf {x} _ {\mathrm {I D}}, y _ {\mathrm {I D}}; \mathbf {h}\right) \right] + \lambda \mathbb {E} _ {\mathcal {P} _ {X} ^ {\mathrm {O O D}}} \left[ \ell_ {\mathrm {O E}} (\mathbf {x}; \mathbf {h}) \right], \tag {2}
$$
where  $\lambda$  is the trade-off hyper-parameter,  $\ell_{\mathrm{CE}}(\cdot)$  is the cross-entropy loss, and  $\ell_{\mathrm{OE}}(\cdot)$  is the Kullback-Leibler divergence of softmax predictions to the uniform distribution. Although outlier exposure remains one of the most powerful methods in OOD detection, its critical reliance on OOD data hinders its practical applications.
Fortunately, data generation-based OOD detection methods can overcome the reliance on real OOD data, meanwhile making the predictor learn to discern ID and OOD data. Overall, existing works [31, 62, 67] leverage the generative adversarial network (GAN) [12, 51] to generate data, collecting those data that are likely to be the OOD cases for predictor training. As a milestone work, Lee et al. [31] propose selecting the "boundary" data that lie in the low-density area of  $\mathcal{P}_X^{\mathrm{ID}}$ , with the following learning objective for OOD generation:
$$
\min  _ {G} \max  _ {D} \underbrace {\mathbb {E} _ {\mathcal {G} _ {X}} \left[ \ell_ {\mathrm {O E}} (\mathbf {x} ; \mathbf {h}) \right]} _ {\text {(a) g e n e r a t i n g b o u n d a r y d a t a}} + \underbrace {\mathbb {E} _ {\mathcal {P} _ {X} ^ {\mathrm {I D}}} \left[ \log D (\mathbf {x} _ {\mathrm {I D}}) \right] + \mathbb {E} _ {\mathcal {G} _ {X}} \left[ \log (1 - D (\mathbf {x})) \right]} _ {\text {(b) t r a i n i n g d a t a g e n e r a t o r}}, \tag {3}
$$
where  $\mathcal{G}_X$  denotes the OOD distribution of the generated data w.r.t. the generator  $G:\mathbb{R}^m\to \mathbb{R}^n$  ( $m$  is the dimension of the latent space). Note that the term (a) forces the generator  $G(\cdot)$  to generate low-density data and the term (b) is the standard learning objective for GAN training [12]. Then, with the generator trained for OOD generation, the generated data are used for predictor training, following the outlier exposure objective, given by
$$
\min  _ {\mathbf {h}} \mathbb {E} _ {\mathcal {P} _ {X, Y} ^ {\mathrm {I D}}} \left[ \ell_ {\mathrm {C E}} \left(\mathbf {x} _ {\mathrm {I D}}, y _ {\mathrm {I D}}; \mathbf {h}\right) \right] + \lambda \mathbb {E} _ {\mathcal {G} _ {X}} \left[ \ell_ {\mathrm {O E}} (\mathbf {x}; \mathbf {h}) \right]. \tag {4}
$$
Drawbacks. Although a promising line of works, the generated data therein may still contain many ID semantics (cf., Figure 1(a)). It stems from the lack of knowledge about OOD data, where one can only access ID data to guide the training of generators. Such mistaken OOD generation is common in practice, and its negative impacts are inevitable in misleading the predictor (cf., Figure 1(b)). Therefore, how to overcome the mistaken OOD generation is one of the key challenges in data generation-based OOD detection methods.
Note that getting generators to generate reliable OOD data is difficult, since there is no access to real OOD data in advance and the selection procedures can make mistakes. Instead, given that generators suffer from mistaken OOD generation, we aim to make the predictors alleviate the negative impacts raised by those unreliable OOD data.
Our key insight is that these unreliable generated data can be used to devise a reliable auxiliary task which can benefit the predictor in real OOD detection. In general, such an auxiliary task is a crafted OOD detection task, of which the generated data therein are separated into the ID and the OOD parts. Ideally, the predictor can learn from such an auxiliary task and transfer the learned knowledge (from the auxiliary task) to benefit the real OOD detection, thereafter relieving the mistaken OOD generation issue. Therein, two issues require our further study:
- Based on unreliable OOD sources, how to devise a learnable auxiliary OOD detection task?
- Given the well-designed auxiliary task, how to make it benefit the real OOD detection?
For the first question, we refer the advanced work [11] in OOD detection theories, which provides necessary conditions for which the OOD detection task is learnable. In the context of the auxiliary OOD detection task, we will separate the generated data into the auxiliary  $ID$  parts and auxiliary  $OOD$  parts, following the distributions defined by  $\mathcal{G}_X^{\mathrm{ID}}$  and  $\mathcal{G}_X^{\mathrm{OOD}}$ , respectively. Then, we provide the following condition for the separable property of the auxiliary OOD detection task.
Condition 1 (Separation for the Auxiliary Task). There is no overlap between the auxiliary ID distribution and the auxiliary OOD distribution, i.e., supp  $\mathcal{G}_X^{ID} \cap \operatorname{supp} \mathcal{G}_X^{OOD} = \emptyset$ , where supp denotes the support set of a distribution.
Overall, C1 states that the auxiliary ID data distribution  $\mathcal{G}_X^{\mathrm{ID}}$  and the auxiliary OOD data distribution  $\mathcal{G}_X^{\mathrm{OOD}}$  should have the disjoint supports. Then, according to Fang et al. [11] (Theorem 3), such an auxiliary OOD detection might be learnable, in that the predictor can have a high success rate in discerning the auxiliary ID and the auxiliary OOD data. In general, the separation condition is indispensable for us to craft a valid OOD detection task. Also, as in the proof of Proposition 1, the separation condition is also important to benefit the real OOD detection.
For the second question, we need to first formally define if a data point can benefit the real OOD detection. Here, we generalize the separation condition in Fang et al. [11], leading to the following definition for the reliability of OOD data.
Definition 1 (Reliability of OOD Data). An OOD data point  $\mathbf{x}$  is reliable (w.r.t. real ID data) to a mapping function  $\phi'(\cdot)$ , if  $\phi'(\mathbf{x}) \notin \text{supp} \phi_{\#}' \mathcal{P}_X^{ID}$ , where  $\phi_{\#}'$  is the distribution transformation associated with  $\phi'(\cdot)$ .
With identity mapping function  $\phi'(\cdot)$ , the above definition states that  $\mathbf{x}$  is a reliable OOD data point if it is not in the support set of the real ID distribution w.r.t. the transformed space. Intuitively, if real ID data are representative almost surely [11],  $\phi'(\cdot)$  far from the ID support also indicates that  $\phi'(\cdot)$  will not possess ID semantics, namely, reliable. Furthermore,  $\phi'(\cdot)$  is not limited to identity mapping,
which can be defined by any transformed space. The feasibility of such a generalized definition is supported by many previous works [10, 41] in OOD learning, demonstrating that reliable OOD data defined in the embedding space (or in our context, the transformed distribution) can also benefit the predictor learning in OOD detection.
Based on Definition 1, we want to make auxiliary OOD data reliable w.r.t. real ID data, such that the auxiliary OOD detection task is ensured to be beneficial, which motivates the following condition.
Condition 2 (Transferability of the Auxiliary Task). The auxiliary OOD detection task is transferable w.r.t. the real OOD detection task if  $\phi_{\#}^{\prime}\mathcal{P}_{X}^{ID}\approx \phi_{\#}^{\prime}\mathcal{G}_{X}^{ID}$
Overall, C2 states that auxiliary ID data approximately follow the same distribution as that of the real ID data in the transformed space, i.e.,  $\phi'(\mathcal{X})$ . Note that, Auxiliary ID and OOD data can arbitrarily differ from real ID and OOD data in the data space, i.e., auxiliary data are unreliable OOD sources. However, if C2 is satisfied, the model "believes" the auxiliary ID data and the real ID data are the same. Then, we are ready to present our main proposition, demonstrating why C2 can ensure the reliability of auxiliary OOD data.
Proposition 1. Assume the predictor  $\mathbf{h} = \rho \circ \phi$  can separate  $ID$  and  $OOD$  data, namely,
$$
\mathbb {E} _ {\mathcal {G} _ {X, Y} ^ {I D}} \left[ \ell_ {C E} \left(\mathbf {x} _ {I D}, y _ {I D}; \mathbf {h}\right) \right] + \lambda \mathbb {E} _ {\mathcal {G} _ {X} ^ {O O D}} \left[ \ell_ {O E} (\mathbf {x}; \mathbf {h}) \right] \tag {5}
$$
approaches 0. Under  $C1$  and  $C2$ , auxiliary OOD data are reliable w.r.t. real ID data given  $\phi' = \phi$ .
The proof can be found in Appendix C. In heuristics, Eq. (5) states that the predictor should excel at such an auxiliary OOD detection task, where the model can almost surely discern the auxiliary ID and the auxiliary OOD cases. Then, if we can further align the real and the auxiliary ID distributions (i.e., C2), the predictor will make no difference between the real ID data and the auxiliary ID data. Accordingly, since the auxiliary OOD data are reliable OOD cases w.r.t. the auxiliary ID data, the auxiliary OOD data are also reliable w.r.t. the real ID data. Thereafter, one can make the predictor learn to discern the real ID and auxiliary OOD data, where no mistaken OOD generation affects. Figure 2 summarizes our key concepts. As we can see, learning from the auxiliary OOD detection task and further aligning the ID distribution ensure the separation between ID and OOD cases, benefiting the predictor learning from reliable OOD data and improving real OOD detection performance.
Remark 1. There are two parallel definitions for real OOD data [70], related to different goals towards effective OOD detection. One definition is that an exact distribution of real OOD data exists, and the goal is to mitigate the distribution discrepancy w.r.t. the real OOD distribution for effective OOD detection. Another definition is that all those data whose true labels are not in the considered label space are real OOD data, and the goal is to make the predictor learn to see as many OOD cases as possible. Due to the lack of real OOD data for supervision, the latter definition is more suitable than the former one in our context, where we can concentrate on mistaken OOD generation.
4 Learning Method
Section 3 motivates a new data generation-based method named Auxiliary Task-based OOD Learning (ATOL), overcoming the mistaken OOD generation via the auxiliary OOD detection task. Referring to Theorem 1, the power of the auxiliary task is built upon C1 and C2. It makes ATOL a two-staged learning scheme, related to auxiliary task crafting (crafting the auxiliary task for C1) and predictor training (applying the auxiliary task for C2), respectively. Here, we provide the detailed discussion.
4.1 Crafting the Auxiliary Task
We first need to construct the auxiliary OOD detection task, defined by auxiliary ID and auxiliary OOD data generated by the generator  $G(\cdot)$ . In the following, we assume the auxiliary ID data  $\hat{\mathbf{x}}_{\mathrm{ID}}$  drawn from  $\mathcal{G}_X^{\mathrm{ID}}$  and the auxiliary OOD data  $\hat{\mathbf{x}}_{\mathrm{OOD}}$  drawn from  $\mathcal{G}_X^{\mathrm{OOD}}$ . Then, according to C1, we need to fulfill the condition that  $\mathcal{G}_X^{\mathrm{ID}}$  and  $\mathcal{G}_X^{\mathrm{OOD}}$  should have the disjoint supports.
Although all distribution pairs  $(\mathcal{G}_X^{\mathrm{ID}},\mathcal{G}_X^{\mathrm{OOD}})$  with disjoint supports can make C1 hold, it is hard to realize such a goal due to the complex data space  $\mathbb{R}^n$  of images. Instead, we suggest crafting such a distribution pair in the latent space  $\mathbb{R}^m$  of the generator, of which the dimension  $m$  is much lower
than  $n$ . We define the latent ID and the latent OOD data as  $\mathbf{z}_{\mathrm{ID}}$  and  $\mathbf{z}_{\mathrm{OOD}}$ , respectively. Then, we assume the latent ID data are drawn from the high-density region of a Mixture of Gaussian (MoG):
$$
\mathbf {z} _ {\mathrm {I D}} \in \mathcal {Z} ^ {\mathrm {I D}} \text {w i t h} \mathcal {Z} ^ {\mathrm {I D}} = \left\{\mathbf {z} \sim \mathcal {M} _ {Z} \mid \mathcal {M} (\mathbf {z}) > \tau \right\}, \tag {6}
$$
where  $\tau$  is the threshold and  $\mathcal{M}_Z$  is a pre-defined MoG, given by the density function of MoG  $\mathcal{M}(\mathbf{z}) = \sum_{i=1}^{c} \frac{1}{c} \mathcal{N}(\mathbf{z} | \boldsymbol{\mu}_i, \boldsymbol{\sigma}_i)$ , with the mean  $\boldsymbol{\mu}_i$  and the covariance  $\boldsymbol{\sigma}_i$  for the  $i$ -th sub-Gaussian. Furthermore, as we demonstrate in Section 4.2, we also require the specification of labels for latent ID data. Therefore, we assume that  $\mathcal{M}_Z$  is constructed by  $c$  sub-distributions of Gaussian, and data belong to each of these  $c$  sub-distributions should have the same label  $\hat{y}_{\mathrm{ID}}$ .
Remark 2. MoG provides a simple way to generate data, yet the key point is to ensure that auxiliary ID/OOD data should have the disjoint support, i.e., C1. Therefore, if C1 is satisfied properly, other noise distributions, such as the beta mixture models[40] and the uniform distribution, can also be used. Further, our ATOL is different from previous data generation-based methods in that we do not require generated data to be reliable in the data space. ATOL does not involve fitting the MoG to real ID data, where the parameters can be pre-defined and fixed. Therefore, we do not consider overfitting and accuracy of MoG in our paper.
Furthermore, for the disjoint support, the latent OOD data are drawn from a uniform distribution except for the region with high MoG density, i.e.,