Repository navigation
Expand file tree
/
Copy pathdemo.py
More file actions
53 lines (43 loc) · 1.77 KB
/
Copy pathdemo.py
File metadata and controls
53 lines (43 loc) · 1.77 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import matplotlib.pyplot as plt
import torchvision
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
from torchvision import datasets
from torch.autograd import Variable
from matplotlib.pyplot import imsave
from PIL import Image
import torchvision.transforms as transforms
from matplotlib.pyplot import imsave
import torch.nn as nn
import torch
import utils.xcorr2 as xcorr2
import time
import utils.network as network
os.makedirs("Reconstructions", exist_ok=True)
cuda = True if torch.cuda.is_available() else False
unet = torch.load('checkpoints/TrainedNetwork.pth', map_location='cuda')#Use this if i used torch.save(model). Reloads both the network and its weights. Uses neglibly more storage
# Configure data loader
dataloader = torch.utils.data.DataLoader(
torchvision.datasets.ImageFolder(
root="./datasets/SubsampledData/",
# root="./datasets/ShortExposureData",
# root="./datasets/SimData",
transform=transforms.Compose([transforms.Resize((128,256),interpolation=Image.BICUBIC),transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
)
,
batch_size=1,
shuffle=False,
)
Tensor = torch.cuda.FloatTensor if cuda else torch.FloatTensor
h=128
w=128
for i, (imgs, _) in enumerate(dataloader):
corr_imgs=Variable(imgs[:,0:1,:,0:128].type(Tensor))
recon_imgs = unet(corr_imgs)
plt.subplot(1,2,1)
plt.imshow(corr_imgs[0,0,:,:].cpu().data.numpy(),vmin=-1,vmax=1)
plt.subplot(1,2,2)
plt.imshow(recon_imgs[0,0,(h // 4):((h * 3) // 4), (w // 4):((w * 3) // 4)].cpu().data.numpy(),vmin=-1,vmax=1)
plt.show()
imsave("Reconstructions/%d_recon.png" % i, recon_imgs.cpu().data.numpy()[0, 0, (h // 4):((h * 3) // 4), (w // 4):((w * 3) // 4)],vmin=-1,vmax=1)