Skip to content

Fix single image pre-processing #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Libraries/MLXVLM/Models/Idefics3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1042,14 +1042,13 @@ public class SmolVLMProcessor: UserInputProcessor {
/// Tile image if it's larger than the maxProcessingImageSize, so the model gets to see more of it
/// TODO: disable in video mode
func tiles(from originalImage: CIImage) -> (tiles: [CIImage], rows: Int, cols: Int) {
guard originalImage.extent.size.width > CGFloat(maxProcessingImageSize) || originalImage.extent.size.height > CGFloat(maxProcessingImageSize) else {
return ([], 1, 1)
}

var tiles: [CIImage] = []
// The original code resizes to maxProcessingImageSize, then resizes again ensuring multiples of fixedImageSize
// We do both resizes in one go
let processingSize = aspectRatioSize(for: originalImage.extent.size, longestEdge: maxProcessingImageSize, multiple: fixedImageSize)
let image = MediaProcessing.resampleLanczos(originalImage, to: processingSize)

var tiles: [CIImage] = []

// Crop nRows x nCols tiles
let nRows = Int(ceil(image.extent.size.height / CGFloat(fixedImageSize)))
let nCols = Int(ceil(image.extent.size.width / CGFloat(fixedImageSize)))
Expand Down