本文整理匯總了Python中config.print_freq方法的典型用法代碼示例。如果您正苦於以下問題:Python config.print_freq方法的具體用法?Python config.print_freq怎麽用?Python config.print_freq使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類config
的用法示例。
在下文中一共展示了config.print_freq方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: train
# 需要導入模塊: import config [as 別名]
# 或者: from config import print_freq [as 別名]
def train(train_loader, model, optimizer, epoch, logger):
model.train() # train mode (dropout and batchnorm is used)
losses = AverageMeter()
# Batches
for i, (img, alpha_label) in enumerate(train_loader):
# Move to GPU, if available
img = img.type(torch.FloatTensor).to(device) # [N, 4, 320, 320]
alpha_label = alpha_label.type(torch.FloatTensor).to(device) # [N, 2, 320, 320]
alpha_label = alpha_label.reshape((-1, 2, im_size * im_size)) # [N, 2, 320*320]
# Forward prop.
alpha_out = model(img) # [N, 320, 320]
alpha_out = alpha_out.reshape((-1, 1, im_size * im_size)) # [N, 320*320]
# Calculate loss
# loss = criterion(alpha_out, alpha_label)
loss = alpha_prediction_loss(alpha_out, alpha_label)
# Back prop.
optimizer.zero_grad()
loss.backward()
# Clip gradients
clip_gradient(optimizer, grad_clip)
# Update weights
optimizer.step()
# Keep track of metrics
losses.update(loss.item())
# Print status
if i % print_freq == 0:
status = 'Epoch: [{0}][{1}/{2}]\t' \
'Loss {loss.val:.4f} ({loss.avg:.4f})\t'.format(epoch, i, len(train_loader), loss=losses)
logger.info(status)
return losses.avg
示例2: train
# 需要導入模塊: import config [as 別名]
# 或者: from config import print_freq [as 別名]
def train(train_loader, model, optimizer, epoch, logger):
model.train() # train mode (dropout and batchnorm is used)
losses = AverageMeter()
# Batches
for i, (img, alpha_label) in enumerate(train_loader):
# Move to GPU, if available
img = img.type(torch.FloatTensor).to(device) # [N, 4, 320, 320]
alpha_label = alpha_label.type(torch.FloatTensor).to(device) # [N, 320, 320]
alpha_label = alpha_label.reshape((-1, 2, im_size * im_size)) # [N, 320*320]
# Forward prop.
alpha_out = model(img) # [N, 3, 320, 320]
alpha_out = alpha_out.reshape((-1, 1, im_size * im_size)) # [N, 320*320]
# Calculate loss
# loss = criterion(alpha_out, alpha_label)
loss = alpha_prediction_loss(alpha_out, alpha_label)
# Back prop.
optimizer.zero_grad()
loss.backward()
# Clip gradients
clip_gradient(optimizer, grad_clip)
# Update weights
optimizer.step()
# Keep track of metrics
losses.update(loss.item())
# Print status
if i % print_freq == 0:
status = 'Epoch: [{0}][{1}/{2}]\t' \
'Loss {loss.val:.4f} ({loss.avg:.4f})\t'.format(epoch, i, len(train_loader), loss=losses)
logger.info(status)
return losses.avg
示例3: train
# 需要導入模塊: import config [as 別名]
# 或者: from config import print_freq [as 別名]
def train(train_loader, model, optimizer, epoch, logger):
model.train() # train mode (dropout and batchnorm is used)
losses = AverageMeter()
# Batches
for i, (data) in enumerate(train_loader):
# Move to GPU, if available
padded_input, padded_target, input_lengths = data
padded_input = padded_input.to(device)
padded_target = padded_target.to(device)
input_lengths = input_lengths.to(device)
# Forward prop.
pred, gold = model(padded_input, input_lengths, padded_target)
loss, n_correct = cal_performance(pred, gold, smoothing=args.label_smoothing)
# Back prop.
optimizer.zero_grad()
loss.backward()
# Update weights
optimizer.step()
# Keep track of metrics
losses.update(loss.item())
# Print status
if i % print_freq == 0:
logger.info('Epoch: [{0}][{1}/{2}]\t'
'Loss {loss.val:.5f} ({loss.avg:.5f})'.format(epoch, i, len(train_loader), loss=losses))
return losses.avg
示例4: train
# 需要導入模塊: import config [as 別名]
# 或者: from config import print_freq [as 別名]
def train(train_loader, model, criterion, scheduler, optimizer, epoch):
start = time.time()
losses = AverageMeter()
batch_time = AverageMeter()
data_time = AverageMeter()
end = time.time()
model.train()
for i, (img, score_map, geo_map, training_mask) in enumerate(train_loader):
data_time.update(time.time() - end)
if cfg.gpu is not None:
img, score_map, geo_map, training_mask = img.cuda(), score_map.cuda(), geo_map.cuda(), training_mask.cuda()
f_score, f_geometry = model(img)
loss1 = criterion(score_map, f_score, geo_map, f_geometry, training_mask)
losses.update(loss1.item(), img.size(0))
# backward
scheduler.step()
optimizer.zero_grad()
loss1.backward()
optimizer.step()
# measure elapsed time
batch_time.update(time.time() - end)
end = time.time()
if i % cfg.print_freq == 0:
print('EAST <==> TRAIN <==> Epoch: [{0}][{1}/{2}] Loss {loss.val:.4f} Avg Loss {loss.avg:.4f})\n'.format(epoch, i, len(train_loader), loss=losses))
save_loss_info(losses, epoch, i, train_loader)
示例5: train
# 需要導入模塊: import config [as 別名]
# 或者: from config import print_freq [as 別名]
def train(train_loader, model, metric_fc, criterion, optimizer, epoch):
model.train() # train mode (dropout and batchnorm is used)
metric_fc.train()
losses = AverageMeter()
top1_accs = AverageMeter()
# Batches
for i, (img, label) in enumerate(train_loader):
# Move to GPU, if available
img = img.to(device)
label = label.to(device) # [N, 1]
# Forward prop.
feature = model(img) # embedding => [N, 512]
output = metric_fc(feature, label) # class_id_out => [N, 10575]
# Calculate loss
loss = criterion(output, label)
# Back prop.
optimizer.zero_grad()
loss.backward()
# Clip gradients
clip_gradient(optimizer, grad_clip)
# Update weights
optimizer.step()
# Keep track of metrics
losses.update(loss.item())
top1_accuracy = accuracy(output, label, 1)
top1_accs.update(top1_accuracy)
# Print status
if i % print_freq == 0:
logger.info('Epoch: [{0}][{1}/{2}]\t'
'Loss {loss.val:.4f} ({loss.avg:.4f})\t'
'Top1 Accuracy {top1_accs.val:.3f} ({top1_accs.avg:.3f})'.format(epoch, i, len(train_loader),
loss=losses,
top1_accs=top1_accs))
return losses.avg, top1_accs.avg
示例6: train
# 需要導入模塊: import config [as 別名]
# 或者: from config import print_freq [as 別名]
def train(train_loader, model, metric_fc, criterion, optimizer, epoch, logger):
model.train() # train mode (dropout and batchnorm is used)
metric_fc.train()
losses = AverageMeter()
top1_accs = AverageMeter()
# Batches
for i, (img, label) in enumerate(train_loader):
# Move to GPU, if available
img = img.to(device)
label = label.to(device) # [N, 1]
# Forward prop.
feature = model(img) # embedding => [N, 512]
output = metric_fc(feature, label) # class_id_out => [N, 10575]
# Calculate loss
loss = criterion(output, label)
# Back prop.
optimizer.zero_grad()
loss.backward()
# Clip gradients
optimizer.clip_gradient(grad_clip)
# Update weights
optimizer.step()
# Keep track of metrics
losses.update(loss.item())
top1_accuracy = accuracy(output, label, 1)
top1_accs.update(top1_accuracy)
# Print status
if i % print_freq == 0:
logger.info('Epoch: [{0}][{1}/{2}]\t'
'Loss {loss.val:.4f} ({loss.avg:.4f})\t'
'Top1 Accuracy {top1_accs.val:.3f} ({top1_accs.avg:.3f})'.format(epoch, i, len(train_loader),
loss=losses,
top1_accs=top1_accs))
return losses.avg, top1_accs.avg
開發者ID:LcenArthas,項目名稱:CCF-BDCI2019-Multi-person-Face-Recognition-Competition-Baseline,代碼行數:46,代碼來源:train.py
示例7: train
# 需要導入模塊: import config [as 別名]
# 或者: from config import print_freq [as 別名]
def train(train_loader, model, metric_fc, criterion, optimizer, epoch, logger):
model.train() # train mode (dropout and batchnorm is used)
metric_fc.train()
losses = AverageMeter()
top5_accs = AverageMeter()
# Batches
for i, (img, label) in enumerate(train_loader):
# Move to GPU, if available
img = img.to(device)
label = label.to(device) # [N, 1]
# Forward prop.
feature = model(img) # embedding => [N, 512]
output = metric_fc(feature, label) # class_id_out => [N, 93431]
# Calculate loss
loss = criterion(output, label)
# Back prop.
optimizer.zero_grad()
loss.backward()
# Clip gradients
optimizer.clip_gradient(grad_clip)
# Update weights
optimizer.step()
# Keep track of metrics
losses.update(loss.item())
top5_accuracy = accuracy(output, label, 5)
top5_accs.update(top5_accuracy)
# Print status
if i % print_freq == 0:
logger.info('Epoch: [{0}][{1}/{2}]\t'
'Loss {loss.val:.4f} ({loss.avg:.4f})\t'
'Top5 Accuracy {top5_accs.val:.3f} ({top5_accs.avg:.3f})'.format(epoch, i, len(train_loader),
loss=losses,
top5_accs=top5_accs))
return losses.avg, top5_accs.avg