def build_autoencoder_network():
    input_var = T.tensor4('input_var');

    layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var);
    layer = batch_norm(layers.Conv2DLayer(layer, 100,  filter_size=(5,5), stride=1, pad='same', nonlinearity=leaky_rectify));
    layer = batch_norm(layers.Conv2DLayer(layer, 120,  filter_size=(5,5), stride=1, pad='same', nonlinearity=leaky_rectify));
    layer = batch_norm(layers.Conv2DLayer(layer, 120,  filter_size=(1,1), stride=1, pad='same', nonlinearity=leaky_rectify));
    pool1 =            layers.MaxPool2DLayer(layer, (2, 2), 2);
    layer = batch_norm(layers.Conv2DLayer(pool1, 240,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    layer = batch_norm(layers.Conv2DLayer(layer, 320,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    layer = batch_norm(layers.Conv2DLayer(layer, 320,  filter_size=(1,1), stride=1, pad='same', nonlinearity=leaky_rectify));
    pool2 =            layers.MaxPool2DLayer(layer, (2, 2), 2);
    layer = batch_norm(layers.Conv2DLayer(pool2, 640,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    prely = batch_norm(layers.Conv2DLayer(layer, 1024, filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));

    featm    = batch_norm(layers.Conv2DLayer(prely, 640, filter_size=(1,1), nonlinearity=leaky_rectify));
    feat_map = batch_norm(layers.Conv2DLayer(featm, 100, filter_size=(1,1), nonlinearity=rectify, name="feat_map"));
    maskm    = batch_norm(layers.Conv2DLayer(prely, 100, filter_size=(1,1), nonlinearity=leaky_rectify));
    mask_rep = batch_norm(layers.Conv2DLayer(maskm, 1,   filter_size=(1,1), nonlinearity=None),   beta=None, gamma=None);
    mask_map = SoftThresPerc(mask_rep, perc=90.0, alpha=0.1, beta=init.Constant(0.5), tight=100.0, name="mask_map");
    layer    = ChInnerProdMerge(feat_map, mask_map, name="encoder");

    layer = batch_norm(layers.Deconv2DLayer(layer, 1024, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    layer = batch_norm(layers.Deconv2DLayer(layer, 640,  filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    layer = batch_norm(layers.Deconv2DLayer(layer, 320,  filter_size=(1,1), stride=1, crop='same', nonlinearity=leaky_rectify));
    layer =            layers.InverseLayer(layer, pool2);
    layer = batch_norm(layers.Deconv2DLayer(layer, 320,  filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    layer = batch_norm(layers.Deconv2DLayer(layer, 320,  filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    layer = batch_norm(layers.Deconv2DLayer(layer, 120,  filter_size=(1,1), stride=1, crop='same', nonlinearity=leaky_rectify));
    layer =            layers.InverseLayer(layer, pool1);
    layer = batch_norm(layers.Deconv2DLayer(layer, 120,  filter_size=(5,5), stride=1, crop='same', nonlinearity=leaky_rectify));
    layer = batch_norm(layers.Deconv2DLayer(layer, 100,  filter_size=(5,5), stride=1, crop='same', nonlinearity=leaky_rectify));
    layer =            layers.Deconv2DLayer(layer, 3,    filter_size=(1,1), stride=1, crop='same', nonlinearity=identity);

    glblf = batch_norm(layers.Conv2DLayer(prely, 128,  filter_size=(1,1), nonlinearity=leaky_rectify));
    glblf = layers.Pool2DLayer(glblf, pool_size=(5,5), stride=5, mode='average_inc_pad');
    glblf = batch_norm(layers.Conv2DLayer(glblf, 64,   filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Conv2DLayer(glblf, 5,    filter_size=(1,1), nonlinearity=rectify), name="global_feature");

    glblf = batch_norm(layers.Deconv2DLayer(glblf, 256, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 128, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 128, filter_size=(9,9), stride=5, crop=(2,2),  nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 128, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 128, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 64,  filter_size=(4,4), stride=2, crop=(1,1),  nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 64,  filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 64,  filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 32,  filter_size=(4,4), stride=2, crop=(1,1),  nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 32,  filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    glblf = batch_norm(layers.Deconv2DLayer(glblf, 32,  filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    glblf =            layers.Deconv2DLayer(glblf, 3,   filter_size=(1,1), stride=1, crop='same', nonlinearity=identity);

    layer = layers.ElemwiseSumLayer([layer, glblf]);

    network = ReshapeLayer(layer, ([0], -1));
    mask_var = lasagne.layers.get_output(mask_map);
    output_var = lasagne.layers.get_output(network);

    return network, input_var, mask_var, output_var;
Beispiel #2
0
 def _forward(self):
     net = {}
     net['input'] = layers.InputLayer(shape=(None, 1, 28, 28),
                                      input_var=self.X)
     net['dense1'] = layers.DenseLayer(net['input'],
                                       num_units=1024,
                                       W=init.GlorotUniform(),
                                       b=init.Constant(0.),
                                       nonlinearity=nonlinearities.rectify)
     net['dense2'] = layers.DenseLayer(net['dense1'],
                                       num_units=512,
                                       W=init.GlorotUniform(),
                                       b=None,
                                       nonlinearity=nonlinearities.rectify)
     net['out'] = layers.DenseLayer(net['dense2'],
                                    num_units=10,
                                    W=init.GlorotUniform(),
                                    b=None,
                                    nonlinearity=nonlinearities.softmax)
     net['outinv'] = layers.InverseLayer(net['out'], net['out'])
     return net
Beispiel #3
0
def build_deconv_network():
    input_var = theano.tensor.tensor4('input_var')

    net = {}
    net['input'] = layers.InputLayer(shape=(None, 3, PS, PS),
                                     input_var=input_var)

    # Encoding part
    net['conv1_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['input'],
                               64,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['conv1_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['conv1_1'],
                               64,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['pool1'] = layers.Pool2DLayer(net['conv1_2'],
                                      pool_size=(2, 2),
                                      stride=2,
                                      mode='max')

    net['conv2_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['pool1'],
                               128,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['conv2_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['conv2_1'],
                               128,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['pool2'] = layers.Pool2DLayer(net['conv2_2'],
                                      pool_size=(2, 2),
                                      stride=2,
                                      mode='max')

    net['conv3_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['pool2'],
                               256,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['conv3_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['conv3_1'],
                               256,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['conv3_3'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['conv3_2'],
                               256,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['pool3'] = layers.Pool2DLayer(net['conv3_3'],
                                      pool_size=(2, 2),
                                      stride=2,
                                      mode='max')

    net['conv4_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['pool3'],
                               512,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['conv4_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['conv4_1'],
                               512,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['conv4_3'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['conv4_2'],
                               512,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['pool4'] = layers.Pool2DLayer(net['conv4_3'],
                                      pool_size=(2, 2),
                                      stride=2,
                                      mode='max')

    net['conv5_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['pool4'],
                               512,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['conv5_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['conv5_1'],
                               512,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['conv5_3'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['conv5_2'],
                               512,
                               filter_size=(3, 3),
                               stride=1,
                               pad=1)))
    net['pool5'] = layers.Pool2DLayer(net['conv5_3'],
                                      pool_size=(2, 2),
                                      stride=2,
                                      mode='max')

    net['fc6'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['pool5'],
                               4096,
                               filter_size=(7, 7),
                               stride=1,
                               pad='same')))

    # fc7 is the encoding layer
    net['fc7'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Conv2DLayer(net['fc6'],
                               4096,
                               filter_size=(1, 1),
                               stride=1,
                               pad='same')))

    # Decoding part
    net['fc6_deconv'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['fc7'],
                                 512,
                                 filter_size=(7, 7),
                                 stride=1,
                                 crop='same')))
    net['unpool5'] = layers.InverseLayer(net['fc6_deconv'], net['pool5'])

    net['deconv5_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['unpool5'],
                                 512,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['deconv5_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['deconv5_1'],
                                 512,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['deconv5_3'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['deconv5_2'],
                                 512,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['unpool4'] = layers.InverseLayer(net['deconv5_3'], net['pool4'])

    net['deconv4_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['unpool4'],
                                 512,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['deconv4_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['deconv4_1'],
                                 512,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['deconv4_3'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['deconv4_2'],
                                 256,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['unpool3'] = layers.InverseLayer(net['deconv4_3'], net['pool3'])

    net['deconv3_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['unpool3'],
                                 256,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['deconv3_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['deconv3_1'],
                                 256,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['deconv3_3'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['deconv3_2'],
                                 128,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['unpool2'] = layers.InverseLayer(net['deconv3_3'], net['pool2'])

    net['deconv2_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['unpool2'],
                                 128,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['deconv2_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['deconv2_1'],
                                 64,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['unpool1'] = layers.InverseLayer(net['deconv2_2'], net['pool1'])

    net['deconv1_1'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['unpool1'],
                                 64,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))
    net['deconv1_2'] = layers.NonlinearityLayer(
        batch_norm(
            layers.Deconv2DLayer(net['deconv1_1'],
                                 64,
                                 filter_size=(3, 3),
                                 stride=1,
                                 crop='same')))

    # Segmentation layer
    net['seg_score'] = layers.Deconv2DLayer(
        net['deconv1_2'],
        1,
        filter_size=(1, 1),
        stride=1,
        crop='same',
        nonlinearity=lasagne.nonlinearities.sigmoid)

    network = ReshapeLayer(net['seg_score'], ([0], -1))
    output_var = lasagne.layers.get_output(network)
    all_param = lasagne.layers.get_all_params(network, trainable=True)

    return network, input_var, output_var, all_param
def build_network_from_ae_old(classn):
    input_var = T.tensor4('input_var');

    net = {}

    net['input'] =  layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var);

    net['conv1_1'] = batch_norm(layers.Conv2DLayer(net['input'], 64,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['conv1_2'] = batch_norm(layers.Conv2DLayer(net['conv1_1'], 64,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['pool1'] = layers.Pool2DLayer(net['conv1_2'], pool_size=(2,2), stride=2, mode='max');

    net['conv2_1'] = batch_norm(layers.Conv2DLayer(net['pool1'], 128,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['conv2_2'] = batch_norm(layers.Conv2DLayer(net['conv2_1'], 128,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['pool2'] = layers.Pool2DLayer(net['conv2_2'], pool_size=(2,2), stride=2, mode='max');

    net['conv3_1'] = batch_norm(layers.Conv2DLayer(net['pool2'], 256,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['conv3_2'] = batch_norm(layers.Conv2DLayer(net['conv3_1'], 256,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['conv3_3'] = batch_norm(layers.Conv2DLayer(net['conv3_2'], 256,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['pool3'] = layers.Pool2DLayer(net['conv3_3'], pool_size=(2,2), stride=2, mode='max');

    net['conv4_1'] = batch_norm(layers.Conv2DLayer(net['pool3'], 512,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['conv4_2'] = batch_norm(layers.Conv2DLayer(net['conv4_1'], 512,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['conv4_3'] = batch_norm(layers.Conv2DLayer(net['conv4_2'], 512,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['pool4'] = layers.Pool2DLayer(net['conv4_3'], pool_size=(2,2), stride=2, mode='max');

    net['conv5_1'] = batch_norm(layers.Conv2DLayer(net['pool4'], 512,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['conv5_2'] = batch_norm(layers.Conv2DLayer(net['conv5_1'], 512,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['conv5_3'] = batch_norm(layers.Conv2DLayer(net['conv5_2'], 512,  filter_size=(3,3), stride=1, pad='same', nonlinearity=leaky_rectify));
    net['pool5'] = layers.Pool2DLayer(net['conv5_3'], pool_size=(2,2), stride=2, mode='max');

    net['fc6'] = batch_norm(layers.Conv2DLayer(net['pool5'], 4096,  filter_size=(7,7), stride=1, pad='valid', nonlinearity=leaky_rectify));
    net['fc7'] = batch_norm(layers.Conv2DLayer(net['fc6'], 4096,  filter_size=(1,1), stride=1, pad='valid', nonlinearity=leaky_rectify));
    #net['fc6'] = batch_norm(layers.DenseLayer(net['pool5'], 4096, nonlinearity=leaky_rectify));
    #net['fc7'] = batch_norm(layers.DenseLayer(net['fc6'], 4096, nonlinearity=leaky_rectify));

    net['fc6_deconv'] = batch_norm(layers.Deconv2DLayer(net['fc7'], 512, filter_size=(7,7), stride=1, crop='valid', nonlinearity=leaky_rectify));
    net['unpool5'] = layers.InverseLayer(net['fc6_deconv'], net['pool5']);

    net['deconv5_1'] = batch_norm(layers.Deconv2DLayer(net['unpool5'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv5_2'] = batch_norm(layers.Deconv2DLayer(net['deconv5_1'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv5_3'] = batch_norm(layers.Deconv2DLayer(net['deconv5_2'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['unpool4'] = layers.InverseLayer(net['deconv5_3'], net['pool4']);

    net['deconv4_1'] = batch_norm(layers.Deconv2DLayer(net['unpool4'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv4_2'] = batch_norm(layers.Deconv2DLayer(net['deconv4_1'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv4_3'] = batch_norm(layers.Deconv2DLayer(net['deconv4_2'], 256, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['unpool3'] = layers.InverseLayer(net['deconv4_3'], net['pool3']);

    net['deconv3_1'] = batch_norm(layers.Deconv2DLayer(net['unpool3'], 256, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv3_2'] = batch_norm(layers.Deconv2DLayer(net['deconv3_1'], 256, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv3_3'] = batch_norm(layers.Deconv2DLayer(net['deconv3_2'], 128, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['unpool2'] = layers.InverseLayer(net['deconv3_3'], net['pool2']);

    net['deconv2_1'] = batch_norm(layers.Deconv2DLayer(net['unpool2'], 128, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv2_2'] = batch_norm(layers.Deconv2DLayer(net['deconv2_1'], 64, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['unpool1'] = layers.InverseLayer(net['deconv2_2'], net['pool1']);

    net['deconv1_1'] = batch_norm(layers.Deconv2DLayer(net['unpool1'], 64, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv1_2'] = batch_norm(layers.Deconv2DLayer(net['deconv1_1'], 64, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));

    net['score'] = layers.Deconv2DLayer(net['deconv1_2'], 1,  filter_size=(1,1), stride=1, crop='same', nonlinearity=sigmoid);
    net['score_flat'] = ReshapeLayer(net['score'], ([0], -1));

    all_params = layers.get_all_params(net['score_flat'], trainable=True);
    target_var = T.fmatrix('targets');

    return net, all_params, input_var, target_var;
def build_network_from_ae(classn):
    input_var = theano.tensor.tensor4('input_var');

    net = {};
    net['input'] = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var);


    # Encoding part
    net['conv1_1'] = batch_norm(layers.Conv2DLayer(net['input'], 64,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['conv1_2'] = batch_norm(layers.Conv2DLayer(net['conv1_1'], 64,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['pool1'] = layers.Pool2DLayer(net['conv1_2'], pool_size=(2,2), stride=2, mode='max');

    net['conv2_1'] = batch_norm(layers.Conv2DLayer(net['pool1'], 128,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['conv2_2'] = batch_norm(layers.Conv2DLayer(net['conv2_1'], 128,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['pool2'] = layers.Pool2DLayer(net['conv2_2'], pool_size=(2,2), stride=2, mode='max');

    net['conv3_1'] = batch_norm(layers.Conv2DLayer(net['pool2'], 256,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['conv3_2'] = batch_norm(layers.Conv2DLayer(net['conv3_1'], 256,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['conv3_3'] = batch_norm(layers.Conv2DLayer(net['conv3_2'], 256,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['pool3'] = layers.Pool2DLayer(net['conv3_3'], pool_size=(2,2), stride=2, mode='max');

    net['conv4_1'] = batch_norm(layers.Conv2DLayer(net['pool3'], 512,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['conv4_2'] = batch_norm(layers.Conv2DLayer(net['conv4_1'], 512,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['conv4_3'] = batch_norm(layers.Conv2DLayer(net['conv4_2'], 512,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['pool4'] = layers.Pool2DLayer(net['conv4_3'], pool_size=(2,2), stride=2, mode='max');

    net['conv5_1'] = batch_norm(layers.Conv2DLayer(net['pool4'], 512,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['conv5_2'] = batch_norm(layers.Conv2DLayer(net['conv5_1'], 512,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['conv5_3'] = batch_norm(layers.Conv2DLayer(net['conv5_2'], 512,   filter_size=(3,3), stride=1, pad=1, nonlinearity=leaky_rectify));
    net['pool5'] = layers.Pool2DLayer(net['conv5_3'], pool_size=(2,2), stride=2, mode='max');

    net['fc6'] = batch_norm(layers.Conv2DLayer(net['pool5'], 4096,   filter_size=(7,7), stride=1, pad='same', nonlinearity=leaky_rectify));

    # fc7 is the encoding layer
    net['fc7'] = batch_norm(layers.Conv2DLayer(net['fc6'], 4096,   filter_size=(1,1), stride=1, pad='same', nonlinearity=leaky_rectify));

    # Decoding part
    net['fc6_deconv'] = batch_norm(layers.Deconv2DLayer(net['fc7'], 512, filter_size=(7,7), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['unpool5'] = layers.InverseLayer(net['fc6_deconv'], net['pool5']);

    net['deconv5_1'] = batch_norm(layers.Deconv2DLayer(net['unpool5'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv5_2'] = batch_norm(layers.Deconv2DLayer(net['deconv5_1'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv5_3'] = batch_norm(layers.Deconv2DLayer(net['deconv5_2'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['unpool4'] = layers.InverseLayer(net['deconv5_3'], net['pool4']);

    net['deconv4_1'] = batch_norm(layers.Deconv2DLayer(net['unpool4'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv4_2'] = batch_norm(layers.Deconv2DLayer(net['deconv4_1'], 512, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv4_3'] = batch_norm(layers.Deconv2DLayer(net['deconv4_2'], 256, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['unpool3'] = layers.InverseLayer(net['deconv4_3'], net['pool3']);

    net['deconv3_1'] = batch_norm(layers.Deconv2DLayer(net['unpool3'], 256, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv3_2'] = batch_norm(layers.Deconv2DLayer(net['deconv3_1'], 256, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv3_3'] = batch_norm(layers.Deconv2DLayer(net['deconv3_2'], 128, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['unpool2'] = layers.InverseLayer(net['deconv3_3'], net['pool2']);

    net['deconv2_1'] = batch_norm(layers.Deconv2DLayer(net['unpool2'], 128, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv2_2'] = batch_norm(layers.Deconv2DLayer(net['deconv2_1'], 64, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['unpool1'] = layers.InverseLayer(net['deconv2_2'], net['pool1']);

    net['deconv1_1'] = batch_norm(layers.Deconv2DLayer(net['unpool1'], 64, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));
    net['deconv1_2'] = batch_norm(layers.Deconv2DLayer(net['deconv1_1'], 64, filter_size=(3,3), stride=1, crop='same', nonlinearity=leaky_rectify));


    # Segmentation layer
    net['seg_score'] = layers.Deconv2DLayer(net['deconv1_2'], 1, filter_size=(1,1), stride=1, crop='same', nonlinearity=lasagne.nonlinearities.sigmoid);

    net['score_flat'] = ReshapeLayer(net['seg_score'], ([0], -1));
    output_var = lasagne.layers.get_output(net['score_flat']);
    all_param = lasagne.layers.get_all_params(net['score_flat'], trainable=True);

    target_var = T.fmatrix('targets');
    #return network, input_var, output_var, all_param;
    return net, all_param, input_var, target_var;
Beispiel #6
0
 def _invert_MaxPoolingLayer(self, layer, feeder):
     assert type(layer) in [L.MaxPool2DLayer, L.MaxPool1DLayer]
     return L.InverseLayer(feeder, layer)
Beispiel #7
0
 def _invert_LocalResponseNormalisation2DLayer(self, layer, feeder):
     return L.InverseLayer(feeder, layer)