dnouri / nolearn

Combines the ease of use of scikit-learn with the power of Theano/Lasagne
http://danielnouri.org/notes/2014/12/17/using-convolutional-neural-nets-to-detect-facial-keypoints-tutorial/
MIT License
948 stars 260 forks source link

Weird error when fitting model #63

Closed EgorLakomkin closed 9 years ago

EgorLakomkin commented 9 years ago

I use the tutorial http://danielnouri.org/notes/2014/12/17/using-convolutional-neural-nets-to-detect-facial-keypoints-tutorial/ as reference and try to make simple model like net1 with one hidden layer.

When I am fitting the batch with shape images(512, 65536) and (512, ) labels, I get this:

Using gpu device 0: Quadro 600 Starting batch InputLayer (None, 65536) produces 65536 outputs DenseLayer (None, 100) produces 100 outputs DenseLayer (None, 5) produces 5 outputs

Epoch Train loss Valid loss Train / Val Valid acc Dur
Traceback (most recent call last):
  File "train.py", line 52, in <module>
    net1.fit( batch_X, batch_y )
  File "/home/egor/anaconda/lib/python2.7/site-packages/nolearn/lasagne.py", line 244, in fit
    self.train_loop(X, y)
  File "/home/egor/anaconda/lib/python2.7/site-packages/nolearn/lasagne.py", line 282, in train_loop
    batch_train_loss = self.train_iter_(Xb, yb)
  File "/home/egor/anaconda/lib/python2.7/site-packages/theano/compile/function_module.py", line 513, in __call__
    allow_downcast=s.allow_downcast)
  File "/home/egor/anaconda/lib/python2.7/site-packages/theano/tensor/type.py", line 169, in filter
    data.shape))
TypeError: ('Bad input argument to theano function with name "/home/egor/anaconda/lib/python2.7/site-packages/nolearn/lasagne.py:215"  at index 1(0-based)', 'Wrong number of dimensions: expected 2, got 1 with shape (128,).')

I have no idea where shape '128' came from? What might go wrong here?

Network:

net1 = NeuralNet(
    layers=[  # three layers: one hidden layer
        ('input', layers.InputLayer),
        ('hidden', layers.DenseLayer),
        ('output', layers.DenseLayer),
        ],
    # layer parameters:
    input_shape=(None, input_image_size * input_image_size),  # 256x256 input pixels per batch
    hidden_num_units=100,  # number of units in hidden layer
    output_nonlinearity=None,  # output layer uses identity function
    output_num_units=5,  # classes 0,1,2,3,4

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

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

Training cycle is trivial:

for batch_X, batch_y in batch_iterator( train_data_gen, 512):
    batch_X = np.array(batch_X, dtype= np.float32)
    print "Starting batch"
    batch_y = np.array(batch_y, dtype= np.float32)
    net1.fit( batch_X, batch_y )
celiacintas commented 9 years ago

I had the same error and I reshape the y array and work just fine, y = y.reshape((X, 1)) before doing this the shape was (X,) and after (X, 1)

mverleg commented 9 years ago

This also happens if you have regression = True while trying to do classification

dnouri commented 9 years ago

Thanks for your comments.