简体   繁体   中英

Why my pre-trained mlmodel is so wrong in object recognition?

recently I wanted to check out CoreML and CreateML so I created simple app with object recognition.

I created model only for bananas and carrots (just for a try).I used over 60 images to trained my model and in Create ML app the training process looked fine.

Everything was going great until I printed out the results in the console and I saw that my model is 100% confident that waterfall is a banana...

Ideally, I thought the output would be 0% confidence for banana and 0% confidence for carrots (because I used image of waterfall).

Could You explain me why the output look like this and give any kind of advice how to improve my app?

This is my code for image recognition:

func recognizeObject (image: CIImage) {

    guard let myModel = try? VNCoreMLModel(for: FruitVegeClassifier_1().model) else {
        fatalError("Couldn't load ML Model")
    }

    let recognizeRequest = VNCoreMLRequest(model: myModel) { (recognizeRequest, error) in
        guard let output = recognizeRequest.results as? [VNClassificationObservation] else {
            fatalError("Your model failed !")
        }
        print(output)
    }

    let handler = VNImageRequestHandler(ciImage: image)

    do {
    try handler.perform([recognizeRequest])
    } catch {
        print(error)
    }

}

in the console we can see that:

[<VNClassificationObservation: 0x600001c77810> 24503983-5770-4F43-8078-F3F6243F47B2 requestRevision=1 confidence=1.000000 "banana", <VNClassificationObservation: 0x600001c77840> E73BFBAE-D6E1-4D31-A2AE-0B3C860EAF99 requestRevision=1 confidence=0.000000 "carrot"]

and the image looks like this:

瀑布图像

Thanks for any help !

If you only trained on images of bananas and carrots, the model should only be used on images of bananas and carrots.

When you give it a totally different kind of images, it will try to match it to the patterns it has learned, which are either bananas or carrots and nothing else.

In other words, these models do not work they way you were expecting them to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM