(images, image_processor, model_cfg)
| 164 | |
| 165 | |
| 166 | def process_images(images, image_processor, model_cfg): |
| 167 | image_aspect_ratio = getattr(model_cfg, "image_aspect_ratio", None) |
| 168 | new_images = [] |
| 169 | if image_aspect_ratio == 'pad': |
| 170 | for image in images: |
| 171 | image = expand2square(image, tuple(int(x*255) for x in image_processor.image_mean)) |
| 172 | image = image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0] |
| 173 | new_images.append(image) |
| 174 | elif image_aspect_ratio == "anyres": |
| 175 | for image in images: |
| 176 | image = process_anyres_image(image, image_processor, model_cfg.image_grid_pinpoints) |
| 177 | new_images.append(image) |
| 178 | else: |
| 179 | return image_processor(images, return_tensors='pt')['pixel_values'] |
| 180 | if all(x.shape == new_images[0].shape for x in new_images): |
| 181 | new_images = torch.stack(new_images, dim=0) |
| 182 | return new_images |
| 183 | |
| 184 | |
| 185 | def tokenizer_image_token(prompt, tokenizer, image_token_index=IMAGE_TOKEN_INDEX, return_tensors=None): |
no test coverage detected