dlfeval
Evaluate deep learning model for custom training loops
Description
The dlfeval
function evaluates deep learning models and functions with automatic differentiation enabled. To compute the gradients, use the dlgradient
function.
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.
Examples
Input Arguments
Output Arguments
Tips
A
dlgradient
call 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, the function
fun
must use only supported functions fordlarray
. See List of Functions with dlarray Support.
Algorithms
Extended Capabilities
Version History
Introduced in R2019b