def forward(self, source, target, s_label): source = self.feature_layers(source) if bottle_neck: source = self.bottle(source) s_pred = self.cls_fc(source) if self.training ==True: target = self.feature_layers(target) if bottle_neck: target = self.bottle(target) t_label = self.cls_fc(target) #原始的lmmd loss = mmd.lmmd(source, target, s_label, torch.nn.functional.softmax(t_label, dim=1),num_classes = self.num_classes) #混合核lmmd #loss = mklmmd.mix_poly_rbf(source, target, s_label, torch.nn.functional.softmax(t_label, dim=1)) else: loss = 0 return s_pred, loss
def forward(self, source, target, s_label): source = self.feature_layers(source) if bottle_neck: source = self.bottle(source) s_pred = self.cls_fc(source) if self.training == True: target = self.feature_layers(target) if bottle_neck: target = self.bottle(target) t_label = self.cls_fc(target) loss_c = mmd.lmmd(source, target, s_label, torch.nn.functional.softmax(t_label, dim=1)) loss_m = self.mmd_marginal(source, target) mu = proxy_a_distance.estimate_mu( source.detach().cpu().numpy(), s_label.detach().cpu().numpy(), target.detach().cpu().numpy(), torch.max(t_label, 1)[1].detach().cpu().numpy()) else: loss_c, loss_m, mu = 0 return s_pred, loss_c, loss_m, mu