Hi everyone,
I'm wondering if and how the gradient reversal layer from the paper "Domain-Adversarial Training of Neural Networks" (
http://arxiv.org/abs/1505.07818) can be implemented in Keras.
The "gradient reversal layer" as described there is a layer which passes input through unchanged, but during backpropagation multiplies all gradients by a constant (negative) factor.*
This sounds simple enough, but I'm still struggling to understand all the internals of Keras, and the way gradient calculation and backpropagation works is still a bit of a mystery to me. Any pointers or ideas would be highly appreciated.
(*For those wondering why one would do this, the idea -- in a nutshell -- is to have a network with two outputs, and train it so it learns to predict the first output well, while punishing features that help to predict the second one. This is intended for domain adaptation, where the second output predicts whether a given sample is from the source or the target domain, and the idea is to punish features that can discriminate between the two domains, thus leaving the model to focus on domain-independent features.)
Best regards,
- Marcel