Utilities¶
siglip2_toolkit.utils ¶
Shared, dependency-light helpers: filesystem scanning, image loading, metadata (EXIF) extraction, thumbnails and incremental-run planning.
setup_logging ¶
Configure root logging with a compact, consistent format.
register_heif_support ¶
Register the Pillow HEIF opener once, supporting HEIC/HEIF images.
find_image_files ¶
Recursively yield the image files found in the given directories.
Non-existent or non-directory inputs are skipped with a warning. Yields absolute paths.
resolve_torch_device ¶
Resolve (device, dtype) from a device choice string.
"auto" prefers CUDA, then MPS, then CPU. Half precision is selected
automatically on accelerated devices unless dtype_choice overrides it.
load_image ¶
Load an image from a path, bytes, a file-like object or a PIL image.
Returns an RGB PIL.Image.Image. Raises ValueError/OSError for
unreadable input.
create_thumbnail ¶
Save a WEBP thumbnail next to the configured thumbnail directory.
Returns the absolute thumbnail path, or None when creation fails.
extract_metadata ¶
extract_metadata(
image_path,
*,
create_thumbnails=False,
thumbnail_dir="thumbnails",
thumbnail_size=(128, 128),
)
Extract filesystem/EXIF metadata (and optionally a thumbnail) for an image.
Returns None when the image cannot be read. The metadata schema is
stable and part of the index format: path, filename, size_bytes,
creation_time, modification_time, width, height, exif
and (optionally) thumbnail_path.
filter_files_for_update ¶
Plan an incremental run.
Files to process are the files on disk that are either new (not in the export) or whose modification time differs from the recorded one by more than one second. Records without metadata (metadata was not exported) cannot be compared, so only new files are detected for them. Missing or unparseable timestamps cause reprocessing.