def build_model(l_in=None):
    stage_depths = [2, 4, 8, 10, 4]
    stage_sizes = [64, 96, 128, 192, 256]

    l_in = nn.layers.InputLayer((None, 30) + patch_size) if not l_in else l_in
    l = l_in
    for i in xrange(len(stage_sizes)):
        # First layer to change dimensions
        l = conv3(l, num_filters=stage_sizes[i])
        for _ in range(stage_depths[i] - 1):
            l = nn_heart.highway_conv3(l)
        l = max_pool(l)

    l_d01 = nn.layers.DenseLayer(l, num_units=512, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1), nonlinearity=nn.nonlinearities.very_leaky_rectify)

    l_d02 = nn.layers.DenseLayer(nn.layers.dropout(l_d01), num_units=512, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1), nonlinearity=nn.nonlinearities.very_leaky_rectify)

    mu0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02), num_units=1, W=nn.init.Orthogonal(),
                               b=nn.init.Constant(50), nonlinearity=nn_heart.lb_softplus())
    sigma0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02), num_units=1, W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(10), nonlinearity=nn_heart.lb_softplus())
    l_cdf0 = nn_heart.NormalCDFLayer(mu0, sigma0, sigma_logscale=False, mu_logscale=False)

    # ---------------------------------------------------------------

    l_d11 = nn.layers.DenseLayer(l, num_units=512, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1), nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l_d12 = nn.layers.DenseLayer(nn.layers.dropout(l_d11), num_units=512, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1), nonlinearity=nn.nonlinearities.very_leaky_rectify)

    mu1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12), num_units=1, W=nn.init.Orthogonal(),
                               b=nn.init.Constant(100), nonlinearity=nn_heart.lb_softplus())
    sigma1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12), num_units=1, W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(10), nonlinearity=nn_heart.lb_softplus())
    l_cdf1 = nn_heart.NormalCDFLayer(mu1, sigma1, sigma_logscale=False, mu_logscale=False)

    l_outs = [l_cdf0, l_cdf1]
    l_top = nn.layers.MergeLayer(l_outs)

    l_target_mu0 = nn.layers.InputLayer((None, 1))
    l_target_mu1 = nn.layers.InputLayer((None, 1))
    l_targets = [l_target_mu0, l_target_mu1]
    dense_layers = [l_d01, l_d02, l_d11, l_d12, mu0, sigma0, mu0, mu1]
    mu_layers = [mu0, mu1]
    sigma_layers = [sigma0, sigma1]

    return namedtuple('Model', ['l_ins', 'l_outs', 'l_targets', 'l_top', 'dense_layers', 'mu_layers', 'sigma_layers'])(
        [l_in], l_outs, l_targets,
        l_top, dense_layers, mu_layers, sigma_layers)
