(self, dino_model='dinov2_giant', pretrained_path=r'pretrained_model/facebookdinov2_giant',img_size = 128)
| 8 | import math |
| 9 | class DinoFeatureModule(nn.Module): |
| 10 | def __init__(self, dino_model='dinov2_giant', pretrained_path=r'pretrained_model/facebookdinov2_giant',img_size = 128): |
| 11 | super(DinoFeatureModule, self).__init__() |
| 12 | |
| 13 | self.dino = AutoModel.from_pretrained( |
| 14 | pretrained_path, |
| 15 | local_files_only=False, |
| 16 | torch_dtype=torch.float16 |
| 17 | ) |
| 18 | |
| 19 | |
| 20 | self.dino.eval() |
| 21 | for param in self.dino.parameters(): |
| 22 | param.requires_grad = False |
| 23 | |
| 24 | |
| 25 | frozen = all(not p.requires_grad for p in self.dino.parameters()) |
| 26 | assert frozen, "DINOv2 model parameters are not completely frozen!" |
| 27 | |
| 28 | |
| 29 | self.shallow_dim = 1536 |
| 30 | self.mid_dim = 1536 |
| 31 | self.deep_dim = 1536 |
| 32 | |
| 33 | def get_dino_features(self, x): |
| 34 | with torch.no_grad(): |
nothing calls this directly
no outgoing calls
no test coverage detected