ios - Failed to read model package AND Error: A valid manifest does not exist at path | CoreML Model does not get loaded in Xcod

admin2025-04-17  2

The idea was to create a simple image picker on iOS. Once the image is loaded, the app shall output its analysis with %.

Right now the CoreML model will not be loaded and crashes with:

Vision___CoreML/MainViewController.swift:34: Fatal error: Unable to load model: Failed to read model package at file:///Users/annamusterfrau/Library/Developer/CoreSimulator/Devices/F1D82391-B4B3-434A-8368-AB960F019A26/data/Containers/Bundle/Application/8F270A8E-D28A-48A7-B782-86F407C33115/Vision%20+%20CoreML.app/companyLogos.mlmodelc/. Error: A valid manifest does not exist at path: /Users/annamusterfrau/Library/Developer/CoreSimulator/Devices/F1D82391-B4B3-434A-8368-AB960F019A26/data/Containers/Bundle/Application/8F270A8E-D28A-48A7-B782-86F407C33115/Vision + CoreML.app/companyLogos.mlmodelc/Manifest.json

And this video shows how those errors got triggered:

Could anyone kindly advise me on what went wrong here? I tried the following:

Reference my .mlmodelc under Copy Bundle Resources, Compile Resources. I had removed and re-added the .mlmodelc a couple of times. None of those helped me.

My full code:

import UIKit
import Vision

class MainViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    @IBOutlet var imgGuess: UIImageView!
    @IBOutlet var lblGuess: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
        if let pickedImage = info[.originalImage] as? UIImage {
            lblGuess.text = "Thinking"
            
            imgGuess.contentMode = .scaleAspectFit
            imgGuess.image = pickedImage
            
            // Load the model using the recommended method
            guard let modelURL = Bundle.main.url(forResource: "companyLogos", withExtension: "mlmodelc"),
                  let model = try? VNCoreMLModel(for: MLModel(contentsOf: modelURL, configuration: MLModelConfiguration())) else {
                fatalError("Unable to load model")
            }
            
            let request = VNCoreMLRequest(model: model) { [weak self] request, error in
                if let error = error {
                    print("❌ Error during Vision request: \(error)")
                    return
                }
                
                print("
转载请注明原文地址:http://anycun.com/QandA/1744851293a88509.html