Hi,
down there you will find an implementation of the coreML/squeeze net that prints first prediction and confidence level.
Problem is that its prediction are not general enough: if I send it a dog, it will try to guess the dog breed, instead of general categorization of "Dog" or even "Animal".
Is there anyway to ask the model to return broader category?
down there you will find an implementation of the coreML/squeeze net that prints first prediction and confidence level.
Problem is that its prediction are not general enough: if I send it a dog, it will try to guess the dog breed, instead of general categorization of "Dog" or even "Animal".
Is there anyway to ask the model to return broader category?
Code Block static func analyzeImageMl(image: UIImage) { if let imageToParse = image.cgImage { do { let model = try SqueezeNet(configuration: MLModelConfiguration()) let mlModel = model.model do { let visionModel = try VNCoreMLModel(for: mlModel) let request = VNCoreMLRequest(model: visionModel) { (response, error) in if let e = error { print("Error is: \(e.localizedDescription)") } if let r = response.results as? [VNClassificationObservation] { if let f = r.first { let id = f.identifier let confidenceToPercent = f.confidence * 100 let confidenceString = String(format: "%.2f", confidenceToPercent) print("I think this object is: \(id)\n with a confidence of: \(confidenceString)%") } } } let handler = VNImageRequestHandler(cgImage: imageToParse, options: [:]) try handler.perform([request]) } catch { print(error.localizedDescription) } } catch { print(error.localizedDescription) } } }