Awesome
CLAE
Code for contrastive learning with adversarial examples
Usage
Preprocess
- Clone the project to directory
git clone https://github.com/chihhuiho/CLAE.git
- Initiate the conda environment
cd CLAE
conda env create -f environment.yml -n CLAE
conda activate CLAE
- Download the tinyImagenet dataset.
cd datasets
sh download_tinyImagenet.sh
Run Plain contrastive learning methods
- Enter to Plain folder
cd Plain
- Run contrastive learning baseline (use cifar100 [cifar10, tinyImagenet] for example)
python main.py --dataset cifar100 --batch-size 128 --gpu 0 --trial 1
python eval.py --dataset cifar100 --batch-size 128 --gpu 0 --trial 1
- Run contrastive learning with adversarial training (use cifar100 [cifar10, tinyImagenet] for example)
python main.py --dataset cifar100 --batch-size 128 --gpu 0 --trial 1 --adv --bn_adv_momentum 0.01 --eps 0.03
python eval.py --dataset cifar100 --batch-size 128 --gpu 0 --trial 1 --adv --bn_adv_momentum 0.01 --eps 0.03
Run UEL contrastive learning methods
- Enter to UEL folder
cd UEL
- Run contrastive learning baseline (use cifar100 [cifar10, tinyImagenet] for example)
python main.py --dataset cifar100 --batch-size 128 --gpu 0 --trial 1
python eval.py --dataset cifar100 --batch-size 128 --gpu 0 --trial 1
- Run contrastive learning with adversarial training (use cifar100 [cifar10, tinyImagenet] for example)
python main.py --dataset cifar100 --batch-size 128 --gpu 0 --trial 1 --adv --bn_adv_momentum 0.01 --eps 0.03
python eval.py --dataset cifar100 --batch-size 128 --gpu 0 --trial 1 --adv --bn_adv_momentum 0.01 --eps 0.03
Run SimCLR contrastive learning methods
- Enter to SimCLR folder
cd SimCLR
- Run contrastive learning baseline (use cifar100 [cifar10, tinyImagenet] for example)
python main.py --trial 1 --gpu 0 --dataset CIFAR100
python eval_lr.py --trial 1 --gpu 0 --dataset CIFAR100
python eval_knn.py --trial 1 --gpu 0 --dataset CIFAR100
- Run contrastive learning with adversarial training (use cifar100 [cifar10, tinyImagenet] for example)
python main.py --alpha 1.0 --trial 1 --gpu 0 --adv --eps 0.03 --bn_adv_momentum 0.01 --dataset CIFAR100
python eval_lr.py --alpha 1.0 --trial 1 --adv --gpu 0 --eps 0.03 --bn_adv_momentum 0.01 --dataset CIFAR100
python eval_knn.py --alpha 1.0 --trial 1 --adv --gpu 0 --eps 0.03 --bn_adv_momentum 0.01 --dataset CIFAR100