Keras implementation of a gradient inversion layer for the Tensorflow backend, following the paper Domain-Adversarial Training of Neural Networks. Modified the Theano version by Pumpikano found here, expanding on the work done by VanushVaswani found here.
The layer can be placed in a Functional model such as:
Flip = flipGradientTF.GradientReversal(hp_lambda)
dann_in = Flip(previous_layer_output)
dann_out = Dense(2)(dann_in)
where hp_lambda
is the constant which multiplies the flipped gradient.