| 91 | return self.args.temperature * F.linear(F.normalize(x, p=2, dim=-1), F.normalize(fc, p=2, dim=-1)) |
| 92 | |
| 93 | def update_fc_ft(self,new_fc,data,label,session): |
| 94 | new_fc=new_fc.clone().detach() |
| 95 | new_fc.requires_grad=True |
| 96 | optimized_parameters = [{'params': new_fc}] |
| 97 | optimizer = torch.optim.SGD(optimized_parameters,lr=self.args.lr_new, momentum=0.9, dampening=0.9, weight_decay=0) |
| 98 | |
| 99 | with torch.enable_grad(): |
| 100 | for epoch in range(self.args.epochs_new): |
| 101 | old_fc = self.fc.weight[:self.args.base_class + self.args.way * (session - 1), :].detach() |
| 102 | fc = torch.cat([old_fc, new_fc], dim=0) |
| 103 | logits = self.get_logits(data,fc) |
| 104 | loss = F.cross_entropy(logits, label) |
| 105 | optimizer.zero_grad() |
| 106 | loss.backward() |
| 107 | optimizer.step() |
| 108 | pass |
| 109 | |
| 110 | self.fc.weight.data[self.args.base_class + self.args.way * (session - 1):self.args.base_class + self.args.way * session, :].copy_(new_fc.data) |
| 111 | |