(self, device: Union[str, torch.device], path: str = MODEL_PATHS, condition: str = 'overall')
| 26 | |
| 27 | class MPScore(torch.nn.Module): |
| 28 | def __init__(self, device: Union[str, torch.device], path: str = MODEL_PATHS, condition: str = 'overall'): |
| 29 | super().__init__() |
| 30 | """Initialize the MPSModel with a processor, tokenizer, and model. |
| 31 | |
| 32 | Args: |
| 33 | device (Union[str, torch.device]): The device to load the model on. |
| 34 | """ |
| 35 | self.device = device |
| 36 | processor_name_or_path = path.get("clip") |
| 37 | self.image_processor = CLIPImageProcessor.from_pretrained(processor_name_or_path) |
| 38 | self.tokenizer = AutoTokenizer.from_pretrained(processor_name_or_path, trust_remote_code=True) |
| 39 | self.model = clip_model.CLIPModel(processor_name_or_path, config_file=True) |
| 40 | state_dict = load_file(path.get("mps")) |
| 41 | self.model.load_state_dict(state_dict, strict=False) |
| 42 | self.model.to(device) |
| 43 | self.condition = condition |
| 44 | |
| 45 | def _calculate_score(self, image: torch.Tensor, prompt: str) -> float: |
| 46 | """Calculate the reward score for a single image and prompt. |
nothing calls this directly
no test coverage detected