I am completely new to Pytorch and I created my first model. I made a similar model in keras and use this code to test it on data it never seen before:
> from keras.models import load_model
> import numpy as np
> from keras.preprocessing import image
> import time
> import sys
> import PIL
>
> start_time =time.time()
> classifier = load_model("C:/Users/deonh/Pictures/Summer Work/model/Covid-19.h5")
> #classifier.summary()
>
> test_image = image.load_img('C:/Users/deonh/Pictures/Summer Work/Prediction/pnemonia_Covid_or_Normal_1.jpeg', target_size = (64, 64))
> #test_image.show()
> test_image = image.img_to_array(test_image)
>
> test_image = np.expand_dims(test_image, axis = 0)
> result = classifier.predict(test_image)
> print(result)
> #training_set.class_indices
> print("%s seconds" %(time.time() - start_time) + " run time")
My goal is to do something similar with my Pytorch model. This is what I have so far, but it is not working.
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
from torchvision import datasets, transforms, models # add models to the list
import os
import time
from PIL import Image
from IPython.display import displaymodel = torch.load(‘C:/Users/deonh/Pictures/Summer Work/xrays/PythonApplication1/scans’)
photo = Image.open(‘C:/Users/deonh/Pictures/Summer Work/prediction/Covid_Normal_or_Pnemonia.jpg’)
photo.show()
transform = transforms.Compose([
transforms.Resize(224), transforms.ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) ])
im = transform(photo)
#with torch.no_grad():
prediction = model(im)
I am getting a ‘collections.OrderedDict’ object is not callable error