MohamedRashad commited on
Commit
acc7dc1
1 Parent(s): 5547bc4
Files changed (3) hide show
  1. app.py +37 -0
  2. fox.jpg +0 -0
  3. parrot.jpg +0 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import paddlehub as hub
3
+ import gradio as gr
4
+ import torch
5
+
6
+ # Images
7
+ torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2018/08/12/16/59/ara-3601194_1280.jpg', 'parrot.jpg')
8
+ torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2016/10/21/14/46/fox-1758183_1280.jpg', 'fox.jpg')
9
+
10
+ model = hub.Module(name='U2NetP')
11
+
12
+ def infer(img):
13
+ result = model.Segmentation(
14
+ images=[cv2.imread(img.name)],
15
+ paths=None,
16
+ batch_size=1,
17
+ input_size=320,
18
+ output_dir='output',
19
+ visualization=True)
20
+ return result[0]['front'][:,:,::-1], result[0]['mask']
21
+
22
+ inputs = gr.inputs.Image(type='file', label="Original Image")
23
+ outputs = [
24
+ gr.outputs.Image(type="numpy",label="Front"),
25
+ gr.outputs.Image(type="numpy",label="Mask")
26
+ ]
27
+
28
+ title = "U^2-NetP"
29
+ description = "demo for U^2-Net Portrait. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
30
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2005.09007'>U^2-Net: Going Deeper with Nested U-Structure for Salient Object Detection</a> | <a href='https://github.com/xuebinqin/U-2-Net'>Github Repo</a></p>"
31
+
32
+ examples = [
33
+ ['fox.jpg'],
34
+ ['parrot.jpg']
35
+ ]
36
+
37
+ gr.Interface(infer, inputs, outputs, title=title, description=description, article=article, examples=examples).launch(share=True)
fox.jpg ADDED
parrot.jpg ADDED