def build_model():
    l0 = nn.layers.InputLayer((batch_size, 1, patch_size[0], patch_size[1]))
    l0c = dihedral.CyclicSliceLayer(l0)

    l1 = convroll(conv(l0c, num_filters=16, filter_size=(7, 7),
                       strides=(2, 2)))

    l2 = convroll(conv(l1, num_filters=32, filter_size=(7, 7), strides=(2, 2)))

    l3a = convroll(conv(l2, num_filters=32, filter_size=(3, 3)))
    l3b = convroll(conv(l3a, num_filters=32, filter_size=(3, 3)))
    l3c = convroll(conv(l3b, num_filters=32, filter_size=(3, 3)))
    l3d = conv(l3c, num_filters=64, filter_size=(3, 3))
    l3 = convroll(pool(l3d))

    l4a = convroll(conv(l3, num_filters=64, filter_size=(3, 3)))
    l4b = convroll(conv(l4a, num_filters=64, filter_size=(3, 3)))
    l4c = convroll(conv(l4b, num_filters=64, filter_size=(3, 3)))
    l4d = conv(l4c, num_filters=128, filter_size=(3, 3))
    l4 = convroll(pool(l4d))

    l5a = convroll(conv(l4, num_filters=64, filter_size=(3, 3)))
    l5b = convroll(conv(l5a, num_filters=64, filter_size=(3, 3)))
    l5c = convroll(conv(l5b, num_filters=64, filter_size=(3, 3)))
    l5d = conv(l5c, num_filters=128, filter_size=(3, 3))
    l5 = convroll(pool(l5d))
    l5f = nn.layers.flatten(l5)

    l6 = nn.layers.DenseLayer(nn.layers.dropout(l5f, p=0.5),
                              num_units=256,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1),
                              nonlinearity=nn_plankton.leaky_relu)
    l6r = dihedral_fast.CyclicRollLayer(l6)

    l7 = nn.layers.DenseLayer(nn.layers.dropout(l6r, p=0.5),
                              num_units=256,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1),
                              nonlinearity=nn_plankton.leaky_relu)
    l7m = dihedral.CyclicPoolLayer(l7, pool_function=nn_plankton.rms)

    l8 = nn.layers.DenseLayer(nn.layers.dropout(l7m, p=0.5),
                              num_units=data.num_classes,
                              nonlinearity=T.nnet.softmax,
                              W=nn_plankton.Orthogonal(1.0))

    return [l0], l8
Exemplo n.º 2
0
def build_model():
    l0 = nn.layers.InputLayer((batch_size, 1, patch_size[0], patch_size[1]))
    l0c = dihedral.CyclicSliceLayer(l0)

    l1a = Conv2DLayer(l0c, num_filters=32, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu)
    l1b = Conv2DLayer(l1a, num_filters=16, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu)
    l1 = MaxPool2DLayer(l1b, ds=(3, 3), strides=(2, 2))
    l1r = dihedral.CyclicConvRollLayer(l1)

    l2a = Conv2DLayer(l1r, num_filters=64, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu)
    l2b = Conv2DLayer(l2a, num_filters=32, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu)
    l2 = MaxPool2DLayer(l2b, ds=(3, 3), strides=(2, 2))
    l2r = dihedral.CyclicConvRollLayer(l2)

    l3a = Conv2DLayer(l2r, num_filters=128, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu, untie_biases=True)
    l3b = Conv2DLayer(l3a, num_filters=128, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu, untie_biases=True)
    l3c = Conv2DLayer(l3b, num_filters=64, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu, untie_biases=True)
    l3 = MaxPool2DLayer(l3c, ds=(3, 3), strides=(2, 2))
    l3r = dihedral.CyclicConvRollLayer(l3)

    l4a = Conv2DLayer(l3r, num_filters=256, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu, untie_biases=True)
    l4b = Conv2DLayer(l4a, num_filters=256, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu, untie_biases=True)
    l4c = Conv2DLayer(l4b, num_filters=128, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu, untie_biases=True)    
    l4 = MaxPool2DLayer(l4c, ds=(3, 3), strides=(2, 2))
    l4r = dihedral.CyclicConvRollLayer(l4)

    l5a = Conv2DLayer(l4r, num_filters=256, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu, untie_biases=True)
    l5b = Conv2DLayer(l5a, num_filters=256, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu, untie_biases=True)
    l5c = Conv2DLayer(l5b, num_filters=128, filter_size=(3, 3), border_mode="same", W=nn_plankton.Conv2DOrthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu, untie_biases=True)    
    l5 = MaxPool2DLayer(l5c, ds=(3, 3), strides=(2, 2))
    l5r = dihedral.CyclicConvRollLayer(l5)
    l5f = nn.layers.flatten(l5r)

    l6 = nn.layers.DenseLayer(nn.layers.dropout(l5f, p=0.5), num_units=256, W=nn_plankton.Orthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu)
    l6r = dihedral.CyclicRollLayer(l6)

    l7 = nn.layers.DenseLayer(nn.layers.dropout(l6r, p=0.5), num_units=256, W=nn_plankton.Orthogonal(1.0), b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu)
    l7m = dihedral.CyclicPoolLayer(l7, pool_function=nn_plankton.rms)

    l8 = nn.layers.DenseLayer(nn.layers.dropout(l7m, p=0.5), num_units=data.num_classes, nonlinearity=T.nnet.softmax, W=nn_plankton.Orthogonal(1.0))

    l_resume = l2
    l_exclude = l2

    return [l0], l8, l_resume, l_exclude
