From 33f75f191c1b67584e4ea00438b0ff95525e5995 Mon Sep 17 00:00:00 2001 From: lixiaohui Date: Mon, 30 Nov 2020 14:09:08 +0800 Subject: [PATCH] Fixbug: fix API docs bugs --- mindspore/explainer/benchmark/_attribution/faithfulness.py | 2 +- mindspore/explainer/benchmark/_attribution/localization.py | 4 ++-- .../explainer/explanation/_attribution/_backprop/gradcam.py | 2 +- .../explainer/explanation/_attribution/_backprop/gradient.py | 2 +- .../explanation/_attribution/_backprop/modified_relu.py | 4 ++-- .../explanation/_attribution/_perturbation/occlusion.py | 2 +- .../explainer/explanation/_attribution/_perturbation/rise.py | 3 +-- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/mindspore/explainer/benchmark/_attribution/faithfulness.py b/mindspore/explainer/benchmark/_attribution/faithfulness.py index 4a43703e0a..460c962005 100644 --- a/mindspore/explainer/benchmark/_attribution/faithfulness.py +++ b/mindspore/explainer/benchmark/_attribution/faithfulness.py @@ -424,7 +424,7 @@ class Faithfulness(LabelSensitiveMetric): >>> res = faithfulness.evaluate(gradient, inputs, targets) >>> # usage 2: input the generated saliency map >>> saliency = gradient(inputs, targets) - >>> res = faithfulenss.evaluate(gradient, inputs, targets, saliency) + >>> res = faithfulness.evaluate(gradient, inputs, targets, saliency) """ self._check_evaluate_param(explainer, inputs, targets, saliency) diff --git a/mindspore/explainer/benchmark/_attribution/localization.py b/mindspore/explainer/benchmark/_attribution/localization.py index 31a049ae7e..95b8c06af0 100644 --- a/mindspore/explainer/benchmark/_attribution/localization.py +++ b/mindspore/explainer/benchmark/_attribution/localization.py @@ -110,10 +110,10 @@ class Localization(LabelSensitiveMetric): numpy.ndarray, 1D array of shape :math:`(N,)`, result of localization evaluated on `explainer`. Examples: - >>> # init an explainer, the network should contain the output activation function. + >>> # init an explainer with a trained network >>> gradient = Gradient(network) >>> inputs = ms.Tensor(np.random.rand(1, 3, 224, 224), ms.float32) - >>> masks = np.zeros(1, 1, 224, 224) + >>> masks = np.zeros([1, 1, 224, 224]) >>> masks[:, :, 65: 100, 65: 100] = 1 >>> targets = 5 >>> # usage 1: input the explainer and the data to be explained, diff --git a/mindspore/explainer/explanation/_attribution/_backprop/gradcam.py b/mindspore/explainer/explanation/_attribution/_backprop/gradcam.py index 6f3f79f557..46f728db65 100644 --- a/mindspore/explainer/explanation/_attribution/_backprop/gradcam.py +++ b/mindspore/explainer/explanation/_attribution/_backprop/gradcam.py @@ -111,7 +111,7 @@ class GradCAM(IntermediateLayerAttribution): Tensor, a 4D tensor of shape :math:`(N, 1, H, W)`. Examples: - >>> inputs = ms.Tensor(np.random.rand([1, 3, 224, 224]), ms.float32) + >>> inputs = ms.Tensor(np.random.rand(1, 3, 224, 224), ms.float32) >>> label = 5 >>> # gradcam is a GradCAM object, parse data and the target label to be explained and get the attribution >>> saliency = gradcam(inputs, label) diff --git a/mindspore/explainer/explanation/_attribution/_backprop/gradient.py b/mindspore/explainer/explanation/_attribution/_backprop/gradient.py index 77eff8f281..d09338f732 100644 --- a/mindspore/explainer/explanation/_attribution/_backprop/gradient.py +++ b/mindspore/explainer/explanation/_attribution/_backprop/gradient.py @@ -89,7 +89,7 @@ class Gradient(Attribution): Tensor, a 4D tensor of shape :math:`(N, 1, H, W)`. Examples: - >>> inputs = ms.Tensor(np.random.rand([1, 3, 224, 224]), ms.float32) + >>> inputs = ms.Tensor(np.random.rand(1, 3, 224, 224), ms.float32) >>> label = 5 >>> # gradient is a Gradient object, parse data and the target label to be explained and get the attribution >>> saliency = gradient(inputs, label) diff --git a/mindspore/explainer/explanation/_attribution/_backprop/modified_relu.py b/mindspore/explainer/explanation/_attribution/_backprop/modified_relu.py index 96cb5c9156..d8c551b2a7 100644 --- a/mindspore/explainer/explanation/_attribution/_backprop/modified_relu.py +++ b/mindspore/explainer/explanation/_attribution/_backprop/modified_relu.py @@ -45,7 +45,7 @@ class ModifiedReLU(Gradient): Tensor, a 4D tensor of shape :math:`(N, 1, H, W)`. Examples: - >>> inputs = ms.Tensor(np.random.rand([1, 3, 224, 224]), ms.float32) + >>> inputs = ms.Tensor(np.random.rand(1, 3, 224, 224), ms.float32) >>> label = 5 >>> # explainer is a "Deconvolution" or "GuidedBackprop" object, parse data and the target label to be >>> # explained and get the attribution @@ -104,7 +104,7 @@ class Deconvolution(ModifiedReLU): >>> # init Gradient with a trained network. >>> deconvolution = Deconvolution(net) >>> # parse data and the target label to be explained and get the saliency map - >>> inputs = ms.Tensor(np.random.rand([1, 3, 224, 224]), ms.float32) + >>> inputs = ms.Tensor(np.random.rand(1, 3, 224, 224), ms.float32) >>> label = 5 >>> saliency = deconvolution(inputs, label) """ diff --git a/mindspore/explainer/explanation/_attribution/_perturbation/occlusion.py b/mindspore/explainer/explanation/_attribution/_perturbation/occlusion.py index 16f32a69b0..08e3f5d15c 100644 --- a/mindspore/explainer/explanation/_attribution/_perturbation/occlusion.py +++ b/mindspore/explainer/explanation/_attribution/_perturbation/occlusion.py @@ -76,7 +76,7 @@ class Occlusion(PerturbationAttribution): >>> param_dict = load_checkpoint("resnet50.ckpt") >>> load_param_into_net(network, param_dict) >>> occlusion = Occlusion(network) - >>> x = Tensor(np.random.rand([1, 3, 224, 224]), ms.float32) + >>> x = Tensor(np.random.rand(1, 3, 224, 224), ms.float32) >>> label = 1 >>> saliency = occlusion(x, label) """ diff --git a/mindspore/explainer/explanation/_attribution/_perturbation/rise.py b/mindspore/explainer/explanation/_attribution/_perturbation/rise.py index 8bbb1128f1..14cc396c5d 100644 --- a/mindspore/explainer/explanation/_attribution/_perturbation/rise.py +++ b/mindspore/explainer/explanation/_attribution/_perturbation/rise.py @@ -114,14 +114,13 @@ class RISE(PerturbationAttribution): Examples: >>> # given an instance of RISE, saliency map can be generate - >>> inputs = ms.Tensor(np.random.rand([2, 3, 224, 224]), ms.float32) + >>> inputs = ms.Tensor(np.random.rand(2, 3, 224, 224), ms.float32) >>> # when `targets` is an integer >>> targets = 5 >>> saliency = rise(inputs, targets) >>> # `targets` can also be a tensor >>> targets = ms.Tensor([[5], [1]]) >>> saliency = rise(inputs, targets) - >>> """ self._verify_data(inputs, targets) height, width = inputs.shape[2], inputs.shape[3]