(self, images: List[ImageItem])
| 125 | return x |
| 126 | |
| 127 | def encode(self, images: List[ImageItem]): |
| 128 | img_tensors = [] |
| 129 | uuids = [] |
| 130 | valid_id = 0 |
| 131 | valid_ids = [] |
| 132 | |
| 133 | for i, img in enumerate(images): |
| 134 | if isinstance(img, ImageItem): |
| 135 | uuids.append(img.uuid) |
| 136 | image_data = read_shm(get_shm_name_data(img.uuid)) |
| 137 | image_data = Image.open(BytesIO(image_data)).convert("RGB") |
| 138 | t = self.image_processor.preprocess(image_data, return_tensors="pt")["pixel_values"] |
| 139 | img_tensors.append(t) |
| 140 | else: |
| 141 | raise Exception("Unsupport input types: {} for {}".format(type(img), img)) |
| 142 | |
| 143 | cur_num = img_tensors[-1].shape[0] |
| 144 | valid_ids.append([valid_id, valid_id + cur_num]) |
| 145 | valid_id += cur_num |
| 146 | |
| 147 | if len(img_tensors) <= 0: |
| 148 | return None |
| 149 | |
| 150 | img = torch.cat(img_tensors, dim=0) |
| 151 | all_img_embeds = self.forward(img) |
| 152 | |
| 153 | return all_img_embeds, uuids, valid_ids |
nothing calls this directly
no test coverage detected