本文整理匯總了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)