Spaces:
Running
Running
add footnote
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- app.py +19 -11
- output.png +0 -0
- poster_vis/bench.png +0 -0
- poster_vis/bench1.png +0 -0
- poster_vis/bird.png +0 -0
- poster_vis/branch.png +0 -0
- poster_vis/car.png +0 -0
- poster_vis/chair.png +0 -0
- poster_vis/control tower.png +0 -0
- poster_vis/cow.png +0 -0
- poster_vis/demo/000000001611.png +0 -0
- poster_vis/demo/000000004068.png +0 -0
- poster_vis/demo/000000004546.png +0 -0
- poster_vis/demo/000000005076.png +0 -0
- poster_vis/demo/000000006336.png +0 -0
- poster_vis/demo/000000011766.png +0 -0
- poster_vis/demo/000000024458.png +0 -0
- poster_vis/demo/000000024931.png +0 -0
- poster_vis/demo/000000034214.png +0 -0
- poster_vis/demo/000000038116.png +0 -0
- poster_vis/demo/000000045280.png +0 -0
- poster_vis/demo/000000221509.png +0 -0
- poster_vis/demo/000000246066.png +0 -0
- poster_vis/demo/000000260974.png +0 -0
- poster_vis/demo/000000268340.png +0 -0
- poster_vis/demo/000000305414.png +0 -0
- poster_vis/demo/000000406874.png +0 -0
- poster_vis/demo/000000484246.png +0 -0
- poster_vis/demo/000000549338.png +0 -0
- poster_vis/demo/sketch_1.png +0 -0
- poster_vis/demo/sketch_2.png +0 -0
- poster_vis/demo/sketch_3.png +0 -0
- poster_vis/ears.png +0 -0
- poster_vis/elephant.png +0 -0
- poster_vis/giraffe.png +0 -0
- poster_vis/girrafe.png +0 -0
- poster_vis/grass.png +0 -0
- poster_vis/hands.png +0 -0
- poster_vis/hat.png +0 -0
- poster_vis/hat_1.png +0 -0
- poster_vis/horse.png +0 -0
- poster_vis/kite.png +0 -0
- poster_vis/mountains1.png +0 -0
- poster_vis/mountains2.png +0 -0
- poster_vis/mountains3.png +0 -0
- poster_vis/person.png +0 -0
- poster_vis/person1.png +0 -0
- poster_vis/planes.png +0 -0
- poster_vis/pot.png +0 -0
- poster_vis/sheeps.png +0 -0
app.py
CHANGED
@@ -22,7 +22,7 @@ cfg = setup(args)
|
|
22 |
|
23 |
multi_classes = False
|
24 |
|
25 |
-
device = "
|
26 |
Ours, preprocess = models.load("CS-ViT-B/16", device=device, cfg=cfg, train_bool=False)
|
27 |
state_dict = torch.load("sketch_seg_best_miou.pth", map_location=device)
|
28 |
|
@@ -37,6 +37,9 @@ print("Model loaded successfully")
|
|
37 |
|
38 |
|
39 |
def run(sketch, caption, threshold, seed):
|
|
|
|
|
|
|
40 |
# set the condidate classes here
|
41 |
caption = caption.replace('\n',' ')
|
42 |
translator = str.maketrans('', '', string.punctuation)
|
@@ -49,7 +52,7 @@ def run(sketch, caption, threshold, seed):
|
|
49 |
# print(classes)
|
50 |
|
51 |
colors = plt.get_cmap("Set1").colors
|
52 |
-
classes_colors = colors[:len(classes)]
|
53 |
|
54 |
sketch2 = sketch['composite']
|
55 |
|
@@ -127,9 +130,11 @@ def run(sketch, caption, threshold, seed):
|
|
127 |
plt.imshow(rgb_image)
|
128 |
plt.axis('off')
|
129 |
plt.tight_layout()
|
|
|
130 |
plt.savefig('output.png', bbox_inches='tight', pad_inches=0)
|
131 |
plt.close()
|
132 |
|
|
|
133 |
rgb_image = Image.open('output.png')
|
134 |
|
135 |
return rgb_image
|
@@ -212,9 +217,7 @@ async () => {
|
|
212 |
element.textContent = firstWord;
|
213 |
});
|
214 |
|
215 |
-
document.querySelector('input[type=number]').disabled = true;
|
216 |
-
|
217 |
-
|
218 |
}
|
219 |
"""
|
220 |
|
@@ -401,13 +404,16 @@ with gr.Blocks(js=scripts, css=css, theme='gstaff/xkcd') as demo:
|
|
401 |
with gr.Row():
|
402 |
with gr.Column():
|
403 |
# in_image = gr.Image( label="Sketch", type="pil", sources="upload" , height=512 )
|
404 |
-
in_canvas_image = gr.Sketchpad(
|
|
|
|
|
405 |
image_mode="RGBA",elem_classes=["white-bg", "gray-border" , "border-radius" ,"own-shadow" ] ,
|
406 |
-
label="Sketch" , canvas_size=(512,512) ,
|
407 |
-
interactive=True , layers= False, transforms=[]
|
|
|
408 |
query_selector = 'button[aria-label="Upload button"]'
|
|
|
409 |
# with gr.Row():
|
410 |
-
|
411 |
# segment_btn.click(fn=run, inputs=[in_image, in_textbox, in_slider], outputs=[out_image])
|
412 |
upload_draw_btn = gr.HTML(f"""
|
413 |
<div id="upload_draw_group" class="svelte-15lo0d8 stretch">
|
@@ -441,7 +447,7 @@ with gr.Blocks(js=scripts, css=css, theme='gstaff/xkcd') as demo:
|
|
441 |
value=0.5 , interactive=True, step=0.05, minimum=0, maximum=1)
|
442 |
|
443 |
with gr.Row():
|
444 |
-
segment_btn = gr.Button( 'Segment it !' , elem_classes=["white-bg", "gray-border" , "border-radius" ,"own-shadow" , 'bold' , 'mt-mb-1' ] , size="sm")
|
445 |
segment_btn.click(fn=run, inputs=[in_canvas_image , in_textbox , in_slider ], outputs=[out_image])
|
446 |
gallery_label = gr.HTML("<h3 class='black-text'> <span class='black-text underline'>Gallery:</span> <span style='color: grey;'>you can click on any of the example sketches below to start segmenting them (or even drawing over them)</span> </div>")
|
447 |
|
@@ -498,5 +504,7 @@ with gr.Blocks(js=scripts, css=css, theme='gstaff/xkcd') as demo:
|
|
498 |
fn=run,
|
499 |
# cache_examples=True,
|
500 |
)
|
501 |
-
|
|
|
|
|
502 |
demo.launch(share=False)
|
|
|
22 |
|
23 |
multi_classes = False
|
24 |
|
25 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
26 |
Ours, preprocess = models.load("CS-ViT-B/16", device=device, cfg=cfg, train_bool=False)
|
27 |
state_dict = torch.load("sketch_seg_best_miou.pth", map_location=device)
|
28 |
|
|
|
37 |
|
38 |
|
39 |
def run(sketch, caption, threshold, seed):
|
40 |
+
# select a random seed between 1 and 10 for the color
|
41 |
+
color_seed = np.random.randint(0, 9)
|
42 |
+
|
43 |
# set the condidate classes here
|
44 |
caption = caption.replace('\n',' ')
|
45 |
translator = str.maketrans('', '', string.punctuation)
|
|
|
52 |
# print(classes)
|
53 |
|
54 |
colors = plt.get_cmap("Set1").colors
|
55 |
+
classes_colors = colors[color_seed:len(classes)+color_seed]
|
56 |
|
57 |
sketch2 = sketch['composite']
|
58 |
|
|
|
130 |
plt.imshow(rgb_image)
|
131 |
plt.axis('off')
|
132 |
plt.tight_layout()
|
133 |
+
# plt.savefig(f'poster_vis/{classes[0]}.png', bbox_inches='tight', pad_inches=0)
|
134 |
plt.savefig('output.png', bbox_inches='tight', pad_inches=0)
|
135 |
plt.close()
|
136 |
|
137 |
+
# rgb_image = Image.open(f'poster_vis/{classes[0]}.png')
|
138 |
rgb_image = Image.open('output.png')
|
139 |
|
140 |
return rgb_image
|
|
|
217 |
element.textContent = firstWord;
|
218 |
});
|
219 |
|
220 |
+
document.querySelector('input[type=number]').disabled = true;
|
|
|
|
|
221 |
}
|
222 |
"""
|
223 |
|
|
|
404 |
with gr.Row():
|
405 |
with gr.Column():
|
406 |
# in_image = gr.Image( label="Sketch", type="pil", sources="upload" , height=512 )
|
407 |
+
in_canvas_image = gr.Sketchpad(
|
408 |
+
# value=Image.new('RGB', (512, 512), color=(255, 255, 255)),
|
409 |
+
brush=gr.Brush(colors=["#000000"], color_mode="fixed" , default_size=2),
|
410 |
image_mode="RGBA",elem_classes=["white-bg", "gray-border" , "border-radius" ,"own-shadow" ] ,
|
411 |
+
label="Sketch" , canvas_size=(512,512) ,sources=['upload'],
|
412 |
+
interactive=True , layers= False, transforms=[]
|
413 |
+
)
|
414 |
query_selector = 'button[aria-label="Upload button"]'
|
415 |
+
|
416 |
# with gr.Row():
|
|
|
417 |
# segment_btn.click(fn=run, inputs=[in_image, in_textbox, in_slider], outputs=[out_image])
|
418 |
upload_draw_btn = gr.HTML(f"""
|
419 |
<div id="upload_draw_group" class="svelte-15lo0d8 stretch">
|
|
|
447 |
value=0.5 , interactive=True, step=0.05, minimum=0, maximum=1)
|
448 |
|
449 |
with gr.Row():
|
450 |
+
segment_btn = gr.Button( 'Segment it* !' , elem_classes=["white-bg", "gray-border" , "border-radius" ,"own-shadow" , 'bold' , 'mt-mb-1' ] , size="sm")
|
451 |
segment_btn.click(fn=run, inputs=[in_canvas_image , in_textbox , in_slider ], outputs=[out_image])
|
452 |
gallery_label = gr.HTML("<h3 class='black-text'> <span class='black-text underline'>Gallery:</span> <span style='color: grey;'>you can click on any of the example sketches below to start segmenting them (or even drawing over them)</span> </div>")
|
453 |
|
|
|
504 |
fn=run,
|
505 |
# cache_examples=True,
|
506 |
)
|
507 |
+
|
508 |
+
gr.HTML("<h5 class='black-text' style='text-align: left;'>*For optimal performance, use a commercial Nvidia RTX 3090 (this demo runs on a basic 2 vCPU).</h5>")
|
509 |
+
gr.HTML("<h5 class='black-text' style='text-align: left;'>*We compare the entire caption to the scene sketch and threshold most similar pixels, without extracting individual classes.</h5>")
|
510 |
demo.launch(share=False)
|
output.png
CHANGED
poster_vis/bench.png
ADDED
poster_vis/bench1.png
ADDED
poster_vis/bird.png
ADDED
poster_vis/branch.png
ADDED
poster_vis/car.png
ADDED
poster_vis/chair.png
ADDED
poster_vis/control tower.png
ADDED
poster_vis/cow.png
ADDED
poster_vis/demo/000000001611.png
ADDED
poster_vis/demo/000000004068.png
ADDED
poster_vis/demo/000000004546.png
ADDED
poster_vis/demo/000000005076.png
ADDED
poster_vis/demo/000000006336.png
ADDED
poster_vis/demo/000000011766.png
ADDED
poster_vis/demo/000000024458.png
ADDED
poster_vis/demo/000000024931.png
ADDED
poster_vis/demo/000000034214.png
ADDED
poster_vis/demo/000000038116.png
ADDED
poster_vis/demo/000000045280.png
ADDED
poster_vis/demo/000000221509.png
ADDED
poster_vis/demo/000000246066.png
ADDED
poster_vis/demo/000000260974.png
ADDED
poster_vis/demo/000000268340.png
ADDED
poster_vis/demo/000000305414.png
ADDED
poster_vis/demo/000000406874.png
ADDED
poster_vis/demo/000000484246.png
ADDED
poster_vis/demo/000000549338.png
ADDED
poster_vis/demo/sketch_1.png
ADDED
poster_vis/demo/sketch_2.png
ADDED
poster_vis/demo/sketch_3.png
ADDED
poster_vis/ears.png
ADDED
poster_vis/elephant.png
ADDED
poster_vis/giraffe.png
ADDED
poster_vis/girrafe.png
ADDED
poster_vis/grass.png
ADDED
poster_vis/hands.png
ADDED
poster_vis/hat.png
ADDED
poster_vis/hat_1.png
ADDED
poster_vis/horse.png
ADDED
poster_vis/kite.png
ADDED
poster_vis/mountains1.png
ADDED
poster_vis/mountains2.png
ADDED
poster_vis/mountains3.png
ADDED
poster_vis/person.png
ADDED
poster_vis/person1.png
ADDED
poster_vis/planes.png
ADDED
poster_vis/pot.png
ADDED
poster_vis/sheeps.png
ADDED