Networks and Layers Supported for C++ 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 convolutional 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.

Network NameDescriptionARM® Compute LibraryIntel® MKL-DNN
AlexNet

AlexNet convolutional neural network. For the pretrained AlexNet model, see alexnet (Deep Learning Toolbox).

YesYes
DarkNetDarkNet-19 and DarkNet-53 convolutional neural networks. For the pretrained DarkNet models, see darknet19 (Deep Learning Toolbox) and darknet53 (Deep Learning Toolbox).YesYes
DenseNet-201

DenseNet-201 convolutional neural network. For the pretrained DenseNet-201 model, see densenet201 (Deep Learning Toolbox).

YesYes
EfficientNet-b0

EfficientNet-b0 convolutional neural network. For the pretrained EfficientNet-b0 model, see efficientnetb0 (Deep Learning Toolbox).

YesYes
GoogLeNet

GoogLeNet convolutional neural network. For the pretrained GoogLeNet model, see googlenet (Deep Learning Toolbox).

YesYes
Inception-ResNet-v2

Inception-ResNet-v2 convolutional neural network. For the pretrained Inception-ResNet-v2 model, see inceptionresnetv2 (Deep Learning Toolbox).

YesYes
Inception-v3Inception-v3 convolutional neural network. For the pretrained Inception-v3 model, see inceptionv3 (Deep Learning Toolbox).YesYes
MobileNet-v2

MobileNet-v2 convolutional neural network. For the pretrained MobileNet-v2 model, see mobilenetv2 (Deep Learning Toolbox).

YesYes
NASNet-Large

NASNet-Large convolutional neural network. For the pretrained NASNet-Large model, see nasnetlarge (Deep Learning Toolbox).

YesYes
NASNet-Mobile

NASNet-Mobile convolutional neural network. For the pretrained NASNet-Mobile model, see nasnetmobile (Deep Learning Toolbox).

YesYes
ResNet

ResNet-18, ResNet-50, and ResNet-101 convolutional neural networks. For the pretrained ResNet models, see resnet18 (Deep Learning Toolbox), resnet50 (Deep Learning Toolbox), and resnet101 (Deep Learning Toolbox).

YesYes
SegNet

Multi-class pixelwise segmentation network. For more information, see segnetLayers (Computer Vision Toolbox).

NoYes
SqueezeNet

Small, deep neural network. For the pretrained SqeezeNet models, see squeezenet (Deep Learning Toolbox).

YesYes
VGG-16

VGG-16 convolutional neural network. For the pretrained VGG-16 model, see vgg16 (Deep Learning Toolbox).

YesYes
VGG-19

VGG-19 convolutional neural network. For the pretrained VGG-19 model, see vgg19 (Deep Learning Toolbox).

YesYes
Xception

Xception convolutional neural network. For the pretrained Xception model, see xception (Deep Learning Toolbox).

YesYes

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 Libraries, you can use coder.getDeepLearningLayers to see a list of the layers supported for a specific deep learning library. For example:

coder.getDeepLearningLayers('mkldnn')

Layer NameDescriptionARM Compute LibraryIntel MKL-DNN
additionLayer (Deep Learning Toolbox)

Addition layer

YesYes
anchorBoxLayer (Computer Vision Toolbox)

Anchor box layer

YesYes
averagePooling2dLayer (Deep Learning Toolbox)

Average pooling layer

YesYes
batchNormalizationLayer (Deep Learning Toolbox)

Batch normalization layer

YesYes
bilstmLayer (Deep Learning Toolbox)Bidirectional LSTM layerYesYes
classificationLayer (Deep Learning Toolbox)

Create classification output layer

YesYes
clippedReluLayer (Deep Learning Toolbox)

Clipped Rectified Linear Unit (ReLU) layer

YesYes
concatenationLayer (Deep Learning Toolbox)

Concatenation layer

YesYes
convolution2dLayer (Deep Learning Toolbox)

2-D convolution layer

Yes

Yes

crop2dLayer (Deep Learning Toolbox)

Layer that applies 2-D cropping to the input

YesYes
CrossChannelNormalizationLayer (Deep Learning Toolbox)

Channel-wise local response normalization layer

YesYes

Custom layers

Custom 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 not supported for code generation.

Yes

  • The generated code uses column-major layout for your array data. Generating code that uses row-major array layout is not supported.

Yes

Custom output layers

All output layers including custom classification or regression output layers created by using nnet.layer.ClassificationLayer or nnet.layer.RegressionLayer.

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

depthConcatenationLayer (Deep Learning Toolbox)

Depth concatenation layer

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.

YesYes
dropoutLayer (Deep Learning Toolbox)

Dropout layer

YesYes
eluLayer (Deep Learning Toolbox)

Exponential linear unit (ELU) layer

YesYes
focalLossLayer (Computer Vision Toolbox)A focal loss layer predicts object classes using focal loss.YesYes
fullyConnectedLayer (Deep Learning Toolbox)

Fully connected layer

YesYes
globalAveragePooling2dLayer (Deep Learning Toolbox)

Global average pooling layer for spatial data

Yes

Yes

globalMaxPooling2dLayer (Deep Learning Toolbox)

2-D global max pooling layer

YesYes

groupedConvolution2dLayer (Deep Learning Toolbox)

2-D grouped convolutional layer

Yes

  • If you specify an integer for numGroups, then the value must be less than or equal to 2.

