Exemple #1
0
    def test_config(self):
        hinge_obj = metrics.Hinge(name='hinge', dtype=dtypes.int32)
        self.assertEqual(hinge_obj.name, 'hinge')
        self.assertEqual(hinge_obj._dtype, dtypes.int32)

        # Check save and restore config
        hinge_obj2 = metrics.Hinge.from_config(hinge_obj.get_config())
        self.assertEqual(hinge_obj2.name, 'hinge')
        self.assertEqual(hinge_obj2._dtype, dtypes.int32)
Exemple #2
0
 def test_weighted(self):
     hinge_obj = metrics.Hinge()
     self.evaluate(variables.variables_initializer(hinge_obj.variables))
     y_true = constant_op.constant(((0, 1, 0, 1, 0), (0, 0, 1, 1, 1),
                                    (1, 1, 1, 1, 0), (0, 0, 0, 0, 1)))
     y_pred = constant_op.constant(((0, 0, 1, 1, 0), (1, 1, 1, 1, 1),
                                    (0, 1, 0, 1, 0), (1, 1, 1, 1, 1)))
     sample_weight = constant_op.constant((1., 1.5, 2., 2.5))
     result = hinge_obj(y_true, y_pred, sample_weight=sample_weight)
     self.assertAllClose(0.65714, self.evaluate(result), atol=1e-5)
Exemple #3
0
    def test_unweighted(self):
        hinge_obj = metrics.Hinge()
        self.evaluate(variables.variables_initializer(hinge_obj.variables))
        y_true = constant_op.constant(((0, 1, 0, 1, 0), (0, 0, 1, 1, 1),
                                       (1, 1, 1, 1, 0), (0, 0, 0, 0, 1)))
        y_pred = constant_op.constant(((0, 0, 1, 1, 0), (1, 1, 1, 1, 1),
                                       (0, 1, 0, 1, 0), (1, 1, 1, 1, 1)))

        update_op = hinge_obj.update_state(y_true, y_pred)
        self.evaluate(update_op)
        result = hinge_obj.result()
        self.assertAllClose(0.65, result, atol=1e-5)