From 6119849270c2aed117627d7d2b060f37d1c25de4 Mon Sep 17 00:00:00 2001 From: Hiroshiba Kazuyuki Date: Tue, 7 Nov 2017 10:20:04 +0900 Subject: can train --- become_yukarin/loss.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 become_yukarin/loss.py (limited to 'become_yukarin/loss.py') 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 -- cgit v1.2.3-70-g09d2