Skip to content

Commit

Permalink
Add value test for sparse_categorical_crossentropy (keras-team#7513)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzw0301 committed Aug 4, 2017
1 parent 7c7d735 commit e932299
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/keras/losses_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,14 @@ def test_categorical_hinge():
assert np.isclose(expected_loss, np.mean(loss))


def test_sparse_categorical_crossentropy():
y_pred = K.variable(np.array([[0.3, 0.6, 0.1],
[0.1, 0.2, 0.7]]))
y_true = K.variable(np.array([1, 2]))
expected_loss = - (np.log(0.6) + np.log(0.7)) / 2
loss = K.eval(losses.sparse_categorical_crossentropy(y_true, y_pred))
assert np.isclose(expected_loss, np.mean(loss))


if __name__ == '__main__':
pytest.main([__file__])

0 comments on commit e932299

Please sign in to comment.