Core MLモデル
https://developer.apple.com/jp/machine-learning/models/
@State private var classficationLabel: String = ""
let model = MobileNetV2()
private func performImageClassfication() {
let currentImageName = photos[currentIndex]
guard let img = UIImage(named: currentImageName),
let resizedImage = img.resizeTo(size: CGSize(width: 224, height: 224)),
let buffer = resizedImage.toBuffer() else {
return
}
let output = try? model.prediction(image: buffer)
if let output = output {
self.classficationLabel = output.classLabel
}
}
let results = output.classLabelProbs.sorted { $0.value > $1.value }
let result = results.map { key, value in
return "\(key) = \(value * 100)"
}.joined(separator: "\n")