Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using NumPy APIs to improve performance and the code quality,  #325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions tensorflow_ranking/python/losses_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from __future__ import print_function

import math

import numpy as np
import tensorflow as tf

from tensorflow_ranking.python import losses as ranking_losses
Expand Down Expand Up @@ -151,14 +153,11 @@ def _loss(si, sj, label_diff, delta):

def _batch_aggregation(batch_loss_list, reduction=None):
"""Returns the aggregated loss."""
loss_sum = 0.
weight_sum = 0.
for loss, weight, count in batch_loss_list:
loss_sum += loss
if reduction == 'mean':
weight_sum += weight
else:
weight_sum += count
loss_sum = np.sum([loss for loss, weight, count in batch_loss_list])
if reduction == 'mean':
weight_sum = np.sum([weight for loss, weight, count in batch_loss_list])
else:
weight_sum = np.sum([count for loss, weight, count in batch_loss_list])
return loss_sum / weight_sum


Expand Down