How to Get Coreml in Pure Playground Files

How To Get CoreML In Pure Playground Files

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

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:

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.

iOS 11 framework (CoreML) inside Playground Book

Solution: Write @available(iOS 11.0, *) in front of all classes that use CoreML in your .playgroundbook

Explanation: Apparently, the .playgroundbook is compiled for older iOS versions despite having set the deployment target to iOS11 inside the Manifest.plist.
Using the @available prefix you can manually exclude your classes from being compiled for older versions.

How do I get the .mlmodel to be used in Swift Playground?

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

Adding two unsigned char variables and result is int

The addition operation will first promote its operands to int, before doing the addition. This is how C works. If you want to truncate, you need to assign it back into a narrower type, such as unsigned char.



Related Topics



Leave a reply



Submit