Ask questions
XUYUNYUN666 opened this issue · comments
mlp.py is designed for training MAML and PMAML, so it is only called in train/maml.py and is not used in train/regular.py.
…On Tue, Jun 23, 2020 at 1:53 AM Eirun_Xu ***@***.***> wrote:
Hi, Yujia,
the codes in mlp.py as below:
def forward(self, XS, YS=None, XQ=None, YQ=None, weights=None):
'''
if y is specified, return loss and accuracy
otherwise, return the transformed x
@param <https://github.com/param>: XS: batch_size * input_dim
@param <https://github.com/param>: YS: batch_size (optional)
@return <https://github.com/return>: XS: batch_size * output_dim
'''
# normal training procedure, train stage only use query
if weights is None:
XS = self.mlp(XS)
else:
# find weight and bias keys for the mlp module
w_keys, b_keys = [], []
for key in weights.keys():
if key[:4] == 'mlp.':
if key[-6:] == 'weight':
w_keys.append(key)
else:
b_keys.append(key)
for i in range(len(w_keys)-1):
XS = F.dropout(XS, self.args.dropout, training=self.training)
XS = F.linear(XS, weights[w_keys[i]], weights[b_keys[i]])
XS = F.relu(XS)
XS = F.dropout(XS, self.args.dropout, training=self.training)
XS = F.linear(XS, weights[w_keys[-1]], weights[b_keys[-1]])
if self.top_layer is not None:
XS = self.top_layer(XS)
# normal training procedure, compute loss/acc
if YS is not None:
_, YS = torch.unique(YS, sorted=True, return_inverse=True)
loss = F.cross_entropy(XS, YS)
acc = BASE.compute_acc(XS, YS)
return acc, loss
else:
return XS
Why the codes do not use the argument XQ, YQ(query set).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#12>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABYZCHDPJXAUJJ2FJ7C7OLLRYA7MPANCNFSM4OFKCJVQ>
.
--
Best,
Yujia