| 6 | from eva2_clip import CustomCLIP |
| 7 | |
| 8 | class Eva2Encoder(nn.Module): |
| 9 | def __init__(self, image_size=224, ckpt_path=''): |
| 10 | super(Eva2Encoder, self).__init__() |
| 11 | self.config = get_model_config('EVA02-CLIP-bigE-14') |
| 12 | self.config['vision_cfg']['image_size'] = image_size |
| 13 | model = CustomCLIP(**self.config) |
| 14 | load_checkpoint(model, ckpt_path) |
| 15 | self.model = model.visual |
| 16 | |
| 17 | def forward(self, **kwargs): |
| 18 | encode = self.model(kwargs['image'], return_all_features=True)[:, 1:, :] |
| 19 | return encode |
| 20 | |
| 21 | model = Eva2Encoder(image_size=224, ckpt_path='EVA02_CLIP_E_psz14_s4B.pt').bfloat16().cuda() |
| 22 | |