This project explores the robustness of Vision Language Models (VLMs) in the medical domain when facing adversarial attacks. The workflow includes SSL finetuning of medical VLMs, denoised smoothing implementation, and comprehensive adversarial attack experiments.
The our pretrained medical VLMs (includings vanilla, w/ SSL and w/ AT) are available at the following link: Hugging-face
The project follows a two-stage workflow:
This stage includes training Vision Language Models with Self-Supervised Learning (SSL) and Adversarial Training (AT) variants. The notebooks provide integrated scripts that automatically import necessary libraries.
This notebook contains the primary script for finetuning three medical VLMs:
Supported Models:
Training Modes:
SSL - Self-Supervised Learning finetuningAT - Adversarial Training finetuningFeatures:
Usage:
# Open and run the notebook
jupyter notebook src/SSL_CTL.ipynb
The notebook guides you through:
This notebook contains the re-implemented script for Denoised Smoothing (DS) certification with VLMs.
Features:
Usage:
# Open and run the notebook
jupyter notebook src/DS_CTL.ipynb
The notebook includes:
Start with SSL_CTL.ipynb
Run DS_CTL.ipynb (optional)
Proceed to Stage 2 (Attack experiments)
Use the main script to perform adversarial attacks. Example command for NES attack on RSNA dataset with MedCLIP:
python main_attack.py \
--dataset_name rsna \
--model_name medclip \
--attacker_name NES \
--epsilon 0.03 \
--norm linf \
--max_evaluation 10000 \
--q 100 \
--batch_q 100 \
--alpha 0.01 \
--out_dir attack_results/nes_attack \
--start_idx 0 \
--index_path "evaluate_result/medclip_ssl_scratch.txt" \
--mode post_transform \
--mode_pretrained ssl
Datasets:
rsna - Pneumonia detection datasetcovid - COVID-19 detection from chest X-raysmimic - Chest X-ray abnormality detectionentrep - Medical dataset variantAttack Methods:
NES - Natural Evolutionary StrategiesES_1_Lambda - Evolutionary Strategy attackPGD - Projected Gradient DescentCEM - Class Expectation over MaxESGD - Evolutionary Stochastic Gradient DescentGridES_1_Lambda - Grid-based Evolutionary StrategyKey Parameters:
--epsilon / --eps: Perturbation budget (default: 8/255)--norm: Norm for perturbation (linf, l2)--max_evaluation: Maximum evaluations for the attack--q: Query parameter for NES--batch_q: Batch query size--alpha: Step size for updates--out_dir: Output directory for results--index_path: Path to indices of samples to attack--start_idx: Starting index for processing--end_idx: Ending index for processing--mode: Attack mode (e.g., post_transform)--mode_pretrained: Pretraining mode (ssl, at, etc.)Results are saved in the specified out_dir or evaluate_result/ directory. Results include:
See evaluate_result/ folder for example results from different models and datasets.
attack/
βββ main_attack.py # Main attack script
βββ eval.py # Evaluation script
βββ test_clean_performance.py # Test clean performance
βββ transfer_attack.py # Transfer attack script
βββ ds_test.py # Denoised smoothing test
βββ modules/
β βββ attack/ # Attack implementations
β β βββ attack.py
β β βββ evaluator.py
β β βββ util.py
β βββ dataset/ # Dataset loaders
β β βββ base.py
β β βββ covid.py
β β βββ entrep.py
β β βββ mimic.py
β β βββ rsna.py
β β βββ factory.py
β βββ models/ # Model definitions
β β βββ base.py
β β βββ biomedclip.py
β β βββ entrep.py
β β βββ medclip.py
β β βββ robustmedclip.py
β β βββ vit.py
β β βββ vision_model.py
β β βββ factory.py
β β βββ RobustMedCLIP/
β βββ utils/ # Utilities
β βββ constants.py
β βββ helpers.py
β βββ logging_config.py
βββ evaluate_result/ # Evaluation results
βββ README.md # Detailed attack instructions
requirements.txt in each folder for detailed dependencies11 commits
Python
80.9%
Jupyter Notebook
16.5%
Shell
2.6%
This project explores the robustness of Vision Language Models (VLMs) in the medical domain when facing adversarial attacks. The workflow includes SSL finetuning of medical VLMs, denoised smoothing implementation, and comprehensive adversarial attack experiments.
The our pretrained medical VLMs (includings vanilla, w/ SSL and w/ AT) are available at the following link: Hugging-face
The project follows a two-stage workflow:
This stage includes training Vision Language Models with Self-Supervised Learning (SSL) and Adversarial Training (AT) variants. The notebooks provide integrated scripts that automatically import necessary libraries.
This notebook contains the primary script for finetuning three medical VLMs:
Supported Models:
Training Modes:
SSL - Self-Supervised Learning finetuningAT - Adversarial Training finetuningFeatures:
Usage:
# Open and run the notebook
jupyter notebook src/SSL_CTL.ipynb
The notebook guides you through:
This notebook contains the re-implemented script for Denoised Smoothing (DS) certification with VLMs.
Features:
Usage:
# Open and run the notebook
jupyter notebook src/DS_CTL.ipynb
The notebook includes:
Start with SSL_CTL.ipynb
Run DS_CTL.ipynb (optional)
Proceed to Stage 2 (Attack experiments)
Use the main script to perform adversarial attacks. Example command for NES attack on RSNA dataset with MedCLIP:
python main_attack.py \
--dataset_name rsna \
--model_name medclip \
--attacker_name NES \
--epsilon 0.03 \
--norm linf \
--max_evaluation 10000 \
--q 100 \
--batch_q 100 \
--alpha 0.01 \
--out_dir attack_results/nes_attack \
--start_idx 0 \
--index_path "evaluate_result/medclip_ssl_scratch.txt" \
--mode post_transform \
--mode_pretrained ssl
Datasets:
rsna - Pneumonia detection datasetcovid - COVID-19 detection from chest X-raysmimic - Chest X-ray abnormality detectionentrep - Medical dataset variantAttack Methods:
NES - Natural Evolutionary StrategiesES_1_Lambda - Evolutionary Strategy attackPGD - Projected Gradient DescentCEM - Class Expectation over MaxESGD - Evolutionary Stochastic Gradient DescentGridES_1_Lambda - Grid-based Evolutionary StrategyKey Parameters:
--epsilon / --eps: Perturbation budget (default: 8/255)--norm: Norm for perturbation (linf, l2)--max_evaluation: Maximum evaluations for the attack--q: Query parameter for NES--batch_q: Batch query size--alpha: Step size for updates--out_dir: Output directory for results--index_path: Path to indices of samples to attack--start_idx: Starting index for processing--end_idx: Ending index for processing--mode: Attack mode (e.g., post_transform)--mode_pretrained: Pretraining mode (ssl, at, etc.)Results are saved in the specified out_dir or evaluate_result/ directory. Results include:
See evaluate_result/ folder for example results from different models and datasets.
attack/
βββ main_attack.py # Main attack script
βββ eval.py # Evaluation script
βββ test_clean_performance.py # Test clean performance
βββ transfer_attack.py # Transfer attack script
βββ ds_test.py # Denoised smoothing test
βββ modules/
β βββ attack/ # Attack implementations
β β βββ attack.py
β β βββ evaluator.py
β β βββ util.py
β βββ dataset/ # Dataset loaders
β β βββ base.py
β β βββ covid.py
β β βββ entrep.py
β β βββ mimic.py
β β βββ rsna.py
β β βββ factory.py
β βββ models/ # Model definitions
β β βββ base.py
β β βββ biomedclip.py
β β βββ entrep.py
β β βββ medclip.py
β β βββ robustmedclip.py
β β βββ vit.py
β β βββ vision_model.py
β β βββ factory.py
β β βββ RobustMedCLIP/
β βββ utils/ # Utilities
β βββ constants.py
β βββ helpers.py
β βββ logging_config.py
βββ evaluate_result/ # Evaluation results
βββ README.md # Detailed attack instructions
requirements.txt in each folder for detailed dependencies11 commits
Python
80.9%
Jupyter Notebook
16.5%
Shell
2.6%