| from hest.bench import benchmark |
| import torch |
| from torchvision import transforms |
|
|
| print("loading base") |
| dinov2 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14_reg') |
|
|
| ours = torch.load("checkpoints/teacher_epoch250000.pth") |
| checkpoint = ours["teacher"] |
| checkpoint_new = {} |
|
|
| for key in list(checkpoint.keys()): |
| if "dino" in str(key) or "ibot" in str(key): |
| checkpoint.pop(key, None) |
|
|
| for key, keyb in zip(checkpoint.keys(), dinov2.state_dict().keys()): |
| checkpoint_new[keyb] = checkpoint[key] |
|
|
| checkpoint = checkpoint_new |
|
|
| new_shape = checkpoint["pos_embed"] |
| dinov2.pos_embed = torch.nn.parameter.Parameter(new_shape) |
|
|
| dinov2.load_state_dict(checkpoint) |
|
|
| PATH_TO_CONFIG = "./HEST/bench_config/bench_config.yaml" |
| model = dinov2 |
|
|
| RESIZE_DIM = 224 |
| NORMALIZE_MEAN = [0.485, 0.456, 0.406] |
| NORMALIZE_STD = [0.229, 0.224, 0.225] |
|
|
| model_transforms = transforms.Compose([ |
| |
| |
| |
| |
| transforms.ToTensor(), |
|
|
| |
| transforms.Normalize( |
| mean=NORMALIZE_MEAN, |
| std=NORMALIZE_STD) |
| ]) |
| |
| benchmark( |
| model, |
| model_transforms, |
| torch.float32, |
| config=PATH_TO_CONFIG, |
| ) |