dlarray
R2026bDeep learning array for customization
Description
A deep learning array stores data with optional data format labels for custom training loops, and enables functions to compute and use derivatives through automatic differentiation.
Tip
For most deep learning tasks, you can use a pretrained neural network and adapt it to your own
data. For an example showing how to use transfer learning to retrain a convolutional neural
network to classify a new set of images, see Retrain Neural Network to Classify New Images. Alternatively, you can
create and train neural networks from scratch using the trainnet and
trainingOptions functions.
If the trainingOptions function does not provide the
training options that you need for your task, then you can create a custom training loop
using automatic differentiation. To learn more, see Train Network Using Custom Training Loop.
If the trainnet
function does not provide the loss function that you need for your task, then you can
specify a custom loss function to the trainnet as a function handle.
For loss functions that require more inputs than the predictions and targets (for example,
loss functions that require access to the neural network or additional inputs), train the
model using a custom training loop. To learn more, see Train Network Using Custom Training Loop.
If Deep Learning Toolbox™ does not provide the layers you need for your task, then you can create a custom layer. To learn more, see Define Custom Deep Learning Layers. For models that cannot be specified as networks of layers, you can define the model as a function. To learn more, see Train Network Using Model Function.
For more information about which training method to use for which task, see Train Deep Learning Model in MATLAB.
Creation
Description
formats the data in dlX = dlarray(X,fmt)dlX with dimension labels according to the data
format in fmt. Dimension labels help in passing deep learning data
between functions. For more information on dimension labels, see Deep Learning Data Formats.
Setting fmt to "" does not remove formats from
data. Use stripdims
instead.
Input Arguments
Output Arguments
Object Functions
dims | Data format of dlarray object |
dlgradient | Compute gradients for custom training loops using automatic differentiation |
extractdata | Extract data from dlarray object |
finddim | Find dimensions with specified label |
stripdims | Remove dlarray data format |
A dlarray also allows functions for numeric, matrix, and other
operations. See the full list in List of Functions with dlarray Support.
Examples
More About
Tips
A
dlgradientcall must be inside a function. To obtain a numeric value of a gradient, you must evaluate the function usingdlfeval, and the argument to the function must be adlarray. See Use Automatic Differentiation In Deep Learning Toolbox.To enable the correct evaluation of gradients,
dlfevalmust call functions that use only supported functions fordlarray. See List of Functions with dlarray Support.