I’m encountering the same error with the code below. Interestingly, my previous version, which used VNCoreMLRequest, is working without issues.
func makePredictions(for photo: CGImage) async throws -> [ImagePrediction] {
guard let imageClassifier = try? MyClassifier(),
let imageModelContainer = try? CoreMLModelContainer(model: imageClassifier.model) else {
return []
}
var request = CoreMLRequest(model: imageModelContainer)
request.cropAndScaleAction = .centerCrop
let results = try await request.perform(on: photo)
guard let observations = results as? [ClassificationObservation] else {
return []
}
let imagePredictions = observations.map { observation in
ImagePrediction(
classification: observation.identifier,
confidence: observation.confidence
)
}
return imagePredictions
}
Topic:
Machine Learning & AI
SubTopic:
Core ML