Views
No views yet
1import timm
2import torch
3from PIL import Image
4from torchvision import transforms
5
6# Load model
7model = timm.create_model('eva_giant_patch14_224.clip_ft_in1k', pretrained=False, num_classes=2)
8model.load_state_dict(torch.load('pytorch_model.bin'))
9model.eval()
10
11# Prepare image
12transform = transforms.Compose([
13 transforms.Resize(224),
14 transforms.CenterCrop(224),
15 transforms.ToTensor(),
16 transforms.Normalize(mean=[0.48145466, 0.4578275, 0.40821073],
17 std=[0.26862954, 0.26130258, 0.27577711])
18])
19
20image = Image.open('your_image.jpg')
21input_tensor = transform(image).unsqueeze(0)
22
23# Inference
24with torch.no_grad():
25 output = model(input_tensor)
26 prediction = torch.nn.functional.softmax(output, dim=1)
27
28print(f"No Roadwork: {prediction[0][0]:.2%}")
29print(f"Roadwork: {prediction[0][1]:.2%}")