I am trying to train and test a simple multi-layer perceptron, exactly as in the first Chainer tutorial, but with my own dataset instead of MNIST. This is the code I'm using (mostly from the tutorial):
class MLP(Chain):
def __init__(self, n_units, n_out):
super(MLP, self).__init__()
with self.init_scope():
self.l1 = L.Linear(None, n_units)
self.l2 = L.Linear(None, n_units)
self.l3 = L.Linear(None, n_out)
def __call__(self, x):
h1 = F.relu(self.l1(x))
h2 = F.relu(self.l2(h1))
y = self.l3(h2)
return y
X, X_test, y, y_test, xHeaders, yHeaders = load_train_test_data('xHeuristicData.csv', 'yHeuristicData.csv')
print 'dataset shape X:', X.shape, ' y:', y.shape
model = MLP(100, 1)
optimizer = optimizers.SGD()
optimizer.setup(model)
train = tuple_dataset.TupleDataset(X, y)
test = tuple_dataset.TupleDataset(X_test, y_test)
train_iter = iterators.SerialIterator(train, batch_size=100, shuffle=True)
test_iter = iterators.SerialIterator(test, batch_size=100, repeat=False, shuffle=False)
updater = training.StandardUpdater(train_iter, optimizer)
trainer = training.Trainer(updater, (10, 'epoch'), out='result')
trainer.extend(extensions.Evaluator(test_iter, model))
trainer.extend(extensions.LogReport())
trainer.extend(extensions.PrintReport(['epoch', 'main/accuracy', 'validation/main/accuracy']))
trainer.extend(extensions.ProgressBar())
trainer.run()
print 'Predicted value for a test example'
print model(X_test[0])
Instead of training and printing the predicted value, I get the following error at "trainer.run()":
dataset shape X: (1003, 116) y: (1003,)
Exception in main training loop: __call__() takes exactly 2 arguments (3 given)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/chainer/training/trainer.py", line 299, in run
update()
File "/usr/local/lib/python2.7/dist-packages/chainer/training/updater.py", line 223, in update
self.update_core()
File "/usr/local/lib/python2.7/dist-packages/chainer/training/updater.py", line 234, in update_core
optimizer.update(loss_func, *in_arrays)
File "/usr/local/lib/python2.7/dist-packages/chainer/optimizer.py", line 534, in update
loss = lossfun(*args, **kwds)
Will finalize trainer extensions and updater before reraising the exception.
Traceback (most recent call last):
File "trainHeuristicChainer.py", line 76, in <module>
trainer.run()
File "/usr/local/lib/python2.7/dist-packages/chainer/training/trainer.py", line 313, in run
six.reraise(*sys.exc_info())
File "/usr/local/lib/python2.7/dist-packages/chainer/training/trainer.py", line 299, in run
update()
File "/usr/local/lib/python2.7/dist-packages/chainer/training/updater.py", line 223, in update
self.update_core()
File "/usr/local/lib/python2.7/dist-packages/chainer/training/updater.py", line 234, in update_core
optimizer.update(loss_func, *in_arrays)
File "/usr/local/lib/python2.7/dist-packages/chainer/optimizer.py", line 534, in update
loss = lossfun(*args, **kwds)
TypeError: __call__() takes exactly 2 arguments (3 given)
I have no clue about how to deal with the error. I have successfully trained similar networks using other frameworks, but I am interested in Chainer because it is PyPy-compatible.
A tgz with the files is available here: https://mega.nz/#!wwsBiSwY!g72pC5ZgekeMiVr-UODJOqQfQZZU3lCqm9Er2jH4UD8