gpt4 book ai didi

Swift 机器学习观察不起作用

转载 作者:行者123 更新时间:2023-11-30 12:01:09 25 4
gpt4 key购买 nike

我有一个应用程序,它使用机器学习来对对象进行分类。我的问题是文本分类器不起作用。请忽略代码的结构

  let classifierText: UILabel = {
let classifer = UILabel()
classifer.translatesAutoresizingMaskIntoConstraints = false
classifer.textColor = .black
classifer.font = UIFont(name: "Times-New-Roman", size: 10)
classifer.textAlignment = .center
return classifer
}() func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
guard let model = try? VNCoreMLModel(for: Inceptionv3().model) else { return }
let request = VNCoreMLRequest(model: model) { (finishedReq, err) in
guard let results = finishedReq.results as? [VNClassificationObservation] else { return }
guard let firstObservation = results.first else { return }
DispatchQueue.main.async {
self.classifierText.text = "This appears to be a \(firstObservation.identifier)"
}
}
try? VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: [:]).perform([request])
} override func viewDidLoad() {
super.viewDidLoad()
let theView: UIView = {
let view = UIView()
view.backgroundColor = .white
view.translatesAutoresizingMaskIntoConstraints = false
view.frame = view.bounds
view.layer.cornerRadius = 10
view.layer.borderWidth = 1
view.addSubview(classifierText)
return view
}()

我修好了。这是解决方案。

让 dataOuput = AVCaptureVideoDataOutput() dataOuput.setSampleBufferDelegate(self, 队列: DispatchQueue(标签: "videoQueue")) imageSession.addOutput(dataOuput)

最佳答案

我修好了。这是解决方案。

让 dataOuput = AVCaptureVideoDataOutput() dataOuput.setSampleBufferDelegate(self, 队列: DispatchQueue(标签: "videoQueue"))imageSession.addOutput(dataOuput)

关于Swift 机器学习观察不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47206220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com