Reputation: 109
I'm wondering, how to design a neural network, where the input data can have different shape, as the network has some fixed number of nodes in the input layer.
Typically when I want to train a image classification network for pictures with unknown (various) resolution or when I want to classify a text, with various length.
For example for images I surely can have some preprocessing pipeline which will resize the image, but I can lose some information with it, in the case of text, the "resizing" would be even harder to perform.
Is there any trick, how to design such a network?
Upvotes: 0
Views: 192
Reputation: 414
In case of images, instead of asking your NN to recognize what's in your image, you can ask it what's in a particular e.g. 256x256 size part of your picture. You train for that, and use it for certain partly overlapped rolling windows of your whole image. If your to-be-recognized pattern varies in size a lot, you can resize it, and use your NN again.
Upvotes: 0
Reputation: 178
Three possibilities come to mind.
The easiest is the zero-padding. Basically, you take a rather big input size and just add zeroes if your concrete input is too small. Of course, this is pretty limited and certainly not useful if your input ranges from a few words to full texts.
Recurrent NNs (RNN) are a very natural NN to choose if you have texts of varying size as input. You input words as word vectors (or embeddings) just one after another and the internal state of the RNN is supposed to encode the meaning of the full string of words. This is one of the earlier papers.
Another possibility is using recursive NNs. This is basically a form of preprocessing in which a text is recursively reduced to a smaller number of word vectors until only one is left - your input, which is supposed to encode the whole text. This makes a lot of sense from a linguistic point of view if your input consists of sentences (which can vary a lot in size), because sentences are structured recursively. For example, the word vector for "the man", should be similar to the word vector for "the man who mistook his wife for a hat", because noun phrases act like nouns, etc. Often, you can use linguistic information to guide your recursion on the sentence. If you want to go way beyond the Wikipedia article, this is probably a good start.
Upvotes: 1