Ejemplo n.º 1
0
def build_model():
    l0 = nn.layers.InputLayer((batch_size, data.num_classes))

    l0_size = nn.layers.InputLayer((batch_size, 7))
    l1_size = nn.layers.DenseLayer(l0_size,
                                   num_units=80,
                                   W=nn_plankton.Orthogonal('relu'),
                                   b=nn.init.Constant(0.1))
    l2_size = nn.layers.DenseLayer(l1_size,
                                   num_units=80,
                                   W=nn_plankton.Orthogonal('relu'),
                                   b=nn.init.Constant(0.1))
    l3_size = nn.layers.DenseLayer(l2_size,
                                   num_units=data.num_classes,
                                   W=nn_plankton.Orthogonal(),
                                   b=nn.init.Constant(0.1),
                                   nonlinearity=None)

    l1 = nn_plankton.NonlinLayer(l0, T.log)
    ltot = nn.layers.ElemwiseSumLayer([l1, l3_size])

    # norm_by_sum = lambda x: x / x.sum(1).dimshuffle(0, "x")
    lout = nn_plankton.NonlinLayer(ltot, nonlinearity=T.nnet.softmax)

    return [l0, l0_size], lout
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
Ejemplo n.º 3
0
    def __init__(self, classes = 20):
        self.output_dim = classes
        self.batch_size = 128

        #layers
        self.l_in = nn.layers.InputLayer(shape=(self.batch_size, 3, 300, 300))

        self.C1 = Conv2DLayer(self.l_in, 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)
        self.C2 = Conv2DLayer(self.C1, 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)
        self.M1 = MaxPool2DLayer(self.C2, ds=(3, 3), strides=(2, 2))
        self.D1 = nn.layers.DropoutLayer(self.M1, p=0.5)

        self.C3 = Conv2DLayer(self.D1, 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)
        self.C4 = Conv2DLayer(self.C3, 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)
        self.M2 = MaxPool2DLayer(self.C4, ds=(3, 3), strides=(2, 2))
        self.D2 = nn.layers.DropoutLayer(self.M2, p=0.5)

        self.C5 = Conv2DLayer(self.D2, 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)
        self.C6 = Conv2DLayer(self.C5, 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)
        self.M3 = MaxPool2DLayer(self.C6, ds=(3, 3), strides=(2, 2))
        self.D3 = nn.layers.DropoutLayer(self.M3, p=0.5)

        self.FC1 = nn.layers.DenseLayer(self.D3, num_units=256, W=nn_plankton.Orthogonal(1.0),
                             b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu)
        self.D4 = nn.layers.DropoutLayer(self.FC1, p=0.5)
        self.FC2 = nn.layers.DenseLayer(self.D4, num_units=256, W=nn_plankton.Orthogonal(1.0),
                             b=nn.init.Constant(0.1), nonlinearity=nn_plankton.leaky_relu)
        self.output = nn.layers.DenseLayer(self.FC2, num_units=self.output_dim, W=nn_plankton.Orthogonal(1.0),
                             b=nn.init.Constant(0.1), nonlinearity=nn.nonlinearities.softmax)
        self.objective = nn.objectives.Objective(self.output, 
                                    loss_function=nn.objectives.categorical_crossentropy)


        self.loss = self.objective.get_loss()#self.x, target=self.y)
        self.probabilities = self.output.get_output(self.l_in.input_var, deterministic=True)
        self.pred = T.argmax(self.output.get_output(self.l_in.input_var, deterministic=True), axis=1)
        self.errors  = T.mean(T.eq(self.pred, self.objective.target_var), dtype=theano.config.floatX)

        #get weights
        self.all_params = nn.layers.get_all_params(self.output)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def build_model():
    l0 = nn.layers.InputLayer((batch_size, 1, patch_sizes[0][0], patch_sizes[0][1]))
    l0_45 = nn.layers.InputLayer((batch_size, 1, patch_sizes[1][0], patch_sizes[1][1]))
    l0_both = nn.layers.concat([l0, l0_45], axis=0)  # stack both
    l0c = dihedral.CyclicSliceLayer(l0_both)

    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.DihedralPoolLayer(l5fp, pool_function=nn_plankton.rms)  # reusing the dihedral pool layer here for 8-way cyclic pooling. Ew!

    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)

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

    return [l0, l0_45], l7
