Add a rescaling layer to a keras model

530 views Asked by At

Suppose I have an input image of shape (100, 100, 3) and I want to rescale the image, i.e., make it smaller and have a dimension say (50, 50, 3), i.e., rescaling it to half. Would be better if Gaussian smoothing is applied to the image within the layer after rescaling.

1

There are 1 answers

0
Jimut123 On BEST ANSWER

Ahh, this works fine, I figured it out,

y = layers.Lambda( 
        lambda image: tf.image.resize( 
            inputs, 
            (int(80 * 1/2), int(80 * 1/2)), 
            method = tf.image.ResizeMethod.BICUBIC,
            #align_corners = True, # possibly important
            preserve_aspect_ratio = True
        )
    )(inputs)