def __init__(self,in_channels,out_channels,kernel_size,stride,padding):
   super(P4InitialConvResidualBlock,self).__init__()
   self.conv1 = P4ConvZ2(in_channels,out_channels,kernel_size=3,stride=1,padding=1)#same convolution   
   self.bn1 = nn.BatchNorm3d(out_channels)
   self.conv2 = P4ConvP4(out_channels,out_channels,kernel_size,stride,padding)
   self.bn2 = nn.BatchNorm3d(out_channels)
   self.bridgeconv = P4ConvZ2(in_channels,out_channels,kernel_size,stride,padding)
   self.bridgebn = nn.BatchNorm3d(out_channels)
 def __init__(self, in_channels, out_channels):
     super(InitialP4ResidualBlock, self).__init__()
     self.conv1 = P4ConvZ2(in_channels, out_channels, 3, 1, 1)
     self.bn1 = nn.BatchNorm3d(out_channels)
     self.conv2 = P4ConvP4(out_channels, out_channels, 3, 1, 1)
     self.bn2 = nn.BatchNorm3d(out_channels, out_channels)
     #self.shortcut = nn.Sequential()
     self.shortcut = nn.Sequential(P4ConvZ2(in_channels, out_channels, 1),
                                   nn.BatchNorm3d(out_channels))
 def __init__(self,in_channels,out_channels):
   super(InitialPreActResidualBlock,self).__init__()
   self.bn1 = nn.BatchNorm2d(in_channels)
   self.conv1 = P4ConvZ2(in_channels, out_channels, kernel_size=3, stride=2, padding=1, bias=False)
   self.bn2 = nn.BatchNorm3d(out_channels)
   self.conv2 = P4ConvP4(out_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=False)
   self.shortcut = nn.Sequential(
                                 P4ConvZ2(in_channels, out_channels, kernel_size=1, stride=2, bias=False)
                   )
Exemplo n.º 4
0
    def __init__(self, block_expansion, sn=False, shift_invariance=False, rot_invariance=False,
                 flip_invariance=False, **kwargs):
        super(DCDiscriminator, self).__init__()

        self.rot_invariance = rot_invariance
        self.flip_invariance = flip_invariance
        self.shift_invariance = shift_invariance
        self.sn = sn

        assert self.rot_invariance or not self.flip_invariance

        if self.shift_invariance and self.rot_invariance and self.flip_invariance:
            block_expansion //= int(8 ** 0.5)
            self.conv0 = P4MConvZ2(3, block_expansion, kernel_size=3)
            self.conv1 = P4MConvP4M(block_expansion, block_expansion * 2, kernel_size=3)
            self.conv2 = P4MConvP4M(block_expansion * 2, block_expansion * 4, kernel_size=3, dilation=2)
            self.conv3 = P4MConvP4M(block_expansion * 4, block_expansion * 8, kernel_size=3, dilation=4)
        elif self.shift_invariance and self.rot_invariance:
            block_expansion //= 2
            self.conv0 = P4ConvZ2(3, block_expansion, kernel_size=3)
            self.conv1 = P4ConvP4(block_expansion, block_expansion * 2, kernel_size=3)
            self.conv2 = P4ConvP4(block_expansion * 2, block_expansion * 4, kernel_size=3, dilation=2)
            self.conv3 = P4ConvP4(block_expansion * 4, block_expansion * 8, kernel_size=3, dilation=4)
        elif self.shift_invariance:
            self.conv0 = nn.Conv2d(3, block_expansion, kernel_size=3)
            self.conv1 = nn.Conv2d(block_expansion, block_expansion * 2, kernel_size=3)
            self.conv2 = nn.Conv2d(block_expansion * 2, block_expansion * 4, kernel_size=3, dilation=2)
            self.conv3 = nn.Conv2d(block_expansion * 4, block_expansion * 8, kernel_size=3, dilation=4)
        elif self.rot_invariance and self.flip_invariance:
            block_expansion //= int(8 ** 0.5)
            self.conv0 = P4MConvZ2(3, block_expansion, kernel_size=3)
            self.conv1 = P4MConvP4M(block_expansion, block_expansion * 2, kernel_size=3)
            self.conv2 = P4MConvP4M(block_expansion * 2, block_expansion * 4, kernel_size=3)
            self.conv3 = P4MConvP4M(block_expansion * 4, block_expansion * 8, kernel_size=3)
        elif self.rot_invariance:
            block_expansion //= 2
            self.conv0 = P4ConvZ2(3, block_expansion, kernel_size=3)
            self.conv1 = P4ConvP4(block_expansion, block_expansion * 2, kernel_size=3)
            self.conv2 = P4ConvP4(block_expansion * 2, block_expansion * 4, kernel_size=3)
            self.conv3 = P4ConvP4(block_expansion * 4, block_expansion * 8, kernel_size=3)
        else:
            self.conv0 = nn.Conv2d(3, block_expansion, kernel_size=3)
            self.conv1 = nn.Conv2d(block_expansion, block_expansion * 2, kernel_size=3)
            self.conv2 = nn.Conv2d(block_expansion * 2, block_expansion * 4, kernel_size=3)
            self.conv3 = nn.Conv2d(block_expansion * 4, block_expansion * 8, kernel_size=3)

        self.fc = nn.Linear(block_expansion * 8, 1)

        if self.sn:
            self.conv0 = nn.utils.spectral_norm(self.conv0)
            self.conv1 = nn.utils.spectral_norm(self.conv1)
            self.conv2 = nn.utils.spectral_norm(self.conv2)
            self.conv3 = nn.utils.spectral_norm(self.conv3)
            self.fc = nn.utils.spectral_norm(self.fc)
