Main Content

Networks and Layers Supported for Code Generation

R2026b

MATLAB® Coder™ supports code generation for dlnetwork (Deep Learning Toolbox), series, and directed acyclic graph (DAG) networks. You can generate code for any trained neural network that uses supported deep learning networks, layers and classes.

Supported Pretrained Networks

These pretrained networks, available in Deep Learning Toolbox™, are supported for code generation. You can use imagePretrainedNetwork (Deep Learning Toolbox) function to load these pretrained neural networks as dlnetwork (Deep Learning Toolbox) objects for code generation. Note that code generation does not support setting the name-value argument Weights of imagePretrainedNetwork function to "none". For example, use this code to load a pretrained GoogLeNet neural network.

net = imagePretrainedNetwork("googlenet")

You can use analyzeNetworkForCodegen to see if a network is compatible for code generation for a specific deep learning library. For example:

result = analyzeNetworkForCodegen(imagePretrainedNetwork("googlenet"),TargetLibrary='none')

Note

Support for the ARM® Compute Library as a target for deep learning code generation will be removed in a future release. The network support information for the ARM Compute Libraries column applies only to the "arm-compute" target library option. Instead, create a deep learning configuration object by using the coder.DeepLearningConfig function with the target library set to "none" to generate generic C/C++ code that does not depend on any third-party library.

imagePretrainedNetwork Model Name ArgumentGeneric C/C++

Intel® MKL-DNN and

ARM Compute Libraries

"alexnet"

"darknet19"

"darknet53"

"densenet201"

"efficientnetb0"

"googlenet"

"inceptionresnetv2"

"inceptionv3"

"mobilenetv2"

"nasnetlarge"

 

"nasnetmobile"

 

"resnet18"

"resnet50"

"resnet101"

"shufflenet"

 

Note

The ARM Compute library is not supported for shufflenet.

"squeezenet"

"vgg16"

"vgg19"

"xception"

Supported Layers

These layers are supported for code generation for the target deep learning libraries specified in the table.

Note

In the following tables, the information icon indicates that the network, layer, or class has limited code generation capabilities. You might see errors and unexpected behavior. For more information, see the Extended Capabilities section on the page for that network, layer, or class.

Note

Support for the ARM Compute Library as a target for deep learning code generation will be removed in a future release. The layer support information for the ARM Compute Libraries column in these tables applies only to the "arm-compute" target library option. Instead, create a deep learning configuration object by using the coder.DeepLearningConfig function with the target library set to "none" to generate generic C/C++ code that does not depend on any third-party library.

Input Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

imageInputLayer (Deep Learning Toolbox)

sequenceInputLayer (Deep Learning Toolbox)

featureInputLayer (Deep Learning Toolbox)

Convolution and Fully Connected Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

convolution1dLayer (Deep Learning Toolbox)

 

convolution2dLayer (Deep Learning Toolbox)

fullyConnectedLayer (Deep Learning Toolbox)

groupedConvolution2dLayer (Deep Learning Toolbox)

Note

You can generate generic C/C++ code for channel-wise convolution when the number of groups is equal to the number of filter channels.

transposedConv1dLayer (Deep Learning Toolbox)

 

transposedConv2dLayer (Deep Learning Toolbox)

spectralConvolution1dLayer (Deep Learning Toolbox)

 

spectralConvolution2dLayer (Deep Learning Toolbox)

 

spectralConvolution3dLayer (Deep Learning Toolbox)

 

Sequence Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

bilstmLayer (Deep Learning Toolbox)

flattenLayer (Deep Learning Toolbox)

gruProjectedLayer (Deep Learning Toolbox)

 

gruLayer (Deep Learning Toolbox)

lstmLayer (Deep Learning Toolbox)

lstmProjectedLayer (Deep Learning Toolbox)

 

sequenceInputLayer (Deep Learning Toolbox)

wordEmbeddingLayer (Text Analytics Toolbox)

Activation Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

clippedReluLayer (Deep Learning Toolbox)

eluLayer (Deep Learning Toolbox)

gelu (Deep Learning Toolbox)

geluLayer (Deep Learning Toolbox)

leakyReluLayer (Deep Learning Toolbox)

