Daniel Varga commited on
Commit
ae2c23b
·
1 Parent(s): 0eab484

image upload, rough ui but working

Browse files
Files changed (2) hide show
  1. app.py +17 -0
  2. readme.sh +11 -2
app.py CHANGED
@@ -124,6 +124,18 @@ def image_retrieval_from_image(state, selected_locally):
124
  return features_to_gallery(embeddings[selected])
125
 
126
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  def show_folder(state, selected_locally):
128
  if state is None or len(state) == 0:
129
  return [], []
@@ -155,6 +167,10 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
155
  image_query_button = gr.Button("Show similar")
156
  selected = gr.Number(0, show_label=False, visible=False)
157
 
 
 
 
 
158
  gallery = gr.Gallery(label="Images", show_label=False, elem_id="gallery"
159
  ).style(columns=4, container=False)
160
 
@@ -164,6 +180,7 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
164
  text_query_button.click(image_retrieval_from_text, [text], [gallery, state])
165
  image_query_button.click(image_retrieval_from_image, [state, selected], [gallery, state])
166
  show_folder_button.click(show_folder, [state, selected], [gallery, state])
 
167
 
168
  def get_select_index(evt: gr.SelectData, state):
169
  selected_locally = evt.index
 
124
  return features_to_gallery(embeddings[selected])
125
 
126
 
127
+ def query_uploaded_image(uploaded_image):
128
+ image = preprocess(uploaded_image)
129
+ image_batch = torch.tensor(np.stack([image])).to(device)
130
+ with torch.no_grad():
131
+ image_features = model.encode_image(image_batch).float()
132
+ image_features = image_features.cpu().numpy()
133
+ assert len(image_features) == 1
134
+ image_features = image_features[0]
135
+ assert len(image_features) == d
136
+ return features_to_gallery(image_features)
137
+
138
+
139
  def show_folder(state, selected_locally):
140
  if state is None or len(state) == 0:
141
  return [], []
 
167
  image_query_button = gr.Button("Show similar")
168
  selected = gr.Number(0, show_label=False, visible=False)
169
 
170
+ uploaded_image = gr.Image(tool="select", type="pil")
171
+
172
+ query_uploaded_image_button = gr.Button("Show similiar to uploaded")
173
+
174
  gallery = gr.Gallery(label="Images", show_label=False, elem_id="gallery"
175
  ).style(columns=4, container=False)
176
 
 
180
  text_query_button.click(image_retrieval_from_text, [text], [gallery, state])
181
  image_query_button.click(image_retrieval_from_image, [state, selected], [gallery, state])
182
  show_folder_button.click(show_folder, [state, selected], [gallery, state])
183
+ query_uploaded_image_button.click(query_uploaded_image, [uploaded_image], [gallery, state])
184
 
185
  def get_select_index(evt: gr.SelectData, state):
186
  selected_locally = evt.index
readme.sh CHANGED
@@ -26,8 +26,8 @@ python convert.py sample_fbi_s1e1.pkl
26
 
27
  ssh -p 2820 hexagon.renyi.hu
28
  cd ai-shared/daniel/sameenergy
29
- lftp -p 2167 gw.pioneer.hu
30
- # manually provide username, password
31
  cd store/05_Photos
32
  # promising directories:
33
  ls 02_LOCATION\ PHOTOS 05_TO_LOCATION_PHOTOS PhotoLibrary Tünde
@@ -39,6 +39,12 @@ ctrl-d
39
 
40
  # scp'd files to buda
41
  cd /data/daniel/sameenergy/
 
 
 
 
 
 
42
  find 02_LOCATION_PHOTOS -type f > raw_files
43
  cat raw_files | grep -i "jpg\|jpeg$" > jpg_files
44
 
@@ -55,6 +61,9 @@ nohup bash create_embeddings.sh &
55
  bash hashes.sh
56
  # takes jpg_files and outputs md5sums
57
 
 
 
 
58
  python convert.py 02_LOCATION_PHOTOS.pkl
59
  # -> creates float16 02_LOCATION_PHOTOS.f16.pkl
60
  mv md5sums 02_LOCATION_PHOTOS.f16.md5sums
 
26
 
27
  ssh -p 2820 hexagon.renyi.hu
28
  cd ai-shared/daniel/sameenergy
29
+ lftp -p 2167 -u d.varga gw.pioneer.hu
30
+ # manually provide password
31
  cd store/05_Photos
32
  # promising directories:
33
  ls 02_LOCATION\ PHOTOS 05_TO_LOCATION_PHOTOS PhotoLibrary Tünde
 
39
 
40
  # scp'd files to buda
41
  cd /data/daniel/sameenergy/
42
+
43
+ # how many bytes, as a check?
44
+ find 02_LOCATION_PHOTOS -type f -exec stat --format="%s" {} \; | awk '{total += $1} END {print total}'
45
+ # -> 141,133,402,112 that's 141GB. in 197108 files, not including directories.
46
+ # on the Pioneer server this was 141,131,778,304 bytes in 196916 files, 6446 directories, good enough.
47
+
48
  find 02_LOCATION_PHOTOS -type f > raw_files
49
  cat raw_files | grep -i "jpg\|jpeg$" > jpg_files
50
 
 
61
  bash hashes.sh
62
  # takes jpg_files and outputs md5sums
63
 
64
+ # ad hoc sample from duplicates:
65
+ cat md5sums | awk 'BEGIN{FS=" "} { if ($1 in m) { print $1 "\t" $2 "\t" m[$1] } ; m[$1] = $2 }' | awk '(NR%4000==0)' | cut -f2-
66
+
67
  python convert.py 02_LOCATION_PHOTOS.pkl
68
  # -> creates float16 02_LOCATION_PHOTOS.f16.pkl
69
  mv md5sums 02_LOCATION_PHOTOS.f16.md5sums