How to use the torch.nn.BatchNorm2d function in torch

To help you get started, we’ve selected a few torch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AceCoooool / LEDNet / model / basic.py View on Github external
def basic_conv(in_channel, channel, kernel=3, stride=1):
    return nn.Sequential(
        nn.Conv2d(in_channel, channel, kernel, stride, kernel // 2, bias=False),
        nn.BatchNorm2d(channel), nn.ReLU(inplace=True)
    )
github AlexMa011 / pytorch-polygon-rnn / model.py View on Github external
)
        self.model3 = nn.Sequential(
            nn.Conv2d(256, 512, 3, 1, 1),
            nn.BatchNorm2d(512),
            nn.ReLU(),
            nn.Conv2d(512, 512, 3, 1, 1),
            nn.BatchNorm2d(512),
            nn.ReLU(),
            nn.Conv2d(512, 512, 3, 1, 1),
            nn.BatchNorm2d(512),
            nn.ReLU()
        )
        self.model4 = nn.Sequential(
            nn.MaxPool2d(2, 2),
            nn.Conv2d(512, 512, 3, 1, 1),
            nn.BatchNorm2d(512),
            nn.ReLU(),
            nn.Conv2d(512, 512, 3, 1, 1),
            nn.BatchNorm2d(512),
            nn.ReLU(),
            nn.Conv2d(512, 512, 3, 1, 1),
            nn.BatchNorm2d(512),
            nn.ReLU()
        )
        self.convlayer1 = basicconv(128, 128, 3, 1, 1)
        self.convlayer2 = basicconv(256, 128, 3, 1, 1)
        self.convlayer3 = basicconv(512, 128, 3, 1, 1)
        self.convlayer4 = basicconv(512, 128, 3, 1, 1)
        self.convlayer5 = basicconv(512, 128, 3, 1, 1)

        # self.convlayer1 = nn.Sequential(
        #     nn.Conv2d(128, 128, 3, 1, 1),
github heronsystems / adeptRL / src / models / attention.py View on Github external
self.normalize = normalize
        self.conv1 = Conv2d(nb_in_chan, 32, kernel_size=3, stride=2, padding=1)
        self.conv2 = Conv2d(32, 32, kernel_size=3, stride=2, padding=1)

        self.attention = MultiHeadSelfAttention(20 * 20, 34, 34, nb_head)
        self.mlp = Linear(34, 34)

        self.conv3 = Conv2d(34, 8, kernel_size=3, stride=2, padding=1)
        # BATCH x 8 x 10 x 10
        self.linear = Linear(800, 512)
        self.actor_linear = Linear(512, nb_action)
        self.critic_linear = Linear(512, 1)

        if normalize:
            self.bn1 = BatchNorm2d(32)
            self.bn2 = BatchNorm2d(32)
            self.bn3 = BatchNorm2d(8)
            self.bn_linear = BatchNorm1d(512)
        else:
            self.bn1 = Identity()
            self.bn2 = Identity()
            self.bn3 = Identity()
            self.bn_linear = Identity()
github donnyyou / torchcv / models / seg / nets / grsnet.py View on Github external
def __init__(self, in_channels, inter_channels, out_channels, stride=1):
        super(ContextResidualModule, self).__init__()
        self.stride = stride
        self.conv1 = nn.Conv2d(in_channels, inter_channels, (3, 3), stride=stride, padding=1, bias=False)
        self.bn1 = nn.BatchNorm2d(inter_channels)

        self.conv2_1 = nn.Conv2d(inter_channels, out_channels, (7, 1), stride=1, padding=(3, 0), bias=False)

        self.conv2_2 = nn.Conv2d(out_channels, out_channels, (1, 7), stride=1, padding=(0, 3), bias=False)

        self.bn2 = nn.BatchNorm2d(out_channels)
github karoly-hars / DE_resnet_unet_hyb / network.py View on Github external
def __init__(self, inplanes, planes, stride=1, downsample=None):
        super(Bottleneck, self).__init__()
        self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
        self.bn1 = nn.BatchNorm2d(planes)
        self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
        self.bn2 = nn.BatchNorm2d(planes)
        self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False)
        self.bn3 = nn.BatchNorm2d(planes * 4)
        self.relu = nn.ReLU(inplace=True)
        self.downsample = downsample
        self.stride = stride
