-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathres.py
57 lines (44 loc) · 1.48 KB
/
res.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import cv2
from cv2 import dnn_superres
from torchvision import models, transforms
import torch
from PIL import Image
import torch.nn as nn
import streamlit as st
image_size = 64
batch_size = 32
stats = (0.5, 0.5, 0.5), (0.5, 0.5, 0.5)
latent_size = 150
def denorm(img_tensors):
return img_tensors * stats[1][0] + stats[0][0]
def resolute():
generator = torch.load("WEIGHTS/w2.pth", map_location = "cpu")
generator.eval()
device = torch.device('cpu')
generator.to(device);
y = generator(torch.randn(batch_size, latent_size, 1, 1))
gen_imgs = denorm(y.detach())
to_pil_image = transforms.ToPILImage()
result1 = to_pil_image(gen_imgs[0])
result2 = to_pil_image(gen_imgs[1])
result3 = to_pil_image(gen_imgs[2])
newsize = (70,70)
im1 = result1.resize(newsize)
im2 = result2.resize(newsize)
im3 = result3.resize(newsize)
im1 = im1.save("SUPERSAMPLES/new.jpg",quality=100)
im2 = im2.save("SUPERSAMPLES/new1.jpg",quality=100)
im3 = im3.save("SUPERSAMPLES/new2.jpg",quality=100)
sr = dnn_superres.DnnSuperResImpl_create()
image = cv2.imread('./SUPERSAMPLES/new.jpg')
image2 = cv2.imread('./SUPERSAMPLES/new1.jpg')
image3 = cv2.imread('./SUPERSAMPLES/new2.jpg')
path = "LapSRN_x8.pb"
sr.readModel(path)
sr.setModel("lapsrn", 8)
result = sr.upsample(image)
result1 = sr.upsample(image2)
result2 = sr.upsample(image3)
cv2.imwrite("./SUPERSAMPLES/supernew.png", result)
cv2.imwrite("./SUPERSAMPLES/supernew1.png", result1)
#cv2.imwrite("./SUPERSAMPLES/supernew2.png", result2)