3

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

4

1 回答 1

2

请查看 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

祝你好运!

于 2018-06-18T19:44:33.747 回答