diff options
| author | Hiroshiba Kazuyuki <hihokaruta@gmail.com> | 2017-11-07 10:20:04 +0900 |
|---|---|---|
| committer | Hiroshiba Kazuyuki <hihokaruta@gmail.com> | 2017-11-07 10:29:28 +0900 |
| commit | 6119849270c2aed117627d7d2b060f37d1c25de4 (patch) | |
| tree | 178e8df7a0c3d33f9de776b85ee4ff545f2ecdc3 /become_yukarin/loss.py | |
| parent | 8e637c41a262373786b94d40a8f3559caf5cd44c (diff) | |
can train
Diffstat (limited to 'become_yukarin/loss.py')
| -rw-r--r-- | become_yukarin/loss.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/become_yukarin/loss.py b/become_yukarin/loss.py new file mode 100644 index 0000000..c088691 --- /dev/null +++ b/become_yukarin/loss.py @@ -0,0 +1,24 @@ +from .config import LossConfig +from .model import Model + +import chainer + +from chainer import reporter + + +class Loss(chainer.link.Chain): + def __init__(self, config: LossConfig, predictor: Model): + super().__init__() + self.config = config + + with self.init_scope(): + self.predictor = predictor + + def __call__(self, input, target): + h = input + y = self.predictor(h) + + loss = chainer.functions.mean_absolute_error(y, target) + reporter.report({'loss': loss}, self) + + return loss * self.config.l1 |
