| 149 | return img |
| 150 | |
| 151 | class QwenVL2ImageTransform: |
| 152 | def __init__( |
| 153 | self, |
| 154 | image_size_h, |
| 155 | image_size_w, |
| 156 | image_stride=14, |
| 157 | max_pixels=14*14*9*1024, |
| 158 | image_mean=OPENAI_CLIP_MEAN, |
| 159 | image_std=OPENAI_CLIP_STD, |
| 160 | ): |
| 161 | self.processor = Qwen2VLImageProcessor.from_pretrained('InternRobotics/G2VLM-2B-MoT') |
| 162 | self.img_h = image_size_h |
| 163 | self.img_w = image_size_w |
| 164 | self.stride = image_stride |
| 165 | |
| 166 | # self.to_tensor_transform = transforms.ToTensor() |
| 167 | # self.normalize_transform = transforms.Normalize(mean=image_mean, std=image_std, inplace=True) |
| 168 | |
| 169 | def __call__(self, img, img_num=1): |
| 170 | # if self.img_h is not None: |
| 171 | target_size = (self.img_h, self.img_w ) |
| 172 | img = [ii.resize(target_size,3) for ii in img] |
| 173 | |
| 174 | out = self.processor(img, return_tensors='pt') |
| 175 | pixel_values = out['pixel_values'] # this is flattened. |
| 176 | image_grid_thw = out['image_grid_thw'] |
| 177 | |
| 178 | return pixel_values, image_grid_thw |
| 179 | |
| 180 | class ImageTransform: |
| 181 | def __init__( |
no outgoing calls
no test coverage detected