Spaces:
Runtime error
Runtime error
Commit
·
7090984
0
Parent(s):
Duplicate from tensorflow/esrgan-tf2
Browse filesCo-authored-by: AK <[email protected]>
- .gitattributes +27 -0
- README.md +12 -0
- app.py +64 -0
- input.png +0 -0
- requirements.txt +5 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Esrgan Tf2
|
3 |
+
emoji: ⚡
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
app_file: app.py
|
8 |
+
pinned: false
|
9 |
+
duplicated_from: tensorflow/esrgan-tf2
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import time
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
import tensorflow as tf
|
6 |
+
import tensorflow_hub as hub
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
# Declaring Constants
|
11 |
+
SAVED_MODEL_PATH = "https://tfhub.dev/captain-pool/esrgan-tf2/1"
|
12 |
+
|
13 |
+
def resize(width,img):
|
14 |
+
basewidth = width
|
15 |
+
img = Image.open(img)
|
16 |
+
wpercent = (basewidth/float(img.size[0]))
|
17 |
+
hsize = int((float(img.size[1])*float(wpercent)))
|
18 |
+
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
|
19 |
+
img.save('somepic.jpg')
|
20 |
+
return 'somepic.jpg'
|
21 |
+
|
22 |
+
def preprocess_image(image_path):
|
23 |
+
""" Loads image from path and preprocesses to make it model ready
|
24 |
+
Args:
|
25 |
+
image_path: Path to the image file
|
26 |
+
"""
|
27 |
+
hr_image = tf.image.decode_image(tf.io.read_file(image_path))
|
28 |
+
# If PNG, remove the alpha channel. The model only supports
|
29 |
+
# images with 3 color channels.
|
30 |
+
if hr_image.shape[-1] == 4:
|
31 |
+
hr_image = hr_image[...,:-1]
|
32 |
+
hr_size = (tf.convert_to_tensor(hr_image.shape[:-1]) // 4) * 4
|
33 |
+
hr_image = tf.image.crop_to_bounding_box(hr_image, 0, 0, hr_size[0], hr_size[1])
|
34 |
+
hr_image = tf.cast(hr_image, tf.float32)
|
35 |
+
return tf.expand_dims(hr_image, 0)
|
36 |
+
|
37 |
+
|
38 |
+
def plot_image(image):
|
39 |
+
"""
|
40 |
+
Plots images from image tensors.
|
41 |
+
Args:
|
42 |
+
image: 3D image tensor. [height, width, channels].
|
43 |
+
title: Title to display in the plot.
|
44 |
+
"""
|
45 |
+
image = np.asarray(image)
|
46 |
+
image = tf.clip_by_value(image, 0, 255)
|
47 |
+
image = Image.fromarray(tf.cast(image, tf.uint8).numpy())
|
48 |
+
return image
|
49 |
+
|
50 |
+
model = hub.load(SAVED_MODEL_PATH)
|
51 |
+
def inference(img):
|
52 |
+
resize_image = resize(256,img)
|
53 |
+
hr_image = preprocess_image(resize_image)
|
54 |
+
fake_image = model(hr_image)
|
55 |
+
fake_image = tf.squeeze(fake_image)
|
56 |
+
pil_image = plot_image(tf.squeeze(fake_image))
|
57 |
+
return pil_image
|
58 |
+
|
59 |
+
title="esrgan-tf2"
|
60 |
+
description="Enhanced Super Resolution GAN for image super resolution. Produces x4 Super Resolution Image from images of {Height, Width} >=64. Works best on Bicubically downsampled images. (*This is because, the model is originally trained on Bicubically Downsampled DIV2K Dataset*)"
|
61 |
+
article = "<p style='text-align: center'><a href='https://tfhub.dev/captain-pool/esrgan-tf2/1' target='_blank'>Tensorflow Hub</a></p>"
|
62 |
+
examples=[['input.png']]
|
63 |
+
gr.Interface(inference,gr.inputs.Image(type="filepath"),"image",title=title,description=description,article=article,examples=examples).launch(enable_queue=True)
|
64 |
+
|
input.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Pillow
|
2 |
+
numpy
|
3 |
+
tensorflow
|
4 |
+
tensorflow_hub
|
5 |
+
matplotlib
|