コード例 #1
0
  def test_config(self):
    sq_hinge_obj = metrics.SquaredHinge(name='sq_hinge', dtype=dtypes.int32)
    self.assertEqual(sq_hinge_obj.name, 'sq_hinge')
    self.assertEqual(sq_hinge_obj._dtype, dtypes.int32)

    # Check save and restore config
    sq_hinge_obj2 = metrics.SquaredHinge.from_config(sq_hinge_obj.get_config())
    self.assertEqual(sq_hinge_obj2.name, 'sq_hinge')
    self.assertEqual(sq_hinge_obj2._dtype, dtypes.int32)
コード例 #2
0
 def test_weighted(self):
     sq_hinge_obj = metrics.SquaredHinge()
     self.evaluate(variables.variables_initializer(sq_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 = sq_hinge_obj(y_true, y_pred, sample_weight=sample_weight)
     self.assertAllClose(0.65714, self.evaluate(result), atol=1e-5)
コード例 #3
0
    def test_unweighted(self):
        sq_hinge_obj = metrics.SquaredHinge()
        self.evaluate(variables.variables_initializer(sq_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 = sq_hinge_obj.update_state(y_true, y_pred)
        self.evaluate(update_op)
        result = sq_hinge_obj.result()
        self.assertAllClose(0.65, result, atol=1e-5)