def __init__(self, nclasses): super().__init__() self.features = [hyper.R_IN, 40, 40, nclasses] self.bandwidths = [hyper.BANDWIDTH_IN, 32, 32, hyper.BANDWIDTH_OUT] self.linear1 = nn.Linear(nclasses + hyper.N_CATS, 50) self.linear2 = nn.Linear(50, 50) sequence = [] # S2 layer grid = s2_equatorial_grid(max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) sequence.append(S2Convolution(self.features[0], self.features[1], self.bandwidths[0], self.bandwidths[1], grid)) # SO3 layers for l in range(1, len(self.features) - 1): nfeature_in = self.features[l] nfeature_out = self.features[l + 1] b_in = self.bandwidths[l] b_out = self.bandwidths[l + 1] sequence.append(nn.BatchNorm3d(nfeature_in, affine=True)) sequence.append(nn.ReLU()) grid = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=2 * b_in, n_beta=1, n_gamma=1) sequence.append(SO3Convolution(nfeature_in, nfeature_out, b_in, b_out, grid)) sequence.append(nn.BatchNorm3d(self.features[-1], affine=True)) sequence.append(nn.ReLU()) self.sequential = nn.Sequential(*sequence)
def __init__(self, features=None, bandwidths=None): super().__init__() if bandwidths is None: bandwidths = [24, 24] if features is None: features = [3, 100] self.features = features self.bandwidths = bandwidths # define the number of layers. self.num_layers = 1 assert len(self.bandwidths) == len(self.features) sequence = [] # S2 layer # =====================If we could chose another gridding method===================== grid = s2_equatorial_grid(max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) sequence.append( S2Convolution(self.features[0], int(self.features[1] / self.num_layers), self.bandwidths[0], self.bandwidths[1], grid)) sequence.append(nn.BatchNorm3d(self.features[-1], affine=True)) sequence.append(nn.ReLU()) self.sequential = nn.Sequential(*sequence) self.bn1 = nn.BatchNorm1d(self.features[-1])
def __init__(self, nclasses, bw_in): super().__init__() self.features = [1, 100, 100, nclasses] self.bandwidths = [bw_in, 16, 10] assert len(self.bandwidths) == len(self.features) - 1 sequence = [] # S2 layer grid = s2_equatorial_grid(max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) sequence.append(S2Convolution(self.features[0], self.features[1], self.bandwidths[0], self.bandwidths[1], grid)) # SO3 layers for l in range(1, len(self.features) - 2): nfeature_in = self.features[l] nfeature_out = self.features[l + 1] b_in = self.bandwidths[l] b_out = self.bandwidths[l + 1] sequence.append(nn.BatchNorm3d(nfeature_in, affine=True)) sequence.append(nn.ReLU()) grid = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=2 * b_in, n_beta=1, n_gamma=1) sequence.append(SO3Convolution(nfeature_in, nfeature_out, b_in, b_out, grid)) sequence.append(nn.BatchNorm3d(self.features[-2], affine=True)) sequence.append(nn.ReLU()) self.sequential = nn.Sequential(*sequence) # Output layer output_features = self.features[-2] self.out_layer = nn.Linear(output_features, self.features[-1])
def __init__(self, nclasses): super().__init__() self.features = [3, 128, nclasses] self.bandwidths = [24, 24] # define the number of layers. self.num_layers = 1 assert len(self.bandwidths) == len(self.features) - 1 sequence = [] # S2 layer # =====================If we could chose another gridding method===================== grid = s2_equatorial_grid(max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) sequence.append( S2Convolution(self.features[0], int(self.features[1] / self.num_layers), self.bandwidths[0], self.bandwidths[1], grid)) # sequence.append(S2Convolution(self.features[0], int(self.features[2] / self.num_layers), self.bandwidths[1], # self.bandwidths[2], grid)) # SO3 layers # for l in range(1, len(self.features) - 2): # nfeature_in = self.features[l] # nfeature_out = self.features[l + 1] # b_in = self.bandwidths[l] # b_out = self.bandwidths[l + 1] # # sequence.append(nn.BatchNorm3d(nfeature_in, affine=True)) # sequence.append(nn.ReLU())+ # grid = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=2 * b_in, n_beta=1, n_gamma=1) # sequence.append(SO3Convolution(nfeature_in, nfeature_out, b_in, b_out, grid)) sequence.append(nn.BatchNorm3d(self.features[-2], affine=True)) sequence.append(nn.ReLU()) self.sequential = nn.Sequential(*sequence) # Output layer output_features = self.features[-2] # self.out_layer = nn.Linear(2*output_features, self.features[-1]) #For ensemble learning self.out_layer_1 = nn.Linear(self.features[-2], self.features[-2]) self.out_layer = nn.Linear(self.features[-2], self.features[-1]) self.bn1 = nn.BatchNorm1d(self.features[-2]) self.bn2 = nn.BatchNorm1d(self.features[-2]) self.relu = nn.LeakyReLU() # self.point_net = PointNetEncoder(global_feat = False) self.point_net = get_model(combine_with_spherical_features=True) print("f**k")
def __init__(self, nclasses, cfg): super().__init__() self.features = [1, 50, 50, 50, 256, 128, nclasses] self.bandwidths = [cfg.bw, cfg.bw, cfg.bw, cfg.bw] sequence = [] # S2 layer grid = s2_equatorial_grid(max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) sequence.append( S2HConvolution(self.features[0], self.features[1], self.bandwidths[0], self.bandwidths[1], grid)) # SO3 layers for l in range(1, len(self.features) - 4): nfeature_in = self.features[l] nfeature_out = self.features[l + 1] b_in = self.bandwidths[l] b_out = self.bandwidths[l + 1] sequence.append(nn.BatchNorm3d(nfeature_in, affine=True)) sequence.append(nn.ReLU()) grid = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=2 * b_in, n_beta=1, n_gamma=1) sequence.append( SO3Convolution(nfeature_in, nfeature_out, b_in, b_out, grid)) sequence.append(nn.BatchNorm3d(self.features[3], affine=True)) sequence.append(nn.ReLU()) self.sequential = nn.Sequential(*sequence) fcs = [] # Output layer for i in range(3, len(self.features) - 1): ch_in = self.features[i] ch_out = self.features[i + 1] fcs.append(nn.Linear(ch_in, ch_out)) if i < len(self.features) - 2: fcs.append(nn.BatchNorm1d(ch_out)) fcs.append(nn.ReLU()) self.out_layer = nn.Sequential(*fcs)
def build_conv_block(self, b_dim, f_dim, norm_layer, activation, use_dropout, use_activation): conv_block = [] grid = s2_equatorial_grid(max_beta=0, n_alpha=3, n_beta=3) conv_block.append(S2Convolution(f_dim, f_dim, b_dim, b_dim, grid)) #grid = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=1, n_beta=1, n_gamma=1) #conv_block.append(SO3Convolution(f_dim, f_dim, b_dim, b_dim, grid)) conv_block += [norm_layer(f_dim)] if use_activation: conv_block += [activation] if use_dropout: conv_block += [nn.Dropout(0.5)] return nn.Sequential(*conv_block)
def __init__(self, out_channels=64, dropout_ratio=None): super().__init__() self.features = [3, 100, 100, out_channels] self.bandwidths = [init_bandwidth, 16, 10] assert len(self.bandwidths) == len(self.features) - 1 sequence = [] # S2 layer # =====================If we could chose another gridding method===================== grid = s2_equatorial_grid(max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) sequence.append(S2Convolution(self.features[0], self.features[1], self.bandwidths[0], self.bandwidths[1], grid)) # SO3 layers for l in range(1, len(self.features) - 2): nfeature_in = self.features[l] nfeature_out = self.features[l + 1] b_in = self.bandwidths[l] b_out = self.bandwidths[l + 1] sequence.append(nn.BatchNorm3d(nfeature_in, affine=True)) sequence.append(nn.ReLU()) grid = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=2 * b_in, n_beta=1, n_gamma=1) sequence.append(SO3Convolution(nfeature_in, nfeature_out, b_in, b_out, grid)) sequence.append(nn.BatchNorm3d(self.features[-2], affine=True)) sequence.append(nn.ReLU()) self.sequential = nn.Sequential(*sequence) # Output layer output_features = self.features[-2] self.out_layer = nn.Linear(output_features, self.features[-1]) self.bn = nn.BatchNorm1d(self.features[-1]) if dropout_ratio != 0: self.dropout = nn.Dropout(p=dropout_ratio) print("Spherical models use dropout.") else: self.dropout = None
def __init__(self, nclasses, cfg): super().__init__() self.features = [1, 40, 40, nclasses] self.bandwidths = [ cfg.bw, ] * len(self.features) self.linear1 = nn.Linear(nclasses + 16, 50) self.linear2 = nn.Linear(50, 50) sequence = [] # S2 layer grid = s2_equatorial_grid(max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) sequence.append( S2HConvolution(self.features[0], self.features[1], self.bandwidths[0], self.bandwidths[1], grid)) # SO3 layers for l in range(1, len(self.features) - 1): nfeature_in = self.features[l] nfeature_out = self.features[l + 1] b_in = self.bandwidths[l] b_out = self.bandwidths[l + 1] sequence.append(nn.BatchNorm3d(nfeature_in, affine=True)) sequence.append(nn.ReLU()) grid = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=2 * b_in, n_beta=1, n_gamma=1) sequence.append( SO3Convolution(nfeature_in, nfeature_out, b_in, b_out, grid)) sequence.append(nn.BatchNorm3d(self.features[-1], affine=True)) sequence.append(nn.ReLU()) sequence.append(GammaMean(2 * self.bandwidths[-1])) self.sequential = nn.Sequential(*sequence)
def __init__(self): super().__init__() self.features = [3, 25, 25, 25, 36] self.bandwidths = [32, 32, 32, 32, 32] # S2 layer grid = s2_equatorial_grid(max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) self.s2_conv = S2Convolution(self.features[0], self.features[1], self.bandwidths[0], self.bandwidths[1], grid) self.bn1 = nn.BatchNorm3d(self.features[1], affine=True) self.relu1 = nn.ReLU() # SO3 layers b_in = 32 b_out = 32 grid3 = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=2 * 32, n_beta=1, n_gamma=1) self.so3_layer1 = SO3Convolution(self.features[1], self.features[2], b_in, b_out, grid3) self.bn2 = nn.BatchNorm3d(self.features[1] + self.features[2], affine=True) self.relu2 = nn.ReLU() self.so3_layer2 = SO3Convolution(self.features[1] + self.features[2], self.features[3], b_in, b_out, grid3) self.bn3 = nn.BatchNorm3d(self.features[1] + self.features[2] + self.features[3], affine=True) self.relu3 = nn.ReLU() self.so3_layer3 = SO3Convolution( self.features[1] + self.features[2] + self.features[3], self.features[4], b_in, b_out, grid3) self.bn4 = nn.BatchNorm3d(self.features[4], affine=True) self.relu4 = nn.ReLU()
def __init__(self, bandwidths, features, use_equatorial_grid): super().__init__() self.bandwidths = bandwidths self.features = features assert len(self.bandwidths) == len(self.features) sequence = [] # S2 layer grid_s2 = s2_equatorial_grid( max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) if use_equatorial_grid else s2_near_identity_grid( max_beta=np.pi / 8, n_alpha=8, n_beta=3) sequence.append( S2Convolution(self.features[0], self.features[1], self.bandwidths[0], self.bandwidths[1], grid_s2)) sequence.append(nn.BatchNorm3d(self.features[-1], affine=True)) sequence.append(nn.ReLU()) self.sequential = nn.Sequential(*sequence)
Where Phi is a composition of a S^2 convolution and a SO(3) convolution For simplicity, R is a rotation around the Z axis. ''' #pylint: disable=C,R,E1101,W0621 import torch from s2cnn import s2_equatorial_grid, S2Convolution from s2cnn import so3_equatorial_grid, SO3Convolution device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") # Define the two convolutions s2_grid = s2_equatorial_grid(max_beta=0, n_alpha=64, n_beta=1) s2_conv = S2Convolution(nfeature_in=12, nfeature_out=15, b_in=64, b_out=32, grid=s2_grid) s2_conv.to(device) so3_grid = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=64, n_beta=1, n_gamma=1) so3_conv = SO3Convolution(nfeature_in=15, nfeature_out=21, b_in=32,
def __init__(self, params): super(S2ConvNet, self).__init__() grid_s2 = s2_equatorial_grid() if (params.so3grid): grid_so3 = so3_equatorial_grid() else: grid_so3 = so3_near_identity_grid() self.conv1 = S2Convolution(nfeature_in=34, nfeature_out=params.s2_1, b_in=13, b_out=10, grid=grid_s2) self.conv2 = SO3Convolution(nfeature_in=params.s2_1, nfeature_out=params.so3_2, b_in=10, b_out=8, grid=grid_so3) self.conv3 = SO3Convolution(nfeature_in=params.so3_2, nfeature_out=params.so3_3, b_in=8, b_out=5, grid=grid_so3) self.conv4 = SO3Convolution(nfeature_in=params.so3_3, nfeature_out=params.so3_4, b_in=5, b_out=3, grid=grid_so3) self.conv5 = SO3Convolution(nfeature_in=params.so3_4, nfeature_out=params.so3_5, b_in=3, b_out=2, grid=grid_so3) last_entry = params.so3_3 if (params.if_so3_4) and (params.if_so3_5): last_entry = params.so3_5 elif (params.if_so3_4): last_entry = params.so3_4 self.fc_layer = nn.Linear(last_entry, params.fc1) self.fc_layer_2 = nn.Linear(params.fc1, params.fc2) self.fc_layer_3 = nn.Linear(params.fc2, params.fc3) self.fc_layer_4 = nn.Linear(params.fc3, params.fc4) self.fc_layer_5 = nn.Linear(params.fc4, params.fc5) self.norm_layer_2d_1 = nn.BatchNorm2d(34) self.norm_1d_1 = nn.BatchNorm1d(params.fc1) self.norm_1d_2 = nn.BatchNorm1d(params.fc2) self.norm_1d_3 = nn.BatchNorm1d(params.fc3) self.norm_1d_4 = nn.BatchNorm1d(params.fc4) self.norm_1d_5 = nn.BatchNorm1d(params.fc5) self.norm_1d_6 = nn.BatchNorm1d(1) last_fc_entry = params.fc3 if params.if_fc_4 and params.if_fc_5: last_fc_entry = params.fc5 elif params.if_fc_4: last_fc_entry = params.fc4 #print(last_fc_entry, params.if_fc_4, params.if_fc_5, params.fc3,params.fc4,params.fc5, "Aoba=================") self.fc_layer_6 = nn.Linear(last_fc_entry, 1) self.do1 = nn.Dropout(params.do1r) self.do2 = nn.Dropout(params.do2r) self.do3 = nn.Dropout(params.do3r) self.do4 = nn.Dropout(params.do4r) self.do5 = nn.Dropout(params.do5r) self.if_so3_4 = params.if_so3_4 self.if_so3_5 = params.if_so3_5 self.if_fc_4 = params.if_fc_4 self.if_fc_5 = params.if_fc_5
def __init__(self, final_output_dim, sconv_dims, bandwidths #BANDWIDTH_IN, #BANDWIDTH_OUT, #R_IN=64, #sconv_intermed_dims ): super().__init__() self.per_point_dims = [32, 32] #self.features = [R_IN, 40, 40, dim_output] self.features = list(sconv_dims) self.bandwidths = bandwidths #[BANDWIDTH_IN, 32, 32, BANDWIDTH_OUT] #self.linear1 = nn.Linear(dim_output, 50) #self.linear2 = nn.Linear(50, 50) print('Building PRIN-based AE Encoder') print('\tFeatures:', self.features) print('\tInput Dim:', final_output_dim) print('\tBandwidths:', self.bandwidths) ### SConv module ### sequence = [] # S2 layer grid = s2_equatorial_grid(max_beta=0, n_alpha=2 * self.bandwidths[0], n_beta=1) sequence.append( S2Convolution(self.features[0], self.features[1], self.bandwidths[0], self.bandwidths[1], grid)) # SO3 layers for l in range(1, len(self.features) - 1): nfeature_in = self.features[l] nfeature_out = self.features[l + 1] b_in = self.bandwidths[l] b_out = self.bandwidths[l + 1] sequence.append(nn.BatchNorm3d(nfeature_in, affine=True)) sequence.append(nn.ReLU()) grid = so3_equatorial_grid(max_beta=0, max_gamma=0, n_alpha=2 * b_in, n_beta=1, n_gamma=1) sequence.append( SO3Convolution(nfeature_in, nfeature_out, b_in, b_out, grid)) # Final BN and non-linearity sequence.append(nn.BatchNorm3d(self.features[-1], affine=True)) sequence.append(nn.ReLU()) self.sequential = nn.Sequential(*sequence) # TODO maybe just operate on the voxel and pool that directly, without converting to a PC first? # Per-point processor self.per_point_processor = nn.Sequential( nn.Conv1d(self.features[-1], self.per_point_dims[0], 1, bias=False), nn.BatchNorm1d(self.per_point_dims[0]), nn.ReLU(False), nn.Conv1d(self.per_point_dims[0], self.per_point_dims[1], 1, bias=False), nn.BatchNorm1d(self.per_point_dims[1]), nn.ReLU(False)) # Final pooled processor self.pooled_processor_dims = [ 2 * self.per_point_dims[-1], final_output_dim, final_output_dim ] self.pooled_processor = nn.Sequential( nn.Linear(self.pooled_processor_dims[0], self.pooled_processor_dims[1]), nn.BatchNorm1d(self.pooled_processor_dims[1]), nn.ReLU(), nn.Linear(self.pooled_processor_dims[1], self.pooled_processor_dims[2]), ) #self.protlin = nn.Linear(2*self.features[-1], final_output_dim) self.protlin = nn.Sequential( nn.Linear(2 * self.features[-1], 2 * final_output_dim), nn.BatchNorm1d(2 * final_output_dim), nn.ReLU(), nn.Linear(final_output_dim * 2, final_output_dim))