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


Python functions.pad方法代码示例

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


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

示例1: infer_return

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def infer_return(self, x_type, ksize, stride, pad):
        pad = make_pair(pad)
        ksize = make_pair(ksize)
        stride = make_pair(stride)

        shape_0 = x_type.shape[0]
        shape_1 = x_type.shape[1]
        if self.cover_all:
            shape_2 = math.ceil((x_type.shape[2] + pad[0] * 2 - ksize[0]) / stride[0]) + 1
            shape_3 = math.ceil((x_type.shape[3] + pad[1] * 2 - ksize[1]) / stride[1]) + 1
        else:
            shape_2 = (x_type.shape[2] + pad[0] * 2 - ksize[0]) // stride[0] + 1
            shape_3 = (x_type.shape[3] + pad[1] * 2 - ksize[1]) // stride[1] + 1

        return TyChainerVariable(x_type.dtype,
                shape=(shape_0, shape_1, shape_2, shape_3)) 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:18,代码来源:chainer_functions.py

示例2: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def __call__(self, ty_args, ty_kwargs):
        x_type, pad_width_type, mode_type = ty_args

        assert isinstance(mode_type, TyString), \
                "chainer.functions.pad: mode_type should be string"
        self.check_type_forward(make_multiple_tc_variable(ty_args[:1], ('x',)))

        if lacks_value(pad_width_type):
            return TyChainerVariable(x_type.dtype, ndim=x_type.ndim)

        assert pad_width_type.size() > 0, \
                "chainer.functions.pad: pad_width is not specified"

        pad_width = extract_value_from_ty(pad_width_type)
        if isinstance(pad_width, int):
            pad_width = make_pair(pad_width)
        if isinstance(pad_width[0], int):
            pad_width = pad_width * x_type.ndim
        for pad in pad_width:
            assert len(pad) == 2, "chainer.functions.pad: pad_width is invalid"
        return self.infer_return(x_type, pad_width) 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:23,代码来源:chainer_functions.py

示例3: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def __init__(self,
                 in_channels,
                 out_channels,
                 stride,
                 preactivate):
        super(IRevUnit, self).__init__()
        if not preactivate:
            in_channels = in_channels // 2

        padding = 2 * (out_channels - in_channels)
        self.do_padding = (padding != 0) and (stride == 1)
        self.do_downscale = (stride != 1)

        with self.init_scope():
            if self.do_padding:
                self.pad = IRevInjectivePad(padding)
            self.bottleneck = IRevBottleneck(
                in_channels=in_channels,
                out_channels=out_channels,
                stride=stride,
                preactivate=preactivate)
            if self.do_downscale:
                self.psi = IRevDownscale(stride) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:25,代码来源:irevnet.py

示例4: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def __init__(self,
                 in_channels,
                 out_channels,
                 bn_eps,
                 activation,
                 tf_mode):
        super(EffiInitBlock, self).__init__()
        self.tf_mode = tf_mode

        with self.init_scope():
            self.conv = conv3x3_block(
                in_channels=in_channels,
                out_channels=out_channels,
                stride=2,
                pad=(0 if tf_mode else 1),
                bn_eps=bn_eps,
                activation=activation) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:19,代码来源:efficientnet.py

示例5: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def __init__(self,
                 in_channels,
                 out_channels,
                 stride,
                 binarized=False):
        super(PreResUnit1bit, self).__init__()
        self.resize_identity = (stride != 1)

        with self.init_scope():
            self.body = PreResBlock1bit(
                in_channels=in_channels,
                out_channels=out_channels,
                stride=stride,
                binarized=binarized)
            if self.resize_identity:
                self.identity_pool = partial(
                    F.average_pooling_2d,
                    ksize=3,
                    stride=2,
                    pad=1) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:22,代码来源:wrn1bit_cifar.py

示例6: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def __init__(self,
                 in_channels,
                 out_channels):
        super(PyrInitBlock, self).__init__()
        with self.init_scope():
            self.conv = L.Convolution2D(
                in_channels=in_channels,
                out_channels=out_channels,
                ksize=7,
                stride=2,
                pad=3,
                nobias=True)
            self.bn = L.BatchNormalization(
                size=out_channels,
                eps=1e-5)
            self.activ = F.relu
            self.pool = partial(
                F.max_pooling_2d,
                ksize=3,
                stride=2,
                pad=1,
                cover_all=False) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:24,代码来源:pyramidnet.py

示例7: process_with_padding

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def process_with_padding(x,
                         process=(lambda x: x),
                         pad_width=((0, 0), (0, 0), (1, 0), (1, 0))):
    """
    Auxiliary decorator for layer with NASNet specific extra padding.

    Parameters:
    ----------
    x : chainer.Variable or numpy.ndarray or cupy.ndarray
        Input tensor.
    process : function, default (lambda x: x)
        a decorated layer
    pad_width : tuple of tuple of int, default ((0, 0), (0, 0), (1, 0), (1, 0))
        Whether the layer uses a bias vector.

    Returns
    -------
    chainer.Variable or numpy.ndarray or cupy.ndarray
        Resulted tensor.
    """
    x = F.pad(x, pad_width=pad_width, mode="constant", constant_values=0)
    x = process(x)
    x = x[:, :, 1:, 1:]
    return x 
