Networks and Layers Supported for Code Generation
MATLAB^{®} Coder™ supports code generation for series, directed acyclic graph (DAG), and recurrent convolutional neural networks (CNNs or ConvNets). You can generate code for any trained neural network whose layers are supported for code generation. See Supported Layers.
Supported Pretrained Networks
The following pretrained networks, available in Deep Learning Toolbox™, are supported for code generation. Support can have limitations, for more information, see the extended capabilities section on the reference page.
Network Name  Description  Intel^{®} MKLDNN  ARM^{®} Compute Library 

AlexNet  AlexNet convolutional neural network. For the pretrained
AlexNet model, see  Yes  Yes 
DarkNet  DarkNet19 and DarkNet53 convolutional neural networks. For the
pretrained DarkNet models, see darknet19 (Deep Learning Toolbox) and darknet53 (Deep Learning Toolbox).  Yes  Yes 
DenseNet201  DenseNet201 convolutional neural network. For the pretrained
DenseNet201 model, see  Yes  Yes 
EfficientNetb0  EfficientNetb0 convolutional neural network. For the
pretrained EfficientNetb0 model, see  Yes  Yes 
GoogLeNet  GoogLeNet convolutional neural network. For the pretrained
GoogLeNet model, see  Yes  Yes 
InceptionResNetv2  InceptionResNetv2 convolutional neural network. For the
pretrained InceptionResNetv2 model, see  Yes  Yes 
Inceptionv3  Inceptionv3 convolutional neural network. For the pretrained
Inceptionv3 model, see inceptionv3 (Deep Learning Toolbox).  Yes  Yes 
MobileNetv2  MobileNetv2 convolutional neural network. For the pretrained
MobileNetv2 model, see  Yes  Yes 
NASNetLarge  NASNetLarge convolutional neural network. For the pretrained
NASNetLarge model, see  Yes  Yes 
NASNetMobile  NASNetMobile convolutional neural network. For the pretrained
NASNetMobile model, see  Yes  Yes 
ResNet  ResNet18, ResNet50, and ResNet101 convolutional neural
networks. For the pretrained ResNet models, see  Yes  Yes 
SegNet  Multiclass pixelwise segmentation network. For more
information, see  Yes  No 
SqueezeNet  Small, deep neural network. For the pretrained SqeezeNet
models, see  Yes  Yes 
VGG16  VGG16 convolutional neural network. For the pretrained VGG16
model, see  Yes  Yes 
VGG19  VGG19 convolutional neural network. For the pretrained VGG19
model, see  Yes  Yes 
Xception  Xception convolutional neural network. For the pretrained
Xception model, see  Yes  Yes 
Supported Layers
The following layers are supported for code generation by MATLAB Coder for the target deep learning libraries specified in the table.
Once you install the support package MATLAB Coder Interface for Deep Learning, you can use analyzeNetworkForCodegen
to see if a network is compatible for code generation for a specific deep learning library. For example:
result = analyzeNetworkForCodegen(mobilenetv2,TargetLibrary = 'mkldnn')
Note
Starting in R2022b, check the code generation compatibility of a deep learning network by using the analyzeNetworkForCodegen
function. coder.getDeepLearningLayers
is not recommended.
Layer Name  Description  Generic C/C++  Intel MKLDNN  ARM Compute Library 

additionLayer (Deep Learning Toolbox)  Addition layer  Yes  Yes  Yes 
anchorBoxLayer (Computer Vision Toolbox)  Anchor box layer  Yes  Yes  Yes 
attentionLayer (Deep Learning Toolbox)  Dotproduct attention layer
 Yes  
averagePooling1dLayer (Deep Learning Toolbox)  1D average pooling layer  Yes  
averagePooling2dLayer (Deep Learning Toolbox)  Average pooling layer
 Yes  Yes  Yes 
batchNormalizationLayer (Deep Learning Toolbox)  Batch normalization layer  Yes  Yes  Yes 
bilstmLayer (Deep Learning Toolbox)  Bidirectional LSTM layer  Yes  Yes  Yes 
classificationLayer (Deep Learning Toolbox)  Create classification output layer  Yes  Yes  Yes 
clippedReluLayer (Deep Learning Toolbox)  Clipped Rectified Linear Unit (ReLU) layer  Yes  Yes  Yes 
concatenationLayer (Deep Learning Toolbox)  Concatenation layer  Yes  Yes  Yes 
convolution1dLayer (Deep Learning Toolbox)  1D convolutional layer  Yes  
convolution2dLayer (Deep Learning Toolbox)  2D convolution layer
 Yes  Yes  Yes 
