Closed wanghan0501 closed 5 years ago
It's hard to tell without the code. Are you sure adversarial is an image (and not e.g. None)?
I'm sure adversarial is an image.
config = parse_yaml()
config['use_tensorboard'] = False
config['device'] = 'cuda'
config['logger'] = False
model = capsnet_model.Model(config)
model.load('ckpt/mnist/2018Nov24-134539/176.pth')
capsnet = model.net.module.cuda().eval()
fmodel = foolbox.models.PyTorchModel(capsnet, bounds=(0, 1), num_classes=10)
dataset = datasets.MNIST('data/mnist/', train=True,
transform=transforms.ToTensor())
img, label = dataset.__getitem__(0)
img = img.data.numpy()
label = label.item()
print('label', label)
print('predicted class', np.argmax(fmodel.predictions(img)))
when I run the above code, it's ok, however, when i run the below code, it's error.
attack = foolbox.attacks.FGSM(fmodel)
adversarial = attack(img, label)
Could you do a print(adversarial) and show the result here?
The result is shown in first comment.
@wanghan0501 No, in your first comment I just see the traceback. Please do:
print(adversarial) print(adversarial.shape) print(adversarial.dtype)
and show the result here.
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-4-428f388bfcfd> in <module>
----> 1 print(adversarial)
2 print(adversarial.shape)
3 print(adversarial.dtype)
NameError: name 'adversarial' is not defined
Please put the print statement below "adversarial = attack(img, label)" ...
Thanks for your help and I know why my codes go into error. The reason is that when I caculate the logits of CapsNet, I detach the relationship between logits and output.
Great you could resolve the issue!
I don't konw why it go into error