Esempio n. 2
0
def build_model(l_in=None):
    l_in = nn.layers.InputLayer((None, 30) + patch_size) if not l_in else l_in

    l = conv3(l_in, num_filters=128)
    l = conv3(l, num_filters=128)

    l = max_pool(l)

    l = conv3(l, num_filters=128)
    l = conv3(l, num_filters=128)

    l = max_pool(l)

    l = conv3(l, num_filters=256)
    l = conv3(l, num_filters=256)
    l = conv3(l, num_filters=256)

    l = max_pool(l)

    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)

    l = max_pool(l)

    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)

    l = max_pool(l)

    l_w = nn.layers.DenseLayer(nn.layers.dropout(l), num_units=1024, W=nn.init.Orthogonal("relu"),
                               b=nn.init.Constant(0.1))

    l_d01 = nn.layers.DenseLayer(l, num_units=1024, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1))

    l_d02 = nn.layers.DenseLayer(nn.layers.dropout(l_d01), num_units=1024, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1))

    l_d02 = nn_heart.MultLayer(l_d02, l_w)

    mu0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02), num_units=1, W=nn.init.Orthogonal(),
                               b=nn.init.Constant(50), nonlinearity=nn_heart.lb_softplus())
    sigma0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02), num_units=1, W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(10), nonlinearity=nn_heart.lb_softplus())
    l_cdf0 = nn_heart.NormalCDFLayer(mu0, sigma0, sigma_logscale=False, mu_logscale=False)

    # ---------------------------------------------------------------

    l_d11 = nn.layers.DenseLayer(l, num_units=1024, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1))
    l_d12 = nn.layers.DenseLayer(nn.layers.dropout(l_d11), num_units=1024, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1))

    l_d12 = nn_heart.MultLayer(l_d12, l_w)

    mu1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12), num_units=1, W=nn.init.Orthogonal(),
                               b=nn.init.Constant(100), nonlinearity=nn_heart.lb_softplus())
    sigma1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12), num_units=1, W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(10), nonlinearity=nn_heart.lb_softplus())
    l_cdf1 = nn_heart.NormalCDFLayer(mu1, sigma1, sigma_logscale=False, mu_logscale=False)

    l_outs = [l_cdf0, l_cdf1]
    l_top = nn.layers.MergeLayer(l_outs)

    l_target_mu0 = nn.layers.InputLayer((None, 1))
    l_target_mu1 = nn.layers.InputLayer((None, 1))
    l_targets = [l_target_mu0, l_target_mu1]
    dense_layers = [l_w, l_d01, l_d02, l_d11, l_d12, mu0, sigma0, mu0, mu1]
    mu_layers = [mu0, mu1]
    sigma_layers = [sigma0, sigma1]

    return namedtuple('Model', ['l_ins', 'l_outs', 'l_targets', 'l_top', 'dense_layers', 'mu_layers', 'sigma_layers'])(
        [l_in], l_outs, l_targets,
        l_top, dense_layers, mu_layers, sigma_layers)
Esempio n. 3
0
def build_model(l_in=None):
    l_in = nn.layers.InputLayer((None, 30) + patch_size) if not l_in else l_in

    l = conv3(l_in, num_filters=128)
    l = conv3(l, num_filters=128)

    l = max_pool(l)

    l = conv3(l, num_filters=128)
    l = conv3(l, num_filters=128)

    l = max_pool(l)

    l = conv3(l, num_filters=256)
    l = conv3(l, num_filters=256)
    l = conv3(l, num_filters=256)

    l = max_pool(l)

    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)

    l = max_pool(l)

    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)

    l = max_pool(l)

    l_d01 = nn.layers.DenseLayer(l, num_units=1024, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1), nonlinearity=None)
    l_d01 = nn.layers.FeaturePoolLayer(l_d01, pool_size=2)

    l_d02 = nn.layers.DenseLayer(nn.layers.dropout(l_d01), num_units=1024, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1), nonlinearity=None)
    l_d02 = nn.layers.FeaturePoolLayer(l_d02, pool_size=2)

    mu0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02), num_units=1, W=nn.init.Orthogonal(),
                               b=nn.init.Constant(50), nonlinearity=nn_heart.lb_softplus())
    sigma0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02), num_units=1, W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(10), nonlinearity=nn_heart.lb_softplus())
    l_cdf0 = nn_heart.NormalCDFLayer(mu0, sigma0, sigma_logscale=False, mu_logscale=False)

    # ---------------------------------------------------------------

    l_d11 = nn.layers.DenseLayer(l, num_units=1024, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1), nonlinearity=None)
    l_d11 = nn.layers.FeaturePoolLayer(l_d11, pool_size=2)

    l_d12 = nn.layers.DenseLayer(nn.layers.dropout(l_d11), num_units=1024, W=nn.init.Orthogonal("relu"),
                                 b=nn.init.Constant(0.1), nonlinearity=None)
    l_d12 = nn.layers.FeaturePoolLayer(l_d12, pool_size=2)

    mu1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12), num_units=1, W=nn.init.Orthogonal(),
                               b=nn.init.Constant(100), nonlinearity=nn_heart.lb_softplus())
    sigma1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12), num_units=1, W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(10), nonlinearity=nn_heart.lb_softplus())
    l_cdf1 = nn_heart.NormalCDFLayer(mu1, sigma1, sigma_logscale=False, mu_logscale=False)

    l_outs = [l_cdf0, l_cdf1]
    l_top = nn.layers.MergeLayer(l_outs)

    l_target_mu0 = nn.layers.InputLayer((None, 1))
    l_target_mu1 = nn.layers.InputLayer((None, 1))
    l_targets = [l_target_mu0, l_target_mu1]
    dense_layers = [l_d01, l_d02, l_d11, l_d12, mu0, sigma0, mu0, mu1]
    mu_layers = [mu0, mu1]
    sigma_layers = [sigma0, sigma1]

    return namedtuple('Model', ['l_ins', 'l_outs', 'l_targets', 'l_top', 'dense_layers', 'mu_layers', 'sigma_layers'])(
        [l_in], l_outs, l_targets,
        l_top, dense_layers, mu_layers, sigma_layers)
