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

Fix for 'update_ops' being None in metrics/factorized_top_k.py #725

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion tensorflow_recommenders/layers/factorized_top_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def top_k(state: Tuple[tf.Tensor, tf.Tensor],
def enumerate_rows(batch: tf.Tensor) -> Tuple[tf.Tensor, tf.Tensor]:
"""Enumerates rows in each batch using a total element counter."""

starting_counter = self._counter.read_value()
starting_counter = self._counter.value
end_counter = self._counter.assign_add(tf.shape(batch)[0])

return tf.range(starting_counter, end_counter), batch
Expand Down
6 changes: 4 additions & 2 deletions tensorflow_recommenders/metrics/factorized_top_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def update_state(
tf.reduce_sum(ids_match[:, :k], axis=1, keepdims=True),
0.0, 1.0
)
update_ops.append(metric.update_state(match_found, sample_weight))
metric.update_state(match_found, sample_weight)
update_ops.append(metric.result())
else:
# Score-based evaluation.
y_pred = tf.concat([positive_scores, top_k_predictions], axis=1)
Expand All @@ -189,7 +190,8 @@ def update_state(
predictions=y_pred,
k=k
)
update_ops.append(metric.update_state(top_k_accuracy, sample_weight))
metric.update_state(top_k_accuracy, sample_weight)
update_ops.append(metric.result())

return tf.group(update_ops)