Hello guys,
I am trying to run resnet18 on Imagenet and here is the code
and i am getting a validation accuracy over 82.09% but the expected accuracy is 69.76%.
Is there a issue in my code?
import deeplake
import torch
import torchvision
from torchvision import transforms
from tqdm import tqdm
# Load pre-trained ResNet-18 model
model = torchvision.models.resnet18(pretrained=True) # Load the pre-trained weights
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval() # Set the model to evaluation mode
correct = 0
total = 0
# Iterate over the test_loader for validation
with torch.no_grad():
for x, y in tqdm(test_loader):
x = x.to(device)
y = y.to(device)
y_pred = model(x)
predicted_labels = y_pred.argmax(dim=1)
correct += (predicted_labels == y).sum().item()
total += y.size(0) # Increment the total count by batch size
accuracy = correct / total
print("Validation Accuracy: {:.2%}".format(accuracy))