Hello
I'm trying to detect objects with CreateML, but it gives me this warning that I think is breaking my app:
'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately.
The classfier.model is a CreatML model that has some images
Have any ideas on how to fix it?
Thank you for your time
I'm trying to detect objects with CreateML, but it gives me this warning that I think is breaking my app:
'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately.
The classfier.model is a CreatML model that has some images
Have any ideas on how to fix it?
Code Block import UIKit import AVKit import Vision import CoreML class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate { let identifierLabel: UILabel = { let label = UILabel() label.backgroundColor = .white label.textAlignment = .center label.translatesAutoresizingMaskIntoConstraints = false return label }() override func viewDidLoad() { super.viewDidLoad() // here is where we start up the camera // for more details visit: https://www.letsbuildthatapp.com/course_video?id=1252 let captureSession = AVCaptureSession() captureSession.sessionPreset = .photo guard let captureDevice = AVCaptureDevice.default(for: .video) else { return } guard let input = try? AVCaptureDeviceInput(device: captureDevice) else { return } captureSession.addInput(input) captureSession.startRunning() let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) view.layer.addSublayer(previewLayer) previewLayer.frame = view.frame let dataOutput = AVCaptureVideoDataOutput() dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue")) captureSession.addOutput(dataOutput) setupIdentifierConfidenceLabel() } fileprivate func setupIdentifierConfidenceLabel() { view.addSubview(identifierLabel) identifierLabel.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -32).isActive = true identifierLabel.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true identifierLabel.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true identifierLabel.heightAnchor.constraint(equalToConstant: 50).isActive = true } func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { // print("Camera was able to capture a frame:", Date()) guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } // !!!Important // make sure to go download the models at https://developer.apple.com/machine-learning/ scroll to the bottom guard let model = try? VNCoreMLModel(for: Classfier().model) else { return } let request = VNCoreMLRequest(model: model) { (finishedReq, err) in //perhaps check the err // print(finishedReq.results) guard let results = finishedReq.results as? [VNClassificationObservation] else { return } guard let firstObservation = results.first else { return } print(firstObservation.identifier, firstObservation.confidence) DispatchQueue.main.async { self.identifierLabel.text = "\(firstObservation.identifier) \(firstObservation.confidence * 100)" } } try? VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: [:]).perform([request]) } }
Thank you for your time
There was a problem and could not finish editing my post…
Which line do you get the error ?
What is the class you try to init ? I called it THEMODEL
You should try this
See details here: http ://www.hackingwithswift. om/forums/swiftui/betterrest-init-deprecated/2593
Which line do you get the error ?
What is the class you try to init ? I called it THEMODEL
You should try this
Code Block let model: THEMODEL = { do { let config = MLModelConfiguration() return try THEMODEL(configuration: config) } catch { print(error) fatalError("Couldn't create SleepCalculator") } }()
See details here: http ://www.hackingwithswift. om/forums/swiftui/betterrest-init-deprecated/2593