ios - swift : Process UIImage data for use in Firebase custom TFLite model
<p><p>我正在使用 Swift、Firebase 和 Tensorflow 构建图像识别模型。我有一个重新训练过的 MobileNet 模型,该模型将 的输入数组复制到我的 Xcode 包中,当我尝试从图像中添加数据作为输入时,我收到错误:<code>Input 0 should有 602112 字节,但找到了 627941 字节。</code> 我正在使用以下代码:</p>
<pre><code> 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)
// ...
}
</code></pre>
<p>如何将图像数据重新处理为 602112 字节?如果有人可以帮助我,我会很困惑,那就太好了:)</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>请查看 Swift 中的快速入门 iOS 演示应用,了解如何使用自定义 TFLite 模型:</p>
<p> <a href="https://github.com/firebase/quickstart-ios/tree/master/mlmodelinterpreter" rel="noreferrer noopener nofollow">https://github.com/firebase/quickstart-ios/tree/master/mlmodelinterpreter</a> </p>
<p>特别是,我认为这是您正在寻找的:</p>
<p> <a href="https://github.com/firebase/quickstart-ios/blob/master/mlmodelinterpreter/MLModelInterpreterExample/UIImage%2BTFLite.swift#L47" rel="noreferrer noopener nofollow">https://github.com/firebase/quickstart-ios/blob/master/mlmodelinterpreter/MLModelInterpreterExample/UIImage%2BTFLite.swift#L47</a> </p>
<p>祝你好运!</p></p>
<p style="font-size: 20px;">关于ios -swift: Process UIImage data for use in Firebase custom TFLite model,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/50892298/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/50892298/
</a>
</p>
页:
[1]