MCPcopy Index your code
hub / github.com/ModelTC/LightLLM / encode

Method encode

lightllm/models/llava/llava_visual.py:127–153  ·  view source on GitHub ↗
(self, images: List[ImageItem])

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

forwardMethod · 0.95
read_shmFunction · 0.90
get_shm_name_dataFunction · 0.90
preprocessMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected