Deep Learning Import, Export, and Customization

Import, export, and customize deep learning networks, and customize layers, training loops, and loss functions

Import networks and network architectures from TensorFlow™-Keras, Caffe, and the ONNX™ (Open Neural Network Exchange) model format. You can also export a trained Deep Learning Toolbox™ network to the ONNX model format.

You can define your own custom deep learning layer for your problem. You can specify a custom loss function using a custom output layers and define custom layers with or without learnable parameters. For example, you can use a custom weighted classification layer with weighted cross entropy loss for classification problems with an imbalanced distribution of classes. After defining a custom layer, you can check that the layer is valid, GPU compatible, and outputs correctly defined gradients.

If the trainingOptions function does not provide the training options that you need for your task, or custom output layers do not support the loss functions that you need, then you can define a custom training loop. For networks that cannot be created using layer graphs, you can define custom networks as a function. To learn more, see Define Custom Training Loops, Loss Functions, and Networks.

Functions

expand all

importKerasNetworkImport a pretrained Keras network and weights
importKerasLayersImport layers from Keras network
importCaffeNetworkImport pretrained convolutional neural network models from Caffe
importCaffeLayersImport convolutional neural network layers from Caffe
importONNXNetworkImport pretrained ONNX network
importONNXLayersImport layers from ONNX network
exportONNXNetworkExport network to ONNX model format
findPlaceholderLayersFind placeholder layers in network architecture imported from Keras or ONNX
replaceLayerReplace layer in layer graph
assembleNetworkAssemble deep learning network from pretrained layers
PlaceholderLayerLayer replacing an unsupported Keras layer, ONNX layer, or unsupported functionality from functionToLayerGraph
checkLayerCheck validity of custom layer
setLearnRateFactorSet learn rate factor of layer learnable parameter
setL2FactorSet L2 regularization factor of layer learnable parameter
getLearnRateFactorGet learn rate factor of layer learnable parameter
getL2FactorGet L2 regularization factor of layer learnable parameter
dlnetworkDeep learning network for custom training loops
forwardCompute deep learning network output for training
predictCompute deep learning network output for inference
adamupdate Update parameters using adaptive moment estimation (Adam)
rmspropupdate Update parameters using root mean squared propagation (RMSProp)
sgdmupdate Update parameters using stochastic gradient descent with momentum (SGDM)
dlupdate Update parameters using custom function
dlarrayDeep learning array for custom training loops
dlgradientCompute gradients for custom training loops using automatic differentiation
dlfevalEvaluate deep learning model for custom training loops
dimsDimension labels of dlarray
finddimFind dimensions with specified label
stripdimsRemove dlarray labels
extractdataExtract data from dlarray
functionToLayerGraphConvert deep learning model function to a layer graph
dlconvDeep learning convolution
dltranspconvDeep learning transposed convolution
lstmLong short-term memory
fullyconnectSum all weighted input data and apply a bias
reluApply rectified linear unit activation
leakyreluApply leaky rectified linear unit activation
batchnormNormalize each channel of input data
avgpoolPool data to average values over spatial dimensions
maxpoolPool data to maximum value
maxunpoolUnpool the output of a maximum pooling operation
softmaxApply softmax activation to channel dimension
crossentropyCategorical cross-entropy loss
sigmoidApply sigmoid activation
mseHalf mean squared error

Topics

Custom Layers

Define Custom Deep Learning Layers

Learn how to define custom deep learning layers

Check Custom Layer Validity

Learn how to check the validity of custom deep learning layers.

Define Custom Deep Learning Layer with Learnable Parameters

This example shows how to define a PReLU layer and use it in a convolutional neural network.

Define Custom Deep Learning Layer with Multiple Inputs

This example shows how to define a custom weighted addition layer and use it in a convolutional neural network.

Define Custom Classification Output Layer

This example shows how to define a custom classification output layer with sum of squares error (SSE) loss and use it in a convolutional neural network.

Define Custom Weighted Classification Layer

This example shows how to define and create a custom weighted classification output layer with weighted cross entropy loss.

Define Custom Regression Output Layer

This example shows how to define a custom regression output layer with mean absolute error (MAE) loss and use it in a convolutional neural network.

Network Training and Assembly

Train Generative Adversarial Network (GAN)

This example shows how to train a generative adversarial network (GAN) to generate images.

Train a Siamese Network for Dimensionality Reduction

This example shows how to train a Siamese network to compare handwritten digits using dimensionality reduction.

Train a Siamese Network to Compare Images

This example shows how to train a Siamese network to identify similar images of handwritten characters.

Define Custom Training Loops, Loss Functions, and Networks

Learn how to define and customize deep learning training loops, loss functions, and networks using automatic differentiation.

Specify Training Options in Custom Training Loop

Learn how to specify common training options in a custom training loop.

Train Network Using Custom Training Loop

This example shows how to train a network that classifies handwritten digits with a custom learning rate schedule.

Make Predictions Using dlnetwork Object

This example shows how to make predictions using a dlnetwork object by splitting data into mini-batches.

Train Network Using Model Function

This example shows how to create and train a deep learning network by using functions rather than a layer graph or a dlnetwork.

Make Predictions Using Model Function

This example shows how to make predictions using a model function by splitting data into mini-batches.

Specify Custom Weight Initialization Function

This example shows how to create a custom He weight initialization function for convolution layers followed by leaky ReLU layers.

Assemble Network from Pretrained Keras Layers

This example shows how to import the layers from a pretrained Keras network, replace the unsupported layers with custom layers, and assemble the layers into a network ready for prediction.

Multiple-Input and Multiple-Output Networks

Multiple-Input and Multiple-Output Networks

Learn how to define and train deep learning networks with multiple inputs or multiple outputs.

Train Network with Multiple Outputs

This example shows how to train a deep learning network with multiple outputs that predict both labels and angles of rotations of handwritten digits.

Assemble Multiple-Output Network for Prediction

Instead of using the model function for prediction, you can assemble the network into a DAGNetwork ready for prediction using the functionToLayerGraph and assembleNetwork functions.

Automatic Differentiation

Automatic Differentiation Background

Learn how automatic differentiation works.

Use Automatic Differentiation In Deep Learning Toolbox

How to use automatic differentiation in deep learning.

List of Functions with dlarray Support

View the list of functions that support dlarray objects.

Grad-CAM Reveals the Why Behind Deep Learning Decisions

Grad-CAM explains why a network makes a decision.

Featured Examples