當前位置: 首頁>>代碼示例>>Python>>正文


Python nn.ConstantPad3d方法代碼示例

本文整理匯總了Python中torch.nn.ConstantPad3d方法的典型用法代碼示例。如果您正苦於以下問題:Python nn.ConstantPad3d方法的具體用法?Python nn.ConstantPad3d怎麽用?Python nn.ConstantPad3d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch.nn的用法示例。


在下文中一共展示了nn.ConstantPad3d方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _make_layer

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import ConstantPad3d [as 別名]
def _make_layer(self, layer_gates, block, planes, blocks, stride=1, conv_downsample=False):
        downsample = None
        outplanes = planes * block.expansion
        if stride != 1 or self.inplanes != outplanes:
            if conv_downsample:
                downsample = nn.Conv2d(self.inplanes, outplanes,
                                       kernel_size=1, stride=stride, bias=False)
            else:
                # Identity downsample uses strided average pooling + padding instead of convolution
                pad_amount = int(self.inplanes / 2)
                downsample = nn.Sequential(
                    nn.AvgPool2d(2),
                    nn.ConstantPad3d((0, 0, 0, 0, pad_amount, pad_amount), 0)
                )

        layers = []
        layers.append(block(layer_gates[0], self.inplanes, planes, stride, downsample, conv_downsample))
        self.inplanes = outplanes
        for i in range(1, blocks):
            layers.append(block(layer_gates[i], self.inplanes, planes))

        return nn.Sequential(*layers) 
開發者ID:cornell-zhang,項目名稱:dnn-quant-ocs,代碼行數:24,代碼來源:preresnet_cifar.py

示例2: get_pad_operation

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import ConstantPad3d [as 別名]
def get_pad_operation(self):
        if self.op in ['Conv2d']:
            lr = (self.dilation[1]) * (self.kernel_size[1] // 2)
            hw = (self.dilation[0]) * (self.kernel_size[0] // 2)
            self.pad_op = nn.ConstantPad2d((lr, lr, hw, hw), 0)
        if self.op in ['Conv3d']:
            lr = (self.dilation[2]) * (self.kernel_size[2] // 2)
            hw = (self.dilation[1]) * (self.kernel_size[1] // 2)
            fb = (self.dilation[0]) * (self.kernel_size[0] // 2)  # (front, back) => depth dimension
            self.pad_op = nn.ConstantPad3d((lr, lr, hw, hw, fb, fb), 0) 
開發者ID:DeepMotionAIResearch,項目名稱:DenseMatchingBenchmark,代碼行數:12,代碼來源:cspn.py

示例3: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import ConstantPad3d [as 別名]
def __init__(self, kernel_size, stride, return_indices=False, return_pad=False):
        super(PadMaxPool3d, self).__init__()
        self.kernel_size = kernel_size
        self.stride = stride
        self.pool = nn.MaxPool3d(kernel_size, stride, return_indices=return_indices)
        self.pad = nn.ConstantPad3d(padding=0, value=0)
        self.return_indices = return_indices
        self.return_pad = return_pad 
開發者ID:aramis-lab,項目名稱:AD-DL,代碼行數:10,代碼來源:modules.py


注:本文中的torch.nn.ConstantPad3d方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。