code: def weak_cross_entropy_2d(
      y_pred, y_true, num_classes=None, epsilon=0.0001, head=None
  ):
      """Weak Crossentropy 2d.
  
      Calculate the semantic segmentation using weak softmax cross entropy loss.
  
      Given the prediction `y_pred` shaped as 2d image and the corresponding
      y_true, this calculated the widely used semantic segmentation loss.
      Using `tf.nn.softmax_cross_entropy_with_logits` is currently not supported.
      See https://github.com/tensorflow/tensorflow/issues/2327#issuecomment-224491229
  
      Arguments:
          y_pred: `tensor, float` - [batch_size, width, height, num_classes].
          y_true: `Labels tensor, int32` - [batch_size, width, height, num_classes].
              The ground truth of your data.
          num_classes: `int`. Number of classes.
          epsilon: `float`. Small number to add to `y_pred`.
          head: `numpy array` - [num_classes]. Weighting the loss of each class.
  
      Returns:
          Loss tensor of type float.
      """
      if num_classes is None:
          num_classes = y_true.get_shape().as_list()[-1]
          # This only works if shape of y_true is defined
          assert num_classes is not None
  
      with tf.name_scope("weakCrossEntropy2d"):
          y_pred = tf.reshape(y_pred, (-1, num_classes))
          y_pred = y_pred + tf.constant(epsilon, dtype=y_pred.dtype)
          y_true = tf.to_float(tf.reshape(y_true, (-1, num_classes)))
  
          softmax = tf.nn.softmax(y_pred)
  
          if head is not None:
              cross_entropy = -tf.reduce_sum(
                  tf.multiply(y_true * tf.log(softmax), head),
                  reduction_indices=[1],
              )
          else:
              cross_entropy = -tf.reduce_sum(
                  y_true * tf.log(softmax), reduction_indices=[1]
              )
  
          cross_entropy_mean = tf.reduce_mean(
              cross_entropy, name="xentropy_mean"
          )
  
      return cross_entropy_mean
  
file_path: tflearn/tflearn/objectives.py
imports: from __future__ import division, print_function, absolute_import
  import tensorflow.compat.v1
  from .config import _EPSILON, _FLOATX
  from .utils import get_from_module
label_desc: Use image node_id 9 for calling a global function with example usage: weak_cross_entropy_2d(y_pred, y_true, num_classes, epsilon, head) and returns: cross_entropy_mean