(patch_info)
| 248 | |
| 249 | |
| 250 | def read_image_patch(patch_info): |
| 251 | if 'img_path' in patch_info.keys(): |
| 252 | image = Image.open(patch_info['img_path']).convert('RGB') |
| 253 | else: |
| 254 | if 'image_encoing' in patch_info.keys(): |
| 255 | patch_info['image_encoding'] = patch_info['image_encoing'] |
| 256 | image_file_name = patch_info['patch'] |
| 257 | start_bytes = int(patch_info['start_num']) |
| 258 | file_size = int(patch_info['size']) |
| 259 | |
| 260 | with open(image_file_name, 'rb') as f: |
| 261 | f.seek(start_bytes) |
| 262 | if 'image_encoding' in patch_info.keys() and patch_info['image_encoding'] == 'base64': |
| 263 | image = Image.open(io.BytesIO(base64.b64decode(f.read(file_size).decode()))).convert("RGB") |
| 264 | else: |
| 265 | image = Image.open(io.BytesIO(f.read(file_size))).convert("RGB") |
| 266 | return image |
| 267 | |
| 268 | def tokenizer_image_token(prompt, tokenizer, image_token_index=IMAGE_TOKEN_INDEX, return_tensors=None): |
| 269 | prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split('<image>')] |
nothing calls this directly
no outgoing calls
no test coverage detected