zdou0830 commited on
Commit
971be17
1 Parent(s): fd60bd4
Dockerfile_back DELETED
@@ -1,103 +0,0 @@
1
- ENV PATH=/opt/conda/bin:/opt/cmake-3.14.6-Linux-x86_64/bin/:/usr/local/mpi/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/ucx/bin:/opt/tensorrt/bin
2
-
3
- ENV CUDA_VERSION=11.3.1.005
4
-
5
- ENV CUDA_DRIVER_VERSION=465.19.01
6
-
7
- ENV CUDA_CACHE_DISABLE=1
8
-
9
- ENV _CUDA_COMPAT_PATH=/usr/local/cuda/compat
10
-
11
- ENV ENV=/etc/shinit_v2
12
-
13
- ENV BASH_ENV=/etc/bash.bashrc
14
-
15
- ENV NVIDIA_REQUIRE_CUDA=cuda>=9.0
16
-
17
- ENV NCCL_VERSION=2.9.9
18
-
19
- ENV CUBLAS_VERSION=11.5.1.109
20
-
21
- ENV CUFFT_VERSION=10.4.2.109
22
-
23
- ENV CURAND_VERSION=10.2.4.109
24
-
25
- ENV CUSPARSE_VERSION=11.6.0.109
26
-
27
- ENV CUSOLVER_VERSION=11.1.2.109
28
-
29
- ENV NPP_VERSION=11.3.3.95
30
-
31
- ENV NVJPEG_VERSION=11.5.0.109
32
-
33
- ENV CUDNN_VERSION=8.2.1.32
34
-
35
- ENV TRT_VERSION=7.2.3.4+cuda11.1.0.024
36
-
37
- ENV TRTOSS_VERSION=21.06
38
-
39
- ENV NSIGHT_SYSTEMS_VERSION=2021.2.1.58
40
-
41
- ENV NSIGHT_COMPUTE_VERSION=2021.1.1.5
42
-
43
- ENV DALI_VERSION=1.2.0
44
-
45
- ENV DALI_BUILD=2356513
46
-
47
- ENV DLPROF_VERSION=21.06
48
-
49
- ENV LD_LIBRARY_PATH=/opt/hpcx/nccl_rdma_sharp_plugin/lib:/usr/local/cuda/compat/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64
50
-
51
- ENV NVIDIA_VISIBLE_DEVICES=all
52
-
53
- ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,video
54
-
55
- ENV GDRCOPY_VERSION=2.2
56
-
57
- ENV HPCX_VERSION=2.8.2rc3
58
-
59
- ENV MOFED_VERSION=5.2-rdmacore32.1
60
-
61
- ENV OPENUCX_VERSION=1.10.1
62
-
63
- ENV OPENMPI_VERSION=4.1.1rc1
64
-
65
- ENV RDMACORE_VERSION=32.1
66
-
67
- ENV LIBRARY_PATH=/usr/local/cuda/lib64/stubs:
68
-
69
- ENV PYTORCH_BUILD_VERSION=1.9.0a0+c3d40fd
70
-
71
- ENV PYTORCH_VERSION=1.9.0a0+c3d40fd
72
-
73
- ENV PYTORCH_BUILD_NUMBER=0
74
-
75
- ENV NVIDIA_PYTORCH_VERSION=21.06
76
-
77
- ENV NVM_DIR=/usr/local/nvm
78
-
79
- ENV JUPYTER_PORT=8888
80
-
81
- ENV TENSORBOARD_PORT=6006
82
-
83
- ENV COCOAPI_VERSION=2.0+nv0.5.1
84
-
85
- ENV PYTHONIOENCODING=utf-8
86
-
87
- ENV LC_ALL=C.UTF-8
88
-
89
- ENV NVIDIA_BUILD_ID=24129275
90
-
91
- ENV NCCL_ASYNC_ERROR_HANDLING=1
92
-
93
- EXPOSE 6006/tcp
94
-
95
- EXPOSE 8888/tcp
96
-
97
- WORKDIR /workspace
98
- ENTRYPOINT ["/usr/local/bin/nvidia_entrypoint.sh"]
99
-
100
-
101
- COPY . .
102
-
103
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
LICENSE ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) Liunian Harold Li, Zi-Yi Dou.
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE
app.py CHANGED
@@ -1,19 +1,4 @@
1
- '''import gradio as gr
2
- def update(name):
3
- return f"Welcome to Gradio, {name}!"
4
-
5
- with gr.Blocks() as demo:
6
- gr.Markdown("Start typing below and then click **Run** to see the output.")
7
- with gr.Row():
8
- inp = gr.Textbox(placeholder="What is your name?")
9
- out = gr.Textbox()
10
- btn = gr.Button("Run")
11
- btn.click(fn=update, inputs=inp, outputs=out)
12
-
13
- demo.launch()
14
-
15
-
16
- exit()#'''
17
 
