fungtion / DANN

pytorch implementation of Domain-Adversarial Training of Neural Networks
MIT License
841 stars 151 forks source link

Question about ReverseLayerF #3

Closed songweige closed 5 years ago

songweige commented 5 years ago

Greetings! Could you give me some quick explanation about why ReverseLayerF() could lead the gradients of parameters in domain classifier to negative? I'm confused since that I though it would instead influence the parameters before domain classifier (in the feature layer). Could you please correct me a little bit? Thanks in advance!

fungtion commented 5 years ago

ReverseLayerF() actually doesn't affect the parameters in domain classifier, since when forward propagation, it equals to 1 https://github.com/fungtion/DANN/blob/master/models/functions.py#L10 and when backward propagation, it only make the gradients from domain classifier to feature layer negative, i.e. only affect the parameters before domain classifier as you thought .

songweige commented 5 years ago

Thx, it makes sense!

songweige commented 5 years ago

BTW, why did you use "x.view_as(x)" as return? Is it a convention or a double check?

fungtion commented 5 years ago

It is necessary, if you return x which is also the input of forward(), backward() will not be recalled.

songweige commented 5 years ago

I see. Thx!

houchenyu commented 5 years ago

Greeting! I have a question about ReverseLayerF.apply() in the model definition. There is no explicit definition of the apply() function. What would happen while executing ReverseLayerF.apply()

samuel01028 commented 1 year ago

Greeting! I have a question about ReverseLayerF.apply() in the model definition. There is no explicit definition of the apply() function. What would happen while executing ReverseLayerF.apply()

Hi,do u understand how does the ReverseLayerF.apply() work?