def build_model(l_in=None):
    l_in = nn.layers.InputLayer((None, 30) + patch_size) if not l_in else l_in

    l = conv3(l_in, num_filters=64)
    l = conv3(l, num_filters=64)

    l = max_pool(l)

    l = conv3(l, num_filters=128)
    l = conv3(l, num_filters=128)

    l = max_pool(l)

    l = conv3(l, num_filters=256)
    l = conv3(l, num_filters=256)
    l = conv3(l, num_filters=256)

    l = max_pool(l)

    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)

    l = max_pool(l)

    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)

    l = max_pool(l)

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

    mu0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02, p=0.5),
                               num_units=1,
                               W=nn.init.Orthogonal(),
                               b=nn.init.Constant(100),
                               nonlinearity=nn_heart.lb_softplus())
    sigma0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02, p=0.5),
                                  num_units=1,
                                  W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(20),
                                  nonlinearity=nn_heart.lb_softplus())
    l_cdf0 = nn_heart.NormalCDFLayer(mu0, sigma0)

    # ---------------------------------------------------------------

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

    mu1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12, p=0.5),
                               num_units=1,
                               W=nn.init.Orthogonal(),
                               b=nn.init.Constant(150),
                               nonlinearity=nn_heart.lb_softplus())
    sigma1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12, p=0.5),
                                  num_units=1,
                                  W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(20),
                                  nonlinearity=nn_heart.lb_softplus())
    l_cdf1 = nn_heart.NormalCDFLayer(mu1, sigma1)

    l_outs = [l_cdf0, l_cdf1]
    l_top = nn.layers.MergeLayer(l_outs)

    l_target_mu0 = nn.layers.InputLayer((None, 1))
    l_target_mu1 = nn.layers.InputLayer((None, 1))
    l_targets = [l_target_mu0, l_target_mu1]
    mu_layers = [mu0, mu1]
    sigma_layers = [sigma0, sigma1]

    return namedtuple(
        'Model',
        ['l_ins', 'l_outs', 'l_targets', 'l_top', 'mu_layers', 'sigma_layers'
         ])([l_in], l_outs, l_targets, l_top, mu_layers, sigma_layers)
def build_model(l_in=None):
    l_in = nn.layers.InputLayer((None, 30) + patch_size) if not l_in else l_in

    l = conv3(l_in, num_filters=128)
    l = conv3(l, num_filters=128)

    l = max_pool(l)

    l = conv3(l, num_filters=128)
    l = conv3(l, num_filters=128)

    l = max_pool(l)

    l = conv3(l, num_filters=256)
    l = conv3(l, num_filters=256)
    l = conv3(l, num_filters=256)

    l = max_pool(l)

    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)

    l = max_pool(l)

    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)
    l = conv3(l, num_filters=512)

    l = max_pool(l)

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

    mu0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02, p=0.5), num_units=1, W=nn.init.Orthogonal(),
                               b=nn.init.Constant(100), nonlinearity=nn_heart.lb_softplus())
    sigma0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02, p=0.5), num_units=1, W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(20), nonlinearity=nn_heart.lb_softplus())
    l_cdf0 = nn_heart.NormalCDFLayer(mu0, sigma0)

    # ---------------------------------------------------------------

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

    mu1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12, p=0.5), num_units=1, W=nn.init.Orthogonal(),
                               b=nn.init.Constant(150), nonlinearity=nn_heart.lb_softplus())
    sigma1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12, p=0.5), num_units=1, W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(20), nonlinearity=nn_heart.lb_softplus())
    l_cdf1 = nn_heart.NormalCDFLayer(mu1, sigma1)

    l_outs = [l_cdf0, l_cdf1]
    l_top = nn.layers.MergeLayer(l_outs)

    l_target_mu0 = nn.layers.InputLayer((None, 1))
    l_target_mu1 = nn.layers.InputLayer((None, 1))
    l_targets = [l_target_mu0, l_target_mu1]
    mu_layers = [mu0, mu1]
    sigma_layers = [sigma0, sigma1]

    return namedtuple('Model', ['l_ins', 'l_outs', 'l_targets', 'l_top', 'mu_layers', 'sigma_layers'])([l_in], l_outs,
                                                                                                       l_targets, l_top,
                                                                                                       mu_layers,
                                                                                                       sigma_layers)