18
  import requests
19
  import os
@@ -27,27 +12,14 @@ import warnings
27
 
28
  warnings.filterwarnings("ignore")
29
 
30
- # os.system(
31
- # "pip install einops shapely timm yacs tensorboardX ftfy prettytable pymongo click opencv-python inflect nltk scipy scikit-learn pycocotools")
32
- # os.system("pip install transformers")
33
  os.system("python setup.py build develop --user")
34
 
35
  from maskrcnn_benchmark.config import cfg
36
  from maskrcnn_benchmark.engine.predictor_glip import GLIPDemo
37
 
38
- # Use this command for evaluate the GLIP-T model
39
- #config_file = "configs/pretrain/glip_Swin_T_O365_GoldG.yaml"
40
- #weight_file = "MODEL/glip_tiny_model_o365_goldg_cc_sbu.pth"
41
-
42
  config_file = "configs/pretrain_new/desco_glip.yaml"
43
  weight_file = "MODEL/desco_glip_tiny.pth"
44
 
45
-
46
- # Use this command if you want to try the GLIP-L model
47
- # ! wget https://penzhanwu2bbs.blob.core.windows.net/data/GLIPv1_Open/models/glip_large_model.pth -O MODEL/glip_large_model.pth
48
- # config_file = "configs/pretrain/glip_Swin_L.yaml"
49
- # weight_file = "MODEL/glip_large_model.pth"
50
-
51
  # update the config options with the config file
52
  # manual override some options
53
  cfg.local_rank = 0
@@ -77,11 +49,8 @@ fiber_demo = GLIPDemo(
77
  show_mask_heatmaps=False
78
  )
79
 
80
- def predict(image, text, specified_tokens=""):
81
- if specified_tokens.strip() == "":
82
- specified_tokens = None
83
- else:
84
- specified_tokens = specified_tokens.strip().split(";")
85
  result, _ = glip_demo.run_on_web_image(deepcopy(image[:, :, [2, 1, 0]]), text, 0.5, specified_tokens)
86
  fiber_result, _ = fiber_demo.run_on_web_image(deepcopy(image[:, :, [2, 1, 0]]), text, 0.5, specified_tokens)
87
  return result[:, :, [2, 1, 0]], fiber_result[:, :, [2, 1, 0]]
@@ -90,27 +59,24 @@ def predict(image, text, specified_tokens=""):
90
  image = gr.inputs.Image()
91
 
92
  gr.Interface(
93
- description="Object Recognition with DesCo",
94
  fn=predict,
95
  inputs=["image", "text", "text"],
96
  outputs=[
97
  gr.outputs.Image(
98
  type="pil",
99
- # label="grounding results"
100
  ),
101
  gr.outputs.Image(
102
  type="pil",
103
- # label="grounding results"
104
  ),
105
  ],
106
  examples=[
107
- #["./flickr_9472793441.jpg", "bobble heads on top of the shelf ."],
108
- #["./flickr_9472793441.jpg", "sofa . remote . dog . person . car . sky . plane ."],
109
  ["./coco_000000281759.jpg", "A green umbrella. A pink striped umbrella. A plain white umbrella.", ""],
110
  ["./coco_000000281759.jpg", "a flowery top. A blue dress. An orange shirt .", ""],
111
  ["./coco_000000281759.jpg", "a car . An electricity box .", ""],
112
  ["./1.jpg", "a train besides sidewalk", "train;sidewalk"],
113
- #["./flickr_7520721.jpg", "A woman figure skater in a blue costume holds her leg by the blade of her skate ."]
114
  ],
115
  article=Path("docs/intro.md").read_text()
116
  ).launch()
 
