Python torch.nn.MaxUnpool2d() Examples

The following are 30 code examples of torch.nn.MaxUnpool2d(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module torch.nn , or try the search function .
Example #1
Source File: enet.py    From SegmenTron with Apache License 2.0 6 votes vote down vote up
def __init__(self, in_channels, inter_channels, out_channels, norm_layer=nn.BatchNorm2d, **kwargs):
        super(UpsamplingBottleneck, self).__init__()
        self.conv = nn.Sequential(
            nn.Conv2d(in_channels, out_channels, 1, bias=False),
            norm_layer(out_channels)
        )
        self.upsampling = nn.MaxUnpool2d(2)

        self.block = nn.Sequential(
            nn.Conv2d(in_channels, inter_channels, 1, bias=False),
            norm_layer(inter_channels),
            nn.PReLU(),
            nn.ConvTranspose2d(inter_channels, inter_channels, 2, 2, bias=False),
            norm_layer(inter_channels),
            nn.PReLU(),
            nn.Conv2d(inter_channels, out_channels, 1, bias=False),
            norm_layer(out_channels),
            nn.Dropout2d(0.1)
        )
        self.act = nn.PReLU() 
Example #2
Source File: enet.py    From awesome-semantic-segmentation-pytorch with Apache License 2.0 6 votes vote down vote up
def __init__(self, in_channels, inter_channels, out_channels, norm_layer=nn.BatchNorm2d, **kwargs):
        super(UpsamplingBottleneck, self).__init__()
        self.conv = nn.Sequential(
            nn.Conv2d(in_channels, out_channels, 1, bias=False),
            norm_layer(out_channels)
        )
        self.upsampling = nn.MaxUnpool2d(2)

        self.block = nn.Sequential(
            nn.Conv2d(in_channels, inter_channels, 1, bias=False),
            norm_layer(inter_channels),
            nn.PReLU(),
            nn.ConvTranspose2d(inter_channels, inter_channels, 2, 2, bias=False),
            norm_layer(inter_channels),
            nn.PReLU(),
            nn.Conv2d(inter_channels, out_channels, 1, bias=False),
            norm_layer(out_channels),
            nn.Dropout2d(0.1)
        )
        self.act = nn.PReLU() 
Example #3
Source File: enet.py    From Lane_Detection-An_Instance_Segmentation_Approach with MIT License 6 votes vote down vote up
def __init__(self, in_channels, inter_channels, out_channels, norm_layer=nn.BatchNorm2d, dropout=0.1, **kwargs):
        super(UpsamplingBottleneck, self).__init__()
        self.conv = nn.Sequential(
            nn.Conv2d(in_channels, out_channels, 1, bias=False),
            norm_layer(out_channels)
        )
        self.upsampling = nn.MaxUnpool2d(2)

        self.block = nn.Sequential(
            nn.Conv2d(in_channels, inter_channels, 1, bias=False),
            norm_layer(inter_channels),
            nn.PReLU(),
            nn.ConvTranspose2d(inter_channels, inter_channels, 2, 2, bias=False),
            norm_layer(inter_channels),
            nn.PReLU(),
            nn.Conv2d(inter_channels, out_channels, 1, bias=False),
            norm_layer(out_channels),
            nn.Dropout2d(dropout)
        )
        self.act = nn.PReLU() 
Example #4
Source File: blocks.py    From geoseg with MIT License 5 votes vote down vote up
def __init__(self, in_ch, out_ch, is_bn=False):
        super(SegNetUpx3, self).__init__()
        # upsampling and convolution block
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.block = UNetDownx3(in_ch, out_ch, is_bn) 
Example #5
Source File: utils.py    From PLARD with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp2, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #6
Source File: vgg16_deconv.py    From VisualizingCNN with MIT License 5 votes vote down vote up
def forward(self, x, layer, activation_idx, pool_locs):
        if layer in self.conv2deconv_indices:
            start_idx = self.conv2deconv_indices[layer]
        else:
            raise ValueError('layer is not a conv feature map')

        for idx in range(start_idx, len(self.features)):
            if isinstance(self.features[idx], nn.MaxUnpool2d):
                x = self.features[idx]\
                (x, pool_locs[self.unpool2pool_indices[idx]])
            else:
                x = self.features[idx](x)
        return x 
Example #7
Source File: utils.py    From CAG_UDA with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp2, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #8
Source File: utils.py    From CAG_UDA with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp3, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv3 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #9
Source File: utils.py    From pytorch-semseg with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp2, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #10
Source File: utils.py    From pytorch-semseg with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp3, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv3 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #11
Source File: enet.py    From scratchai with MIT License 5 votes vote down vote up
def mupool(ks:int=2, s:int=2, p:int=0):
    return nn.MaxUnpool2d(kernel_size=ks, stride=s, padding=p) 
Example #12
Source File: models.py    From 3DGNN_pytorch with MIT License 5 votes vote down vote up
def __init__(self, input_channels=None, output_channels=None, upsample=None, pooling_module=None):
        super().__init__()

        self.__dict__.update(locals())
        del self.self

        if output_channels != input_channels or upsample:
            self.conv = nn.Conv2d(
                input_channels, output_channels, 1,
                stride=1, padding=0, bias=False)
            self.batch_norm = nn.BatchNorm2d(output_channels, eps=1e-03)
            if upsample and pooling_module:
                self.unpool = nn.MaxUnpool2d(2, stride=2, padding=0) 
Example #13
Source File: blocks.py    From geoseg with MIT License 5 votes vote down vote up
def __init__(self, in_ch, out_ch, is_bn=False):
        super(SegNetUpx2, self).__init__()
        # upsampling and convolution block
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.block = UNetDownx2(in_ch, out_ch, is_bn) 
Example #14
Source File: models.py    From Deep-Image-Matting-PyTorch with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp1, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv = conv2DBatchNormRelu(in_size, out_size, k_size=5, stride=1, padding=2, with_relu=False) 
Example #15
Source File: unet_utils.py    From NeuralSceneDecomposition with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp2, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(out_size, out_size, 3, 1, 1) 
Example #16
Source File: unet_utils.py    From NeuralSceneDecomposition with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp3, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(out_size, out_size, 3, 1, 1)
        self.conv3 = conv2DBatchNormRelu(out_size, out_size, 3, 1, 1) 
Example #17
Source File: segnet.py    From netharn with Apache License 2.0 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(SegnetUp2, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = layers.ConvNorm2d(in_size, out_size, 3, 1, 1,
                                       norm='batch', noli='relu')
        self.conv2 = layers.ConvNorm2d(out_size, out_size, 3, 1, 1,
                                       norm='batch', noli='relu') 
Example #18
Source File: segnet.py    From netharn with Apache License 2.0 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(SegnetUp3, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = layers.ConvNorm2d(in_size, out_size, 3, 1, 1,
                                       norm='batch', noli='relu')
        self.conv2 = layers.ConvNorm2d(out_size, out_size, 3, 1, 1,
                                       norm='batch', noli='relu')
        self.conv3 = layers.ConvNorm2d(out_size, out_size, 3, 1, 1,
                                       norm='batch', noli='relu') 
Example #19
Source File: main.py    From HUAWEIOCR-2019 with MIT License 5 votes vote down vote up
def __init__(self, out_size):
        super(DenseNet121, self).__init__()
        self.inplanes = 1024
        self.densenet121 = densenet.densenet121(pretrained=False, small=args.small)
        num_ftrs = self.densenet121.classifier.in_features
        self.classifier_font = nn.Sequential(
            # 这里可以用fc做分类
            # nn.Linear(num_ftrs, out_size)
            # 这里可以用1×1卷积做分类
            nn.Conv2d(num_ftrs, out_size, kernel_size=1, bias=False)
        )
        self.train_params = []
        self.unpool = nn.MaxUnpool2d(kernel_size=2, stride=2)

    # 用于构建Resnet中的4个blocks 
Example #20
Source File: utils.py    From PLARD with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp3, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv3 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #21
Source File: unet_utils.py    From UnsupervisedGeometryAwareRepresentationLearning with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp2, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(out_size, out_size, 3, 1, 1) 
Example #22
Source File: unet_utils.py    From UnsupervisedGeometryAwareRepresentationLearning with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp3, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(out_size, out_size, 3, 1, 1)
        self.conv3 = conv2DBatchNormRelu(out_size, out_size, 3, 1, 1) 
Example #23
Source File: models.py    From Autoencoder with Apache License 2.0 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp3, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv3 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #24
Source File: models.py    From Autoencoder with Apache License 2.0 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp2, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #25
Source File: layers.py    From LiverCancerSeg with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp3, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv3 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #26
Source File: layers.py    From LiverCancerSeg with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp2, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1) 
Example #27
Source File: enet.py    From Pointnet2.ScanNet with MIT License 5 votes vote down vote up
def __init__(self, pooling):
        super(StatefulMaxUnpool2d, self).__init__()
        self.pooling = pooling
        self.unpooling = nn.MaxUnpool2d(pooling.kernel_size, pooling.stride, pooling.padding) 
Example #28
Source File: sub_module.py    From FastSurfer with Apache License 2.0 5 votes vote down vote up
def __init__(self, params, outblock=False):
        """
        Decoder Block initialization
        :param dict params: parameters like number of channels, stride etc.
        :param bool outblock: Flag, indicating if last block of network before classifier
                              is created. Default: False
        """
        super(CompetitiveDecoderBlock, self).__init__(params, outblock=outblock)
        self.unpool = nn.MaxUnpool2d(kernel_size=params['pool'], stride=params['stride_pool']) 
Example #29
Source File: segnet_utils.py    From MultiObjectiveOptimization with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp2Instance, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2D(in_size, out_size, 3, 1, 1) 
Example #30
Source File: segnet_utils.py    From MultiObjectiveOptimization with MIT License 5 votes vote down vote up
def __init__(self, in_size, out_size):
        super(segnetUp3, self).__init__()
        self.unpool = nn.MaxUnpool2d(2, 2)
        self.conv1 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv2 = conv2DBatchNormRelu(in_size, in_size, 3, 1, 1)
        self.conv3 = conv2DBatchNormRelu(in_size, out_size, 3, 1, 1)