1
votes

There are many tutorials how to print top detected objects on image with ML, like

let request = VNCoreMLRequest(model: model) { [weak self] request, error in
        guard let results = request.results as? [VNClassificationObservation],
            let topResult = results.first else {
                fatalError("unexpected result type from VNCoreMLRequest")
        }

but is there any way to solve the opposite problem: with a given key-word get the probability of that the object with this key is present on the picture ?

1

1 Answers

0
votes

I don't know of any way to use the CoreML library directly to get the probability of a certain object, but you could use the results array to get any probability you are interested in. Instead of taking results.first, filter for the key you are interested in:

let interestingResults = results.filter { $0.identifier == "key" }
let topResult = interestingResults.first

and then you can get the confidence with topResult.confidence