MCPcopy Create free account
hub / github.com/apple/ml-4m / decode_tok_imagebind

Function decode_tok_imagebind

fourm/utils/plotting_utils.py:308–325  ·  view source on GitHub ↗

Decodes a sequence of ImageBind spatial tokens from a model dictionary into an PCA representation. Args: mod_dict (dict): Model output dictionary. key (str): Key of the tokenized CLIP modality to decode. tokenizers (dict): Dictionary of tokenizers. image_siz

(mod_dict, tokenizers, key='tok_imagebind', image_size=224, patch_size=14)

Source from the content-addressed store, hash-verified

306 return pca_viz
307
308def decode_tok_imagebind(mod_dict, tokenizers, key='tok_imagebind', image_size=224, patch_size=14):
309 """
310 Decodes a sequence of ImageBind spatial tokens from a model dictionary into an PCA representation.
311
312 Args:
313 mod_dict (dict): Model output dictionary.
314 key (str): Key of the tokenized CLIP modality to decode.
315 tokenizers (dict): Dictionary of tokenizers.
316 image_size (int): Size of the image.
317 patch_size (int): Size of the patches.
318 """
319 patch_size = 14
320 n_patches = image_size // patch_size
321 img_tok = rearrange(mod_dict[key]['tensor'], "b (nh nw) -> b nh nw", nh=n_patches, nw=n_patches)
322 rec = tokenizers[get_transform_key(key)].decode_tokens(img_tok)
323 pca_viz = [pca_visualize(feat) for feat in rec]
324 pca_viz = np_squeeze(np.stack(pca_viz), axis=0)
325 return pca_viz
326
327def decode_tok_dinov2_global(mod_dict, tokenizers, key='tok_dinov2_global'):
328 """

Callers 1

decode_dictFunction · 0.85

Calls 4

get_transform_keyFunction · 0.90
pca_visualizeFunction · 0.85
np_squeezeFunction · 0.85
decode_tokensMethod · 0.45

Tested by

no test coverage detected