Пример #1
0
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
        }
    }
Пример #2
0
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,
        }
    }