crop2dLayer (Deep Learning Toolbox)  Layer that applies 2D cropping to the input  No  Yes  Yes 
CrossChannelNormalizationLayer (Deep Learning Toolbox)  Channelwise local response normalization layer  No  Yes  Yes 
Custom layers  Custom layers, with or without learnable parameters, that you define for your problem. See:
The outputs of the custom layer must be fixedsize arrays. Custom layers in sequence networks are supported for generic C/C++ code generation only. For code generation, custom layers must
contain the You
can pass
For unsupported
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  Yes Custom layers in sequence networks are supported for generic C/C++ code generation only.  Yes  Yes 
Custom output layers  All output layers
including custom classification or regression output layers
created by using
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).  Yes  Yes  Yes 
depthConcatenationLayer (Deep Learning Toolbox)  Depth concatenation layer  Yes  Yes  Yes 
depthToSpace2dLayer (Image Processing Toolbox)  2D depth to space layer  Yes  Yes  Yes 
dicePixelClassificationLayer (Computer Vision Toolbox)  A Dice pixel classification layer provides a categorical label for each image pixel or voxel using generalized Dice loss.  No  Yes  Yes 
dropoutLayer (Deep Learning Toolbox)  Dropout layer  Yes  Yes  Yes 
eluLayer (Deep Learning Toolbox)  Exponential linear unit (ELU) layer  Yes  Yes  Yes 
embeddingConcatenationLayer (Deep Learning Toolbox)  Embedding concatenation layer  Yes  
featureInputLayer (Deep Learning Toolbox)  Feature input layer  Yes  Yes  Yes 
flattenLayer (Deep Learning Toolbox)  Flatten layer  Yes  Yes  Yes 
focalLossLayer (Computer Vision Toolbox)  A focal loss layer predicts object classes using focal loss.  Yes  Yes  Yes 
fullyConnectedLayer (Deep Learning Toolbox)  Fully connected layer  Yes  Yes  Yes 
geluLayer (Deep Learning Toolbox)  Gaussian error linear unit (GELU) layer  Yes  Yes  Yes 
globalAveragePooling1dLayer (Deep Learning Toolbox)  1D global average pooling layer  Yes  
globalAveragePooling2dLayer (Deep Learning Toolbox)  Global average pooling layer for spatial data  Yes  Yes  Yes 
globalMaxPooling1dLayer (Deep Learning Toolbox)  1D global max pooling layer  Yes  
globalMaxPooling2dLayer (Deep Learning Toolbox)  2D global max pooling layer  Yes  Yes  Yes 
 2D grouped convolutional layer
 No  Yes  Yes

 Group normalization layer  Yes  Yes  Yes 
 Gated recurrent unit (GRU) layer  Yes  Yes  Yes 
 GRU projected layer  Yes  No  No 
imageInputLayer (Deep Learning Toolbox)  Image input layer
 Yes  Yes  Yes 
indexing1dLayer (Deep Learning Toolbox)  1D indexing layer  Yes  
layerNormalizationLayer (Deep Learning Toolbox)  Layer normalization layer  Yes  Yes  Yes 
leakyReluLayer (Deep Learning Toolbox)  Leaky Rectified Linear Unit (ReLU) layer  Yes  Yes  Yes 
lstmLayer (Deep Learning Toolbox)  Long shortterm memory (LSTM) layer  Yes  Yes  Yes 
lstmProjectedLayer (Deep Learning Toolbox)  LSTM projected layer  Yes  No  No 
maxPooling1dLayer (Deep Learning Toolbox)  1D max pooling layer  Yes  
maxPooling2dLayer (Deep Learning Toolbox)  Max pooling layer If equal max values exists
along the offdiagonal in a kernel window, implementation
differences for the  Yes  Yes  Yes 
maxUnpooling2dLayer (Deep Learning Toolbox)  Max unpooling layer If equal max values exists
along the offdiagonal in a kernel window, implementation
differences for the  No  Yes  No 
multiplicationLayer (Deep Learning Toolbox)  Multiplication layer  Yes  Yes  Yes 
patchEmbeddingLayer (Computer Vision Toolbox)  Patch embedding layer
 Yes  
pixelClassificationLayer (Computer Vision Toolbox)  Create pixel classification layer for semantic segmentation  No  Yes  Yes 
positionEmbeddingLayer (Deep Learning Toolbox)  Maps sequential or spatial indices to vectors.  Yes  
rcnnBoxRegressionLayer (Computer Vision Toolbox)  Box regression layer for Fast and Faster RCNN  Yes  Yes  Yes 
rpnClassificationLayer (Computer Vision Toolbox)  Classification layer for region proposal networks (RPNs)  No  Yes  Yes 
regressionLayer (Deep Learning Toolbox)  Create a regression output layer  Yes  Yes  Yes 
reluLayer (Deep Learning Toolbox)  Rectified Linear Unit (ReLU) layer  Yes  Yes  Yes 
resize2dLayer (Image Processing Toolbox)  2D resize layer  Yes  Yes  Yes 
scalingLayer (Reinforcement Learning Toolbox)  Scaling layer for actor or critic network  Yes  Yes  Yes 
selfAttentionLayer (Deep Learning Toolbox)  Selfattention layer
 Yes  
