最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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("

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论