Commit ·
11ac8da
1
Parent(s): a13d965
adding app.py
Browse files- .gitignore +1 -0
- app.py +30 -0
.gitignore
CHANGED
|
@@ -158,3 +158,4 @@ cython_debug/
|
|
| 158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 160 |
#.idea/
|
|
|
|
|
|
| 158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 160 |
#.idea/
|
| 161 |
+
gradio_cached_examples/*
|
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from u2net.u2net_inference import get_u2net_model, get_saliency_mask
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
+
import numpy as np
|
| 10 |
+
import gradio as gr
|
| 11 |
+
|
| 12 |
+
print('Loading model...')
|
| 13 |
+
model = get_u2net_model()
|
| 14 |
+
print('Successfully loaded model...')
|
| 15 |
+
examples = ['examples/1.jpg', 'examples/2.jpg', 'examples/3.jpg', 'examples/4.jpg','examples/5.jpg','examples/6.jpg']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def infer(image):
|
| 19 |
+
image_out = get_saliency_mask(model, image)
|
| 20 |
+
return image_out
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=infer,
|
| 25 |
+
title="U^2Net Based Saliency Estimatiion",
|
| 26 |
+
description = "U^2Net Saliency Estimation",
|
| 27 |
+
inputs=[gr.Image(label="image", type="numpy", shape=(640, 480))],
|
| 28 |
+
outputs="image",
|
| 29 |
+
cache_examples=True,
|
| 30 |
+
examples=examples).launch(debug=True)
|