Example #1
0
 def test_torch_composite_loss(self):
     epsilon = 1e-4
     config = {'training': {'loss': {'bce': {}, 'hinge': {}}}}
     lf = get_loss('torch', config)
     y_true = torch.tensor([1, 1, 1], dtype=torch.float)
     y_pred = torch.tensor([0, 1, 0], dtype=torch.float)
     assert np.abs(lf.forward(y_true, y_pred) - 19.4207) < epsilon
Example #2
0
 def test_torch_composite_loss(self):
     epsilon = 1e-4
     loss_dict = {'bce' : {}, 'hinge' : {}}
     lf = get_loss('torch', loss_dict)
     y_true = torch.tensor([0, 1, 1], dtype=torch.float)
     y_pred = torch.tensor([.1, .9, .4], dtype=torch.float)
     assert np.abs(
         lf.forward(y_pred, y_true) - 1.1423372030) < epsilon
Example #3
0
 def test_keras_composite_loss_noweight(self):
     epsilon = 1e-6
     loss_dict = {'bce' : {}, 'hinge' : {}}
     lf = get_loss('keras', loss_dict)
     y_true = tf.constant([0, 1, 1], dtype='float')
     y_pred = tf.constant([.1, .9, .4], dtype='float')
     sess = tf.Session()
     with sess.as_default():
         assert np.abs(
             lf(y_true, y_pred).eval() - 0.9423373) < epsilon
Example #4
0
 def test_keras_composite_loss_noweight(self):
     epsilon = 1e-6
     config = {'training': {'loss': {'bce': {}, 'hinge': {}}}}
     lf = get_loss('keras', config)
     y_true = tf.constant([1, 1, 1], dtype='float')
     y_pred = tf.constant([0, 1, 0], dtype='float')
     sess = tf.Session()
     with sess.as_default():
         assert np.abs(lf(y_true, y_pred).eval() -
                       11.41206380063888) < epsilon
Example #5
0
 def test_torch_vanilla_loss(self):
     loss_dict = {'bce' : {}}
     lf = get_loss('torch', loss_dict)
     assert isinstance(lf, torch.nn.BCELoss)
Example #6
0
 def test_keras_vanilla_loss(self):
     loss_dict = {'bce' : {}}
     lf = get_loss('keras', loss_dict)
     assert lf == keras.losses.binary_crossentropy
Example #7
0
 def test_torch_vanilla_loss(self):
     config = {'training': {'loss': {'bce': {}}}}
     lf = get_loss('torch', config)
     assert isinstance(lf, torch.nn.BCELoss)
Example #8
0
 def test_keras_vanilla_loss(self):
     config = {'training': {'loss': {'bce': {}}}}
     lf = get_loss('keras', config)
     assert lf == keras.losses.binary_crossentropy