Exploring Adversarial Watermarking in Transformer-Based Models: Transferability and Robustness Against Defense Mechanism for Medical Images

Rifat Sadik, Tanvir Rahman, Arpan Bhattacharjee, Bibhrajit Halder, Ismail Hossain, Banik, Mridul, Uddin, Jia · DOI

Abstract

Deep learning models have shown remarkable success in dermatological image analysis, offering potential for automated skin disease diagnosis. Previously, convolutional neural network (CNN) based architectures have achieved immense popularity and success in computer vision (CV) tasks like skin image recognition, generation, and video analysis. However, with the emergence of transformer-based models, CV tasks are increasingly carried out using these architectures. Vision Transformers (ViTs) use self-attention mechanisms to achieve state-of-the-art performance across various tasks. Nevertheless, their reliance on global attention mechanisms makes them susceptible to adversarial perturbations. This paper investigates the susceptibility of ViTs for medical images to adversarial watermarking—a method that adds imperceptible perturbations to fool models. By generating adversarial watermarks through Projected Gradient Descent (PGD), we examine the transferability of such attacks to CNNs and analyze the performance of a defense mechanism: adversarial training. Results indicate that while performance is not compromised for clean images, ViTs become significantly more vulnerable to adversarial attacks, with accuracy dropping as low as 27.6%. Adversarial training restores this performance to 90.0%.

Introduction

Deep learning has become a cornerstone of dermatological image analysis, assisting clinicians in identifying conditions ranging from eczema to malignant melanoma. Recently, the field has shifted from traditional Convolutional Neural Networks (CNNs) to Vision Transformers (ViTs). Unlike CNNs, which process images by analyzing local pixel neighborhoods, ViTs utilize "global self-attention" to weigh relationships between distant parts of an image simultaneously.

This study utilizes a specialized skin disease dataset containing five classes: Atopic dermatitis, Eczema, Herpes, Nevus, and Melanoma. Images were preprocessed to 224×224 pixels with standard augmentations to ensure the models learned generalizable features. The central question is whether the global perspective of ViTs makes them "brittle" when faced with adversarial watermarks—imperceptible pixel changes designed to trigger misdiagnosis.

Methodology

The researchers conducted a head-to-head robustness trial between three architectures: ViT, ResNet-50, and VGG16.

Architecture of a Vision Transformer (ViT) for skin image classification.
  1. Attack Generation: Projected Gradient Descent (PGD) was used to create adversarial watermarks. PGD is an iterative algorithm that identifies tiny pixel adjustments (within a constraint $\epsilon$) that maximize the model's prediction loss.
  2. Transferability Testing: The study examined how effectively an attack designed for one model could fool another architecture.
  3. Defense Mechanism: Adversarial Training was employed to counter these attacks. This involves augmenting the training dataset with adversarial examples, teaching the model to recognize and ignore the noise introduced by the PGD attack.

Adversarial Vulnerability and Insights

The most striking finding is that ViTs are far more sensitive to distributed noise than CNNs. Because ViTs rely on the interrelationships between image patches, a "watermark" that subtly disrupts these relationships across the entire image can derail the model's logic.

Illustration of an adversarial attack where a subtle perturbation causes a misclassification from Eczema to Herpes.

In contrast, CNNs like ResNet-50 and VGG16 proved more naturally resilient. By focusing on local hierarchical features (edges, textures, shapes), they are less likely to be confused by perturbations spread across the whole image. However, ViTs showed a remarkable ability to adapt during adversarial training. Their training loss converged faster than CNNs, suggesting that once a ViT is exposed to the nature of the attack, its self-attention mechanism efficiently learns to filter it out.

Results

The quantitative gap between performance on "clean" versus "attacked" images was dramatic:

  • Baseline (Clean Images): ViT (94.4%) and ResNet-50 (94.2%) performed similarly, both outperforming VGG16 (84.0%).
  • Under PGD Attack: ViT accuracy plummeted to 27.6%. ResNet-50 maintained 70.0% accuracy, while VGG16 dropped to 54.4%.
  • Post-Adversarial Training: After training on adversarial examples, ViT accuracy on attacked images recovered to 90.0% (a 62.4% improvement). ResNet-50 and VGG16 also improved, reaching 81.6% and 82.6%, respectively.

Conclusion and Future Work

While ViTs offer high performance, their vulnerability to adversarial attacks in medical contexts is a significant concern. Adversarial training appears to be a highly effective "vaccine," restoring robust performance. Future research should expand this investigation to include testing against other vectors like FGSM or Carlini & Wagner (C&W) attacks, validating findings on larger multi-center datasets, and investigating whether model scale (e.g., ViT-Large) impacts inherent robustness.

Summary updated

BibTeX
@misc{sadik2025exploring,
  author = {Rifat Sadik and Tanvir Rahman and Arpan Bhattacharjee and Bibhrajit Halder and Ismail Hossain and Banik, Mridul and Uddin, Jia},
  title = {{Exploring Adversarial Watermarking in Transformer-Based Models: Transferability and Robustness Against Defense Mechanism for Medical Images}},
  year = {2025},
  eprint = {2506.06389},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.06389},
}
Figure