forked from mindspore-Ecosystem/mindspore
add context setting in examples due to the default mode shift in mindspore 1.3
This commit is contained in:
parent
dcd9d18411
commit
a88e8da01b
|
@ -259,7 +259,9 @@ class ImageClassificationRunner(_Verifier):
|
|||
>>> from mindspore.explainer.benchmark import Faithfulness
|
||||
>>> from mindspore.nn import Softmax
|
||||
>>> from mindspore.train.serialization import load_checkpoint, load_param_into_net
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # The detail of AlexNet is shown in model_zoo.official.cv.alexnet.src.alexnet.py
|
||||
>>> net = AlexNet(10)
|
||||
>>> # Load the checkpoint
|
||||
|
|
|
@ -55,7 +55,9 @@ class ClassSensitivity(LabelAgnosticMetric):
|
|||
>>> import mindspore as ms
|
||||
>>> from mindspore.explainer.benchmark import ClassSensitivity
|
||||
>>> from mindspore.explainer.explanation import Gradient
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # The detail of LeNet5 is shown in model_zoo.official.cv.lenet.src.lenet.py
|
||||
>>> net = LeNet5(10, num_channel=3)
|
||||
>>> # prepare your explainer to be evaluated, e.g., Gradient.
|
||||
|
|
|
@ -423,7 +423,9 @@ class Faithfulness(LabelSensitiveMetric):
|
|||
>>> from mindspore import nn
|
||||
>>> from mindspore.explainer.benchmark import Faithfulness
|
||||
>>> from mindspore.explainer.explanation import Gradient
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # init a `Faithfulness` object
|
||||
>>> num_labels = 10
|
||||
>>> metric = "InsertionAUC"
|
||||
|
|
|
@ -117,7 +117,9 @@ class Localization(LabelSensitiveMetric):
|
|||
>>> import mindspore as ms
|
||||
>>> from mindspore.explainer.explanation import Gradient
|
||||
>>> from mindspore.explainer.benchmark import Localization
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> num_labels = 10
|
||||
>>> localization = Localization(num_labels, "PointingGame")
|
||||
>>>
|
||||
|
|
|
@ -79,7 +79,9 @@ class Robustness(LabelSensitiveMetric):
|
|||
>>> from mindspore import nn
|
||||
>>> from mindspore.explainer.explanation import Gradient
|
||||
>>> from mindspore.explainer.benchmark import Robustness
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # Initialize a Robustness benchmarker passing num_labels of the dataset.
|
||||
>>> num_labels = 10
|
||||
>>> activation_fn = nn.Softmax()
|
||||
|
|
|
@ -83,7 +83,9 @@ class GradCAM(IntermediateLayerAttribution):
|
|||
>>> import numpy as np
|
||||
>>> import mindspore as ms
|
||||
>>> from mindspore.explainer.explanation import GradCAM
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # The detail of LeNet5 is shown in model_zoo.official.cv.lenet.src.lenet.py
|
||||
>>> net = LeNet5(10, num_channel=3)
|
||||
>>> # specify a layer name to generate explanation, usually the layer can be set as the last conv layer.
|
||||
|
|
|
@ -61,7 +61,9 @@ class Gradient(Attribution):
|
|||
>>> import numpy as np
|
||||
>>> import mindspore as ms
|
||||
>>> from mindspore.explainer.explanation import Gradient
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # The detail of LeNet5 is shown in model_zoo.official.cv.lenet.src.lenet.py
|
||||
>>> net = LeNet5(10, num_channel=3)
|
||||
>>> gradient = Gradient(net)
|
||||
|
|
|
@ -116,6 +116,9 @@ class Deconvolution(ModifiedReLU):
|
|||
>>> import numpy as np
|
||||
>>> import mindspore as ms
|
||||
>>> from mindspore.explainer.explanation import Deconvolution
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # The detail of LeNet5 is shown in model_zoo.official.cv.lenet.src.lenet.py
|
||||
>>> net = LeNet5(10, num_channel=3)
|
||||
>>> deconvolution = Deconvolution(net)
|
||||
|
@ -168,6 +171,9 @@ class GuidedBackprop(ModifiedReLU):
|
|||
>>> import numpy as np
|
||||
>>> import mindspore as ms
|
||||
>>> from mindspore.explainer.explanation import GuidedBackprop
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # The detail of LeNet5 is shown in model_zoo.official.cv.lenet.src.lenet.py
|
||||
>>> net = LeNet5(10, num_channel=3)
|
||||
>>> gbp = GuidedBackprop(net)
|
||||
|
|
|
@ -78,6 +78,9 @@ class Occlusion(PerturbationAttribution):
|
|||
>>> import numpy as np
|
||||
>>> import mindspore as ms
|
||||
>>> from mindspore.explainer.explanation import Occlusion
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # The detail of LeNet5 is shown in model_zoo.official.cv.lenet.src.lenet.py
|
||||
>>> net = LeNet5(10, num_channel=3)
|
||||
>>> # initialize Occlusion explainer with the pretrained model and activation function
|
||||
|
|
|
@ -70,7 +70,9 @@ class RISE(PerturbationAttribution):
|
|||
>>> import numpy as np
|
||||
>>> import mindspore as ms
|
||||
>>> from mindspore.explainer.explanation import RISE
|
||||
>>> from mindspore import context
|
||||
>>>
|
||||
>>> context.set_context(mode=context.PYNATIVE_MODE)
|
||||
>>> # The detail of LeNet5 is shown in model_zoo.official.cv.lenet.src.lenet.py
|
||||
>>> net = LeNet5(10, num_channel=3)
|
||||
>>> # initialize RISE explainer with the pretrained model and activation function
|
||||
|
|
Loading…
Reference in New Issue