[英]Do not compile MLModel in Swift Package Bundle
我想在我的 swift 包中添加一個 .mlmodel 以進行測試以驗證編譯是否正常工作。
targets: [
.target(
name: "packageName",
dependencies: ["package1"]
),
.testTarget(
name: "packageNameTests",
dependencies: ["packageName"],
resources: [
.copy("Resources/testmodel.mlmodel"),
]
)
]
我的問題是 .mlmodel 在捆綁后總是作為編譯模型
let docsPath = Bundle.module.resourcePath!
let docsArray = try fileManager.contentsOfDirectory(atPath: docsPath)
print(docsArray)
導致 ["testmodel.mlmodelc"]
我將 testmodel.mlmodel 改為存在。 我覺得奇怪的是副本正在處理資源。 有解決方法嗎? 我正在使用 Xcode 14 beta,但 StackOverflow 上有一個類似的帖子,但沒有回答關於這個問題How to add uncompiled .mlmodel to Xcode UnitTests bundle that got this issue with Xcode 12
謝謝
Apple 允許您即時下載和編譯MLModel
。
因此,如果您為您的MLModel
使用 URL,您應該能夠按照這個 Apple 指南編譯它。
let compiledModelURL = try MLModel.compileModel(at: modelDescriptionURL)
let model = try MLModel(contentsOf: compiledModelURL)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.