Swift:CoreML 中的图像预处理:调整大小和转置

发布于 2025-01-15 16:41:31 字数 323 浏览 4 评论 0原文

我需要在输入模型之前对 UIImage 对象进行预处理。

该模型需要 2 次转换:

  1. 调整大小为 224,224
  2. 转置为 CHW

我搜索并发现有两种方法:

  1. 在 Swift 中进行预处理
  2. 使用 Coremltools 将操作添加到 AI 模型

我只设法找到如何在 Swift 中调整大小,但是有不知道如何进行转置以确保图像具有 CHW 数据格式。

也不知道如何从 UIImage 中查看数据格式(CHW 或 HWC)。

如何转置以及如何查看数据格式?

I need to preprocess the UIImage object before feeding to my model.

The model requires 2 transforms:

  1. resize to 224,224
  2. transpose to CHW

I searched and found there are 2 approaches:

  1. do the preprocessing in Swift
  2. add the operations to the AI model using Coremltools

I only managed to find how to do the resize in Swift, but have no idea how to do transpose to make sure the image has data format in CHW.

Also have no idea how to see the data format(CHW or HWC) from UIImage.

How to transpose and how to view the data format?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事与诗 2025-01-22 16:41:31

设置图像输入类型,不用担心大小和数据格式。有明确的API。

例子:

image_input = ct.ImageType(name="input_image", shape=(224,224))
model = ct.convert(traced_model, inputs=[image_input])

Setup Image input type and don't worry about sizes and data formats. Have clear API.

Example:

image_input = ct.ImageType(name="input_image", shape=(224,224))
model = ct.convert(traced_model, inputs=[image_input])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文