%% Create Initialized dlnetwork with Unconnected Inputs
% Use example inputs to create a multi-input dlnetwork that is ready for training. The software propagates the example inputs through the network to determine the appropriate sizes and formats of the learnable and state parameters of the dlnetwork.
% Define the network architecture. Construct a network with two branches. The network takes two inputs, with one input per branch. Connect the branches using an addition layer.

numFilters = 24;

layersBranch1 = [
    convolution2dLayer(3,6*numFilters,'Padding','same','Stride',2,'Name','conv1Branch1')
    groupNormalizationLayer('all-channels')
    reluLayer
    convolution2dLayer(3,numFilters,'Padding','same')
    groupNormalizationLayer('channel-wise')
    additionLayer(2,'Name','add')
    reluLayer
    fullyConnectedLayer(10)
    softmaxLayer];

layersBranch2 = [
    convolution2dLayer(1,numFilters,'Name','convBranch2')
    groupNormalizationLayer('all-channels','Name','gnBranch2')];

lgraph = layerGraph(layersBranch1);
lgraph = addLayers(lgraph,layersBranch2);
lgraph = connectLayers(lgraph,'gnBranch2','add/in2');

% Create example network inputs of the same size format as typical network inputs. For both inputs, use a batch size of 32. Use an input of size 64-by-64 with three channels for the input to the layer convBranch1. Use an input of size 64-by-64 with 18 channels for the input for the input to the layer convBranch2.

dlX1 = dlarray(rand([64 64 3 32]),"SSCB");
dlX2 = dlarray(rand([32 32 18 32]),"SSCB");

% Create the dlnetwork. Provide the inputs in the same order that the unconnected layers appear in the Layers property of lgraph.

dlnet = dlnetwork(lgraph,dlX1,dlX2);

% Check that the network is initialized and ready for training.

dlnet.Initialized

% Copyright 2021 The MathWorks, Inc.