Skip to content

Add configurable VLM image preprocessing strategy#108

Merged
stikves merged 4 commits into
apple:mainfrom
stikves:feature/vlm-image-preprocessing
Jul 17, 2026
Merged

Add configurable VLM image preprocessing strategy#108
stikves merged 4 commits into
apple:mainfrom
stikves:feature/vlm-image-preprocessing

Conversation

@stikves

@stikves stikves commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Support three image preprocessing strategies for VLM vision encoders:

  • stretch: resize directly to target (default, backward compatible)
  • center_crop: shortest-edge resize then center crop (for CLIP-based models)
  • pad: longest-edge resize with zero-padding (preserves geometry)

The strategy is declared in metadata.json and inferred from the model at export time. Runtime CLI overrides via --image-strategy.

Also adds --image-info flag to optionally inject original image dimensions into the text prompt (useful for models trained with resolution awareness).

Closes #100.

stikves added 2 commits July 16, 2026 11:16
Support three image preprocessing strategies for VLM vision encoders:
- stretch: resize directly to target (default, backward compatible)
- center_crop: shortest-edge resize then center crop (for CLIP-based models)
- pad: longest-edge resize with zero-padding (preserves geometry)

The strategy is declared in metadata.json and inferred from the model at
export time. Runtime CLI overrides via --image-strategy.

Also adds --image-info flag to optionally inject original image dimensions
into the text prompt (useful for models trained with resolution awareness).

Closes apple#100.
@stikves
stikves marked this pull request as ready for review July 16, 2026 18:44
@stikves stikves self-assigned this Jul 16, 2026
Comment thread swift/Sources/CoreAILanguageModels/Bundle/LanguageConfig.swift Outdated
Comment thread swift/Tests/CoreAISharedTests/ImagePreprocessorTests.swift
@stikves
stikves merged commit 2607aea into apple:main Jul 17, 2026
3 checks passed
@stikves
stikves deleted the feature/vlm-image-preprocessing branch July 17, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Add configurable VLM image preprocessing strategy (stretch / center_crop)

2 participants