【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.]]
  • 12
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值