Extract CNN's output with gather, convert in Variable; lost gradient?

Hi guys,

Is more a clarification question more then technical.

I need extract two class from my features extractors (CNN).
For doing that i have used

dataLoad.data.gather(1, idsDim.view(-1,1)

Where: dataLoad are my CNN output prediction and ids a zero tensor of the
same length of output class.

Now, I need to backward those independent outputs with a two different targets and different loss function as well.
Then, I have converted the specific sequence output (from gather) in autograd Variable and i set the flag “requires_grad=True”.

==> The question is: This it’s correct or i have lost the gradient of CNN?

I am sorry for the question.

Best,

Nico

You have lost it when you used .data. If you use gather on the variable (no .data), yoy get to keep it.

Best regards

Thomas

1 Like