我是新手,它尽我所能,努力学习尽可能多的知识,并通过许多论坛进行搜索。但是,这个问题的答案似乎无处不在。因此,我希望有人能够对此提供帮助。
我想返回Model图像可能是的第一个值。它大多数时候返回一个,但不确定时可能提供两个或三个。即使我在request.results ?.方法的第一部分中指定了第一个命令。
我正在使用文本来显示结果self.Output.text =“ Item:(classification!.identifier.capitalized)”
我尝试过使用语法,但首先要包括运气。我尝试将其视为一个数组,但我不相信会有一个数组,因为只有在拍摄图像后才返回数据。
func detect(image: CIImage) {
// Load the ML model through its generated class
guard let model = try? VNCoreMLModel(for: Inceptionv3().model) else {
fatalError("can't load ML model")
}
let request = VNCoreMLRequest(model: model) { (request, error) in
let classification = request.results?.first as? VNClassificationObservation
self.Output.text = "Item: \(classification!.identifier.capitalized)"
}
let handler = VNImageRequestHandler(ciImage: image)
do {
try handler.perform([request])
}
catch {
print(error)
}
}
我正在获得结果,我只需要将其缩小到一个。