is said to learn from experience E with respect to some task T and some performance measure P, if its performance on T, as measured by P, improves with experience E.”
let handler = VNImageRequestHandler(ciImage: image) let request = try makeRequest() // Run the Core ML classifier DispatchQueue.global(qos: .userInteractive).async { do { try handler.perform([request]) } catch { print(error) } } }
ML model through its generated class let model = try VNCoreMLModel(for: SqueezeNet().model) // Create a Vision request with completion handler return VNCoreMLRequest(model: model) { [weak self] request, error in guard let strongSelf = self else { return } // Print result print(strongSelf.makeResult(from: request)) } }
`results` to `VNClassificationObservation` guard let results = request.results as? [VNClassificationObservation] else { return " ¯\\_(ツ)_/¯ " } // Return the top two classifications return Array(results.prefix(2)) // With a confidence score more than 70% .filter({ $0.confidence > 0.7 }) // Make an array of strings with object’s label and confidence in percents .map({ "\($0.identifier): \(Int($0.confidence * 100))%" }) // Join the array to a single, newline-separated string .joined(separator: "\n") } }
let features = makeFeatures(from: name) let output = try model.prediction(input: features) let prob = output.classProbability[output.classLabel] print("\(output.classLabel): \(probability)") }