如何在 Swift Playground 中使用 .mlmodel? [英] How do I get the .mlmodel to be used in Swift Playground?

查看:48
本文介绍了如何在 Swift Playground 中使用 .mlmodel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将 .mlmodel 转换为 .mlmodelc ,并将其放在资源文件夹中.我使用 Vision frameworkMNIST 模型,遵循本教程 (

I have already converted the .mlmodel to .mlmodelc , and I have put it in the resources folder. Im using Vision framework and MNIST model, following this tutorial (https://www.youtube.com/watch?v=bOg8AZSFvOc), but using swift playground.

What am i missing? (im using .playground files, not .playgroundbook files)

line of code:

 guard let visionModel = try? VNCoreMLModel(for: MNIST().modelc) else {fatalError("can not load Vision ML model")}

Error message:

use of undefined identifier 'MNIST'

Screenshot:

解决方案

Playground doesn't recognize the .mlmodel file by default, so we need an iOS Project to help us find the compiled mlmodelc folder, and copy the mlmodelc folder to playground's resource folder, and the auto generated helper class to playground's source folder and change it to public. Then it works!

Try this project: https://github.com/DocRace/AnimalClassifier-Swift-Playground

这篇关于如何在 Swift Playground 中使用 .mlmodel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