mirror of
https://github.com/Vision-CAIR/MiniGPT-4.git
synced 2025-04-09 12:30:45 +00:00
16 lines
491 B
Python
16 lines
491 B
Python
|
import torch
|
||
|
from PIL import Image
|
||
|
|
||
|
|
||
|
def load_image(image, image_processor):
|
||
|
if isinstance(image, str): # is a image path
|
||
|
raw_image = Image.open(image).convert('RGB')
|
||
|
image = image_processor(raw_image).unsqueeze(0)
|
||
|
elif isinstance(image, Image.Image):
|
||
|
raw_image = image
|
||
|
image = image_processor(raw_image).unsqueeze(0)
|
||
|
elif isinstance(image, torch.Tensor):
|
||
|
if len(image.shape) == 3:
|
||
|
image = image.unsqueeze(0)
|
||
|
return image
|