ConfuseIous / ASLearn

My winning submission for the WWDC 2022 Swift Student Challenge.
8 stars 0 forks source link

Issue regarding using custom ml model #19

Open arijitdas123student opened 1 year ago

arijitdas123student commented 1 year ago

Hey, great work indeed! I was trying to use a different ML model (image classification) that I made using CreateML however I do face some issues while running it with your code. image

Can you please take a look?

ConfuseIous commented 1 year ago

Hi, it seems Apple changed the way models are loaded in Playgrounds apps some time between when I created ASLearn and now.

Previously, you'd add in a compiled mlmodelc and load that in, but now, you need to add the autogenerated Model class (you can get this by adding your model to a regular iOS app, building it, and checking the ~DerivedData directory.

You then need to just add the mlmodel file and the generated class in. You may need to modify the generated class slightly so it's like this:

class var urlOfModelInThisBundle : URL {
    let resPath = Bundle(for: self).url(forResource: "YourModelName", withExtension: "mlmodel")!
    return try! MLModel.compileModel(at: resPath)
}