Example #1
0
    def test_unweighted_from_logits(self):
        scce_obj = metrics.SparseCategoricalCrossentropy(from_logits=True)

        y_true = np.asarray([1, 2])
        logits = np.asarray([[1, 9, 0], [1, 8, 1]], dtype=np.float32)
        result = scce_obj(y_true, logits)

        assert np.allclose(K.eval(result), 3.5011, atol=1e-3)
Example #2
0
    def test_unweighted(self):
        scce_obj = metrics.SparseCategoricalCrossentropy()

        y_true = np.asarray([1, 2])
        y_pred = np.asarray([[0.05, 0.95, 0], [0.1, 0.8, 0.1]])
        result = scce_obj(y_true, y_pred)

        assert np.allclose(K.eval(result), 1.176, atol=1e-3)
Example #3
0
    def test_weighted_from_logits(self):
        scce_obj = metrics.SparseCategoricalCrossentropy(from_logits=True)
        y_true = np.asarray([1, 2])
        logits = np.asarray([[1, 9, 0], [1, 8, 1]], dtype=np.float32)
        sample_weight = [1.5, 2.]
        result = scce_obj(y_true, logits, sample_weight=sample_weight)

        assert np.allclose(K.eval(result), 4.0012, atol=1e-3)
Example #4
0
    def test_weighted(self):
        scce_obj = metrics.SparseCategoricalCrossentropy()

        y_true = np.asarray([1, 2])
        y_pred = np.asarray([[0.05, 0.95, 0], [0.1, 0.8, 0.1]])
        sample_weight = [1.5, 2.]
        result = scce_obj(y_true, y_pred, sample_weight=sample_weight)

        assert np.allclose(K.eval(result), 1.338, atol=1e-3)
Example #5
0
 def test_config(self):
     scce_obj = metrics.SparseCategoricalCrossentropy(
         name='scce', dtype='int32')
     assert scce_obj.name == 'scce'
     assert scce_obj.dtype == 'int32'