当前位置: 首页>>代码示例>>Python>>正文


Python chainer.report方法代码示例

本文整理汇总了Python中chainer.report方法的典型用法代码示例。如果您正苦于以下问题:Python chainer.report方法的具体用法?Python chainer.report怎么用?Python chainer.report使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainer的用法示例。


在下文中一共展示了chainer.report方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_loss_gen

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def _get_loss_gen(self):
        batchsize = self.y_fake.data.shape[0]
        L_mce = F.softmax_cross_entropy(self.pred_label_map, self.ground_truth, normalize=False)
        L_bce = F.softmax_cross_entropy(self.y_fake, Variable(self.xp.ones(batchsize, dtype=self.xp.int32), volatile=not self.gen.train))
        loss = L_mce + self.L_bce_weight * L_bce

        # log report
        label_true = chainer.cuda.to_cpu(self.ground_truth.data)
        label_pred = chainer.cuda.to_cpu(self.pred_label_map.data).argmax(axis=1)
        logs = []
        for i in six.moves.range(batchsize):
            acc, acc_cls, iu, fwavacc = utils.label_accuracy_score(
                label_true[i], label_pred[i], self.n_class)
            logs.append((acc, acc_cls, iu, fwavacc))
        log = np.array(logs).mean(axis=0)
        values = {
            'loss': loss,
            'accuracy': log[0],
            'accuracy_cls': log[1],
            'iu': log[2],
            'fwavacc': log[3],
        }
        chainer.report(values, self.gen)

        return loss 
开发者ID:oyam,项目名称:Semantic-Segmentation-using-Adversarial-Networks,代码行数:27,代码来源:updater.py

示例2: calc_loss

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def calc_loss(self):
        batchsize = self.ground_truth.shape[0]
        self.loss = F.softmax_cross_entropy(self.pred_label_map, self.ground_truth, normalize=False)

        # log report
        label_true = chainer.cuda.to_cpu(self.ground_truth.data)
        label_pred = chainer.cuda.to_cpu(self.pred_label_map.data).argmax(axis=1)
        logs = []
        for i in six.moves.range(batchsize):
            acc, acc_cls, iu, fwavacc = utils.label_accuracy_score(
                label_true[i], label_pred[i], self.n_class)
            logs.append((acc, acc_cls, iu, fwavacc))
        log = np.array(logs).mean(axis=0)
        values = {
            'loss': self.loss,
            'accuracy': log[0],
            'accuracy_cls': log[1],
            'iu': log[2],
            'fwavacc': log[3],
        }
        chainer.report(values, self.model) 
开发者ID:oyam,项目名称:Semantic-Segmentation-using-Adversarial-Networks,代码行数:23,代码来源:updater.py

示例3: forward

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def forward(self, x, t):
        # def forward(self, x):
        h = F.max_pooling_2d(F.local_response_normalization(
            F.relu(self.conv1(x))), 3, stride=2)
        h = F.max_pooling_2d(F.local_response_normalization(
            F.relu(self.conv2(h))), 3, stride=2)
        h = F.relu(self.conv3(h))
        h = F.relu(self.conv4(h))
        h = F.max_pooling_2d(F.relu(self.conv5(h)), 3, stride=2)
        h = F.dropout(F.relu(self.fc6(h)))
        h = F.dropout(F.relu(self.fc7(h)))
        h = self.fc8(h)

        loss = F.softmax_cross_entropy(h, t)
        #loss = h

        # chainer.report({'loss': loss, 'accuracy': F.accuracy(h, t)}, self)
        return loss

# from https://github.com/chainer/chainer/blob/master/examples/imagenet/alex.py 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:22,代码来源:Alex_with_loss.py

示例4: forward

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def forward(self, x, t):
        h = self.bn1(self.conv1(x))
        h = F.max_pooling_2d(F.relu(h), 3, stride=2)
        h = self.res2(h)
        h = self.res3(h)
        h = self.res4(h)
        h = self.res5(h)
        h = F.average_pooling_2d(h, 7, stride=1)
        h = self.fc(h)

        #loss = F.softmax_cross_entropy(h, t)
        loss = self.softmax_cross_entropy(h, t)
        if self.compute_accuracy:
            chainer.report({'loss': loss, 'accuracy': F.accuracy(h, np.argmax(t, axis=1))}, self)
        else:
            chainer.report({'loss': loss}, self)
        return loss 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:19,代码来源:resnet50.py

