class_docstr: GridMask class for grid masking augmentation.
class_docstr_tok: ["GridMask","class","for","grid","masking","augmentation","."]
docstr: mask helper function for initializing grid mask of required size.
docstr_tok: ["mask","helper","function","for","initializing","grid","mask","of","required","size","."]
code: def mask(self, h, w):
      """mask helper function for initializing grid mask of required size."""
      h = tf.cast(h, tf.float32)
      w = tf.cast(w, tf.float32)
      mask_w = mask_h = tf.cast(
          tf.cast((self.gridmask_size_ratio + 1), tf.float32)
          * tf.math.maximum(h, w),
          tf.int32,
      )
      self.mask_w = mask_w
      mask = tf.zeros(shape=[mask_h, mask_w], dtype=tf.int32)
      gridblock = tf.random.uniform(
          shape=[],
          minval=int(tf.math.minimum(h * 0.5, w * 0.3)),
          maxval=int(tf.math.maximum(h * 0.5, w * 0.3)) + 1,
          dtype=tf.int32,
      )
  
      if self.ratio == 1:
          length = tf.random.uniform(
              shape=[], minval=1, maxval=gridblock + 1, dtype=tf.int32
          )
      else:
          length = tf.cast(
              tf.math.minimum(
                  tf.math.maximum(
                      int(
                          tf.cast(gridblock, tf.float32) * self.ratio
                          + 0.5
                      ),
                      1,
                  ),
                  gridblock - 1,
              ),
              tf.int32,
          )
  
      for _ in range(2):
          start_w = tf.random.uniform(
              shape=[], minval=0, maxval=gridblock + 1, dtype=tf.int32
          )
          for i in range(mask_w // gridblock):
              start = gridblock * i + start_w
              end = tf.math.minimum(start + length, mask_w)
              indices = tf.reshape(
                  tf.range(start, end), [end - start, 1]
              )
              updates = (
                  tf.ones(shape=[end - start, mask_w], dtype=tf.int32)
                  * self.fill
              )
              mask = tf.tensor_scatter_nd_update(mask, indices, updates)
          mask = tf.transpose(mask)
  
      return mask
  
file_path: DALI/docs/examples/use_cases/tensorflow/efficientdet/pipeline/tf/gridmask.py
imports: import math
  import tensorflow
  from tensorflow_addons import image
label_desc: Use image node_id 4 for calling the GridMask obj's underlying member method code with example usage: obj.mask(h, w) and returns: mask