def __call__(self, x, t):
"""Perform a forward pass and compute the loss. This method ultimately
defines the model.
Args:
x (chainer.Variable): Input vector.
t (chainer.Variable): Target vector. Usually identical to `x` in
the case of an Autoencoder.
Returns:
chainer.Variable: Loss.
"""
# Test different activation functions and dropout.
h = self.l1(x)
y = self.l2(h)
if self.train:
# Scale the MSE by 5, i.e 0.5 * 10 so that the loss can be compared to
# the loss computed in Assignment 4. Factor 0.5, since the Chainer
# implementation doesn't scale the error by 0.5 and factor 10, since
# the previous assignment loss functions does not compute the mean,
# and the number of summed elements are 10.
self.loss = 5 * F.mean_squared_error(y, t)
return self.loss
else:
return y
评论列表
文章目录