From df0491896444547c4901199213c83762059f383e Mon Sep 17 00:00:00 2001 From: zhanke Date: Wed, 9 Sep 2020 16:54:21 +0800 Subject: [PATCH] add epoch time print --- model_zoo/official/gnn/bgcf/src/metrics.py | 2 +- model_zoo/official/gnn/bgcf/train.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/model_zoo/official/gnn/bgcf/src/metrics.py b/model_zoo/official/gnn/bgcf/src/metrics.py index c7692604b..6c0024ab0 100644 --- a/model_zoo/official/gnn/bgcf/src/metrics.py +++ b/model_zoo/official/gnn/bgcf/src/metrics.py @@ -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) diff --git a/model_zoo/official/gnn/bgcf/train.py b/model_zoo/official/gnn/bgcf/train.py index 148fbe0cc..055aebb96 100644 --- a/model_zoo/official/gnn/bgcf/train.py +++ b/model_zoo/official/gnn/bgcf/train.py @@ -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: -- GitLab