Exploring the Adversarial Robustness of Deep Metric LearningExploring Adversarial Robustness of Deep Metric Learning
The authors propose a robust optimization training framework for deep metric learning (DML), raising R@1 on SOP under l∞(ε=0.01) PGD attack from 0.7% to 53.6% (Table 1).
When the attacker performs inference-time white-box attacks, first-order methods such as PGD are used to perturb the input within an lp ball (l∞ ε=0.01, l2 ε=4) so that the class inferred by the nearest-neighbor anchor changes (untargeted); the victim system is a DML model trained with contrastive or triplet loss and performing class inference via nearest-neighbor anchors.
- Deep metric learning (DML) is widely used in tasks such as face verification and phishing detection, but research conclusions on its robustness to adversarial examples are contradictory; metric losses depend on other samples within the mini-batch, making standard adversarial training difficult to apply directly.
- The authors propose three robust optimization formulations for contrastive and triplet losses, use a PGD attack that perturbs only one component of a tuple/triplet at a time for the inner maximization, and use R+FGSM plus early stopping to reduce training cost.
- On CUB200-2011, CARS196, SOP, and VisualPhish, the R@1 of naturally trained models drops substantially under PGD; after robust training it improves, e.g., on SOP under l∞(ε=0.01) from 0.7% to 53.6%, exceeding VisualPhishNet's 42.8% (Table 1).
- The authors state that the C&W experiment may be non-optimal due to modifications and hyperparameters, and the results should be regarded as a lower bound on C&W robustness (Appendix B); robust training covers only the l2 and l∞ norms and the PGD and C&W attacks, and benign accuracy decreases under some settings (Table 1).
- Evaluated models
- ContrastiveTripletContrastive (ℓ2)Triplet (ℓ2)Contrastive (ℓ∞)Triplet (ℓ∞)VisualPhishNet
- Benchmarks
- CUB200-2011CARS196SOPVisualPhishSynth Dataset
- Metrics
- R@1mAP@R
Deep metric learning (DML) is susceptible to adversarially perturbed samples, and a study proposes a robust optimization formulation to train more robust DML models. This work analyzes the challenge that metric losses depend on samples within a mini-batch; on three commonly used DML datasets, adversarial accuracy improves by 5–76 times, and it outperforms an existing DML model aimed at robustness.
Paper analysis
What problem does this paper attempt to solve?
How to perform adversarial robust training for deep metric learning (DML) models, handling the dependence of metric losses on mini-batch samples.
Core question: how to train deep metric learning (DML) models that are robust to adversarial examples. DML learns a distance metric between samples, pulling similar samples closer and pushing dissimilar samples apart in the embedding space, and is used for tasks where classes not seen in training appear at test time (e.g., zero-shot learning).
- Application scenarios and importance: The authors state that DML is used in tasks such as person re-identification, face verification, phishing detection, and image retrieval, including security-related scenarios, so understanding its sensitivity to adversarial examples and solving the robustness problem is important.
- Gaps in existing research: The authors state that research on whether DML is vulnerable to adversarial example attacks is scarce and the conclusions are contradictory (citing Abdelnabi et al., 2020 and Panum et al., 2020); training DML models with robust optimization techniques has not been sufficiently studied.
- Core challenge: The loss of a metric loss (such as triplet loss) for a single data point depends on the other data points in the mini-batch, whereas the standard classification loss depends only on a single input-output pair; adversarial perturbations are usually computed by maximizing the single-point loss, and this interdependence makes efficient perturbation generation challenging. In addition, the authors state that metric losses are sensitive to high-noise samples, and training may fall into undesirable local minima.
- Contributions of the paper: The authors propose a robust optimization formulation for the two losses, contrastive and triplet; the core observation is that at inference time the attacker perturbs data points to maximize the intra-class distance, and this behavior needs to be considered during training; and they conduct experiments on three commonly used DML datasets.
- Threat model:
- Attacker goal: test-time attacks—untargeted attacks change the class inferred by the nearest-neighbor anchor after perturbation, and targeted attacks make it infer a specified class (the paper focuses on untargeted, because the main goal is use for adversarial training).
- Attacker knowledge: white-box—the attack algorithms rely on the gradient of the loss function with respect to the input (first-order methods such as FGSM, PGD, C&W).
- Attacker capability: perturb the input within an lp norm ball, with l∞(ε=0.01) and l2(ε=4) used in the experiments; for each perturbed data point, its nearest positive-class neighbor is taken to construct the attack.
- Victim system: a DML model trained with contrastive or triplet loss, which at inference uses the class of the nearest anchor in the embedding space as the prediction.
What related research exists?
Related work falls into three groups: DML losses and sampling, adversarial robust training, and research that uses metric losses to enhance classifier robustness.
Deep metric learning (DML)
- Metric losses: contrastive loss (Hadsell et al., 2006), triplet loss (Schroff et al., 2015), Neighborhood Component Analysis (Goldberger et al., 2004) and its extensions (Sohn, 2016; Wang et al., 2019; Zheng et al., 2019)—learning an embedding space where similar samples are close and dissimilar samples are far.
- Sampling strategies: Schroff et al. (2015), Yuan et al. (2017), Xuan et al. (2020) and others study organizing the mini-batch into tuples or triplets to ensure effective training; Wu et al. (2017) point out the impact of sampling on deep embedding learning.
- Hints from surveys: the surveys of Roth et al. (2020) and Musgrave et al. (2020) point out that the actual performance of new metric losses is lower than previously reported, so this paper focuses on the two mature losses, contrastive and triplet.
Adversarial robustness
- Discovery of adversarial examples: Szegedy et al. (2014) and Biggio et al. (2013) found that deep models are susceptible to adversarial examples.
- Robust optimization training: this paper adopts the saddle-point (min-max) formulation of Ben-Tal et al. (2009) and Madry et al. (2018); the authors state that, to their knowledge, training DML models with robust optimization techniques has not been sufficiently studied, with only recent work beginning to address it (Abdelnabi et al., 2020).
- Duan et al. (2018): uses a GAN architecture to generate hard negatives from easy negatives; the paper notes that its goal is to improve natural training rather than adversarial robustness, differing from this paper's focus.
Metric losses as regularization
- Mao et al. (2019), Li et al. (2019): use metric losses as auxiliary regularization to improve the adversarial robustness of CNN classifiers; the paper notes that these methods are not applicable to training robust DML models, because they do not address the inter-data-point dependence caused by metric losses.
Baseline and benchmarks
- Baseline method: VisualPhishNet (Abdelnabi et al., 2020)—the authors state this is, to their knowledge, the only prior attempt to train an adversarially robust DML model with metric losses, based on a VGG16 variant with a 512-dimensional unnormalized embedding, trained on the VisualPhish dataset.
- Benchmarks/datasets: CUB200-2011, CARS196, SOP, VisualPhish, plus a synthetic dataset (Synth Dataset).
The authors position this paper as: a robust DML training framework that accounts for the mini-batch sample dependence and sampling sensitivity of metric losses; and they state that when VisualPhishNet is tested with this paper's attack techniques, its actual robustness is lower than its reported value.
How does the paper address this problem?
Incorporate the sample dependence of metric losses into robust optimization, propose three formulations, and use PGD that perturbs only one component of a tuple for adversarial training.
Overall approach: rewrite the DML metric loss as a surrogate loss that depends on the entire dataset, build a min-max robust optimization formulation on it, and solve the inner maximization with a modified gradient attack, so that adversarial training can be done by perturbing tuples/triplets separately. The method targets two metric losses: contrastive and triplet.
Problem setting and surrogate loss
- DML model: a deep metric model fθ maps the input space X to the d-dimensional unit sphere S^d; at inference, the class of the nearest neighbor in the reference set A (anchors) is used as the prediction, i.e., lb(A, z) = c_{k(A,z)}, where k(A, z) is the index of the anchor that minimizes dθ(a_j, z).
- Surrogate loss: for a sample (xi, yi), the contrastive surrogate loss is l̂(θ, (xi,yi), S) = 1/n∑j lc(θ, (xi,yi), (xj,yj)), i.e., the average contrastive loss over all samples in dataset S; the triplet case is similar (averaging over the same-class set Sy and the different-class set S−y). The key difference from the classification case is that the single-point loss depends on the entire dataset S.
- Attack formulation: an untargeted attack minimizes the perturbation δ under metric µ and changes the predicted label after perturbation; a targeted attack makes the prediction equal to the target label. The paper focuses on untargeted, because the goal is use in adversarial training.
Three robust optimization formulations
- Formulation 1 (direct formulation): minθ 1/n∑i max(z1,...,zn)∈∏j Bp(xj,ϵ) l̂(θ, (zi,yi), S) — all samples are perturbed simultaneously (the max is outside the sum). The authors note this is inconvenient for training algorithms such as SGD/ADAM, because the entire dataset must be perturbed simultaneously, and it is also incompatible with the various sampling strategies of DML.
- Formulation 2 (max moved inside the sum): define the operator max(r, ε, θ), which perturbs only the r-th component of a tuple/triplet (r∈{1,2} for contrastive, r∈{1,2,3} for triplet) to maximize the loss; each tuple can be perturbed separately, which suits adversarial training.
- Formulation 3 (adding a regularization term): add λ·max_{z∈Bp(xi,ε)} dθ(z, xi) to the surrogate loss, i.e., the informal constraint that "when x changes a little, the embedding-space distance should not change too much".
Attack algorithm
- Gradient computation: the paper gives the gradient of the embedding-space l2 distance dθ with respect to the input (Eq. 15), and the gradient of the contrastive loss with respect to the tuple components (Eq. 17); the triplet loss is similar. Any attack algorithm that relies only on loss gradients can be adapted; the paper gives the adapted form of PGD (iterative update with projection Π).
- Single-component perturbation: for computational reasons, the attack algorithm perturbs only one component of the tuple/triplet at a time.
Adversarial training procedure
- Training loop: each iteration samples a tuple T from the dataset, uses the attack algorithm to construct the perturbed T′ (Ac_r/At_r for Formulation 2, attack A for Formulation 3), and runs one SGD or ADAM step on T′.
- Computational cost control: the authors state that DML natural training is itself already resource-intensive, so they adopt the technique of Wong et al. (2020)—adversarial training with the cheaper R+FGSM attack plus early stopping—and set the step size α = ε·0.25 (the authors state this is an empirically determined effective value).
- Perturbing positive samples: during training, positive-class data points are perturbed; the authors' stated reason is to avoid affecting the relative distance to negative-class data points—too-small negative distances make DML training unstable (citing Wu et al., 2017).
- Success determination/evaluation: evaluated with the DML metrics R@1 (accuracy of inferring the nearest-anchor class) and mAP@R (a measure of the ability to rank similar entities); attacks use PGD (5 iterations), and Appendix B additionally evaluates with the C&W attack.
What experiments did the paper conduct?
R@1 and mAP@R of naturally trained and robustly trained models under PGD/C&W attacks are measured on four real datasets plus one synthetic dataset.
Experimental setup
- Models tested: all models are ResNet50 (initialized with ImageNet pretraining), with the last layer replaced by a 128-dimensional embedding normalized to the unit sphere; trained with contrastive (α=1.0) and triplet (α=0.2) losses respectively. Variants include natural training (Contrastive, Triplet) and robust training (Contrastive(l2), Triplet(l2), Contrastive(l∞), Triplet(l∞), with the suffix indicating the norm used in training).
- Baseline: VisualPhishNet (a VGG16 variant, 512-dimensional unnormalized embedding, trained on VisualPhish); due to its architecture and data constraints, it is comparable only on the VisualPhish dataset, and the other datasets are marked N/A.
- Datasets: CUB200-2011 (200 bird classes, 11 788 images), CARS196 (196 car classes, 16 185 images), SOP (eBay product images, 120 053 images, 22 634 products), VisualPhish (146 brands, 10 558 website screenshots, test set 717 images); for the first three, the first half of the classes are used for training and the second half for testing, constituting an out-of-distribution setting. There is also a synthetic dataset: two classes a, b, x∈[0,1]^k (k=224×224×3), sampled from N(0.25, σ²I) and N(0.75, σ²I) respectively, σ=0.075.
- Attacks: PGD (5 iterations, step size 2ε/i), with norms l∞(ε=0.01) and l2(ε=4); for each perturbed point, its nearest positive-class neighbor is taken to form the attack; Appendix B additionally has the C&W attack (l2(ε=4), with projection clipping, early stopping disabled).
- Training parameters: ADAM, learning rate 10⁻⁶, weight decay 4·10⁻⁴; mini-batch 112, SPC-2 sampling (two samples per class); negative samples use distance weighted sampling; trained for 150 epochs (100 for SOP).
- Metrics and repetitions: R@1 and mAP@R; results are averages over 5 random seeds (table notes of Table 1 and Table 2).
Main results
According to Table 1 (R@1, %):
Swipe horizontally to read the table
Model Setting CUB200-2011 CARS196 SOP VisualPhish Contrastive Benign 59.1 74.0 71.8 78.2 Contrastive l∞ PGD 3.9 1.4 0.7 35.7 Triplet l∞ PGD 4.0 0.7 0.2 20.8 VisualPhishNet l∞ PGD N/A N/A N/A 42.8 Contrastive(l∞) l∞ PGD 20.3 35.7 53.6 56.7 Triplet(l∞) l∞ PGD 16.9 36.2 39.3 54.7 Contrastive(l2) l2 PGD 26.4 37.2 51.6 56.6 Triplet(l2) l2 PGD 27.2 37.0 37.7 55.1 - Naturally trained models are poorly robust: the authors state that on the three commonly used real datasets, the R@1 and mAP@R of naturally trained models drop by several orders of magnitude under attack, e.g., on CUB200-2011 the triplet model drops from 59.3% benign to 4.0% under l∞(ε=0.01).
- VisualPhish is an exception: naturally trained models have higher baseline robustness on VisualPhish (35.7% for Contrastive under l∞); the authors suspect this is related to the underlying data distribution of this dataset.
- Robust training is effective and surpasses prior work: the authors state that robust training improves robustness across losses, norms, attacks, and datasets; the main text states that on SOP the robust R@1 under l∞(ε=0.01) rises from 0.7% to 56.3%, but the corresponding number in Table 1 is 53.6% (Contrastive(l∞)), an inconsistency between the two; on VisualPhish, Contrastive(l∞) reaches 56.7%, higher than VisualPhishNet's 42.8%. Performance on benign inputs is largely unaffected (e.g., on CUB200-2011, Contrastive(l∞) has benign R@1 of 58.2%, versus 59.1% for natural training).
Robustness to the C&W attack (Appendix B)
- What was measured: robustness of robustly trained models to the C&W attack under l2(ε=4); C&W used projection clipping and early stopping was disabled.
- Results: according to Table 2, under C&W the R@1 of Contrastive(l2) is 40.6% on CUB200-2011, 58.7% on CARS196, 63.2% on SOP, and 67.8% on VisualPhish, all higher than the same model's 26.4%, 37.2%, 51.6%, 56.6% under PGD; the same holds for Triplet(l2) (e.g., on VisualPhish, 68.7% under C&W versus 55.1% under PGD).
- The authors' interpretation: the authors state that robust models retain higher robustness to C&W than to the stronger PGD attack; but the modifications made and hyperparameters may make C&W non-optimal, and these results should be regarded as a lower bound on robustness to C&W, even though PGD is generally considered SOTA.
Effect on the embedding space (Q3, synthetic dataset)
- What was measured: on the synthetic dataset (about 15K data points, two classes), natural and robust models are trained with the contrastive loss, mapping the high-dimensional input to a two-dimensional embedding space; the attack is l∞(ε=0.01) PGD.
- Results: Figure 2 shows the embeddings of benign points (circles) and perturbed points (crosses) on the unit circle; the authors state that the embeddings of the robustly trained model shift less under adversarial perturbation, maintaining a smaller intra-class distance between perturbed and benign points.
- Theoretical connection: Appendix C gives an analysis—if the embedding distance dθ is L-Lipschitz and L ≤ δ/(2ε), then δ-separated points are ε-robust (Lemma 1); and under a Gaussian mixture model it proves that the upper bound on the misclassification probability decreases as the Lipschitz constant decreases (Eq. 21).
Other ablations and analyses
- Changes in benign performance: according to Table 1, benign R@1 after robust training both rises and falls, e.g., on SOP, Contrastive drops from 71.8% to 66.3% for Contrastive(l2), and on CUB200-2011, Triplet(l∞) drops to 53.4% (natural training 59.3%).
- Summary numbers in the abstract and introduction: the abstract states adversarial accuracy improves by 5–76 times; the introduction states that under l∞(ε=0.01) SOP reaches 53.6%, compared with the SOP natural accuracy baseline of 71.8% (referring to benign R@1).
- mAP@R trend: consistent with R@1, e.g., on SOP under l∞ PGD, Contrastive is 1.5% and Contrastive(l∞) is 30.4% (Table 1).
What are some points that can be further explored?
The authors explicitly state few caveats: the C&W results should be regarded as a lower bound; the experiments cover four datasets, two norms, and two attacks.
Limitations and future directions noted by the authors
- C&W results regarded as a lower bound: Appendix B states that the modifications made to the C&W attack (projection clipping, early stopping disabled) and the hyperparameters used may make the C&W attack non-optimal, so these results should be regarded as a lower-bound representation of robustness to C&W.
- Training cost: Section 4.1 states that DML natural training is already considered costly, and solving the inner maximization of the robust formulation makes training more expensive and possibly infeasible for practical applications, so the R+FGSM plus early stopping technique is adopted; the authors state it can also bring similar robustness improvements against stronger attacks (such as PGD).
- The paper has no dedicated Limitations or Future Work section and lists no other future directions.
Scope of experiments
- Models tested: all are ResNet50 (128-dimensional embedding), trained with contrastive and triplet losses respectively; the only external comparison model is VisualPhishNet, and it is reported only on the VisualPhish dataset (the other datasets are N/A in Table 1).
- Datasets: four image datasets CUB200-2011, CARS196, SOP, VisualPhish, plus a two-class Gaussian synthetic dataset; the first three are split in half by class for training/testing (out-of-distribution setting).
- Attacks and norms: evaluation covers PGD (l∞ ε=0.01, l2 ε=4, 5 iterations) and C&W (only l2 ε=4, Appendix B); adversarial training uses R+FGSM, and only positive-class data points are perturbed during training.
- Losses and formulations: experiments cover only the contrastive and triplet losses; the authors state they focus on Formulation 2 and 3, and Formulation 1 was not used in experiments because it is computationally infeasible.
- Number of repetitions: results in Table 1 and Table 2 are averages over 5 random seeds; the paper does not report statistical significance tests.
Summarize the main content of the paper
A robust optimization training framework for DML: accounting for the sample dependence of metric losses, R@1 under PGD rises from single digits to at most 56.7%.
A defense paper on the adversarial robustness of deep metric learning (DML), addressing the problem that metric losses depend on other samples in the mini-batch, making standard adversarial training difficult to apply directly.
- Problem: DML is used in tasks such as face verification and phishing detection, but research conclusions on its sensitivity to adversarial examples are contradictory; the authors state that training DML models with robust optimization techniques has not been sufficiently studied before.
- Method: rewrite the contrastive/triplet losses as a surrogate loss that depends on the entire dataset, and give three min-max robust optimization formulations; the experiments use the form with the max moved inside the sum, perturb only one component of a tuple/triplet at a time, use R+FGSM plus early stopping for adversarial training, and perturb only positive-class data points.
- Naturally trained models are fragile: on CUB200-2011, CARS196, SOP, naturally trained models drop from above 59.1% to below 4.0% R@1 under l∞(ε=0.01) PGD (Table 1); on VisualPhish the baseline is higher (35.7%), which the authors suspect is related to the data distribution.
- Robust training is effective: on SOP, R@1 under l∞(ε=0.01) PGD rises from 0.7% to 53.6% (Contrastive(l∞), Table 1); on VisualPhish it reaches 56.7%, surpassing VisualPhishNet's 42.8%; benign-input accuracy is largely maintained.
- Additional evidence: robustness to the C&W attack is also maintained under l2(ε=4) (e.g., 67.8% on VisualPhish, Table 2), which the authors state should be regarded as a lower bound; synthetic-dataset experiments show that robust training makes embeddings shift less under perturbation (Figure 2), and Appendix C gives a theoretical analysis of the connection between the Lipschitz constant and robustness.
- Authors' conclusion: naturally trained DML models are fragile to strong attackers, and the proposed robust training objective can produce DML models that withstand PGD attacks without greatly reducing benign performance.