bethgelab / bethgelab/foolbox

How to load datasets that are not among the sample?

Open
#732 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
3k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'd like to use attacks available in foolbox to run them over the full cifar10, 100, imagenet, and not the few images that are available from the sample folder. The tutorial only explains that and when I tested questions on issues, I was not successful in loading.

Basically I want to load a pretrained model, and load a batch of size 128, and see accuracies.`Any help would help a lot and appreciated. Thanks in advance.

```
model = timm.create_model("resnet18", pretrained=True, num_class=10)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

testset = torchvision.datasets.CIFAR10(root='./data', train=False, download=True, transform=transform_test)
testloader = torch.utils.data.DataLoader(testset, batch_size=128, shuffle=False, num_workers=2)
processing =dict( mean=[0.491, 0.482, 0.446],std=[0.247, 0.243, 0.261], axis=-3)
bounds = ((0,1))
fmodel = fb.PyTorchModel(model, bounds=bounds, preprocessing=processing)
assert fmodel.bounds == (0, 1)
images, labels = next(iter(testloader))
fb.utils.accuracy(fmodel, images, labels)

attack = fb.attacks.LinfDeepFoolAttack()
raw, clipped, is_adv = attack(fmodel, images, labels, epsilons=0.03)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
```
Even when I send everything to cuda, same error happens!! is there any miminal working code that I uses the full cifar10
that I use it as the start code?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.