-
Notifications
You must be signed in to change notification settings - Fork 0
/
gab2x.py
55 lines (45 loc) · 2.47 KB
/
gab2x.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
import tensorflow as tf
import tensorflow_hub as hub
import cv2
import requests
import numpy as np
import matplotlib.pyplot as plt
# based on esrgan
print("""\
\n
██████╗ █████╗ ██████╗ ██████╗ ██╗███████╗██╗ ██████╗ █████╗ ███╗ ██╗
██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██║██╔════╝██║ ██╔════╝ ██╔══██╗████╗ ██║
██║ ███╗███████║██████╔╝██████╔╝██║█████╗ ██║ ██║ ███╗███████║██╔██╗ ██║
██║ ██║██╔══██║██╔══██╗██╔══██╗██║██╔══╝ ██║ ██║ ██║██╔══██║██║╚██╗██║
╚██████╔╝██║ ██║██████╔╝██║ ██║██║███████╗███████╗██╗╚██████╔╝██║ ██║██║ ╚████║
╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝╚══════╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝
coded by Kiana
""")
print("upscale ur image resolution \n ctrl + c to quit \n")
# get and read image to process
img = cv2.imread(input("filename: "))
image_plot = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.title(image_plot.shape)
plt.imshow(image_plot)
plt.show()
# preprocess image
def preprocessing(img):
imageSize = (tf.convert_to_tensor(image_plot.shape[:-1]) // 4) * 4
cropimg = tf.image.crop_to_bounding_box(
img, 0, 0, imageSize[0], imageSize[1])
prepro = tf.cast(cropimg, tf.float32)
return tf.expand_dims(prepro, 0)
# add esrgan
esrgn_path = "https://tfhub.dev/captain-pool/esrgan-tf2/1"
model = hub.load(esrgn_path)
# employ model
def srmodel(img):
prepro = preprocessing(img) # Preprocess image
newim = model(prepro) # Run model
# returns original image
return tf.squeeze(newim) / 255.0
# Plot the processed image
proimg = srmodel(image_plot)
plt.title(proimg.shape)
plt.imshow(proimg)
plt.show()