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

Error while trying to run code from the tutorials #170

Closed abhishekmalali closed 8 years ago

abhishekmalali commented 8 years ago

Hi, I was trying to run the code from the tutorials to learn deep learning. I am getting the issue below which is not dependant on the version of python. Kindly let me know what you think of it. Currently I am running the code locally but plan on running on the GPUs later. I have been trying it out for sometime but cannot get rid of the issue.

Traceback (most recent call last):
  File "test_run.py", line 61, in <module>

net.fit(X,y)
    File "/Users/abhishek/Projects/deepLearning/ENV/lib/python2.7/site-packages/nolearn/lasagne/base.py", line 290, in fit
    self.initialize()
      File "/Users/abhishek/Projects/deepLearning/ENV/lib/python2.7/site-packages/nolearn/lasagne/base.py", line 166, in initialize
    self.y_tensor_type,
  File "/Users/abhishek/Projects/deepLearning/ENV/lib/python2.7/site-packages/nolearn/lasagne/base.py", line 256, in _create_iter_funcs
    updates = update(loss_train, all_params, **update_params)
TypeError: adagrad() got an unexpected keyword argument 'momentum'

My code is as follows:

import os
import numpy as np
import pandas as pd
from sklearn.utils import shuffle
from lasagne import layers
from lasagne.updates import nesterov_momentum,adagrad
from nolearn.lasagne import NeuralNet

pr_dir = os.getcwd()
TRAIN = pr_dir + '/data/training.csv'
TEST = pr_dir + '/data/test.csv'

def load(test=False,cols = None):

    fname = TEST if test else TRAIN
    df = pd.read_csv(fname) #loading dataframe

    df['Image'] = df['Image'].apply(lambda im: np.fromstring(im, sep = ' '))

    if cols:
        df = df[list(cols) + ['Image']]

    print ("No. of values for each column")
    print(df.count())
    df = df.dropna()

    X = np.vstack(df['Image'].values)/255 #Scaling intensity of pixels to [0,1]
    X = X.astype(np.float32)

    if not test:
        y = df[df.columns[:-1]].values
        y = (y - 48)/48
        X,y = shuffle(X,y,random_state=42) #Shuffling the order
        y = y.astype(np.float32)
    else:
        y = None

    return X,y

#Single hidden layer
net = NeuralNet(
        layers=[
            ('input', layers.InputLayer),
            ('hidden', layers.DenseLayer),
            ('output', layers.DenseLayer),],
        #Layer parameters
        input_shape=(None,9216),
        hidden_num_units=100,
        output_nonlinearity = None,
        output_num_units=30,
        update=adagrad,
        update_learning_rate=0.01,
        update_momentum=0.9,
        regression=True,
        max_epochs=10,
        verbose=1,
        )

X,y = load()
net.fit(X,y)

EDIT: Is there a need for a GPU to get Theano running?

cancan101 commented 8 years ago

You are spelling momentun wrong.

dnouri commented 8 years ago

adagrad doesn't take a momentum parameter!

abhishekmalali commented 8 years ago

Thanks Daniel. Sorry for troubling you guys.