Skip to content

Commit d6fd31e

Browse files
Make embedding file checks more robust
1 parent 02b9d10 commit d6fd31e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

micro_sam/util.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,15 @@ def precompute_image_embeddings(
514514
("halo", halo if halo is None else list(halo)),
515515
("model_type", predictor.model_type)
516516
]
517-
for key, val in key_vals:
518-
if "input_size" in f.attrs: # we have computed the embeddings already
519-
# key signature does not match or is not in the file
517+
if "input_size" in f.attrs: # we have computed the embeddings already and perform checks
518+
for key, val in key_vals:
519+
if val is None:
520+
continue
521+
# check whether the key signature does not match or is not in the file
520522
if key not in f.attrs or f.attrs[key] != val:
521523
warnings.warn(
522524
f"Embeddings file {save_path} is invalid due to unmatching {key}: "
523-
f"{f.attrs[key]} != {val}.Please recompute embeddings in a new file."
525+
f"{f.attrs.get(key)} != {val}.Please recompute embeddings in a new file."
524526
)
525527
if wrong_file_callback is not None:
526528
save_path = wrong_file_callback(save_path)

0 commit comments

Comments
 (0)