(self, dtype, device, checkpoint_path, tokenizer_path)
| 495 | class CLIPModel: |
| 496 | |
| 497 | def __init__(self, dtype, device, checkpoint_path, tokenizer_path): |
| 498 | self.dtype = dtype |
| 499 | self.device = device |
| 500 | self.checkpoint_path = checkpoint_path |
| 501 | self.tokenizer_path = tokenizer_path |
| 502 | |
| 503 | # init model |
| 504 | self.model, self.transforms = clip_xlm_roberta_vit_h_14( |
| 505 | pretrained=False, |
| 506 | return_transforms=True, |
| 507 | return_tokenizer=False, |
| 508 | dtype=dtype, |
| 509 | device=device) |
| 510 | self.model = self.model.eval().requires_grad_(False) |
| 511 | logging.info(f'loading {checkpoint_path}') |
| 512 | self.model.load_state_dict( |
| 513 | torch.load(checkpoint_path, map_location='cpu')) |
| 514 | |
| 515 | # init tokenizer |
| 516 | self.tokenizer = HuggingfaceTokenizer( |
| 517 | name=tokenizer_path, |
| 518 | seq_len=self.model.max_text_len - 2, |
| 519 | clean='whitespace') |
| 520 | |
| 521 | def visual(self, videos): |
| 522 | # preprocess |
nothing calls this directly
no test coverage detected