- Notifications
You must be signed in to change notification settings - Fork34
[CVPR 2022 Oral] Balanced MSE for Imbalanced Visual Regressionhttps://arxiv.org/abs/2203.16427
License
jiawei-ren/BalancedMSE
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Code for the paper:
Balanced MSE for Imbalanced Visual Regression
Jiawei Ren, Mingyuan Zhang, Cunjun Yu, Ziwei Liu
CVPR 2022 (Oral)
- [07/28/2022] We have released the code of IHMR inMMHuman3d
- [04/27/2022] We have released the code for theSynthetic Benchmark, includingmulti-dimensional Balanced MSE and visualizations!
- [03/31/2022] Code release, with aninteractive demo and ahands-on tutorial.
Check out ourlive demo in the Hugging Face 🤗 space!
We provide a minimal working example of Balanced MSE using the BMC implementation on a small-scale dataset,Boston Housing dataset.
The notebook is developed on top ofDeep Imbalanced Regression (DIR) Tutorial,we thank the authors for their amazing tutorial!
A code snippet of the Balanced MSE loss is shown below. We use the BMC implementation for demonstration,BMC does not require any label prior beforehand.
defbmc_loss(pred,target,noise_var):"""Compute the Balanced MSE Loss (BMC) between `pred` and the ground truth `targets`. Args: pred: A float tensor of size [batch, 1]. target: A float tensor of size [batch, 1]. noise_var: A float number or tensor. Returns: loss: A float tensor. Balanced MSE Loss. """logits=- (pred-target.T).pow(2)/ (2*noise_var)# logit size: [batch, batch]loss=F.cross_entropy(logits,torch.arange(pred.shape[0]))# contrastive-like lossloss=loss* (2*noise_var).detach()# optional: restore the loss scale, 'detach' when noise is learnablereturnloss
noise_var
is a one-dimensional hyper-parameter.noise_var
can be optionally optimized in training:
classBMCLoss(_Loss):def__init__(self,init_noise_sigma):super(BMCLoss,self).__init__()self.noise_sigma=torch.nn.Parameter(torch.tensor(init_noise_sigma))defforward(self,pred,target):noise_var=self.noise_sigma**2returnbmc_loss(pred,target,noise_var)criterion=BMCLoss(init_noise_sigma)optimizer.add_param_group({'params':criterion.noise_sigma,'lr':sigma_lr,'name':'noise_sigma'})
The multi-dimensional implementation is compatible with the 1-D version.
fromtorch.distributionsimportMultivariateNormalasMVNdefbmc_loss_md(pred,target,noise_var):"""Compute the Multidimensional Balanced MSE Loss (BMC) between `pred` and the ground truth `targets`. Args: pred: A float tensor of size [batch, d]. target: A float tensor of size [batch, d]. noise_var: A float number or tensor. Returns: loss: A float tensor. Balanced MSE Loss. """I=torch.eye(pred.shape[-1])logits=MVN(pred.unsqueeze(1),noise_var*I).log_prob(target.unsqueeze(0))# logit size: [batch, batch]loss=F.cross_entropy(logits,torch.arange(pred.shape[0]))# contrastive-like lossloss=loss* (2*noise_var).detach()# optional: restore the loss scale, 'detach' when noise is learnablereturnloss
noise_var
is still a one-dimensional hyper-parameter and can be optionally learned in training.
Please go into the sub-folder to run experiments.
As for IHMR, we have released our code and pretrained models inMMHuman3d
@inproceedings{ren2021bmse,title={Balanced MSE for Imbalanced Visual Regression},author={Ren, Jiawei and Zhang, Mingyuan and Yu, Cunjun and Liu, Ziwei},booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},year={2022}}
This work is supported by NTU NAP, MOE AcRF Tier 2 (T2EP20221-0033), the National Research Foundation, Singapore under its AI Singapore Programme, and under the RIE2020 Industry Alignment Fund – Industry Collabo- ration Projects (IAF-ICP) Funding Initiative, as well as cash and in-kind contribution from the industry partner(s).
The code is developed on top ofDelving into Deep Imbalanced Regression.
About
[CVPR 2022 Oral] Balanced MSE for Imbalanced Visual Regressionhttps://arxiv.org/abs/2203.16427