我有一个使用机器学习来分类对象是什么的应用程序。 我的问题是文本分类器不起作用。请忽略代码的结构
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,queue:DispatchQueue(label:“videoQueue”)) imageSession.addOutput(dataOuput)
答案 0 :(得分:0)
我修好了。这是解决方案。
让dataOuput = AVCaptureVideoDataOutput()dataOuput.setSampleBufferDelegate(self,queue:DispatchQueue(label:" videoQueue")) imageSession.addOutput(dataOuput)