如何在纯 Playground 文件中获取 CoreML [英] How To Get CoreML In Pure Playground Files

查看:39
本文介绍了如何在纯 Playground 文件中获取 CoreML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 .playground 文件,但似乎无法向其中添加我的 CoreML 模型.我将它拖到 Resources 文件夹中,这是我的代码:

I am using a .playground file and I can't seem to add my CoreML model to it. I drag it into the Resources folder and this is my code:

func predict(image: CGImage) {
    let model = try! VNCoreMLModel(for: Inceptionv3().model)
    let request = VNCoreMLRequest(model: model, completionHandler: results)
    let handler = VNSequenceRequestHandler()
    try! handler.perform([request], on: image)
}

但是,我收到错误消息:

However, I get the error saying:

未声明类型 Inceptionv3 的使用

Use of Undeclared Type Inceptionv3

有人可以帮我吗?

推荐答案

编译器引发此错误,因为它找不到类 Inceptionv3 的声明,您尝试实例化其对象.

The compiler raises this error, because it cannot find a declaration of the class Inceptionv3, that you try to instantiate an object of.

只要你有一个常规的 Xcode 项目,这个类就会自动为你创建.如果你想在 Swift playground 中使用它,你需要手动添加这个文件:

This class is automatically created for you as long as you have a regular Xcode project. If you want to work with it inside a Swift playground, you will need to add this file manually:

首先,创建一个常规的 Xcode 项目(例如一个 iOS 应用程序)并将您的 mlmodel 集成到其中.然后 Xcode 会自动为该模型生成一个接口.这些正是您的项目中缺少的文件,其中包含 Inceptionv3 类的定义.

First, create a regular Xcode project (an iOS app for example) and integrate your mlmodel there. Xcode will then generate an interface for that model automatically. These are exactly the files that are missing in your project and contain the definition of the Inceptionv3 class.

此处询问并回答了同样的问题.您还可以在那里找到一张图片,展示如何找到自动生成的类.

The same problem has been asked and answered here. There you can also find an image showing how to find the automatically generated classes.

这篇关于如何在纯 Playground 文件中获取 CoreML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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