无法加载模型,使用 Xcode 或 `MLModel.compileModel(at:)` 编译模型。 SwiftUI 稳定扩散

问题描述 投票:0回答:0

我正在尝试使用 SwiftUI 应用程序在装有 MacOS Ventura 13.2.1 的 M2 pro mac 上运行 Stable Diffusion 的 CoreML 模型。我已经从 Hugging Face Hub 下载了 Core ML Stable Diffusion Models,该应用程序在我的 mac 上编译并成功运行,没有错误。

**我项目中的 Core ML Stable Diffusion 文件:** Image of the CoreML Stable Diffusion files

我通过克隆那个 repo 下载了那些 coreML

git clone https://huggingface.co/apple/coreml-stable-diffusion-v1-4

(https://i.stack.imgur.com/5li9m.png)

但是,当我点击触发

generateImage
功能的生成按钮时,我得到了错误:

Thread 11: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.CoreML Code=0 "Unable to load model: file:///Users/landon/Library/Developer/Xcode/DerivedData/ArtSenseiPro-abnumyedexjximglshwxziyuddrp/Build/Products/Debug/ArtSenseiPro.app/Contents/Resources/TextEncoder.mlmodelc/. Compile the model with Xcode or `MLModel.compileModel(at:)`. " UserInfo={NSLocalizedDescription=Unable to load model: file:///Users/landon/Library/Developer/Xcode/DerivedData/ArtSenseiPro-abnumyedexjximgls

这是我的全部代码:

import SwiftUI
import Combine
import StableDiffusion

@available(macOS 13.1, *)
@available(iOS 16.2, *)
struct ContentView: View {
    
    @State var prompt: String = "Penguins in business suits debating whether to invest in an ice cream stand on the beach."
    @State var pipeline: StableDiffusionPipeline?
    @State var image: CGImage?
    @State var progress = 0.0
    @State var generating = false
    @State var initializing = true
    
    var body: some View {
        VStack {
            if initializing {
                Text("Initializing...")
            } else {
                if let image = self.image {
                    Image(image, scale: 1.0, label: Text(""))
                }
                if generating {
                    Spacer()
                    ProgressView(value: progress)
                    Text("generating (\(Int(progress*100)) %)")
                } else {
                    Spacer()
                    TextField("Prompt", text: $prompt)
                    Button("Generate") {
                        generateImage()
                    }
                }
            }
        }
        .padding()
        .task {
            guard let resourceURL = Bundle.main.resourceURL else {
                return
            }
            do {
                pipeline = try StableDiffusionPipeline(resourcesAt: resourceURL)
            } catch let error {
                print(error.localizedDescription)
            }
            initializing = false
        }
    }
    
    func generateImage(){
        progress = 0.0
        image = nil
        generating = true
        Task.detached(priority: .high) {
            var images: [CGImage?]?
            do {
                images = try pipeline?.generateImages(prompt: prompt, disableSafety: false, progressHandler: { progress in
                    self.progress = Double(progress.step) / 50
                    if let image = progress.currentImages.first {
                        self.image = image
                    }
                    return true
                })
            } catch let error {
                print(error.localizedDescription)
            }
            if let image = images?.first {
                self.image = image
            }
            generating = false
        }
    }
}

任何帮助将不胜感激。谢谢!

我正在尝试使用 SwiftUI 应用程序在装有 MacOS Ventura 13.2.1 的 M2 pro mac 上运行 Stable Diffusion 的 CoreML 模型。我已经从 Hugging Face Hub 下载了 Core ML Stable Diffusion Models,该应用程序在我的 mac 上编译并成功运行,没有错误。

但是,当我点击触发

generateImage
功能的生成按钮时,我得到了错误:

Thread 11: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.CoreML Code=0 "Unable to load model: file:///Users/landon/Library/Developer/Xcode/DerivedData/ArtSenseiPro-abnumyedexjximglshwxziyuddrp/Build/Products/Debug/ArtSenseiPro.app/Contents/Resources/TextEncoder.mlmodelc/. Compile the model with Xcode or `MLModel.compileModel(at:)`. " UserInfo={NSLocalizedDescription=Unable to load model: file:///Users/landon/Library/Developer/Xcode/DerivedData/ArtSenseiPro-abnumyedexjximgls

重装了很多次模型相关的文件都没有用

xcode swiftui coreml huggingface stable-diffusion
© www.soinside.com 2019 - 2024. All rights reserved.