Yes

gruLayer (Deep Learning Toolbox)

Gated recurrent unit (GRU) layer

Yes

Yes

imageInputLayer (Deep Learning Toolbox)

Image input layer

  • Code generation does not support 'Normalization' specified using a function handle.

YesYes
leakyReluLayer (Deep Learning Toolbox)

Leaky Rectified Linear Unit (ReLU) layer

YesYes
lstmLayer (Deep Learning Toolbox)

Long short-term memory (LSTM) layer

YesYes
maxPooling2dLayer (Deep Learning Toolbox)

Max pooling layer

YesYes
maxUnpooling2dLayer (Deep Learning Toolbox)

Max unpooling layer

NoYes
multiplicationLayer (Deep Learning Toolbox)

Multiplication layer

YesYes
pixelClassificationLayer (Computer Vision Toolbox)

Create pixel classification layer for semantic segmentation

YesYes
rcnnBoxRegressionLayer (Computer Vision Toolbox)

Box regression layer for Fast and Faster R-CNN

YesYes
rpnClassificationLayer (Computer Vision Toolbox)

Classification layer for region proposal networks (RPNs)

YesYes
regressionLayer (Deep Learning Toolbox)

Create a regression output layer

YesYes
reluLayer (Deep Learning Toolbox)

Rectified Linear Unit (ReLU) layer

YesYes
scalingLayer (Reinforcement Learning Toolbox)Scaling layer for actor or critic networkYesYes
sigmoidLayer (Deep Learning Toolbox)Sigmoid layerYesYes
sequenceInputLayer (Deep Learning Toolbox)

Sequence input layer

  • For code generation, only vector input sequences are supported.

  • For vector sequence inputs, the number of features must be a constant during code generation.

  • Code generation does not support 'Normalization' specified using a function handle.

YesYes
softmaxLayer (Deep Learning Toolbox)

Softmax layer

Yes

Yes

softplusLayer (Reinforcement Learning Toolbox)

Softplus layer for actor or critic network

YesYes
spaceToDepthLayer (Computer Vision Toolbox)

Space to depth layer

YesYes
ssdMergeLayer (Computer Vision Toolbox)

SSD merge layer for object detection

YesYes

nnet.keras.layer.FlattenCStyleLayer

Flattens activations into 1-D assuming C-style (row-major) order

Yes

Yes

nnet.keras.layer.GlobalAveragePooling2dLayer

Global average pooling layer for spatial data

Yes

Yes

nnet.keras.layer.SigmoidLayer

Sigmoid activation layer

Yes

Yes

nnet.keras.layer.TanhLayer

Hyperbolic tangent activation layer

Yes

Yes

nnet.keras.layer.ZeroPadding2dLayer

Zero padding layer for 2-D input

Yes

Yes

nnet.onnx.layer.ElementwiseAffineLayer

Layer that performs element-wise scaling of the input followed by an addition

YesYes

nnet.onnx.layer.FlattenLayer

Flatten layer for ONNX™ network

Yes

Yes

nnet.onnx.layer.IdentityLayer

Layer that implements ONNX identity operator

Yes

Yes

tanhLayer (Deep Learning Toolbox)

Hyperbolic tangent (tanh) layer

Yes

Yes

transposedConv2dLayer (Deep Learning Toolbox)

Transposed 2-D convolution layer

Code generation does not support asymmetric cropping of the input. For example, specifying a vector [t b l r] for the 'Cropping' parameter to crop the top, bottom, left, and right of the input is not supported.

Yes

Yes

wordEmbeddingLayer (Text Analytics Toolbox)

A word embedding layer maps word indices to vectors

Yes

Yes

yolov2OutputLayer (Computer Vision Toolbox)

Output layer for YOLO v2 object detection network

Yes

Yes

yolov2ReorgLayer (Computer Vision Toolbox)

Reorganization layer for YOLO v2 object detection network

Yes

Yes

yolov2TransformLayer (Computer Vision Toolbox)

Transform layer for YOLO v2 object detection network

Yes

Yes

Supported Classes

Class

Description

ARM Compute Library

Intel MKL-DNN

yolov2ObjectDetector (Computer Vision Toolbox)

  • Only the detect (Computer Vision Toolbox) method of the yolov2ObjectDetector is supported for code generation.

  • The roi argument to the detect method must be a code generation constant (coder.const()) and a 1x4 vector.

  • Only the Threshold, SelectStrongest, MinSize, and MaxSize name-value pairs for detect are supported.

  • The labels output of detect is returned as a cell array of character vectors, for example, {'car','bus'}.

Yes

Yes

ssdObjectDetector (Computer Vision Toolbox)

Object to detect objects using the SSD-based detector.

  • Only the detect (Computer Vision Toolbox) method of the ssdObjectDetector is supported for code generation.

  • The roi argument to the detect method must be a codegen constant (coder.const()) and a 1x4 vector.

  • Only the Threshold, SelectStrongest, MinSize, MaxSize, and MiniBatchSize Name-Value pairs are supported. All Name-Value pairs must be compile-time constants.

  • The channel and batch size of the input image must be fixed size.

  • The labels output is returned as a categorical array.

  • In the generated code, the input is rescaled to the size of the input layer of the network. But the bounding box that the detect method returns is in reference to the original input size.

Yes

Yes

See Also

Related Topics