Search code examples
pythonneural-networkchainer

Multi-dimensional inputs in Chainer


I'm trying to build a neural network with Chainer that takes a 4-dimensional numpy array as an input.

I know that, according to this publication, that is feasible. However, I don't see the way to build it anywhere in the datasets documentation.

Does anyone know how to build it?


Solution

  • You can use any N-dimensional input as long as the input and output data have the same length:

    from chainer.datasets import split_dataset_random, TupleDataset
    
    X = [
        [[.04, .46], [.18, .26]],
        [[.32, .28], [.21, .12]]
    ]
    Y = [.4, .5]  # these are the labels for the X instances, in the same order
    
    train, test = split_dataset_random(TupleDataset(X, Y), int(X.shape[0] * .7))
    

    In earlier versions it was required to flatten the arrays into input vectors, but now you can use any N-dimensional numeric array input.

    Also, you can use numpy.reshape to change the dimensions of the input.