Learn Courses My Dashboard

Core ML Module - own model does not work

Dear all,
I am in the process of doing the Core ML module by Micah.
When I made my own trained model using the sample data in lesson 5, it did not work once loaded into Xcode, the debugger just reports the catch blocks:
Could not classify animal
Invalid image

The App then crashes as it is stuck in the while loop that is waiting for results in the results array.

I downloaded the completed Xcode project file from the resources page and switched the ML model from MobileNetV2 to CatOrDog 1 and even this doesn’t work.

Not sure what’s gone wrong.
I’m using Xcode 14.0.1, iPhone 14 simulator using iOS 16.0, not sure if that’s relevant.

Thanks very much in advance,


I just downloaded and checked the project created by Micah Beech. It works fine with his model so you need to find out what is wrong with your own model.

Hi Chris, thanks for answering but I tried this - i.e. using Micah’s own model in the downloaded file and it still does not work for me.
It says this error in the console:
[coreml] Failed to get the home directory when checking model path.

The path is correct however - I am using the name of the file (i.e. CatOrDog_1) just as Micah does. The project builds fine as well.

I have seen that others on stack overflow also have a similar problem

Any thoughts? Could it be related to my Xcode/swift setup if it works for you?
Many thanks

Hi Tim,

Yes I see that error now having changed to the CatOrDog model. Weird.

Hi @timothynjones17

I know this is late, but I encountered the same error as you did.

However, what worked for me is to run the app on an actual device (an iPhone in my case). I’m not sure if this is due to a breaking change with Xcode 14, but running the model requires access to the home directory now compared to when it was recorded (for some reasons unknown to me), and you can’t access that directory in SwiftUI preview and iOS simulator due to it being sandboxed.

You can, however, have the app access to this directory by using an actual device to test your app.

I also did some changes in ContentView.swift. Apparently, classification.confidence is now a normalized value in between 0.0, and 1.0. So in order to show 0% to 100% in the UI, you need to multiply it by 100.

So far everything works, but the results would show either 100% cat or 100% dog. There were times when it shows 98% initially for either class but 98% goes to the correct class for most of the time.

Hi @inaki

Thanks very much, very helpful. Yes I had found it worked on a real device subsequently, but still am not sure what has changed on the simulator compared to when Micah made it. I wonder whether this will be fixed in an update or something,