特征可视化:https://github.com/jindongwang/transferlearning/blob/aa6ee9fcbc7e2fa75ce6fb5f2f60d8193e1c6894/code/utils/feature_vis.py
一、GRL
绿色是特征提取,蓝色是分类损失,红色是域损失,因为目标是无法区分特征来自哪个域,所以域损失要最大化,叫梯度反转。

import torch
class GradReverse(torch.autograd.Function):
@staticmethod
def forward(ctx, x, eta=1.0):
ctx.eta = eta