Пример #1
0
 def forward(self, x): 
     x = x.unsqueeze(1)  # [batch, sigma, feature, y, x]
     x = x.repeat(1, self.nratio, 1, 1, 1)  # [batch, sigma, feature, y, x]
     
     x = F.relu(self.conv1(x))
     self.pool = ScalePool(self.ratio)
     x = F.relu(self.conv2(x))
     x = self.pool(x) 
     x = F.relu(self.conv3(x))
     self.pool = ScalePool(self.ratio)
     x = F.relu(self.fc1(x))
     x = self.fc2(x)
     return x
Пример #2
0
    def __init__(self, f_in, ratio, nratio, nb_classes=10):
        super().__init__()
        '''
        Basic scale equivariant architecture, replicating StdNet
        '''
        self.f_in = f_in
        self.ratio = ratio
        self.nratio = nratio
        self.nb_classes = nb_classes

        self.conv1 = ScaleConvolution(self.f_in,
                                      12,
                                      7,
                                      self.ratio,
                                      self.nratio,
                                      srange=0,
                                      boundary_condition="dirichlet",
                                      stride=2)
        self.conv2 = ScaleConvolution(12,
                                      21,
                                      5,
                                      self.ratio,
                                      self.nratio,
                                      srange=1,
                                      boundary_condition="dirichlet")
        self.pool = ScalePool(self.ratio)

        self.fc1 = nn.Linear(21, 150, bias=True)
        self.fc2 = nn.Linear(150, self.nb_classes, bias=True)
Пример #3
0
    def __init__(self, f_in, ratio, nratio, srange=1, nb_classes=10):
        super().__init__()
        '''
        Scale equivariant arch, based on architecture in Kanazawa's paper https://arxiv.org/abs/1412.5104
        selecting srange = 1 is equivalent to the paper
        '''
        self.f_in = f_in
        self.ratio = ratio
        self.nratio = nratio
        self.srange = srange
        self.nb_classes = nb_classes

        self.conv1 = ScaleConvolution(self.f_in,
                                      69,
                                      3,
                                      self.ratio,
                                      self.nratio,
                                      srange=0,
                                      boundary_condition="dirichlet",
                                      stride=2)
        self.conv2 = ScaleConvolution(69,
                                      122,
                                      3,
                                      self.ratio,
                                      self.nratio,
                                      srange=self.srange,
                                      boundary_condition="dirichlet")
        self.pool = ScalePool(self.ratio)

        self.fc1 = nn.Linear(122, 288, bias=True)
        self.fc2 = nn.Linear(288, self.nb_classes, bias=True)
Пример #4
0
    def __init__(self, ratio, nratio):
        super().__init__()

        self.ratio = ratio
        self.nratio = nratio

        self.conv1 = ScaleConvolution(7,
                                      3,
                                      12,
                                      self.ratio,
                                      self.nratio,
                                      srange=0,
                                      boundary_condition="dirichlet",
                                      stride=2)
        self.conv2 = ScaleConvolution(5,
                                      12,
                                      21,
                                      self.ratio,
                                      self.nratio,
                                      srange=1,
                                      boundary_condition="dirichlet")
        self.pool = ScalePool(self.ratio)

        self.fc1 = nn.Linear(21, 150, bias=True)
        self.fc2 = nn.Linear(150, 10, bias=True)
Пример #5
0
    def __init__(self,
                 f_in=1,
                 size=5,
                 ratio=2**(2 / 3),
                 nratio=3,
                 srange=2,
                 padding=0,
                 nb_classes=10):
        super().__init__()
        '''
        Scale equivariant arch with 3 convolutional layers
        '''
        self.f_in = f_in
        self.size = size
        self.ratio = ratio
        self.nratio = nratio
        self.srange = srange
        self.padding = padding
        self.nb_classes = nb_classes

        self.conv1 = ScaleConvolution(self.f_in,
                                      96,
                                      self.size,
                                      self.ratio,
                                      self.nratio,
                                      srange=0,
                                      boundary_condition="dirichlet",
                                      padding=self.padding,
                                      stride=2)
        self.conv2 = ScaleConvolution(96,
                                      96,
                                      self.size,
                                      self.ratio,
                                      self.nratio,
                                      srange=self.srange,
                                      boundary_condition="dirichlet",
                                      padding=self.padding)
        self.conv3 = ScaleConvolution(96,
                                      192,
                                      self.size,
                                      self.ratio,
                                      self.nratio,
                                      srange=self.srange,
                                      boundary_condition="dirichlet",
                                      padding=self.padding)
        self.pool = ScalePool(self.ratio)

        self.fc1 = nn.Linear(192, 150, bias=True)
        self.fc2 = nn.Linear(150, self.nb_classes, bias=True)
Пример #6
0
    def __init__(self,
                 f_in=1,
                 size=5,
                 ratio=2**(2 / 3),
                 nratio=3,
                 srange=2,
                 padding=0,
                 nb_classes=10,
                 factor=1):
        super().__init__()
        '''
        Scale equivariant arch with 3 convolutional layers
        '''
        self.f_in = f_in
        self.size = size
        self.ratio = ratio
        self.nratio = nratio
        self.srange = srange
        self.padding = padding
        self.nb_classes = nb_classes

        self.conv1 = ScaleConvolution(self.f_in,
                                      int(factor * 12),
                                      self.size,
                                      self.ratio,
                                      self.nratio,
                                      srange=0,
                                      boundary_condition="dirichlet",
                                      padding=self.padding,
                                      stride=2)
        self.conv2 = ScaleConvolution(int(factor * 12),
                                      int(factor * 21),
                                      self.size,
                                      self.ratio,
                                      self.nratio,
                                      srange=self.srange,
                                      boundary_condition="dirichlet",
                                      padding=self.padding)
        self.conv3 = ScaleConvolution(int(factor * 21),
                                      int(factor * 36),
                                      self.size,
                                      self.ratio,
                                      self.nratio,
                                      srange=self.srange,
                                      boundary_condition="dirichlet",
                                      padding=self.padding)
        self.conv4 = ScaleConvolution(int(factor * 36),
                                      int(factor * 36),
                                      self.size,
                                      self.ratio,
                                      self.nratio,
                                      srange=self.srange,
                                      boundary_condition="dirichlet",
                                      padding=self.padding)
        self.conv5 = ScaleConvolution(int(factor * 36),
                                      int(factor * 64),
                                      self.size,
                                      self.ratio,
                                      self.nratio,
                                      srange=self.srange,
                                      boundary_condition="dirichlet",
                                      padding=self.padding)
        self.conv6 = ScaleConvolution(int(factor * 64),
                                      int(factor * 64),
                                      self.size,
                                      self.ratio,
                                      self.nratio,
                                      srange=self.srange,
                                      boundary_condition="dirichlet",
                                      padding=self.padding)
        self.pool = ScalePool(self.ratio)

        self.fc = nn.Linear(int(factor * 64), self.nb_classes, bias=True)