本文整理匯總了Python中models.crnn.train方法的典型用法代碼示例。如果您正苦於以下問題:Python crnn.train方法的具體用法?Python crnn.train怎麽用?Python crnn.train使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.crnn
的用法示例。
在下文中一共展示了crnn.train方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: training
# 需要導入模塊: from models import crnn [as 別名]
# 或者: from models.crnn import train [as 別名]
def training(start):
for total_steps in range(start, params.niter):
train_iter = iter(train_loader)
i = 0
print(len(train_loader))
while i < len(train_loader):
for p in crnn.parameters():
p.requires_grad = True
crnn.train()
cost = trainBatch(crnn, criterion, optimizer, train_iter)
loss_avg.add(cost)
i += 1
if i % params.displayInterval == 0:
print('[%d/%d][%d/%d] Loss: %f' %
(total_steps, params.niter, i, len(train_loader), loss_avg.val()))
loss_avg.reset()
if i % params.valInterval == 0:
val(crnn, test_dataset, criterion)
if (total_steps + 1) % params.saveInterval == 0:
# if i % params.valInterval == 0:
print('save model ..........')
ti = time.strftime('%Y-%m-%d', time.localtime(time.time()))
torch.save(crnn.state_dict(),
'{0}/crnn_Rec_done_{1}_{2}.pth'.format(params.experiment, total_steps, ti))
print('save model done')