thomasht86 commited on
Commit
61562fa
·
verified ·
1 Parent(s): 51cbf12

Upload backend/colpali.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. backend/colpali.py +12 -6
backend/colpali.py CHANGED
@@ -299,6 +299,7 @@ def add_sim_maps_to_result(
299
  query_id: str,
300
  result_cache,
301
  ) -> Dict[str, Any]:
 
302
  vit_config = load_vit_config(model)
303
  imgs: List[str] = []
304
  vespa_sim_maps: List[str] = []
@@ -311,6 +312,11 @@ def add_sim_maps_to_result(
311
  vespa_sim_maps.append(vespa_sim_map)
312
  if not imgs:
313
  return result
 
 
 
 
 
314
  sim_map_imgs_generator = gen_similarity_maps(
315
  model=model,
316
  processor=processor,
@@ -327,14 +333,14 @@ def add_sim_maps_to_result(
327
  if (
328
  len(result["root"]["children"]) > img_idx
329
  and "fields" in result["root"]["children"][img_idx]
330
- and "sim_map" in result["root"]["children"][img_idx]["fields"]
331
  ):
332
  result["root"]["children"][img_idx]["fields"][f"sim_map_{token}"] = (
333
  sim_mapb64
334
  )
335
- # Update result_cache with the new sim_map
336
- result_cache.set(query_id, result)
337
- # for single_result, sim_map_dict in zip(result["root"]["children"], sim_map_imgs):
338
- # for token, sim_mapb64 in sim_map_dict.items():
339
- # single_result["fields"][f"sim_map_{token}"] = sim_mapb64
 
340
  return result
 
299
  query_id: str,
300
  result_cache,
301
  ) -> Dict[str, Any]:
302
+ print("Adding similarity maps to result - query_id:", query_id)
303
  vit_config = load_vit_config(model)
304
  imgs: List[str] = []
305
  vespa_sim_maps: List[str] = []
 
312
  vespa_sim_maps.append(vespa_sim_map)
313
  if not imgs:
314
  return result
315
+ if len(imgs) != len(vespa_sim_maps):
316
+ print(
317
+ "Number of images and similarity maps do not match. Skipping similarity map generation."
318
+ )
319
+ return result
320
  sim_map_imgs_generator = gen_similarity_maps(
321
  model=model,
322
  processor=processor,
 
333
  if (
334
  len(result["root"]["children"]) > img_idx
335
  and "fields" in result["root"]["children"][img_idx]
 
336
  ):
337
  result["root"]["children"][img_idx]["fields"][f"sim_map_{token}"] = (
338
  sim_mapb64
339
  )
340
+ # Update result_cache with the new sim_map
341
+ result_cache.set(query_id, result)
342
+ else:
343
+ print(
344
+ f"Could not add sim map to result for image {img_idx} and token {token}"
345
+ )
346
  return result