(pretrained=False, load_pos_embed=True, pretrain_path=None, pos_embed_interp=False, **kwargs)
| 558 | |
| 559 | |
| 560 | def vit_base_patch16(pretrained=False, load_pos_embed=True, pretrain_path=None, pos_embed_interp=False, **kwargs): |
| 561 | default = dict( |
| 562 | drop_path_rate=0.1, use_abs_pos_emb=True, # as in table 11 |
| 563 | #### |
| 564 | patch_size=16, embed_dim=768, depth=12, num_heads=12, mlp_ratio=4, qkv_bias=True, |
| 565 | norm_layer=partial(nn.LayerNorm, eps=1e-6) |
| 566 | ) |
| 567 | recursive_update(default, kwargs) |
| 568 | model = ViT(**default) |
| 569 | # del model.head |
| 570 | |
| 571 | if pretrained: |
| 572 | script_dir = os.path.dirname(__file__) |
| 573 | if pretrain_path: |
| 574 | checkpoint = torch.load(pretrain_path)['model'] |
| 575 | print("load pretrain from {}".format(pretrain_path)) |
| 576 | elif pretrained == 'supervised-80ecf9dd': |
| 577 | rel_path = "pretrain_weights/jx_vit_base_p16_224-80ecf9dd.pth" |
| 578 | checkpoint = torch.load(os.path.join(script_dir, rel_path)) |
| 579 | elif pretrained == 'clip': |
| 580 | rel_path = "pretrain_weights/CLIP-ViT-B-16.pt" |
| 581 | checkpoint = torch.load(os.path.join(script_dir, rel_path)) |
| 582 | # rename & clean loaded keys |
| 583 | checkpoint = clip_checkpoint_preprocess(checkpoint) |
| 584 | else: |
| 585 | rel_path = "pretrain_weights/mae_pretrain_vit_base.pth" |
| 586 | checkpoint = torch.load(os.path.join(script_dir, rel_path))['model'] |
| 587 | |
| 588 | # load while interpolates position embedding |
| 589 | load_checkpoint(model, checkpoint, load_pos_embed, strict=False, pos_embed_interp=pos_embed_interp, logger=dummy_logger) |
| 590 | del checkpoint |
| 591 | |
| 592 | return model |
| 593 | |
| 594 | |
| 595 | def vit_large_patch16(pretrained=False, load_pos_embed=True, pretrain_path=None, pos_embed_interp=False, **kwargs): |
no test coverage detected