9b9a42de05056b418f98e3635f2cffd747123548,art/classifiers/pytorch.py,PyTorchClassifier,class_gradient,#PyTorchClassifier#Any#Any#,114

Before Change


        
        // Compute the gradient and return
        if logits:
            grds = self._sess.run(self._logit_class_grads, feed_dict={self._input_ph: inputs})
        else:
            grds = self._sess.run(self._class_grads, feed_dict={self._input_ph: inputs})

        grds = np.swapaxes(np.array(grds), 0, 1)

        return grds

After Change


        :rtype: `np.ndarray`
        
        // Convert the inputs to Tensors
        x = torch.from_numpy(inputs)
        x.requires_grad = True

        // Compute the gradient and return
        // Run prediction
        preds = self._forward_at(x, self._logit_layer)
        if not logits:
            preds = torch.nn.Softmax()(preds)

        // Compute the gradient
        grds = []
        self._model.zero_grad()
        for i in range(self.nb_classes):
            x.grad.data.zero_()
            torch.autograd.backward(preds[:, i], torch.FloatTensor([1] * len(preds[:, 0])), retain_graph=True)
            grds.append(x.grad.numpy().copy())

        grds = np.swapaxes(np.array(grds), 0, 1)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 9

Instances


Project Name: IBM/adversarial-robustness-toolbox
Commit Name: 9b9a42de05056b418f98e3635f2cffd747123548
Time: 2018-05-16
Author: M.N.Tran@ibm.com
File Name: art/classifiers/pytorch.py
Class Name: PyTorchClassifier
Method Name: class_gradient


Project Name: tensorlayer/tensorlayer
Commit Name: 13ed139f539684bf39919963241bf37ab2967d77
Time: 2019-04-23
Author: rundi_wu@pku.edu.cn
File Name: examples/pretrained_cnn/tutorial_models_mobilenetv1.py
Class Name:
Method Name:


Project Name: IBM/adversarial-robustness-toolbox
Commit Name: 9b9a42de05056b418f98e3635f2cffd747123548
Time: 2018-05-16
Author: M.N.Tran@ibm.com
File Name: art/classifiers/pytorch.py
Class Name: PyTorchClassifier
Method Name: class_gradient


Project Name: tensorlayer/tensorlayer
Commit Name: 301f593e6d80712315ec965996cdccb9a20b54c0
Time: 2019-04-24
Author: rundi_wu@pku.edu.cn
File Name: examples/pretrained_cnn/tutorial_models_squeezenetv1.py
Class Name:
Method Name: