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