Add PIL Image support for remote device inference#2647
Open
soof-golan wants to merge 1 commit intoapple:mainfrom
Open
Add PIL Image support for remote device inference#2647soof-golan wants to merge 1 commit intoapple:mainfrom
soof-golan wants to merge 1 commit intoapple:mainfrom
Conversation
Enable passing and receiving PIL.Image.Image objects to remote inference by: - Adding UInt8 dtype support to TensorDescriptor - Creating a CVPixelBuffer as the input based on the model's input metadata - Retrieving the contents of a CVPixelBuffer based on the model's output metadata
cymbalrush
approved these changes
Jan 29, 2026
| return buffer | ||
| } | ||
|
|
||
| fileprivate func extractPixelBufferData(_ pixelBuffer: CVPixelBuffer) throws -> (Data, [Int], [Int]) { |
Collaborator
There was a problem hiding this comment.
nit: Could we please make it a named tuple (data: [Data], shape: [Int], strides: [Int])?
| } else if pixelFormat == kCVPixelFormatType_32BGRA { | ||
| var data = Data(count: height * width * 3) | ||
| data.withUnsafeMutableBytes { dstBuffer in | ||
| let dstPtr = dstBuffer.baseAddress!.assumingMemoryBound(to: UInt8.self) |
Collaborator
There was a problem hiding this comment.
nit: Instead of force unwrapping baseAddress, could we do a guard and throw an error instead?
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR:
Enables passing and receiving PIL.Image.Image objects to remote inference by:
Testing Approach
Manual testing was performed to ensure the code works as intended.
I'm not sure how to integrate this into the main repo in a clean way: