code: def class_balanced_sigmoid_cross_entropy(
      logits, label, name="cross_entropy_loss"
  ):
      """
      The class-balanced cross entropy loss,
      as in `Holistically-Nested Edge Detection
      <http://arxiv.org/abs/1504.06375>`_.
  
      Args:
          logits: of shape (b, ...).
          label: of the same shape. the ground truth in {0,1}.
      Returns:
          class-balanced cross entropy loss.
      """
      with tf.name_scope("class_balanced_sigmoid_cross_entropy"):
          y = tf.cast(label, tf.float32)
  
          count_neg = tf.reduce_sum(1.0 - y)
          count_pos = tf.reduce_sum(y)
          beta = count_neg / (count_neg + count_pos)
  
          pos_weight = beta / (1 - beta)
          cost = tf.nn.weighted_cross_entropy_with_logits(
              logits=logits, targets=y, pos_weight=pos_weight
          )
          cost = tf.reduce_mean(cost * (1 - beta))
          zero = tf.equal(count_pos, 0.0)
      return tf.where(zero, 0.0, cost, name=name)
  
imports: import argparse
  import numpy
  import os
  import cv2
  import tensorflow
  from tensorpack import *
  from tensorpack.dataflow import dataset
  from tensorpack.tfutils import gradproc, optimizer
  from tensorpack.tfutils.summary import add_moving_summary, add_param_summary
  from tensorpack.utils.gpu import get_num_gpu
  from tensorpack.utils import logger
label_desc: Use image node_id 1 for calling a global function with example usage: class_balanced_sigmoid_cross_entropy(logits, label, name) and returns: tf