Exemplo n.º 5
0
    def __init__(self, block, num_blocks):
        super(ResNetPreCapsule, self).__init__()
        self.in_planes = 64

        self.conv1 = P4ConvZ2(3, 64, kernel_size=3, stride=1, padding=1, bias=False)#(b_size,64,32,32)
        self.bn1 = nn.BatchNorm3d(64)
        self.layer1 = self._make_layer(block, 64, num_blocks[0], stride=1)#(b_size,64,32,32)
        self.layer2 = self._make_layer(block, 128, num_blocks[1], stride=2)#(b_size,128,16,16)
 def __init__(self, in_planes=3, out_planes=32):
     super(P4BasicBlock, self).__init__()
     self.residue_conv1 = P4ConvP4(32, out_planes, kernel_size=3, stride=2, padding=1, bias=True)
     self.residue_bn1 = nn.BatchNorm3d(out_planes)
     self.residue_conv2 = P4ConvP4(out_planes, out_planes, kernel_size=3, stride=1, padding=1, bias=True)
     self.residue_bn2 = nn.BatchNorm3d(out_planes)
     self.shortcut = nn.Sequential(
             P4ConvP4(32, out_planes, kernel_size=1, stride=2, bias=True),
             nn.BatchNorm3d(out_planes)
         )
     self.conv1 = P4ConvZ2(in_planes,32,kernel_size=3,bias=True)
 def __init__(self):
     super(InitialP4Conv,self).__init__()
     self.conv = nn.Sequential(
                               P4ConvZ2(3,32,5),
                               nn.BatchNorm3d(32),
                               nn.SELU(),
                               P4ConvP4(32,32,5),
                               nn.BatchNorm3d(32),
                               nn.SELU(), 
                               P4ConvP4(32,32,3),
                               nn.BatchNorm3d(32),
                               nn.SELU()   
                              )
 def __init__(self, input_size, n_classes=10, **kwargs):
     super(AllConvNet1, self).__init__()
     self.conv1 = P4ConvZ2(input_size, 96, 3, padding=1)
     self.bn1 = nn.BatchNorm3d(96) 
     self.conv2 = P4ConvP4(96, 96, 3, padding=1)
     self.bn2 = nn.BatchNorm3d(96)
     self.conv3 = P4ConvP4(96, 96, 3, padding=1, stride=2)
     self.bn3 = nn.BatchNorm3d(96)
     self.conv4 = P4ConvP4(96, 192, 3, padding=1)
     self.bn4 = nn.BatchNorm3d(192)
     self.conv5 = P4ConvP4(192, 192, 3, padding=1)
     self.bn5 = nn.BatchNorm3d(192)
     self.conv6 = P4ConvP4(192, 192, 3, padding=1, stride=2)
     self.bn6 = nn.BatchNorm3d(192)
     self.conv7 = P4ConvP4(192, 192, 3, padding=1)
     self.bn7 = nn.BatchNorm3d(192)
     self.conv8 = P4ConvP4(192, 192, 1)
     self.bn8 = nn.BatchNorm3d(192)
     self.hidden_fc = nn.Linear(192*4*8*8,128)
     self.class_fc = nn.Linear(128, n_classes)