Ejemplo n.º 6
0
    def __init__(self, classes=212):
        self.output_dim = classes
        self.batch_size = 128

        #layers using amazon instance with GRID K520
        self.l_in = nn.layers.InputLayer(shape=(self.batch_size, 3, 100, 100))

        #self.C1 = nn.layers.Conv2DLayer(self.l_in, 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)
        #self.C2 = nn.layers.Conv2DLayer(self.C1, 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)
        #self.M1 = nn.layers.pool.MaxPool2DLayer(self.C2, pool_size=3, stride=2)
        ##self.D1 = nn.layers.DropoutLayer(self.M1, p=0.5)

        #self.C3 = nn.layers.Conv2DLayer(self.M1, 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)
        #self.C4 = nn.layers.Conv2DLayer(self.C3, 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)
        #self.M2 = nn.layers.pool.MaxPool2DLayer(self.C4, pool_size=3, stride=2)
        ##self.D2 = nn.layers.DropoutLayer(self.M2, p=0.5)

        # due to mem contrainst, this went from 64,128,256,512,512 to what it is now

        #self.C5 = nn.layers.Conv2DLayer(self.M2, num_filters=256, filter_size=(3, 3), border_mode="same",
        self.C5 = nn.layers.Conv2DLayer(self.l_in,
                                        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)
        self.C6 = nn.layers.Conv2DLayer(self.C5,
                                        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)
        self.C7 = nn.layers.Conv2DLayer(self.C6,
                                        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)
        self.M3 = nn.layers.pool.MaxPool2DLayer(self.C7, pool_size=3, stride=2)

        self.C8 = nn.layers.Conv2DLayer(self.M3,
                                        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)
        self.C9 = nn.layers.Conv2DLayer(self.C8,
                                        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)
        self.C10 = nn.layers.Conv2DLayer(self.C9,
                                         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)
        self.M4 = nn.layers.pool.MaxPool2DLayer(self.C10,
                                                pool_size=3,
                                                stride=2)

        self.C11 = nn.layers.Conv2DLayer(self.M4,
                                         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)
        self.C12 = nn.layers.Conv2DLayer(self.C11,
                                         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)
        self.C13 = nn.layers.Conv2DLayer(self.C12,
                                         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)
        self.M5 = nn.layers.pool.MaxPool2DLayer(self.C13,
                                                pool_size=3,
                                                stride=2)

        self.FC1 = nn.layers.DenseLayer(self.M5,
                                        num_units=4096,
                                        W=nn_plankton.Orthogonal(1.0),
                                        b=nn.init.Constant(0.1),
                                        nonlinearity=nn_plankton.leaky_relu)
        self.D1 = nn.layers.DropoutLayer(self.FC1, p=0.5)
        self.FC2 = nn.layers.DenseLayer(self.D1,
                                        num_units=4096,
                                        W=nn_plankton.Orthogonal(1.0),
                                        b=nn.init.Constant(0.1),
                                        nonlinearity=nn_plankton.leaky_relu)
        self.D2 = nn.layers.DropoutLayer(self.FC2, p=0.5)
        self.FC3 = nn.layers.DenseLayer(self.D2,
                                        num_units=4096,
                                        W=nn_plankton.Orthogonal(1.0),
                                        b=nn.init.Constant(0.1),
                                        nonlinearity=nn_plankton.leaky_relu)
        self.D3 = nn.layers.DropoutLayer(self.FC3, p=0.5)

        self.output_layer = nn.layers.DenseLayer(
            self.D3,
            num_units=self.output_dim,
            W=nn_plankton.Orthogonal(1.0),
            b=nn.init.Constant(0.1),
            nonlinearity=nn.nonlinearities.softmax)
        self.objective = nn.objectives.Objective(
            self.output_layer,
            loss_function=nn.objectives.categorical_crossentropy)

        self.loss = self.objective.get_loss()  #self.x, target=self.y)
        self.probabilities = self.output_layer.get_output(self.l_in.input_var,
                                                          deterministic=True)
        self.pred = T.argmax(self.output_layer.get_output(self.l_in.input_var,
                                                          deterministic=True),
                             axis=1)

        #get weights
        self.all_params = nn.layers.get_all_params(self.output_layer)
Ejemplo n.º 7
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
Ejemplo n.º 8
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