Exemple #1
0
    def test_loss_same_images(self, size):
        """Tests that passing same images results in a loss close to 0.0."""
        tensor_shape = np.random.randint(size, 6, size=3).tolist()
        image = np.random.uniform(0.0, 1.0, size=tensor_shape + [1])

        laplacian, _ = matting.build_matrices(image, size=size)
        loss = matting.loss(image, laplacian)

        self.assertAllClose(loss, 0.0, atol=1e-4)
Exemple #2
0
    def test_loss_same_images(self):
        """Tests that passing same images results in a loss close to 0.0."""
        shape = np.random.randint(3, 5, size=3).tolist()
        image = np.random.uniform(0.0, 1.0, size=shape + [1])

        weights = matting.laplacian_weights(image)
        loss = matting.loss(image, weights)

        self.assertAllClose(loss, 0.0, atol=1e-4)
Exemple #3
0
    def test_loss_positive(self):
        """Tests that the loss is always greater or equal to 0.0."""
        shape = np.random.randint(3, 5, size=3).tolist()
        image = tf.random.uniform(minval=0.0, maxval=1.0, shape=shape + [3])
        matte = tf.random.uniform(minval=0.0, maxval=1.0, shape=shape + [1])

        weights = matting.laplacian_weights(image)
        loss = matting.loss(matte, weights)

        self.assertAllGreaterEqual(loss, 0.0)
Exemple #4
0
  def test_loss_positive(self, size):
    """Tests that the loss is always greater or equal to 0.0."""
    tensor_shape = np.random.randint(size, 6, size=3).tolist()
    image = tf.random.uniform(minval=0.0, maxval=1.0, shape=tensor_shape + [3])
    matte = tf.random.uniform(minval=0.0, maxval=1.0, shape=tensor_shape + [1])

    laplacian, _ = matting.build_matrices(image, size=size)
    loss = matting.loss(matte, laplacian)

    self.assertAllGreaterEqual(loss, 0.0)
Exemple #5
0
  def test_loss_jacobian_random(self, size):
    """Tests the Jacobian of the matting loss function."""
    tensor_shape = np.random.randint(size, 6, size=3)
    matte_init = np.random.uniform(0.0, 1.0, size=tensor_shape.tolist() + [1])
    tensor_shape[1:3] -= (size - 1)
    laplacian_init = np.random.uniform(
        0.0, 1.0, size=tensor_shape.tolist() + [size**2, size**2])
    matte = tf.convert_to_tensor(value=matte_init)
    laplacian = tf.convert_to_tensor(value=laplacian_init)

    loss = matting.loss(matte, laplacian)

    with self.subTest(name="matte"):
      self.assert_jacobian_is_correct(matte, matte_init, loss)
    with self.subTest(name="laplacian"):
      self.assert_jacobian_is_correct(laplacian, laplacian_init, loss)
Exemple #6
0
    def test_loss_jacobian_random(self):
        """Tests the Jacobian of the matting loss function."""
        shape = np.random.randint(3, 5, size=3)
        matte_init = np.random.uniform(0.0, 1.0, size=shape.tolist() + [1])
        shape[1:3] -= 2
        weights_init = np.random.uniform(0.0,
                                         1.0,
                                         size=shape.tolist() + [9, 9])
        matte = tf.convert_to_tensor(value=matte_init)
        weights = tf.convert_to_tensor(value=weights_init)

        loss = matting.loss(matte, weights)

        with self.subTest(name="matte"):
            self.assert_jacobian_is_correct(matte, matte_init, loss)
        with self.subTest(name="weights"):
            self.assert_jacobian_is_correct(weights, weights_init, loss)