Spaces:
Runtime error
Runtime error
sunshangquan
commited on
Commit
·
c7e6ba9
1
Parent(s):
cf16bad
commit from ssq
Browse files
README.md
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: Histoformer
|
3 |
-
emoji: 🦀
|
4 |
-
colorFrom: yellow
|
5 |
-
colorTo: purple
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 5.0.1
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: mit
|
11 |
-
short_description: Adverse Weather Removal
|
12 |
-
---
|
13 |
-
|
14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -1,10 +1,32 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def predict(input_img):
|
7 |
-
prediction =
|
8 |
return input_img, prediction
|
9 |
|
10 |
gradio_app = gr.Interface(
|
|
|
1 |
+
import torch
|
2 |
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
import torch.nn.functional as F
|
5 |
|
6 |
+
from Allweather.util import load_img
|
7 |
+
from basicsr.models.archs.histoformer_arch import Histoformer
|
8 |
+
|
9 |
+
model_restoration = Histoformer()
|
10 |
+
checkpoint = torch.load("Allweather/pretrained_models/net_g_real.pth")
|
11 |
+
model_restoration.load_state_dict(checkpoint['params'])
|
12 |
+
model_restoration.cuda()
|
13 |
+
model_restoration = nn.DataParallel(model_restoration)
|
14 |
+
|
15 |
+
def preprocess(file_, factor = 8):
|
16 |
+
img = np.float32(load_img(file_))/255.
|
17 |
+
img = torch.from_numpy(img).permute(2,0,1)
|
18 |
+
input_ = img.unsqueeze(0).cuda()
|
19 |
+
|
20 |
+
# Padding in case images are not multiples of 8
|
21 |
+
h,w = input_.shape[2], input_.shape[3]
|
22 |
+
H,W = ((h+factor)//factor)*factor, ((w+factor)//factor)*factor
|
23 |
+
padh = H-h if h%factor!=0 else 0
|
24 |
+
padw = W-w if w%factor!=0 else 0
|
25 |
+
input_ = F.pad(input_, (0,padw,0,padh), 'reflect')
|
26 |
+
return input_
|
27 |
|
28 |
def predict(input_img):
|
29 |
+
prediction = model_restoration(preprocess(input_img))
|
30 |
return input_img, prediction
|
31 |
|
32 |
gradio_app = gr.Interface(
|
git.bash
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
git add .
|
|
|
|
|
|
1 |
+
git add .
|
2 |
+
git commit -m "commit from $USER"
|
3 |
+
git push
|
requirements.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
transformers
|
2 |
-
torch
|
|
|
|
|
|