0efc69bdc63b49673fd3df91341f91a84abd33ba,foolbox/models/pytorch.py,PyTorchModel,predictions_and_gradient,#PyTorchModel#Any#Any#,100

Before Change


        target = target.to(self.device)

        images = image[np.newaxis]
        images = torch.from_numpy(images)
        images = images.to(self.device)

        if self._old_pytorch():  // pragma: no cover
            target = Variable(target)
            images = Variable(images, requires_grad=True)
        else:
            images.requires_grad_()

        predictions = self._model(images)
        ce = nn.CrossEntropyLoss()
        loss = ce(predictions, target)
        loss.backward()
        grad = images.grad

        if self._old_pytorch():  // pragma: no cover
            predictions = predictions.data
        predictions = predictions.to(self.device)

        if not self._old_pytorch():
            predictions = predictions.detach()
        predictions = predictions.numpy()

After Change


        target = torch.from_numpy(target).to(self.device)

        images = image[np.newaxis]
        images = torch.from_numpy(images).to(self.device)

        if self._old_pytorch():  // pragma: no cover
            target = Variable(target)
            images = Variable(images, requires_grad=True)
        else:
            images.requires_grad_()

        predictions = self._model(images)
        ce = nn.CrossEntropyLoss()
        loss = ce(predictions, target)
        loss.backward()
        grad = images.grad

        if self._old_pytorch():  // pragma: no cover
            predictions = predictions.data
        if self.device != "cpu":
            predictions = predictions.to("cpu")

        if not self._old_pytorch():
            predictions = predictions.detach()
        predictions = predictions.numpy()
        predictions = np.squeeze(predictions, axis=0)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 13

Instances


Project Name: bethgelab/foolbox
Commit Name: 0efc69bdc63b49673fd3df91341f91a84abd33ba
Time: 2018-09-13
Author: renebidart@gmail.com
File Name: foolbox/models/pytorch.py
Class Name: PyTorchModel
Method Name: predictions_and_gradient


Project Name: bethgelab/foolbox
Commit Name: b64be0eb6798ed545f2490984afa71327d0c3592
Time: 2018-08-15
Author: renebidart@gmail.com
File Name: foolbox/models/pytorch.py
Class Name: PyTorchModel
Method Name: batch_predictions


Project Name: bethgelab/foolbox
Commit Name: b64be0eb6798ed545f2490984afa71327d0c3592
Time: 2018-08-15
Author: renebidart@gmail.com
File Name: foolbox/models/pytorch.py
Class Name: PyTorchModel
Method Name: predictions_and_gradient


Project Name: bethgelab/foolbox
Commit Name: 0efc69bdc63b49673fd3df91341f91a84abd33ba
Time: 2018-09-13
Author: renebidart@gmail.com
File Name: foolbox/models/pytorch.py
Class Name: PyTorchModel
Method Name: batch_predictions