File size: 26,628 Bytes
cbba703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374a0d6
cbba703
ae3aed8
 
f00ee3e
 
 
ec1e968
 
374a0d6
4cd058c
 
 
 
 
 
 
 
374a0d6
c305a03
 
 
6faef3f
ec1e968
 
 
 
 
4cd058c
cb97d35
f00ee3e
 
a3f2113
f00ee3e
199d28b
cbba703
 
 
 
 
 
 
 
 
e9d5a30
cbba703
 
 
 
 
95bf211
cbba703
 
 
 
 
 
 
 
 
b61fad9
cbba703
 
f949a41
b61fad9
 
 
 
 
 
 
 
 
 
 
 
 
cbba703
 
 
 
 
 
 
 
 
 
 
 
 
 
b61fad9
cbba703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9d5a30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbba703
 
d4a60e3
cbba703
d4a60e3
 
cbba703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3f2113
 
cbba703
 
a3f2113
cbba703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3f2113
cbba703
 
 
 
 
 
 
 
b61fad9
cbba703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ad2222
b61fad9
cbba703
 
3ad2222
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbba703
 
 
 
 
 
 
 
374a0d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
import gradio as gr

from io import BytesIO
import requests
import PIL
from PIL import Image
import numpy as np
import os
import uuid
import torch
from torch import autocast
import cv2
from matplotlib import pyplot as plt
from inpainting import StableDiffusionInpaintingPipeline
from torchvision import transforms
from clipseg.models.clipseg import CLIPDensePredT

#from huggingface_hub import hf_hub_download
#hf_hub_download(repo_id="ThereforeGames/txt2mask", filename="/repositories/clipseg/")
#clone_from (str, optional) — Either a repository url or repo_id. Example:
#api = HfApi()

#from huggingface_hub import Repository
#with Repository(local_dir="clipseg", clone_from="ThereforeGames/txt2mask/repositories/clipseg/")
"""
import sys
import os

from zipfile import ZipFile
zf = ZipFile('clipseg-master.zip', 'r')
zf.extractall('./clipseg')
zf.close()


from huggingface_hub import HfApi
api = HfApi()
api.upload_folder(
    folder_path="/",
    path_in_repo="ThereforeGames/txt2mask/repositories/clipseg/",
    repo_id="ThereforeGames/txt2mask",
#    repo_type="dataset",
#    ignore_patterns="**/logs/*.txt",
)
"""
#.commit(commit_message="clipseg uploaded...")
#    with open("file.txt", "w+") as f:
#        f.write(json.dumps({"hey": 8}))


auth_token = os.environ.get("API_TOKEN") or True

def download_image(url):
    response = requests.get(url)
    return PIL.Image.open(BytesIO(response.content)).convert("RGB")

device = "cuda" if torch.cuda.is_available() else "cpu"
pipe = StableDiffusionInpaintingPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4",
    revision="fp16", 
    torch_dtype=torch.float16 if torch.cuda.is_available() else float
    use_auth_token=auth_token,
).to(device)

model = CLIPDensePredT(version='ViT-B/16', reduce_dim=64)
model.eval()
model.load_state_dict(torch.load('./clipseg/weights/rd64-uni.pth', map_location=torch.device(device)), strict=False)

transform = transforms.Compose([
      transforms.ToTensor(),
      transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
      transforms.Resize((512, 512)),
])

