%% Import and Assemble ONNX Network with Multiple Outputs
% Import an ONNX network that has multiple outputs by using importONNXLayers, and then assemble the imported layer graph into a DAGNetwork object.
%
% Specify the network file from which to import layers and weights.

modelfile = "digitsMIMO.onnx";

% Import the layers and weights from modelfile. The network in digitsMIMO.onnx has two output layers: one classification layer (ClassificationLayer_sm_1) to classify digits and one regression layer (RegressionLayer_fc_1_Flatten) to compute the mean squared error for the predicted angles of the digits.

lgraph = importONNXLayers(modelfile)

% Plot the layer graph using plot, and display the layers of lgraph.

plot(lgraph)
lgraph.Layers

%
% The classification layer does not contain the classes, so you must specify these before assembling the network. If you do not specify the classes, then the software automatically sets the classes to 1, 2, ..., N, where N is the number of classes. Specify the classes of cLayer as 0, 1, ..., 9. Then, replace the imported classification layer with the new one.

ClassNames = string(0:9);
cLayer = lgraph.Layers(18);
cLayer.Classes = ClassNames;
lgraph = replaceLayer(lgraph,"ClassificationLayer_sm_1",cLayer);

% Assemble the layer graph using assembleNetwork. The function returns a DAGNetwork object that is ready to use for prediction.

assembledNet = assembleNetwork(lgraph)

% Copyright 2019 The MathWorks, Inc.