本文整理匯總了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))
示例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)