SlowGuess/NeurIPS_2023_OCR huggingface dataset:
I.I.D. setting. Table 2 reports both accuracy and ECE on the dataset CIFAR-10/100 and ImageNet1k, where the training and evaluation data follow the same distribution. Our method considerably improves both accuracy and ECE over all baselines. It is worth noting that except ER and our method, the others cannot simultaneously improve both ECE and accuracy, trading accuracy for calibration or vice versa. Compared to conventional ER with a constant weighting, our sample difficulty-aware instance-wise weighting leads to much more pronounced gains, e.g., reducing ECE more than  $50\%$  on ImageNet1k with an accuracy increase of  $+0.43\%$ . Furthermore, we also compare with PolyLoss [29], a recent state-of-the-art classification loss. It reformulates the CE loss as a linear combination of polynomial functions and additionally allows flexibly adjusting the polynomial coefficients. In order to improve the accuracy, it has to encourage confident predictions, thus compromising ECE. After introducing the sample difficulty awareness, we avoid facing such a trade-off.
Table 2: The comparison of predictive Top-1 accuracy (\%) and ECE (\%) on CIFAR-10/-100 and ImageNet1k using ResNet-34. The six baseline methods respectively use the standard cross entropy (CE) loss, CE with label smoothing (LS) [36], focal loss (FL) [35], CE with  $L_{1}$  Norm-based regularization [22], CE with entropy regularization (ER) [42], and PolyLoss (Poly) [29]. In contrast to our method, all these baseline losses are sample difficulty-agnostic.
CE	LS	FL	\(L_1\)Norm	ER	Poly	Proposed
CIFAR-10	ACC↑	93.79	94.47	93.82	94.51	94.34	94.66	95.67±0.16
ECE↓	3.980	3.816	3.520	3.542	3.198	5.283	1.212±0.11
CIFAR-100	ACC↑	76.79	76.48	76.74	74.32	77.32	77.39	78.58±0.12
ECE↓	7.251	6.363	4.110	6.232	4.092	8.554	3.410±0.23
ImageNet1k	ACC↑	73.56	73.69	72.82	73.21	73.68	74.02	74.11±0.10
ECE↓	5.301	3.994	4.901	2.625	3.720	7.882	1.602±0.15
Figure 3: Box plot: ECEs of different methods on ImageNet-C under all types of corruptions with 5 levels of shift intensity. Each box shows a summary of the results of 16 types of shifts.
Figure 4: Accuracy vs. rejection rate, using the predictive entropy as the uncertainty measure to reject predictions on ImageNet1k.
Improvements across classification models. If our sample difficulty measure carries useful information about the dataset, it should lead to consistent gains across different classifier architectures (e.g., ResNet, Wide-ResNet and DenseNet). Table 9 in Appendix positively confirms that it benefits the training of small and large models.
Under distributional shift. [39] has shown that the quality of predictive uncertainty degrades under distribution shifts, which however are often inevitable in real-world applications. We further evaluate the calibration performance achieved by the ImageNet1k classifier on ImageNet-C [17]. Specifically, Fig. 3 plots the ECE of each method across 16 different types of corruptions at five severity levels, which ranges from the lowest level one to the highest level five. It is prominent that the proposed method surpasses other methods for ECE at various levels of skew. In particular, the gain becomes even larger as the shift intensity increases.
5.2 Selective classification
While we do not have the ground-truth predictive uncertainty annotation for each sample, it is natural to expect that a more uncertain prediction should be more likely to be wrong. A critical real-world application of calibrated predictions is to make the model aware of what it does not know. Next, we validate such expectations via selective classification. Namely, the uncertainty measure is used to detect misclassification via thresholding. Rejecting every prediction whose uncertainty measure is above a threshold, we then evaluate the achieved accuracy on the remaining predictions. A high-quality uncertainty measure should improve the accuracy by rejecting misclassifications but also ensure coverage (not trivially rejecting every prediction).
Misclassification detection. Table 3 reports the threshold-free metrics, i.e., FPR, AUROC and AUPR, that quantify the success rate of detecting misclassifications based on two uncertainty mea
sures, i.e., maximum softmax probability (MSP) [18] and entropy. The proposed regularizer is obviously the top-performing one in all metrics on both CIFAR100 and ImageNet1k. The gains are particularly pronounced in FPRs, indicating that the proposed method does not overly trade coverage for accuracy. This is further confirmed in Fig. 4.
Interestingly, our method also reduces the performance gap between the two uncertainty measures, i.e., entropy can deliver similar performance as MSP. Both are scalar measures derived from the same predictive distribution over all classes but carry different statistical properties. While we cannot directly assess the predictive distribution, the fact that different statistics derived from it are all useful is a positive indication.
Accuracy vs. Coverage. Fig. 4 plots the accuracy vs. rejection rate on ImageNet1k. Compared to the cross entropy loss (CE) and entropy regularization (ER) with a constant weighting (which is the best baseline in Table 3), our proposal offers much higher selective classification accuracy at the same rejection rate. Moreover, the gain (orange area) increases along with the rejection rate, indicating the effectiveness of our method. Without sample difficulty-aware weighting, the accuracy gain of ER over CE vanishes on ImageNet1k.
In Appendix D, we also compare the predictive entropy and confidence of different methods for wrong predictions, see Fig 11. The proposed method achieves the lowest predictive confidence and highest entropy among all methods for misclassified samples, which further verifies the reliable uncertainty estimation of the proposed regularizer.
Table 3: The comparison of misclassification de- Table 4: The comparison of near OOD detection detection performance  $(\%)$  . performance  $(\%)$
Dataset	Method	FPR-95%↓	AUROC ↑	AUPR ↑
C100	CE	MSP / Entropy
LS	45.21/47.44	86.29/86.58	94.70/95.47
FL	49.19/49.71	86.00/85.82	94.31/94.19
L1	47.30/48.84	85.90/84.72	94.90/94.50
ER	48.11/48.40	85.52/85.31	94.05/93.90
CRL	45.40/46.88	86.32/85.69	95.26/95.20
Ours	44.80/46.08	86.67/85.98	95.55/95.49
ImageNet1k	CE	42.71/43.22	87.50/87.03	96.10/96.02
LS	46.93/48.94	86.03/85.02	94.22/93.75
FL	52.12/61.52	85.28/81.03	93.86/91.98
L1	48.54/51.10	85.67/83.05	94.08/93.03
ER	47.19/48.58	86.19/84.58	94.39/93.82
CRL	46.03/48.01	86.11/84.33	94.38/93.82
Ours	45.69/46.72	86.53/85.23	94.76/94.31
Din/Dout	Method	FPR-95%↓	AUROC ↑	AUPR ↑
MaxLogit / Entropy
C100/C10	CE	60.19/60.10	78.42/78.91	79.02/80.19
LS	69.51/70.08	77.14/77.31	75.92/75.89
FL	61.02/61.33	78.79/79.36	80.22/80.22
L1	61.58/61.60	76.52/76.58	79.19/79.21
ER	59.52/59.92	79.22/79.46	81.01/81.22
CRL	58.13/58.54	79.91/80.13	81.75/81.89
Ours	55.48/55.60	80.20/80.72	82.51/82.84
ImageNet1k / iNaturalist	CE	36.06/40.33	89.82/89.02	97.61/97.40
LS	37.56/41.22	89.10/89.35	97.12/97.30
FL	36.50/36.32	90.03/90.25	97.76/97.80
L1	38.32/46.03	88.90/88.29	97.53/97.27
ER	36.00/35.11	89.86/90.04	97.75/97.43
CRL	35.07/34.65	90.11/90.32	97.96/97.81
Ours	32.17/34.19	91.03/90.65	98.03/97.99
5.3 Out-of-distribution detection (OOD)
In an open-world context, test samples can be drawn from any distribution. A reliable uncertainty estimate should be high on test samples when they deviate from the training distribution. In light of this, we verify the performance of the proposed method on near OOD detection (i.e., CIFAR-100 vs CIFAR-10 and ImageNet1k vs iNaturalist), which is a more difficult setting than far OOD tasks (e.g., CIFAR100 vs SVHN and CIFAR10 vs MNIST) [12].
As our goal is to evaluate the quality of uncertainty rather than specifically solving the OOD detection task, we leverage MaxLogit and predictive entropy as the OOD score. [16] showed MaxLogit to be more effective than MSP for OOD detection when dealing with a large number of training classes, e.g., ImageNet1k. Table 4 shows that the uncertainty measures improved by our method lead to improvements in OOD detection, indicating its effectiveness for reliable predictions.
5.4 The robustness of hyperparameter  $\alpha$
We analyze the effects of hyper-parameters:  $\alpha$  in ER and the proposed method on the predictive performance, and Table 5 reports the comparison results of different  $\alpha$  on ImageNet1k. Compared to ER, the proposed method is less sensitive to the choice of owing to sample adaptive weighting, whereas ER penalizes confident predictions regardless of easy or hard samples. Oftentimes, a large
Table 5: The comparison for ACC and ECE under different  $\alpha$  on ImageNet1k. Bold indicates the results from the chosen hyperparameter.
α	0	0.05	0.10	0.15	0.20	0.25	0.30
ER	ACC	73.56	73.59	73.68	73.76	73.78	73.81	73.88
ECE	5.301	3.308	3.720	10.19	15.24	25.22	33.26
Proposed	ACC	73.56	73.89	73.91	74.08	74.11	74.13	73.98
ECE	5.301	1.855	1.851	1.596	1.602	1.612	1.667
A portion of data is not difficult to classify, but the equal penalty on every sample results in the model becoming underconfident, resulting in poor ECEs.
5.5 Comparison of different sample difficulty measures
Finally, we compare different sample difficulty measures for reliable prediction, showing the superiority of using large-scale pre-trained models and the derived RMD score.
CLIP is the top-performing model for sample difficulty quantification. In addition to Fig. 2, Table 6 compares the pre-trained models listed in Table 1 in terms of accuracy and ECE. All pre-trained models improve the baseline (using the standard CE loss), especially in ECE. CLIP outperforms ViT-B/MAE-ViT-B, thanks to a large amount of diverse multi-modal pre-trained data (i.e., learning the visual concept from language supervision). Additionally, the performance of using recent DINOv2 [38] as a pre-trained model to quantify sample difficulty also surpasses ViT-B/MAE-ViT-B. While ImageNet21k is larger than ImageNet1k, self-supervised learning adopted by MAE-ViT-B reduces overfitting the training classes, thus resulting in better performance than ViT-B (which is trained supervisedly).
Table 6: The comparison of different pre-trained models for accuracy and ECE on ImageNet1k.
ViT-B	MAE-ViT-B	DINOv2	CLIP-R50	CLIP-ViT-B
ACC ↑	73.59	73.81	74.01	74.05	74.11
ECE ↓	2.701	1.925	1.773	1.882	1.602
CLIP outperforms supervised models on the task dataset. To further confirm the benefits from large-scale pre-training models, we compare them with supervised models on the task dataset (i.e., ImageNet1k). We use three models (i.e., ResNet34/50/101) trained with 90 epochs on ImageNet1k to measure the sample difficulty. We did not find it beneficial to use earlier-terminated models. The classifier model is always ResNet34-based. Besides RMD, we also exploit the training loss of each sample for sample difficulty quantification. Table 10 in Appendix shows that they all lead to better ECEs than ER with constant weighting (see Table 2). Compared to the pre-trained models in Table 6, they are slightly worse than ViT-B in ECE. Without exposure to the 1k classes, MAE-ViT-B achieves a noticeably better ECE. The pronounced improvements in both accuracy and ECE shown in the last column of Table 10 are enabled by CLIP.
Effectiveness of RMD. We resorted to density estimation for quantifying sample difficulty and derived the RMD score. Alternatively, [50] proposed to use the frequency of correct predictions during training epochs. Based on that, [34] proposed a new loss termed correctness ranking loss (CRL). It aims to ensure that the confidence-based ranking between the two samples should be consistent with their frequency-based ranking. Table 7 shows our method scales better with larger datasets. Our RMD score is derived from the whole data distribution, thus considering all samples at once rather than a random pair at each iteration. The ranking between the two samples also changes over training, while RMD is constant, thus ensuring a stable training objective.
Next, we compare different distance measures in the feature space of CLIP-ViT-B, i.e., K-means, MD and RMD. Table 8 confirms the superiority of RMD in measuring the sample difficulty and ranking the training samples.
Table 7: The comparison of RMD and correctness Table 8: The comparison of different sample diffi- ranking loss (CRL) [34] in regularizing the pre- cuity measures for predictive Top-1 accuracy  $(\%)$  prediction confidence. and ECE  $(\%)$  on ImageNet1k.
Method	C10	C100	ImageNet1k
CRL	ACC ↑	94.06	76.71	73.60
ECE ↓	0.957	3.877	2.272
Proposed	ACC ↑	95.67	78.58	74.11
ECE ↓	1.212	3.410	1.602
K-means	MD	RMD
ACC ↑	73.78	73.71	74.11
ECE ↓	2.241	2.125	1.613
This work introduced a new application of pre-trained models, exploiting them to improve the calibration and quality of uncertainty quantification of the downstream model. Profiting from rich large-scale (or even multi-modal) datasets and self-supervised learning for pre-training, pre-trained models do not overfit the downstream training data. Hence, we derive a relative Mahalanobis distance (RMD) via the Gaussian modeling in the feature space of pre-trained models to measure the sample difficulty and leverage such information to penalize overconfident predictions adaptively. We perform extensive experiments to verify our method's effectiveness, showing that the proposed method can improve prediction performance and uncertainty quantification simultaneously.
In the future, the proposed method may promote more approaches to explore the potential of large-scale pre-trained models and exploit them to enhance the reliability and robustness of the downstream model. For example, for the medical domain, MedCLIP [53] can be an interesting alternative to CLIP/DINOv2 for practicing our method. Besides, conjoining accuracy and calibration is vital for the practical deployment of the model, so we hope our method could bridge this gap. Furthermore, many new large-scale models (including CLIP already) have text-language alignment. In our method, we do not explore the language part yet, however, it would be interesting to use the text encoder to "explain" the hard/easy samples in human language. One step further, if the pre-trained models can also synthesize (here CLIPs cannot), we can augment the training with additional easy or hard samples to further boost the performance.
Potential Limitations. Pre-trained models may have their own limitations. For example, CLIP is not straightforwardly suitable for medical domain data, as medical images can be OOD (out-of-distribution) to CLIP. If targeting chest x-rays, we need to switch from CLIP to MedCLIP [53] as a pre-trained model to compute the sample difficulty. In this work, CLIP is the chosen pre-trained model, as it is well-suited for handling natural images, which are the basis of the targeted benchmarks. Besides, the calculation of sample difficulty introduces an additional computational overhead although we find it very affordable.
This work was supported by NSFC Projects (Nos. 62061136001, 92248303, 62106123, 61972224), Natural Science Foundation of Shanghai (No. 23ZR1428700) and the Key Research and Development Program of Shandong Province, China (No. 2023CXGC010112), Tsinghua Institute for Guo Qiang, and the High Performance Computing Center, Tsinghua University. J.Z is also supported by the XPlorer Prize.
[1] Chirag Agarwal, Daniel D'souza, and Sara Hooker. Estimating example difficulty using variance of gradients. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 10368-10378, June 2022.
[2] Robert John Nicholas Baldock, Hartmut Maennel, and Behnam Neyshabur. Deep learning through the lens of example difficulty. In A. Beygelzimer, Y. Dauphin, P. Liang, and J. Wortman Vaughan, editors, Advances in Neural Information Processing Systems, 2021.
[51] Grant Van Horn, Oisin Mac Aodha, Yang Song, Yin Cui, Chen Sun, Alex Shepard, Hartwig Adam, Pietro Perona, and Serge Belongie. The inaturalist species classification and detection dataset. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 8769-8778, 2018.
[52] Deng-Bao Wang, Lei Feng, and Min-Ling Zhang. Rethinking calibration of deep neural networks: Do not be afraid of overconfidence. Advances in Neural Information Processing Systems, 34:11809-11820, 2021.
[53] Zifeng Wang, Zhenbang Wu, Dinesh Agarwal, and Jimeng Sun. Medclip: Contrastive learning from unpaired medical images and text. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pages 3876-3887, 2022.
[54] Xiaohua Zhai, Xiao Wang, Basil Mustafa, Andreas Steiner, Daniel Keysers, Alexander Kolesnikov, and Lucas Beyer. Lit: Zero-shot transfer with locked-image text tuning. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 18123-18133, 2022.
A The comparison of MD and RMD for measuring the sample difficulty
(a) Visualization of the Top-8 hardest samples (top row) and Top-8 easiest samples (bottom row) in ImageNet (class Tusker) which are ranked by means of the CLIP-VIT-B-based RMD score.
(b) Visualization of the Top-8 hardest samples (top row) and Top-8 easiest samples (bottom row) in ImageNet (class Tusker) which are ranked by means of the CLIP-VIT-B-based MD score.
Figure 5: Visualization of the Top-k hardest and easiest samples in ImageNet (class Tusker) which are ranked by RMD and MD scores. In contrast to the MD score, the easy and hard samples measured by RMD are more accurate than those by MD.
(a) Error rate achieved by ResNet18 (trained on ImageNet) on the validation subsets, which respectively contain 500 samples ranked from the  $a$ th to  $b$ th hardest.
Figure 6: The performance comparison of RMD and MD for characterizing Top-K hardest samples.
(b) Error rate achieved by ResNet34 (trained on ImageNet) on the validation subsets, which respectively contain 500 samples ranked from the  $a$ th to  $b$ th hardest.
In Fig. 5, we further compare Top-k hardest and easiest samples that are ranked by RMD (Fig. 5a) and MD (Fig. 5b) scores respectively. We can see that hard and easy samples characterized by RMD are more accurate than those characterized by MD, and there is a high-level agreement between human visual perception and RMD-based sample difficulty. Moreover, we quantitatively compare the performance of RMD and MD for characterizing Top-K hardest samples in Fig 6. We can observe that the error rate of ResNet18 and ResNet34 on the hardest data split rated by RMD is close to  $90\%$ , which significantly suppresses the performance of MD. Therefore, the derived RMD in this paper is an improvement over the class-conditional MD for measuring the sample difficulty.
B Additional comparisons for different pre-trained models
Figure 7: Error rate achieved by DenseNet121 (trained on ImageNet) on the validation subsets, which respectively contain 500 samples ranked from the  $a$ th to  $b$ th hardest. Four different pre-trained models are used for computing RMDs and ranking. They all show the same trend, i.e., the error rate reduces along with the sample difficulty. However, ViT-B supervisedly trained on ImageNet21k performed much worse than the others.
C More hard and easy samples ranked by RMD
Figure 8: Visualization of the Top-8 hardest samples (top row) and Top-8 easiest samples (bottom row) in ImageNet (class indigo bird) which are ranked by means of the CLIP-VIT-B-based RMD score.
Figure 9: Visualization of the Top-8 hardest samples (top row) and Top-8 easiest samples (bottom row) in ImageNet (class echidna) which are ranked by means of the CLIP-VIT-B-based RMD score.
(a) ImageNet1k.
(b) CIFAR100.
D More experimental results
(a) Predictive entropy of misclassified samples on CIFAR and ImageNet datasets.
Figure 11: Predictive entropy and confidence of misclassified samples for different methods on CIFAR and ImageNet datasets.
Figure 10: Histograms of  $s(x_{i},y_{i})$  at different  $T$ .
(b) Predictive confidence of misclassified samples on CIFAR and ImageNet datasets.
Figure 12: Test samples with predictions corresponding to the Top-100 relative Mahalanobis distance. The text box ("x-x") with green shade represents a misclassification. The first number indicates the label class, and the second number indicates the predictive class.
Table 9: The comparison of various architectures for predictive Top-1 accuracy (%) and ECE (%) on ImageNet1k.
Arch.	CE	ER	Proposed
ResNet18	ACC ↑	70.46	70.59	70.82
ECE ↓	4.354	2.773	1.554
ResNet34	ACC ↑	73.56	73.68	74.11
ECE ↓	5.301	3.720	1.602
ResNet50	ACC ↑	76.08	76.11	76.59
ECE ↓	3.661	3.212	1.671
DenseNet121	ACC ↑	75.60	75.73	75.99
ECE ↓	3.963	3.010	1.613
WRN50x2	ACC ↑	76.79	76.81	77.23
ECE ↓	4.754	2.957	1.855
Table 10: The comparison of different model-based measures for predictive Top-1 accuracy  $(\%)$  and ECE  $(\%)$  on ImageNet1k. Compared to the three ResNets, “ $\Delta$ ” denotes the averaged gain achieved by CLIP-ViT-B in Table 6.
Measures	ResNet34	ResNet50	ResNet101	Δ
RMD	ACC ↑	73.73	73.78	73.88	+0.31
ECE ↓	3.298	2.996	2.882	-1.44
Loss	ACC ↑	73.58	73.61	73.75	+0.46
ECE ↓	3.624	2.997	2.783	-1.52