Sujit Pal commited on
Commit
5de821f
1 Parent(s): 6d88167

fix: removing commented out code since runs on HF spaces

Browse files
dashboard_featurefinder.py CHANGED
@@ -15,14 +15,10 @@ from PIL import Image
15
  import utils
16
 
17
  BASELINE_MODEL = "openai/clip-vit-base-patch32"
18
- # MODEL_PATH = "/home/shared/models/clip-rsicd/bs128x8-lr5e-6-adam/ckpt-1"
19
  MODEL_PATH = "flax-community/clip-rsicd-v2"
20
 
21
- # IMAGE_VECTOR_FILE = "/home/shared/data/vectors/test-baseline.tsv"
22
- # IMAGE_VECTOR_FILE = "/home/shared/data/vectors/test-bs128x8-lr5e-6-adam-ckpt-1.tsv"
23
  IMAGE_VECTOR_FILE = "./vectors/test-bs128x8-lr5e-6-adam-ckpt-1.tsv"
24
 
25
- # IMAGES_DIR = "/home/shared/data/rsicd_images"
26
  IMAGES_DIR = "./images"
27
  DEMO_IMAGES_DIR = "./demo-images"
28
 
@@ -113,7 +109,6 @@ def app():
113
  to look for, this will show the original image, and you will get more ideas
114
  for features that you can ask the model to identify.
115
  """)
116
- # buf = st.file_uploader("Upload Image for Analysis", type=["png", "jpg"])
117
  image_file = st.selectbox(
118
  "Sample Image File",
119
  options=[
@@ -132,8 +127,6 @@ def app():
132
  searched_feature = st.text_input("Feature to find", value="beach")
133
 
134
  if st.button("Find"):
135
- # print("image_file:", image_file)
136
- # print("image_url:", image_url)
137
  if image_file.startswith("--"):
138
  image = download_and_prepare_image(image_url)
139
  else:
@@ -144,9 +137,7 @@ def app():
144
  else:
145
  st.image(image, caption="Input Image")
146
  st.markdown("---")
147
- # print("image.shape:", image.shape)
148
  num_rows, num_cols, patches = split_image(image)
149
- # print("num_rows, num_cols, num(patches:", num_rows, num_cols, len(patches), patches[0].shape)
150
  image_preprocessor = Compose([
151
  ToPILImage(),
152
  Resize(224)
@@ -167,9 +158,3 @@ def app():
167
  patch_ranks[pid] + 1, searched_feature, patch_probs[pid])
168
  col.image(patches[pid], caption=caption)
169
  pid += 1
170
- # row_patches = patches[i * num_cols : (i + 1) * num_cols]
171
- # row_probs = patch_probs[i * num_cols : (i + 1) * num_cols]
172
- # row_ranks = patch_ranks[i * num_cols : (i + 1) * num_cols]
173
- # captions = ["p({:s})={:.3f}, rank={:d}".format(searched_feature, p, r + 1)
174
- # for p, r in zip(row_probs, row_ranks)]
175
- # st.image(row_patches, caption=captions)
 
15
  import utils
16
 
17
  BASELINE_MODEL = "openai/clip-vit-base-patch32"
 
18
  MODEL_PATH = "flax-community/clip-rsicd-v2"
19
 
 
 
20
  IMAGE_VECTOR_FILE = "./vectors/test-bs128x8-lr5e-6-adam-ckpt-1.tsv"
21
 
 
22
  IMAGES_DIR = "./images"
23
  DEMO_IMAGES_DIR = "./demo-images"
24
 
 
109
  to look for, this will show the original image, and you will get more ideas
110
  for features that you can ask the model to identify.
111
  """)
 
