上采样2D层如何在Keras中工作?

2024-04-19 17:34:22 发布

您现在位置:Python中文网/ 问答频道 /正文

Keras中的UpSampling2D层是如何工作的?根据official documentation

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

那么,如果size=(2, 2),它如何重复输入矩阵的行和列呢?你能举例说明一下程序吗?在


Tags: columnsandofthedatasizebydocumentation
1条回答
网友
1楼 · 发布于 2024-04-19 17:34:22

如果

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

没有帮助,那么也许有个例子会有帮助:

>>> import numpy as np
>>> from keras.layers import UpSampling2D
>>> from keras.models import Sequential
>>> model = Sequential()
>>> model.add(UpSampling2D(size=(2,2), input_shape=(3,3,1)))

>>> x = np.arange(9).reshape(1,3,3,1)
>>> x[0,:,:,0]  # this is what x looks like initially
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
>>> y = model.predict(x)
>>> y[0,:,:,0] # this is what it looks like after upsampling
array([[0., 0., 1., 1., 2., 2.],
       [0., 0., 1., 1., 2., 2.],
       [3., 3., 4., 4., 5., 5.],
       [3., 3., 4., 4., 5., 5.],
       [6., 6., 7., 7., 8., 8.],
       [6., 6., 7., 7., 8., 8.]], dtype=float32) 

相关问题 更多 >