Hi all,
I’m trying to run Alexnet but I don’t have enough space on C so I downloaded on D the ImageNet dataset.
How to point to it?
Device configuration
device = torch.device(‘cuda’ if torch.cuda.is_available() else ‘cpu’)
model = torch.hub.load(‘pytorch/vision:v0.10.0’, ‘alexnet’, pretrained=True)
model.eval().to(device)
from datasets import load_dataset
ds = load_dataset(“imagenet-1k”)
test_ds = ds[“test”]
dataloader = DataLoader(
test_ds,
batch_size=64, # may need to reduce this depending on your GPU
num_workers=0, # may need to reduce this depending on your num of CPUs and RAM
shuffle=False,
drop_last=False,
pin_memory=True
)
with torch.no_grad():
correct = 0
total = 0
for images, labels in dataloader:
images = images.to(device)
labels = labels.to(device)
outputs = model(images)
_, predicted = torch.max(outputs.data, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
del images, labels, outputs
print('Accuracy of the network on the {} test images: {} %'.format(total, 100 * correct / total))