def build_model(l_in=None):
    stage_depths = [2, 4, 8, 10, 4]
    stage_sizes = [64, 96, 128, 192, 256]

    l_in = nn.layers.InputLayer((None, 30) + patch_size) if not l_in else l_in
    l = l_in
    for i in xrange(len(stage_sizes)):
        # First layer to change dimensions
        l = conv3(l, num_filters=stage_sizes[i])
        for _ in range(stage_depths[i] - 1):
            l = nn_heart.highway_conv3(l)
        l = max_pool(l)

    l_d01 = nn.layers.DenseLayer(
        l,
        num_units=512,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        nonlinearity=nn.nonlinearities.very_leaky_rectify)

    l_d02 = nn.layers.DenseLayer(
        nn.layers.dropout(l_d01),
        num_units=512,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        nonlinearity=nn.nonlinearities.very_leaky_rectify)

    mu0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02),
                               num_units=1,
                               W=nn.init.Orthogonal(),
                               b=nn.init.Constant(50),
                               nonlinearity=nn_heart.lb_softplus())
    sigma0 = nn.layers.DenseLayer(nn.layers.dropout(l_d02),
                                  num_units=1,
                                  W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(10),
                                  nonlinearity=nn_heart.lb_softplus())
    l_cdf0 = nn_heart.NormalCDFLayer(mu0,
                                     sigma0,
                                     sigma_logscale=False,
                                     mu_logscale=False)

    # ---------------------------------------------------------------

    l_d11 = nn.layers.DenseLayer(
        l,
        num_units=512,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        nonlinearity=nn.nonlinearities.very_leaky_rectify)
    l_d12 = nn.layers.DenseLayer(
        nn.layers.dropout(l_d11),
        num_units=512,
        W=nn.init.Orthogonal("relu"),
        b=nn.init.Constant(0.1),
        nonlinearity=nn.nonlinearities.very_leaky_rectify)

    mu1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12),
                               num_units=1,
                               W=nn.init.Orthogonal(),
                               b=nn.init.Constant(100),
                               nonlinearity=nn_heart.lb_softplus())
    sigma1 = nn.layers.DenseLayer(nn.layers.dropout(l_d12),
                                  num_units=1,
                                  W=nn.init.Orthogonal(),
                                  b=nn.init.Constant(10),
                                  nonlinearity=nn_heart.lb_softplus())
    l_cdf1 = nn_heart.NormalCDFLayer(mu1,
                                     sigma1,
                                     sigma_logscale=False,
                                     mu_logscale=False)

    l_outs = [l_cdf0, l_cdf1]
    l_top = nn.layers.MergeLayer(l_outs)

    l_target_mu0 = nn.layers.InputLayer((None, 1))
    l_target_mu1 = nn.layers.InputLayer((None, 1))
    l_targets = [l_target_mu0, l_target_mu1]
    dense_layers = [l_d01, l_d02, l_d11, l_d12, mu0, sigma0, mu0, mu1]
    mu_layers = [mu0, mu1]
    sigma_layers = [sigma0, sigma1]

    return namedtuple('Model', [
        'l_ins', 'l_outs', 'l_targets', 'l_top', 'dense_layers', 'mu_layers',
        'sigma_layers'
    ])([l_in], l_outs, l_targets, l_top, dense_layers, mu_layers, sigma_layers)