Search code examples
pythondeep-learningkerascntk

CNTK: How to define UpSampling2D


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?


Solution

  • 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)