【问题标题】:Swift: Process UIImage data for use in Firebase custom TFLite modelSwift:处理 UIImage 数据以用于 Firebase 自定义 TFLite 模型
【发布时间】:2018-06-16 22:35:12
【问题描述】:

我正在使用 Swift、Firebase 和 Tensorflow 构建图像识别模型。我有一个重新训练过的 MobileNet 模型,该模型将 [1,224,224,3] 的输入数组复制到我的 Xcode 包中,当我尝试从图像中添加数据作为输入时,我收到错误:Input 0 should have 602112 bytes, but found 627941 bytes. 我正在使用以下代码:

    let input = ModelInputs()
    do {
        let newImage = image.resizeTo(size: CGSize(width: 224, height: 224))

        let data = UIImagePNGRepresentation(newImage)

        // Store input data in `data`

        // ...
        try input.addInput(data)
        // Repeat as necessary for each input index
    } catch let error as NSError {
        print("Failed to add input: \(error.localizedDescription)")
    }



    interpreter.run(inputs: input, options: ioOptions) { outputs, error in
        guard error == nil, let outputs = outputs else {
            print(error!.localizedDescription)//ERROR BEING CALLED HERE
            return }
        // Process outputs
        print(outputs)
        // ...
    }

如何将图像数据重新处理为 602112 字节?如果有人可以帮助我,我会很困惑,那就太好了:)

【问题讨论】:

  • 您在使用 Firebase ML 套件吗?
  • @PannagSanketi 是的,我是。我在任何地方都找不到用于格式化输入数据以匹配 Swift 中的 MobileNet 规范的指南。只有 Obj-C
  • 嘿@Ellek,链接由于某种原因被破坏了。你设法让它工作了吗?

标签: ios arrays firebase tensorflow tensorflow-lite


【解决方案1】:

请查看 Swift 中的 Quick Start iOS 演示应用,了解如何使用自定义 TFLite 模型:

https://github.com/firebase/quickstart-ios/tree/master/mlmodelinterpreter

特别是,我认为这是您正在寻找的:

https://github.com/firebase/quickstart-ios/blob/master/mlmodelinterpreter/MLModelInterpreterExample/UIImage%2BTFLite.swift#L47

祝你好运!

【讨论】:

猜你喜欢
  • 2022-06-30
  • 1970-01-01
  • 1970-01-01
  • 2021-11-16
  • 1970-01-01
  • 2021-04-25
  • 2023-03-26
  • 1970-01-01
  • 2017-02-27
相关资源
最近更新 更多