问题
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?
回答1:
I had the same problem. I solved by add inceptionv3 in bridging header.
回答2:
make sure that your target membership is checked.
回答3:
Seems some sort of bug. This might help, Remove the file reference and try adding it again.
This worked for me. Cheers
回答4:
Instead of Drag and Drop, Right click the project and click "Add Files To Project". Then add the model files. This worked for me.
回答5:
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.
来源:https://stackoverflow.com/questions/45345873/why-is-inceptionv3-machine-learning-model-not-recognized-on-my-project