当前位置: 首页>>代码示例>>Python>>正文


Python functions.convolution_2d方法代码示例

本文整理汇总了Python中chainer.functions.convolution_2d方法的典型用法代码示例。如果您正苦于以下问题:Python functions.convolution_2d方法的具体用法?Python functions.convolution_2d怎么用?Python functions.convolution_2d使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainer.functions的用法示例。


在下文中一共展示了functions.convolution_2d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: forward_expected

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def forward_expected(self, inputs):
        """
        Current forward_expected implementation depends on
        F.convolution_2d itself and thus it's only capable
        of checking consistency between backends, not absolute
        correctness of computations
        """
        if self.nobias:
            x, W = inputs
            b = None
        else:
            x, W, b = inputs
        with chainer.using_config('use_ideep', 'never'):
            y_expected = F.convolution_2d(
                x, W, b, stride=self.stride, pad=self.pad,
                cover_all=self.cover_all, dilate=self.dilate,
                groups=self.groups)
        if self.old_numpy_fp16:
            return y_expected.array*0,
        return y_expected.array, 
开发者ID:chainer,项目名称:chainer,代码行数:22,代码来源:test_convolution_2d.py

示例2: check_forward_consistency_regression

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def check_forward_consistency_regression(self, backend_config):
        inputs = self.generate_inputs()
        if self.nobias:
            x, W = inputs
            b = None
        else:
            x, W, b = inputs
        x = chainer.Variable(backend_config.get_array(x))
        W = chainer.Variable(backend_config.get_array(W))
        if b is not None:
            b = chainer.Variable(backend_config.get_array(b))

        with chainer.using_config('use_cudnn', 'never'):
            y_nd = F.convolution_nd(
                x, W, b, stride=self.stride, pad=self.pad,
                cover_all=self.cover_all, dilate=self.dilate,
                groups=self.groups)
            y_2d = F.convolution_2d(
                x, W, b, stride=self.stride, pad=self.pad,
                cover_all=self.cover_all, dilate=self.dilate,
                groups=self.groups)

        testing.assert_allclose(
            y_nd.array, y_2d.array, **self.check_forward_options) 
开发者ID:chainer,项目名称:chainer,代码行数:26,代码来源:test_convolution_nd.py

示例3: check_forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def check_forward(self, x, offset, W, b, stride, pad):
        with chainer.using_config('use_cudnn', self.use_cudnn):
            _, _, h, w = x.shape
            _, _, kh, kw = W.shape
            offset[:, :kh * kw] = -1 * stride[1]
            offset[:, kh * kw:] = 1 * stride[0]

            x = chainer.Variable(x)
            offset = chainer.Variable(offset)
            out = deformable_convolution_2d_sampler(
                x, offset, W, b, stride, pad).data
            pad = (pad[0] + 1 * stride[0], pad[1] + 1 * stride[1])
            expeceted = convolution_2d(
                x, W, b, stride, pad).data
            expeceted = expeceted[:, :, 2:, :-2]
        testing.assert_allclose(out, expeceted) 
开发者ID:chainer,项目名称:chainer,代码行数:18,代码来源:test_deformable_convolution_2d_sampler.py

示例4: propdown

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def propdown(self, hid):
        """ This function propagates the hidden units activation downwords to the visible units
        :param hid: Variable Matrix(batch_size, out_channels, image_height_out, image_width_out)  - given h_sample
        :return: Variable Matrix(batch_size, in_channels, image_height, image_width) - probability for each visible units to be v_j = 1
        """
        batch_size = hid.data.shape[0]
        if self.real == 0:
            W_flipped = F.swapaxes(CF.flip(self.conv.W, axes=(2, 3)), axis1=0, axis2=1)
            pre_sigmoid_activation = F.convolution_2d(hid, W_flipped, self.conv.a, pad=self.ksize-1)
                # F.matmul(hid, self.l.W) + F.broadcast_to(self.l.a, (batch_size, self.n_visible))
            v_mean = F.sigmoid(pre_sigmoid_activation)
            #print('W info ', self.conv.W.data.shape, 'W_flipped info ', W_flipped.data.shape)
            #print('W info ', self.conv.W.data[3, 0, 2, 3], 'W_flipped info ', W_flipped.data[0, 3, 8, 7])
            #print('W info ', self.conv.W.data[3, 0, 8, 7], 'W_flipped info ', W_flipped.data[0, 3, 2, 3])
            #print('W info ', self.conv.W.data[19, 0, 4, 0], 'W_flipped info ', W_flipped.data[0, 19, 6, 10])
            #print('pre_sigmoidactivation', F.sum(pre_sigmoid_activation).data)
            #print('v_mean', v_mean.data.shape)
            #print('v_mean sum', F.sum(v_mean).data)
            #print('hid', hid.data.shape)

        else:
            # TODO: check
            W_flipped = F.swapaxes(CF.flip(self.conv.W, axes=(2, 3)), axis1=0, axis2=1)
            v_mean = F.convolution_2d(hid, W_flipped, self.conv.a, pad=self.ksize-1)
        return v_mean 
开发者ID:corochann,项目名称:SeRanet,代码行数:27,代码来源:convolution_rbm.py

