This repository provides the official implementation of the algorithm SPUME proposed in the paper "Spuriousness-Aware Meta-Learning for Learning Robust Classifiers (KDD'24)".
Download all the datasets and decompress them into individual folders.
For the NICO dataset, run the following to prepare metadata:
from data.nico_data import prepare_metadata
prepare_metadata(NICO_DATA_FOLDER, NICO_CXT_DIC_PATH, NICO_CLASS_DIC_PATH)For the ImageNet-9 and ImageNet-A datasets, run the following to prepare metadata:
from data.in9_data import prepare_imagenet9_metadata, prepare_imageneta_metadata
prepare_imagenet9_metadata("/path/to/imagenet")
prepare_imageneta_metadata("/path/to/imagenet-a")In the extract_concepts.py file, modify csv_path and img_path. Then, run the following script:
python extract_concepts.py --dataset waterbirds --model vit-gpt2In the config/waterbirds.yaml file (or other yaml files), specify the following parameters:
data_folder: /path/to/datasets
save_folder: /path/to/results/
vit_gpt2_attr_embed_path: "/path/data/vit-gpt2_img_embeddings.pickle"
vit_gpt2_vocab_path: "/path/data/vit-gpt2_vocab.pickle"
blip_attr_embed_path: "/path/data/blip_img_embeddings.pickle"
blip_vocab_path: "/path/data/blip_vocab.pickle"
vlm: "vit-gpt2"
Then run the following code:
python train_meta_spurious.py --config config/waterbirds.yamlThe final results are shown in the last line starting with "[PseudoUnbiasedModel]".
Please consider citing this paper if you find the code helpful.
@inproceedings{zheng2024spuriousness,
title={Spuriousness-Aware Meta-Learning for Learning Robust Classifiers},
author={Zheng, Guangtao and Ye, Wenqian and Zhang, Aidong},
booktitle={The 30th ACM SIGKDD Conference on Knowledge Discovery and Data Mining (KDD’24)},
year={2024}
}