开发者ID:osmr,项目名称:imgclsmob,代码行数:26,代码来源:nasnet.py

示例8: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def __init__(self,
                 in_channels,
                 out_channels,
                 ksize,
                 stride,
                 pad,
                 groups):
        super(NasConv, self).__init__()
        with self.init_scope():
            self.activ = F.relu
            self.conv = L.Convolution2D(
                in_channels=in_channels,
                out_channels=out_channels,
                ksize=ksize,
                stride=stride,
                pad=pad,
                nobias=True,
                groups=groups)
            self.bn = nasnet_batch_norm(channels=out_channels) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:21,代码来源:nasnet.py

示例9: nas_conv1x1

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def nas_conv1x1(in_channels,
                out_channels):
    """
    1x1 version of the NASNet specific convolution block.

    Parameters:
    ----------
    in_channels : int
        Number of input channels.
    out_channels : int
        Number of output channels.
    """
    return NasConv(
        in_channels=in_channels,
        out_channels=out_channels,
        ksize=1,
        stride=1,
        pad=0,
        groups=1) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:21,代码来源:nasnet.py

示例10: dws_branch_k3_s1_p1

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def dws_branch_k3_s1_p1(in_channels,
                        out_channels,
                        extra_padding=False):
    """
    3x3/1/1 version of the NASNet specific depthwise separable convolution branch.

    Parameters:
    ----------
    in_channels : int
        Number of input channels.
    out_channels : int
        Number of output channels.
    extra_padding : bool, default False
        Whether to use extra padding.
    """
    return DwsBranch(
        in_channels=in_channels,
        out_channels=out_channels,
        ksize=3,
        stride=1,
        pad=1,
        extra_padding=extra_padding) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:24,代码来源:nasnet.py

示例11: dws_branch_k5_s1_p2

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def dws_branch_k5_s1_p2(in_channels,
                        out_channels,
                        extra_padding=False):
    """
    5x5/1/2 version of the NASNet specific depthwise separable convolution branch.

    Parameters:
    ----------
    in_channels : int
        Number of input channels.
    out_channels : int
        Number of output channels.
    extra_padding : bool, default False
        Whether to use extra padding.
    """
    return DwsBranch(
        in_channels=in_channels,
        out_channels=out_channels,
        ksize=5,
        stride=1,
        pad=2,
        extra_padding=extra_padding) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:24,代码来源:nasnet.py

示例12: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def forward(self, f, corr_feature, pos):
        p0 = F.pad(f[0], ((0, 0), (0, 0), (16, 16), (16, 16)), 'constant')
        p0 = p0[:, :, 4*pos[0]:4*pos[0]+61, 4*pos[1]:4*pos[1]+61]

        p1 = F.pad(f[1], ((0, 0), (0, 0), (8, 8), (8, 8)), 'constant')
        p1 = p1[:, :, 2*pos[0]:2*pos[0]+31, 2*pos[1]:2*pos[1]+31]

        p2 = F.pad(f[2], ((0, 0), (0, 0), (4, 4), (4, 4)), 'constant')
        p2 = p2[:, :, pos[0]:pos[0]+15, pos[1]:pos[1]+15]

        p3 = corr_feature[:, :, pos[0], pos[1]].reshape((-1, 256, 1, 1))

        out = self.deconv(p3)
        # NOTE: In the original Torch, resize_images uses 'nearest' interpolation
        out = self.h2(out) + self.v2(p2)
        out = self.post0(resize_images(
            out, (31, 31), align_corners=False, mode='nearest'))
        out = self.h1(out) + self.v1(p1)
        out = self.post1(
                resize_images(out, (61, 61), align_corners=False, mode='nearest'))
        out = self.h0(out) + self.v0(p0)
        out = self.post2(
                resize_images(out, (127, 127), align_corners=False, mode='nearest'))

        return out.reshape((-1, 127 ** 2)) 
开发者ID:chainer,项目名称:models,代码行数:27,代码来源:mask_refine.py

示例13: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def __call__(self, x):
        return F.pad(x, pad_width=((0, 0), (0, self.padding), (0, 0), (0, 0)), mode="constant", constant_values=0) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:4,代码来源:irevnet.py

示例14: inverse

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def inverse(self, x2, y1):
        if self.do_downscale:
            x2 = self.psi.inverse(x2)
        fx2 = - self.bottleneck(x2)
        x1 = fx2 + y1
        if self.do_downscale:
            x1 = self.psi.inverse(x1)
        if self.do_padding:
            x = F.concat((x1, x2), axis=1)
            x = self.pad.inverse(x)
            x1, x2 = F.split_axis(x, indices_or_sections=2, axis=1)
        return x1, x2 
开发者ID:osmr,项目名称:imgclsmob,代码行数:14,代码来源:irevnet.py

示例15: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import pad [as 别名]
def __call__(self, x):
        if self.residual:
            identity = x
        x = self.conv1(x)
        if self.tf_mode:
            x = F.pad(x, pad_width=calc_tf_padding(x, kernel_size=self.kernel_size, stride=self.stride),
                      mode="constant", constant_values=0)
        x = self.conv2(x)
        if self.use_se:
            x = self.se(x)
        x = self.conv3(x)
        if self.residual:
            x = x + identity
        return x 
开发者ID:osmr,项目名称:imgclsmob,代码行数:16,代码来源:efficientnet.py


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