Skip to content

vllm.assets.image

ImageAssetName module-attribute

ImageAssetName = Literal[
    "stop_sign",
    "cherry_blossom",
    "hato",
    "2560px-Gfp-wisconsin-madison-the-nature-boardwalk",
    "Grayscale_8bits_palette_sample_image",
    "1280px-Venn_diagram_rgb",
    "RGBA_comp",
    "237-400x300",
    "231-200x300",
    "27-500x500",
    "17-150x600",
    "handelsblatt-preview",
    "paper-11",
]

VLM_IMAGES_DIR module-attribute

VLM_IMAGES_DIR = 'vision_model_images'

ImageAsset dataclass

Source code in vllm/assets/image.py
@dataclass(frozen=True)
class ImageAsset:
    name: ImageAssetName

    def get_path(self, ext: str) -> Path:
        """
        Return s3 path for given image.
        """
        return get_vllm_public_assets(filename=f"{self.name}.{ext}",
                                      s3_prefix=VLM_IMAGES_DIR)

    @property
    def pil_image(self, ext="jpg") -> Image.Image:

        image_path = self.get_path(ext)
        return Image.open(image_path)

    @property
    def image_embeds(self) -> torch.Tensor:
        """
        Image embeddings, only used for testing purposes with llava 1.5.
        """
        image_path = self.get_path('pt')
        return torch.load(image_path, map_location="cpu", weights_only=True)

    def read_bytes(self, ext: str) -> bytes:
        p = Path(self.get_path(ext))
        return p.read_bytes()

image_embeds property

image_embeds: Tensor

Image embeddings, only used for testing purposes with llava 1.5.

name instance-attribute

pil_image property

pil_image: Image

__init__

__init__(name: ImageAssetName) -> None

get_path

get_path(ext: str) -> Path

Return s3 path for given image.

Source code in vllm/assets/image.py
def get_path(self, ext: str) -> Path:
    """
    Return s3 path for given image.
    """
    return get_vllm_public_assets(filename=f"{self.name}.{ext}",
                                  s3_prefix=VLM_IMAGES_DIR)

read_bytes

read_bytes(ext: str) -> bytes
Source code in vllm/assets/image.py
def read_bytes(self, ext: str) -> bytes:
    p = Path(self.get_path(ext))
    return p.read_bytes()