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


Python nn.UpsamplingNearest2d方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self, in_num, neck_size, growth_rate, layer_num, max_link):
        super(_CU_Net, self).__init__()
        self.down_blocks = []
        self.up_blocks = []
        self.num_blocks = 4
        print('creating hg ...')
        for i in range(0, self.num_blocks):
            print('creating down block %d ...' % i)
            self.down_blocks.append(_DenseBlock(in_num=in_num, neck_size=neck_size,
                                      growth_rate=growth_rate, layer_num=layer_num,
                                      max_link=max_link, requires_skip=True))
            print('creating up block %d ...' % i)
            self.up_blocks.append(_DenseBlock(in_num=in_num*2, neck_size=neck_size,
                                      growth_rate=growth_rate, layer_num=layer_num,
                                      max_link=max_link, requires_skip=False, is_up=True))
        self.down_blocks = nn.ModuleList(self.down_blocks)
        self.up_blocks = nn.ModuleList(self.up_blocks)
        print('creating neck block ...')
        self.neck_block = _DenseBlock(in_num=in_num, neck_size=neck_size,
                                     growth_rate=growth_rate, layer_num=layer_num,
                                     max_link=max_link, requires_skip=False)
        self.maxpool = nn.MaxPool2d(kernel_size=2, stride=2)
        self.upsample = nn.UpsamplingNearest2d(scale_factor=2) 
開發者ID:zhiqiangdon,項目名稱:CU-Net,代碼行數:25,代碼來源:cu_net_prev_version.py

示例2: _make_layer

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def _make_layer(self, block, planes, blocks, stride=1):
        if blocks == 0:
            return nn.Sequential(nn.Identity())
        norm_layer = self._norm_layer
        upsample = None
        if stride != 1:
            upsample = nn.Sequential(
                nn.UpsamplingNearest2d(scale_factor=2),
                SpectralNorm(conv1x1(self.inplanes, planes * block.expansion)),
                norm_layer(planes * block.expansion),
            )
        elif self.inplanes != planes * block.expansion:
            upsample = nn.Sequential(
                SpectralNorm(conv1x1(self.inplanes, planes * block.expansion)),
                norm_layer(planes * block.expansion),
            )

        layers = [block(self.inplanes, planes, stride, upsample, norm_layer, self.large_kernel)]
        self.inplanes = planes * block.expansion
        for _ in range(1, blocks):
            layers.append(block(self.inplanes, planes, norm_layer=norm_layer, large_kernel=self.large_kernel))

        return nn.Sequential(*layers) 
開發者ID:Yaoyi-Li,項目名稱:GCA-Matting,代碼行數:25,代碼來源:resnet_dec.py

示例3: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self):
		super(Channels1, self).__init__()
		self.list = nn.ModuleList()
		self.list.append(
			nn.Sequential(
				inception(256,[[64],[3,32,64],[5,32,64],[7,32,64]]),
				inception(256,[[64],[3,32,64],[5,32,64],[7,32,64]])
				)
			) #EE
		self.list.append(
			nn.Sequential(
				nn.AvgPool2d(2),
				inception(256,[[64],[3,32,64],[5,32,64],[7,32,64]]),
				inception(256,[[64],[3,32,64],[5,32,64],[7,32,64]]),
				inception(256,[[64],[3,32,64],[5,32,64],[7,32,64]]), 
				nn.UpsamplingNearest2d(scale_factor=2)
				)
			) #EEE 
開發者ID:princeton-vl,項目名稱:YouTube3D,代碼行數:20,代碼來源:HourglassNetwork.py

