MATLAB: Pattern Recognition with 3D input variable

2d3dDeep Learning Toolboxinputpatternpatternnetrecognition

If you have elements of 2D data that are put into a 3D inputs variable, is it possible to do pattern recognition on this data in MATLAB?
>> inputs = rand(3,3,10);
>> targets = ones(2,10);
>> net = patternnet(10);
>> net = train(net, inputs, targets) %error inputs must be 2D
>> nprtool %dropdown does not give 3D inputs variable as an option

Best Answer

The input data for training classical neural networks is expected to be an R x Q dimensional matrix (or a cell array of R x Q matrices), where Q is the batch size or number of observations and R is the number of variables.
Since ‘patternnets’ (in general, not just in MATLAB) do not take account of spatial dependencies between variables (as opposed to convolutional deep learning networks) you could try to work around this requirement by reshaping the data from a 2D matrix into a 1D vector. For example:
Instead of:
inputs = rand(3,3,10)
targets = ones(2,10);
You could use:
inputs = rand(9,10);
targets = ones(2,10);
However, depending on what your 2-D data represents, a better alternative might be to work with convolutional neural networks (CNNs). These networks are designed to model spatial dependencies between variables/features and are the state-of-the-art for tasks such as image classification.
Please see here how to create a simple classification deep learning network for 2-D image data: