keras.layers.UpSampling2D()

在U-Net代码中出现过UpSampling2D,对卷积结果进行上采样从而将特征图放大,这个方法没有引入可训练的参数,就是一个简单的插值,一个重要的参数是size,该操作将数据的行和列分别重复size[0]和size[1]次,见如下例子

x = numpy.array([[1, 2], [3, 4]])
inputs = layers.Input(shape=(2, 2, 1))
out = layers.UpSampling2D(size=(2, 2))(inputs)
model = Model(inputs, out)
model.summary()
y = model.predict(numpy.reshape(x, (1, 2, 2, 1)))
y = numpy.reshape(y, (4, 4))
print('input:')
print(x)
print('output:')
print(y)
# print
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
input_1 (InputLayer)         (None, 2, 2, 1)           0
_________________________________________________________________
up_sampling2d_1 (UpSampling2 (None, 4, 4, 1)           0
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
_________________________________________________________________、
input:
[[1 2]
 [3 4]]
output:
[[1. 1. 2. 2.]
 [1. 1. 2. 2.]
 [3. 3. 4. 4.]
 [3. 3. 4. 4.]]

size=(10,10)时

output:
[[1. 1. 1. 1. 1. 2. 2. 2. 2. 2.]
 [1. 1. 1. 1. 1. 2. 2. 2. 2. 2.]
 [1. 1. 1. 1. 1. 2. 2. 2. 2. 2.]
 [1. 1. 1. 1. 1. 2. 2. 2. 2. 2.]
 [1. 1. 1. 1. 1. 2. 2. 2. 2. 2.]
 [3. 3. 3. 3. 3. 4. 4. 4. 4. 4.]
 [3. 3. 3. 3. 3. 4. 4. 4. 4. 4.]
 [3. 3. 3. 3. 3. 4. 4. 4. 4. 4.]
 [3. 3. 3. 3. 3. 4. 4. 4. 4. 4.]
 [3. 3. 3. 3. 3. 4. 4. 4. 4. 4.]]
发布了48 篇原创文章 · 获赞 3 · 访问量 1999

猜你喜欢

转载自blog.csdn.net/weixin_43486780/article/details/105152444