MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / clip_checkpoint_preprocess

Function clip_checkpoint_preprocess

PATH/core/models/backbones/vitdet.py:645–665  ·  view source on GitHub ↗
(checkpoint)

Source from the content-addressed store, hash-verified

643
644
645def clip_checkpoint_preprocess(checkpoint):
646 for k in list(checkpoint.keys()):
647 if k.startswith('visual'):
648 if k in ["visual.proj", "visual.class_embedding"]:
649 new_k = k
650 elif k.startswith('visual.transformer.resblocks'):
651 new_k = k[len("visual.transformer.res"):]
652 new_k = new_k.replace('in_proj_weight', 'qkv.weight')
653 new_k = new_k.replace('in_proj_bias', 'qkv.bias')
654 new_k = new_k.replace('out_proj', 'proj')
655 new_k = new_k.replace('ln_', 'norm')
656 new_k = new_k.replace('c_fc', 'fc1')
657 new_k = new_k.replace('c_proj', 'fc2')
658 else:
659 new_k = k[len("visual."):]
660 new_k = new_k.replace('positional_embedding', 'pos_embed')
661 new_k = new_k.replace('conv1', 'patch_embed.proj')
662 new_k = new_k.replace('ln_post', 'norm')
663 checkpoint[new_k] = checkpoint[k]
664 del checkpoint[k]
665 return checkpoint
666
667
668def load_checkpoint(model, state_dict, load_pos_embed, strict=False, pos_embed_interp=True, logger=None):

Callers 2

vit_base_patch16Function · 0.70
vit_large_patch16Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected