[英]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.