Skip to content

Commit

Permalink
Fix error when testing xla in cosine similarity metric (#3213)
Browse files Browse the repository at this point in the history
* add cosine similarity

* update doc for cosine similarity metric

* fix the position of the CosineSimilarity

* Update ignite/contrib/metrics/cosine_similarity.py

Co-authored-by: vfdev <[email protected]>

* autopep8 fix

* move CosineSimilarity from contrib.metrics to metrics

* autopep8 fix

* fix typo

* fix typo

* Update ignite/metrics/cosine_similarity.py

Co-authored-by: vfdev <[email protected]>

* autopep8 fix

* Update ignite/metrics/cosine_similarity.py

Co-authored-by: vfdev <[email protected]>

* fix formatting

* autopep8 fix

* fix formatting

* autopep8 fix

* add test for CosineSimilarity metric

* autopep8 fix

* fix error when testing in xla

---------

Co-authored-by: vfdev <[email protected]>
Co-authored-by: kzkadc <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent 27deb45 commit 3d8f3ec
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/ignite/metrics/test_cosine_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def update(engine, i):
y_true_np = y_true.cpu().numpy()
y_preds_np = y_preds.cpu().numpy()
y_true_norm = np.clip(np.linalg.norm(y_true_np, axis=1, keepdims=True), 1e-8, None)
y_preds_norm = np.clip(np.linalg.norm(y_preds, axis=1, keepdims=True), 1e-8, None)
y_preds_norm = np.clip(np.linalg.norm(y_preds_np, axis=1, keepdims=True), 1e-8, None)
true_res = np.sum((y_true_np / y_true_norm) * (y_preds_np / y_preds_norm), axis=1)
true_res = np.mean(true_res)

Expand Down

0 comments on commit 3d8f3ec

Please sign in to comment.