def build_model(): ################# # Regular model # ################# data_size = data_sizes["sliced:data:ax:noswitch"] l0 = InputLayer(data_size) l0r = batch_norm(reshape(l0, ( -1, 1, ) + data_size[1:])) # (batch, channel, axis, time, x, y) # convolve over time l1 = batch_norm( ConvolutionOverAxisLayer( l0r, num_filters=4, filter_size=(3, ), axis=(3, ), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.0), )) l1m = batch_norm(MaxPoolOverAxisLayer(l1, pool_size=(4, ), axis=(3, ))) # convolve over x and y l2a = batch_norm( ConvolutionOver2DAxisLayer( l1m, num_filters=8, filter_size=(3, 3), axis=(4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.0), )) l2b = batch_norm( ConvolutionOver2DAxisLayer( l2a, num_filters=8, filter_size=(3, 3), axis=(4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.0), )) l2m = batch_norm(MaxPoolOver2DAxisLayer(l2b, pool_size=(2, 2), axis=(4, 5))) # convolve over x, y, time l3a = batch_norm( ConvolutionOver3DAxisLayer( l2m, num_filters=64, filter_size=(3, 3, 3), axis=(3, 4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l3b = batch_norm( ConvolutionOver2DAxisLayer( l3a, num_filters=64, filter_size=(3, 3), axis=(4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l3m = batch_norm(MaxPoolOver2DAxisLayer(l3b, pool_size=(2, 2), axis=(4, 5))) # convolve over time l4 = batch_norm( ConvolutionOverAxisLayer( l3m, num_filters=64, filter_size=(3, ), axis=(3, ), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l4m = batch_norm(MaxPoolOverAxisLayer(l4, pool_size=(2, ), axis=(2, ))) # maxpool over axis l5 = batch_norm(MaxPoolOverAxisLayer(l3m, pool_size=(4, ), axis=(2, ))) # convolve over x and y l6a = batch_norm( ConvolutionOver2DAxisLayer( l5, num_filters=128, filter_size=(3, 3), axis=(4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l6b = batch_norm( ConvolutionOver2DAxisLayer( l6a, num_filters=128, filter_size=(3, 3), axis=(4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l6m = batch_norm(MaxPoolOver2DAxisLayer(l6b, pool_size=(2, 2), axis=(4, 5))) # convolve over time and x,y l7 = ConvolutionOver3DAxisLayer( l6m, num_filters=128, filter_size=(3, 3, 3), axis=(3, 4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l8 = lasagne.layers.DropoutLayer(l7, p=0.5) l_d3a = lasagne.layers.DenseLayer(l8, num_units=128) l_d3b = lasagne.layers.DropoutLayer(l_d3a) l_systole = CumSumLayer( lasagne.layers.DenseLayer(l_d3b, num_units=600, nonlinearity=lasagne.nonlinearities.softmax)) l_d3c = lasagne.layers.DenseLayer(l8, num_units=128) l_d3d = lasagne.layers.DropoutLayer(l_d3c) l_diastole = CumSumLayer( lasagne.layers.DenseLayer(l_d3d, num_units=600, nonlinearity=lasagne.nonlinearities.softmax)) return { "inputs": { "sliced:data:ax:noswitch": l0 }, "outputs": { "systole": l_systole, "diastole": l_diastole, }, "regularizable": { l_d3a: 0.25, l_d3c: 0.25, l_systole: 0.25, l_diastole: 0.25, } }
def build_model(): ################# # Regular model # ################# l0 = InputLayer(data_sizes["sliced:data:ax"]) l0r = reshape(l0, ( -1, 1, ) + data_sizes["sliced:data:ax"][1:]) # (batch, channel, time, axis, x, y) # convolve over time l1 = ConvolutionOverAxisLayer( l0r, num_filters=4, filter_size=(3, ), axis=(2, ), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l1b = ConvolutionOverAxisLayer( l1, num_filters=4, filter_size=(3, ), axis=(2, ), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l1m = MaxPoolOverAxisLayer(l1b, pool_size=(2, ), axis=(2, )) # convolve over x and y l2a = ConvolutionOver2DAxisLayer( l1m, num_filters=32, filter_size=(3, 3), axis=(4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l2b = ConvolutionOver2DAxisLayer( l2a, num_filters=32, filter_size=(3, 3), axis=(4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l2m = MaxPoolOver2DAxisLayer(l2b, pool_size=(2, 2), axis=(4, 5)) # convolve over x, y and axis l3a = ConvolutionOver3DAxisLayer( l2m, num_filters=64, filter_size=(3, 3, 3), axis=(3, 4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l3b = ConvolutionOver3DAxisLayer( l3a, num_filters=64, filter_size=(3, 3, 3), axis=(3, 4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l3c = ConvolutionOver3DAxisLayer( l3b, num_filters=64, filter_size=(3, 3, 3), axis=(3, 4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l3m = MaxPoolOver3DAxisLayer(l3c, pool_size=(2, 2, 2), axis=(3, 4, 5)) # convolve over time l4 = ConvolutionOverAxisLayer( l3m, num_filters=64, filter_size=(3, ), axis=(2, ), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l4m = MaxPoolOverAxisLayer(l4, pool_size=(2, ), axis=(2, )) # convolve over axis l5 = ConvolutionOverAxisLayer( l4m, num_filters=128, filter_size=(3, ), axis=(3, ), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) # convolve over x and y l6a = ConvolutionOver2DAxisLayer( l5, num_filters=128, filter_size=(3, 3), axis=(4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l6b = ConvolutionOver2DAxisLayer( l6a, num_filters=128, filter_size=(3, 3), axis=(4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l6m = MaxPoolOver2DAxisLayer(l6b, pool_size=(2, 2), axis=(4, 5)) # convolve over time and x,y l7 = ConvolutionOver3DAxisLayer( l6m, num_filters=32, filter_size=(3, 3, 3), axis=(2, 4, 5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l8 = lasagne.layers.DropoutLayer(l7) l_d3a = lasagne.layers.DenseLayer(l8, num_units=600) l_d3b = lasagne.layers.DropoutLayer(l_d3a) l_systole = lasagne.layers.DenseLayer( l_d3b, num_units=600, nonlinearity=lasagne.nonlinearities.softmax) l_d3c = lasagne.layers.DenseLayer(l8, num_units=600) l_d3d = lasagne.layers.DropoutLayer(l_d3c) l_diastole = lasagne.layers.DenseLayer( l_d3d, num_units=600, nonlinearity=lasagne.nonlinearities.softmax) return { "inputs": { "sliced:data:ax": l0 }, "outputs": { "systole:onehot": l_systole, "diastole:onehot": l_diastole, }, "regularizable": { l_d3a: 0.25, l_d3c: 0.25, l_systole: 0.25, l_diastole: 0.25, } }
def build_model(): ################# # Regular model # ################# l0 = InputLayer(data_sizes["sliced:data:ax"]) l0r = reshape(l0, (-1, 1, ) + data_sizes["sliced:data:ax"][1:]) # (batch, channel, time, axis, x, y) # convolve over time l1 = ConvolutionOverAxisLayer(l0r, num_filters=2, filter_size=(5,), axis=(2,), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l1m = MaxPoolOverAxisLayer(l1, pool_size=(2,), axis=(2,)) # convolve over x and y l2a = ConvolutionOver2DAxisLayer(l1m, num_filters=32, filter_size=(5, 5), stride=(2,2), axis=(4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l2b = ConvolutionOver2DAxisLayer(l2a, num_filters=32, filter_size=(5, 5), axis=(4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l2m = MaxPoolOver2DAxisLayer(l2b, pool_size=(3, 3), axis=(4,5)) # convolve over x, y and axis l3a = ConvolutionOver3DAxisLayer(l2m, num_filters=32, filter_size=(3, 3, 3), axis=(3,4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l3b = ConvolutionOver3DAxisLayer(l3a, num_filters=32, filter_size=(3, 3, 3), axis=(3,4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l3m = MaxPoolOver3DAxisLayer(l3b, pool_size=(2, 2, 2), axis=(3,4,5)) # convolve over time l4 = ConvolutionOverAxisLayer(l3m, num_filters=32, filter_size=(5,), axis=(2,), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) l4m = MaxPoolOverAxisLayer(l4, pool_size=(2,), axis=(2,)) # convolve over axis l5 = ConvolutionOverAxisLayer(l4m, num_filters=32, filter_size=(3,), axis=(3,), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) """ l_d3 = lasagne.layers.DenseLayer(l3m, num_units=2, nonlinearity=lasagne.nonlinearities.identity) l_systole = MuLogSigmaErfLayer(l_d3) l_d3b = lasagne.layers.DenseLayer(l3m, num_units=2, nonlinearity=lasagne.nonlinearities.identity) l_diastole = MuLogSigmaErfLayer(l_d3b) """ l_d3 = lasagne.layers.DenseLayer(l5, num_units=600, nonlinearity=lasagne.nonlinearities.softmax) l_systole = CumSumLayer(l_d3) l_d3b = lasagne.layers.DenseLayer(l5, num_units=600, nonlinearity=lasagne.nonlinearities.softmax) l_diastole = CumSumLayer(l_d3b) return { "inputs":{ "sliced:data:ax": l0 }, "outputs":{ "systole": l_systole, "diastole": l_diastole } }
def build_model(): ################# # Regular model # ################# input_key = "sliced:data:ax:noswitch" data_size = data_sizes[input_key] l0 = InputLayer(data_size) l0r = batch_norm(reshape(l0, (-1, 1, ) + data_size[1:])) # (batch, channel, axis, time, x, y) # convolve over time l1 = batch_norm(ConvolutionOverAxisLayer(l0r, num_filters=8, filter_size=(3,), axis=(3,), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.0), )) l1m = batch_norm(MaxPoolOverAxisLayer(l1, pool_size=(4,), axis=(3,))) # convolve over x and y l2a = batch_norm(ConvolutionOver2DAxisLayer(l1m, num_filters=8, filter_size=(3, 3), axis=(4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.0), )) l2b = batch_norm(ConvolutionOver2DAxisLayer(l2a, num_filters=8, filter_size=(3, 3), axis=(4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.0), )) l2m = batch_norm(MaxPoolOver2DAxisLayer(l2b, pool_size=(2, 2), axis=(4,5))) # convolve over x, y, time l3a = batch_norm(ConvolutionOver3DAxisLayer(l2m, num_filters=32, filter_size=(3, 3, 3), axis=(3,4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l3b = batch_norm(ConvolutionOver2DAxisLayer(l3a, num_filters=32, filter_size=(3, 3), axis=(4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l3m = batch_norm(MaxPoolOver2DAxisLayer(l3b, pool_size=(2, 2), axis=(4,5))) # convolve over time l4 = batch_norm(ConvolutionOverAxisLayer(l3m, num_filters=32, filter_size=(3,), axis=(3,), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l4m = batch_norm(MaxPoolOverAxisLayer(l4, pool_size=(2,), axis=(2,))) # maxpool over axis l5 = batch_norm(MaxPoolOverAxisLayer(l3m, pool_size=(4,), axis=(2,))) # convolve over x and y l6a = batch_norm(ConvolutionOver2DAxisLayer(l5, num_filters=128, filter_size=(3, 3), axis=(4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l6b = batch_norm(ConvolutionOver2DAxisLayer(l6a, num_filters=128, filter_size=(3, 3), axis=(4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), )) l6m = batch_norm(MaxPoolOver2DAxisLayer(l6b, pool_size=(2, 2), axis=(4,5))) # convolve over time and x,y, is sparse reduction layer l7 = ConvolutionOver3DAxisLayer(l6m, num_filters=32, filter_size=(3,3,3), axis=(3,4,5), channel=1, W=lasagne.init.Orthogonal(), b=lasagne.init.Constant(0.1), ) key_scale = "area_per_pixel:sax" l_scale = InputLayer(data_sizes[key_scale]) # Systole Dense layers ldsys1 = lasagne.layers.DenseLayer(l7, num_units=512, W=lasagne.init.Orthogonal("relu"), b=lasagne.init.Constant(0.1), nonlinearity=lasagne.nonlinearities.rectify) ldsys1drop = lasagne.layers.dropout(ldsys1, p=0.5) ldsys2 = lasagne.layers.DenseLayer(ldsys1drop, num_units=128, W=lasagne.init.Orthogonal("relu"), b=lasagne.init.Constant(0.1), nonlinearity=lasagne.nonlinearities.rectify) ldsys2drop = lasagne.layers.dropout(ldsys2, p=0.5) ldsys3 = lasagne.layers.DenseLayer(ldsys2drop, num_units=1, b=lasagne.init.Constant(0.1), nonlinearity=lasagne.nonlinearities.identity) l_systole = layers.MuConstantSigmaErfLayer(layers.ScaleLayer(ldsys3, scale=l_scale), sigma=0.0) # Diastole Dense layers lddia1 = lasagne.layers.DenseLayer(l7, num_units=512, W=lasagne.init.Orthogonal("relu"), b=lasagne.init.Constant(0.1), nonlinearity=lasagne.nonlinearities.rectify) lddia1drop = lasagne.layers.dropout(lddia1, p=0.5) lddia2 = lasagne.layers.DenseLayer(lddia1drop, num_units=128, W=lasagne.init.Orthogonal("relu"), b=lasagne.init.Constant(0.1), nonlinearity=lasagne.nonlinearities.rectify) lddia2drop = lasagne.layers.dropout(lddia2, p=0.5) lddia3 = lasagne.layers.DenseLayer(lddia2drop, num_units=1, b=lasagne.init.Constant(0.1), nonlinearity=lasagne.nonlinearities.identity) l_diastole = layers.MuConstantSigmaErfLayer(layers.ScaleLayer(lddia3, scale=l_scale), sigma=0.0) return { "inputs":{ input_key: l0, key_scale: l_scale, }, "outputs": { "systole": l_systole, "diastole": l_diastole, }, "regularizable": { ldsys1: l2_weight, ldsys2: l2_weight, ldsys3: l2_weight, lddia1: l2_weight, lddia2: l2_weight, lddia3: l2_weight, }, }