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


Python Logger.add方法代码示例

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


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

示例1: enumerate

# 需要导入模块: from core.logger import Logger [as 别名]
# 或者: from core.logger.Logger import add [as 别名]
        accs.append(metrics.logit2acc(log_outputs.data, labels))
        training_loss += loss.cpu().data.numpy()[0]

    # ELBO evaluation
    net.train()
    training_loss = 0
    steps = 0
    accs = []
    for i, (inputs, labels) in enumerate(trainloader, 0):
        steps += 1
        inputs, labels = Variable(inputs.cuda(async=True)), Variable(labels.cuda(async=True))
        for j in range(10):
            outputs = net(inputs).detach()
            training_loss += criterion(outputs, labels).cpu().data.numpy()[0]/10.0
        accs.append(metrics.logit2acc(outputs.data, labels))
    logger.add(epoch, kl=criterion.get_kl(), tr_loss=training_loss/steps, tr_acc=np.mean(accs))

    # zero-mean ELBO evaluation
    net.train()
    net.set_flag('zero_mean', True)
    training_loss = 0
    steps = 0
    accs = []
    for i, (inputs, labels) in enumerate(trainloader, 0):
        steps += 1
        inputs, labels = Variable(inputs.cuda(async=True)), Variable(labels.cuda(async=True))
        for j in range(10):
            outputs = net(inputs).detach()
            training_loss += criterion(net(inputs), labels).cpu().data.numpy()[0] / 10.0
        accs.append(metrics.logit2acc(outputs.data, labels))
    logger.add(epoch, zero_mean_tr_loss=training_loss / steps, zero_mean_tr_acc=np.mean(accs))
开发者ID:AlliedToasters,项目名称:elko_den,代码行数:33,代码来源:lenet5-vdo.py

示例2: enumerate

# 需要导入模块: from core.logger import Logger [as 别名]
# 或者: from core.logger.Logger import add [as 别名]
    accs = []
    steps = 0
    for i, (inputs, labels) in enumerate(trainloader, 0):
        steps += 1
        inputs, labels = Variable(inputs.cuda(async=True)), Variable(labels.cuda(async=True))

        optimizer.zero_grad()
        outputs = net(inputs)
        loss = criterion(outputs, labels)
        loss.backward()
        optimizer.step()

        accs.append(metrics.logit2acc(outputs.data, labels))  # probably a bad way to calculate accuracy
        training_loss += loss.cpu().data.numpy()[0]

    logger.add(epoch, tr_loss=training_loss/steps, tr_acc=np.mean(accs))

    # Deterministic test
    net.eval()
    acc, nll = utils.evaluate(net, testloader, num_ens=1)
    logger.add(epoch, te_nll_det=nll, te_acc_det=acc)

    # Stochastic test
    net.train()
    acc, nll = utils.evaluate(net, testloader, num_ens=1)
    logger.add(epoch, te_nll_stoch=nll, te_acc_stoch=acc)

    # Test-time averaging
    net.train()
    acc, nll = utils.evaluate(net, testloader, num_ens=20)
    logger.add(epoch, te_nll_ens=nll, te_acc_ens=acc)
开发者ID:AlliedToasters,项目名称:elko_den,代码行数:33,代码来源:lenet5-vanilla.py


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