def __init__(self, n_classes): nn.Module.__init__(self) self.n_classes = n_classes self.sparseModel = scn.Sequential( # 255x255 scn.SubmanifoldConvolution( 2, 2, 16, 3, False), # dimension, nIn, nOut, filter_size, bias scn.MaxPooling(2, 3, 2), # dimension, pool_size, pool_stride # 127x127 scn.SparseResNet( 2, 16, [ # dimension, nInputPlanes, layers ['b', 16, 2, 1], # 63x63 # blockType, n, reps, stride ['b', 32, 2, 2], # 63x63 ['b', 48, 2, 2], # 31x31 ['b', 96, 2, 2], # 15x15 ['b', 144, 2, 2], # 7x7 ['b', 192, 2, 2] ]), # 3x3 scn.Convolution( 2, 192, 256, 3, 1, False ), # 1x1 # dimension, nIn, nOut, filter_size, filter_stride, bias scn.BatchNormReLU(256)) # dimension, nPlanes self.sparse_to_dense = scn.SparseToDense(2, 256) #self.spatial_size= self.sc.input_spatial_size(torch.LongTensor([1, 1])) self.spatial_size = self.sparseModel.input_spatial_size( torch.LongTensor([1, 1])) self.inputLayer = scn.InputLayer(2, self.spatial_size, 2) # dimension, spatial_size, mode self.linear = nn.Linear(256, self.n_classes) print(self.spatial_size)
def __init__(self, full_scale=127, use_normal=False): nn.Module.__init__(self) dimension = 3 m = 32 # 16 or 32 residual_blocks = True #True or False block_reps = 2 #Conv block repetition factor: 1 or 2 blocks = [['b', m * k, 2, 2] for k in [1, 2, 3, 4, 5]] self.num_final_channels = m * len(blocks) self.sparseModel = scn.Sequential().add( scn.InputLayer(dimension, full_scale, mode=4)).add( scn.SubmanifoldConvolution( dimension, 3 + 3 * int(use_normal), m, 3, False)).add(scn.MaxPooling(dimension, 3, 2)).add( scn.SparseResNet(dimension, m, blocks)).add( scn.BatchNormReLU(self.num_final_channels)).add( scn.SparseToDense(dimension, self.num_final_channels)) self.num_labels = 20 self.label_encoder = nn.Sequential(nn.Linear(self.num_labels, 64), nn.ReLU()) #self.pred = nn.Linear(m * len(blocks), 1) self.pred = nn.Sequential(nn.Linear(self.num_final_channels + 64, 64), nn.ReLU(), nn.Linear(64, 1)) return
def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential( scn.SubmanifoldConvolution( 3, 1, 64, 7, False), # sscn(dimension, nIn, nOut, filter_size, bias) scn.BatchNormReLU(64), scn.MaxPooling(3, 3, 2), # MaxPooling(dimension, pool_size, pool_stride) scn.SparseResNet( 3, 64, [ # SpraseResNet(dimension, nInputPlanes, layers=[]) ['b', 64, 2, 1], # [block_type, nOut, rep, stride] ['b', 64, 2, 1], ['b', 128, 2, 2], ['b', 128, 2, 2], ['b', 256, 2, 2], ['b', 256, 2, 2], ['b', 512, 2, 2], ['b', 512, 2, 2] ]), scn.SparseToDense(3, 256)) self.avgpool = nn.AdaptiveAvgPool3d((1, 1, 1)) # self.spatial_size= self.sparseModel.input_spatial_size(torch.LongTensor([1, 1])) self.spatial_size = torch.LongTensor([101, 101, 101]) self.inputLayer = scn.InputLayer(3, self.spatial_size, mode=3)
def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential( scn.SubmanifoldConvolution(2, 3, 16, 3, False), scn.BatchNormReLU(16), scn.SparseResNet( 2, 16, [['b', 16, 3, 1], ['b', 32, 3, 2], ['b', 64, 3, 2]]), scn.AveragePooling(2, 8, 8), scn.SparseToDense(2, 64)) self.spatial_size = self.sparseModel.input_spatial_size( torch.LongTensor([1, 1])) self.inputLayer = scn.InputLayer(2, self.spatial_size, 2) self.linear = nn.Linear(64, 10)
def __init__(self, num_classes=5): nn.Module.__init__(self) self.sparseModel = scn.Sequential().add(scn.DenseToSparse(2)).add( scn.ValidConvolution(2, 3, 8, 2, False)).add( scn.MaxPooling(2, 4, 2)).add( scn.SparseResNet(2, 8, [['b', 8, 3, 1], [ 'b', 16, 2, 2 ], ['b', 24, 2, 2], ['b', 32, 2, 2]])).add( scn.Convolution(2, 32, 64, 4, 1, False)).add(scn.BatchNormReLU(64)).add( scn.SparseToDense(2, 64)) self.linear = nn.Linear(6400, num_classes)
def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential().add( scn.SubmanifoldConvolution(2, 3, 8, 3, False)).add( scn.MaxPooling(2, 3, 2)).add( scn.SparseResNet(2, 8, [['b', 8, 2, 1], [ 'b', 16, 2, 2 ], ['b', 24, 2, 2], ['b', 32, 2, 2]])).add( scn.Convolution(2, 32, 64, 5, 1, False)).add(scn.BatchNormReLU(64)).add( scn.SparseToDense(2, 64)) self.linear = nn.Linear(64, 183)
def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential( scn.SubmanifoldConvolution(2, 3, 16, 3, False), scn.MaxPooling(2, 3, 2), scn.SparseResNet(2, 16, [['b', 16, 2, 1], ['b', 32, 2, 2], ['b', 48, 2, 2], ['b', 96, 2, 2]]), scn.Convolution(2, 96, 128, 3, 1, False), scn.BatchNormReLU(128), scn.SparseToDense(2, 128)) self.spatial_size = self.sparseModel.input_spatial_size( torch.LongTensor([1, 1])) self.inputLayer = scn.InputLayer(2, self.spatial_size, 2) self.linear = nn.Linear(128, 3755)
def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential().add( scn.InputLayer(dimension, (nvox, nvox, nvoxz), mode=3)).add( scn.SubmanifoldConvolution( dimension, nPlanes, 4, 3, False)).add(scn.MaxPooling(dimension, 3, 3)).add( scn.SparseResNet(dimension, 4, [[ 'b', 8, 2, 1 ], ['b', 16, 2, 1], ['b', 24, 2, 1]])).add( # ['b', 32, 2, 1]])).add( scn.Convolution( dimension, 24, 32, 5, 1, False)).add(scn.BatchNormReLU(32)).add( scn.SparseToDense(dimension, 32)) # self.spatial_size = self.sparseModel.input_spatial_size(torch.LongTensor([1, 1])) self.linear = nn.Linear(int(32 * 46 * 46 * 96), 32) self.linear2 = nn.Linear(32, global_Nclass)
def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential( scn.SubmanifoldConvolution(2, 1, 8, 3, False), scn.MaxPooling(2, 3, 2), scn.SparseResNet(2, 8, [['b', 8, 2, 1], ['b', 16, 2, 2], ['b', 24, 2, 2], ['b', 32, 2, 2]]), scn.Convolution(2, 32, 64, 5, 1, False), scn.BatchNormReLU(64), scn.SparseToDense(2, 64)) # self.spatial_size= self.sparseModel.input_spatial_size(torch.LongTensor([1, 1])) self.spatial_size = torch.LongTensor([28, 28]) self.inputLayer = scn.InputLayer(2, self.spatial_size, 2) self.linear = nn.Linear(64, 183) self.sscn1 = scn.SubmanifoldConvolution(2, 1, 32, 3, False) self.sscn2 = scn.SubmanifoldConvolution(2, 32, 64, 3, False) self.dropout1 = nn.Dropout2d(0.25) self.dropout2 = nn.Dropout2d(0.5) # self.fc1 = nn.Linear(9216, 128) self.fc1 = nn.Linear(12544, 128) self.fc2 = nn.Linear(128, 10)
def __init__(self, dimension=3, device='cuda'): nn.Module.__init__(self) self.sparseModel = scn.Sequential( scn.SubmanifoldConvolution(dimension, nIn=1, nOut=8, filter_size=3, bias=False), scn.MaxPooling(dimension, pool_size=3, pool_stride=2), scn.SparseResNet(dimension, 8, [['b', 8, 2, 1], ['b', 16, 2, 2], ['b', 24, 2, 2], ['b', 32, 2, 2]]), scn.Convolution(dimension, nIn=32, nOut=64, filter_size=5, filter_stride=1, bias=False), scn.BatchNormReLU(64), scn.SparseToDense(dimension, 64)).to(device) self.spatial_size = self.sparseModel.input_spatial_size( torch.LongTensor([1] * dimension)) self.inputLayer = scn.InputLayer(dimension, self.spatial_size, mode=4) self.linear = nn.Linear(64, 1).to(device)