-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinference.py
39 lines (28 loc) · 966 Bytes
/
inference.py
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
39
import torch
import argparse
from data.test_loader import loader
from utils.model import ModelSA
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--img_path", help="path of the image to be checked")
parser.add_argument("--model_path", help="path of the pth file", default='./Weights/best.pth')
args = parser.parse_args()
if torch.cuda.is_available():
device = torch.device('cuda')
else:
device = torch.device('cpu')
classes = ['TB', 'TE']
# Change image path here
img_path = args.img_path
# Change weights path, if necessary
model_path = args.model_path
# Loading the image
img = loader(img_path)
img = img.to(device)
model = ModelSA()
model = model.to(device)
model.load_state_dict(torch.load(model_path))
model.eval()
pred = model.forward(img)
indx = torch.argmax(pred[0])
print('The prediction is: ', classes[indx])