为 Xamarin.iOS 将 .mlmodel 编译为 .mlmodelc?

Compile .mlmodel to .mlmodelc for Xamarin.iOS?

我想为我的 Xamarin.iOS 应用程序使用 CoreML,但如何使用模型? developer.xamarin 中的所有示例都使用 .mlmodelc,但我下载了 .mlmodel。如何转换为 .mlmodelc?

您可以使用Xcode编译您的模型:

xcrun coremlcompiler compile MyModel.mlmodel MyModel.mlmodelc

这会输出一个 .mlmodelc,您可以将其添加到您的项目中。

或者您可以使用 MLModel.compileModel(at:).

在您的应用程序中动态执行此操作

您也可以在 Mac 终端中使用此命令:

/Applications/Xcode.app/Contents/Developer/usr/bin/coremlc compile coreml.mlmodel

您可以按照以下步骤操作:

第 1 步:打开终端并使用 'pwd' 命令检查当前目录。

第 2 步:使用 cd 命令从 .mlmodel 文件所在的当前目录转到 directory/folder,例如:'cd Desktop/mlfolder'.

第 3 步:输入以下命令

   /Applications/Xcode.app/Contents/Developer/usr/bin/coremlc compile model_name.mlmodel model_name.mlmodelc

注意:这里的model_name.mlmodel是mlmodel的名字(你可以在这里命名你的模型名字),model_name.mlmodelc是转换后的modelc名字(名字可以不一样)