4

I'm wondering how to achieve UpSampling2D in CNTK. I cannot find such layer in the API.

UpSampling2D is an opposite operation of pooling layers, and expand the data by repeating the rows and columns of the data. Here's keras/tensorflow API for UpSampling2D.

By looking at the tensorflow code, they use backend.resize_images operation, but I cannot find resize operation in CNTK API either.

UpSampling2D

Answer 1 (From Frank)

enter image description here

Answer 2 (From David)

enter image description here

Picture from Quora: How do fully convolutional networks upsample their coarse output?

Naoto Usuyama
  • 845
  • 1
  • 7
  • 13

1 Answers1

2

It can be assembled from basic operations of reshaping and splicing, e.g.

>>> x = Input((3, 480, 640))
>>> xr = reshape(x, (3, 480, 1, 640, 1))
>>> xr.shape
(3, 480, 1, 640, 1)
>>> xx = splice(xr, xr, axis=-1) # axis=-1 refers to the last axis
>>> xx.shape
(3, 480, 1, 640, 2)
>>> xy = splice(xx, xx, axis=-3) # axis=-3 refers to the middle axis
>>> xy.shape
(3, 480, 2, 640, 2)
>>> r = reshape(xy, (3, 480*2, 640*2))
>>> r.shape
(3, 960, 1280)
David Pisani
  • 181
  • 1
  • 7
  • Actually, with version 2.0 of CNTK/Python (on Azure Notebook), I got this error: TypeError: splice() got multiple values for argument 'axis'. Need to do like this C.splice((xr, xr), axis=-1) – Naoto Usuyama Mar 31 '17 at 04:11
  • @Frank Seide I tried this in CNTK C#. The dimensions doubled, but the image content isn't upsampled. Instead it's just 4 times the original image next to each other. How could splicing upsample the content of the image? – Floris Devreese Oct 15 '18 at 10:36