findAdversarialExamples
Find adversarial examples for MATLAB, ONNX, and PyTorch classification networks
Since R2026a
Syntax
Description
Add-On Required: This feature requires the AI Verification Library for Deep Learning Toolbox add-on.
dlnetwork adversarial examples
[
also returns index vectors example,mislabel,iX,iE] = findAdversarialExamples(net,XLower,XUpper,label)iX and iE. You can
find adversarial examples for several sets of input bounds and labels at once. However,
the findAdversarialExamples function does not always find an
adversarial example. If the generated example is not misclassified as expected, then the
function does not return it. Therefore, the batch dimension of
example can be smaller than the batch dimensions of
XLower, XUpper, and
label. To find out which example corresponds to which set of inputs,
use the index vectors iX and iE to index into
the example and input batches, respectively.
___ = findAdversarialExamples(___,AdversarialLabel=adversarialLabel)
creates targeted adversarial examples that the network incorrectly classifies as
adversarialLabel instead of label.
___ = findAdversarialExamples(___,
specifies additional options using one or more name-value arguments.Name=Value)
ONNX and PyTorch network adversarial examples
This syntax requires the Deep Learning Toolbox Interface for alpha-beta-CROWN Verifier add-on.
[
creates untargeted adversarial examples example,mislabel] = findAdversarialExamples(modelfile,XLower,XUpper,label,numClasses)example between
XLower and XUpper from the pretrained
ONNX™ or PyTorch® network in modelfile. Specify the expected correct
label using the label argument and the number of classes in the
network with the numClasses argument. The function also returns the
actual predicted label mislabel
[
also returns index vectors example,mislabel,iX,iE] = findAdversarialExamples(modelfile,XLower,XUpper,label,numClasses)iX and iE. You can
find adversarial examples for several sets of input bounds and labels at once. However,
the findAdversarialExamples function does not always find an
adversarial example. If the created example is not misclassified as expected, then the
function does not return it. Therefore, the batch dimension of
example can be smaller than the batch dimensions of
XLower, XUpper, and
label. To find out which example corresponds to which set of inputs,
use the index vectors iX and iE to index into
the example and input batches, respectively.
___ = findAdversarialExamples(___,
specifies additional options using one or more name-value arguments.Name=Value)
Examples
Input Arguments
Name-Value Arguments
Output Arguments
More About
Algorithms
References
[1] Goodfellow, Ian J., Jonathon Shlens, and Christian Szegedy. “Explaining and Harnessing Adversarial Examples.” Preprint, submitted March 20, 2015. https://arxiv.org/abs/1412.6572.
Version History
Introduced in R2026a



