Beispiel #1
0
 def test_fail_on_mismatching_dimensionality(self):
     from lasagne.layers.pool import MaxPool2DLayer
     with pytest.raises(ValueError) as exc:
         MaxPool2DLayer((10, 20, 30), 3, 2)
     assert "Expected 4 input dimensions" in exc.value.args[0]
     with pytest.raises(ValueError) as exc:
         MaxPool2DLayer((10, 20, 30, 40, 50), 3, 2)
     assert "Expected 4 input dimensions" in exc.value.args[0]
Beispiel #2
0
 def layer(self, input_layer, ds, st=None):
     from lasagne.layers.pool import MaxPool2DLayer
     return MaxPool2DLayer(
         input_layer,
         ds=ds,
         st=st,
         ignore_border=False,
     )
Beispiel #3
0
 def layer_ignoreborder(self, input_layer, ds, st=None, pad=(0, 0)):
     from lasagne.layers.pool import MaxPool2DLayer
     return MaxPool2DLayer(
         input_layer,
         ds=ds,
         st=st,
         pad=pad,
         ignore_border=True,
     )
Beispiel #4
0
 def layer(self, input_layer, pool_size, stride=None,
           pad=(0, 0), ignore_border=False):
     from lasagne.layers.pool import MaxPool2DLayer
     return MaxPool2DLayer(
         input_layer,
         pool_size=pool_size,
         stride=stride,
         pad=pad,
         ignore_border=ignore_border,
     )
Beispiel #5
0
def build_model(inp):
    net = {}
    net['input'] = InputLayer((None, 3, 224, 224), input_var=inp)
    net['conv1'] = Conv2DLayer(net['input'],
                               96,
                               7,
                               stride=2,
                               pad=(1, 1),
                               W=lasagne.init.Uniform())
    net['norm1'] = LocalResponseNormalization2DLayer(net['conv1'],
                                                     alpha=0.00005)
    net['pool1'] = MaxPool2DLayer(net['norm1'], 3, stride=2)
    net['conv2'] = Conv2DLayer(net['pool1'],
                               256,
                               5,
                               stride=2,
                               pad=(0, 0),
                               W=lasagne.init.Uniform(),
                               b=lasagne.init.Constant(1.))
    net['norm2'] = LocalResponseNormalization2DLayer(net['conv2'],
                                                     alpha=0.00005)
    net['pool2'] = MaxPool2DLayer(net['norm2'], 3, stride=2)
    net['conv3'] = Conv2DLayer(net['pool2'],
                               384,
                               3,
                               stride=1,
                               pad=(1, 1),
                               W=lasagne.init.Uniform())
    net['conv4'] = Conv2DLayer(net['conv3'],
                               384,
                               3,
                               stride=1,
                               pad=(1, 1),
                               W=lasagne.init.Uniform(),
                               b=lasagne.init.Constant(1.))
    net['conv5'] = Conv2DLayer(net['conv4'],
                               256,
                               3,
                               stride=1,
                               pad=(1, 1),
                               W=lasagne.init.Uniform(),
                               b=lasagne.init.Constant(1.))
    net['p5_spm6'] = FlattenLayer(MaxPool2DLayer(net['conv5'], 3, stride=2))
    net['p5_spm3'] = FlattenLayer(MaxPool2DLayer(net['conv5'], 5, stride=4))
    net['p5_spm2'] = FlattenLayer(MaxPool2DLayer(net['conv5'], 7, stride=7))
    net['p5_spm1'] = MaxPool2DLayer(net['conv5'], 13, stride=13)
    net['p5_spm1_f'] = FlattenLayer(net['p5_spm1'])
    net['conc_spm'] = ConcatLayer(
        [net['p5_spm6'], net['p5_spm3'], net['p5_spm2'], net['p5_spm1_f']])
    net['fc6'] = DenseLayer(net['conc_spm'],
                            num_units=4096,
                            W=lasagne.init.Uniform(),
                            b=lasagne.init.Constant(1.))
    net['fc6_drop'] = DropoutLayer(net['fc6'], p=0.5)
    net['fc7'] = DenseLayer(net['fc6_drop'],
                            num_units=4096,
                            W=lasagne.init.Uniform(),
                            b=lasagne.init.Constant(1.))
    net['fc7_drop'] = DropoutLayer(net['fc7'], p=0.5)
    net['fc8'] = DenseLayer(net['fc6_drop'],
                            num_units=1000,
                            W=lasagne.init.Uniform(),
                            b=lasagne.init.Constant(1.))
    net['out'] = NonlinearityLayer(net['fc8'], softmax)
    return net
Beispiel #6
0
 def layer_ignoreborder(self, input_layer):
     from lasagne.layers.pool import MaxPool2DLayer
     return MaxPool2DLayer(input_layer, ds=(2, 2), ignore_border=True)
Beispiel #7
0
 def layer(self, input_layer):
     from lasagne.layers.pool import MaxPool2DLayer
     return MaxPool2DLayer(input_layer, ds=(2, 2))
