Ejemplo n.º 1
0
 def test_categorical_cross_entropy_pytorch(self):
     """Test CategoricalCrossEntropy."""
     loss = losses.CategoricalCrossEntropy()
     outputs = torch.tensor([[0.2, 0.8], [0.4, 0.6]])
     labels = torch.tensor([[0.0, 1.0], [1.0, 0.0]])
     result = loss._create_pytorch_loss()(outputs, labels).numpy()
     expected = [-np.log(0.8), -np.log(0.4)]
     assert np.allclose(expected, result)
Ejemplo n.º 2
0
 def test_categorical_cross_entropy_tf(self):
     """Test CategoricalCrossEntropy."""
     loss = losses.CategoricalCrossEntropy()
     outputs = tf.constant([[0.2, 0.8], [0.4, 0.6]])
     labels = tf.constant([[0.0, 1.0], [1.0, 0.0]])
     result = loss._compute_tf_loss(outputs, labels).numpy()
     expected = [-np.log(0.8), -np.log(0.4)]
     assert np.allclose(expected, result)