简体   繁体   English

不要在 Swift Package Bundle 中编译 MLModel

[英]Do not compile MLModel in Swift Package Bundle

I want to add a .mlmodel to my swift package to have a test to verify that the compilation is working.我想在我的 swift 包中添加一个 .mlmodel 以进行测试以验证编译是否正常工作。

targets: [
    .target(
      name: "packageName",
      dependencies: ["package1"]
    ),
    .testTarget(
      name: "packageNameTests",
      dependencies: ["packageName"],
      resources: [
        .copy("Resources/testmodel.mlmodel"),
      ]
    )
  ]

My problem is the .mlmodel is always as a compiled model after bundling我的问题是 .mlmodel 在捆绑后总是作为编译模型

let docsPath = Bundle.module.resourcePath!
let docsArray = try fileManager.contentsOfDirectory(atPath: docsPath)
    print(docsArray)

leads to ["testmodel.mlmodelc"]导致 ["testmodel.mlmodelc"]

I am excepting testmodel.mlmodel to be present instead.我将 testmodel.mlmodel 改为存在。 I find it strange that copy is processing the ressource.我觉得奇怪的是副本正在处理资源。 Is there a workaround ?有解决方法吗? I am using Xcode 14 beta but there is a similar post on StackOverflow without answer regarding this issue How to add uncompiled .mlmodel to Xcode UnitTests bundle that got this problem with Xcode 12我正在使用 Xcode 14 beta,但 StackOverflow 上有一个类似的帖子,但没有回答关于这个问题How to add uncompiled .mlmodel to Xcode UnitTests bundle that got this issue with Xcode 12

Thank you谢谢

Apple allows you to download and compile a MLModel on the fly. Apple 允许您即时下载和编译MLModel

So if you use a URL for your MLModel , you should be able to compile it following this Apple guide .因此,如果您为您的MLModel使用 URL,您应该能够按照这个 Apple 指南编译它。

let compiledModelURL = try MLModel.compileModel(at: modelDescriptionURL)
let model = try MLModel(contentsOf: compiledModelURL)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM