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

if I set alpha the program crash #4

Open
stephane-archer opened this issue Oct 31, 2018 · 2 comments
Open

if I set alpha the program crash #4

stephane-archer opened this issue Oct 31, 2018 · 2 comments

Comments

@stephane-archer
Copy link

~/FullyConnected/focalloss.py in forward(self, input, target)
     32 
     33         loss = -1 * (1-pt)**self.gamma * logpt
---> 34         if self.size_average: return loss.mean()
     35         else: return loss.sum()

RuntimeError: cuda runtime error (59) : device-side assert triggered at /opt/conda/conda-bld/pytorch_1524586445097/work/aten/src/THC/generated/../THCReduceAll.cuh:339
@rxqy
Copy link

rxqy commented Nov 8, 2018

Met exactly the same problem.
I found that the problem is coming from

at = self.alpha.gather(0,target.data.view(-1))

Any ideas? @stephane-archer

@rxqy
Copy link

rxqy commented Nov 10, 2018

Hi, for anyone who met the same problem, I might have a solution.
You can add one line before the following line
select = (target!=0).type(torch.LongTensor).cuda()

at = self.alpha.gather(0,target.data.view(-1))

and set this line to
at = self.alpha.gather(0,select.data.view(-1))

i.e alpha controls the balance between positive samples and negative samples.
so in the test code, you can set gamma=0, alpha=0.5, and multiple the loss by 2.
This should give a similar result. ( It's also the case in the original implementation of detectron)

The problem is that, when you are doing index select, alpha only has two dimensions
however, if you use target to select the index, you might have more than two labels in your target.
BTW, I'm using pytorch 0.3.1, don't know if it's a bug @clcarwin @stephane-archer

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