cd GPaCo/Seg/semseg
bash sh/ablation_paco_ade20k/upernet_swinbase_160k_ade20k_paco.sh
bash sh/ablation_paco_coco10k/r50_deeplabv3plus_40k_coco10k_paco.sh
bash sh/ablation_paco_context/r50_deeplabv3plus_40k_context_paco.sh
bash sh/ablation_paco_cityscapes/r50_deeplabv3plus_40k_context.sh
Parametric-Contrastive-Learning
This repository contains the implementation code for ICCV2021 paper: Parametric Contrastive Learning (https://arxiv.org/abs/2107.12028)
Overview
In this paper, we propose Parametric Contrastive Learning (PaCo) to tackle long-tailed recognition. Based on theoretical analysis, we observe supervised contrastive loss tends to bias on high-frequency classes and thus increases the difficulty of imbalance learning. We introduce a set of parametric class-wise learnable centers to rebalance from an optimization perspective. Further, we analyze our PaCo loss under a balanced setting. Our analysis demonstrates that PaCo can adaptively enhance the intensity of pushing samples of the same class close as more samples are pulled together with their corresponding centers and benefit hard example learning. Experiments on long-tailed CIFAR, ImageNet, Places, and iNaturalist 2018 manifest the new state-of-the-art for long-tailed recognition. On full ImageNet, models trained with PaCo loss surpass supervised contrastive learning across various ResNet backbones.
For full ImageNet, ImageNet-LT, iNaturalist 2018, Places-LT training and evaluation. Note that PyTorch>=1.6. All experiments are conducted on 4 GPUs. If you have more GPU resources, please make sure that the learning rate should be linearly scaled and 32 images per gpu is recommented.
cd Full-ImageNet
bash sh/train_resnet50.sh
bash sh/eval_resnet50.sh
cd LT
bash sh/ImageNetLT_train_R50.sh
bash sh/ImageNetLT_eval_R50.sh
bash sh/PlacesLT_train_R152.sh
bash sh/PlacesLT_eval_R152.sh
cd LT
bash sh/CIFAR100_train_imb0.1.sh
Contact
If you have any questions, feel free to contact us through email ([email protected]) or Github issues. Enjoy!
BibTex
If you find this code or idea useful, please consider citing our work:
@ARTICLE{10130611,
author={Cui, Jiequan and Zhong, Zhisheng and Tian, Zhuotao and Liu, Shu and Yu, Bei and Jia, Jiaya},
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
title={Generalized Parametric Contrastive Learning},
year={2023},
volume={},
number={},
pages={1-12},
doi={10.1109/TPAMI.2023.3278694}}
@inproceedings{cui2021parametric,
title={Parametric contrastive learning},
author={Cui, Jiequan and Zhong, Zhisheng and Liu, Shu and Yu, Bei and Jia, Jiaya},
booktitle={Proceedings of the IEEE/CVF international conference on computer vision},
pages={715--724},
year={2021}
}
@ARTICLE{9774921,
author={Cui, Jiequan and Liu, Shu and Tian, Zhuotao and Zhong, Zhisheng and Jia, Jiaya},
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
title={ResLT: Residual Learning for Long-Tailed Recognition},
year={2023},
volume={45},
number={3},
pages={3695-3706},
doi={10.1109/TPAMI.2022.3174892}
}
@article{cui2022region,
title={Region Rebalance for Long-Tailed Semantic Segmentation},
author={Cui, Jiequan and Yuan, Yuhui and Zhong, Zhisheng and Tian, Zhuotao and Hu, Han and Lin, Stephen and Jia, Jiaya},
journal={arXiv preprint arXiv:2204.01969},
year={2022}
}
@article{zhong2023understanding,
title={Understanding Imbalanced Semantic Segmentation Through Neural Collapse},
author={Zhong, Zhisheng and Cui, Jiequan and Yang, Yibo and Wu, Xiaoyang and Qi, Xiaojuan and Zhang, Xiangyu and Jia, Jiaya},
journal={arXiv preprint arXiv:2301.01100},
year={2023}
}
Hi, thanks for the great work, I have a question about the selection of the framework. Since you use the supervised contrastive loss, why not use the framework from supcon and use MoCo framework instead?
In your paper, you mentioned that when calculating Paco-loss for sample xi, the learnable centers cj,j=1...m, are alsoincluded as positive/negative samples, besides, the centers seen as positive samples share a different weight compared to other positive samples which are data samples not centers.
However, I checked the codes of GPaco and Paco, finding no use of centers in PacoLoss.
When reproducing your work, I find taking centers into consideration even badly hurts the model performance.
Could you tell the reason? I am quite bothered by this issue.
Hi, I notice that compared with the FCL (which is similar to SupCon) in "EXPLORING BALANCED FEATURE SPACES FOR REPRESENTATION LEARNING", the result of SupCon given in your paper is much lower. What is the reason?
parser.add_argument('--beta', default=1.0, type=float,
help='supervise loss weight')
parser.add_argument('--gamma', default=1.0, type=float,
help='paco loss')
I found these two parameters in the code, and they are used in losses.py, but I can't understand the using of them, are they mentioned in the paper?
If you can explain them to me, I will very appreciate on you, thank you!
Thanks for your work. I found that there is a requirement for pretrained_models/resnet152-394f9c45.pth when I run the PlacesLT_train_R152.sh. Could you share the link to download the pretrained model?
Thank you guys for your impressive work and releasing the code. I just wonder when will the checkpoint on iNat2018 be released? I'm looking forward to that. Thanks a lot!
We used the code below to load gpaco_r50_imagenetlt.pth.tar onto model and evaluated it on ImagenetLT. We ensured to use the correct moco builder files and appropriate parameters given in this repo. However, the model gives near 0 accuracy on ImagenetLT.
We were able to load the parameters successfully from the checkpoint to the model. We are unable to pinpoint the reason for the reduced accuracy, and seek your help for the same.
if 'paco' in args.path:
model = moco.builder.MoCo(
models.__dict__[args.model],
args.moco_dim, args.moco_k, args.moco_m, args.moco_t, args.mlp, args.feat_dim, num_classes=1000)
else:
model = models.__dict__[args.model](num_classes=args.nb_classes, use_norm=args.use_norm)
if args.path.startswith('https'):
checkpoint = torch.hub.load_state_dict_from_url(
args.path, map_location='cpu', check_hash=True)
else:
print("[INFORMATION] Loading teacher model from path ", args.path)
checkpoint = torch.load(args.path, map_location='cuda:0')
if 'paco' in args.path:
model.to(device)
model = torch.nn.parallel.DistributedDataParallel(model, device_ids = [0], find_unused_parameters = True)
model.load_state_dict(checkpoint['state_dict'])
else:
model.load_state_dict(checkpoint['model'] if 'model' in checkpoint.keys() else checkpoint['state_dict'])
model.to(device)
model.eval()
The "bias" term is not mentionned in your paper but it seems to appear when you compare centers with representations. Moreover there is no normalisation in the previous case.
If my previous comment is correct, can you explain this choice. Thanks in advance
Hello, I'm impressed with your work and thank you for sharing the codes.
I have a question abut inference function in LT/moco/builder.py !
In the code below, you are not using q but using self.feat_after_avg_q as input for linear.
Then, it doesn't seem to need the first two lines in the code.
Or, should self.feat_after_avg_q be changed to q?
Can you check this?
Thank you in advance! :)
dalao, I find that in PaCo or GPaCo the logits on the numerator in the loss function not masked, but the denominator of the loss function is masked cause exp_logits = torch.exp(logits) * logits_mask i think the the logits on the numerator also should masked? and the learnable center is used for predict ground truth to make it become a supervised question? thanks😢
Hi, thanks for your exciting work.
I have a question about the centre learning that I did not find any function in the paper, and I did not find any comment of centres on the code.
Could you give any clue about how could we the parametric centres?
Thanks for your ICCV work. However, I find you directly use the test set of ImageNet-LT to store the best models, which may lead to overfitting in practice and seems to be unfair to other compared methods. Could you please provide the results on ImageNet-LT using the validation set to store models? It would be easier for us to compare with PaCo in our work. Thanks very much.
Hi thanks for the great work. I notice that you have used different renet backbones for cifar training (load from resnet_cifar) and imagenet training (load from resnet_imagenet). Is there a reason why you use different backbones?
Thanks for your great work. I am trying to use NormedLinear_Classifier since I may modify it later. But, it is not good now. Could you please tell me the hyperparameters when your training, such as lr, supt in loss?
May I ask where can I download data corresponding to as listed in ImageNet_LT_train.txt, ImageNet_LT_val.txt, ImageNet_LT_test.txt.
I have downloaded several from the original ImageNet site but none of them corresponds to the items listed in the .txt completely.
Thanks for the answer in advance.
Thank you very much for your work. I am currently trying to reproduce this work, and found that when the Batch Size is 128, the speed is relatively slow, and I want to increase the Batch Size to speed up training. But it is found that Batch Size is limited by the parameter MoCo-k, can I modify MoCo-k arbitrarily, will this affect the result?
Looking forward to your reply.
I have a question on hyperparameters in CIFAR-LT dataset experiments
The paper explains alpha and moco temperature, but there is no explanation for the rest of the hyper-parameters(beta, gamma, augmentation stradegy). Can you please provide it?
Thanks for your exciting work!
Tau-norm with randaugment performs so well as shown in Table 3 and Table 5. I wonder about its implementation, just use augmentation_randncls as train_transform in training stage-1?
Hi, Thank you so much for your work. I am facing this issue while using this repo. I don't know where to upload this file because this folder is not there.