예제 #1
0
 def test_hinge_loss_pytorch(self):
     """Test HingeLoss."""
     loss = losses.HingeLoss()
     outputs = torch.tensor([[0.1, 0.8], [0.4, 0.6]])
     labels = torch.tensor([[1.0, -1.0], [-1.0, 1.0]])
     result = loss._create_pytorch_loss()(outputs, labels).numpy()
     expected = [np.mean([0.9, 1.8]), np.mean([1.4, 0.4])]
     assert np.allclose(expected, result)
예제 #2
0
 def test_hinge_loss_tf(self):
     """Test HingeLoss."""
     loss = losses.HingeLoss()
     outputs = tf.constant([[0.1, 0.8], [0.4, 0.6]])
     labels = tf.constant([[1.0, -1.0], [-1.0, 1.0]])
     result = loss._compute_tf_loss(outputs, labels).numpy()
     expected = [np.mean([0.9, 1.8]), np.mean([1.4, 0.4])]
     assert np.allclose(expected, result)