CNTK:如何定义UpSampling2D

时间:2017-03-28 20:48:25

标签: python deep-learning keras cntk

我想知道如何在CNTK中实现UpSampling2D。我在API中找不到这样的图层。

UpSampling2D是池化图层的相反操作,通过重复数据的行和列来扩展数据。这是UpSampling2D的keras / tensorflow API。

通过查看tensorflow code,他们使用backend.resize_images操作,但我无法在CNTK API中找到调整大小操作。

UpSampling2D

答案1(来自Frank)

enter image description here

答案2(来自大卫)

enter image description here

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

1 个答案:

答案 0 :(得分:2)

它可以通过重塑和拼接的基本操作进行组装,例如

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