From d241e84e2c78674b8aefc3d1a6ef27ab4727eeac Mon Sep 17 00:00:00 2001 From: AK391 Date: Wed, 5 May 2021 12:23:22 -0400 Subject: [PATCH 1/6] gradio demo --- gradio/demo.py | 28 ++++++++++++++++++++++++++++ requirements.txt | 4 ++++ 2 files changed, 32 insertions(+) create mode 100644 gradio/demo.py diff --git a/gradio/demo.py b/gradio/demo.py new file mode 100644 index 0000000..32ae04e --- /dev/null +++ b/gradio/demo.py @@ -0,0 +1,28 @@ +import cv2 +import paddlehub as hub +import gradio as gr + +model = hub.Module(name='U2Net') + +def infer(img): + result = model.Segmentation( + images=[cv2.imread(img.name)], + paths=None, + batch_size=1, + input_size=320, + output_dir='output', + visualization=True) + return result[0]['front'][:,:,::-1], result[0]['mask'] + +inputs = gr.inputs.Image(type='file', label="Original Image") +outputs = [ + gr.outputs.Image(type="numpy",label="Front"), + gr.outputs.Image(type="numpy",label="Mask") + ] + +title = "Artline" +description = "demo for OpenAI's CLIP. To use it, simply upload your image, or click one of the examples to load them and optionally add a text label seperated by commas to help clip classify the image better. Read more at the links below." +article = "

CLIP: Connecting Text and Images | Github Repo

" + + +gr.Interface(infer, inputs, outputs, title=title, description=description, article=article).launch(debug=True) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 85ccd0e..aa4fdba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,7 @@ scikit-image==0.14.0 torch==0.4.1.post2 torchvision==0.2.1 pillow==7.2.0 +opencv +paddlepaddle +paddlehub +gradio From 4fa44df9c508384fd08b9fcafefc6a7aef0f0365 Mon Sep 17 00:00:00 2001 From: AK391 Date: Wed, 5 May 2021 12:29:27 -0400 Subject: [PATCH 2/6] fix req --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index aa4fdba..1c5f2c9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ scikit-image==0.14.0 torch==0.4.1.post2 torchvision==0.2.1 pillow==7.2.0 -opencv +opencv-python paddlepaddle paddlehub gradio From c51831998a0aa938a408f25d75de1f8a99719b1f Mon Sep 17 00:00:00 2001 From: AK391 Date: Wed, 5 May 2021 12:39:42 -0400 Subject: [PATCH 3/6] examples and update --- gradio/demo.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gradio/demo.py b/gradio/demo.py index 32ae04e..2ad81ef 100644 --- a/gradio/demo.py +++ b/gradio/demo.py @@ -1,6 +1,11 @@ import cv2 import paddlehub as hub import gradio as gr +import torch + +# Images +torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2018/08/12/16/59/ara-3601194_1280.jpg', 'parrot.jpg') +torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2016/10/21/14/46/fox-1758183_1280.jpg', 'fox.jpg') model = hub.Module(name='U2Net') @@ -20,9 +25,13 @@ outputs = [ gr.outputs.Image(type="numpy",label="Mask") ] -title = "Artline" -description = "demo for OpenAI's CLIP. To use it, simply upload your image, or click one of the examples to load them and optionally add a text label seperated by commas to help clip classify the image better. Read more at the links below." -article = "

CLIP: Connecting Text and Images | Github Repo

" +title = "U^2-Net" +description = "demo for U^2-Net. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below." +article = "

U^2-Net: Going Deeper with Nested U-Structure for Salient Object Detection | Github Repo

" +examples = [ + ['fox.jpg'], + ['parrot.jpg'] +] -gr.Interface(infer, inputs, outputs, title=title, description=description, article=article).launch(debug=True) \ No newline at end of file +gr.Interface(infer, inputs, outputs, title=title, description=description, article=article, examples=examples).launch() \ No newline at end of file From e7256426a1fa1ca52f23aebe7234c34d573ee783 Mon Sep 17 00:00:00 2001 From: AK391 Date: Wed, 5 May 2021 12:45:01 -0400 Subject: [PATCH 4/6] req fix --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1c5f2c9..74e3a98 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ numpy==1.15.2 scikit-image==0.14.0 -torch==0.4.1.post2 +torch==1.1.0 torchvision==0.2.1 pillow==7.2.0 opencv-python From bab9fe1b833f9439fbd4f44809a3ef0b4b5d12fc Mon Sep 17 00:00:00 2001 From: AK391 Date: Wed, 5 May 2021 12:48:31 -0400 Subject: [PATCH 5/6] req upgrade --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 74e3a98..0355a3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ numpy==1.15.2 scikit-image==0.14.0 -torch==1.1.0 -torchvision==0.2.1 +torch +torchvision pillow==7.2.0 opencv-python paddlepaddle From f8dbc64e5de3b8090acb52ece734d485c45e8071 Mon Sep 17 00:00:00 2001 From: AK391 Date: Wed, 5 May 2021 12:58:13 -0400 Subject: [PATCH 6/6] readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0cd2548..2437b6a 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ year = {2020} ## Updates !!! +**(2021-May-5)** [**Gradio Web Demo**](https://gradio.app/hub/AK391/U-2-Net) + **(2021-Apr-29)** Thanks [**Jonathan Benavides Vallejo**](https://www.linkedin.com/in/jonathanbv/) for releasing his App [**LensOCR: Extract Text & Image**](https://apps.apple.com/ch/app/lensocr-extract-text-image/id1549961729?l=en&mt=12), which uses U^2-Net for extracting the image foreground. ![LensOCR APP](figures/LensOCR.jpg)