示例5: reconstruct

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def reconstruct(self, v):
        """

        :param v: Variable Matrix(batch_size, in_channels, image_height, image_width)
        :return: reconstructed_v, Variable Matrix(batch_size, in_channels, image_height, image_width)
        """
        batch_size = v.data.shape[0]
        xp = cuda.get_array_module(v.data)
        if self.real == 0:
            h = F.sigmoid(self.conv(v))
        else:
            std_ch = xp.reshape(self.std, (1, self.in_channels, 1, 1))
            h = F.sigmoid(self.conv(v / std_ch))
        # F.sigmoid(F.matmul(v, self.l.W, transb=True) + F.broadcast_to(self.l.b, (batch_size, self.n_hidden)))
        W_flipped = F.swapaxes(CF.flip(self.conv.W, axes=(2, 3)), axis1=0, axis2=1)
        reconstructed_v = F.sigmoid(F.convolution_2d(h, W_flipped, self.conv.a, pad=self.ksize-1))
            # = F.sigmoid(F.matmul(h, self.l.W) + F.broadcast_to(self.l.a, (batch_size, self.n_visible)))
        return reconstructed_v 
开发者ID:corochann,项目名称:SeRanet,代码行数:20,代码来源:convolution_rbm.py

示例6: gradient_loss

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def gradient_loss(generated, truth):
	"""

	:param generated: generated image by the generator at any scale
	:param truth: The ground truth image at that scale
	:return: GDL loss
	"""
	xp = cp.get_array_module(generated.data)
	n, c, h, w = generated.shape
	wx = xp.array([[[1, -1]]]*c, ndmin=4).astype(xp.float32)
	wy = xp.array([[[1], [-1]]]*c, ndmin=4).astype(xp.float32)

	d_gx = F.convolution_2d(generated, wx)
	d_gy = F.convolution_2d(generated, wy)

	d_tx = F.convolution_2d(truth, wx)
	d_ty = F.convolution_2d(truth, wy)

	return (F.sum(F.absolute(d_gx - d_tx)) + F.sum(F.absolute(d_gy - d_ty))) 
开发者ID:alokwhitewolf,项目名称:Video-frame-prediction-by-multi-scale-GAN,代码行数:21,代码来源:loss.py

示例7: blur

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def blur(h, w_k):
    b, ch, w_s, h_s = h.shape
    h = F.reshape(h, (b*ch, 1, w_s, h_s))
    h = F.convolution_2d(h, w_k, stride=1, pad=1)
    h = F.reshape(h, (b, ch, w_s, h_s))
    return h 
开发者ID:pfnet-research,项目名称:chainer-stylegan,代码行数:8,代码来源:rescale.py

示例8: tvh

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def tvh(self, x):
        return F.convolution_2d(x, W=self.Wh) 
开发者ID:mitmul,项目名称:ssai-cnn,代码行数:4,代码来源:invert.py

示例9: tvw

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def tvw(self, x):
        return F.convolution_2d(x, W=self.Ww) 
开发者ID:mitmul,项目名称:ssai-cnn,代码行数:4,代码来源:invert.py

示例10: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def forward(self, x):
        W_1bit = Binarize()(self.W) if self.binarized else self.W
        b_1bit = Binarize()(self.b) if self.b is not None and self.binarized else self.b
        return F.convolution_2d(
            x=x,
            W=W_1bit,
            b=b_1bit,
            stride=self.stride,
            pad=self.pad,
            dilate=self.dilate,
            groups=self.groups) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:13,代码来源:wrn1bit_cifar.py

示例11: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def forward(self, x):
        if self.W.array is None:
            self._initialize_params(x.shape[1])
        masked_weight = self.W * self.mask
        # print("self.W.sum()={}".format(self.W.array.sum()))
        # print("self.mask.sum()={}".format(self.mask.sum()))
        # print("masked_weight.sum()={}".format(masked_weight.array.sum()))
        return F.convolution_2d(
            x=x,
            W=masked_weight,
            b=self.b,
            stride=self.stride,
            pad=self.pad,
            dilate=self.dilate,
            groups=self.groups) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:17,代码来源:xdensenet.py

示例12: forward_expected

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def forward_expected(self, link, inputs):
        x, = inputs
        W = link.W
        b = link.b
        y = F.convolution_2d(
            x, W, b,
            pad=self.pad,
            stride=self.stride)
        return y.array, 
开发者ID:chainer,项目名称:chainer,代码行数:11,代码来源:test_convolution_2d.py

示例13: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def forward(self, inputs, device):
        if self.nobias:
            x, W = inputs
            b = None
        else:
            x, W, b = inputs
        out = F.convolution_2d(
            x, W, b, stride=self.stride, pad=self.pad,
            cover_all=self.cover_all, dilate=self.dilate,
            groups=self.groups)
        if self.old_numpy_fp16:
            return out*0,
        return out, 
开发者ID:chainer,项目名称:chainer,代码行数:15,代码来源:test_convolution_2d.py

示例14: _run_forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def _run_forward(self, x_data, W_data, b_data):
        x = chainer.Variable(x_data)
        W = chainer.Variable(W_data)
        b = None if self.nobias else chainer.Variable(b_data)
        y = F.convolution_2d(x, W, b, stride=self.stride, pad=self.pad,
                             cover_all=False, groups=self.groups)
        return x, W, b, y 
开发者ID:chainer,项目名称:chainer,代码行数:9,代码来源:test_convolution_2d.py

示例15: check_invalid_dilation

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import convolution_2d [as 别名]
def check_invalid_dilation(self, x_data, w_data):
        x = chainer.Variable(x_data)
        w = chainer.Variable(w_data)
        F.convolution_2d(x, w, dilate=self.dilate) 
开发者ID:chainer,项目名称:chainer,代码行数:6,代码来源:test_convolution_2d.py


注:本文中的chainer.functions.convolution_2d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。