ariG23498 commited on
Commit
a2ca503
1 Parent(s): e1c2e43

chore: updating app with linked model

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import utils
 
 
2
  import streamlit as st
3
  import tensorflow as tf
4
 
@@ -13,4 +15,28 @@ image, preprocessed_image = utils.load_image_from_url(
13
  image_url,
14
  model_type="dino"
15
  )
16
- st.image(image, caption="Original Image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import utils
2
+ from huggingface_hub.keras_mixin import from_pretrained_keras
3
+ from PIL import Image
4
  import streamlit as st
5
  import tensorflow as tf
6
 
 
15
  image_url,
16
  model_type="dino"
17
  )
18
+ st.image(image, caption="Original Image")
19
+
20
+ # Load the DINO model
21
+ dino = from_pretrained_keras("probing-vits/vit-dino-base16")
22
+
23
+ # Get the attention scores
24
+ _, attention_score_dict = dino.predict(preprocessed_image)
25
+
26
+ # De-normalize the image for visual clarity.
27
+ in1k_mean = tf.constant([0.485 * 255, 0.456 * 255, 0.406 * 255])
28
+ in1k_std = tf.constant([0.229 * 255, 0.224 * 255, 0.225 * 255])
29
+ preprocessed_img_orig = (preprocessed_image * in1k_std) + in1k_mean
30
+ preprocessed_img_orig = preprocessed_img_orig / 255.
31
+ preprocessed_img_orig = tf.clip_by_value(preprocessed_img_orig, 0.0, 1.0).numpy()
32
+
33
+ attentions = utils.attention_heatmap(
34
+ attention_score_dict=attention_score_dict,
35
+ image=preprocessed_img_orig
36
+ )
37
+
38
+ utils.plot(attentions=attentions, image=preprocessed_img_orig)
39
+
40
+ # Show the attention maps
41
+ image = Image.open("heat_map.png")
42
+ st.image(image, caption="Attention Heat Maps")