sigmoidLayer (Deep Learning Toolbox)  Sigmoid layer  Yes  Yes  Yes 
sequenceFoldingLayer (Deep Learning Toolbox)  Sequence folding layer  No  Yes  Yes 
sequenceInputLayer (Deep Learning Toolbox)  Sequence input layer
 Yes  Yes  Yes 
sequenceUnfoldingLayer (Deep Learning Toolbox)  Sequence unfolding layer  No  Yes  Yes 
softmaxLayer (Deep Learning Toolbox)  Softmax layer  Yes  Yes  Yes 
softplusLayer (Reinforcement Learning Toolbox)  Softplus layer for actor or critic network  Yes  Yes  Yes 
spaceToDepthLayer (Image Processing Toolbox)  Space to depth layer  No  Yes  Yes 
ssdMergeLayer (Computer Vision Toolbox)  SSD merge layer for object detection  Yes  Yes  Yes 
swishLayer (Deep Learning Toolbox)  Swish layer  Yes  Yes  Yes 
 Clips the input between the upper and lower bounds  Yes  Yes  Yes 
 Flattens activations into 1D assuming Cstyle (rowmajor) order  Yes  Yes  Yes 
nnet.keras.layer.GlobalAveragePooling2dLayer  Global average pooling layer for spatial data  Yes  Yes  Yes 
 Parametric rectified linear unit  Yes  Yes  Yes 
 Sigmoid activation layer  Yes  Yes  Yes 
 Hyperbolic tangent activation layer  Yes  Yes  Yes 
 Flatten a sequence of input image into a sequence of vector, assuming Cstyle (or rowmajor) storage ordering of the input layer  Yes  Yes  Yes 
 Zero padding layer for 2D input  Yes  Yes  Yes 
 Clips the input between the upper and lower bounds  Yes  Yes  Yes 
nnet.onnx.layer.ElementwiseAffineLayer  Layer that performs elementwise scaling of the input followed by an addition  Yes  Yes  Yes 
 Flattens a MATLAB 2D image batch in the way ONNX does, producing a
2D output array with  Yes  Yes  Yes 
 Flatten layer for ONNX™ network  Yes  Yes  Yes 
 Global average pooling layer for spatial data  Yes  Yes  Yes 
 Layer that implements ONNX identity operator  Yes  Yes  Yes 
 Parametric rectified linear unit  Yes  Yes  Yes 
 Sigmoid activation layer  Yes  Yes  Yes 
 Hyperbolic tangent activation layer  Yes  Yes  Yes 
 Verify fixed batch size  Yes  Yes  Yes 
 Hyperbolic tangent (tanh) layer  Yes  Yes  Yes 
 Transposed 2D convolution layer Code
generation does not support asymmetric cropping of the input.
For example, specifying a vector  No  Yes  Yes 
 A word embedding layer maps word indices to vectors
 Yes  Yes  Yes 
 Output layer for YOLO v2 object detection network  No  Yes  Yes 
 Transform layer for YOLO v2 object detection network  No  Yes  Yes 
Supported Classes
Class  Description  Generic C/C++  Intel MKLDNN  ARM Compute Library 

DAGNetwork (Deep Learning Toolbox)  Directed acyclic graph (DAG) network for deep learning
 Yes  Yes  Yes 
dlnetwork (Deep Learning Toolbox)  Deep learning network for custom training loops
 Yes  Yes  Yes 
SeriesNetwork (Deep Learning Toolbox)  Series network for deep learning
 Yes  Yes  Yes 
 Detect objects using YOLO v2 object detector
 No  Yes  Yes 
 Detect objects using YOLO v3 object detector
 Yes  Yes  Yes 
yolov4ObjectDetector (Computer Vision Toolbox)  Detect objects using YOLO v4 object detector
 Yes  Yes  Yes 
yoloxObjectDetector (Computer Vision Toolbox)  Detect objects using YOLOX object detector
 No  Yes  Yes 
ssdObjectDetector (Computer Vision Toolbox)  Object to detect objects using the SSDbased detector.
 Yes  Yes  Yes 
 PointPillars network to detect objects in lidar point clouds
 No  Yes  Yes 
int8
Code Generation
You can use Deep Learning Toolbox in tandem with the Deep Learning Toolbox Model Quantization Library support package to reduce the memory footprint of a deep neural network by quantizing the weights, biases, and activations of convolution layers to 8bit scaled integer data types. Then, you can use MATLAB Coder to generate optimized code for the network. See Generate int8 Code for Deep Learning Networks.
Related Topics
 Pretrained Deep Neural Networks (Deep Learning Toolbox)
 Learn About Convolutional Neural Networks (Deep Learning Toolbox)
 Workflow for Deep Learning Code Generation with MATLAB Coder