Hello everybody,
I am trying to run inference on a CoreML Model created by me using CreateML. I am following the sample code provided by Apple on the CoreML documentation page and every time I try to classify an image I get this error: "Could not create Espresso context".
Has this ever happened to anyone? How did you solve it?
Here is my code:
Thank you for your help!
I am trying to run inference on a CoreML Model created by me using CreateML. I am following the sample code provided by Apple on the CoreML documentation page and every time I try to classify an image I get this error: "Could not create Espresso context".
Has this ever happened to anyone? How did you solve it?
Here is my code:
Code Block import Foundation import Vision import UIKit import ImageIO final class ButterflyClassification { var classificationResult: Result? lazy var classificationRequest: VNCoreMLRequest = { do { let model = try VNCoreMLModel(for: ButterfliesModel_1(configuration: MLModelConfiguration()).model) return VNCoreMLRequest(model: model, completionHandler: { [weak self] request, error in self?.processClassification(for: request, error: error) }) } catch { fatalError("Failed to lead model.") } }() func processClassification(for request: VNRequest, error: Error?) { DispatchQueue.main.async { guard let results = request.results else { print("Unable to classify image.") return } let classifications = results as! [VNClassificationObservation] if classifications.isEmpty { print("No classification was provided.") return } else { let firstClassification = classifications[0] self.classificationResult = Result(speciesName: firstClassification.identifier, confidence: Double(firstClassification.confidence)) } } } func classifyButterfly(image: UIImage) -> Result? { guard let ciImage = CIImage(image: image) else { fatalError("Unable to create ciImage") } DispatchQueue.global(qos: .userInitiated).async { let handler = VNImageRequestHandler(ciImage: ciImage, options: [:]) do { try handler.perform([self.classificationRequest]) } catch { print("Failed to perform classification.\n\(error.localizedDescription)") } } return classificationResult } }
Thank you for your help!