noelshin commited on
Commit
7b03ec2
1 Parent(s): 68aa8af

downgrade gradio to 2.9.0 from 3.0.17 for a better example UI

Browse files
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
  title: Selfmask
3
- emoji: 📉
4
  colorFrom: gray
5
  colorTo: gray
6
  sdk: gradio
7
- sdk_version: 3.0.17
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
1
  ---
2
  title: Selfmask
3
+ emoji: 😷
4
  colorFrom: gray
5
  colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 2.9.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
__pycache__/bilateral_solver.cpython-38.pyc CHANGED
Binary files a/__pycache__/bilateral_solver.cpython-38.pyc and b/__pycache__/bilateral_solver.cpython-38.pyc differ
 
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from argparse import ArgumentParser, Namespace
2
  from typing import Dict, List, Tuple
 
3
  import yaml
4
  import numpy as np
5
  import cv2
@@ -26,23 +27,6 @@ parser.add_argument(
26
  default="duts-dino-k234-nq20-224-swav-mocov2-dino-p16-sr10100.yaml"
27
  )
28
 
29
- # parser.add_argument(
30
- # "--p_state_dict",
31
- # type=str,
32
- # default="/users/gyungin/selfmask_bak/ckpt/nq20_ndl6_bc_sr10100_duts_pm_all_k2,3,4_md_seed0_final/eval/hku_is/best_model.pt",
33
- # )
34
- #
35
- # parser.add_argument(
36
- # "--dataset_name", '-dn', type=str, default="duts",
37
- # choices=["dut_omron", "duts", "ecssd"]
38
- # )
39
-
40
- # independent variables
41
- # parser.add_argument("--use_gpu", type=bool, default=True)
42
- # parser.add_argument('--seed', default=0, type=int)
43
- # parser.add_argument("--dir_root", type=str, default="..")
44
- # parser.add_argument("--gpu_id", type=int, default=2)
45
- # parser.add_argument("--suffix", type=str, default='')
46
  args: Namespace = parser.parse_args()
47
  base_args = yaml.safe_load(open(f"{args.config}", 'r'))
48
  base_args.pop("dataset_name")
@@ -54,15 +38,14 @@ model = get_model(arch="maskformer", configs=args).to(device)
54
  model.load_state_dict(state_dict)
55
  model.eval()
56
 
 
 
 
 
 
57
 
58
  @torch.no_grad()
59
- def main(
60
- image: Image.Image,
61
- size: int = 384,
62
- max_size: int = 512,
63
- mean: Tuple[float, float, float] = (0.485, 0.456, 0.406),
64
- std: Tuple[float, float, float] = (0.229, 0.224, 0.225)
65
- ):
66
  pil_image: Image.Image = resize(image, size=size, max_size=max_size)
67
  image: torch.Tensor = normalize(to_tensor(pil_image), mean=list(mean), std=list(std)) # 3 x H x W
68
  dict_outputs = model(image[None].to(device))
@@ -101,10 +84,11 @@ def main(
101
  return super_imposed_img
102
  # return pred_mask_bi
103
 
 
104
  demo = gr.Interface(
105
  fn=main,
106
- inputs=gr.inputs.Image(type="pil"),
107
- outputs="image",
108
  examples=[f"resources/{fname}.jpg" for fname in [
109
  "0053",
110
  "0236",
@@ -124,6 +108,8 @@ demo = gr.Interface(
124
  "sun_amnrcxhisjfrliwa",
125
  "sun_bvyxpvkouzlfwwod"
126
  ]],
 
 
127
  title="Unsupervised Salient Object Detection with Spectral Cluster Voting",
128
  allow_flagging="never",
129
  analytics_enabled=False
 
1
  from argparse import ArgumentParser, Namespace
2
  from typing import Dict, List, Tuple
3
+ import codecs
4
  import yaml
5
  import numpy as np
6
  import cv2
 
27
  default="duts-dino-k234-nq20-224-swav-mocov2-dino-p16-sr10100.yaml"
28
  )
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  args: Namespace = parser.parse_args()
31
  base_args = yaml.safe_load(open(f"{args.config}", 'r'))
32
  base_args.pop("dataset_name")
 
38
  model.load_state_dict(state_dict)
39
  model.eval()
40
 
41
+ size: int = 384
42
+ max_size: int = 512
43
+ mean: Tuple[float, float, float] = (0.485, 0.456, 0.406)
44
+ std: Tuple[float, float, float] = (0.229, 0.224, 0.225)
45
+
46
 
47
  @torch.no_grad()
48
+ def main(image: Image):
 
 
 
 
 
 
49
  pil_image: Image.Image = resize(image, size=size, max_size=max_size)
50
  image: torch.Tensor = normalize(to_tensor(pil_image), mean=list(mean), std=list(std)) # 3 x H x W
51
  dict_outputs = model(image[None].to(device))
 
84
  return super_imposed_img
85
  # return pred_mask_bi
86
 
87
+
88
  demo = gr.Interface(
89
  fn=main,
90
+ inputs=gr.inputs.Image(type="pil", source="upload", tool="editor"),
91
+ outputs=gr.outputs.Image(type="numpy", label="saliency map"), # "image",
92
  examples=[f"resources/{fname}.jpg" for fname in [
93
  "0053",
94
  "0236",
 
108
  "sun_amnrcxhisjfrliwa",
109
  "sun_bvyxpvkouzlfwwod"
110
  ]],
111
+ examples_per_page=20,
112
+ description=codecs.open("description.html", 'r', "utf-8").read(),
113
  title="Unsupervised Salient Object Detection with Spectral Cluster Voting",
114
  allow_flagging="never",
115
  analytics_enabled=False
description.html CHANGED
@@ -1,10 +1,16 @@
1
  <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
4
- <meta charset="UTF-8">
5
- <title>$Title$</title>
6
  </head>
7
  <body>
8
- $END$
 
 
 
 
 
 
9
  </body>
10
  </html>
 
1
  <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <title>Title</title>
6
  </head>
7
  <body>
8
+ This is a demo of <a href="https://arxiv.org/pdf/2203.12614.pdf">Unsupervised Salient Object Detection with Spectral Cluster Voting</a> (CVPRW 2022).</br>
9
+ In the paper, we tackle the challenging task of unsupervised salient object detection (SOD) by leveraging spectral clustering on self-supervised features.
10
+ We make the following contributions:
11
+ (i) We revisit spectral clustering and demonstrate its potential to group the pixels of salient objects;
12
+ (ii) Given mask proposals from multiple applications of spectral clustering on image features computed from various self-supervised models, e.g., MoCov2, SwAV, DINO, we propose a simple but effective winner-takes-all voting mechanism for selecting the salient masks, leveraging object priors based on framing and distinctiveness;
13
+ (iii) Using the selected object segmentation as pseudo groundtruth masks, we train a salient object detector, dubbed SelfMask, which outperforms prior approaches on three unsupervised SOD benchmarks.
14
+ Code is publicly available at <a href="https://github.com/NoelShin/selfmask">our repo</a>.
15
  </body>
16
  </html>