preluLayer (Deep Learning Toolbox)

reluLayer (Deep Learning Toolbox)

sigmoidLayer (Deep Learning Toolbox)

softmaxLayer (Deep Learning Toolbox)

softplusLayer (Deep Learning Toolbox)

swishLayer (Deep Learning Toolbox)

tanhLayer (Deep Learning Toolbox)

Normalization Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

batchNormalizationLayer (Deep Learning Toolbox)

crossChannelNormalizationLayer (Deep Learning Toolbox)

 

instanceNormalizationLayer (Deep Learning Toolbox)

layerNormalizationLayer (Deep Learning Toolbox)

groupNormalizationLayer (Deep Learning Toolbox)

inverseNormalizationLayer (Deep Learning Toolbox)

Utility Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

crop2dLayer (Deep Learning Toolbox)

dropoutLayer (Deep Learning Toolbox)

formatLayer (Deep Learning Toolbox)

reshapeLayer (Deep Learning Toolbox)

 

scalingLayer (Deep Learning Toolbox)

sliceLayer (Deep Learning Toolbox)

spatialDropoutLayer (Deep Learning Toolbox)

Resizing Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

resize2dLayer (Image Processing Toolbox)

Pooling and Unpooling Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

adaptiveAveragePooling2dLayer (Deep Learning Toolbox)

averagePooling1dLayer (Deep Learning Toolbox)

 

averagePooling2dLayer (Deep Learning Toolbox)

globalAveragePooling1dLayer (Deep Learning Toolbox)

 

globalAveragePooling2dLayer (Deep Learning Toolbox)

globalMaxPooling1dLayer (Deep Learning Toolbox)

 

globalMaxPooling2dLayer (Deep Learning Toolbox)

maxPooling1dLayer (Deep Learning Toolbox)

 

maxPooling2dLayer (Deep Learning Toolbox)

maxUnpooling2dLayer (Deep Learning Toolbox)

 

Note

The ARM Compute library is not supported for maxUnpooling2dLayer.

waveletPooling1dLayer (Wavelet Toolbox) (since R2026b)

 

waveletPooling2dLayer (Wavelet Toolbox) (since R2026b)

 

Combination Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

additionLayer (Deep Learning Toolbox)

concatenationLayer (Deep Learning Toolbox)

depthConcatenationLayer (Deep Learning Toolbox)

multiplicationLayer (Deep Learning Toolbox)

Transformer Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

attentionLayer (Deep Learning Toolbox)

 

embeddingConcatenationLayer (Deep Learning Toolbox)

 

embeddingLayer (Deep Learning Toolbox)

 

indexing1dLayer (Deep Learning Toolbox)

 

patchEmbeddingLayer (Computer Vision Toolbox)

 

positionEmbeddingLayer (Deep Learning Toolbox)

 

selfAttentionLayer (Deep Learning Toolbox)

 

sinusoidalPositionEncodingLayer (Deep Learning Toolbox)

 

Computer Vision and Image Processing Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

depthToSpace2dLayer (Image Processing Toolbox)

patchEmbeddingLayer (Computer Vision Toolbox)

 

spaceToDepthLayer (Image Processing Toolbox)

ssdMergeLayer (Computer Vision Toolbox)

resize2dLayer (Image Processing Toolbox)

yolov2TransformLayer (Computer Vision Toolbox)

Signal Transform Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

cwtLayer (Wavelet Toolbox) (since R2026a)

 

icwtLayer (Wavelet Toolbox) (since R2026a)

 

istftLayer (Signal Processing Toolbox) (since R2025a)

 

modwtLayer (Wavelet Toolbox) (since R2025a)

 

stftLayer (Signal Processing Toolbox) (since R2025a)

 

Custom Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

Custom layers

Custom layers are layers, with or without learnable parameters, that you define for your problem.

