| 160 | return self.args.temperature * F.linear(F.normalize(x, p=2, dim=-1), F.normalize(fc, p=2, dim=-1)) |
| 161 | |
| 162 | def update_fc_ft(self,new_fc,data,label,session): |
| 163 | new_fc=new_fc.clone().detach() |
| 164 | new_fc.requires_grad=True |
| 165 | optimized_parameters = [{'params': new_fc}] |
| 166 | optimizer = torch.optim.SGD(optimized_parameters,lr=self.args.lr_new, momentum=0.9, dampening=0.9, weight_decay=0) |
| 167 | |
| 168 | with torch.enable_grad(): |
| 169 | for epoch in range(self.args.epochs_new): |
| 170 | old_fc = self.fc.weight[:self.args.base_class + self.args.way * (session - 1), :].detach() |
| 171 | fc = torch.cat([old_fc, new_fc], dim=0) |
| 172 | logits = self.get_logits(data,fc) |
| 173 | loss = F.cross_entropy(logits, label) |
| 174 | optimizer.zero_grad() |
| 175 | loss.backward() |
| 176 | optimizer.step() |
| 177 | pass |
| 178 | |
| 179 | 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) |
| 180 | |