7

I would like to use the Keras layer:

from keras.layers.convolutional import UpSampling2D
x = UpSampling2D((2, 2))(x)

How can I replicate this behavior with native tensorflow ?

I can't manage to find an equivalent function/layer.

Jonathan DEKHTIAR
  • 3,456
  • 1
  • 21
  • 42

2 Answers2

11

Assuming x is of shape (BATCH_SIZE, H, W, C), you can use tf.image.resize_nearest_neighbor, which is the backend implementation used by keras:

x = tf.image.resize_nearest_neighbor(x, (2*H,2*W))
amirbar
  • 841
  • 6
  • 11
0

There is tf.keras.layers.UpSampling2D. I'm not exactly sure, but I think the tf.image functions are implemented on the CPU only.

nio1814
  • 11
  • 1