Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load datasets that are not among the sample? #732

Open
DeepOceanDeep opened this issue Mar 23, 2024 · 0 comments
Open

How to load datasets that are not among the sample? #732

DeepOceanDeep opened this issue Mar 23, 2024 · 0 comments

Comments

@DeepOceanDeep
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant