1
1

The convolutional mlp (Theano) example in the DeepLearningTutorials on deeplearning.net works fine except it doesn't include any hints on how to actually do a single forward pass to do a classification on a new sample with a trained network.

I've tried a number of things but it seems like everything is setup exactly and only to do the training but not the classification. Does anybody know how to go about doing this?

asked Jun 21 '13 at 15:31

Rolf%20van%20Dam's gravatar image

Rolf van Dam
36455


One Answer:

The script is indeed a demonstration piece, but everything you need to do classification on new data is in there. Focus on lines 183 - 193 in the convolutional_mlp.py example.

The logistic regression object layer3 performs the classification:

layer3 = LogisticRegression(input=layer2.output, n_in=500, n_out=10)

and the theano.function test_model (see below) computes the 0-1 loss on a mini-batch of data. If you want to compute some predicted labels for new data, you will need to construct another theano.function object whose output is the predicted labels (i.e layer3.y_pred instead of layer3.errors(y)).

# from the lenet example: create a function to compute the mistakes that are made by the model
test_model = theano.function([index], layer3.errors(y),
         givens={
            x: test_set_x[index * batch_size: (index + 1) * batch_size],
            y: test_set_y[index * batch_size: (index + 1) * batch_size]})

# what you want: create a function to predict labels that are made by the model
model_predict = theano.function([index], layer3.y_pred,
         givens={
            x: my_new_data[index * batch_size: (index + 1) * batch_size]})

You will have to package up your new data, denoted above as my_new_data, in the same format as the theano.shared objects returned by load_data (see logistic_sgd.py).

Hope this helps,

answered Jun 21 '13 at 17:04

LeeZamparo's gravatar image

LeeZamparo
56247

Thanks! It worked! :D

(Jun 21 '13 at 18:28) Rolf van Dam
Your answer
toggle preview

powered by OSQA

User submitted content is under Creative Commons: Attribution - Share Alike; Other things copyright (C) 2010, MetaOptimize LLC.