code: def maybe_gen_fake_data_based_on_real_data(
      image, label, reso, min_fake_lesion_ratio, gen_fake_probability
  ):
      """Remove real lesion and synthesize lesion."""
      # TODO(lehou): Replace magic numbers with flag variables.
      gen_prob_indicator = tf.random_uniform(
          shape=[], minval=0.0, maxval=1.0, dtype=tf.float32
      )
  
      background_mask = tf.less(label, 0.5)
      lesion_mask = tf.greater(label, 1.5)
      liver_mask = tf.logical_not(
          tf.logical_or(background_mask, lesion_mask)
      )
  
      liver_intensity = tf.boolean_mask(image, liver_mask)
      lesion_intensity = tf.boolean_mask(image, lesion_mask)
  
      intensity_diff = tf.reduce_mean(liver_intensity) - (
          tf.reduce_mean(lesion_intensity)
      )
      intensity_diff *= 1.15
      intensity_diff = tf.cond(
          tf.is_nan(intensity_diff), lambda: 0.0, lambda: intensity_diff
      )
  
      lesion_liver_ratio = 0.0
      lesion_liver_ratio += tf.random.normal(
          shape=[], mean=0.01, stddev=0.01
      )
      lesion_liver_ratio += tf.random.normal(
          shape=[], mean=0.0, stddev=0.05
      )
      lesion_liver_ratio = tf.clip_by_value(
          lesion_liver_ratio,
          min_fake_lesion_ratio,
          min_fake_lesion_ratio + 0.20,
      )
  
      fake_lesion_mask = tf.logical_and(
          _gen_rand_mask(
              ratio_mean=lesion_liver_ratio,
              ratio_stddev=0.0,
              scale=reso // 32,
              shape=label.shape,
              smoothness=reso // 32,
          ),
          tf.logical_not(background_mask),
      )
      liver_mask = tf.logical_not(
          tf.logical_or(background_mask, fake_lesion_mask)
      )
  
      # Blur the masks
      lesion_mask_blur = tf.squeeze(
          tf.nn.conv3d(
              tf.expand_dims(
                  tf.expand_dims(tf.cast(lesion_mask, tf.float32), -1),
                  0,
              ),
              filter=tf.ones([reso // 32] * 3 + [1, 1], tf.float32)
              / (reso // 32) ** 3,
              strides=[1, 1, 1, 1, 1],
              padding="SAME",
          )
      )
      fake_lesion_mask_blur = tf.squeeze(
          tf.nn.conv3d(
              tf.expand_dims(
                  tf.expand_dims(
                      tf.cast(fake_lesion_mask, tf.float32), -1
                  ),
                  0,
              ),
              filter=tf.ones([reso // 32] * 3 + [1, 1], tf.float32)
              / (reso // 32) ** 3,
              strides=[1, 1, 1, 1, 1],
              padding="SAME",
          )
      )
  
      # Remove real lesion and add fake lesion.
      # If the intensitify is too small (maybe no liver or lesion region labeled),
      # do not generate fake data.
      gen_prob_indicator = tf.cond(
          tf.greater(intensity_diff, 0.0001),
          lambda: gen_prob_indicator,
          lambda: 0.0,
      )
      # pylint: disable=g-long-lambda
      image = tf.cond(
          tf.greater(gen_prob_indicator, 1 - gen_fake_probability),
          lambda: image
          + intensity_diff * lesion_mask_blur
          - intensity_diff * fake_lesion_mask_blur,
          lambda: image,
      )
      label = tf.cond(
          tf.greater(gen_prob_indicator, 1 - gen_fake_probability),
          lambda: tf.cast(background_mask, tf.float32) * 0
          + tf.cast(liver_mask, tf.float32) * 1
          + tf.cast(fake_lesion_mask, tf.float32) * 2,
          lambda: label,
      )
      # pylint: enable=g-long-lambda
  
      return image, label
  
file_path: mesh/mesh_tensorflow/experimental/data_aug_lib.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow.compat.v1
  import tensorflow_probability
  from tensorflow.contrib import image
label_desc: Use image node_id 6 for calling a global function with example usage: maybe_gen_fake_data_based_on_real_data(image, label, reso, min_fake_lesion_ratio, gen_fake_probability) and returns: image,  label