Spaces:
Runtime error
Runtime error
Eugene Siow
commited on
Commit
·
41506bf
1
Parent(s):
89d3a8e
Add pre download and setup of models first and DRLN and EDSR models.
Browse files
app.py
CHANGED
@@ -12,12 +12,7 @@ article = "<p style='text-align: center'><a href='https://github.com/eugenesiow/
|
|
12 |
"| <a href='https://github.com/eugenesiow/super-image#scale-x2'>Models</a></p>"
|
13 |
|
14 |
|
15 |
-
def
|
16 |
-
_id = randint(1, 1000)
|
17 |
-
output_dir = Path('./tmp/')
|
18 |
-
output_dir.mkdir(parents=True, exist_ok=True)
|
19 |
-
output_file = output_dir / ('output_image' + str(_id) + '.jpg')
|
20 |
-
scale = int(scale_str.replace('x', ''))
|
21 |
if model_name == 'EDSR':
|
22 |
model = EdsrModel.from_pretrained('eugenesiow/edsr', scale=scale)
|
23 |
elif model_name == 'MSRN':
|
@@ -40,6 +35,16 @@ def inference(img, scale_str, model_name):
|
|
40 |
model = RcanModel.from_pretrained('eugenesiow/rcan', scale=scale)
|
41 |
else:
|
42 |
model = EdsrModel.from_pretrained('eugenesiow/edsr-base', scale=scale)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
inputs = ImageLoader.load_image(img)
|
44 |
preds = model(inputs)
|
45 |
output_file_str = str(output_file.resolve())
|
@@ -51,8 +56,11 @@ torch.hub.download_url_to_file('http://people.rennes.inria.fr/Aline.Roumy/result
|
|
51 |
'baby.bmp')
|
52 |
torch.hub.download_url_to_file('http://people.rennes.inria.fr/Aline.Roumy/results/images_SR_BMVC12/input_groundtruth/woman_mini_d3_gaussian.bmp',
|
53 |
'woman.bmp')
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
56 |
|
57 |
gr.Interface(
|
58 |
inference,
|
@@ -68,7 +76,7 @@ gr.Interface(
|
|
68 |
article=article,
|
69 |
examples=[
|
70 |
['baby.bmp', 'x2', 'EDSR-base'],
|
71 |
-
['woman.bmp', 'x3', '
|
72 |
],
|
73 |
enable_queue=True
|
74 |
-
).launch(debug=
|
|
|
12 |
"| <a href='https://github.com/eugenesiow/super-image#scale-x2'>Models</a></p>"
|
13 |
|
14 |
|
15 |
+
def get_model(model_name, scale):
|
|
|
|
|
|
|
|
|
|
|
16 |
if model_name == 'EDSR':
|
17 |
model = EdsrModel.from_pretrained('eugenesiow/edsr', scale=scale)
|
18 |
elif model_name == 'MSRN':
|
|
|
35 |
model = RcanModel.from_pretrained('eugenesiow/rcan', scale=scale)
|
36 |
else:
|
37 |
model = EdsrModel.from_pretrained('eugenesiow/edsr-base', scale=scale)
|
38 |
+
return model
|
39 |
+
|
40 |
+
|
41 |
+
def inference(img, scale_str, model_name):
|
42 |
+
_id = randint(1, 1000)
|
43 |
+
output_dir = Path('./tmp/')
|
44 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
45 |
+
output_file = output_dir / ('output_image' + str(_id) + '.jpg')
|
46 |
+
scale = int(scale_str.replace('x', ''))
|
47 |
+
model = get_model(model_name, scale)
|
48 |
inputs = ImageLoader.load_image(img)
|
49 |
preds = model(inputs)
|
50 |
output_file_str = str(output_file.resolve())
|
|
|
56 |
'baby.bmp')
|
57 |
torch.hub.download_url_to_file('http://people.rennes.inria.fr/Aline.Roumy/results/images_SR_BMVC12/input_groundtruth/woman_mini_d3_gaussian.bmp',
|
58 |
'woman.bmp')
|
59 |
+
models = ['EDSR-base', 'DRLN', 'EDSR', 'MSRN', 'MDSR', 'AWSRN-BAM', 'A2N', 'CARN', 'PAN']
|
60 |
+
scales = [2, 3, 4]
|
61 |
+
for model_name in models:
|
62 |
+
for scale in scales:
|
63 |
+
get_model(model_name, scale)
|
64 |
|
65 |
gr.Interface(
|
66 |
inference,
|
|
|
76 |
article=article,
|
77 |
examples=[
|
78 |
['baby.bmp', 'x2', 'EDSR-base'],
|
79 |
+
['woman.bmp', 'x3', 'DRLN']
|
80 |
],
|
81 |
enable_queue=True
|
82 |
+
).launch(debug=False)
|