Views
No views yet
1import torch
2import torch.nn as nn
3from torchvision import models, transforms
4from PIL import Image
5
6# Load the pretrained model
7model = models.inception_v3(aux_logits=False)
8model.fc = nn.Linear(model.fc.in_features, 100) # CIFAR-100 has 100 classes
9model.load_state_dict(torch.load("Inception-v3.pt", map_location=torch.device('cpu')))
10model.eval()
11
12# Example inference
13transform = transforms.Compose([
14 transforms.Resize((32, 32)),
15 transforms.ToTensor(),
16 transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
17])
18
19image = Image.open("example_image.png")
20input_tensor = transform(image).unsqueeze(0) # Add batch dimension
21
22output = model(input_tensor)
23predicted_class = output.argmax(1).item()
24print("Predicted Class:", predicted_class)