Why is Inceptionv3 Machine Learning model not recognized on my project?

Viewed 3138

I am building a basic image recognition app in Swift using the Inception v3 Machine Learning model. I dragged and dropped the Inceptionv3.mlmodel inside my project folder and made sure the "Copy items if needed" option was ticked.

Inside the detect function:

func detect(image: CIImage) {

    guard let model = try? VNCoreMLModel(for: Inceptionv3().model) else {
        fatalError("Loading CoreML Model Failed!")
    }

    let request = VNCoreMLRequest(model: model) { (request, error) in
        guard let results = request.results as? [VNClassificationObservation] else {
            fatalError("Model failed to process")
    }

        if let firstResult = results.first {
            self.navigationItem.title = firstResult.identifier
        }

}

I get the following message:

Use of unresolved identifier 'Inceptionv3'

Also when I click on the Inceptionv3.mlmodel file on my project browser I get this message:

Interface generation only available with valid target

But I know it should read something like:

Inceptionv3 (Swift generated source)

With a small arrow next to it that allow you to access the class.

Any ideas?

5 Answers

The issue is that you cannot have the line of code existing before you import the model file.

Delete the model file, remove the references when it asks. Now add back the model library file. Go back to the commented line of code and directly under type the same line of code and allow xcode to predict you want use the 'Incepetionv3' model file. The error will now go away.

Xcode doesn’t like cut and paste lines of code when there is a reference to a file but more importantly the file has to exist before the line of code is written.

Related