示例4: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self,d):
        super(decoder2,self).__init__()
        # decoder
        self.reflecPad5 = nn.ReflectionPad2d((1,1,1,1))
        self.conv5 = nn.Conv2d(128,64,3,1,0)
        self.conv5.weight = torch.nn.Parameter(d.get(1).weight.float())
        self.conv5.bias = torch.nn.Parameter(d.get(1).bias.float())
        self.relu5 = nn.ReLU(inplace=True)
        # 112 x 112

        self.unpool = nn.UpsamplingNearest2d(scale_factor=2)
        # 224 x 224

        self.reflecPad6 = nn.ReflectionPad2d((1,1,1,1))
        self.conv6 = nn.Conv2d(64,64,3,1,0)
        self.conv6.weight = torch.nn.Parameter(d.get(5).weight.float())
        self.conv6.bias = torch.nn.Parameter(d.get(5).bias.float())
        self.relu6 = nn.ReLU(inplace=True)
        # 224 x 224

        self.reflecPad7 = nn.ReflectionPad2d((1,1,1,1))
        self.conv7 = nn.Conv2d(64,3,3,1,0)
        self.conv7.weight = torch.nn.Parameter(d.get(8).weight.float())
        self.conv7.bias = torch.nn.Parameter(d.get(8).bias.float()) 
開發者ID:sunshineatnoon,項目名稱:PytorchWCT,代碼行數:26,代碼來源:modelsNIPS.py

示例5: forward

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def forward(self, embedding):
        def act(x):
            return F.relu(x, inplace=True)
        def up(x):
            m = nn.UpsamplingNearest2d(scale_factor=2)
            return m(x)
        x_ae = embedding # Bx256
        x_ae = act(self.ae_fc1_bn(self.ae_fc1(x_ae))) # 128x3x5
        x_ae = x_ae.view(-1, 128, 3, 5)
        x_ae = up(x_ae) # 6x10
        x_ae = act(self.ae_c1_bn(self.ae_c1(x_ae))) # 6x10
        x_ae = up(x_ae) # 12x20
        x_ae = act(self.ae_c2_bn(self.ae_c2(x_ae))) # 12x20 -> 10x20
        x_ae = F.pad(x_ae, (0, 0, 1, 0)) # 11x20
        x_ae = up(x_ae) # 22x40
        x_ae = act(self.ae_c3_bn(self.ae_c3(x_ae))) # 22x40
        x_ae = up(x_ae) # 44x80
        x_ae = F.pad(x_ae, (0, 0, 1, 0)) # add 1px at top (from 44 to 45)
        x_ae = F.sigmoid(self.ae_c4(x_ae))
        return x_ae 
開發者ID:aleju,項目名稱:self-driving-truck,代碼行數:22,代碼來源:models.py

示例6: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self, n, nModules, nFeats):
    super(Hourglass, self).__init__()
    self.n = n
    self.nModules = nModules
    self.nFeats = nFeats
    
    _up1_, _low1_, _low2_, _low3_ = [], [], [], []
    for j in range(self.nModules):
      _up1_.append(Residual(self.nFeats, self.nFeats))
    self.low1 = nn.MaxPool2d(kernel_size = 2, stride = 2)
    for j in range(self.nModules):
      _low1_.append(Residual(self.nFeats, self.nFeats))
    
    if self.n > 1:
      self.low2 = Hourglass(n - 1, self.nModules, self.nFeats)
    else:
      for j in range(self.nModules):
        _low2_.append(Residual(self.nFeats, self.nFeats))
      self.low2_ = nn.ModuleList(_low2_)
    
    for j in range(self.nModules):
      _low3_.append(Residual(self.nFeats, self.nFeats))
    
    self.up1_ = nn.ModuleList(_up1_)
    self.low1_ = nn.ModuleList(_low1_)
    self.low3_ = nn.ModuleList(_low3_)
    
    #self.up2 = nn.Upsample(scale_factor = 2)
    self.up2 = nn.UpsamplingNearest2d(scale_factor = 2) 
開發者ID:xingyizhou,項目名稱:StarMap,代碼行數:31,代碼來源:hg.py

示例7: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self, n, f, bn=None, increase=128):
        super(Hourglass, self).__init__()
        nf = f + increase
        self.up1 = Conv(f, f, 3, bn=bn)
        # Lower branch
        self.pool1 = Pool(2, 2)
        self.low1 = Conv(f, nf, 3, bn=bn)
        # Recursive hourglass
        if n > 1:
            self.low2 = Hourglass(n-1, nf, bn=bn)
        else:
            self.low2 = Conv(nf, nf, 3, bn=bn)
        self.low3 = Conv(nf, f, 3)
        self.up2  = nn.UpsamplingNearest2d(scale_factor=2) 
