0

I am performing classification with the help of neural network used in danielnouri's blog post. The total size of the training data is 6300 samples. The data is 20*20 sized character pictures. I am unable to figure out how to select the size of output_num_units. Total number of unique classes are 63. Shape of xtrain is (6283L, 400L) . Shape of yTrain is (6283L,). Below is the code for the nueral network.

net1 = NeuralNet(
           layers=[  # three layers: one hidden layer
                   ('input', layers.InputLayer),
                   ('hidden', layers.DenseLayer),
                   ('output', layers.DenseLayer),
               ],
           # layer parameters:
           input_shape=(None, 400),  # 20x20 input pixels per batch
           hidden_num_units=100,  # number of units in hidden layer

           # output layer uses identity function
           output_nonlinearity=lasagne.nonlinearities.softmax,
           output_num_units=63,

           # optimization method:
           update=nesterov_momentum,
           update_learning_rate=0.01,
           update_momentum=0.9,

           # flag to indicate we're dealing with regression problem
           regression=False,
           max_epochs=400,  # we want to train this many epochs
           verbose=1,
)

net1.fit(xTrain, yTrain)

If I select the size as 63, I get the following error:

net1.fit(xTrain, yTrain) File "C:\Users\FTS.fts-gnosis\Anaconda2\lib\site-packages\nolearn\lasagne\base.py", line 539, in fit self.train_loop(X, y, epochs=epochs) File "C:\Users\FTS.fts-gnosis\Anaconda2\lib\site-packages\nolearn\lasagne\base.py", line 597, in train_loop self.apply_batch_func(self.train_iter_, Xb, yb)) File "C:\Users\FTS.fts-gnosis\Anaconda2\lib\site-packages\nolearn\lasagne\base.py", line 687, in apply_batch_func return func(Xb) if yb is None else func(Xb, yb) File "C:\Users\FTS.fts-gnosis\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 879, in call storage_map=getattr(self.fn, 'storage_map', None)) File "C:\Users\FTS.fts-gnosis\Anaconda2\lib\site-packages\theano\gof\link.py", line 325, in raise_with_op reraise(exc_type, exc_value, exc_trace) File "C:\Users\FTS.fts-gnosis\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 866, in call self.fn() if output_subset is None else\ ValueError: y_i value out of bounds Apply node that caused the error: CrossentropySoftmaxArgmax1HotWithBias(Dot22.0, output.b, y_batch) Toposort index: 11 Inputs types: [TensorType(float64, matrix), TensorType(float64, vector), TensorType(int32, vector)] Inputs shapes: [(128L, 63L), (63L,), (128L,)] Inputs strides: [(504L, 8L), (8L,), (4L,)] Inputs values: ['not shown', 'not shown', 'not shown'] Outputs clients: [[Sum{acc_dtype=float64}(CrossentropySoftmaxArgmax1HotWithBias.0)], [CrossentropySoftmax1HotWithBiasDx(Elemwise{Inv}[(0, 0)].0, CrossentropySoftmaxArgmax1HotWithBias.1, y_batch)], []] HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'. HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.

If I change the

output_nonlinearity=lasagne.nonlinearities.rectify

I get the following error:

File "C:\Users\FTS.fts-gnosis\Anaconda2\lib\site-packages\theano\tensor\nnet\nnet.py", line 1453, in perform y[i] = -numpy.log(coding[i, one_of_n[i]]) IndexError: index 107 is out of bounds for axis 1 with size 63 Apply node that caused the error: CrossentropyCategorical1Hot(Elemwise{Composite{(i0 * (Abs(i1) + i2 + i3))}}[(0, 2)].0, y_batch) Toposort index: 14 Inputs types: [TensorType(float64, matrix), TensorType(int32, vector)] Inputs shapes: [(128L, 63L), (128L,)] Inputs strides: [(504L, 8L), (4L,)] Inputs values: ['not shown', 'not shown'] Outputs clients: [[Sum{acc_dtype=float64}(CrossentropyCategorical1Hot.0)]] Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer): File "C:\Users\FTS.fts-gnosis\workspace\hello1\facialrec.py", line 200, in net1.fit(xTrain, yTrain)

o-90
  • 17,045
  • 10
  • 39
  • 63
Zohair Zahid
  • 119
  • 2
  • 15

1 Answers1

0

I suspect your classes aren't encoded as integers 0-62, in which case you can pass use_label_encoder=True to NeuralNet to have it do the encoding automatically.

Daniel Nouri
  • 1,264
  • 8
  • 9