Cameron Diver
Cameron Diver

Reputation: 13

Using theano with single examples out of batch

I'm currently using the machine learning library theano to produce a project which utilises deep learning techniques, to find an internal representation of the MNIST dataset.

So far my codebase is pretty much the same as this convolutional net tutorial http://deeplearning.net/tutorial/lenet.html

Mt problem is arising from the fact that I want to be able to select individual examples out of the test batches (or indeed my own handwritten characters for testing) but I can't seem to get theano to do this.

I have tried quite a few things (been stuck for 4+ days) but my latest attempt which I think is getting somewhere looks like this:

testFunction = theano.function(
        inputs=[index],
        outputs=[layer3.y_pred],
        givens={
            layer0.input: [tData[index]]
        }
)

tData is a theano.shared variable which contains the testing images, layer3.y_pred is the output I'm interested in.

But I keep getting errors related to shape, non-tensor types, and conversions. Anybody who has any experience with theano and knows what's going on under the hood I would really appreciate some input.

Upvotes: 0

Views: 142

Answers (1)

user3098048
user3098048

Reputation: 151

You can change tData[index] to tData[index:index+1].

If tData is an n by m matrix containing n samples, then theano is expecting training data with dimension (batch_size, m). In your case, tData[index] has dimension (m,) while tData[index:index+1] has dimension (1,m)

Upvotes: 0

Related Questions