Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
SRnet.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a2d225fc37e4908cf360e503ec7b34cebe9ce6b9905cc853a7d83b0ba026b1ba
|
| 3 |
+
size 67952735
|
app.py
CHANGED
|
@@ -1,37 +1,49 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import onnxruntime as ort
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Load the ONNX model
|
| 7 |
-
model_path = "
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Define the superresolution function
|
| 11 |
def superresolve(image):
|
| 12 |
# Preprocess the image
|
| 13 |
-
image =
|
| 14 |
-
|
| 15 |
-
image = np.transpose(image, (2, 0, 1)) # Transpose to NHWC format
|
| 16 |
-
image = image[np.newaxis, ...] # Add batch dimension
|
| 17 |
|
| 18 |
# Run inference
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Postprocess the output
|
| 24 |
-
output = output.
|
| 25 |
-
output =
|
| 26 |
-
output =
|
| 27 |
-
output = Image.fromarray(output
|
|
|
|
| 28 |
|
| 29 |
return output
|
| 30 |
|
| 31 |
# Define the Gradio interface
|
| 32 |
interface = gr.Interface(
|
| 33 |
fn=superresolve,
|
| 34 |
-
inputs="
|
| 35 |
outputs="image",
|
| 36 |
title="Super Resolution",
|
| 37 |
description="Upload an image to upscale its resolution.",
|
|
@@ -41,4 +53,8 @@ interface = gr.Interface(
|
|
| 41 |
)
|
| 42 |
|
| 43 |
# Launch the Gradio app
|
| 44 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
from torchvision.transforms import ToTensor
|
| 6 |
+
from torchvision import transforms
|
| 7 |
+
|
| 8 |
|
| 9 |
# Load the ONNX model
|
| 10 |
+
model_path = "./SRnet.pth" # Replace with your model path
|
| 11 |
+
|
| 12 |
+
transforms = transforms.Compose([
|
| 13 |
+
#transforms.Resize(size=(50, 50), antialias=True),
|
| 14 |
+
transforms.ToTensor()
|
| 15 |
+
])
|
| 16 |
+
|
| 17 |
+
|
| 18 |
|
| 19 |
# Define the superresolution function
|
| 20 |
def superresolve(image):
|
| 21 |
# Preprocess the image
|
| 22 |
+
image = transforms(image)[None,...]
|
| 23 |
+
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Run inference
|
| 26 |
+
|
| 27 |
+
net = torch.load(model_path)
|
| 28 |
+
net = net['arch']
|
| 29 |
+
net.eval()
|
| 30 |
+
net.cpu()
|
| 31 |
+
|
| 32 |
+
output = net(image)
|
| 33 |
|
| 34 |
# Postprocess the output
|
| 35 |
+
output = output.permute(0,2,3,1)[0].data.numpy()
|
| 36 |
+
output *= 255.0
|
| 37 |
+
output = output.clip(0, 255)
|
| 38 |
+
output = Image.fromarray(np.uint8(output))
|
| 39 |
+
|
| 40 |
|
| 41 |
return output
|
| 42 |
|
| 43 |
# Define the Gradio interface
|
| 44 |
interface = gr.Interface(
|
| 45 |
fn=superresolve,
|
| 46 |
+
inputs=gr.Image(type="pil"),
|
| 47 |
outputs="image",
|
| 48 |
title="Super Resolution",
|
| 49 |
description="Upload an image to upscale its resolution.",
|
|
|
|
| 53 |
)
|
| 54 |
|
| 55 |
# Launch the Gradio app
|
| 56 |
+
interface.launch()
|
| 57 |
+
|
| 58 |
+
# impath = './image.jpg'
|
| 59 |
+
# img = Image.open(impath).convert('RGB')
|
| 60 |
+
# superresolve(img)
|