示例5: forward

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def forward(self, x, t):
        h = F.max_pooling_2d(F.local_response_normalization(
            F.relu(self.conv1(x))), 3, stride=2)
        h = F.max_pooling_2d(F.local_response_normalization(
            F.relu(self.conv2(h))), 3, stride=2)
        h = F.relu(self.conv3(h))
        h = F.relu(self.conv4(h))
        h = F.max_pooling_2d(F.relu(self.conv5(h)), 3, stride=2)
        h = F.dropout(F.relu(self.fc6(h)))
        h = F.dropout(F.relu(self.fc7(h)))
        h = self.fc8(h)

        # EDIT(hamaji): ONNX-chainer cannot output SoftmaxCrossEntropy.
        # loss = F.softmax_cross_entropy(h, t)
        loss = self.softmax_cross_entropy(h, t)
        if self.compute_accuracy:
            chainer.report({'loss': loss, 'accuracy': F.accuracy(h, t)}, self)
        else:
            chainer.report({'loss': loss}, self)
        return loss 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:22,代码来源:alex.py

示例6: __call__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def __call__(self, trainer):
        device = self.device

        with chainer.no_backprop_mode():
            references = []
            hypotheses = []
            for i in range(0, len(self.test_data), self.batch):
                sources, targets = zip(*self.test_data[i:i + self.batch])
                references.extend([[t.tolist()] for t in targets])

                sources = [device.send(x) for x in sources]
                ys = [y.tolist()
                      for y in self.model.translate(sources, self.max_length)]
                hypotheses.extend(ys)

        bleu = bleu_score.corpus_bleu(
            references, hypotheses,
            smoothing_function=bleu_score.SmoothingFunction().method1)
        chainer.report({self.key: bleu}) 
开发者ID:chainer,项目名称:chainer,代码行数:21,代码来源:seq2seq.py

示例7: test_add_observers

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def test_add_observers(self):
        reporter = chainer.Reporter()
        observer1 = object()
        reporter.add_observer('o1', observer1)
        observer2 = object()
        reporter.add_observer('o2', observer2)

        reporter.report({'x': 1}, observer1)
        reporter.report({'y': 2}, observer2)

        observation = reporter.observation
        self.assertIn('o1/x', observation)
        self.assertEqual(observation['o1/x'], 1)
        self.assertIn('o2/y', observation)
        self.assertEqual(observation['o2/y'], 2)
        self.assertNotIn('x', observation)
        self.assertNotIn('y', observation)
        self.assertNotIn('o1/y', observation)
        self.assertNotIn('o2/x', observation) 
开发者ID:chainer,项目名称:chainer,代码行数:21,代码来源:test_reporter.py

示例8: scope

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def scope(self, observation):
        """Creates a scope to report observed values to ``observation``.

        This is a context manager to be passed to ``with`` statements. In this
        scope, the observation dictionary is changed to the given one.

        It also makes this reporter object current.

        Args:
            observation (dict): Observation dictionary. All observations
                reported inside of the ``with`` statement are written to this
                dictionary.

        """
        old = self.observation
        self.observation = observation
        self.__enter__()
        try:
            yield
        finally:
            self.__exit__(None, None, None)
            self.observation = old 
开发者ID:chainer,项目名称:chainer,代码行数:24,代码来源:reporter.py

示例9: forward

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def forward(self, trainer):
        with chainer.no_backprop_mode():
            references = []
            hypotheses = []
            for i in range(0, len(self.test_data), self.batch):
                sources, targets = zip(*self.test_data[i:i + self.batch])
                references.extend([[t.tolist()] for t in targets])

                sources = [
                    chainer.dataset.to_device(self.device, x) for x in sources]
                ys = [y.tolist()
                      for y in self.model.translate(sources, self.max_length)]
                hypotheses.extend(ys)

        bleu = bleu_score.corpus_bleu(
            references, hypotheses,
            smoothing_function=bleu_score.SmoothingFunction().method1)
        chainer.report({self.key: bleu}) 
开发者ID:pfnet,项目名称:pfio,代码行数:20,代码来源:seq2seq_chainerio.py

示例10: __call__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def __call__(self, x, t=None, w=None):
        # t, w is on host.

        # Forward network
        alpha = self.forward(x)

        if t is None:
            assert not chainer.config.train
            return

        # Weighted mean squared error
        # TODO: Do more tests
#         loss = F.mean(F.squared_error(alpha, t) * w)
        loss = F.mean_squared_error(alpha, t)

        if np.isnan(float(loss.data)):
            raise ValueError('Loss is nan.')
        chainer.report({'loss': loss}, self)

        return loss 
