Closed Nevermore-Aino closed 2 years ago
Glad you find DeepRobust helpful!
To use a specific image, you can try the following lines:
IMAGE_ID = 123
ds = datasets.CIFAR10('deeprobust/image/data', train=False, download=True)
x, y = ds[IMAGE_ID][0], ds[IMAGE_ID][1]
In case you want to create a subset for a specific class, hopefully this will be helpful to you: https://stackoverflow.com/questions/59351910/cifar10-dataset-read-certain-number-of-images-from-a-class
test_loader = torch.utils.data.DataLoader( datasets.CIFAR10('deeprobust/image/data', train = False, download=True, transform = transform_val), batch_size = 1, shuffle=True) #, **kwargs)
classes = np.array(('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'))
IMAGE_ID = 1 #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ds = datasets.CIFAR10('deeprobust/image/data', train=False, download=True) xx, yy = ds[IMAGE_ID][0], ds[IMAGE_ID][1] predict0 = model(xx) #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< predict0= predict0.argmax(dim=1, keepdim=True)
After I tried the giving codes, I got this error below:
File "mypic.py", line 39, in
I am so excited to read your response. Thanks for helping.
test_loader = torch.utils.data.DataLoader( datasets.CIFAR10('deeprobust/image/data', train = False, download=True, transform = transform_val), batch_size = 1, shuffle=True) #, **kwargs)
classes = np.array(('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'))
xx, yy = next(iter(test_loader)) #<<<<<<<<<<<<<<<------------------------------------------- xx = xx.to('cuda').float()
predict0 = model(xx) predict0= predict0.argmax(dim=1, keepdim=True)
adversary = PGD(model) AdvExArray = adversary.generate(xx, yy, **attack_params['PGD_CIFAR10']).float()
I am a beginner, and DeepRobust helps me a lot.
I want to use a specific image from CIFAR10 or my own custom image instead of xx, yy = next(iter(test_loader)). I did some searching online, but I couldn't find an solution yet.
Sorry to leave a noob question here, but I really could use some help.
Thanks