How can I add a resizing by scale layer to a model in tensorflow or keras

703 Views Asked by At

How can I add a resizing by scale layer to a model using tensorflow or keras ? ( not by fixed output dimensions) for example i want to resize image shape (100, 100, 3) by up scale of 2 , so the output shape of that layer will be (200, 200, 3) resizing layer should use interpolation methods like ( "bilinear", "nearest", "bicubic", "area") Thank you.

1

There are 1 best solutions below

6
Yaoshiang On

You can't really be dynamic about image shapes within a dataset. To generate high speed execution on GPU, your images need to be fixed size.

That said, if all your images are a certain size within a dataset, but you want your model to generalize to different datasets, each with a different image size, you can just use an upsampling layer.

If you really need dynamic images within a dataset, and you know the largest image, you could center-pad all images until they match the correct size.

https://www.tensorflow.org/api_docs/python/tf/keras/layers/UpSampling2D.