-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsartorious_model_eval.py
More file actions
39 lines (34 loc) · 1.17 KB
/
sartorious_model_eval.py
File metadata and controls
39 lines (34 loc) · 1.17 KB
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
from torchvision import transforms
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
import numpy as np
import matplotlib.pyplot as plt
from pytorch_unet import UNet
from sartorious_dataset import SartoriousDataset
import torch.optim as optim
import os
import PIL
img_preprocess = transforms.Compose([
transforms.Resize((224,224)),
transforms.ToTensor()
])
model = UNet(num_input_ch = 1, num_output_ch = 2)
trained_models_path = 'trained_models'
for modelname in sorted(os.listdir(trained_models_path)):
if '99' not in modelname:
continue
model.load_state_dict(torch.load(f'{trained_models_path}/{modelname}'))
model.eval()
for i,testid in enumerate(['7ae19de7bc2a','d8bfd1dafdc4','d48ec7815252']):
img = PIL.Image.open(f'data/test/{testid}.png')
img = img_preprocess(img).squeeze()
x = img.unsqueeze(0).unsqueeze(0)
yhat = model(x)
plt.figure(1)
plt.subplot(2,3,1+i)
plt.imshow(x[0,:,:].cpu().squeeze().detach().numpy())
plt.subplot(2,3,4+i)
plt.imshow(F.softmax(yhat,dim=1)[0,1,:,:].cpu().squeeze().detach().numpy())
plt.show()