Search code examples
theanodeep-learningmnist

How do I use a trained Theano artificial neural network on single examples?


I have been following the http://deeplearning.net/tutorial/ tutorial on how to train an ANN to classify the MNIST numbers. I am now at the "Convolutional Neural Networks" chapter. I want to use the trained network on single examples (MNIST images) and get the predictions. Is there a way to do that?

I have looked ahead in the tutorial and on google but can't find anything.

Thanks a lot in advance for any kind of help!


Solution

  • The material in the Theano tutorial in the earlier chapters, before reaching the Convolutional Neural Networks (CNN) chapter, give a good overview of how Theano works and some of the components the CNN sample code uses. It might be reasonable to assume that students reaching this point have developed their understanding of Theano sufficiently to figure out how to modify the code to extract the model's predictions. Here's a few hints.

    The CNN's output layer, called layer3, is an instance of the LogisticRegression class, introduced in an earlier chapter.

    The LogisticRegression class has an attribute called y_pred. The comments next to the code which assigns that attribute's values says

    symbolic description of how to compute prediction as class whose probability is maximal

    Looking for places where y_pred is used in the logistic regression sample will highlight a function called predict(). This does for the logistic regression sample what is desired of the CNN example.

    If one follows the same approach, using layer3.y_pred as the output of a new Theano function, the model's predictions will become apparent.