1 Answers

First you need to create a new Keras layer for input resize and here is how you can do it.

import tensorflow as tf
from keras.engine.topology import Layer

# The class is prepared to change the size of model's input dynamically
class MyInput(Layer):
    def __init__(self, image_size=(512, 512), **kwargs):
        self.image_size = image_size[0], image_size[1]
        super(MyInput, self).__init__(**kwargs)

    def call(self, inputs, **kwargs):
        return tf.image.resize_images(inputs, self.image_size)

    def compute_output_shape(self, input_shape):
        return input_shape[0], self.image_size[0], self.image_size[1], input_shape[-1]

Then you can just use this layer as any other regular keras layer and it will resize the inputs for you. (Remember this is just only for tensorflow. You can rewrite call function for other backends)

Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?