ios - swift : Process UIImage data for use in Firebase custom TFLite model

标签 ios arrays firebase tensorflow tensorflow-lite

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

    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 字节?我很困惑,如果有人可以帮助我,那就太好了:)

最佳答案

请查看 Swift 中的快速入门 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

祝你好运!

关于ios - swift : Process UIImage data for use in Firebase custom TFLite model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50892298/

相关文章:

c - 如何在C中的while循环中存储数组索引的值

javascript - Laravel 5.2 PHP 数组到 Javascript 变量

ios - Firebase iOS 错误使用未声明的类型 'StorageReference'

ios - Swift:关于 presentScene() 的安全实践

IOS & Objective C - 如何用国家列表填充 UIPickerView?

ios - 将 firebase 图像放入数组中

firebase - Dart Firebase Firestore Atomic注册

Python-如何从数组中复制所有数据

iOS 7 模态视图使按钮变灰(禁用)

ios - 在 iOS 上后台运行应用程序