!5960 [ModelZoo]Add bgcf epoch time print

Merge pull request !5960 from zhanke/bgcf
This commit is contained in:
mindspore-ci-bot 2020-09-10 12:06:54 +08:00 committed by Gitee
commit 20991a0718
2 changed files with 4 additions and 2 deletions

View File

@ -50,7 +50,7 @@ def novelty_at_k(topk_items, item_degree_dict, num_user, k):
"""Calculate the novelty at k"""
avg_nov = []
for item in topk_items[:k]:
avg_nov.append(-np.log2(item_degree_dict[item] / num_user))
avg_nov.append(-np.log2((item_degree_dict[item] + 1e-8) / num_user))
return np.mean(avg_nov)

View File

@ -16,6 +16,7 @@
BGCF training script.
"""
import os
import time
import datetime
from mindspore import Tensor
@ -56,6 +57,7 @@ def train_and_eval():
for _epoch in range(1, parser.num_epoch + 1):
epoch_start = time.time()
iter_num = 1
for data in itr:
@ -96,7 +98,7 @@ def train_and_eval():
if iter_num == num_iter:
print('Epoch', '%03d' % _epoch, 'iter', '%02d' % iter_num,
'loss',
'{}'.format(train_loss))
'{}, cost:{:.4f}'.format(train_loss, time.time() - epoch_start))
iter_num += 1
if _epoch % parser.eval_interval == 0: