def test_dropout(self):
        import theano, numpy

        inp = ML.Input(100,
                       'inp',
                       decorators=[MD.BinomialDropout(dropoutRatio=0.8)])
        model = inp.network
        model.init()

        data = numpy.random.randn(1, 100).astype(theano.config.floatX) + 1
        out = model["inp"].propagate["train"]({
            "inp.inputs": data
        })["inp.propagate.train"]

        self.assertTrue(sum(out[0] != 0) < sum(data[0] != 0))
def MLP(ls, cost):

    i = ML.Input(28 * 28, name='inp')
    h = ML.Hidden(500,
                  activation=MA.Tanh(),
                  decorators=[MD.BinomialDropout(0.2)],
                  initializations=[MI.GlorotTanhInit()],
                  regularizations=[MR.L1(0), MR.L2(0.0001)],
                  name="hid")
    o = ML.SoftmaxClassifier(10,
                             initializations=[MI.ZerosWeights()],
                             learningScenario=ls,
                             costObject=cost,
                             name="out",
                             regularizations=[MR.L1(0),
                                              MR.L2(0.0001)])

    mlp = i > h > o

    return mlp
Beispiel #3
0
    def __init__(self, ls, cost):
        maxPool = MCONV.MaxPooling2D(3, 3)
        i = MCONV.Input(nbChannels=1, height=100, width=100, name='inp')

        c1 = MCONV.Convolution2D(nbFilters=10,
                                 filterHeight=3,
                                 filterWidth=3,
                                 activation=MA.Max_norm(),
                                 pooler=maxPool,
                                 name="conv1")
        c3 = MCONV.Convolution2D(nbFilters=20,
                                 filterHeight=3,
                                 filterWidth=3,
                                 activation=MA.Max_norm(),
                                 pooler=maxPool,
                                 name="conv3")

        c2 = MCONV.Convolution2D(nbFilters=10,
                                 filterHeight=3,
                                 filterWidth=3,
                                 activation=MA.Max_norm(),
                                 pooler=maxPool,
                                 name="conv2")

        f = MCONV.Flatten(name="flat")
        h = ML.Hidden(2048,
                      activation=MA.Max_norm(),
                      decorators=[MD.BinomialDropout(0.7)],
                      regularizations=[],
                      name="hid")

        o = ML.SoftmaxClassifier(2,
                                 decorators=[],
                                 learningScenario=ls,
                                 costObject=cost,
                                 name="out",
                                 regularizations=[])

        self.model = i > c1 > c3 > c2 > f > h > o
	name = "conv3"
)

c2 = MCONV.Convolution2D( 
	nbFilters = 15,
	filterHeight = 3,
	filterWidth = 3,
	activation = MA.Max_norm(),
	pooler = maxPool,
	name = "conv2"
)
fa = MCONV.Flatten(name="flata")
fb = MCONV.Flatten(name="flatb")
f = MCONV.Flatten(name = "flat")

h = ML.Hidden(2048, activation = MA.Max_norm(), decorators = [MD.BinomialDropout(0.75)], regularizations = [], name = "hid" )
passa = ML.Hidden(1500, activation = MA.Pass(), decorators = [MD.BinomialDropout(0.5)], regularizations = [], name = "pass1" )
passb = ML.Hidden(1500, activation = MA.Pass(), decorators = [MD.BinomialDropout(0.5)], regularizations = [], name = "pass2" )
h2 = ML.Hidden(2048, activation = MA.Max_norm(), decorators = [MD.BinomialDropout(0.75)], regularizations = [], name = "hid2" )
o = ML.SoftmaxClassifier(2, decorators = [], learningScenario = ls, costObject = cost, name = "out", regularizations = [] )

model = i > c1 > c3 > c2 > f > h > h2 > o
c1 > fa > passa > h > h2 > o
c2 > fb > passb >h > h2 > o

tscore = []
vscore = []
tdata = load_data(trainfile)
vdata = load_data(validfile)
vdata = (center(vdata[0]),vdata[1])        
test = load_data(testfile)