JeffLiang commited on
Commit
f037852
1 Parent(s): ee2b9bc
Files changed (3) hide show
  1. app.py +17 -11
  2. ovseg_clip_l_9a1909.pth +3 -0
  3. sam_vit_h_4b8939.pth +3 -0
app.py CHANGED
@@ -18,7 +18,7 @@ from detectron2.config import get_cfg
18
  from detectron2.projects.deeplab import add_deeplab_config
19
  from detectron2.data.detection_utils import read_image
20
  from open_vocab_seg import add_ovseg_config
21
- from open_vocab_seg.utils import VisualizationDemo
22
 
23
  import gradio as gr
24
 
@@ -38,13 +38,14 @@ def setup_cfg(config_file):
38
  return cfg
39
 
40
 
41
- def inference(class_names, input_img):
42
  mp.set_start_method("spawn", force=True)
43
  config_file = './ovseg_swinB_vitL_demo.yaml'
44
  cfg = setup_cfg(config_file)
45
-
46
- demo = VisualizationDemo(cfg)
47
-
 
48
  class_names = class_names.split(',')
49
  img = read_image(input_img, format="BGR")
50
  _, visualized_output = demo.run_on_image(img, class_names)
@@ -52,18 +53,21 @@ def inference(class_names, input_img):
52
  return Image.fromarray(np.uint8(visualized_output.get_image())).convert('RGB')
53
 
54
 
55
- examples = [['Oculus, Ukulele', './resources/demo_samples/sample_03.jpeg'],
56
- ['Saturn V, toys, blossom', './resources/demo_samples/sample_01.jpeg'],
57
- ['Golden gate, yacht', './resources/demo_samples/sample_02.jpeg'],]
 
 
58
  output_labels = ['segmentation map']
59
 
60
- title = 'OVSeg'
61
 
62
  description = """
 
63
  Gradio Demo for Open-Vocabulary Semantic Segmentation with Mask-adapted CLIP. \n
64
  OVSeg could perform open vocabulary segmentation, you may input more classes (seperate by comma). You may click on of the examples or upload your own image. \n
65
  It might take some time to process. Cheers!
66
- <p>Don't want to wait in queue? <a href="https://colab.research.google.com/drive/1O4Ain5uFZNcQYUmDTG92DpEGCatga8K5?usp=sharing"><img data-canonical-src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667"></a></p>
67
  """
68
 
69
  article = """
@@ -80,7 +84,9 @@ gr.Interface(
80
  inputs=[
81
  gr.inputs.Textbox(
82
  lines=1, placeholder=None, default='', label='class names'),
83
- gr.inputs.Image(type='filepath')
 
 
84
  ],
85
  outputs=gr.outputs.Image(label='segmentation map'),
86
  title=title,
 
18
  from detectron2.projects.deeplab import add_deeplab_config
19
  from detectron2.data.detection_utils import read_image
20
  from open_vocab_seg import add_ovseg_config
21
+ from open_vocab_seg.utils import VisualizationDemo, SAMVisualizationDemo
22
 
23
  import gradio as gr
24
 
 
38
  return cfg
39
 
40
 
41
+ def inference(class_names, proposal_gen, granularity, input_img):
42
  mp.set_start_method("spawn", force=True)
43
  config_file = './ovseg_swinB_vitL_demo.yaml'
44
  cfg = setup_cfg(config_file)
45
+ if proposal_gen == 'MaskFormer':
46
+ demo = VisualizationDemo(cfg)
47
+ elif proposal_gen == 'Segment_Anything':
48
+ demo = SAMVisualizationDemo(cfg, granularity, './sam_vit_h_4b8939.pth', './ovseg_clip_l_9a1909.pth')
49
  class_names = class_names.split(',')
50
  img = read_image(input_img, format="BGR")
51
  _, visualized_output = demo.run_on_image(img, class_names)
 
53
  return Image.fromarray(np.uint8(visualized_output.get_image())).convert('RGB')
54
 
55
 
56
+ examples = [['Saturn V, toys, desk, sunflowers, white roses, chrysanthemums, carnations, green dianthus', 'Segment_Anything', 0.8, './resources/demo_samples/sample_01.jpeg'],
57
+ ['red bench, yellow bench, black bench, blue bench, brown bench, green bench, red chair, blue chair, yellow chair, green chair', 'Segment_Anything', 0.8, './resources/demo_samples/sample_04.png'],
58
+ ['Saturn V, toys, blossom', 'MaskFormer', 1.0, './resources/demo_samples/sample_01.jpeg'],
59
+ ['Oculus, Ukulele', 'MaskFormer', 1.0, './resources/demo_samples/sample_03.jpeg'],
60
+ ['Golden gate, yacht', 'MaskFormer', 1.0, './resources/demo_samples/sample_02.jpeg'],]
61
  output_labels = ['segmentation map']
62
 
63
+ title = 'OVSeg (+ Segment_Anything)'
64
 
65
  description = """
66
+ [NEW!] We incorperate OVSeg CLIP w/ Segment_Anything, enabling SAM's text prompts.
67
  Gradio Demo for Open-Vocabulary Semantic Segmentation with Mask-adapted CLIP. \n
68
  OVSeg could perform open vocabulary segmentation, you may input more classes (seperate by comma). You may click on of the examples or upload your own image. \n
69
  It might take some time to process. Cheers!
70
+ <p>(Colab only supports MaskFormer proposal generator) Don't want to wait in queue? <a href="https://colab.research.google.com/drive/1O4Ain5uFZNcQYUmDTG92DpEGCatga8K5?usp=sharing"><img data-canonical-src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667"></a></p>
71
  """
72
 
73
  article = """
 
84
  inputs=[
85
  gr.inputs.Textbox(
86
  lines=1, placeholder=None, default='', label='class names'),
87
+ gr.inputs.Radio(["Segment_Anything", "MaskFormer"], label="Proposal generator", default="Segment_Anything"),
88
+ gr.inputs.Slider(0, 1.0, 0.8, label="For Segment_Anything, Granularity of masks from 0 (most coarse) to 1 (most precise)"),
89
+ gr.inputs.Image(type='filepath'),
90
  ],
91
  outputs=gr.outputs.Image(label='segmentation map'),
92
  title=title,
ovseg_clip_l_9a1909.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb5cbc83b922e18241654a19ad4cb836cf4f00169cd5684a4932d8a6f825dd36
3
+ size 1710616901
sam_vit_h_4b8939.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7bf3b02f3ebf1267aba913ff637d9a2d5c33d3173bb679e46d9f338c26f262e
3
+ size 2564550879