sneha
commited on
Commit
·
4ef25ba
1
Parent(s):
ffecbe9
add slider
Browse files
app.py
CHANGED
@@ -63,7 +63,7 @@ def download_bin(model):
|
|
63 |
os.rename(model_bin, bin_path)
|
64 |
|
65 |
|
66 |
-
def run_attn(input_img, model="vc1-large"):
|
67 |
download_bin(model)
|
68 |
model, embedding_dim, transform, metadata = get_model(model)
|
69 |
if input_img.shape[0] != 3:
|
@@ -75,7 +75,7 @@ def run_attn(input_img, model="vc1-large"):
|
|
75 |
input_img = resize_transform(input_img)
|
76 |
x = transform(input_img)
|
77 |
|
78 |
-
attention_rollout = VITAttentionGradRollout(model,head_fusion="max",discard_ratio=
|
79 |
|
80 |
y = model(x)
|
81 |
mask = attention_rollout.get_attn_mask()
|
@@ -86,11 +86,11 @@ model_type = gr.Dropdown(
|
|
86 |
["vc1-base", "vc1-large"], label="Model Size", value="vc1-large")
|
87 |
input_img = gr.Image(shape=(250,250))
|
88 |
output_img = gr.Image(shape=(250,250))
|
|
|
89 |
css = "#component-2, .input-image, .image-preview {height: 240px !important}"
|
90 |
-
markdown ="This is a demo for the Visual Cortex models. When passed an image input, it displays the attention of the last layer of the transformer
|
91 |
-
|
92 |
-
Along with the attention heatmap, it also displays the embedding values reshaped to a 16x48 or 16x64 grid."
|
93 |
demo = gr.Interface(fn=run_attn, title="Visual Cortex Large Model", description=markdown,
|
94 |
-
examples=[[os.path.join('./imgs',x),None]for x in os.listdir(os.path.join(os.getcwd(),'imgs')) if 'jpg' in x],
|
95 |
-
inputs=[input_img,model_type],outputs=output_img,css=css)
|
96 |
demo.launch()
|
|
|
63 |
os.rename(model_bin, bin_path)
|
64 |
|
65 |
|
66 |
+
def run_attn(input_img, model="vc1-large",discard_ratio=0.89):
|
67 |
download_bin(model)
|
68 |
model, embedding_dim, transform, metadata = get_model(model)
|
69 |
if input_img.shape[0] != 3:
|
|
|
75 |
input_img = resize_transform(input_img)
|
76 |
x = transform(input_img)
|
77 |
|
78 |
+
attention_rollout = VITAttentionGradRollout(model,head_fusion="max",discard_ratio=discard_ratio)
|
79 |
|
80 |
y = model(x)
|
81 |
mask = attention_rollout.get_attn_mask()
|
|
|
86 |
["vc1-base", "vc1-large"], label="Model Size", value="vc1-large")
|
87 |
input_img = gr.Image(shape=(250,250))
|
88 |
output_img = gr.Image(shape=(250,250))
|
89 |
+
discard_ratio = gr.Slider(0,1,value=0.89)
|
90 |
css = "#component-2, .input-image, .image-preview {height: 240px !important}"
|
91 |
+
markdown ="This is a demo for the Visual Cortex models. When passed an image input, it displays the attention of the last layer of the transformer."
|
92 |
+
|
|
|
93 |
demo = gr.Interface(fn=run_attn, title="Visual Cortex Large Model", description=markdown,
|
94 |
+
examples=[[os.path.join('./imgs',x),None,None]for x in os.listdir(os.path.join(os.getcwd(),'imgs')) if 'jpg' in x],
|
95 |
+
inputs=[input_img,model_type,discard_ratio],outputs=output_img,css=css)
|
96 |
demo.launch()
|