def v(depth, nPlanes): m = scn.Sequential() if depth == 1: for _ in range(reps): res(m, nPlanes, nPlanes, dropout_p) else: m = scn.Sequential() for _ in range(reps): res(m, nPlanes, nPlanes, dropout_p) if dropout_width: m.add(scn.ConcatTable().add(scn.Identity()).add( scn.Sequential().add(scn.BatchNormReLU(nPlanes)).add( #In place of Maxpooling scn.Convolution( dimension, nPlanes, nPlanes, 2, 2, False)).add(scn.Dropout(dropout_p)).add( v(depth - 1, nPlanes)).add( scn.BatchNormReLU(nPlanes)).add( scn.Deconvolution( dimension, nPlanes, nPlanes, 2, 2, False)))) else: m.add(scn.ConcatTable().add(scn.Identity()).add( scn.Sequential().add(scn.BatchNormReLU(nPlanes)).add( scn.Convolution(dimension, nPlanes, nPlanes, 2, 2, False)).add(v(depth - 1, nPlanes)).add( scn.BatchNormReLU(nPlanes)).add( scn.Deconvolution( dimension, nPlanes, nPlanes, 2, 2, False)))) m.add(scn.JoinTable()) for i in range(reps): res(m, 2 * nPlanes if i == 0 else nPlanes, nPlanes, dropout_p) return m
def __init__(self, output_shape, use_norm=True, num_input_features=128, num_filters_down1=[64], num_filters_down2=[64, 64], name='SparseMiddleExtractor'): super(SparseMiddleExtractor, self).__init__() self.name = name if use_norm: BatchNorm1d = change_default_args( eps=1e-3, momentum=0.01)(nn.BatchNorm1d) Linear = change_default_args(bias=False)(nn.Linear) else: BatchNorm1d = Empty Linear = change_default_args(bias=True)(nn.Linear) sparse_shape = np.array(output_shape[1:4]) + [1, 0, 0] # sparse_shape[0] = 11 print(sparse_shape) self.scn_input = scn.InputLayer(3, sparse_shape.tolist()) self.voxel_output_shape = output_shape middle_layers = [] num_filters = [num_input_features] + num_filters_down1 # num_filters = [64] + num_filters_down1 filters_pairs_d1 = [[num_filters[i], num_filters[i + 1]] for i in range(len(num_filters) - 1)] for i, o in filters_pairs_d1: middle_layers.append(scn.SubmanifoldConvolution(3, i, o, 3, False)) middle_layers.append(scn.BatchNormReLU(o, eps=1e-3, momentum=0.99)) middle_layers.append( scn.Convolution( 3, num_filters[-1], num_filters[-1], (3, 1, 1), (2, 1, 1), bias=False)) middle_layers.append( scn.BatchNormReLU(num_filters[-1], eps=1e-3, momentum=0.99)) # assert len(num_filters_down2) > 0 if len(num_filters_down1) == 0: num_filters = [num_filters[-1]] + num_filters_down2 else: num_filters = [num_filters_down1[-1]] + num_filters_down2 filters_pairs_d2 = [[num_filters[i], num_filters[i + 1]] for i in range(len(num_filters) - 1)] for i, o in filters_pairs_d2: middle_layers.append(scn.SubmanifoldConvolution(3, i, o, 3, False)) middle_layers.append(scn.BatchNormReLU(o, eps=1e-3, momentum=0.99)) middle_layers.append( scn.Convolution( 3, num_filters[-1], num_filters[-1], (3, 1, 1), (2, 1, 1), bias=False)) middle_layers.append( scn.BatchNormReLU(num_filters[-1], eps=1e-3, momentum=0.99)) middle_layers.append(scn.SparseToDense(3, num_filters[-1])) self.middle_conv = Sequential(*middle_layers)
def U(nPlanes, n_input_planes=-1): #Recursive function m = scn.Sequential() for i in range(reps): block(m, n_input_planes if n_input_planes != -1 else nPlanes[0], nPlanes[0]) n_input_planes = -1 if len(nPlanes) > 1: m.add(scn.ConcatTable().add(scn.Identity()).add( scn.Sequential().add( scn.BatchNormLeakyReLU( nPlanes[0], leakiness=leakiness)).add( scn.Convolution(dimension, nPlanes[0], nPlanes[1], downsample[0], downsample[1], False)).add(U(nPlanes[1:])).add( scn.BatchNormLeakyReLU( nPlanes[1], leakiness=leakiness)).add( scn.Deconvolution( dimension, nPlanes[1], nPlanes[0], downsample[0], downsample[1], False)))) m.add(scn.JoinTable()) for i in range(reps): block(m, nPlanes[0] * (2 if i == 0 else 1), nPlanes[0]) return m
def block(self, nPlanes, n, reps, stride): m = scn.Sequential() for rep in range(reps): if rep == 0: m.add(scn.BatchNormReLU(nPlanes)) m.add(scn.ConcatTable().add(self.residual( nPlanes, n, stride)).add(scn.Sequential().add( scn.SubmanifoldConvolution(self.dimension, nPlanes, n, 3, False) if stride == 1 else scn.Convolution( self.dimension, nPlanes, n, 2, stride, False)).add( scn.BatchNormReLU(n)).add( scn.SubmanifoldConvolution( self.dimension, n, n, 3, False)))) else: m.add(scn.ConcatTable().add(scn.Sequential().add( scn.BatchNormReLU(nPlanes)).add( scn.SubmanifoldConvolution( self.dimension, nPlanes, n, 3, False)).add(scn.BatchNormReLU(n)).add( scn.SubmanifoldConvolution( self.dimension, n, n, 3, False))).add(scn.Identity())) m.add(scn.AddTable()) nPlanes = n return m
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, flags): torch.nn.Module.__init__(self) import sparseconvnet as scn self._flags = flags dimension = self._flags.DATA_DIM num_class = self._flags.NUM_CLASS image_size = self._flags.SPATIAL_SIZE num_filter = self._flags.BASE_NUM_FILTERS assert image_size == 128 net = scn.Sequential() net.add(scn.InputLayer(dimension, image_size, mode=3)) net.add(scn.SubmanifoldConvolution(dimension, 1, num_filter, 3, False)) net.add(scn.MaxPooling(dimension, 2, 2)) net.add( SparseResNet(dimension, num_filter, [[num_filter * 1, 2, 1], [num_filter * 2, 2, 2], [num_filter * 4, 2, 2], [num_filter * 8, 2, 2]])) net.add( scn.Convolution(dimension, num_filter * 8, num_filter * 16, 3, 1, False)) net.add(scn.BatchNormReLU(num_filter * 16)) net.add(scn.SparseToDense(dimension, num_filter * 16)) net.add(torch.nn.AvgPool3d(6)) self._net = net self.linear = torch.nn.Linear(num_filter * 16, num_class)
def make_encoder_layer(self, ninputchs, noutputchs, nreps, leakiness=0.01, downsample=[2, 2]): """ inputs ------ ninputchs [int]: number of features going into layer noutputchs [int]: number of features output by layer nreps [int]: number of times residual modules repeated leakiness [int]: leakiness of LeakyReLU layers downsample [length 2 list of int]: stride in [height,width] dims outputs ------- scn.Sequential module with resnet and downsamping layers """ encode_blocks = create_resnet_layer(nreps, ninputchs, noutputchs, downsample=downsample) if downsample is not None: # if we specify downsize factor for each dimension, we apply # it to the output of the residual layers encode_blocks.add( scn.BatchNormLeakyReLU(noutputchs, leakiness=leakiness)) encode_blocks.add( scn.Convolution(self.dimension, noutputchs, noutputchs, downsample[0], downsample[1], False)) return encode_blocks
def __init__(self, nf_in, nf, input_sparsetensor, return_sparsetensor, max_data_size): nn.Module.__init__(self) data_dim = 3 self.nf_in = nf_in self.nf = nf self.input_sparsetensor = input_sparsetensor self.return_sparsetensor = return_sparsetensor self.max_data_size = max_data_size if not self.input_sparsetensor: self.p0 = scn.InputLayer(data_dim, self.max_data_size, mode=0) self.p1 = scn.SubmanifoldConvolution(data_dim, nf_in, nf, filter_size=FSIZE0, bias=False) self.p2 = scn.Sequential() self.p2.add(scn.ConcatTable().add(scn.Identity()).add( scn.Sequential().add(scn.BatchNormReLU(nf)).add( scn.SubmanifoldConvolution( data_dim, nf, nf, FSIZE0, False)).add(scn.BatchNormReLU(nf)).add( scn.SubmanifoldConvolution(data_dim, nf, nf, FSIZE0, False)))).add( scn.AddTable()) self.p2.add(scn.BatchNormReLU(nf)) # downsample space by factor of 2 self.p3 = scn.Sequential().add( scn.Convolution(data_dim, nf, nf, FSIZE1, 2, False)) self.p3.add(scn.BatchNormReLU(nf)) if not self.return_sparsetensor: self.p4 = scn.SparseToDense(data_dim, nf)
def __init__(self, cfg, name='yresnet_encoder'): super(YResNetEncoder, self).__init__(cfg, name='network_base') self.model_config = cfg[name] # YResNet Configurations # Conv block repetition factor self.reps = self.model_config.get('reps', 2) self.kernel_size = self.model_config.get('kernel_size', 2) self.num_strides = self.model_config.get('num_strides', 5) self.num_filters = self.model_config.get('filters', 16) self.nPlanes = [ i * self.num_filters for i in range(1, self.num_strides + 1) ] # [filter size, filter stride] self.downsample = [self.kernel_size, 2] dropout_prob = self.model_config.get('dropout_prob', 0.5) # Define Sparse YResNet Encoder self.encoding_block = scn.Sequential() self.encoding_conv = scn.Sequential() for i in range(self.num_strides): m = scn.Sequential() for _ in range(self.reps): self._resnet_block(m, self.nPlanes[i], self.nPlanes[i]) self.encoding_block.add(m) m = scn.Sequential() if i < self.num_strides - 1: m.add( scn.BatchNormLeakyReLU(self.nPlanes[i], leakiness=self.leakiness)).add( scn.Convolution(self.dimension, self.nPlanes[i], self.nPlanes[i+1], \ self.downsample[0], self.downsample[1], self.allow_bias)).add( scn.Dropout(p=dropout_prob)) self.encoding_conv.add(m)
def __init__(self, nr_classes): super(FBSparseVGGTest, self).__init__() self.sparseModel = scn.SparseVggNet( 2, nInputPlanes=2, layers=[['C', 16], ['C', 16], 'MP', ['C', 32], ['C', 32], 'MP', ['C', 64], ['C', 64], 'MP', ['C', 128], ['C', 128], 'MP', ['C', 256], ['C', 256], 'MP', ['C', 512]]).add( scn.Convolution(2, 512, 256, 3, filter_stride=2, bias=False)).add( scn.BatchNormReLU(256)).add( scn.SparseToDense(2, 256)) cnn_spatial_output_size = [2, 3] self.spatial_size = self.sparseModel.input_spatial_size( torch.LongTensor(cnn_spatial_output_size)) self.inputLayer = scn.InputLayer(dimension=2, spatial_size=self.spatial_size, mode=2) self.linear_input_features = cnn_spatial_output_size[ 0] * cnn_spatial_output_size[1] * 256 self.linear = nn.Linear(self.linear_input_features, nr_classes)
def residual(nIn, nOut, stride): if stride > 1: return scn.Convolution(dimension, nIn, nOut, 3, stride, False) elif nIn != nOut: return scn.NetworkInNetwork(nIn, nOut, False) else: return scn.Identity()
def __init__(self, *, inplanes, params): nn.Module.__init__(self) # The deepest block applies convolutions that act on all three planes together # First we apply a convolution to map all three planes into 1 plane (of the same spatial size) self.merger = scn.Convolution(dimension=3, nIn=inplanes, nOut=params.bottleneck_deepest, filter_size=[3, 1, 1], filter_stride=[1, 1, 1], bias=params.use_bias) self.blocks = SparseBlockSeries(inplanes=params.bottleneck_deepest, n_blocks=params.blocks_deepest_layer, n_planes=1, params=params) self.splitter = scn.Deconvolution(dimension=3, nIn=params.bottleneck_deepest, nOut=inplanes, filter_size=[3, 1, 1], filter_stride=[1, 1, 1], bias=params.use_bias)
def __init__(self, dimension, reps, n_layers, leakiness=0, input_layer=None, name='encoder', device=None): super(Encoder, self).__init__() self.dimension = dimension self.reps = reps self.n_layers = n_layers self.leakiness = leakiness self.name = name self.device = device if input_layer != None: self.input_layer = scn.InputLayer(len(input_layer), input_layer) self.blocks = [] self.block_names = {} n_in, n_out = 1, 1 for i in range(len(n_layers)): block = scn.Sequential() # add reps Resnet blocks, where reps >= 1 and first block just ensures number of # input channels is correct for rep in range(reps): block.add( resnet_block(dimension, n_in, n_out, 1, leakiness, computation='submanifoldconvolution')) n_in = n_out n_out = n_layers[i][1] ''' block.add( scn.BatchNormLeakyReLU(n_in, leakiness) ) ''' block.add(scn.LeakyReLU(leakiness)) if len(n_layers[i]) == 2: block.add(scn.Convolution(dimension, n_in, n_out, 2, 2, False)) elif len(n_layers[i] ) == 3 and n_layers[i][2] == 'submanifoldconvolution': block.add( scn.SubmanifoldConvolution(dimension, n_in, n_out, 2, False)) elif len(n_layers[i]) == 3 and n_layers[i][2] == 'maxpool': block.add(scn.MaxPooling(dimension, 2, 2)) elif len(n_layers[i]) == 3 and n_layers[i][2] == 'avgpool': block.add(scn.AveragePooling(dimension, 2, 2)) block_name = get_block_name(name, dimension, reps, n_in, n_out, leakiness) n_in = n_out self.blocks.append(block) self.block_names[block_name] = len(self.blocks) - 1 self.blocks = torch.nn.ModuleList(self.blocks)
def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.SparseVggNet( 2, 3, [['C', 16], ['C', 16], 'MP', ['C', 32], ['C', 32], 'MP', ['C', 48], ['C', 48], 'MP', ['C', 64], ['C', 64], 'MP', ['C', 96], ['C', 96] ]).add(scn.Convolution(2, 96, 128, 3, 2, False)).add( scn.BatchNormReLU(128)).add(scn.SparseToDense(2, 128)) self.linear = nn.Linear(128, 3755)
def __init__(self, inplanes, kernel, stride, bias=False, dim=3): torch.nn.Module.__init__(self) outplanes = 2 * inplanes #f1 self.bnr1 = scn.BatchNormReLU(inplanes) self.conv1 = scn.Convolution(dim, inplanes, outplanes, kernel, stride, bias) self.bnr2 = scn.BatchNormReLU(outplanes) self.subconv = scn.SubmanifoldConvolution(dim, outplanes, outplanes, kernel, bias) #f2 self.conv2 = scn.Convolution(dim, inplanes, outplanes, kernel, stride, bias) self.add = scn.AddTable()
def iter_unet(self, n_input_planes): # different from scn implementation, which is a recursive function enc_convs = scn.Sequential() dec_convs = scn.Sequential() for n_planes_in, n_planes_out in zip(self.n_planes[:-1], self.n_planes[1:]): # encode conv1x1 = scn.Sequential() for i in range(self.block_reps): conv1x1.add( self.block( n_input_planes if n_input_planes != -1 else n_planes_in, n_planes_in)) n_input_planes = -1 conv = scn.Sequential() conv.add( scn.BatchNormLeakyReLU(n_planes_in, leakiness=self.leakiness)) conv.add( scn.Convolution(self.dimension, n_planes_in, n_planes_out, self.downsample[0], self.downsample[1], False)) enc_conv = scn.Sequential() enc_conv.add(conv1x1) enc_conv.add(conv) enc_convs.add(enc_conv) # decode(corresponding stage of encode; symmetric with U) b_join = scn.Sequential() # before_join b_join.add( scn.BatchNormLeakyReLU(n_planes_out, leakiness=self.leakiness)) b_join.add( scn.Deconvolution(self.dimension, n_planes_out, n_planes_in, self.downsample[0], self.downsample[1], False)) join_table = scn.JoinTable() a_join = scn.Sequential() # after_join for i in range(self.block_reps): a_join.add( self.block(n_planes_in * (2 if i == 0 else 1), n_planes_in)) dec_conv = scn.Sequential() dec_conv.add(b_join) dec_conv.add(join_table) dec_conv.add(a_join) dec_convs.add(dec_conv) middle_conv = scn.Sequential() for i in range(self.block_reps): middle_conv.add( self.block( n_input_planes if n_input_planes != -1 else self.n_planes[-1], self.n_planes[-1])) n_input_planes = -1 return enc_convs, middle_conv, dec_convs
def __init__(self): super(Model, self).__init__() self.inputLayer = scn.InputLayer(dimension, spatial_size=512, mode=3) self.initialconv = scn.SubmanifoldConvolution(dimension, nPlanes, 64, 7, False) self.residual = scn.Identity() self.add = scn.AddTable() self.sparsebl11 = scn.Sequential().add( scn.SubmanifoldConvolution(dimension, 64, 64, 3, False)).add( scn.BatchNormLeakyReLU(64)).add( scn.SubmanifoldConvolution(dimension, 64, 64, 3, False)) self.sparsebl12 = scn.Sequential().add( scn.SubmanifoldConvolution(dimension, 64, 64, 3, False)).add( scn.BatchNormLeakyReLU(64)).add( scn.SubmanifoldConvolution(dimension, 64, 64, 3, False)) self.sparsebl21 = scn.Sequential().add( scn.SubmanifoldConvolution(dimension, 128, 128, 3, False)).add( scn.BatchNormLeakyReLU(128)).add( scn.SubmanifoldConvolution(dimension, 128, 128, 3, False)) self.sparsebl22 = scn.Sequential().add( scn.SubmanifoldConvolution(dimension, 128, 128, 3, False)).add( scn.BatchNormLeakyReLU(128)).add( scn.SubmanifoldConvolution(dimension, 128, 128, 3, False)) self.relu1 = scn.LeakyReLU(64) self.relu2 = scn.LeakyReLU(128) self.downsample1 = scn.Sequential().add( scn.Convolution(dimension, 64, 64, [2, 2, 2], [2, 2, 2], False)).add(scn.BatchNormLeakyReLU(64)) self.downsample2 = scn.Sequential().add( scn.Convolution(dimension, 64, 128, [2, 2, 2], [2, 2, 2], False)).add(scn.BatchNormLeakyReLU(128)) self.downsample3 = scn.Sequential().add( scn.Convolution(dimension, 128, 64, [4, 4, 4], [4, 4, 4], False)).add(scn.BatchNormLeakyReLU(64)) self.downsample4 = scn.Sequential().add( scn.Convolution(dimension, 64, 2, [4, 4, 4], [4, 4, 4], False)).add(scn.BatchNormLeakyReLU(2)) self.sparsetodense = scn.SparseToDense(dimension, 2) self.dropout1 = nn.Dropout(0.5) self.dropout2 = nn.Dropout(0.5) self.linear2 = nn.Linear(2 * 8 * 8 * 8, 2) self.linear3 = nn.Linear(2, 1)
def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.SparseVggNet(2, 3, [ ['C', 8, ], ['C', 8], 'MP', ['C', 16], ['C', 16], 'MP', ['C', 16 + 8], ['C', 16 + 8], 'MP', ['C', 24 + 8], ['C', 24 + 8], 'MP'] ).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): super(CNN, self).__init__() ############################### # Hardcoded settings ############################### self._dimension = 3 reps = 2 kernel_size = 2 num_strides = 7 init_num_features = 8 nInputFeatures = 1 spatial_size = 128 #padding the rest for 169 PMTs num_classes = 2 # good versus ghost nPlanes = [(2**i) * init_num_features for i in range(0, num_strides) ] # every layer double the number of features downsample = [kernel_size, 2] leakiness = 0 ################################# # Input layer ################################# self.input = scn.Sequential().add( scn.InputLayer(self._dimension, spatial_size, mode=3)).add( scn.SubmanifoldConvolution(self._dimension, nInputFeatures, init_num_features, 3, False)) # Kernel size 3, no bias self.concat = scn.JoinTable() ################################# # Encode layers #################################\ self.encoding_conv = scn.Sequential() for i in range(num_strides): if i < 4: #hardcoded self.encoding_conv.add( scn.BatchNormLeakyReLU( nPlanes[i], leakiness=leakiness)).add( scn.Convolution(self._dimension, nPlanes[i], nPlanes[i + 1], downsample[0], downsample[1], False)) elif i < num_strides - 1: self.encoding_conv.add(scn.MaxPooling(self._dimension, 2, 2)) self.output = scn.Sequential().add( scn.SparseToDense(self._dimension, nPlanes[-1])) ################################### # Final linear layer ################################### self.deepest_layer_num_features = int( nPlanes[-1] * np.power(spatial_size / (2**(num_strides - 1)), 3.)) self.classifier = torch.nn.Sequential( torch.nn.ReLU(), torch.nn.Linear(self.deepest_layer_num_features, 2), )
def baz(depth, nPlanes): if depth == 1: return scn.Sequential().add(foo(nPlanes)).add(bar(nPlanes, True)) else: return scn.Sequential().add(foo(nPlanes)).add(scn.ConcatTable().add(bar(nPlanes,False)).add( scn.Sequential()\ .add(scn.BatchNormReLU(nPlanes))\ .add(scn.Convolution(dimension, nPlanes, l(nPlanes), 2, 2, False))\ .add(baz(depth-1,l(nPlanes)))\ .add(scn.UnPooling(dimension, 2, 2)) )).add(scn.AddTable())
def SparseResNet(dimension, nInputPlanes, layers): import sparseconvnet as scn """ pre-activated ResNet e.g. layers = {{'basic',16,2,1},{'basic',32,2}} """ nPlanes = nInputPlanes m = scn.Sequential() def residual(nIn, nOut, stride): if stride > 1: return scn.Convolution(dimension, nIn, nOut, 2, stride, False) elif nIn != nOut: return scn.NetworkInNetwork(nIn, nOut, False) else: return scn.Identity() for n, reps, stride in layers: for rep in range(reps): if rep == 0: m.add(scn.BatchNormReLU(nPlanes)) tab = scn.ConcatTable() tab_seq = scn.Sequential() if stride == 1: tab_seq.add( scn.SubmanifoldConvolution(dimension, nPlanes, n, 3, False)) else: tab_seq.add( scn.Convolution(dimension, nPlanes, n, 2, stride, False)) tab_seq.add(scn.BatchNormReLU(n)) tab_seq.add( scn.SubmanifoldConvolution(dimension, n, n, 3, False)) tab.add(tab_seq) tab.add(residual(nPlanes, n, stride)) m.add(tab) else: tab = scn.ConcatTable() tab_seq = scn.Sequential() tab_seq.add(scn.BatchNormReLU(nPlanes)) tab_seq.add( scn.SubmanifoldConvolution(dimension, nPlanes, n, 3, False)) tab_seq.add(scn.BatchNormReLU(n)) tab_seq.add( scn.SubmanifoldConvolution(dimension, n, n, 3, False)) tab.add(tab_seq) tab.add(scn.Identity()) m.add(tab) nPlanes = n m.add(scn.AddTable()) m.add(scn.BatchNormReLU(nPlanes)) return m
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.SparseVggNet( 2, 3, [['C', 16], ['C', 16], 'MP', ['C', 32], ['C', 32], 'MP', ['C', 48], ['C', 48], 'MP', ['C', 64], ['C', 64], 'MP', ['C', 96], ['C', 96] ]).add(scn.Convolution(2, 96, 128, 3, 2, False)).add( scn.BatchNormReLU(128)).add(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, 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, inplanes, outplanes, nplanes=1): nn.Module.__init__(self) self.conv = scn.Convolution(dimension=3, nIn=inplanes, nOut=outplanes, filter_size=[nplanes, 2, 2], filter_stride=[1, 2, 2], bias=False) # if FLAGS.BATCH_NORM: self.bn = scn.BatchNormalization(outplanes) self.relu = scn.ReLU()
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, *, inplanes, outplanes, nplanes=1, params): nn.Module.__init__(self) self.conv = scn.Convolution(dimension=3, nIn=inplanes, nOut=outplanes, filter_size=[nplanes, 2, 2], filter_stride=[1, 2, 2], bias=params.use_bias) self.do_batch_norm = False if params.batch_norm: self.do_batch_norm = True self.bn = scn.BatchNormalization(outplanes) self.relu = scn.ReLU()
def __init__(self, inplanes, outplanes, bias, batch_norm): nn.Module.__init__(self) self.conv = scn.Convolution(dimension=3, nIn=inplanes, nOut=outplanes, filter_size=2, filter_stride=2, bias=bias) # if FLAGS.BATCH_NORM: if batch_norm: self.activation = scn.BatchNormReLU(outplanes, momentum=0.5) else: self.activation = scn.ReLU()
def __init__(self, dimension, nPlanes_up, nPlanes_down, reps, sgc_config=None): super(down, self).__init__() self.net = scn.Sequential() self.net.add(scn.BatchNormReLU(nPlanes_up)).add( scn.Convolution(dimension, nPlanes_up, nPlanes_down, 2, 2, False)) self.conv = scn.Sequential() for _ in range(reps): res(self.conv, dimension, nPlanes_down, nPlanes_down) self.sgc_config = sgc_config
def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential( scn.SparseVggNet( 2, 3, [[ 'C', 8, ], ['C', 8], 'MP', ['C', 16], ['C', 16], 'MP', ['C', 16, 8], ['C', 16, 8], 'MP', ['C', 24, 8], ['C', 24, 8], 'MP']), 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.inputLayer = scn.InputLayer(2, self.spatial_size, 2) self.linear = nn.Linear(64, 183)