python 随机padding_Python backend.spatial_2d_padding方法代码示例

这篇博客介绍了如何在Python中使用Keras后端的spatial_2d_padding方法进行2D填充,特别是在卷积神经网络中的应用。通过示例代码展示了如何计算和应用填充,以及如何进行反卷积操作以保持输出尺寸正确。
摘要由CSDN通过智能技术生成

# 需要导入模块: from keras import backend [as 别名]

# 或者: from keras.backend import spatial_2d_padding [as 别名]

def _deconv(self, X, lname, d_switch, feat_map=None):

o_width, o_height = self[lname].output_shape[-2:]

# Get filter size

f_width = self[lname].W_shape[2]

f_height = self[lname].W_shape[3]

# Compute padding needed

i_width, i_height = X.shape[-2:]

pad_width = (o_width - i_width + f_width - 1) / 2

pad_height = (o_height - i_height + f_height - 1) / 2

assert isinstance(

pad_width, int), "Pad width size issue at layer %s" % lname

assert isinstance(

pad_height, int), "Pad height size issue at layer %s" % lname

# Set to zero based on switch values

X[d_switch[lname]] = 0

# Get activation function

activation = self[lname].activation

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值