Reputation: 363
I'm building a neural network with lasagne and am following the example from the github. I'm curious on how exactly to input into the network. In the example they state that the input layer is 4 dimensions and indeed it is a theano tensor4. Does this mean I have to give the network a 4 dimensional numpy array? Is that even possible? How would you build one from a 4 d vector of lists?
Upvotes: 1
Views: 459
Reputation: 13218
In the MNIST example provided by Lasagne, you need to input a 4D tensor.
Generally speaking, if your data is 2 dimensional (images for example), the shape of your input must be (n_samples, n_channels, height, width)
. In the MNIST dataset n_channel
is 1 (might be something else, e.g. 3 for RGB images), and height
and width
are both 28.
If your data is only 1 dimensional, then you must input a 3D tensor, of shape (n_samples, n_channel, n_features)
.
Note that this might be problematic if you want to predict a label for a single image ((28, 28) ndarray as in this question, because you need to make the input 4 dimensional. In this case, you can add axis using data = data[None, None, :, :]
.
Upvotes: 0