开发者ID:takiyu,项目名称:portrait_matting,代码行数:22,代码来源:fcn8s_matting.py

示例11: __call__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def __call__(self, x, t=None):
        score = self.forward(x)

        if t is None:
            assert not chainer.config.train
            return

        loss = F.softmax_cross_entropy(score, t, normalize=True)
        if np.isnan(float(loss.data)):
            raise ValueError('Loss is nan.')
        chainer.report({'loss': loss}, self)

        accuracy = F.accuracy(score, t)
        chainer.report({'accuracy': accuracy}, self)

        return loss 
开发者ID:takiyu,项目名称:portrait_matting,代码行数:18,代码来源:fcn8s.py

示例12: _loss_discriminator

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def _loss_discriminator(self, discriminator, d_real, d_fake):
        b, _, t = d_real.data.shape

        loss_real = F.sum(F.softplus(-d_real)) / (b * t)
        chainer.report({'real': loss_real}, discriminator)

        loss_fake = F.sum(F.softplus(d_fake)) / (b * t)
        chainer.report({'fake': loss_fake}, discriminator)

        loss = loss_real + loss_fake
        chainer.report({'loss': loss}, discriminator)

        tp = (d_real.data > 0.5).sum()
        fp = (d_fake.data > 0.5).sum()
        fn = (d_real.data <= 0.5).sum()
        tn = (d_fake.data <= 0.5).sum()
        accuracy = (tp + tn) / (tp + fp + fn + tn)
        precision = tp / (tp + fp)
        recall = tp / (tp + fn)
        chainer.report({'accuracy': accuracy}, self.discriminator)
        chainer.report({'precision': precision}, self.discriminator)
        chainer.report({'recall': recall}, self.discriminator)
        return loss 
开发者ID:Hiroshiba,项目名称:become-yukarin,代码行数:25,代码来源:updater.py

示例13: _loss_discriminator

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def _loss_discriminator(self, discriminator, d_real, d_fake):
        b, _, w, h = d_real.data.shape

        loss_real = F.sum(F.softplus(-d_real)) / (b * w * h)
        chainer.report({'real': loss_real}, discriminator)

        loss_fake = F.sum(F.softplus(d_fake)) / (b * w * h)
        chainer.report({'fake': loss_fake}, discriminator)

        loss = loss_real + loss_fake
        chainer.report({'loss': loss}, discriminator)

        tp = (d_real.data > 0.5).sum()
        fp = (d_fake.data > 0.5).sum()
        fn = (d_real.data <= 0.5).sum()
        tn = (d_fake.data <= 0.5).sum()
        accuracy = (tp + tn) / (tp + fp + fn + tn)
        precision = tp / (tp + fp)
        recall = tp / (tp + fn)
        chainer.report({'accuracy': accuracy}, self.discriminator)
        chainer.report({'precision': precision}, self.discriminator)
        chainer.report({'recall': recall}, self.discriminator)
        return loss 
开发者ID:Hiroshiba,项目名称:become-yukarin,代码行数:25,代码来源:sr_updater.py

示例14: fid_extension

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def fid_extension(fidapi,
                  generate_func,
                  seed=None,
                  report_key='FID',
                  verbose=True):
    @chainer.training.make_extension()
    def calc(trainer):
        if verbose:
            print('Running FID...')
        fidapi.calc_fake(generate_func, seed)
        fid = fidapi.calc_FID()
        chainer.report({report_key: fid})
        if verbose:
            print(report_key + ' Value: ', fid)
    return calc 
开发者ID:pfnet-research,项目名称:chainer-stylegan,代码行数:17,代码来源:fid.py

示例15: _get_loss_dis

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import report [as 别名]
def _get_loss_dis(self):
        batchsize = self.y_fake.data.shape[0]
        loss = F.softmax_cross_entropy(self.y_real, Variable(self.xp.ones(batchsize, dtype=self.xp.int32), volatile=not self.gen.train))
        loss += F.softmax_cross_entropy(self.y_fake, Variable(self.xp.zeros(batchsize, dtype=self.xp.int32), volatile=not self.gen.train))
        chainer.report({'loss': loss}, self.dis)
        return loss 
开发者ID:oyam,项目名称:Semantic-Segmentation-using-Adversarial-Networks,代码行数:8,代码来源:updater.py


注:本文中的chainer.report方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。