def predict(radio, dict, word_mask, prompt=""):
    if(radio == "draw a mask above"):
        with autocast(device): #"cuda"
            init_image = dict["image"].convert("RGB").resize((512, 512))
            mask = dict["mask"].convert("RGB").resize((512, 512))
    elif(radio == "type what to keep"):
        img = transform(dict["image"]).squeeze(0)
        word_masks = [word_mask]
        with torch.no_grad():
            preds = model(img.repeat(len(word_masks),1,1,1), word_masks)[0]
        init_image = dict['image'].convert('RGB').resize((512, 512))
        filename = f"{uuid.uuid4()}.png"
        plt.imsave(filename,torch.sigmoid(preds[0][0]))
        img2 = cv2.imread(filename)
        gray_image = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
        (thresh, bw_image) = cv2.threshold(gray_image, 100, 255, cv2.THRESH_BINARY)
        cv2.cvtColor(bw_image, cv2.COLOR_BGR2RGB)
        mask = Image.fromarray(np.uint8(bw_image)).convert('RGB')
        os.remove(filename)
    else:
        img = transform(dict["image"]).unsqueeze(0)
        word_masks = [word_mask]
        with torch.no_grad():
            preds = model(img.repeat(len(word_masks),1,1,1), word_masks)[0]
        init_image = dict['image'].convert('RGB').resize((512, 512))
        filename = f"{uuid.uuid4()}.png"
        plt.imsave(filename,torch.sigmoid(preds[0][0]))
        img2 = cv2.imread(filename)
        gray_image = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
        (thresh, bw_image) = cv2.threshold(gray_image, 100, 255, cv2.THRESH_BINARY)
        cv2.cvtColor(bw_image, cv2.COLOR_BGR2RGB)
        mask = Image.fromarray(np.uint8(bw_image)).convert('RGB')
        os.remove(filename)
    with autocast(device): #"cuda"
        images = pipe(prompt = prompt, init_image=init_image, mask_image=mask, strength=0.8)["sample"]
    return images[0]

# examples = [[dict(image="init_image.png", mask="mask_image.png"), "A panda sitting on a bench"]]
css = '''
.container {max-width: 1150px;margin: auto;padding-top: 1.5rem}
#image_upload{min-height:400px}
#image_upload [data-testid="image"], #image_upload [data-testid="image"] > div{min-height: 400px}
#mask_radio .gr-form{background:transparent; border: none}
#word_mask{margin-top: .75em !important}
#word_mask textarea:disabled{opacity: 0.3}
.footer {margin-bottom: 45px;margin-top: 35px;text-align: center;border-bottom: 1px solid #e5e5e5}
.footer>p {font-size: .8rem; display: inline-block; padding: 0 10px;transform: translateY(10px);background: white}
.dark .footer {border-color: #303030}
.dark .footer>p {background: #0b0f19}
.acknowledgments h4{margin: 1.25em 0 .25em 0;font-weight: bold;font-size: 115%}
#image_upload .touch-none{display: flex}

.markdown-body {
	font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
	font-size: 16px;
	line-height: 1.5;
	word-wrap: break-word;
}
.container-lg {
	max-width: 1012px;
	margin-right: auto;
	margin-left: auto;
}
[data-color-mode="auto"][data-light-theme*="light"] {
	--color-workflow-card-connector: var(--color-scale-gray-3);
	--color-workflow-card-connector-bg: var(--color-scale-gray-3);
	--color-workflow-card-connector-inactive: var(--color-border-default);
	--color-workflow-card-connector-inactive-bg: var(--color-border-default);
	--color-workflow-card-connector-highlight: var(--color-scale-blue-4);
	--color-workflow-card-connector-highlight-bg: var(--color-scale-blue-4);
	--color-workflow-card-bg: var(--color-scale-white);
	--color-workflow-card-inactive-bg: var(--color-canvas-inset);
	--color-workflow-card-header-shadow: rgba(0, 0, 0, 0);
	--color-workflow-card-progress-complete-bg: var(--color-scale-blue-4);
	--color-workflow-card-progress-incomplete-bg: var(--color-scale-gray-2);
	--color-discussions-state-answered-icon: var(--color-scale-white);
	--color-bg-discussions-row-emoji-box: rgba(209, 213, 218, 0.5);
	--color-notifications-button-text: var(--color-fg-muted);
	--color-notifications-button-hover-text: var(--color-fg-default);
	--color-notifications-button-hover-bg: var(--color-scale-gray-2);
	--color-notifications-row-read-bg: var(--color-canvas-subtle);
	--color-notifications-row-bg: var(--color-scale-white);
	--color-icon-directory: var(--color-scale-blue-3);
	--color-checks-step-error-icon: var(--color-scale-red-4);
	--color-calendar-halloween-graph-day-L1-bg: #ffee4a;
	--color-calendar-halloween-graph-day-L2-bg: #ffc501;
	--color-calendar-halloween-graph-day-L3-bg: #fe9600;
	--color-calendar-halloween-graph-day-L4-bg: #03001c;
	--color-calendar-graph-day-bg: #ebedf0;
	--color-calendar-graph-day-border: rgba(27, 31, 35, 0.06);
	--color-calendar-graph-day-L1-bg: #9be9a8;
	--color-calendar-graph-day-L2-bg: #40c463;
	--color-calendar-graph-day-L3-bg: #30a14e;
	--color-calendar-graph-day-L4-bg: #216e39;
	--color-calendar-graph-day-L1-border: rgba(27, 31, 35, 0.06);
	--color-calendar-graph-day-L2-border: rgba(27, 31, 35, 0.06);
	--color-calendar-graph-day-L3-border: rgba(27, 31, 35, 0.06);
	--color-calendar-graph-day-L4-border: rgba(27, 31, 35, 0.06);
	--color-user-mention-fg: var(--color-fg-default);
	--color-user-mention-bg: var(--color-attention-subtle);
	--color-text-white: var(--color-scale-white);
}
:root {
	--Layout-pane-width: 220px;
	--Layout-content-width: 100%;
	--Layout-template-columns: 1fr var(--Layout-pane-width);
	--Layout-template-areas: "content pane";
	--Layout-column-gap: 16px;
	--Layout-row-gap: 16px;
	--Layout-outer-spacing-x: 0px;
	--Layout-outer-spacing-y: 0px;
	--Layout-inner-spacing-min: 0px;
	--Layout-inner-spacing-max: 0px;
}
'''
def swap_word_mask(radio_option):
    if(radio_option == "draw a mask above"):
        return gr.update(interactive=False, placeholder="Disabled")
    else:
        return gr.update(interactive=True, placeholder="A cat")

