I'm pursuing Machine Learning advance course and here is my question. What I would like to do is that once I open the picture library from the camera to select a photo, I will be able to make it identified by a Machine Learning Model. Does anyone know how to do it?
This is the code to classify the photo:
@State private var isShowPicker: Bool = false
@State private var image: Image? = Image("")
@State private var classificationLabel: String = ""
let model = MobileNetV2()
private func performImageClassification() {
let currentImageName = ImagePicker(image: self.$image)
guard let img = UIImage(named: "\(String(describing: currentImageName))"),
let resizedImage = img.resizeTo(size: CGSize(width: 224, height: 224)),
let pixelBuffer = resizedImage.toCVPixelBuffer() else {
return
}
let output = try? model.prediction(image: pixelBuffer)
if let output = output {
self.classificationLabel = output.classLabel
}
}
I am assuming I will have to call it somewhere in the image Picker Controller function which is this one:
func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let uiImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
image = Image(uiImage: uiImage)
presentationMode.dismiss()
}