%% Combine Image and Feature Input Layers
% To train a network containing both an image input layer and a feature input layer, you must use a dlnetwork object in a custom training loop.
% Define the size of the input image, the number of features of each observation, the number of classes, and the size and number of filters of the convolution layer.

imageInputSize = [28 28 1];
numFeatures = 1;
numClasses = 10;
filterSize = 5;
numFilters = 16;

% To create a network with two input layers, you must define the network in two parts and join them, for example, by using a concatenation layer.
% Define the first part of the network. Define the image classification layers and include a concatenation layer before the last fully connected layer.

layers = [
    imageInputLayer(imageInputSize,'Normalization','none','Name','images')
    convolution2dLayer(filterSize,numFilters,'Name','conv')
    reluLayer('Name','relu')
    fullyConnectedLayer(50,'Name','fc1')
    concatenationLayer(1,2,'Name','concat')
    fullyConnectedLayer(numClasses,'Name','fc2')
    softmaxLayer('Name','softmax')];

% Convert the layers to a layer graph.

lgraph = layerGraph(layers);

% For the second part of the network, add a feature input layer and connect it to the second input of the concatenation layer.

featInput = featureInputLayer(numFeatures,'Name','features');
lgraph = addLayers(lgraph, featInput);
lgraph = connectLayers(lgraph, 'features', 'concat/in2');

% Visualize the network.

plot(lgraph)

% Create a dlnetwork object.

dlnet = dlnetwork(lgraph)

% Copyright 2020 The MathWorks, Inc.