简体   繁体   中英

python - Error with Mariana/Theano neural network

I am facing a problem when I start my trainer and I can't figure out the cause.

My input data is of dimension 42 and my output should be one value out of 4.

This is the shape of my training and test set:

Training set: 
input = (1152, 42) target = (1152,)

Training set: input = (1152, 42) target = (1152,)
Test set: input = (384, 42) target = (384,)

This is the construction of my network:

ls = MS.GradientDescent(lr=0.01)
cost = MC.CrossEntropy()

i = ML.Input(42, name='inp')
h = ML.Hidden(23, activation=MA.Sigmoid(), initializations=[MI.GlorotTanhInit()], name="hid")
o = ML.SoftmaxClassifier(4, learningScenario=ls, costObject=cost, name="out")

mlp = i > h > o

And this is the construction of the datasets, trainers and recorders:

trainData = MDM.RandomSeries(distances = train_set[0], next_state = train_set[1])
trainMaps = MDM.DatasetMapper()
trainMaps.mapInput(i, trainData.distances)
trainMaps.mapOutput(o, trainData.next_state)

testData = MDM.RandomSeries(distances = test_set[0], next_state = test_set[1])
testMaps = MDM.DatasetMapper()
testMaps.mapInput(i, testData.distances)
testMaps.mapOutput(o, testData.next_state)

earlyStop = MSTOP.GeometricEarlyStopping(testMaps, patience=100, patienceIncreaseFactor=1.1, significantImprovement=0.00001, outputFunction="score", outputLayer=o)
epochWall = MSTOP.EpochWall(1000)

trainer = MT.DefaultTrainer(
        trainMaps=trainMaps,
        testMaps=testMaps,
        validationMaps=None,
        stopCriteria=[earlyStop, epochWall],
        testFunctionName="testAndAccuracy",
        trainMiniBatchSize=MT.DefaultTrainer.ALL_SET,
        saveIfMurdered=False
    )

recorder = MREC.GGPlot2("MLP", whenToSave = [MREC.SaveMin("test", o.name, "score")], printRate=1, writeRate=1)

trainer.start("MLP", mlp, recorder = recorder)

But the following error is being produced:

Traceback (most recent call last):
  File "nn-mariana.py", line 82, in <module>
    trainer.start("MLP", mlp, recorder = recorder)
  File "SUPRESSED/Mariana/Mariana/training/trainers.py", line 226, in start
    Trainer_ABC.start( self, runName, model, recorder, trainingOrder, moreHyperParameters )
  File "SUPRESSED/Mariana/Mariana/training/trainers.py", line 110, in start
    return self.run(runName, model, recorder, *args, **kwargs)
  File "SUPRESSED/Mariana/Mariana/training/trainers.py", line 410, in run
    outputLayers
  File "SUPRESSED/Mariana/Mariana/training/trainers.py", line 269, in _trainTest
    res = modelFct(output, **kwargs)
  File "SUPRESSED/Mariana/Mariana/network.py", line 47, in __call__
    return self.callTheanoFct(outputLayer, **kwargs)
  File "SUPRESSED/Mariana/Mariana/network.py", line 44, in callTheanoFct
    return self.outputFcts[ol](**kwargs)
  File "SUPRESSED/Mariana/Mariana/wrappers.py", line 110, in __call__
    return self.run(**kwargs)
  File "SUPRESSED/Mariana/Mariana/wrappers.py", line 102, in run
    fres = iter(self.theano_fct(*self.fctInputs.values()))
  File "SUPRESSED/Theano/theano/compile/function_module.py", line 871, in __call__
    storage_map=getattr(self.fn, 'storage_map', None))
  File "SUPRESSED/Theano/theano/gof/link.py", line 314, in raise_with_op
    reraise(exc_type, exc_value, exc_trace)
  File "SUPRESSED/Theano/theano/compile/function_module.py", line 859, in __call__
    outputs = self.fn()
ValueError: Input dimension mis-match. (input[0].shape[1] = 1152, input[1].shape[1] = 4)
Apply node that caused the error: Elemwise{Composite{((i0 * i1) + (i2 * log(i3)))}}[(0, 1)](InplaceDimShuffle{x,0}.0, LogSoftmax.0, Elemwise{sub,no_inplace}.0, Elemwise{sub,no_inplace}.0)
Toposort index: 18
Inputs types: [TensorType(int32, row), TensorType(float64, matrix), TensorType(int32, row), TensorType(float64, matrix)]
Inputs shapes: [(1, 1152), (1152, 4), (1, 1152), (1152, 4)]
Inputs strides: [(4608, 4), (32, 8), (4608, 4), (32, 8)]
Inputs values: ['not shown', 'not shown', 'not shown', 'not shown']
Outputs clients: [[Sum{axis=[1], acc_dtype=float64}(Elemwise{Composite{((i0 * i1) + (i2 * log(i3)))}}[(0, 1)].0)]]

Versions:

Mariana (1.0.1rc1, /media/guilhermevrs/Data/Documentos/Academico/TCC-code/Mariana)
Theano (0.8.0.dev0, SUPRESSED/Theano)

This code was produced having as base the tutorial code from the mnist example.

Could you please help me to figure out what's going on?

Thank you in advance

我直接与Mariana的作者交谈,并在此问题中解释了原因和解决方案

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM