Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Deepseek ai Janus Load Pil Images

From Leeroopedia
Revision as of 14:45, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Deepseek_ai_Janus_Load_Pil_Images.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Computer_Vision, Preprocessing
Last Updated 2026-02-10 09:30 GMT

Overview

Concrete tool for extracting and loading PIL images from conversation message dictionaries provided by the Janus I/O utilities.

Description

The load_pil_images function iterates over a list of conversation message dicts, extracts any images field entries, and loads them as PIL Image objects. It supports both file paths and base64 data URIs. All images are converted to RGB format.

Usage

Import this function when you have a conversation dict with image references and need to convert them to PIL images for the VLChatProcessor.

Code Reference

Source Location

  • Repository: Janus
  • File: janus/utils/io.py
  • Lines: L44-83

Signature

def load_pil_images(
    conversations: List[Dict[str, str]]
) -> List[PIL.Image.Image]:
    """
    Load PIL images from conversation messages.

    Supports file paths and base64 data URIs.

    Args:
        conversations: List of message dicts with optional "images" key
            containing file paths or "data:image" base64 strings.

    Returns:
        List of RGB PIL.Image.Image objects extracted from all messages.
    """

Import

from janus.utils.io import load_pil_images

I/O Contract

Inputs

Name Type Required Description
conversations List[Dict[str, str]] Yes Conversation message list; messages with "images" key will be processed

Outputs

Name Type Description
pil_images List[PIL.Image.Image] RGB-converted PIL images from all messages, in order

Usage Examples

Load From File Paths

from janus.utils.io import load_pil_images

conversation = [
    {
        "role": "User",
        "content": "<image_placeholder>\nDescribe this image.",
        "images": ["./examples/image.png"],
    },
    {"role": "Assistant", "content": ""},
]

pil_images = load_pil_images(conversation)
# Returns: [<PIL.Image.Image mode='RGB'>]

Load From Base64

import base64

with open("image.png", "rb") as f:
    b64 = base64.b64encode(f.read()).decode()

conversation = [
    {
        "role": "User",
        "content": "<image_placeholder>\nWhat is this?",
        "images": [f"data:image/png;base64,{b64}"],
    },
    {"role": "Assistant", "content": ""},
]

pil_images = load_pil_images(conversation)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment