如何在keras中将一层上采样到任意大小?

How to upsample one layer to any size in keras?

我想将大小为 (w,h,channels) 的一层上采样到 (w',h',channels) 的大小,但是 Upsample2D 层只能上采样到两倍大小。

任何人都可以告诉我如何进行任何大小的上采样?

Keras UpSample2D 可以 上采样到不同的大小,而不仅仅是两倍大小。从 Keras docs 我们可以看到这是为这样的层指示的:

keras.layers.UpSampling2D(size=(2, 2), data_format=None)

Upsampling layer for 2D inputs.

Repeats the rows and columns of the data by size[0] and size[1] respectively.

默认 size 值确实是 (2,2),因此在这种情况下,您的上采样将加倍。通过指定您想要的大小,您可以根据需要设法上采样到不同的大小。所以,如果你想要一个上采样因子,比如 3,那么你应该使用 size=(3,3),等等

作为替代方案,您还可以 define your own custom layers if you want something really specific to your case. For example, here 是一个关于创建自定义池函数的 Github 问题(与上采样层相反,因此很容易比较),如果您需要这样的自定义,它可以帮助您层.