(self, example: Dict[str, Any], **kwargs)
| 486 | return [[-200], '\n'] |
| 487 | |
| 488 | def _encode(self, example: Dict[str, Any], **kwargs) -> Tuple[Dict[str, Any], Dict[str, Any]]: |
| 489 | inputs, _ = super()._encode(example) |
| 490 | if len(inputs) == 0: |
| 491 | return inputs, {} |
| 492 | inputs.pop('loss_scale', None) |
| 493 | from llava.mm_utils import expand2square |
| 494 | # This processor should be put from the `model.vision_tower.image_processor` |
| 495 | image_processor = self.tokenizer.image_processor |
| 496 | images = example.get('images') or [] |
| 497 | for i, image in enumerate(images): |
| 498 | background_color = tuple(int(x * 255) for x in image_processor.image_mean) |
| 499 | image = expand2square(image, background_color) |
| 500 | images[i] = image |
| 501 | if images: |
| 502 | image_tensor = image_processor.preprocess(images, return_tensors='pt')['pixel_values'] |
| 503 | inputs['images'] = image_tensor.to(kwargs['dtype']) |
| 504 | return inputs, {} |
| 505 | |
| 506 | def data_collator(self, batch: List[Dict[str, Any]], padding_to: Optional[int] = None) -> Dict[str, Any]: |
| 507 | res = super().data_collator(batch, padding_to) |
nothing calls this directly
no test coverage detected