Exemplo n.º 1
0
def build_model():
    l_in = lasagne.layers.InputLayer(shape=(None, max_rois) + nn_input_shape)
    l_norm = Hu2normHULayer(l_in, min_hu=-1000, max_hu=400)

    l = lasagne.layers.ReshapeLayer(l_norm, (-1, 1) + nn_input_shape)

    l = conv3d(l, 64)
    l = inrn_v2_red(l)
    l = inrn_v2_red(l)
    l = inrn_v2_red(l)

    n_f_dense_patch = 128
    l = dense(drop(l), n_f_dense_patch)
    l = lasagne.layers.ReshapeLayer(l, (-1, max_rois, n_f_dense_patch))

    l = dense(drop(l), 128)

    l_out = lasagne.layers.DenseLayer(
        l,
        num_units=2,
        W=lasagne.init.Constant(0.),
        nonlinearity=lasagne.nonlinearities.softmax)

    return {
        "inputs": {
            tag + "3d": l_in,
        },
        "outputs": {
            "predicted_probability": l_out
        },
    }
Exemplo n.º 2
0
def build_model(image_size=nn_input_shape):
    l_in = lasagne.layers.InputLayer(shape=(None, ) + image_size)
    l_norm = Hu2normHULayer(l_in, min_hu=-1000, max_hu=400)
    # l_norm = ZMUVLayer(l_norm, mean=0.36, std=0.31)
    l = lasagne.layers.DimshuffleLayer(l_norm, pattern=[0, 'x', 1, 2, 3])

    l = conv3d(l, 64)
    l = inrn_v2_red(l)
    l = inrn_v2_red(l)
    l = inrn_v2_red(l)
    l = inrn_v2_red(l)

    l = dense(drop(l), 128)

    # this is a different way to output compared to luna_direct_x23 config
    l_out = lasagne.layers.DenseLayer(
        l,
        num_units=2,
        W=lasagne.init.Constant(0.),
        nonlinearity=lasagne.nonlinearities.softmax)

    # l_out = lasagne.layers.DenseLayer(l, num_units=1,
    #                              W=lasagne.init.Constant(0.),
    #                              nonlinearity=lasagne.nonlinearities.sigmoid)

    # l_out = lasagne.layers.reshape(l_out, shape=(-1,))

    return {
        "inputs": {
            tag + "3d": l_in,
        },
        "outputs": {
            "predicted_probability": l_out
        },
    }
Exemplo n.º 3
0
def build_model(image_size=(IMAGE_SIZE,IMAGE_SIZE,IMAGE_SIZE)):

    l_in = lasagne.layers.InputLayer(shape=(None,)+image_size)
    l_norm = Hu2normHULayer(l_in, min_hu=-1000,max_hu=400)
    l0 = lasagne.layers.DimshuffleLayer(l_norm, pattern=[0,'x',1,2,3])
    

    net = {}
    base_n_filters = 128
    net['contr_1_1'] = conv3d(l0, base_n_filters)
    net['contr_1_1'] = lasagne.layers.ParametricRectifierLayer(net['contr_1_1'])
    net['contr_1_2'] = conv3d(net['contr_1_1'], base_n_filters)
    net['contr_1_2'] = lasagne.layers.ParametricRectifierLayer(net['contr_1_2'])
    net['contr_1_3'] = conv3d(net['contr_1_2'], base_n_filters)
    net['contr_1_3'] = lasagne.layers.ParametricRectifierLayer(net['contr_1_3'])
    net['pool1'] = max_pool3d(net['contr_1_3'])

    net['encode_1'] = conv3d(net['pool1'], base_n_filters)
    net['encode_1'] = lasagne.layers.ParametricRectifierLayer(net['encode_1'])
    net['encode_2'] = conv3d(net['encode_1'], base_n_filters)
    net['encode_2'] = lasagne.layers.ParametricRectifierLayer(net['encode_2'])
    net['encode_3'] = conv3d(net['encode_2'], base_n_filters)
    net['encode_3'] = lasagne.layers.ParametricRectifierLayer(net['encode_3'])
    net['encode_4'] = conv3d(net['encode_3'], base_n_filters)
    net['encode_4'] = lasagne.layers.ParametricRectifierLayer(net['encode_4'])
    
    net['dropout_1'] = lasagne.layers.DropoutLayer(net['encode_4'], p=0.25)
    
    net['upscale1'] = lasagne.layers.Upscale3DLayer(net['dropout_1'], 2)

    net['concat1'] = lasagne.layers.ConcatLayer([net['upscale1'], net['contr_1_3']],
                                           cropping=(None, None, "center", "center", "center"))
    net['expand_1_1'] = conv3d(net['concat1'], 2 * base_n_filters)
    net['expand_1_1'] = lasagne.layers.ParametricRectifierLayer(net['expand_1_1'])
    net['expand_1_2'] = conv3d(net['expand_1_1'], 2 * base_n_filters)
    net['expand_1_2'] = lasagne.layers.ParametricRectifierLayer(net['expand_1_2'])
    net['expand_1_3'] = conv3d(net['expand_1_2'], base_n_filters)
    net['expand_1_3'] = lasagne.layers.ParametricRectifierLayer(net['expand_1_3'])

    net['output_segmentation'] = dnn.Conv3DDNNLayer(net['expand_1_3'], num_filters=1,
                               filter_size=1,
                               nonlinearity=lasagne.nonlinearities.sigmoid)

    l_out = lasagne.layers.SliceLayer(net['output_segmentation'], indices=0, axis=1)
    
    
    
    return {
        "inputs":{
            "luna:3d": l_in,
        },
        "outputs": {
            "predicted_segmentation": l_out
        },
    }