Spaces:
Runtime error
Runtime error
Commit
·
ea1509a
1
Parent(s):
9b4e7cb
Changed model loading asynchronously
Browse files
app.py
CHANGED
|
@@ -1,21 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
|
|
|
|
|
|
|
| 4 |
import torch
|
| 5 |
import numpy as np
|
| 6 |
from models.network_swinir import SwinIR as net
|
| 7 |
|
| 8 |
# model load
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
img_range=1., depths=[6, 6, 6, 6, 6, 6, 6, 6, 6], embed_dim=240,
|
| 14 |
-
num_heads=[8, 8, 8, 8, 8, 8, 8, 8, 8],
|
| 15 |
-
mlp_ratio=2, upsampler='nearest+conv', resi_connection='3conv')
|
| 16 |
-
super_res_pretrained_model = torch.load("model_zoo/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_PSNR.pth")
|
| 17 |
-
super_res_model.load_state_dict(super_res_pretrained_model[param_key_g] if param_key_g in super_res_pretrained_model.keys() else super_res_pretrained_model, strict=True)
|
| 18 |
-
super_res_model.eval()
|
| 19 |
|
| 20 |
def predict(input_img):
|
| 21 |
out = None
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
|
| 4 |
+
import _thread
|
| 5 |
+
import time
|
| 6 |
import torch
|
| 7 |
import numpy as np
|
| 8 |
from models.network_swinir import SwinIR as net
|
| 9 |
|
| 10 |
# model load
|
| 11 |
+
def load_model():
|
| 12 |
+
global super_res_model
|
| 13 |
+
global device
|
| 14 |
+
|
| 15 |
+
param_key_g = 'params_ema'
|
| 16 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 17 |
+
|
| 18 |
+
super_res_model = net(upscale=4, in_chans=3, img_size=64, window_size=8,
|
| 19 |
+
img_range=1., depths=[6, 6, 6, 6, 6, 6, 6, 6, 6], embed_dim=240,
|
| 20 |
+
num_heads=[8, 8, 8, 8, 8, 8, 8, 8, 8],
|
| 21 |
+
mlp_ratio=2, upsampler='nearest+conv', resi_connection='3conv')
|
| 22 |
+
super_res_pretrained_model = torch.load("model_zoo/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_PSNR.pth")
|
| 23 |
+
super_res_model.load_state_dict(super_res_pretrained_model[param_key_g] if param_key_g in super_res_pretrained_model.keys() else super_res_pretrained_model, strict=True)
|
| 24 |
+
super_res_model.eval()
|
| 25 |
|
| 26 |
+
_thread.start_new_thread(load_model, tuple())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def predict(input_img):
|
| 29 |
out = None
|