Beispiel #8
0
def build_model(inp):
    net = {}
    net['input'] = InputLayer((None, 3, 224, 224), input_var=input_var)
    net['conv1_1'] = batch_norm(
        Conv2DLayer(net['input'], 64, 3, pad=1, flip_filters=False))
    net['conv1_2'] = batch_norm(
        Conv2DLayer(net['conv1_1'], 64, 3, pad=1, flip_filters=False))
    net['pool1'] = MaxPool2DLayer(net['conv1_2'], 2)
    net['conv2_1'] = batch_norm(
        Conv2DLayer(net['pool1'], 128, 3, pad=1, flip_filters=False))
    net['conv2_2'] = batch_norm(
        Conv2DLayer(net['conv2_1'], 128, 3, pad=1, flip_filters=False))
    net['pool2'] = MaxPool2DLayer(net['conv2_2'], 2)
    net['conv3_1'] = batch_norm(
        Conv2DLayer(net['pool2'], 256, 3, pad=1, flip_filters=False))
    net['conv3_2'] = batch_norm(
        Conv2DLayer(net['conv3_1'], 256, 3, pad=1, flip_filters=False))
    net['conv3_3'] = batch_norm(
        Conv2DLayer(net['conv3_2'], 256, 3, pad=1, flip_filters=False))
    net['pool3'] = MaxPool2DLayer(net['conv3_3'], 2)
    net['conv4_1'] = batch_norm(
        Conv2DLayer(net['pool3'], 512, 3, pad=1, flip_filters=False))
    net['conv4_2'] = batch_norm(
        Conv2DLayer(net['conv4_1'], 512, 3, pad=1, flip_filters=False))
    net['conv4_3'] = batch_norm(
        Conv2DLayer(net['conv4_2'], 512, 3, pad=1, flip_filters=False))
    net['pool4'] = MaxPool2DLayer(net['conv4_3'], 2)
    net['conv5_1'] = batch_norm(
        Conv2DLayer(net['pool4'], 512, 3, pad=1, flip_filters=False))
    net['conv5_2'] = batch_norm(
        Conv2DLayer(net['conv5_1'], 512, 3, pad=1, flip_filters=False))
    net['conv5_3'] = batch_norm(
        Conv2DLayer(net['conv5_2'], 512, 3, pad=1, flip_filters=False))
    net['pool5'] = MaxPool2DLayer(net['conv5_3'], 2)
    net['fc6'] = batch_norm(DenseLayer(net['pool5'], num_units=4096))
    net['fc6_dropout'] = DropoutLayer(net['fc6'], p=0.5)
    net['fc7'] = batch_norm(DenseLayer(net['fc6_dropout'], num_units=4096))
    net['fc7_dropout'] = DropoutLayer(net['fc7'], p=0.5)
    net['reshape'] = ReshapeLayer(net['fc7_dropout'], (-1, 4096, 1, 1))
    net['deconv6'] = batch_norm(Deconv2DLayer(net['reshape'], 512, 7))
    net['unpool5'] = Upscale2DLayer(net['deconv6'], 2)
    net['deconv5_3'] = batch_norm(
        Deconv2DLayer(net['unpool5'], 512, 3, crop=1, flip_filters=False))
    net['deconv5_2'] = batch_norm(
        Deconv2DLayer(net['deconv5_3'], 512, 3, crop=1, flip_filters=False))
    net['deconv5_1'] = batch_norm(
        Deconv2DLayer(net['deconv5_2'], 512, 3, crop=1, flip_filters=False))
    net['unpool4'] = Upscale2DLayer(net['deconv5_1'], 2)
    net['deconv4_3'] = batch_norm(
        Deconv2DLayer(net['unpool4'], 512, 3, crop=1, flip_filters=False))
    net['deconv4_2'] = batch_norm(
        Deconv2DLayer(net['deconv4_3'], 512, 3, crop=1, flip_filters=False))
    net['deconv4_1'] = batch_norm(
        Deconv2DLayer(net['deconv4_2'], 512, 3, crop=1, flip_filters=False))
    net['unpool3'] = Upscale2DLayer(net['deconv4_1'], 2)
    net['deconv3_3'] = batch_norm(
        Deconv2DLayer(net['unpool3'], 256, 3, crop=1, flip_filters=False))
    net['deconv3_2'] = batch_norm(
        Deconv2DLayer(net['deconv3_3'], 256, 3, crop=1, flip_filters=False))
    net['deconv3_1'] = batch_norm(
        Deconv2DLayer(net['deconv3_2'], 256, 3, crop=1, flip_filters=False))
    net['unpool2'] = Upscale2DLayer(net['deconv3_1'], 2)
    net['deconv2_2'] = batch_norm(
        Deconv2DLayer(net['unpool2'], 128, 3, crop=1, flip_filters=False))
    net['deconv2_1'] = batch_norm(
        Deconv2DLayer(net['deconv2_2'], 128, 3, crop=1, flip_filters=False))
    net['unpool1'] = Upscale2DLayer(net['deconv2_1'], 2)
    net['deconv1_1'] = batch_norm(
        Deconv2DLayer(net['unpool1'], 64, 3, crop=1, flip_filters=False))
    net['deconv1_2'] = batch_norm(
        Deconv2DLayer(net['deconv1_1'], 64, 3, crop=1, flip_filters=False))
    net['out'] = NonlinearityLayer(DenseLayer(net['deconv1_2'], 21), softmax)
    return net