%% Analyze Network Using Example Inputs
% To analyze a network that has an input that is not connected to an input layer, you can provide example network inputs to the analyzeNetwork function. You can provide example inputs when you analyze dlnetwork objects, or when you analyze Layer arrays or LayerGraph objects for custom training workflows using the 'TargetUsage','dlnetwork' name-value option.
% 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;
inputSize = [64 64 3];

layersBranch1 = [
    imageInputLayer(inputSize,'Normalization','none','Name','input')
    convolution2dLayer(3,6*numFilters,'Padding','same','Stride',2,'Name','conv1Branch1')
    groupNormalizationLayer('all-channels','Name','gn1Branch1')
    reluLayer('Name','relu1Branch1')
    convolution2dLayer(3,numFilters,'Padding','same','Name','conv2Branch1')
    groupNormalizationLayer('channel-wise','Name','gn2Branch1')
    additionLayer(2,'Name','add')
    reluLayer('Name','reluCombined')
    fullyConnectedLayer(10,'Name','fc')
    softmaxLayer('Name','sm')];

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 the dlnetwork. Because this network contains an unconnected input, create an uninitialized dlnetwork object by setting the 'Initialize' name-value option to false.

dlnet = dlnetwork(lgraph,'Initialize',false);

% Create example network inputs of the same size and format as typical inputs for this network. 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 'input'. Use an input of size 64-by-64 with 18 channels for the input to the layer 'convBranch2'.

exampleInput = dlarray(rand([inputSize 32]),'SSCB');
exampleConvBranch2 = dlarray(rand([32 32 18 32]),'SSCB');

% Examine the Layers property of the network to determine the order in which to supply the example inputs.

dlnet.Layers

% Analyze the network. Provide the example inputs in the same order as the layers that require inputs appear in the Layers property of the dlnetwork. You must provide an example input for all network inputs, including inputs that are connected to an input layer.

analyzeNetwork(dlnet,exampleInput,exampleConvBranch2)

%
% Copyright 2021 The MathWorks, Inc.
%