What methods can be used to enlarge spartial dimension of the layer output blob?
As far as I can see from documentation it can be:
Repeats the rows and columns of the data by size[0] and size[1] respectively.
and it's not very smart.Conv2DTranspose Can it have arbitary output size (not power of 2 upsapmple)?
How bilinear interpolation upscale with arbitary dimensions can be done (it can be Conv2DTranspose with fixed weights?)
What other options can be used to enlarge spartial dimension of the layer output blob?
Expanding on the answer from y300, here is a complete example of wrapping TensorFlow bilinear image resizing in a Keras Lambda layer:
from keras import Sequential
from keras.layers import Lambda
import tensorflow as tf
def UpSampling2DBilinear(size):
return Lambda(lambda x: tf.image.resize_bilinear(x, size, align_corners=True))
upsampler = Sequential([UpSampling2DBilinear((256, 256))])
upsampled = upsampler.predict(images)
Note that align_corners=True
to get similar performance to other bilinear image upsampling algorithms, as described in this post.
To use bicubic resampling, create a new function and replace resize_bilinear
with resize_bicubic
.
For an implementation even more similar to UpSampling2D, try this:
from keras import backend as K
def UpSampling2DBilinear(stride, **kwargs):
def layer(x):
input_shape = K.int_shape(x)
output_shape = (stride * input_shape[1], stride * input_shape[2])
return tf.image.resize_bilinear(x, output_shape, align_corners=True)
return Lambda(layer, **kwargs)
This will allow you to use name=''
, input_shape=''
and other arguments for Lamba
, and allows you to pass an integer stride/upsample amount.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With