開發者ID:princeton-vl,項目名稱:pose-ae-train,代碼行數:16,代碼來源:layers.py

示例8: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self, in_num, out_num):
        super(_Bn_Relu_Conv1x1, self).__init__()
        self.add_module('norm', nn.BatchNorm2d(in_num))
        self.add_module('relu', nn.ReLU(inplace=True))
        self.add_module('conv', nn.Conv2d(in_num, out_num, kernel_size=1,
                                          stride=1, bias=False))

# class _TransitionDown(nn.Module):
#     def __init__(self, in_num_list, out_num, num_units):
#         super(_TransitionDown, self).__init__()
#         self.adapters = []
#         for i in range(0, num_units):
#             self.adapters.append(_Bn_Relu_Conv1x1(in_num=in_num_list[i], out_num=out_num))
#         self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
#
#     def forward(self, x, i):
#         x = self.adapters[i](x)
#         out = self.pool(x)
#         return out
#
# class _TransitionUp(nn.Module):
#     def __init__(self, in_num_list, out_num_list, num_units):
#         super(_TransitionUp, self).__init__()
#         self.adapters = []
#         for i in range(0, num_units):
#             self.adapters.append(_Bn_Relu_Conv1x1(in_num=in_num_list[i], out_num=out_num_list[i]))
#         self.upsample = nn.UpsamplingNearest2d(scale_factor=2)
#
#     def forward(self, x, i):
#         x = self.adapters[i](x)
#         out = self.upsample(x)
#         return out 
開發者ID:zhiqiangdon,項目名稱:CU-Net,代碼行數:34,代碼來源:cu_net.py

示例9: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self, inp=10, out=16, kernel_size=3, bias=True):
        super(TestUpsampleNearest2d, self).__init__()
        self.conv2d = nn.Conv2d(inp, out, kernel_size=kernel_size, bias=bias)
        self.up = nn.UpsamplingNearest2d(scale_factor=2) 
開發者ID:nerox8664,項目名稱:pytorch2keras,代碼行數:6,代碼來源:upsample_nearest.py

示例10: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self, scale_factor=2):
        super(LayerTest, self).__init__()
        self.up = nn.UpsamplingNearest2d(scale_factor=scale_factor) 
開發者ID:nerox8664,項目名稱:pytorch2keras,代碼行數:5,代碼來源:upsampling_nearest.py

示例11: VggBNBone

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def VggBNBone(arch, in_ch=3, leak=0, block=tnn.Conv2dBNReLU, debug=False):
    """
    Construct a VGG net

    How to specify a VGG architecture:

    It's a list of blocks specifications. Blocks are either:

    - 'M' for maxpool of kernel size 2 and stride 2
    - 'A' for average pool of kernel size 2 and stride 2
    - 'U' for nearest neighbors upsampling (scale factor 2)
    - an integer `ch` for a block with `ch` output channels

    Args:
        arch (list): architecture specification
        in_ch (int): number of input channels
        leak (float): leak in relus
        block (fn): block ctor

    Returns:
        A VGG instance
    """
    layers = []

    if debug:
        layers.append(tnn.Debug('Input'))

    for i, layer in enumerate(arch):
        if layer == 'M':
            layers.append(nn.MaxPool2d(2, 2))
        elif layer == 'A':
            layers.append(nn.AvgPool2d(2, 2))
        elif layer == 'U':
            layers.append(nn.UpsamplingNearest2d(scale_factor=2))
        else:
            layers.append(block(in_ch, layer, ks=3, leak=leak))
            in_ch = layer
        if debug:
            layer_name = 'layer_{}_{}'.format(layers[-1].__class__.__name__, i)
            layers.append(tnn.Debug(layer_name))
    return tnn.CondSeq(*layers) 
開發者ID:Vermeille,項目名稱:Torchelie,代碼行數:43,代碼來源:vgg.py

