def __init__(self,in_channels,out_channels,kernel_size,stride,padding):
   super(P4ResidualBlock,self).__init__()
   self.conv1 = P4ConvP4(in_channels,in_channels,kernel_size=3,stride=1,padding=1)#same convolution   
   self.bn1 = nn.BatchNorm3d(in_channels)
   self.conv2 = P4ConvP4(in_channels,out_channels,kernel_size,stride,padding)
   self.bn2 = nn.BatchNorm3d(out_channels)
   self.bridgeconv = P4ConvP4(in_channels,out_channels,kernel_size,stride,padding)
   self.bridgebn = nn.BatchNorm3d(out_channels)
 def __init__(self,num_out_capsules,in_capsule_dim,out_capsule_dim,stride=1):
     super(CapsuleP4ResidualBlock,self).__init__()
     self.conv1 = P4ConvP4(in_capsule_dim,out_capsule_dim,3,stride,1)
     self.bn1 = nn.BatchNorm3d(out_capsule_dim)
     self.conv2 = P4ConvP4(out_capsule_dim,num_out_capsules*out_capsule_dim,3,1,1)
     self.bn2 = nn.BatchNorm3d(num_out_capsules*out_capsule_dim)
     self.shortcut = nn.Sequential(
                                   P4ConvP4(in_capsule_dim,num_out_capsules*out_capsule_dim, kernel_size=1, stride=stride),
                                   nn.BatchNorm3d(num_out_capsules*out_capsule_dim)
                                  )
 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)
예제 #4
0
    def __init__(self, in_planes, planes, stride=1):
        super(BasicBlock, self).__init__()
        self.conv1 = P4ConvP4(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
        self.bn1 = nn.BatchNorm3d(planes)
        self.conv2 = P4ConvP4(planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
        self.bn2 = nn.BatchNorm3d(planes)

        self.shortcut = nn.Sequential()
        if stride != 1 or in_planes != self.expansion*planes:
            self.shortcut = nn.Sequential(
                P4ConvP4(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False),
                nn.BatchNorm3d(self.expansion*planes)
            )
 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,
              num_in_capsules,
              in_capsule_dim,
              num_out_capsules,
              out_capsule_dim,
              kernel_size=7,
              stride=1,
              padding=0,
              class_=False):
     super(ConvolutionalCapsules, self).__init__()
     self.num_in_capsules = num_in_capsules
     self.in_capsule_dim = in_capsule_dim
     self.num_out_capsules = num_out_capsules
     self.out_capsule_dim = out_capsule_dim
     self.kernel_size = kernel_size
     self.stride = stride
     self.padding = padding
     #self.projection_networks = nn.ModuleList([nn.Sequential(
     #                            P4ResidualBlock(in_capsule_dim,out_capsule_dim,kernel_size,stride,padding)) for i in range(num_out_capsules)
     #])
     #self.projection_network = nn.Sequential(P4ResidualBlock(in_capsule_dim,out_capsule_dim*num_out_capsules,kernel_size,stride,padding))
     #self.projection_network = nn.Sequential(P4ConvP4(in_capsule_dim,out_capsule_dim*num_out_capsules,kernel_size,stride,padding),
     #                                        nn.BatchNorm3d(out_capsule_dim*num_out_capsules))
     if class_ == False:
         self.projection_network = CapsuleP4ResidualBlock(
             num_out_capsules, in_capsule_dim, out_capsule_dim, stride)
     else:
         self.projection_network = nn.Sequential(
             P4ConvP4(in_capsule_dim, out_capsule_dim * num_out_capsules,
                      kernel_size, stride, padding))
예제 #7
0
 def __init__(self,in_caps,in_dim,out_caps,out_dim,kernel_size,stride,padding):
     super(ConvCapsule,self).__init__()
     self.in_caps = in_caps
     self.in_dim = in_dim
     self.out_caps = out_caps
     self.out_dim = out_dim
     self.preds = nn.Sequential(
                                P4ConvP4(in_dim,out_caps*out_dim,kernel_size=kernel_size,stride=stride,padding=padding),
                                nn.BatchNorm3d(out_caps*out_dim))
 def __init__(self,num_capsules=10,in_channels=32,out_channels=32):
   super(PrimaryCapsules, self).__init__()
   self.num_capsules = num_capsules
   self.out_channels = out_channels
   self.capsules = nn.Sequential(
                                 P4ConvP4(in_channels,out_channels*num_capsules,3),
                                 nn.BatchNorm3d(out_channels*num_capsules),
                                 nn.SELU(),
                                )   
 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)
                   )
예제 #11
0
 def __init__(self,in_channels,num_capsules,out_dim,H=16,W=16):
     super(PrimaryCapsules,self).__init__()
     self.in_channels = in_channels
     self.num_capsules = num_capsules
     self.out_dim = out_dim
     self.H = H
     self.W = W
     self.preds = nn.Sequential(
                                P4ConvP4(in_channels,num_capsules*out_dim,kernel_size=1),
                                nn.LayerNorm((num_capsules*out_dim,4,H,W)))
 def __init__(self,num_in_capsules,in_capsule_dim,num_out_capsules,out_capsule_dim,kernel_size,stride=1,padding=0):
   super(ConvolutionalCapsules,self).__init__()
   self.num_in_capsules = num_in_capsules
   self.in_capsule_dim = in_capsule_dim
   self.num_out_capsules = num_out_capsules
   self.out_capsule_dim = out_capsule_dim
   self.kernel_size = kernel_size
   self.stride = stride
   self.padding = padding
   self.projection_network = nn.Sequential(
                                           P4ConvP4(in_capsule_dim,out_capsule_dim*num_out_capsules,kernel_size,stride,padding),
                                           nn.BatchNorm3d(out_capsule_dim*num_out_capsules)
                                          )  
예제 #13
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)
 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)
 def __init__(self, num_capsules=10, in_channels=32, out_channels=32):
     super(PrimaryCapsules, self).__init__()
     self.num_capsules = num_capsules
     self.out_channels = out_channels
     '''self.capsules = nn.ModuleList([
       nn.Sequential(
                     nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=True),
                     nn.BatchNorm2d(out_channels),  
                     nn.SELU(),                         
                     nn.Conv2d(out_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=True),
                     nn.BatchNorm2d(out_channels), 
                     nn.SELU(),
                     nn.Conv2d(out_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=True),
                     nn.BatchNorm2d(out_channels),    
                     nn.SELU(),
        )
        for i in range(num_capsules)
     ])'''
     #self.capsules = nn.ModuleList([
     #                               nn.Sequential(
     #                                             P4ResidualBlock(in_channels,out_channels,3,1,1),
     #                                             P4ResidualBlock(out_channels,out_channels,3,1,1),
     #                                             P4ResidualBlock(out_channels,out_channels,3,1,1)
     #                               ) for i in range(num_capsules)])
     #self.capsules = nn.Sequential(
     #                              P4ConvP4(in_channels,out_channels*num_capsules,kernel_size=5),
     #                              nn.BatchNorm3d(out_channels*num_capsules),
     #                             )
     self.capsules = nn.Sequential(
         P4ConvP4(in_channels, out_channels, 3, 1, 1),
         nn.SELU(),
         nn.BatchNorm3d(out_channels),
         #P4ConvP4(out_channels,out_channels,3,1,1),
         #nn.SELU(),
         #nn.BatchNorm3d(out_channels),
         CapsuleP4ResidualBlock(num_capsules,
                                out_channels,
                                out_channels,
                                stride=1))