This repository is the official Pytorch implementation of Self-Supervised Aggregation of Diverse Experts for Test-Agnostic Long-Tailed Recognition (NeurIPS 2022).
- SADE (our method) innovates the expert training scheme by introducing diversity-promoting expertise-guided losses, which train different experts to handle distinct class distributions. In this way, the learned experts would be more diverse than existing multi-expert methods, leading to better ensemble performance, and aggregatedly simulate a wide spectrum of possible class distributions.
- SADE develops a new self-supervised method, namely prediction stability maximization, to adaptively aggregate these experts for better handling unknown test distribution, using unlabeled test class data.
Long-tailed recognition with uniform test class distribution:
Methods | MACs(G) | Top-1 acc. | Model |
---|---|---|---|
Softmax | 4.26 | 48.0 | |
RIDE | 6.08 | 56.3 | |
SADE (ours) | 6.08 | 58.8 | Download |
Test-agnostic long-tailed recognition:
Methods | MACs(G) | Forward-50 | Forward-10 | Uniform | Backward-10 | Backward-50 |
---|---|---|---|---|---|---|
Softmax | 4.26 | 66.1 | 60.3 | 48.0 | 34.9 | 27.6 |
RIDE | 6.08 | 67.6 | 64.0 | 56.3 | 48.7 | 44.0 |
SADE (ours) | 6.08 | 69.4 | 65.4 | 58.8 | 54.5 | 53.1 |
Long-tailed recognition with uniform test class distribution:
Methods | MACs(G) | Top-1 acc. |
---|---|---|
Softmax | 0.07 | 41.4 |
RIDE | 0.11 | 48.0 |
SADE (ours) | 0.11 | 49.8 |
Test-agnostic long-tailed recognition:
Methods | MACs(G) | Forward-50 | Forward-10 | Uniform | Backward-10 | Backward-50 |
---|---|---|---|---|---|---|
Softmax | 0.07 | 62.3 | 56.2 | 41.4 | 25.8 | 17.5 |
RIDE | 0.11 | 63.0 | 57.0 | 48.0 | 35.4 | 29.3 |
SADE (ours) | 0.11 | 65.9 | 58.3 | 49.8 | 43.9 | 42.4 |
Long-tailed recognition with uniform test class distribution:
Methods | MACs(G) | Top-1 acc. |
---|---|---|
Softmax | 11.56 | 31.4 |
RIDE | 13.18 | 40.3 |
SADE (ours) | 13.18 | 40.9 |
Test-agnostic long-tailed recognition:
Methods | MACs(G) | Forward-50 | Forward-10 | Uniform | Backward-10 | Backward-50 |
---|---|---|---|---|---|---|
Softmax | 11.56 | 45.6 | 40.2 | 31.4 | 23.4 | 19.4 |
RIDE | 13.18 | 43.1 | 41.6 | 40.3 | 38.2 | 36.9 |
SADE (ours) | 13.18 | 46.4 | 43.3 | 40.9 | 41.4 | 41.6 |
Long-tailed recognition with uniform test class distribution:
Methods | MACs(G) | Top-1 acc. |
---|---|---|
Softmax | 4.14 | 64.7 |
RIDE | 5.80 | 71.8 |
SADE (ours) | 5.80 | 72.9 |
Test-agnostic long-tailed recognition:
Methods | MACs(G) | Forward-3 | Forward-2 | Uniform | Backward-2 | Backward-3 |
---|---|---|---|---|---|---|
Softmax | 4.14 | 65.4 | 65.5 | 64.7 | 64.0 | 63.4 |
RIDE | 5.80 | 71.5 | 71.9 | 71.8 | 71.9 | 71.8 |
SADE (ours) | 5.80 | 72.3 | 72.5 | 72.9 | 73.5 | 73.3 |
- To install requirements:
pip install -r requirements.txt
- Hardware requirements 8 GPUs with >= 11G GPU RAM are recommended. Otherwise the model with more experts may not fit in, especially on datasets with more classes (the FC layers will be large). We do not support CPU training, but CPU inference could be supported by slight modification.
- Please download these datasets and put them to the /data file.
- ImageNet-LT and Places-LT can be found at here.
- iNaturalist data should be the 2018 version from here.
- CIFAR-100 will be downloaded automatically with the dataloader.
data
├── ImageNet_LT
│ ├── test
│ ├── train
│ └── val
├── CIFAR100
│ └── cifar-100-python
├── Place365
│ ├── data_256
│ ├── test_256
│ └── val_256
└── iNaturalist
├── test2018
└── train_val2018
- We provide txt files for test-agnostic long-tailed recognition for ImageNet-LT, Places-LT and iNaturalist 2018. CIFAR-100 will be generated automatically with the code.
- For iNaturalist 2018, please unzip the iNaturalist_train.zip.
data_txt
├── ImageNet_LT
│ ├── ImageNet_LT_backward2.txt
│ ├── ImageNet_LT_backward5.txt
│ ├── ImageNet_LT_backward10.txt
│ ├── ImageNet_LT_backward25.txt
│ ├── ImageNet_LT_backward50.txt
│ ├── ImageNet_LT_forward2.txt
│ ├── ImageNet_LT_forward5.txt
│ ├── ImageNet_LT_forward10.txt
│ ├── ImageNet_LT_forward25.txt
│ ├── ImageNet_LT_forward50.txt
│ ├── ImageNet_LT_test.txt
│ ├── ImageNet_LT_train.txt
│ ├── ImageNet_LT_uniform.txt
│ └── ImageNet_LT_val.txt
├── Places_LT_v2
│ ├── Places_LT_backward2.txt
│ ├── Places_LT_backward5.txt
│ ├── Places_LT_backward10.txt
│ ├── Places_LT_backward25.txt
│ ├── Places_LT_backward50.txt
│ ├── Places_LT_forward2.txt
│ ├── Places_LT_forward5.txt
│ ├── Places_LT_forward10.txt
│ ├── Places_LT_forward25.txt
│ ├── Places_LT_forward50.txt
│ ├── Places_LT_test.txt
│ ├── Places_LT_train.txt
│ ├── Places_LT_uniform.txt
│ └── Places_LT_val.txt
└── iNaturalist18
├── iNaturalist18_backward2.txt
├── iNaturalist18_backward3.txt
├── iNaturalist18_forward2.txt
├── iNaturalist18_forward3.txt
├── iNaturalist18_train.txt
├── iNaturalist18_uniform.txt
└── iNaturalist18_val.txt
- For the training on Places-LT, we follow previous methods and use the pre-trained ResNet-152 model.
- Please download the checkpoint. Unzip and move the checkpoint files to /model/pretrained_model_places/.
- To train the expertise-diverse model, run this command:
python train.py -c configs/config_imagenet_lt_resnext50_sade.json
- To evaluate expertise-diverse model on the uniform test class distribution, run:
python test.py -r checkpoint_path
- To evaluate expertise-diverse model on agnostic test class distributions, run:
python test_all_imagenet.py -r checkpoint_path
- To test-time train the expertise-diverse model for agnostic test class distributions, run:
python test_train_imagenet.py -c configs/test_time_imagenet_lt_resnext50_sade.json -r checkpoint_path
- To train the expertise-diverse model, run this command:
python train.py -c configs/config_cifar100_ir100_sade.json
- One can change the imbalance ratio from 100 to 10/50 by changing the config file.
- To evaluate expertise-diverse model on the uniform test class distribution, run:
python test.py -r checkpoint_path
{'accuracy': 0.4976, 'many_class_num': 35, 'medium_class_num': 35, 'few_class_num': 30, 'many_shot_acc': 0.61485714, 'medium_shot_acc': 0.5091429, 'few_shot_acc': 0.34733337}
- To evaluate expertise-diverse model on agnostic test class distributions, run:
python test_all_cifar.py -r checkpoint_path
========================= Final results ========================= forward50 60.53 48.8 38.67 58.57 forward25 60.5 47.93 32.85 56.77 forward10 60.58 48.09 32.9 54.88 forward5 60.1 47.35 30.75 52.25 forward2 60.75 47.98 31.25 49.86 uniform 61.51 50.91 34.73 49.77 backward2 60.42 47.62 30.85 44.54 backward5 61.83 48.91 31.1 42.09 backward10 63.04 48.48 31.16 39.65 backward25 57.14 47.64 31.18 36.64 backward50 61.63 48.56 31.61 35.24
- To test-time train the expertise-diverse model for agnostic test class distributions, run:
python test_train_cifar.py -c configs/test_time_cifar100_ir100_sade.json -r checkpoint_path
- One can change the imbalance ratio from 100 to 10/50 by changing the config file. ========================= Final results =========================
Top-1 accuracy on many-shot, medium-shot, few-shot and all classes: forward50 68.99 48.26 18.5 65.53 forward25 68.84 47.85 19.06 62.82 forward10 67.88 49.1 21.85 59.18 forward5 68.87 48.15 19.95 55.96 forward2 64.5 50.1 30.33 52.04 uniform 56.51 49.54 38.0 48.52 backward2 51.1 47.5 40.25 45.69 backward5 43.5 44.83 42.94 43.67 backward10 46.55 46.46 42.61 44.09 backward25 42.53 44.01 42.56 42.52 backward50 42.4 43.82 43.62 43.28
Aggregation weights of three experts: forward50 0.55 0.36 0.1 forward25 0.56 0.33 0.1 forward10 0.5 0.37 0.13 forward5 0.5 0.38 0.12 forward2 0.39 0.34 0.27 uniform 0.28 0.32 0.4 backward2 0.22 0.31 0.47 backward5 0.16 0.27 0.57 backward10 0.16 0.3 0.54 backward25 0.16 0.27 0.57 backward50 0.13 0.25 0.62
- To train the expertise-diverse model, run this command:
python train.py -c configs/config_places_lt_resnet152_sade.json
- To evaluate expertise-diverse model on the uniform test class distribution, run:
python test_places.py -r checkpoint_path
- To evaluate expertise-diverse model on agnostic test class distributions, run:
python test_all_places.py -r checkpoint_path
- To test-time train the expertise-diverse model for agnostic test class distributions, run:
python test_train_places.py -c configs/test_time_places_lt_resnet152_sade.json -r checkpoint_path
- To train the expertise-diverse model, run this command:
python train.py -c configs/config_iNaturalist_resnet50_sade.json
- To evaluate expertise-diverse model on the uniform test class distribution, run:
python test.py -r checkpoint_path
- To evaluate expertise-diverse model on agnostic test class distributions, run:
python test_all_inat.py -r checkpoint_path
- To test-time train the expertise-diverse model for agnostic test class distributions, run:
python test_train_inat.py -c configs/test_time_iNaturalist_resnet50_sade.json -r checkpoint_path
If you find our work inspiring or use our codebase in your research, please cite our work.
@inproceedings{zhang2022Self,
title={Self-Supervised Aggregation of Diverse Experts for Test-Agnostic Long-Tailed Recognition},
author={Zhang, Yifan and Hooi, Bryan and Hong, Lanqing and Feng, Jiashi},
booktitle={Advances in Neural Information Processing Systems},
year={2022}
}
This is a project based on this pytorch template.
The mutli-expert framework are based on RIDE. The data generation of agnostic test class distributions takes references from LADE.