code: def loss(
      matte: type_alias.TensorLike,
      laplacian: type_alias.TensorLike,
      name: str = "matting_loss",
  ) -> tf.Tensor:
      """Computes the matting loss function based on the matting Laplacian.
  
      Computes the matting loss function based on the `laplacian` generated by the
      `build_matrices` function which implements the approach proposed by Levin
      et al. in "A Closed Form Solution to Natural Image Matting".
  
      Args:
        matte: A tensor of shape `[B, H, W, 1]`.
        laplacian: A tensor of shape `[B, H - pad, W - pad, size^2, size^2]`
          containing the Laplacian matrices computed by the `build_matrices`
          function, where `pad` is equal to `size - 1` and `size` is the patch size
          used to compute this tensor.
        name: A name for this op. Defaults to "matting_loss".
  
      Returns:
        A tensor containing a scalar value defining the matting loss.
  
      Raises:
        ValueError: If the last dimension of `matte` is not 1. If `matte` is not
        of rank 4. If the last two dimensions of `laplacian` are not of the
        same size. If `laplacian` is not of rank 5. If `B` is different
        between `matte` and `laplacian`.
      """
      with tf.name_scope(name):
          matte = tf.convert_to_tensor(value=matte)
          laplacian = tf.convert_to_tensor(value=laplacian)
  
          pixels = tf.compat.dimension_value(laplacian.shape[-1])
          shape.check_static(matte, has_rank=4, has_dim_equals=(-1, 1))
          shape.check_static(
              laplacian, has_rank=5, has_dim_equals=(-2, pixels)
          )
          shape.compare_batch_dimensions(
              tensors=(matte, laplacian),
              last_axes=0,
              broadcast_compatible=False,
          )
  
          size = np.sqrt(pixels)
          patches = tf.expand_dims(_image_patches(matte, size), axis=-2)
          losses = _quadratic_form(laplacian, patches)
          return tf.reduce_mean(input_tensor=losses)
  
file_path: graphics/tensorflow_graphics/image/matting.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import List, Tuple, Union
  import numpy
  import tensorflow
  from tensorflow_graphics.math import vector
  from tensorflow_graphics.util import asserts
  from tensorflow_graphics.util import export_api
  from tensorflow_graphics.util import shape
  from tensorflow_graphics.util import type_alias
label_desc: Use image node_id 7 for calling a global function with example usage: loss(matte, laplacian, name) and returns: tf