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

Points for sampler #7

Open
halbielee opened this issue Nov 22, 2019 · 5 comments
Open

Points for sampler #7

halbielee opened this issue Nov 22, 2019 · 5 comments

Comments

@halbielee
Copy link

halbielee commented Nov 22, 2019

Thanks for sharing your great job.

I have a question about the point for sampler in your code.

train_sampler is first declared at L167 in cifar_train.py then, train_loader gets the sampler in L169-171.

This seems to be fine in itself. But in the middle of training(train+validation) there is a part which seems to be for sampler in L186-L208. I understand this part is need for LDAM and DRW, but I think this new train_sampler object does not affect train_loader.

How's your opinion?
Thnks!

LDAM-DRW/cifar_train.py

Lines 186 to 208 in 3193f05

if args.train_rule == 'None':
train_sampler = None
per_cls_weights = None
elif args.train_rule == 'Resample':
train_sampler = ImbalancedDatasetSampler(train_dataset)
per_cls_weights = None
elif args.train_rule == 'Reweight':
train_sampler = None
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':
train_sampler = None
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:
warnings.warn('Sample rule is not listed')

@AlanChou
Copy link

I think you're right. I also found this issue when running the code. I think it only effects "Resample" and can be fixed by adding a line after the "ImbalancedDatasetSampler" is created to make sure the dataloader use the created sampler.

@halbielee
Copy link
Author

Thank you for the quick response!

@AlanChou
Copy link

You should probably wait for the author's response before closing the issue though I think you're right about the question. And it's also better to keep the issue opened before the code is updated.
I’m just a random guy which want to help :)

@halbielee halbielee reopened this Nov 25, 2019
@halbielee
Copy link
Author

@AlanChou
Oh, I see. I thought you were the author. :)

Thank you for the another reply!

@yibuxulong
Copy link

yibuxulong commented Jan 20, 2021

The same question for me. I found it rejected to change the sampler of train_loader after initialization(because the sampler affects shuffle, etc.), so I wonder if I should:

  1. resample and create train_loader each epoch
  2. just resample and create train_loader once before the epoch-loop

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

3 participants