Code for the paper "Margin Calibration for Long-Tailed Visual Recognition".
Margin Calibration for Long-Tailed Visual Recognition
Yidong Wang, Bowen Zhang, Wenxin Hou, Zhen Wu, Jindong Wang, Takahiro Shinozaki
ACML 2022
class MARCLinear(nn.Module):
"""
A wrapper for nn.Linear with support of MARC method.
"""
def __init__(self, in_features, out_features):
super().__init__()
self.fc = nn.Linear(in_features, out_features)
self.a = torch.nn.Parameter(torch.ones(1, out_features))
self.b = torch.nn.Parameter(torch.zeros(1, out_features))
def forward(self, input, *args):
with torch.no_grad():
logit_before = self.fc(input)
w_norm = torch.norm(self.fc.weight, dim=1)
logit_after = self.a * logit_before + self.b * w_norm
return logit_after
Please follow classifier-balancing.
Then, you need to download all the preprocessed data indexs for each dataset by: wget https://github.com/microsoft/robustlearn.git
. Then, unzip this file and move the unziped folders under ./data
folder.
- Base model (Representation Learning)
python main.py --cfg ./config/CIFAR10_LT/softmax_100.yaml
- MARC
python main.py --cfg ./config/CIFAR10_LT/MARC_100.yaml
The logs of training can be found at logs link. We download Stage 1 model weights of Places and iNaturalist18 from classifier-balancing for quick reproduction. The results could be slightly different from the results reported in the paper (most results of this repo are better than those in the paper), since we originally used an internal repository for the experiments in the paper.
@article{wang2022margin,
title={Margin calibration for long-tailed visual recognition},
author={Wang, Yidong and Zhang, Bowen and Hou, Wenxin and Wu, Zhen and Wang, Jindong and Shinozaki, Takahiro},
booktitle={Asian Conference on Machine Learning (ACML)},
year={2022}
}
Yidong Wang ([email protected])
Qiang Heng ([email protected]) Thanks for helping reproduction!
Jindong Wang ([email protected])
- The code is based on balanced meta softmax.