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

SCCE fix for bug in Jax<0.2.7 #130

Merged
merged 3 commits into from
Dec 22, 2020
Merged
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
14 changes: 13 additions & 1 deletion elegy/losses/sparse_categorical_crossentropy_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import elegy


import jax.numpy as jnp
import jax, jax.numpy as jnp
import numpy as np
import tensorflow.keras as keras


#
Expand Down Expand Up @@ -47,3 +49,13 @@ def test_scce_out_of_bounds():
scce = elegy.losses.SparseCategoricalCrossentropy(check_bounds=False)
assert not jnp.isnan(scce(ytrue0, ypred)).any()
assert not jnp.isnan(scce(ytrue1, ypred)).any()


def test_scce_uint8_ytrue():
ypred = np.random.random([2, 256, 256, 10])
ytrue = np.random.randint(0, 10, size=(2, 256, 256)).astype(np.uint8)

loss0 = elegy.losses.sparse_categorical_crossentropy(ytrue, ypred, from_logits=True)
loss1 = keras.losses.sparse_categorical_crossentropy(ytrue, ypred, from_logits=True)

assert np.allclose(loss0, loss1)
46 changes: 37 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.