See:

  • The outputs of the custom layer must be fixed-size arrays.

  • Custom layers in sequence networks are supported for generic C/C++ code generation only.

  • For code generation, custom layers must contain the %#codegen pragma.

  • You can pass dlarray to custom layers if:

    • The custom layer is in dlnetwork.

    • Custom layer is in a DAG or series network and either inherits from nnet.layer.Formattable or has no backward propagation.

  • For unsupported dlarray methods, then you must extract the underlying data from the dlarray, perform the computations and reconstruct the data back into the dlarray for code generation. For example,

    function Z = predict(layer, X)
    
    if coder.target('MATLAB')
       Z = doPredict(X);
    else
       if isdlarray(X)
          X1 = extractdata(X);
          Z1 = doPredict(X1);
          Z = dlarray(Z1);
      else
          Z = doPredict(X);
      end
    end
    
    end
    

Custom Output Layer (Deep Learning Toolbox)

  • An output layer including custom classification or regression output layers created by nnet.layer.ClassificationLayer or nnet.layer.RegressionLayer functions.

  • For an example showing how to define a custom classification output layer and specify a loss function, see Define Custom Classification Output Layer (Deep Learning Toolbox).

  • For an example showing how to define a custom regression output layer and specify a loss function, see Define Custom Regression Output Layer (Deep Learning Toolbox).

Custom Keras Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

nnet.keras.layer.ClipLayer (Deep Learning Toolbox)

nnet.keras.layer.FlattenCStyleLayer (Deep Learning Toolbox)

nnet.keras.layer.GlobalAveragePooling2dLayer (Deep Learning Toolbox)

nnet.keras.layer.PreluLayer (Deep Learning Toolbox)

nnet.keras.layer.SigmoidLayer (Deep Learning Toolbox)

nnet.keras.layer.TanhLayer (Deep Learning Toolbox)

nnet.keras.layer.TimeDistributedFlattenCStyleLayer (Deep Learning Toolbox)

nnet.keras.layer.ZeroPadding2dLayer (Deep Learning Toolbox)

Custom ONNX Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

nnet.onnx.layer.ClipLayer (Deep Learning Toolbox)

nnet.onnx.layer.ElementwiseAffineLayer (Deep Learning Toolbox)

nnet.onnx.layer.FlattenInto2dLayer (Deep Learning Toolbox)

nnet.onnx.layer.FlattenLayer (Deep Learning Toolbox)

nnet.onnx.layer.GlobalAveragePooling2dLayer (Deep Learning Toolbox)

nnet.onnx.layer.IdentityLayer (Deep Learning Toolbox)

nnet.onnx.layer.PreluLayer (Deep Learning Toolbox)

nnet.onnx.layer.SigmoidLayer (Deep Learning Toolbox)

nnet.onnx.layer.TanhLayer (Deep Learning Toolbox)

nnet.onnx.layer.VerifyBatchSizeLayer (Deep Learning Toolbox)

Custom PyTorch Layers

LayerGeneric C/C++

Intel MKL-DNN and

ARM Compute Libraries

nnet.pytorch.layer.AdaptiveAveragePoolingLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.AttentionMaskTransformLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.ConcatLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.CustomInputLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.CustomOutputLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.FeatureDropoutLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.Flatten2DLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.IdentityLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.PReLULayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.PaddingMaskTransformLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.PassthroughLayer (Deep Learning Toolbox)

 

nnet.pytorch.layer.SoftmaxLayer (Deep Learning Toolbox)

 

Supported Classes

Note

Support for the ARM Compute Library as a target for deep learning code generation will be removed in a future release. The class support information for the ARM Compute Libraries column applies only to the "arm-compute" target library option. Instead, create a deep learning configuration object by using the coder.DeepLearningConfig function with the target library set to "none" to generate generic C/C++ code that does not depend on any third-party library.

Class

Generic C/C++

Intel MKL-DNN and

ARM Compute Libraries

dlnetwork (Deep Learning Toolbox)

DAGNetwork (Deep Learning Toolbox)

pointPillarsObjectDetector (Point Cloud Toolbox)

SeriesNetwork (Deep Learning Toolbox)

ssdObjectDetector (Computer Vision Toolbox)

yolov2ObjectDetector (Computer Vision Toolbox)

 

yolov3ObjectDetector (Computer Vision Toolbox)

yolov4ObjectDetector (Computer Vision Toolbox)

yoloxObjectDetector (Visual Inspection Toolbox)

peopleDetector (Computer Vision Toolbox) (since R2025a)

 

See Also

(Deep Learning Toolbox) |

Topics