github rwightman / pytorch-planet-amazon / models / wrn50_2.py View on Github external
nn.Conv2d(256, 256, (3, 3), (1, 1), (1, 1), 1, 1, bias=False),
                              nn.BatchNorm2d(256),
                              activation_fn,
                              nn.Conv2d(256, 512, (1, 1), (1, 1), (0, 0), 1, 1, bias=False),
                              nn.BatchNorm2d(512),
                          ),
                          Lambda(lambda x: x),  # Identity,
                          ),
                LambdaReduce(lambda x, y: x + y),  # CAddTable,
                activation_fn,
            ),
            nn.Sequential(  # Sequential,
                LambdaMap(lambda x: x,  # ConcatTable,
                          nn.Sequential(  # Sequential,
                              nn.Conv2d(512, 256, (1, 1), (1, 1), (0, 0), 1, 1, bias=False),
                              nn.BatchNorm2d(256),
                              activation_fn,
                              nn.Conv2d(256, 256, (3, 3), (1, 1), (1, 1), 1, 1, bias=False),
                              nn.BatchNorm2d(256),
                              activation_fn,
                              nn.Conv2d(256, 512, (1, 1), (1, 1), (0, 0), 1, 1, bias=False),
                              nn.BatchNorm2d(512),
                          ),
                          Lambda(lambda x: x),  # Identity,
                          ),
                LambdaReduce(lambda x, y: x + y),  # CAddTable,
                activation_fn,
            ),
            nn.Sequential(  # Sequential,
                LambdaMap(lambda x: x,  # ConcatTable,
                          nn.Sequential(  # Sequential,
                              nn.Conv2d(512, 256, (1, 1), (1, 1), (0, 0), 1, 1, bias=False),
github chrischute / pbt / models / resnet.py View on Github external
super(ResNet, self).__init__()
        self.conv1 = nn.Conv2d(3, layer_planes, kernel_size=3, stride=1, padding=1,
                               bias=False)
        self.bn1 = nn.BatchNorm2d(layer_planes)
        self.relu = nn.ReLU(inplace=True)
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
        self.layer1 = self._make_layer(block, 1*layer_planes, layer_blocks)
        self.layer2 = self._make_layer(block, 2*layer_planes, layer_blocks, stride=2)
        self.layer3 = self._make_layer(block, 4*layer_planes, layer_blocks, stride=2)
        self.avgpool = nn.AvgPool2d(8)
        self.fc = nn.Linear(64 * block.expansion, num_classes)

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
github kalviny / MSDNet-PyTorch / models / msdnet.py View on Github external
nInner = min(nInner, bnWidth * nOut)
            layer.append(nn.Conv2d(
                nIn, nInner, kernel_size=1, stride=1, padding=0, bias=False))
            layer.append(nn.BatchNorm2d(nInner))
            layer.append(nn.ReLU(True))

        if type == 'normal':
            layer.append(nn.Conv2d(nInner, nOut, kernel_size=3,
                                   stride=1, padding=1, bias=False))
        elif type == 'down':
            layer.append(nn.Conv2d(nInner, nOut, kernel_size=3,
                                   stride=2, padding=1, bias=False))
        else:
            raise ValueError

        layer.append(nn.BatchNorm2d(nOut))
        layer.append(nn.ReLU(True))

        self.net = nn.Sequential(*layer)
github google-research / augmix / third_party / ResNeXt_DenseNet / models / resnext.py View on Github external
dim * cardinality,
        kernel_size=3,
        stride=stride,
        padding=1,
        groups=cardinality,
        bias=False)
    self.bn = nn.BatchNorm2d(dim * cardinality)

    self.conv_expand = nn.Conv2d(
        dim * cardinality,
        planes * 4,
        kernel_size=1,
        stride=1,
        padding=0,
        bias=False)
    self.bn_expand = nn.BatchNorm2d(planes * 4)

    self.downsample = downsample