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

hello,there is some wrong with the compute_adjustment #2

Closed
limengyang1992 opened this issue Aug 27, 2021 · 4 comments
Closed

hello,there is some wrong with the compute_adjustment #2

limengyang1992 opened this issue Aug 27, 2021 · 4 comments

Comments

@limengyang1992
Copy link

image

There is no problem with 10 classification, when 100 classification, the order is wrong
I modified it:

label_freq = dict(sorted(label_freq.items()))
label_freq = sorted(label_freq.items(), key=lambda e: e[1], reverse=True)
label_freq_array = np.array([x[1] for x in label_freq])
label_freq_array = label_freq_array / label_freq_array.sum()
@Chumsy0725
Copy link
Owner

Chumsy0725 commented Sep 7, 2021

Hey! @limengyang1992
It can be rectified by casting the keys as integers.

    for j in target:
       key = int(j.item())
       label_freq[key] = label_freq.get(key, 0) + 1

It is convenient to have adjustments sorted according to the class number than the class frequency.
Thanks!

@sadeepj
Copy link
Collaborator

sadeepj commented Sep 8, 2021

Hi @Chumsy0725,

I didn't have a deeper look - but it looks like there's still a problem here. As seen from the screenshot, the tensor returned by the above compute_adjustment() method has the order ['0', '1', '10', '11', ...] instead of ['0', '1', '2', '3', ...]. Wouldn't this cause a problem for CIFAR-100 when this output tensor is used to correct the logits, which are always ordered ['0', '1', '2', '3', ...] ?

@sadeepj sadeepj reopened this Sep 8, 2021
@Chumsy0725
Copy link
Owner

Hi Dr. @sadeepj ,

The issue of keys being out of order is corrected by casting the key as integers. The resulting label_freq dictionary is attached bellow.
image

also the resulting probability values (attached bellow) in label_freq_array after normalizing are the same as the values listed in google-research/logit_adjustment and the values are in the same order.
image

@sadeepj
Copy link
Collaborator

sadeepj commented Sep 8, 2021

Thanks @Chumsy0725! I didn't realize that the issue is already fixed by 2e5bd39.

@limengyang1992, does this solve the issue you were facing?

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