Spaces:
Runtime error
Runtime error
add clip
Browse files
app.py
CHANGED
@@ -9,15 +9,15 @@
|
|
9 |
# ------------------------------------------------------------------------------
|
10 |
|
11 |
import os
|
12 |
-
#
|
13 |
-
# os.system(
|
14 |
-
os.system("pip install git+https://github.com/NVlabs/ODISE.git")
|
15 |
-
os.system("pip freeze")
|
16 |
|
17 |
import itertools
|
18 |
import json
|
19 |
from contextlib import ExitStack
|
20 |
import gradio as gr
|
|
|
|
|
21 |
import torch
|
22 |
from mask2former.data.datasets.register_ade20k_panoptic import ADE20K_150_CATEGORIES
|
23 |
from PIL import Image
|
@@ -31,20 +31,13 @@ from detectron2.data.datasets.builtin_meta import COCO_CATEGORIES
|
|
31 |
from detectron2.evaluation import inference_context
|
32 |
from detectron2.utils.env import seed_all_rng
|
33 |
from detectron2.utils.logger import setup_logger
|
34 |
-
from detectron2.utils.visualizer import ColorMode, Visualizer, random_color
|
35 |
|
36 |
from odise import model_zoo
|
37 |
from odise.checkpoint import ODISECheckpointer
|
38 |
from odise.config import instantiate_odise
|
39 |
from odise.data import get_openseg_labels
|
40 |
from odise.modeling.wrapper import OpenPanopticInference
|
41 |
-
from odise.utils.file_io import ODISEHandler, PathManager
|
42 |
-
from odise.model_zoo.model_zoo import _ModelZooUrls
|
43 |
-
|
44 |
-
for k in ODISEHandler.URLS:
|
45 |
-
ODISEHandler.URLS[k] = ODISEHandler.URLS[k].replace("https://github.com/NVlabs/ODISE/releases/download/v1.0.0/", "https://huggingface.co/xvjiarui/download_cache/resolve/main/torch/odise/")
|
46 |
-
PathManager.register_handler(ODISEHandler())
|
47 |
-
_ModelZooUrls.PREFIX = _ModelZooUrls.PREFIX.replace("https://github.com/NVlabs/ODISE/releases/download/v1.0.0/", "https://huggingface.co/xvjiarui/download_cache/resolve/main/torch/odise/")
|
48 |
|
49 |
setup_logger()
|
50 |
logger = setup_logger(name="odise")
|
@@ -81,6 +74,55 @@ LVIS_COLORS = list(
|
|
81 |
itertools.islice(itertools.cycle([c["color"] for c in COCO_CATEGORIES]), len(LVIS_CLASSES))
|
82 |
)
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
class VisualizationDemo(object):
|
86 |
def __init__(self, model, metadata, aug, instance_mode=ColorMode.IMAGE):
|
|
|
9 |
# ------------------------------------------------------------------------------
|
10 |
|
11 |
import os
|
12 |
+
# os.system("pip install git+https://github.com/NVlabs/ODISE.git")
|
13 |
+
# os.system("pip freeze")
|
|
|
|
|
14 |
|
15 |
import itertools
|
16 |
import json
|
17 |
from contextlib import ExitStack
|
18 |
import gradio as gr
|
19 |
+
import numpy as np
|
20 |
+
import matplotlib.colors as mplc
|
21 |
import torch
|
22 |
from mask2former.data.datasets.register_ade20k_panoptic import ADE20K_150_CATEGORIES
|
23 |
from PIL import Image
|
|
|
31 |
from detectron2.evaluation import inference_context
|
32 |
from detectron2.utils.env import seed_all_rng
|
33 |
from detectron2.utils.logger import setup_logger
|
34 |
+
from detectron2.utils.visualizer import ColorMode, Visualizer as _Visualizer, random_color
|
35 |
|
36 |
from odise import model_zoo
|
37 |
from odise.checkpoint import ODISECheckpointer
|
38 |
from odise.config import instantiate_odise
|
39 |
from odise.data import get_openseg_labels
|
40 |
from odise.modeling.wrapper import OpenPanopticInference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
setup_logger()
|
43 |
logger = setup_logger(name="odise")
|
|
|
74 |
itertools.islice(itertools.cycle([c["color"] for c in COCO_CATEGORIES]), len(LVIS_CLASSES))
|
75 |
)
|
76 |
|
77 |
+
class Visualizer(_Visualizer):
|
78 |
+
|
79 |
+
def draw_text(
|
80 |
+
self,
|
81 |
+
text,
|
82 |
+
position,
|
83 |
+
*,
|
84 |
+
font_size=None,
|
85 |
+
color="g",
|
86 |
+
horizontal_alignment="center",
|
87 |
+
rotation=0,
|
88 |
+
):
|
89 |
+
"""
|
90 |
+
Args:
|
91 |
+
text (str): class label
|
92 |
+
position (tuple): a tuple of the x and y coordinates to place text on image.
|
93 |
+
font_size (int, optional): font of the text. If not provided, a font size
|
94 |
+
proportional to the image width is calculated and used.
|
95 |
+
color: color of the text. Refer to `matplotlib.colors` for full list
|
96 |
+
of formats that are accepted.
|
97 |
+
horizontal_alignment (str): see `matplotlib.text.Text`
|
98 |
+
rotation: rotation angle in degrees CCW
|
99 |
+
|
100 |
+
Returns:
|
101 |
+
output (VisImage): image object with text drawn.
|
102 |
+
"""
|
103 |
+
if not font_size:
|
104 |
+
font_size = self._default_font_size
|
105 |
+
|
106 |
+
# since the text background is dark, we don't want the text to be dark
|
107 |
+
color = np.clip(color, 0, 1).tolist()
|
108 |
+
color = np.maximum(list(mplc.to_rgb(color)), 0.2)
|
109 |
+
color[np.argmax(color)] = max(0.8, np.max(color))
|
110 |
+
|
111 |
+
x, y = position
|
112 |
+
self.output.ax.text(
|
113 |
+
x,
|
114 |
+
y,
|
115 |
+
text,
|
116 |
+
size=font_size * self.output.scale,
|
117 |
+
family="sans-serif",
|
118 |
+
bbox={"facecolor": "black", "alpha": 0.8, "pad": 0.7, "edgecolor": "none"},
|
119 |
+
verticalalignment="top",
|
120 |
+
horizontalalignment=horizontal_alignment,
|
121 |
+
color=color,
|
122 |
+
zorder=10,
|
123 |
+
rotation=rotation,
|
124 |
+
)
|
125 |
+
return self.output
|
126 |
|
127 |
class VisualizationDemo(object):
|
128 |
def __init__(self, model, metadata, aug, instance_mode=ColorMode.IMAGE):
|