Home > database >  Preprocessing layers with seed not producing the same data augmentation for images and masks
Preprocessing layers with seed not producing the same data augmentation for images and masks

Time:12-13

I'm trying to create a simple preprocessing augmentation layer, following this Tensorflow image and field

Alright, now I used the example from the different processing to image and mask

I would expect the image and its mask to be flip the same way since I set the seed in the Augment class as suggested in the Tensorflow tutorial.

CodePudding user response:

Augmentation can be done on the concatenated image and mask along the channel axis to form a single array and then recover the image and label back, which is shown below:

class Augment(tf.keras.layers.Layer):
    def __init__(self):
        super().__init__()
        # both use the same seed, so they'll make the same random changes.
        self.augment_inputs = tf.keras.layers.RandomRotation(0.3)


    def call(self, inputs, labels):
        
        output = self.augment_inputs(tf.concat([inputs, labels], -1) )
        
        inputs = output[:,:,0:4]
        labels = output[:,:,4:]

        return inputs, labels
  • Related