bienom commited on
Commit
307dfdb
1 Parent(s): 4261ef7

add masked items option

Browse files
Files changed (2) hide show
  1. app.py +8 -3
  2. model.py +5 -3
app.py CHANGED
@@ -5,13 +5,18 @@ from model import SegmentationTool
5
  seg_tool = SegmentationTool()
6
 
7
 
8
- def segment(input_img):
9
- mask_image, transparent_mask_image, image, items, room = seg_tool.get_mask(image=input_img)
 
10
  return mask_image
11
 
12
 
13
  demo = gr.Interface(fn=segment,
14
- inputs=gr.Image(type='pil'),
 
 
 
 
15
  outputs=['image'],
16
  allow_flagging='never')
17
  if __name__ == "__main__":
 
5
  seg_tool = SegmentationTool()
6
 
7
 
8
+ def segment(input_img, masked_items):
9
+ mask_image, transparent_mask_image, image, items, room = (
10
+ seg_tool.get_mask(image=input_img, masked_items=masked_items))
11
  return mask_image
12
 
13
 
14
  demo = gr.Interface(fn=segment,
15
+ inputs=[
16
+ gr.Image(type='pil'),
17
+ gr.CheckboxGroup([("Door", 14), ("Window", 8)],
18
+ value=[8, 14],
19
+ label="Masked Items")],
20
  outputs=['image'],
21
  allow_flagging='never')
22
  if __name__ == "__main__":
model.py CHANGED
@@ -68,7 +68,7 @@ class SegmentationTool:
68
 
69
  return mask_image
70
 
71
- def get_mask(self, image_path=None, image=None):
72
  if image_path:
73
  image = Image.open(image_path)
74
  else:
@@ -76,13 +76,15 @@ class SegmentationTool:
76
  raise ValueError("no image provided")
77
 
78
  # display(image)
 
79
  prediction = self._predict(image)
80
 
81
  label_ids = np.unique(prediction)
82
 
83
  # mask_items = [0, 3, 5, 8, 14]
84
- mask_items = [8] # windowpane
85
-
 
86
  if 73 in label_ids or 50 in label_ids or 61 in label_ids:
87
  # mask_items = [0, 3, 5, 8, 14, 50, 61, 71, 73, 118, 124, 129]
88
  room = 'kitchen'
 
68
 
69
  return mask_image
70
 
71
+ def get_mask(self, image_path=None, image=None, masked_items=None):
72
  if image_path:
73
  image = Image.open(image_path)
74
  else:
 
76
  raise ValueError("no image provided")
77
 
78
  # display(image)
79
+ # print(image)
80
  prediction = self._predict(image)
81
 
82
  label_ids = np.unique(prediction)
83
 
84
  # mask_items = [0, 3, 5, 8, 14]
85
+ # mask_items = [8] # windowpane
86
+ if masked_items is None:
87
+ masked_items = []
88
  if 73 in label_ids or 50 in label_ids or 61 in label_ids:
89
  # mask_items = [0, 3, 5, 8, 14, 50, 61, 71, 73, 118, 124, 129]
90
  room = 'kitchen'