Exemplo n.º 3
0
def build_model(input_layer=None):

    #################
    # Regular model #
    #################
    input_size = data_sizes["sliced:data:singleslice"]

    if input_layer:
        l0 = input_layer
    else:
        l0 = nn.layers.InputLayer(input_size)
    l0c = dihedral.CyclicSliceLayer(l0)

    l1a = nn.layers.dnn.Conv2DDNNLayer(
        l0c,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=64,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l1b = nn.layers.dnn.Conv2DDNNLayer(
        l1a,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=64,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l1 = nn.layers.dnn.MaxPool2DDNNLayer(l1b, pool_size=(2, 2), stride=(2, 2))
    l1r = dihedral_fast.CyclicConvRollLayer(l1)

    l2a = nn.layers.dnn.Conv2DDNNLayer(
        l1r,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=128,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l2b = nn.layers.dnn.Conv2DDNNLayer(
        l2a,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=128,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l2 = nn.layers.dnn.MaxPool2DDNNLayer(l2b, pool_size=(2, 2), stride=(2, 2))
    l2r = dihedral_fast.CyclicConvRollLayer(l2)

    l3a = nn.layers.dnn.Conv2DDNNLayer(
        l2r,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=256,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l3b = nn.layers.dnn.Conv2DDNNLayer(
        l3a,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=256,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l3c = nn.layers.dnn.Conv2DDNNLayer(
        l3b,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=256,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l3 = nn.layers.dnn.MaxPool2DDNNLayer(l3c, pool_size=(2, 2), stride=(2, 2))
    l3r = dihedral_fast.CyclicConvRollLayer(l3)

    l4a = nn.layers.dnn.Conv2DDNNLayer(
        l3r,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=512,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l4b = nn.layers.dnn.Conv2DDNNLayer(
        l4a,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=512,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l4c = nn.layers.dnn.Conv2DDNNLayer(
        l4b,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        filter_size=(3, 3),
        num_filters=512,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l4 = nn.layers.dnn.MaxPool2DDNNLayer(l4c, pool_size=(2, 2), stride=(2, 2))
    l4r = dihedral_fast.CyclicConvRollLayer(l4)

    l5a = nn.layers.dnn.Conv2DDNNLayer(
        l4r,
        W=nn.init.Orthogonal("relu"),
        filter_size=(3, 3),
        num_filters=512,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l5b = nn.layers.dnn.Conv2DDNNLayer(
        l5a,
        W=nn.init.Orthogonal("relu"),
        filter_size=(3, 3),
        num_filters=512,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l5c = nn.layers.dnn.Conv2DDNNLayer(
        l5b,
        W=nn.init.Orthogonal("relu"),
        filter_size=(3, 3),
        num_filters=512,
        stride=(1, 1),
        pad="same",
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l5 = nn.layers.dnn.MaxPool2DDNNLayer(l5c, pool_size=(2, 2), stride=(2, 2))
    l5r = dihedral_fast.CyclicConvRollLayer(l5)
    l5f = nn.layers.FlattenLayer(l5r)
    l5m = dihedral.CyclicPoolLayer(l5f, pool_function=rms)

    #    l5drop = nn.layers.dropout(l5m, p=0.5)

    # Systole Dense layers
    ldsys1 = nn.layers.DenseLayer(
        l5m,
        num_units=256,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        nonlinearity=nn.nonlinearities.very_leaky_rectify)

    ldsys1drop = nn.layers.dropout(ldsys1, p=0.5)
    ldsys2 = nn.layers.DenseLayer(
        ldsys1drop,
        num_units=512,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        nonlinearity=nn.nonlinearities.very_leaky_rectify)

    ldsys2drop = nn.layers.dropout(ldsys2, p=0.5)
    ldsys3mu = nn.layers.DenseLayer(ldsys2drop,
                                    num_units=1,
                                    W=nn.init.Orthogonal("relu"),
                                    b=nn.init.Constant(200.0),
                                    nonlinearity=None)
    ldsys3sigma = nn.layers.DenseLayer(ldsys2drop,
                                       num_units=1,
                                       W=nn.init.Orthogonal("relu"),
                                       b=nn.init.Constant(100.0),
                                       nonlinearity=lb_softplus(3))
    ldsys3musigma = nn.layers.ConcatLayer([ldsys3mu, ldsys3sigma], axis=1)

    l_systole = layers.MuSigmaErfLayer(ldsys3musigma)

    # Diastole Dense layers
    lddia1 = nn.layers.DenseLayer(
        l5m,
        num_units=256,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        nonlinearity=nn.nonlinearities.very_leaky_rectify)

    lddia1drop = nn.layers.dropout(lddia1, p=0.5)
    lddia2 = nn.layers.DenseLayer(
        lddia1drop,
        num_units=512,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        nonlinearity=nn.nonlinearities.very_leaky_rectify)

    lddia2drop = nn.layers.dropout(lddia2, p=0.5)
    lddia3mu = nn.layers.DenseLayer(lddia2drop,
                                    num_units=1,
                                    W=nn.init.Orthogonal("relu"),
                                    b=nn.init.Constant(200.0),
                                    nonlinearity=None)
    lddia3sigma = nn.layers.DenseLayer(lddia2drop,
                                       num_units=1,
                                       W=nn.init.Orthogonal("relu"),
                                       b=nn.init.Constant(100.0),
                                       nonlinearity=lb_softplus(3))
    lddia3musigma = nn.layers.ConcatLayer([lddia3mu, lddia3sigma], axis=1)

    l_diastole = layers.MuSigmaErfLayer(lddia3musigma)

    return {
        "inputs": {
            "sliced:data:singleslice": l0
        },
        "outputs": {
            "systole": l_systole,
            "diastole": l_diastole,
        },
        "regularizable": {
            ldsys1: l2_weight,
            ldsys2: l2_weight,
            ldsys3mu: l2_weight_out,
            ldsys3sigma: l2_weight_out,
            lddia1: l2_weight,
            lddia2: l2_weight,
            lddia3mu: l2_weight_out,
            lddia3sigma: l2_weight_out,
        },
        "meta_outputs": {
            "systole": ldsys2,
            "diastole": lddia2,
        }
    }
Exemplo n.º 4
0
def build_model():
    # variable scale part
    l0_variable = nn.layers.InputLayer(
        (batch_size, 1, patch_sizes[0][0], patch_sizes[0][1]))
    l0c = dihedral.CyclicSliceLayer(l0_variable)

    l1a = Conv2DLayer(l0c,
                      num_filters=32,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l1b = Conv2DLayer(l1a,
                      num_filters=16,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l1 = MaxPool2DLayer(l1b, ds=(3, 3), strides=(2, 2))
    l1r = dihedral_fast.CyclicConvRollLayer(l1)

    l2a = Conv2DLayer(l1r,
                      num_filters=64,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l2b = Conv2DLayer(l2a,
                      num_filters=32,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l2 = MaxPool2DLayer(l2b, ds=(3, 3), strides=(2, 2))
    l2r = dihedral_fast.CyclicConvRollLayer(l2)

    l3a = Conv2DLayer(l2r,
                      num_filters=128,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l3b = Conv2DLayer(l3a,
                      num_filters=128,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l3c = Conv2DLayer(l3b,
                      num_filters=64,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l3 = MaxPool2DLayer(l3c, ds=(3, 3), strides=(2, 2))
    l3r = dihedral_fast.CyclicConvRollLayer(l3)

    l4a = Conv2DLayer(l3r,
                      num_filters=256,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l4b = Conv2DLayer(l4a,
                      num_filters=256,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l4c = Conv2DLayer(l4b,
                      num_filters=128,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l4 = MaxPool2DLayer(l4c, ds=(3, 3), strides=(2, 2))
    l4r = dihedral_fast.CyclicConvRollLayer(l4)
    l4f = nn.layers.flatten(l4r)

    l5 = nn.layers.DenseLayer(nn.layers.dropout(l4f, p=0.5),
                              num_units=1024,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1),
                              nonlinearity=nn_plankton.leaky_relu)
    l5fp = nn.layers.FeaturePoolLayer(l5, ds=2)
    l5m = dihedral.CyclicPoolLayer(l5fp, pool_function=nn_plankton.rms)

    l6 = nn.layers.DenseLayer(nn.layers.dropout(l5m, p=0.5),
                              num_units=1024,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1),
                              nonlinearity=nn_plankton.leaky_relu)
    l6fp = nn.layers.FeaturePoolLayer(l6, ds=2)

    l_variable = l6fp

    # fixed scale part
    l0_fixed = nn.layers.InputLayer(
        (batch_size, 1, patch_sizes[1][0], patch_sizes[1][1]))
    l0c = dihedral.CyclicSliceLayer(l0_fixed)

    l1a = Conv2DLayer(l0c,
                      num_filters=16,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l1b = Conv2DLayer(l1a,
                      num_filters=8,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l1 = MaxPool2DLayer(l1b, ds=(3, 3), strides=(2, 2))
    l1r = dihedral_fast.CyclicConvRollLayer(l1)

    l2a = Conv2DLayer(l1r,
                      num_filters=32,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l2b = Conv2DLayer(l2a,
                      num_filters=16,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l2 = MaxPool2DLayer(l2b, ds=(3, 3), strides=(2, 2))
    l2r = dihedral_fast.CyclicConvRollLayer(l2)

    l3a = Conv2DLayer(l2r,
                      num_filters=64,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l3b = Conv2DLayer(l3a,
                      num_filters=64,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l3c = Conv2DLayer(l3b,
                      num_filters=32,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1),
                      nonlinearity=nn_plankton.leaky_relu,
                      untie_biases=True)
    l3 = MaxPool2DLayer(l3c, ds=(3, 3), strides=(2, 2))
    l3r = dihedral_fast.CyclicConvRollLayer(l3)
    l3f = nn.layers.flatten(l3r)

    l4 = nn.layers.DenseLayer(nn.layers.dropout(l3f, p=0.5),
                              num_units=512,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1),
                              nonlinearity=nn_plankton.leaky_relu)
    l4fp = nn.layers.FeaturePoolLayer(l4, ds=2)
    l4m = dihedral.CyclicPoolLayer(l4fp, pool_function=nn_plankton.rms)

    l5 = nn.layers.DenseLayer(nn.layers.dropout(l4m, p=0.5),
                              num_units=512,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1),
                              nonlinearity=nn_plankton.leaky_relu)
    l5fp = nn.layers.FeaturePoolLayer(l5, ds=2)

    l_fixed = l5fp

    # merge the parts
    l_merged = nn.layers.concat([l_variable, l_fixed])

    l7 = nn.layers.DenseLayer(nn.layers.dropout(l_merged, p=0.5),
                              num_units=data.num_classes,
                              nonlinearity=T.nnet.softmax,
                              W=nn_plankton.Orthogonal(1.0))

    return [l0_variable, l0_fixed], l7
Exemplo n.º 5
0
def build_model():
    # variable scale part
    l0_variable = nn.layers.InputLayer(
        (batch_size, 1, patch_sizes[0][0], patch_sizes[0][1]))
    l0c = dihedral.CyclicSliceLayer(l0_variable)

    l1a = Conv2DLayer(l0c,
                      num_filters=32,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l1b = Conv2DLayer(l1a,
                      num_filters=32,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l1 = MaxPool2DLayer(l1b, ds=(3, 3), strides=(2, 2))

    l2a = Conv2DLayer(l1,
                      num_filters=64,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l2b = Conv2DLayer(l2a,
                      num_filters=64,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l2 = MaxPool2DLayer(l2b, ds=(3, 3), strides=(2, 2))

    l3a = Conv2DLayer(l2,
                      num_filters=128,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l3b = Conv2DLayer(l3a,
                      num_filters=128,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l3c = Conv2DLayer(l3b,
                      num_filters=128,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l3 = MaxPool2DLayer(l3c, ds=(3, 3), strides=(2, 2))

    l4a = Conv2DLayer(l3,
                      num_filters=256,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l4b = Conv2DLayer(l4a,
                      num_filters=256,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l4c = Conv2DLayer(l4b,
                      num_filters=256,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l4 = MaxPool2DLayer(l4c, ds=(3, 3), strides=(2, 2))
    l4f = nn.layers.flatten(l4)

    l5 = nn.layers.DenseLayer(nn.layers.dropout(l4f, p=0.5),
                              num_units=256,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1))
    l5r = dihedral.CyclicRollLayer(l5)

    l6 = nn.layers.DenseLayer(nn.layers.dropout(l5r, p=0.5),
                              num_units=256,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1))
    l_variable = dihedral.CyclicPoolLayer(l6, pool_function=nn_plankton.rms)

    # fixed scale part
    l0_fixed = nn.layers.InputLayer(
        (batch_size, 1, patch_sizes[1][0], patch_sizes[1][1]))
    l0c = dihedral.CyclicSliceLayer(l0_fixed)

    l1a = Conv2DLayer(l0c,
                      num_filters=16,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l1b = Conv2DLayer(l1a,
                      num_filters=16,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l1 = MaxPool2DLayer(l1b, ds=(3, 3), strides=(2, 2))

    l2a = Conv2DLayer(l1,
                      num_filters=32,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l2b = Conv2DLayer(l2a,
                      num_filters=32,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l2 = MaxPool2DLayer(l2b, ds=(3, 3), strides=(2, 2))

    l3a = Conv2DLayer(l2,
                      num_filters=64,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l3b = Conv2DLayer(l3a,
                      num_filters=64,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l3c = Conv2DLayer(l3b,
                      num_filters=64,
                      filter_size=(3, 3),
                      border_mode="same",
                      W=nn_plankton.Conv2DOrthogonal(1.0),
                      b=nn.init.Constant(0.1))
    l3 = MaxPool2DLayer(l3c, ds=(3, 3), strides=(2, 2))
    l3f = nn.layers.flatten(l3)

    l4 = nn.layers.DenseLayer(nn.layers.dropout(l3f, p=0.5),
                              num_units=128,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1))
    l4r = dihedral.CyclicRollLayer(l4)

    l5 = nn.layers.DenseLayer(nn.layers.dropout(l4r, p=0.5),
                              num_units=128,
                              W=nn_plankton.Orthogonal(1.0),
                              b=nn.init.Constant(0.1))
    l_fixed = dihedral.CyclicPoolLayer(l5, pool_function=nn_plankton.rms)

    # merge the parts
    l_merged = nn.layers.concat([l_variable, l_fixed])

    l7 = nn.layers.DenseLayer(nn.layers.dropout(l_merged, p=0.5),
                              num_units=data.num_classes,
                              nonlinearity=T.nnet.softmax,
                              W=nn_plankton.Orthogonal(1.0))

    return [l0_variable, l0_fixed], l7