Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

eval.py 934 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  1. from model import net,criterion,optimizer
  2. import torch
  3. from torch.autograd import Variable
  4. from torch.utils.data import DataLoader
  5. import cv2 as cv
  6. import torchvision.transforms as transforms
  7. from PIL import Image
  8. from download import classes
  9. net.load_state_dict(torch.load('./weights'))
  10. net.eval()
  11. imsize = (32,32)
  12. transform = transforms.Compose(
  13. [transforms.Resize(imsize),
  14. transforms.ToTensor(),
  15. transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
  16. def image_loader(image_name):
  17. """load image, returns cuda tensor"""
  18. image = Image.open(image_name)
  19. image = transform(image).float()
  20. image = Variable(image, requires_grad=True)
  21. image = image.unsqueeze(0) #this is for VGG, may not be needed for ResNet
  22. # return image.cuda() #assumes that you're using GPU
  23. return image
  24. image = image_loader('test_2.jpg')
  25. res = net(image)
  26. index = res.data.numpy().argmax()
  27. print(classes[index])
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...