示例12: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self, in_ch, out_ch, inner=None):
        super(UBlock, self).__init__()
        self.in_conv = nn.Sequential(
            OrderedDict([
                ('pad1', nn.ReflectionPad2d(1)),
                ('conv1', tu.kaiming(nn.Conv2d(in_ch, out_ch, 3))),
                ('relu1', nn.ReLU(inplace=True)),
                ('pad2', nn.ReflectionPad2d(1)),
                ('conv2', tu.kaiming(nn.Conv2d(out_ch, out_ch, 3))),
                ('relu2', nn.ReLU(inplace=True)),
            ]))

        self.inner = inner
        if inner is not None:
            self.inner = nn.Sequential(
                    nn.MaxPool2d(2, 2),
                    inner,
                    nn.UpsamplingNearest2d(scale_factor=2),
                    nn.ReflectionPad2d(1),
                    tu.kaiming(nn.Conv2d(out_ch, out_ch, 3)),
                )
            self.skip = nn.Sequential(
                    tu.kaiming(nn.Conv2d(out_ch, out_ch, 1)))

        inner_ch = out_ch * (1 if inner is None else 2)
        self.out_conv = nn.Sequential(
            OrderedDict([
                ('pad1', nn.ReflectionPad2d(1)),
                ('conv1', tu.kaiming(nn.Conv2d(inner_ch, out_ch, 3))),
                ('relu1', nn.ReLU(inplace=True)),
                ('pad2', nn.ReflectionPad2d(1)),
                ('conv2', tu.kaiming(nn.Conv2d(out_ch, in_ch, 3))),
                ('relu2', nn.ReLU(inplace=True)),
            ])) 
開發者ID:Vermeille,項目名稱:Torchelie,代碼行數:36,代碼來源:unet.py

示例13: upsample_prediction

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def upsample_prediction(self, prediction, image_height, image_width):

        #assert len(prediction.size()) == 4   # n, c, h, w  

        #return nn.UpsamplingNearest2d((image_height, image_width))(prediction)
        resizer = ImageUtilities.image_resizer(image_height, image_width, interpolation=Image.NEAREST)
        return resizer(prediction) 
開發者ID:Wizaron,項目名稱:reseg-pytorch,代碼行數:9,代碼來源:prediction.py

示例14: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self, block, num_blocks, planes, depth):
        super(Hourglass, self).__init__()
        self.depth = depth
        self.block = block
        self.upsample = nn.UpsamplingNearest2d(scale_factor=2)
        self.hg = self._make_hour_glass(block, num_blocks, planes, depth) 
開發者ID:krematas,項目名稱:soccerontable,代碼行數:8,代碼來源:hourglass.py

示例15: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import UpsamplingNearest2d [as 別名]
def __init__(self):
        super(decoder3,self).__init__()
        # decoder
        self.reflecPad7 = nn.ReflectionPad2d((1,1,1,1))
        self.conv7 = nn.Conv2d(256,128,3,1,0)
        self.relu7 = nn.ReLU(inplace=True)
        # 56 x 56

        self.unpool = nn.UpsamplingNearest2d(scale_factor=2)
        # 112 x 112

        self.reflecPad8 = nn.ReflectionPad2d((1,1,1,1))
        self.conv8 = nn.Conv2d(128,128,3,1,0)
        self.relu8 = nn.ReLU(inplace=True)
        # 112 x 112

        self.reflecPad9 = nn.ReflectionPad2d((1,1,1,1))
        self.conv9 = nn.Conv2d(128,64,3,1,0)
        self.relu9 = nn.ReLU(inplace=True)

        self.unpool2 = nn.UpsamplingNearest2d(scale_factor=2)
        # 224 x 224

        self.reflecPad10 = nn.ReflectionPad2d((1,1,1,1))
        self.conv10 = nn.Conv2d(64,64,3,1,0)
        self.relu10 = nn.ReLU(inplace=True)

        self.reflecPad11 = nn.ReflectionPad2d((1,1,1,1))
        self.conv11 = nn.Conv2d(64,3,3,1,0) 
開發者ID:sunshineatnoon,項目名稱:LinearStyleTransfer,代碼行數:31,代碼來源:models.py


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