Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码问题 #78

Open
wiluen opened this issue Jan 1, 2025 · 0 comments
Open

代码问题 #78

wiluen opened this issue Jan 1, 2025 · 0 comments

Comments

@wiluen
Copy link

wiluen commented Jan 1, 2025

for i in range(task_num):

        # 1. run the i-th task and compute loss for k=0
        logits = self.net(x_spt[i], vars=None, bn_training=True)
        loss = F.cross_entropy(logits, y_spt[i])
        grad = torch.autograd.grad(loss, self.net.parameters())
        fast_weights = list(map(lambda p: p[1] - self.update_lr * p[0], zip(grad, self.net.parameters())))

        # this is the loss and accuracy before first update
        with torch.no_grad():
            # [setsz, nway]
            logits_q = self.net(x_qry[i], self.net.parameters(), bn_training=True)
            loss_q = F.cross_entropy(logits_q, y_qry[i])
            losses_q[0] += loss_q

            pred_q = F.softmax(logits_q, dim=1).argmax(dim=1)
            correct = torch.eq(pred_q, y_qry[i]).sum().item()
            corrects[0] = corrects[0] + correct

在每个任务的第一轮, logits_q = self.net(x_qry[i], self.net.parameters(), bn_training=True)为什么用的网络参数是 self.net.parameters()而不是fast_weights呢?这两个数据的值并不一样。而后续的更新用的一直是fast_weights

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant