in FastViTSample/FastViTSample/DataModel.swift [102:116]
func performInference(_ pixelBuffer: CVPixelBuffer) async throws {
guard let model else {
return
}
let inputImage = CIImage(cvPixelBuffer: pixelBuffer).resized(to: targetSize)
context.render(inputImage, to: inputPixelBuffer)
let result = try model.prediction(image: inputPixelBuffer)
let top3 = result.classLabel_probs.sorted { $0.value > $1.value }.prefix(3).map { (label, prob) in
PredictionResult(label: label, probability: prob)
}
Task { @MainActor in
prediction = top3
}
}