image_blocks = gr.Blocks(css=css)
with image_blocks as demo:
    gr.HTML(
        """
            <div style="text-align: center; max-width: 650px; margin: 0 auto;">
              <div
                style="
                  display: inline-flex;
                  align-items: center;
                  gap: 0.8rem;
                  font-size: 1.75rem;
                "
              >
                <svg
                  width="0.65em"
                  height="0.65em"
                  viewBox="0 0 115 115"
                  fill="none"
                  xmlns="http://www.w3.org/2000/svg"
                >
                  <rect width="23" height="23" fill="#AEAEAE"></rect>
                  <rect y="69" width="23" height="23" fill="black"></rect>
                  <rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
                  <rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
                  <rect x="46" width="23" height="23" fill="#D9D9D9"></rect>
                  <rect x="46" y="69" width="23" height="23" fill="white"></rect>
                  <rect x="69" width="23" height="23" fill="black"></rect>
                  <rect x="69" y="69" width="23" height="23" fill="black"></rect>
                  <rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
                  <rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
                  <rect x="115" y="46" width="23" height="23" fill="white"></rect>
                  <rect x="115" y="115" width="23" height="23" fill="white"></rect>
                  <rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
                  <rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
                  <rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
                  <rect x="92" y="69" width="23" height="23" fill="white"></rect>
                  <rect x="69" y="46" width="23" height="23" fill="white"></rect>
                  <rect x="69" y="115" width="23" height="23" fill="white"></rect>
                  <rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
                  <rect x="46" y="46" width="23" height="23" fill="black"></rect>
                  <rect x="46" y="115" width="23" height="23" fill="black"></rect>
                  <rect x="46" y="69" width="23" height="23" fill="black"></rect>
                  <rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
                  <rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
                  <rect x="23" y="69" width="23" height="23" fill="black"></rect>
                </svg>
                <h1 style="font-weight: 900; margin-bottom: 7px;">
                  Stable Diffusion Multi Inpainting
                </h1>
              </div>
              <p style="margin-bottom: 10px; font-size: 94%">
                Inpaint Stable Diffusion by either drawing a mask or typing what to replace & what to keep !!!
              </p>
            </div>
        """
    )
    with gr.Row():
        with gr.Column():
            image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="Upload").style(height=400)
            with gr.Box(elem_id="mask_radio").style(border=False):
                radio = gr.Radio(["draw a mask above", "type what to mask below", "type what to keep"], value="draw a mask above", show_label=False, interactive=True).style(container=False)
                word_mask = gr.Textbox(label = "What to find in your image", interactive=False, elem_id="word_mask", placeholder="Disabled").style(container=False)
            prompt = gr.Textbox(label = 'Your prompt (what you want to add in place of what you are removing)')
            radio.change(fn=swap_word_mask, inputs=radio, outputs=word_mask,show_progress=False)
            radio.change(None, inputs=[], outputs=image_blocks, _js = """
            () => {
                css_style = document.styleSheets[document.styleSheets.length - 1]
                last_item = css_style.cssRules[css_style.cssRules.length - 1]
                last_item.style.display = ["flex", ""].includes(last_item.style.display) ? "none" : "flex";
            }""")
            btn = gr.Button("Run")
        with gr.Column():
            result = gr.Image(label="Result")
        btn.click(fn=predict, inputs=[radio, image, word_mask, prompt], outputs=result)
    gr.HTML(
            """
            <div class="footer">
                    <p>Model by <a href="https://huggingface.co/CompVis" style="text-decoration: underline;" target="_blank">CompVis</a> and <a href="https://huggingface.co/stabilityai" style="text-decoration: underline;" target="_blank">Stability AI</a> - Inpainting by <a href="https://github.com/" style="text-decoration: underline;" target="_blank">NightFury</a> using clipseg[model] with bit modification - Gradio Demo on 🤗 Hugging Face
                    </p>
                </div>
                
                
            <div id="readme" class="Box-body readme blob js-code-block-container p-5 p-xl-6 gist-border-0">
    <article class="markdown-body entry-content container-lg" itemprop="text"><h1 dir="auto"><a id="user-content-image-segmentation-using-text-and-image-prompts" class="anchor" aria-hidden="true" href="#image-segmentation-using-text-and-image-prompts"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Image Segmentation Using Text and Image Prompts</h1>
<p dir="auto">This repository contains the code used in the paper <a href="https://arxiv.org/abs/2112.10003" rel="nofollow">"Image Segmentation Using Text and Image Prompts"</a>.</p>
<p dir="auto"><strong>The Paper has been accepted to CVPR 2022!</strong></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer" href="/ThereforeGames/txt2mask/blob/main/repositories/clipseg/overview.png"><img src="/ThereforeGames/txt2mask/raw/main/repositories/clipseg/overview.png" alt="drawing" style="max-width: 100%;" height="200em"></a></p>
<p dir="auto">The systems allows to create segmentation models without training based on:</p>
<ul dir="auto">
<li>An arbitrary text query</li>
<li>Or an image with a mask highlighting stuff or an object.</li>
</ul>
<h3 dir="auto"><a id="user-content-quick-start" class="anchor" aria-hidden="true" href="#quick-start"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Quick Start</h3>
<p dir="auto">In the <code>Quickstart.ipynb</code> notebook we provide the code for using a pre-trained CLIPSeg model. If you run the notebook locally, make sure you downloaded the <code>rd64-uni.pth</code> weights, either manually or via git lfs extension.
It can also be used interactively using <a href="https://mybinder.org/v2/gh/timojl/clipseg/HEAD?labpath=Quickstart.ipynb" rel="nofollow">MyBinder</a>
(please note that the VM does not use a GPU, thus inference takes a few seconds).</p>
<h3 dir="auto"><a id="user-content-dependencies" class="anchor" aria-hidden="true" href="#dependencies"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Dependencies</h3>
<p dir="auto">This code base depends on pytorch, torchvision and clip (<code>pip install git+https://github.com/openai/CLIP.git</code>).
Additional dependencies are hidden for double blind review.</p>
<h3 dir="auto"><a id="user-content-datasets" class="anchor" aria-hidden="true" href="#datasets"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Datasets</h3>
<ul dir="auto">
<li><code>PhraseCut</code> and <code>PhraseCutPlus</code>: Referring expression dataset</li>
<li><code>PFEPascalWrapper</code>: Wrapper class for PFENet's Pascal-5i implementation</li>
<li><code>PascalZeroShot</code>: Wrapper class for PascalZeroShot</li>
<li><code>COCOWrapper</code>: Wrapper class for COCO.</li>
</ul>
<h3 dir="auto"><a id="user-content-models" class="anchor" aria-hidden="true" href="#models"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Models</h3>
<ul dir="auto">
<li><code>CLIPDensePredT</code>: CLIPSeg model with transformer-based decoder.</li>
<li><code>ViTDensePredT</code>: CLIPSeg model with transformer-based decoder.</li>
</ul>
<h3 dir="auto"><a id="user-content-third-party-dependencies" class="anchor" aria-hidden="true" href="#third-party-dependencies"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Third Party Dependencies</h3>
<p dir="auto">For some of the datasets third party dependencies are required. Run the following commands in the <code>third_party</code> folder.</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto"><pre>git clone https://github.com/cvlab-yonsei/JoEm
git clone https://github.com/Jia-Research-Lab/PFENet.git
git clone https://github.com/ChenyunWu/PhraseCutDataset.git
git clone https://github.com/juhongm999/hsnet.git</pre><div class="zeroclipboard-container position-absolute right-0 top-0">
    <clipboard-copy aria-label="Copy" class="ClipboardButton btn js-clipboard-copy m-2 p-0 tooltipped-no-delay" data-copy-feedback="Copied!" data-tooltip-direction="w" value="git clone https://github.com/cvlab-yonsei/JoEm
git clone https://github.com/Jia-Research-Lab/PFENet.git
git clone https://github.com/ChenyunWu/PhraseCutDataset.git
git clone https://github.com/juhongm999/hsnet.git" tabindex="0" role="button">
      <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-copy js-clipboard-copy-icon m-2">
    <path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path>
</svg>
      <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-check js-clipboard-check-icon color-fg-success d-none m-2">
    <path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path>
</svg>
    </clipboard-copy>
  </div></div>
<h3 dir="auto"><a id="user-content-weights" class="anchor" aria-hidden="true" href="#weights"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Weights</h3>
<p dir="auto">The MIT license does not apply to these weights.</p>
<ul dir="auto">
<li><a href="https://github.com/timojl/clipseg/raw/master/weights/rd64-uni.pth">CLIPSeg-D64</a> (4.1MB, without CLIP weights)</li>
<li><a href="https://github.com/timojl/clipseg/raw/master/weights/rd16-uni.pth">CLIPSeg-D16</a> (1.1MB, without CLIP weights)</li>
</ul>
<h3 dir="auto"><a id="user-content-training-and-evaluation" class="anchor" aria-hidden="true" href="#training-and-evaluation"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Training and Evaluation</h3>
<p dir="auto">To train use the <code>training.py</code> script with experiment file and experiment id parameters. E.g. <code>python training.py phrasecut.yaml 0</code> will train the first phrasecut experiment which is defined by the <code>configuration</code> and first <code>individual_configurations</code> parameters. Model weights will be written in <code>logs/</code>.</p>
<p dir="auto">For evaluation use <code>score.py</code>. E.g. <code>python score.py phrasecut.yaml 0 0</code> will train the first phrasecut experiment of <code>test_configuration</code> and the first configuration in <code>individual_configurations</code>.</p>
<h3 dir="auto"><a id="user-content-usage-of-pfenet-wrappers" class="anchor" aria-hidden="true" href="#usage-of-pfenet-wrappers"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Usage of PFENet Wrappers</h3>
<p dir="auto">In order to use the dataset and model wrappers for PFENet, the PFENet repository needs to be cloned to the root folder.
<code>git clone https://github.com/Jia-Research-Lab/PFENet.git </code></p>
<h3 dir="auto"><a id="user-content-license" class="anchor" aria-hidden="true" href="#license"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>License</h3>
<p dir="auto">The source code files in this repository (excluding model weights) are released under MIT license.</p>


</article>
  </div>
                <div class="acknowledgments">
                    <p><h4>LICENSE</h4>
The model is licensed with a <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" style="text-decoration: underline;" target="_blank">CreativeML Open RAIL-M</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p>
                    <p><h4>Biases and content acknowledgment</h4>
Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" style="text-decoration: underline;" target="_blank">model card</a></p>
               </div>
           """
        )
demo.launch()