1
+ # Reference: https://huggingface.co/spaces/haotiz/glip-zeroshot-demo/blob/main/app.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  import requests
4
  import os
 
12
 
13
  warnings.filterwarnings("ignore")
14
 
 
 
 
15
  os.system("python setup.py build develop --user")
16
 
17
  from maskrcnn_benchmark.config import cfg
18
  from maskrcnn_benchmark.engine.predictor_glip import GLIPDemo
19
 
 
 
 
 
20
  config_file = "configs/pretrain_new/desco_glip.yaml"
21
  weight_file = "MODEL/desco_glip_tiny.pth"
22
 
 
 
 
 
 
 
23
  # update the config options with the config file
24
  # manual override some options
25
  cfg.local_rank = 0
 
49
  show_mask_heatmaps=False
50
  )
51
 
52
+ def predict(image, text, ground_tokens=""):
53
+ ground_tokens = None if ground_tokens.strip() == "" else ground_tokens.strip().split(";")
 
 
 
54
  result, _ = glip_demo.run_on_web_image(deepcopy(image[:, :, [2, 1, 0]]), text, 0.5, specified_tokens)
55
  fiber_result, _ = fiber_demo.run_on_web_image(deepcopy(image[:, :, [2, 1, 0]]), text, 0.5, specified_tokens)
56
  return result[:, :, [2, 1, 0]], fiber_result[:, :, [2, 1, 0]]
 
59
  image = gr.inputs.Image()
60
 
61
  gr.Interface(
62
+ description="Object Recognition with DesCo (https://github.com/liunian-harold-li/DesCo)",
63
  fn=predict,
64
  inputs=["image", "text", "text"],
65
  outputs=[
66
  gr.outputs.Image(
67
  type="pil",
68
+ label="DesCo-GLIP"
69
  ),
70
  gr.outputs.Image(
71
  type="pil",
72
+ label="DesCo-FIBER"
73
  ),
74
  ],
75
  examples=[
 
 
76
  ["./coco_000000281759.jpg", "A green umbrella. A pink striped umbrella. A plain white umbrella.", ""],
77
  ["./coco_000000281759.jpg", "a flowery top. A blue dress. An orange shirt .", ""],
78
  ["./coco_000000281759.jpg", "a car . An electricity box .", ""],
79
  ["./1.jpg", "a train besides sidewalk", "train;sidewalk"],
 
80
  ],
81
  article=Path("docs/intro.md").read_text()
82
  ).launch()
