MCPcopy
hub / github.com/XPixelGroup/DiffBIR / process_images

Function process_images

llava/mm_utils.py:166–182  ·  view source on GitHub ↗
(images, image_processor, model_cfg)

Source from the content-addressed store, hash-verified

164
165
166def 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
185def tokenizer_image_token(prompt, tokenizer, image_token_index=IMAGE_TOKEN_INDEX, return_tensors=None):

Callers 8

generate_streamMethod · 0.90
mainFunction · 0.90
__getitem__Method · 0.90
eval_modelFunction · 0.90
eval_modelFunction · 0.90
eval_modelFunction · 0.90
eval_modelFunction · 0.90
__call__Method · 0.90

Calls 2

expand2squareFunction · 0.85
process_anyres_imageFunction · 0.85

Tested by

no test coverage detected