本文整理汇总了Python中mxnet.nd.Convolution方法的典型用法代码示例。如果您正苦于以下问题:Python nd.Convolution方法的具体用法?Python nd.Convolution怎么用?Python nd.Convolution使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mxnet.nd
的用法示例。
在下文中一共展示了nd.Convolution方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forward
# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import Convolution [as 别名]
def forward(self, x):
# x shape is batch_size x in_channels x height x width
return nd.Convolution(
data=x,
weight=self._spectral_norm(),
kernel=(self.kernel_size, self.kernel_size),
pad=(self.padding, self.padding),
stride=(self.strides, self.strides),
num_filter=self.num_filter,
no_bias=True
)
示例2: _add_fake_bn_ema_hook
# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import Convolution [as 别名]
def _add_fake_bn_ema_hook(m):
def _ema_hook(m, x):
x = x[0]
weight = m.weight.data()
bias = nd.zeros(shape=weight.shape[0], ctx=weight.context) if m.bias is None else m.bias.data()
y = nd.Convolution(x, weight, bias, **m._kwargs)
num_samples = y.shape[0] * y.shape[2] * y.shape[3]
m.current_mean = y.sum(axis=(0, 2, 3)) / num_samples
diff_square = (y - m.current_mean.reshape(1, -1, 1, 1)) ** 2
m.current_var = diff_square.sum(axis=(0, 2, 3)) / num_samples
m.register_forward_pre_hook(_ema_hook)