code: def _gen_rand_mask(
      ratio_mean, ratio_stddev, scale, shape, smoothness=0
  ):
      """Generate a binary mask."""
      scale = max(scale, 1)
  
      ratio = tf.random.normal(
          shape=[], mean=ratio_mean, stddev=ratio_stddev
      )
      low_bound = tf.maximum(0.0, ratio_mean - 2 * ratio_stddev)
      up_bound = tf.minimum(1.0, ratio_mean + 2 * ratio_stddev)
      percentil_q = tf.cast(
          100.0 * tf.clip_by_value(ratio, low_bound, up_bound), tf.int32
      )
  
      pattern = _rand_noise(0.0, 1.0, scale, shape)
      if smoothness > 0:
          smoothness = int(smoothness) // 2 * 2 + 1
          pattern = tf.expand_dims(tf.expand_dims(pattern, 0), -1)
          pattern = tf.nn.conv3d(
              pattern,
              filter=tf.ones(
                  [smoothness, smoothness, smoothness, 1, 1]
              ),
              strides=[1, 1, 1, 1, 1],
              padding="SAME",
              dilations=[1, 1, 1, 1, 1],
          )
          pattern = tf.reduce_sum(pattern, 0)
          pattern = tf.reduce_sum(pattern, -1)
  
      thres = tfp.stats.percentile(pattern, q=percentil_q)
      rand_mask = tf.less(pattern, thres)
  
      return rand_mask
  
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 5 for calling a global function with example usage: _gen_rand_mask(ratio_mean, ratio_stddev, scale, shape, smoothness) and returns: rand_mask