ios - TensorflowLite iOS Swift
问题描述
我需要在 iOS 中运行一个 tensorflow lite 模型,它从输入接收一个数组 (1, 4500, 1),但我不明白如何在不将其转换为数据的情况下将其发送到输入。如果我将它打印到解释器并且输入准确地告诉我我需要什么,但是当我运行代码时它会打印出 nil 输出。我在互联网指南中找到了这个:
let resultArray = (
boundingBox: [Float](unsafeData: outputBoundingBox.data) ??
)
但是 Float unsafedata 函数告诉我它不存在。这是我的代码:
import UIKit
import TensorFlowLite
import SwiftyJSON
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
var opt1 = Interpreter.Options()
opt1.threadCount = 2
let model_path = Bundle.main.path(forResource: "model1", ofType: "tflite")
let int1 = try? Interpreter(modelPath: model_path!, options: opt1)
try? int1?.allocateTensors()
let input = try? int1?.input(at: 0).shape
if let filepath = Bundle.main.path(forResource: "numpytest", ofType: "txt") {
do {
let contents = try String(contentsOfFile: filepath)
let data2 = Data(filepath.utf8)
try? int1!.copy(data2, toInputAt: 0)
try? int1?.invoke()
let salida = try? int1?.output(at: 0)
} catch {
// contents could not be loaded
}
} else {
// example.txt not found!
}
}
}
我做错了什么,我需要添加什么?
有没有人有任何意见或建议?
问候!
解决方案
推荐阅读
- java - Bean 名称“bookDto”的 BindingResult 和普通目标对象都不能用作请求属性
- reactjs - 如何在 redux observable 史诗中为 ajax 响应发出两个动作
- c# - C# Form Application Process.Start() Gives Access is denied 错误
- kubernetes-helm - 水平 Pod 自动缩放配置重置
- javascript - 如何解决 React 中的意外令牌 (<) 错误?
- json - 使用 pyspark 将平面数据帧写入数据块中的 json 时维护列顺序
- python-3.x - 将数据插入数据库的简单 Flask 应用程序在本地工作,但在部署时无法工作
- javascript - 将一个组件嵌套到另一个组件中有什么用
- ansible - Ansible 从列表中删除项目
- windows - 在目录中保留 100 个最新文件 - Windows 脚本移植