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


Python functions.accuracy方法代码示例

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


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

示例1: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [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

示例2: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [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 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:20,代码来源:Alex.py

示例3: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [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

示例4: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [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

示例5: accuracy

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def accuracy(x, t, ignore_label):
    x_ = numpy.rollaxis(x, 1, x.ndim).reshape(t.size, -1)
    t_ = t.ravel()

    if ignore_label is not None:
        count = 0
        for i in six.moves.range(t_.size):
            pred = x_[i].argmax()
            if t_[i] != ignore_label and pred == t_[i]:
                count += 1
        total = (t_ != ignore_label).sum()
    else:
        count = 0
        for i in six.moves.range(t_.size):
            pred = x_[i].argmax()
            if pred == t_[i]:
                count += 1
        total = t_.size

    if total == 0:
        return 0.0
    else:
        return float(count) / total 
开发者ID:chainer,项目名称:chainer,代码行数:25,代码来源:test_accuracy.py

示例6: update_net

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def update_net(self):
        batch = next(self.get_iterator('main'))
        batch = self.converter(batch, self.device)

        optimizer = self.get_optimizer('main')
        net = optimizer.target

        # for training we need one label less, since we right shift the output of the network
        predictions = net(batch['data'], batch['label'][:, :-1])

        batch_size, num_steps, vocab_size = predictions.shape
        predictions = F.reshape(predictions, (-1, vocab_size))
        labels = batch['label'][:, 1:].ravel()

        loss = F.softmax_cross_entropy(predictions, labels)
        accuracy = F.accuracy(F.softmax(predictions), labels)

        net.cleargrads()
        loss.backward()
        optimizer.update()

        chainer.reporter.report({
            "loss": loss,
            "train/accuracy": accuracy
        }) 
开发者ID:chainer,项目名称:models,代码行数:27,代码来源:copy_transformer_updater.py

示例7: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def __call__(self, x, t):
        self.clear()
        h = F.max_pooling_2d(F.relu(
            F.local_response_normalization(self.conv1(x))), 3, stride=2)
        h = F.max_pooling_2d(F.relu(
            F.local_response_normalization(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)), train=self.train)
        h = F.dropout(F.relu(self.fc7(h)), train=self.train)
        h = self.fc8(h)

        self.loss = F.softmax_cross_entropy(h, t)
        self.accuracy = F.accuracy(h, t)
        return self.loss 
开发者ID:masataka46,项目名称:MultimodalDL,代码行数:18,代码来源:mdl_rgb_d.py

示例8: update_recognizer

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def update_recognizer(self):
        recognizer_optimizer = self.get_optimizer('opt_rec')

        batch = next(self.get_iterator('main'))
        batch = self.converter(batch, self.device)

        recognizer_output = self.recognizer(
            batch['image'],
            batch['words'].squeeze()
        )
        loss = self.recognizer.calc_loss(recognizer_output, batch['words'])

        batch_size, num_chars, num_classes = recognizer_output.shape
        recognizer_output = F.reshape(recognizer_output, (-1, num_classes))
        char_accuracy = F.accuracy(F.softmax(recognizer_output, axis=1), batch['words'].ravel())

        self.recognizer.cleargrads()
        loss.backward()
        recognizer_optimizer.update()

        recognizer_losses = {
            'loss': loss,
            'char_accuracy': char_accuracy,
        }
        return recognizer_losses 
开发者ID:Bartzi,项目名称:kiss,代码行数:27,代码来源:transformer_text_updater.py

示例9: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [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

示例10: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def __call__(self, x, t):
        h, t1, t2 = self.calc(x)
        cls_loss = functions.softmax_cross_entropy(h, t)
        reporter.report({'cls_loss': cls_loss}, self)

        loss = cls_loss
        # Enforce the transformation as orthogonal matrix
        if self.trans and self.trans_lam1 >= 0:
            trans_loss1 = self.trans_lam1 * calc_trans_loss(t1)
            reporter.report({'trans_loss1': trans_loss1}, self)
            loss = loss + trans_loss1
        if self.trans and self.trans_lam2 >= 0:
            trans_loss2 = self.trans_lam2 * calc_trans_loss(t2)
            reporter.report({'trans_loss2': trans_loss2}, self)
            loss = loss + trans_loss2
        reporter.report({'loss': loss}, self)

        if self.compute_accuracy:
            acc = functions.accuracy(h, t)
            reporter.report({'accuracy': acc}, self)
        return loss 
开发者ID:corochann,项目名称:chainer-pointnet,代码行数:23,代码来源:pointnet_cls.py

示例11: test_report_key

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def test_report_key(self, metrics_fun, compute_metrics):
        repo = chainer.Reporter()

        link = Classifier(predictor=DummyPredictor(),
                          metrics_fun=metrics_fun)
        link.compute_metrics = compute_metrics
        repo.add_observer('target', link)
        with repo:
            observation = {}
            with reporter.report_scope(observation):
                link(self.x, self.t)

        # print('observation ', observation)
        actual_keys = set(observation.keys())
        if compute_metrics:
            if metrics_fun is None:
                assert set(['target/loss']) == actual_keys
            elif isinstance(metrics_fun, dict):
                assert set(['target/loss', 'target/user_key']) == actual_keys
            elif callable(metrics_fun):
                assert set(['target/loss', 'target/accuracy']) == actual_keys
            else:
                raise TypeError()
        else:
            assert set(['target/loss']) == actual_keys 
开发者ID:chainer,项目名称:chainer-chemistry,代码行数:27,代码来源:test_classifier.py

示例12: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def __call__(self, x, t, train=True, finetune=False):

        h = x

        # First conv layer
        h = self[0](h)

        # Residual blocks
        for i in range(1, len(self) - 2):
            h = self[i](h, train, finetune)

        # BN, relu, pool, final layer
        h = self[-2](h)
        h = F.relu(h)
        h = F.average_pooling_2d(h, ksize=h.data.shape[2:])
        h = self[-1](h)
        h = F.reshape(h, h.data.shape[:2])

        return F.softmax_cross_entropy(h, t), F.accuracy(h, t) 
开发者ID:tscohen,项目名称:gconv_experiments,代码行数:21,代码来源:ResNet.py

示例13: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def __call__(self, x, t, train=True, finetune=False):

        h = x
        h = F.dropout(h, ratio=0.2, train=train)
        h = self.l1(h, train, finetune)
        h = self.l2(h, train, finetune)
        h = self.l3(h, train, finetune)
        h = F.dropout(h, ratio=0.5, train=train)
        h = self.l4(h, train, finetune)
        h = self.l5(h, train, finetune)
        h = self.l6(h, train, finetune)
        h = F.dropout(h, ratio=0.5, train=train)
        h = self.l7(h, train, finetune)
        h = self.l8(h, train, finetune)
        h = self.l9(h, train, finetune)

        h = F.sum(h, axis=-1)
        h = F.sum(h, axis=-1)
        h = F.sum(h, axis=-1)
        h /= 8 * 8 * 8

        return F.softmax_cross_entropy(h, t), F.accuracy(h, t) 
开发者ID:tscohen,项目名称:gconv_experiments,代码行数:24,代码来源:P4MAllCNNC.py

示例14: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def __call__(self, x, t, train=True, finetune=False):

        h = x
        h = F.dropout(h, ratio=0.2, train=train)
        h = self.l1(h, train, finetune)
        h = self.l2(h, train, finetune)
        h = self.l3(h, train, finetune)
        h = F.dropout(h, ratio=0.5, train=train)
        h = self.l4(h, train, finetune)
        h = self.l5(h, train, finetune)
        h = self.l6(h, train, finetune)
        h = F.dropout(h, ratio=0.5, train=train)
        h = self.l7(h, train, finetune)
        h = self.l8(h, train, finetune)
        h = self.l9(h, train, finetune)

        h = F.sum(h, axis=-1)
        h = F.sum(h, axis=-1)
        h /= 8 * 8

        return F.softmax_cross_entropy(h, t), F.accuracy(h, t) 
开发者ID:tscohen,项目名称:gconv_experiments,代码行数:23,代码来源:AllCNNC.py

示例15: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import accuracy [as 别名]
def __call__(self, x, t, train=True, finetune=False):

        # First conv layer
        h = self[0](x)

        # Residual blocks
        for i in range(1, len(self) - 2):
            h = self[i](h, train, finetune)

        # BN, relu, pool, final layer
        h = self[-2](h)
        h = F.relu(h)
        n, nc, ns, nx, ny = h.data.shape
        h = F.reshape(h, (n, nc * ns, nx, ny))
        h = F.average_pooling_2d(h, ksize=h.data.shape[2:])
        h = self[-1](h)
        h = F.reshape(h, h.data.shape[:2])

        return F.softmax_cross_entropy(h, t), F.accuracy(h, t) 
开发者ID:tscohen,项目名称:gconv_experiments,代码行数:21,代码来源:P4MResNet.py


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