wangzhuo2019 / SSAN

Domain Generalization via Shuffled Style Assembly for Face Anti-Spoofing, CVPR2022.
MIT License
93 stars 22 forks source link

The implement of GRL maybe not correct? #18

Open Shayne-AuthMe opened 1 year ago

Shayne-AuthMe commented 1 year ago

The implement of GRL maybe not correct?

https://github.com/wangzhuo2019/SSAN/blob/f4c2cbcd351a57766fc2ee7b83bde620c5cb00fc/networks/pub_mod.py#L7

The backword function is need to inherit torch.autograd.Function like this example in pytorch as follow:

https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function

A simple implement might be:

from torch.autograd import Function

class GRL(Function):

    @staticmethod
    def forward(ctx: Any, input: torch.Tensor):
        return input * 1.0

    @staticmethod
    def backward(ctx: Any, gradOutput: torch.Tensor):
        return gradOutput.neg()