guidellm.utils.vision
encode_image(image, width=None, height=None, max_size=None, max_width=None, max_height=None, encode_type='base64')
Input image types: - bytes: raw image bytes, decoded with Pillow - str: file path on disk, url, or already base64 encoded image string - pathlib.Path: file path on disk - np.ndarray: image array, decoded with Pillow - PIL.Image.Image: Pillow image - datasets.Image: HuggingFace datasets Image object
max_size: maximum size of the longest edge of the image max_width: maximum width of the image max_height: maximum height of the image
encode_type: None to return the supported format (url for url, base64 string for others) "base64" to return base64 encoded string (or download URL and encode) "url" to return url (only if input is url, otherwise fails)
Returns a str of either: - image url - "data:image/{type};base64, {data}" string
Source code in src/guidellm/utils/vision.py
encode_video(video, encode_type='base64')
Input video types: - bytes: raw video bytes - str: file path on disk, url, or already base64 encoded video string - pathlib.Path: file path on disk - datasets.Video: HuggingFace datasets Video object
encode_type: None to return the supported format (url for url, base64 string for others) "base64" to return base64 encoded string (or download URL and encode) "url" to return url (only if input is url, otherwise fails)
Returns a str of either: - video url - "data:video/{type};base64, {data}" string
Source code in src/guidellm/utils/vision.py
get_file_format(path)
image_dict_to_pil(item)
Decode an encoded image column item to a PIL Image for vLLM multi_modal_data.
The item must have an "image" key with either a data URL (data:image/...;base64,...) or an HTTP(S) URL. For data URLs the image is base64-decoded; for URLs the image is fetched with httpx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item | dict[str, Any] | Dict with "image" key (data URL or URL string) | required |
Returns:
| Type | Description |
|---|---|
Image | PIL Image in RGB if needed |
Raises:
| Type | Description |
|---|---|
ValueError | If item has no "image" or unsupported format |
Source code in src/guidellm/utils/vision.py
synthesize_image(width, height, *, content='gradient', image_format='jpeg', jpeg_quality=85, seed=0, row_index=0)
Synthesize a single image and return the canonical encoded dict.
The output shape matches :func:encode_image so it flows through the rest of the pipeline (column mapper -> finalizer) unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width | int | image width in pixels. | required |
height | int | image height in pixels. | required |
content | str |
| 'gradient' |
image_format | str |
| 'jpeg' |
jpeg_quality | int | JPEG quality 1..100 (ignored for png). | 85 |
seed | int | base seed for reproducibility. | 0 |
row_index | int | row index used to vary the RNG stream per row so successive rows are byte-different even with the same seed. | 0 |
Source code in src/guidellm/utils/vision.py
synthesize_video(width, height, frames, *, fps=1.0, content='gradient', video_format='mp4', video_bitrate=None, seed=0, row_index=0)
Synthesize a short video clip and return the canonical encoded dict.
Matches the shape of :func:encode_video. Only mp4 (h264, yuv420p) is supported in v1. Encoding uses -fflags +bitexact so two runs with the same seed produce byte-identical mp4 payloads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width | int | frame width in pixels (must be > 0). | required |
height | int | frame height in pixels (must be > 0). | required |
frames | int | number of frames in the clip (must be >= 1). | required |
fps | float | frames per second (encoded into the container, drives | 1.0 |
content | str |
| 'gradient' |
video_format | str | only | 'mp4' |
video_bitrate | str | None | optional libx264 bitrate, e.g. | None |
seed | int | base seed for reproducibility. | 0 |
row_index | int | row index used to vary the RNG stream per row. | 0 |
Source code in src/guidellm/utils/vision.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |