faizanahemad / FastNet

API layer built on tensorflow-2.0 for high performance and easy training
3 stars 2 forks source link

Cutout Image Augmentation: Additional mode to fill with zeros #10

Open unography opened 5 years ago

unography commented 5 years ago

Current code seems to be filling the cutout area with noise. Should we add a mode to fill it with zeros as well?

def tf_cutout(x: tf.Tensor) -> tf.Tensor:
        """
        Cutout data augmentation. Randomly cuts a h by w whole in the image, and fill the whole with zeros.
        :param x: Input image.
        :param h: Height of the hole.
        :param w: Width of the hole
        :param c: Number of color channels in the image. Default: 3 (RGB).
        :return: Transformed image.
        """
        dtype = x.dtype
        minval = tf.cast(minimum, dtype=dtype)
        maxval = tf.cast(maximum, dtype=dtype)

        aspect_ratio = tf.random.uniform([], min_aspect_ratio, max_aspect_ratio)
        h, w = get_h_w(aspect_ratio)

        shape = tf.shape(x)
        x0 = tf.random.uniform([], 0, shape[1] + 1 - h, dtype=tf.int32)
        y0 = tf.random.uniform([], 0, shape[2] + 1 - w, dtype=tf.int32)

        slic = tf.random.uniform([shape[0], h, w, c], minval=minval, maxval=maxval, dtype=dtype)
        x = replace_slice(x, slic, [0, x0, y0, 0])
        return x

https://github.com/faizanahemad/FastNet/blob/master/fastnet/data/image_augmentations.py#L51

faizanahemad commented 5 years ago

@unography The idea to fill with uniform noise instead of zeros was to make sure that

What we can do is have a flag pixel_level=True which controls which version is used. The fill value will be noise for pixel_level=True and minimum parameter for pixel_level=False.