112
  image_file = st.selectbox(
113
  "Sample Image File",
114
  options=[
 
127
  searched_feature = st.text_input("Feature to find", value="beach")
128
 
129
  if st.button("Find"):
 
 
130
  if image_file.startswith("--"):
131
  image = download_and_prepare_image(image_url)
132
  else:
 
137
  else:
138
  st.image(image, caption="Input Image")
139
  st.markdown("---")
 
140
  num_rows, num_cols, patches = split_image(image)
 
141
  image_preprocessor = Compose([
142
  ToPILImage(),
143
  Resize(224)
 
158
  patch_ranks[pid] + 1, searched_feature, patch_probs[pid])
159
  col.image(patches[pid], caption=caption)
160
  pid += 1
 
 
 
 
 
 
dashboard_image2image.py CHANGED
@@ -11,14 +11,10 @@ from transformers import CLIPProcessor, FlaxCLIPModel
11
  import utils
12
 
13
  BASELINE_MODEL = "openai/clip-vit-base-patch32"
14
- # MODEL_PATH = "/home/shared/models/clip-rsicd/bs128x8-lr5e-6-adam/ckpt-1"
15
  MODEL_PATH = "flax-community/clip-rsicd-v2"
16
 
17
- # IMAGE_VECTOR_FILE = "/home/shared/data/vectors/test-baseline.tsv"
18
- # IMAGE_VECTOR_FILE = "/home/shared/data/vectors/test-bs128x8-lr5e-6-adam-ckpt-1.tsv"
19
  IMAGE_VECTOR_FILE = "./vectors/test-bs128x8-lr5e-6-adam-ckpt-1.tsv"
20
 
21
- # IMAGES_DIR = "/home/shared/data/rsicd_images"
22
  IMAGES_DIR = "./images"
23
 
24
 
@@ -50,10 +46,7 @@ def download_and_prepare_image(image_url):
50
  image_raw = requests.get(image_url, stream=True,).raw
51
  image = Image.open(image_raw).convert("RGB")
52
  width, height = image.size
53
- # print("width, height:", width, height)
54
  resize_mult = width / 224 if width < height else height / 224
55
- # print("resize_mult:", resize_mult)
56
- # print("resize:", width // resize_mult, height // resize_mult)
57
  image = image.resize((int(width // resize_mult),
58
  int(height // resize_mult)))
59
  width, height = image.size
@@ -61,11 +54,9 @@ def download_and_prepare_image(image_url):
61
  top = int((height - 224) // 2)
62
  right = int((width + 224) // 2)
63
  bottom = int((height + 224) // 2)
64
- # print("LTRB:", left, top, right, bottom)
65
  image = image.crop((left, top, right, bottom))
66
  return image
67
  except Exception as e:
68
- # print(e)
69
  return None
70
 
71
  def app():
@@ -137,7 +128,7 @@ def app():
137
 
138
  image_url = st.text_input(
139
  "OR provide an image URL",
140
- value="https://media.wired.com/photos/5a8c80647b7bd44d86b88077/master/w_2240,c_limit/Satellite-FINAL.jpg")
141
 
142
  submit_button = st.button("Find Similar")
143
 
 
11
  import utils
12
 
13
  BASELINE_MODEL = "openai/clip-vit-base-patch32"
 
14
  MODEL_PATH = "flax-community/clip-rsicd-v2"
15
 
 
 
16
  IMAGE_VECTOR_FILE = "./vectors/test-bs128x8-lr5e-6-adam-ckpt-1.tsv"
17
 
 
18
  IMAGES_DIR = "./images"
19
 
20
 
 
46
  image_raw = requests.get(image_url, stream=True,).raw
47
  image = Image.open(image_raw).convert("RGB")
48
  width, height = image.size
 
49
  resize_mult = width / 224 if width < height else height / 224
 
 
50
  image = image.resize((int(width // resize_mult),
51
  int(height // resize_mult)))
52
  width, height = image.size
 
54
  top = int((height - 224) // 2)
55
  right = int((width + 224) // 2)
56
  bottom = int((height + 224) // 2)
 
57
  image = image.crop((left, top, right, bottom))
58
  return image
59
  except Exception as e:
 
60
  return None
61
 
62
  def app():
 
128
 
129
  image_url = st.text_input(
130
  "OR provide an image URL",
131
+ value="https://static.eos.com/wp-content/uploads/2019/04/Main.jpg")
132
 
133
  submit_button = st.button("Find Similar")
134