Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
Author: Egrt
|
| 3 |
+
Date: 2022-01-04 21:46:25
|
| 4 |
+
LastEditors: Egrt
|
| 5 |
+
LastEditTime: 2022-01-07 19:49:19
|
| 6 |
+
FilePath: \License-super-resolution-master\app.py
|
| 7 |
+
'''
|
| 8 |
+
from Utilities.io import DataLoader
|
| 9 |
+
from Models.RRDBNet import RRDBNet
|
| 10 |
+
import numpy as np
|
| 11 |
+
import gradio as gr
|
| 12 |
+
import cv2
|
| 13 |
+
import os
|
| 14 |
+
loader = DataLoader()
|
| 15 |
+
# --------加载模型---------- #
|
| 16 |
+
MODEL_PATH = 'Pretrained/rrdb'
|
| 17 |
+
model = RRDBNet(blockNum=10)
|
| 18 |
+
model.load_weights(MODEL_PATH)
|
| 19 |
+
|
| 20 |
+
# --------模型推理---------- #
|
| 21 |
+
def inference(file):
|
| 22 |
+
# 将np转Tensor
|
| 23 |
+
input_image= loader.input_image(file.name)
|
| 24 |
+
# 维度扩张
|
| 25 |
+
input_image= np.expand_dims(input_image, axis=0)
|
| 26 |
+
yPred = model.predict(input_image)
|
| 27 |
+
yPred = np.squeeze(np.clip(yPred, a_min=0, a_max=1))
|
| 28 |
+
return yPred
|
| 29 |
+
|
| 30 |
+
# --------网页信息---------- #
|
| 31 |
+
title = "车牌超分辨率"
|
| 32 |
+
description = "基于生成对抗网络的车牌超分辨率,可从24×12像素的超低分辨率车牌图片恢复到正常可视状态@西南科技大学智能控制与图像处理研究室"
|
| 33 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2108.10257' target='_blank'>SwinIR: Image Restoration Using Swin Transformer</a> | <a href='https://github.com/JingyunLiang/SwinIR' target='_blank'>Github Repo</a></p>"
|
| 34 |
+
example_img_dir = 'Samples'
|
| 35 |
+
example_img_name = os.listdir(example_img_dir)
|
| 36 |
+
examples=[[os.path.join(example_img_dir, image_path)] for image_path in example_img_name if image_path.endswith('.jpg')]
|
| 37 |
+
gr.Interface(
|
| 38 |
+
inference,
|
| 39 |
+
[gr.inputs.Image(type="file", label="Input")],
|
| 40 |
+
gr.outputs.Image(type="numpy", label="Output"),
|
| 41 |
+
title=title,
|
| 42 |
+
description=description,
|
| 43 |
+
article=article,
|
| 44 |
+
enable_queue=True,
|
| 45 |
+
examples=examples
|
| 46 |
+
).launch(debug=True)
|