Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where can I setting the CE(Uniform) and CE(Balanced) ? #10

Closed
hooseok opened this issue Dec 15, 2020 · 1 comment
Closed

Where can I setting the CE(Uniform) and CE(Balanced) ? #10

hooseok opened this issue Dec 15, 2020 · 1 comment

Comments

@hooseok
Copy link

hooseok commented Dec 15, 2020

I see the Self-supervised pretrained learning (SSP).
There are many models in SSP.

  1. CE(Uniform) + SSP
  2. CE(Balanced) + SSP

Where can I setting the CB in train.py code?
In my opinion, per_cls_weights seems to set a uniform or balance.
Does the CB setting mean 'Reweight' in args.train_rule?

    if args.train_rule == 'Reweight':
        beta = 0.9999
        effective_num = 1.0 - np.power(beta, cls_num_list)
        per_cls_weights = (1.0 - beta) / np.array(effective_num)
        per_cls_weights = per_cls_weights / np.sum(per_cls_weights) * len(cls_num_list)
        per_cls_weights = torch.FloatTensor(per_cls_weights).cuda(args.gpu)
    elif args.train_rule == 'DRW':
        idx = epoch // 160
        betas = [0, 0.9999]
        effective_num = 1.0 - np.power(betas[idx], cls_num_list)
        per_cls_weights = (1.0 - betas[idx]) / np.array(effective_num)
        per_cls_weights = per_cls_weights / np.sum(per_cls_weights) * len(cls_num_list)
        per_cls_weights = torch.FloatTensor(per_cls_weights).cuda(args.gpu)
    else:
        per_cls_weights = None

    if args.loss_type == 'CE':
        criterion = nn.CrossEntropyLoss(weight=per_cls_weights).cuda(args.gpu)
    elif args.loss_type == 'LDAM':
        criterion = LDAMLoss(cls_num_list=cls_num_list, max_m=0.5, s=30, weight=per_cls_weights).cuda(args.gpu)
    elif args.loss_type == 'Focal':
        criterion = FocalLoss(weight=per_cls_weights, gamma=1).cuda(args.gpu)
    else:
        warnings.warn('Loss type is not listed')
        return
@YyzHarry
Copy link
Owner

Hi, thanks for your interest. "CE(Balanced)" means CE with class-balanced sampling, which corresponds to "Resample" as for args.train_rule. You can also choose "Reweight", which means re-weighting the loss for each class according to # of samples, by changing args.train_rule.

parser.add_argument('--train_rule', default='None', type=str,
choices=['None', 'Resample', 'Reweight', 'DRW'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants