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

Is this implementation correct? #4

Closed
Hhhhhhao opened this issue Oct 8, 2019 · 4 comments
Closed

Is this implementation correct? #4

Hhhhhhao opened this issue Oct 8, 2019 · 4 comments

Comments

@Hhhhhhao
Copy link

Hhhhhhao commented Oct 8, 2019

Hi, I wonder if this implementation is correct?

When I run the code with softmax, I get weights like this:

tensor([[0.8824, 0.8824, 0.8824, 0.8824, 0.8824],
        [0.8824, 0.8824, 0.8824, 0.8824, 0.8824],
        [0.8824, 0.8824, 0.8824, 0.8824, 0.8824],
        [0.8824, 0.8824, 0.8824, 0.8824, 0.8824],
        [1.7646, 1.7646, 1.7646, 1.7646, 1.7646],
        [1.7646, 1.7646, 1.7646, 1.7646, 1.7646],
        [0.8824, 0.8824, 0.8824, 0.8824, 0.8824],
        [0.8824, 0.8824, 0.8824, 0.8824, 0.8824],
        [0.8824, 0.8824, 0.8824, 0.8824, 0.8824],
        [0.8824, 0.8824, 0.8824, 0.8824, 0.8824]])

where each sample enjoin the same weights.

This is weird, right? According to the original paper, we should have different weight for each class (column), right?

@Hhhhhhao Hhhhhhao closed this as completed Oct 8, 2019
@zdaiot
Copy link

zdaiot commented Dec 16, 2019

@HHHHHHHHHHao I have the same question. Can you help me?

@wmf1991yeah
Copy link

@HHHHHHHHHHao I have the same question too. Why?

@Hhhhhhao
Copy link
Author

sorry I didn't figure out yet...

@Saadmaghani
Copy link

I know this is an old issue but I just want to give my understanding to any one who has the same question (as I did too)

Yes, the columns should have different values. But since Cross Entropy and Focal Loss take the one-hot labels of the target and multiply it by this weight matrix, essentially the final result is that you are only taking the weight for a particular class. That particular class' weight is actually the one you see above, repeated along the entire column.

Hope I helped!

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

4 participants