docs/intro.md CHANGED
@@ -1 +1,6 @@
1
- DesCo
 
 
 
 
 
 
1
+ # DesCo
2
+ This is the HuggingFace Gradio Demo for the paper [DesCo: Learning Object Recognition with Rich Language Descriptions (NeurIPS 2023)](https://arxiv.org/pdf/2306.14060.pdf).
3
+
4
+ `ground_tokens` specifies which tokens we wish the model to ground to, separated by `;`; if it is not specified, the script will use NLTK to extract noun phrases automatically.
5
+
6
+ Code: https://github.com/liunian-harold-li/DesCo
main.py DELETED
@@ -1,105 +0,0 @@
1
- import gradio as gr
2
- import sys
3
- import torch
4
- import requests
5
- import socket
6
- from torchvision import transforms
7
- import os
8
- import asyncio
9
-
10
- torch.hub._validate_not_a_forked_repo=lambda a,b,c: True
11
-
12
- model = torch.hub.load("pytorch/vision:v0.6.0", "resnet18", pretrained=True).eval()
13
- response = requests.get("https://git.io/JJkYN")
14
- labels = response.text.split("\n")
15
-
16
-
17
- INITIAL_PORT_VALUE = int(os.getenv("GRADIO_SERVER_PORT", "7860"))
18
- TRY_NUM_PORTS = int(os.getenv("GRADIO_NUM_PORTS", "100"))
19
- LOCALHOST_NAME = os.getenv("GRADIO_SERVER_NAME", "127.0.0.1")
20
- GRADIO_API_SERVER = "https://api.gradio.app/v1/tunnel-request"
21
-
22
-
23
- if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"):
24
- # "Any thread" and "selector" should be orthogonal, but there's not a clean
25
- # interface for composing policies so pick the right base.
26
- _BasePolicy = asyncio.WindowsSelectorEventLoopPolicy # type: ignore
27
- else:
28
- _BasePolicy = asyncio.DefaultEventLoopPolicy
29
-
30
-
31
- class AnyThreadEventLoopPolicy(_BasePolicy): # type: ignore
32
- """Event loop policy that allows loop creation on any thread.
33
- The default `asyncio` event loop policy only automatically creates
34
- event loops in the main threads. Other threads must create event
35
- loops explicitly or `asyncio.get_event_loop` (and therefore
36
- `.IOLoop.current`) will fail. Installing this policy allows event
37
- loops to be created automatically on any thread, matching the
38
- behavior of Tornado versions prior to 5.0 (or 5.0 on Python 2).
39
- Usage::
40
- asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
41
- .. versionadded:: 5.0
42
- """
43
-
44
- def get_event_loop(self) -> asyncio.AbstractEventLoop:
45
- try:
46
- return super().get_event_loop()
47
- except (RuntimeError, AssertionError):
48
- # This was an AssertionError in python 3.4.2 (which ships with debian jessie)
49
- # and changed to a RuntimeError in 3.4.3.
50
- # "There is no current event loop in thread %r"
51
- loop = self.new_event_loop()
52
- self.set_event_loop(loop)
53
- return loop
54
-
55
-
56
- asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
57
-
58
- def get_first_available_port(initial: int, final: int) -> int:
59
- """
60
- Gets the first open port in a specified range of port numbers
61
- Parameters:
62
- initial: the initial value in the range of port numbers
63
- final: final (exclusive) value in the range of port numbers, should be greater than `initial`
64
- Returns:
65
- port: the first open port in the range
66
- """
67
- for port in range(initial, final):
68
- try:
69
- s = socket.socket() # create a socket object
70
- s.bind((LOCALHOST_NAME, port)) # Bind to the port
71
- s.close()
72
- return port
73
- except OSError:
74
- pass
75
- raise OSError(
76
- "All ports from {} to {} are in use. Please close a port.".format(
77
- initial, final
78
- )
79
- )
80
-
81
- def predict(inp):
82
- inp = transforms.ToTensor()(inp).unsqueeze(0)
83
- with torch.no_grad():
84
- prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
85
- confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
86
- return confidences
87
-
88
-
89
- def run():
90
- demo = gr.Interface(
91
- fn=predict,
92
- inputs=gr.inputs.Image(type="pil"),
93
- outputs=gr.outputs.Label(num_top_classes=3),
94
- )
95
-
96
- demo.launch() #server_name="0.0.0.0", server_port=7861)
97
- #demo.launch(server_name=LOCALHOST_NAME, server_port=get_first_available_port(
98
- # INITIAL_PORT_VALUE, INITIAL_PORT_VALUE + TRY_NUM_PORTS
99
- # ), share=True)
100
- #demo.launch(server_name="0.0.0.0", server_port=7861)
101
-
102
-
103
- if __name__ == "__main__":
104
- run()
105
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
maskrcnn_benchmark/modeling/rpn/inference.py CHANGED
@@ -726,7 +726,6 @@ class ATSSPostProcessor(torch.nn.Module):
726
  if number_of_detections > self.fpn_post_nms_top_n > 0:
727
  cls_scores = result.get_field("scores")
728
  image_thresh, _ = torch.kthvalue(
729
- # TODO: confirm with Pengchuan and Xiyang, torch.kthvalue is not implemented for 'Half'
730
  # cls_scores.cpu(),
731
  cls_scores.cpu().float(),
732
  number_of_detections - self.fpn_post_nms_top_n + 1,
 
726
  if number_of_detections > self.fpn_post_nms_top_n > 0:
727
  cls_scores = result.get_field("scores")
728
  image_thresh, _ = torch.kthvalue(
 
729
  # cls_scores.cpu(),
730
  cls_scores.cpu().float(),
731
  number_of_detections - self.fpn_post_nms_top_n + 1,
tools/.DS_Store DELETED
Binary file (10.2 kB)