Debugging and Explaining Metric Learning Approaches: An Influence Function Based Perspective
Abstract
Deep metric learning (DML) learns a generalizable embedding space where the representations of semantically similar samples are closer.
Despite achieving good performance, the state-of-the-art models still suffer from the generalization errors such as farther similar samples and closer dissimilar samples in the space.
In this work, we design empirical influence function (EIF), a debugging and explaining technique for the generalization errors of the state-of-the-art metric learning models.
EIF is designed to efficiently identify and quantify how a subset of training samples contribute to the generalization errors.
Moreover, given a user-specific error, EIF can be used to relabel a potentially noisy training sample as a mitigation.
In our quantitative experiment, EIF outperforms the traditional baseline in identifying more relevant training samples with statistical significance and 33.5% less time.
In the field study on the well-known datasets such as CUB200, CARS196, and InShop, EIF identifies 4.4%, 6.6%, and 17.7% labelling mistakes, indicating the direction of the DML community to further improve the model performance.
Our code is available at https: //github.com/lindsey98/Influence_function_metric_learning .
Introduction
Deep metric learning (DML) learns a generalizable embedding space of a dataset, where semantically similar samples are mapped closer [12].
It has been widely applied in face recognition [27], image retrieval [38] and clustering [5].
Recently, the record-breaking methodologies have been generally evolving from pairwise-based approaches (e.g., triplet-based [12] and pair-based [11]) to proxy-based approaches [20, 14, 31, 10, 23].
However, many recent works [28, 25] begin to achieve only marginal improvements on the classical datasets [37, 18, 19].
Thus, the explanation approaches of DML are in need for understanding why the trained model confuses the dissimilar samples and fails to recognize the similar samples .
This research starts with our investigation on popular classical datasets (i.e., CUB200, CARS196, and InShop) that, for state-of-the-art metric learning approaches, (1) different approaches share not only similar performance metrics (e.g., Recall@1), but the same types of generalization errors, and (2) the human inspection sometimes has no less generalization errors on existing DML datasets.
We report the results at Section 5 and our website [2].
The observation leads us to design an influence function based explanation framework to investigate the existing datasets, consisting of:
• Scalable training-sample attribution: We propose empirical influential function (EIF) to (1) identify what training samples contribute to the generalization errors, and (2) quantify how much contribution they make to the errors.
Technically, we replace the Hessian matrix in traditional influence function [15] with light-weighted Newton step estimation to improve both its effectiveness and efficiency.
• Dataset relabelling recommendation: We further aim to identify the potentially “buggy” training samples with mistaken labels and generate their relabelling recommendation.
Technique Evaluation.
We design one sample-locating experiment and one sample-relabelling experiment on 3 datasets to evaluate our framework.
In the sample-locating experiment, we evaluate EIF’s performance on locating the influential training samples for both individual-pair confusion (i
e., model is confused on one pair of samples) and group-pair confusion (i
e., model is confused on a class of samples).
The results show that, compared to the traditional influence function [15], EIF identifies root-cause training samples which can significantly mitigate the confusion distances with 33.5% less time.
As for the sample-relabelling experiment, we inject 10% noisy training samples to train a DML model.
Our results show that we can accurately recommend on average 88.2% of the mis-labelled training samples.
Empirical Investigation.
Based on the proposed framework, we investigate the classical datasets such as CUB200 [37], CARS196 [18], and InShop [19].
We find that the labels annotated in the datasets are more unreliable than expected.
We summarize a taxonomy of dataset problems (e.g., see
Section 5), We further conclude that the major barriers for DML performance might not be the model design, but the confusing labels in the classical datasets.
In summary, this work makes the following contributions:
• We propose empirical influence function (EIF) for DML approaches, which can attribute root-cause training samples for arbitrary number of pairs of unseen test samples.
• We propose a sample-relabelling technique based on EIF for mitigating potential dataset problems.
• We identify and categorize labelling problems of the well-known classical datasets for DML, indicating the potential direction to further improve the performance of DML approaches.
Problem Setting
We denote the input space as X ⊂ R d
( d is the input dimension), the embedding space as Z ⊂ R m ( m is the embedding dimension), and the class label space Y ⊂
Z + .
A DML network f ( . ) parameterized by θ is denoted as f θ : X → Z .
Given a distance measure d ( ., . )
where d : Z × Z → { 0 , R + } , we can calculate the distance between any input pairs ( x i ,
x j ) ∈
X by d ( f θ ( x i ) , f θ ( x j )) .
Typically, cosine distance and Euclidean distance are common choices of d ( ., . ) .
In addition, we define a labelling
function
R ( . )
where R : X → Y .
The DML techniques aim to optimize θ such that ∀ x i , x j , x k ∈ X
( y i , y j , y k ∈ Y , y i =
y j ̸ = y k ),
d ( f θ ( x i ) , f θ ( x j )) <
d ( f θ ( x i ) , f θ ( x k )) .
Pair-based losses try to optimize the inequality directly on pairs / triplets [11, 12, 29].
However, studies have shown that the optimization suffer from (1) slow and noisy convergence, (2) high computational complexity.
Therefore, proxy-based losses have been proposed to address these issues [20, 31, 14, 23, 6], which significantly outperform the pair-based losses.
Most of proxy-based losses are defined on a per-sample basis [20, 31, 23, 6].
Therefore, in this work, we follow the loss of form L ( x ; θ ) .
Given the training dataset set X train with labels Y train and the testing dataset X test with labels Y test where training and testing are class disjoint, i.e., Y train ∩ Y test = ∅ .
The generalization error can be defined as a testing sample not sharing the same class label as its nearest neighbor in the space, i.e.,
Definition 2.1.
We define a testing-sample pair p =
( x i , x j ) ( x i , x j ∈ X test ) as a confusion pair if:
z j = f θ ( x j ) is the nearest neighbour of z i =
f θ ( x i ) in the distance space; 2.
y i ̸
= y j
and y i , y j ∈ Y test .
Given a set of confusion pairs P c
= { p 1 , p 2 , ..., p n } , we aim to achieve the following two goals:
G1.
Influential Sample Identification We aim to locate the set of root-cause training samples
X r ⊂ X train such that retraining with re-weighted X r can increase the average distance of confusion pairs in P c the most,
[Equation]
In Equation 1, ˆ θ r is the retrained model by re-weighting the training sample x i by ϵ i .
Specifically, | ϵ i | is the re-weighting magnitude, if x i is a helpful training sample (i.e. helpful in de-confusion), then ϵ i is set to be greater than one; otherwise for a harmful training, ϵ i is set to be less than one.
Under certain choice of X r , the average distance of the confusion pair set P c is maximized.
G2. Influential Sample Relabelling
We aim to find the set of root-cause training samples
X l ⊂
X train and a relabelling function R : X
→ Y such that retraining θ by changing the labels of X l with
R ( . ) can increase the average distance of confusion pairs in P c the most.
Specifically,
[Equation]
to
[Equation]
Approach
Recaping Influence Function Given that a learned model parameterized by ˆ θ , and its DML loss
L ( x ; ˆ θ ) .
The influence of up-weighting a training sample x train on a testing sample x test is [15]:
[Equation]
In Equation 3, ˆ θ is the original model, ˆ θ ′ is the retrained model after x train is adjusted, H − 1 θ
[Equation]
1 |
[Equation]
train |
[Equation]
|X train | i =
[Equation]
∇ 2 θ L ( x i , ˆ θ ) .
The first term can be interpreted as the testing sample’s sensitivity to the model’s parameters, the second term estimates the interaction between training samples, and the third term is the influence of this training sample to the model.
In DML settings, testing loss is undefined according to Equation 3 since testing classes are unseen.
Given a confusion pair p c =
( x i , x j ) with distance d ( p c ; ˆ θ ) , we can replace the testing loss with d ( p c ; ˆ θ ) , i.e.,
[Equation]
However, computing I ( x train , p c ) still suffers from two drawbacks, i.e., (1) high computational cost and (2) inaccurate approximation for group-pair confusion.
High Computational Cost Computing the Hessian function H − 1 ˆ θ is non-trivial, which requires the complexity of O ( np 2 + p 3 ) where n is training dataset size and p is the parameter size.
In [15], the complexity is further reduced to O ( np + rtp ) where rt ∼ O ( n ) .
With the increase of parameter size (e.g., millions) and the training set, the runtime cost is still considerably large.
[Figure]
Sphere ( θ 0 , r)
Accuracy of Influence of Group-pair Confusion When we are locating the influential training samples for a group of confusion pairs, the assumption of Equation 4 cannot hold in practice because the derivation of the Hessian matrix H − 1 ˆ θ in Equation 3 requires that ˆ θ ′ ∼ ˆ θ so that Taylor expansion can be applied [15].
However, the number of influential training samples to a group of confusion pairs (i.e., X r in Equation 1) can be large, indicating that the adjusted parameters ˆ θ ′ could be very different from the original ˆ θ .
Thus, such approximation can lead to inaccurate estimation.
Empirical Influence Function (EIF)
In this work, we design empirical influence function (EIF) to address the above challenges.
Our rationale lies in that, (1) fitting harmful samples contribute to more generalization errors, and (2) fitting helpful samples contribute to mitigating the generalization errors.
We estimate the influence scores by the empirical co-change product between the distance of confusion pairs ∆ d
( P c ; θ ) and the training loss ∆ L ( x ; θ ) ( x ∈ X train ) as Equation 5:
[Equation]
Assume that we train the network by upweighting x to have θ
→ θ , the co-change product is defined as
[Equation] [Equation]
cop (∆ d ( P c ; θ ) , ∆ L ( x ; θ )) > 0 indicates that x is harmful.
Intuitively, x is harmful to distinguish P c if (1) more fitting on x (with ∆ L ( x ; θ )) < 0 ) co-happens with more confused pairs (with ∆ d ( P c ; θ ) < 0 ) or (2) less fitting on x (with ∆ L ( x ; θ )) > 0 ) co-happens with less confused pairs (with ∆ d ( P c ; θ ) > 0 ).
On the other hand, cop (∆ d ( P c ; θ ) , ∆ L ( x ; θ )) < 0 indicates that x is helpful.
However, retraining each individual sample is prohibitively expensive, therefore we need to estimate the integral by carefully sampling representative θ ’s only.
As shown in Figure 1, assume that θ 0 is the model parameter, θ is the parameter after re-retraining, the distribution of θ forms a high-dimensional Sphere p ( θ ) ∼ Sphere ( θ 0 , r ) with a radius r , where r is some pre-defined bound to limit the perturbation step.
The intractable integral in Equation 5 is estimated by drawing Monte Carlo samples (e.g., θ (1) , θ (2) , ...
θ ( m ) ) on the sphere.
i.e., we sample
[Equation]
In this work, instead of random sampling, we heuristically construct Θ , regarding how sensitive each θ ( m
) ∈ Θ is to the change of d ( P c ; θ ) .
Specifically, we first sample θ max ∈
Sphere ( θ 0 , r ) pointing to the steepest ascent direction of d ( P c ; θ ) , which can be considered as “repairing” the network.
Symmetrically, θ min is taken as the steepest descent direction of d ( P c ; θ ) , which can be considered as “worsening” the network.
Next, given a user-defined threshold N θ , we repetitively sample θ ( m ) ∈
Sphere ( θ 0 , r ) which is orthogonal to ∀ θ ∈ Θ , until N θ exhausts.
Θ is calculated once and shared across the whole training set.
Our experiment shows that even using Θ = { θ max } can achieve an accurate influence estimation, with well improved runtime efficiency.
The complexity of our empirical influence function on the whole training set is O ( p ) +
O
( N train ×
N θ × p ) , where p is the parameter size.
The first term stands for the complexity of constructing Θ ,
[Table] [Table]
and the second term is performing forward pass on training data with Θ .
As a result, we can attach each x ∈ X train with an influence function score I ( x , P c ) , which can be used to rank X train and select the most influential training samples.
Input : Training set X train , K
Output : Relabelled set S =
{ ( x , l ) }
X harm = { x |I ( x , P c ) > 0 , x ∈ X train }
S = ∅ for x ∈ X harm do
[Equation]
return S
Sample Relabelling Recommendation Based on the empirical influence function, we propose the data relabelling as a data cleansing strategy.
Given the identified influential harmful training samples X harm from EIF.
Assuming that the noisy samples are the minority in the training dataset, we recommend a label l ∈ Y train according to the labels of its neighbors through a weighted-KNN algorithm (See Algorithm 1).
Intuitively, the label supported by more weighted neighbours is recommended to correct a harmful sample x .
The neighbours are weighted by their proximity to x .
Note that, we use hard label re-assignment (one-hot label) in Algorithm 1 (line 5).
We can also revise it to soft label re-assignment by using the probability score P ( y new ) as the calibration label.
Experiment
Experimental Settings
In this study, we use Proxy-NCA++ [31] and SoftTriple [23] loss to train
DML models with ResNet-50 model architecture on three datasets, i.e., CUB200 [37], CARS [18], and InShop [19].
The influential sample location capability is evaluated by a DML training experiment.
The sample relabelling capability is evaluated by the noisy data relabelling experiment.
In the DML training experiment, we evaluate whether retraining the model by upweighting or downweighting the reported influential samples can mitigate the confusion pairs.
In the noisy data relabelling experiment, we flip 1%, 5%, and 10% of the labels in the above training datasets, and evaluate whether EIF can identify and correct those noisy samples.
We choose the influence function with modified testing loss function (as in Equation 4) as our baseline.
More details of training configuration can be referred on our website [2].
DML Training Experiment In the experiment, for each dataset, we select the top- K ( K =30, 50, 70, 90, 100) most confusing pairs in its testing dataset.
For each selected confusion pair p k , we
[Table] [Table]
IF
[Table]
/ evaluate the identified influential training samples (either helpful or harmful) by comparing :
[Equation] [Equation]
In Equation 7, θ 0 represents the original network, θ ′ represents the network actually trained by downweighting harmful samples and up-weighting helpful samples for one epoch, and d ( p k ; θ ′ ) represents the L2-normalized embedding distance of the confusion pair p c on θ ′ .
We test the hypothesis
H 1 : ∆ ¯ d EIF ( p k ) >
∆ ¯ d IF ( p k ) , i.e., the selected influential samples by EIF can de-confuse the confusion pairs in a more significant way than IF on average.
We use the paired t-test for the statistical hypothesis testing, with the assumption that the normality assumption can hold when
K > = 30 [13].
Furthermore, to evaluate whether EIF can work well on groups of confusion pairs, we select the top- M ( M =10, 15, 20, 25, 30) testing classes with the most generalization errors, denoted as
G M = { c 1 , c 2 , ..., c M } .
We call each c m ∈ G M as a confusion pair group.
We evaluate the change in average distance after retraining the influential training samples for each confusion pair group.
[Equation]
We test the hypothesis H 1 : ∆ ¯ d EIF ( c m ) >
∆ ¯ d IF ( c m ) over G M .
We use non-parametric hypothesis testing method, i.e. Wilcoxon signed-rank test since M < = 30 .
Noisy Data Detection Experiment
In the experiment, we evaluate how effective EIF can detect and recommend to relabel the noisy training samples.
Results: Influential Sample Identification Table 1 shows the comparison of the score ∆ d ( p ) between EIF and the original influence function (IF).
We can see that EIF outperforms IF on the average improvement on “deconfusing” the confusion pair.
Compared to IF, EIF identifies samples with which retraining the model can increase larger distance for the confusion pair.
Moreover, the improvement is of statistical significance (all p -values are smaller than 0.001 but the group confusion on the InShop dataset).
Compared to other datasets, InShop is a few-shot dataset with more noises (i.e., 50K over 8K classes), which may require a larger training batch size for EIF to be more effective.
Results: Relabelling Recommendation Figure
shows the performance of EIF on detecting 10% noisy data samples on the three datasets.
The x-axis represents the ranked training samples regarding
[Figure]
of training data
checked 0.
F r a c t i o n o f m i s l a b e ll e d d a t a d e t e c t e d
EIF with N_theta = 1 EIF with N_theta = 2 Random (a) CUB 0.
[Figure]
F r a c t i o n o f m i s l a b e ll e d d a t a d e t e c t e d
EIF with N_theta = 1 EIF with N_theta =
[Figure]
[Figure] [Figure]
F r a c t i o n o f m i s l a b e ll e d d a t a d e t e c t e d
EIF with N_theta = 1 EIF with N_theta =
[Figure]
their influence score in descending order (from positive to negative values), the y-axis represents the ratio of mislabelled samples being detected.
We plot random choice (in green) and EIF with different N θ (in blue and orange).
Readers can refer to Section 3 for the definition of N θ .
We can see that the samples of influence score with small magnitude contribute very few noisy samples; in contrast, either reported harmful or helpful training samples constitute almost all the noisy samples.
Our investigation shows that the harmful and the helpful noisy samples are influential in a different way.
Comparing to those harmful noisy samples, helpful noisy samples are largely ignored by the model.
Thus, they have much larger training loss than the other samples, making them sensitive to model perturbation.
Further, Table 2 shows the performance of recommending the relabelling suggestion.
Overall, the sampling relabelling algorithm performs well in predicting and re-calibrating the labels.
Note that, with the increase in mislabelling ratio, the relabelling algorithm can still preserve its performance.
Results: Runtime Performance Table 3 shows the runtime cost of EIF and IF in the above experiment.
We use N θ = 1 for (see Section 4) recording the runtime cost of EIF.
In Table 3, we report the mean ± std runtime for mislabelled sample experiments.
Overall, we can see that EIF can boost the runtime efficiency of IF by ∼ 33.5% on average.
Qualitative Result We qualitatively investigate the top 5 harmful samples identified by EIF v.s. IF.
One example is shown in Figure 3.
Overall, we have the following two observations (1) EIF identifies top harmful training samples more visually similar to the testing pair (compared to those from IF) and (2) distributed in concentrated classes.
More examples can be found in ?? [Table] [Figure] [Table]
[Figure]
Field Study on Popular Datasets
Based on our EIF framework, we further investigate the generalization errors of the state-of-the-art models make on the popular datasets such as CUB200 [37], CARS196 [18], and InShop [19].
We investigate (1) what does the generalization errors look like and how human agree with the errors?
(2) what are the root causes for the erroneous model decision?
In this study, we choose Proxy-NCA++ [31] in this study as its leading performance in metric learning community.
Study Design For each dataset, we investigate two types of generalization errors: confusion pair and mis-similar pair.
The mis-similar pair corresponds to the alternative definition in Section 2, i.e., the semantically similar pair with large distance.
For each erroneous pair, we manually evaluate and classify them into: (1) agreeable error and (2) disagreeable error.
For agreeable errors, humans agree with the model’s decision.
For disagreeable errors, humans disagree with the model.
In this study, we recruit two volunteers (university graduate students majoring in computer science) to independently verify the reported confusion and mis-similar pairs.
For the pairs where they disagree with each other, we let them discuss and reach a consensus.
In addition, we use Algorithm 1 to identify and generate relabelling suggestions for the harmful training samples of the erroneous pairs.
Based on the recommendation, we further confirm the recommendation and qualitatively analyze the reported problems in training datasets.
Generalization Errors and Their Agreeability Table 4 shows that human may share a considerable number of generalization errors with the model.
Overall, human agrees with 51.6% (31 out of 60) of the confusion pairs and 30% (18 out of 60) of the mis-similar pairs.
We show agreeable and disagreeable confusion pairs in Figure 4.
Overall, human investigators agree with many of the “erroneous” model decisions.
Readers can check mis-similar pairs on our website [2].
Root Cause of Erroneous Decision Table 5 shows that EIF generates relabelling suggestion for 41% (41 out of 100) training classes in CUB200 dataset, 46.9% (46 out of 98) training classes in the
CARS196 dataset, and 22.5% (901 out of 3997) training classes in the InShop dataset.
Moreover, we further investigate the training classes with more than 10% of their samples recommended to change their labels.
We can see that, compared to CUB200 and CARS196, the InShop dataset has more confusing training classes.
Figure 5 show some relabelled training samples in the InShop dataset.
We further manually sample the training classes with relabelling recommendations, regarding the following criteria:
• Centralized Relabelling :
The training classes with more than 10% samples are recommended to be relabelled, and the recommended labels lean towards a single label.
[Table]
[Figure]
Figure 5a is recommend to relabel to class 652, Figure 5c is recommend to relabel to class 2961,
Figure 5e is recommend to relabel to class 2216,
• Diversified Relabelling :
The training classes with more than 10% samples are recommended to be relabelled, and the recommended labels lean towards diversified labels.
• Individual Relabelling :
The training classes with less than 5% samples are recommended to be relabelled.
We distinguish centralized and diversified relabelling cases by introducing a threshold th H (we use 0.35 in this study).
Given the entropy of the relabelling-class distribution of a class C as H c , if
H c < th H , we consider C as a centralized relabelling class; otherwise, we consider C as a diversified relabelling class.
Generally, a dataset, if with centralized relabelling requirements, needs to have its relevant training classes merged.
In contrast, a dataset, if with diversified and individual relabelling requirements, needs to clean the samples under the relevant training classes.
We sample 3 training classes from each category on each dataset and report the confirmed relabelled suggestions in Table 6.
Overall, EIF achieves high recommendation accuracy on the training classes with centralized and diversified relabelling in CUB200 and CARS196; and acceptable accuracy on the training classes with individual relabelling classes in CARS196 and InShop.
We provide more details on our website [2].
Summary and Discussion
In this study, we conclude that the following problems are universal among the popular DML training and testing datasets:
• The testing dataset includes a number of arguably confusing samples, thus an “erroneous” model decision by the labels of testing samples may not necessary be really erroneous.
• Some classes are confusing with each other,
i
e., over 10% of the samples have the potential to be merged into other classes.
• Many training classes involve outliers that look very different from other samples in the same class, but similar to other classes.
We provide more detailed examples on our website [2].
We conclude that those dataset problems are one of the most important barriers to further improve new state-of-the-art DML approaches.
The future work of DML should revolve around dataset cleaning and merging to improve the metrics in a more significant manner.
Related Work
Deep Metric Learning Deep metric learning (DML) learns an embedding space such that intraclass samples are located closer than inter-class samples.
Loss functions are usually the key for learning such an embedding, which has been evolved from pairwise-based loss such as [11], [12], [7], and [29] to proxy-based loss such as [20, 31, 6, 34, 8, 23, 14].
[Table] While new approaches emerge to outperform the state-of-the-art with marginal improvements [21, 10, 24, 40], few work has been proposed towards understanding of generalization error in DML, from the dataset perspective.
This work makes the first step, and our findings shed light on the potential problems of the datasets.
Moreover, our EIF technique can further facilitate their fixes.
Model Explanation Despite its great successes in multiple disciplines, the deep learning model has remained to be black-box mystery for decades.
There are two types of explanations: featurelevel and instance-level.
While feature-level explanations would like to interpret the semantics and importance of features, instance-level explanations would like to quantify the individual training sample’s contribution to prediction.
In [15], the idea of influence function is introduced to measure the change in testing loss upon removal of certain training sample.
Variations of influence functions are later developed to solve the overestimation for outliers [3], the low diversity in high-influence points [4], the high computaional cost in Hessian estimation [26, 22].
RPS [39] proposes an alternative view from the Representer Point Theorem: they use the weighted kernels of training points as the influence measure.
Since RPS has restrictions on model regularizers, RPS-LJE [30] has been later proposed to generalize RPS to models without regularization.
However, its definition has subtle differences to the original influence function [15].
Influence function has been applied to various tasks such as VAE [17], GAN [32], data poisoning [9], causal inference [1], data subsampling [33, 36, 35], data relabelling [16].
As far as we know, we are the first work which designs influence function catering to DML problems.
Conclusion
In this work, we design an empirical influence function (EIF) to debug and understand the generalization errors in state-of-the-art deep metric learning models.
Comparing to the traditional influence function, EIF can (1) guide us to locate the influential harmful and helpful training samples and (2) recommend the potential relabelling suggestion for the harmful training samples.
Our extensive experiments have proved its effectiveness.
With the support of EIF, we further identify the problems of existing datasets for metric learning, which suggests the improvement of the dataset for achieving further world-record performance.
Acknowledgement
This research is supported in part by the Minister of Education, Singapore (T1-251RES1901,
T2EP20120-0019, MOET32020-0004), NUS-NCS Joint Laboratory for Cyber Security, Singapore, the National Research Foundation, Singapore, and Cyber Security Agency of Singapore under its
National Cybersecurity Research and Development Programme (Award No. NRF-NCR_TAU_20210002) and A*STAR, CISCO Systems (USA) Pte.
Ltd and National University of Singapore under its
Cisco-NUS Accelerated Digital Economy Corporate Laboratory (Award I21001E0002).