%% Import ONNX Network with Unsupported Operators as a Function
% Import an ONNX network as a function. The network contains ONNX operators that are not supported by Deep Learning Toolbox layers. You can use the imported model function for deep learning tasks, such as prediction and transfer learning.
% Download and install the Deep Learning Toolbox Converter for ONNX Model Format support package. You can enter importONNXFunction at the command line to check if the support package is installed. If it is not installed, then the function provides a link to the required support package in the Add-On Explorer. To install the support package, click the link, and then click Install.
%
% Specify the file to import as shufflenet with operator set 9 from the ONNX Model Zoo. shufflenet is a convolutional neural network that is trained on images from the ImageNet database.

modelfile = 'shufflenet-9.onnx';

%
% A recommended practice is to try to import the network by using importONNXNetwork. If importONNXNetwork is unable to import the network because some of the network layers are not supported, you can import the network as layers by using importONNXLayers, or as a function by using importONNXFunction.
% Import the shufflenet network as layers. The software generates placeholder layers in place of the unsupported layers.

lgraph = importONNXLayers(modelfile,'OutputLayerType','classification');

% Find the placeholder layers and display the number of placeholder layers.

indPlaceholderLayers = findPlaceholderLayers(lgraph);
numel(indPlaceholderLayers)

% You must replace the 48 placeholder layers to use lgraph for deep learning tasks, such as prediction.
%
% Instead, import the network as a function to generate a model function that you can readily use for deep learning tasks.

params = importONNXFunction(modelfile,'shufflenetFcn')

% importONNXFunction returns the ONNXParameters object params, which contains the network parameters, and the model function shufflnetFcn, which contains the network architecture. importONNXFunction saves shufflenetFcn in the current folder. You can open the model function to view or edit the network architecture by using open shufflenetFcn.
% Copyright 2020 The MathWorks, Inc.