Awesome
MEDIC++
1. Introduction
This repository contains the implementation of the unreleased paper Exploring Dualistic Meta-Learning to Enhance Domain Generalization in Open Set Scenarios, entended from our ICCV 2023 paper Generalizable Decision Boundaries: Dualistic Meta-Learning for Open Set Domain Generalization.
2. Dataset Construction (Optional)
You can divide the dataset into two folders for training and validation. We provide reference code for automatically dividing data using official split in data_list/split_kfold.py
.
root_dir = "path/to/PACS"
instr_dir = "path/to/PACS_data_list"
3. Train
To run the training code, please update the path of the dataset in main.py
:
if dataset == 'PACS':
train_dir = 'path/to/PACS_train' # the folder of training data
val_dir = 'path/to/PACS_val' # the folder of validation data
test_dir = 'path/to/PACS_all' or ['path/to/PACS_train', 'path/to/PACS_val']
then simply run:
python main.py --source-domain ... --target-domain ... --save-name ... --gpu 0
If there is no validation folder, please use the option --random-split to create the validation set.
You can use --save-later to save the model in the last 15% iterations.
4. DomainBed
To simulate the DomainBed benchmark, please set transforms in dataset/dataloader.py
as follows:
if small_img == False:
img_tr = [transforms.RandomResizedCrop((224, 224), (0.7, 1.0))] # 0.7 for DomainBed, otherwise 0.8
if color_jitter:
img_tr.append(transforms.ColorJitter(brightness=0.3, contrast=0.3, saturation=0.3, hue=0.3)) # 0.3 for DomainBed, otherwise 0.4
then add options:
- --batch-size 12 (18 for DomainNet, the total batch size is this value times the number of tasks 9)
- --optimize-method Adam
- --num-epoch 5100 (15000 for DomainNet)
- --eval-step 300
- --lr 6e-6 (divide the default learning rate 5e-5 by the number of tasks 9)
- --without-bcls
python main.py --source-domain ... --target-domain ... --save-name ... --gpu 0 --batch-size 12 --optimize-method Adam --num-epoch 5100 --eval-step 300 --lr 6e-6 --without-bcls
5. Evalution
To run the evaluation code, please update the path of the dataset in eval.py
:
if dataset == 'PACS':
root_dir = 'path/to/PACS_all' or ['path/to/PACS_train', 'path/to/PACS_val']
then simply run:
python eval.py --hits ... --save-name ... --gpu 0
- --hits (check points for H-score)