Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get error: problem decoding CoreML document?

I am using CoreML with Swift 4.0 on Xcode 9 Beta.

If you select a file VGG16.mlmodel in the Project navigator, I get an error: There was an problem decoding this document CoreML

In addition, as a consequence in the code I get the errors Use of unresolved identifier 'VGG16' and Use of undeclared type 'VGG16'

VGG16.mlmodel downloaded from here https://developer.apple.com/machine-learning/

What could be the problem?

PS for models Places205-GoogLeNet, ResNet50 and Inception v3 everything works fine.

like image 551
A.Kant Avatar asked Jun 11 '17 22:06

A.Kant


2 Answers

As requested, I'll flesh out my comment into an answer.

Others have mentioned this, but you most likely have a corrupted download or there's something broken with the model itself. To begin with, I highly recommend not using the VGG16 model or related models on a mobile device just due to their sheer size (500 MB for VGG16). You'll exhaust memory on an iPhone 6 just loading the model, your application size will be gigantic, and you'll have a lengthy initialization time as those weights are loaded.

I recommend using something like a SqueezeNet variant, which is small (~5 MB), can be more accurate when trained on ImageNet, and isn't as computationally expensive as the Inception family. Apple makes reference to using one of these in one of the Core ML WWDC sessions.

When you add the model to your Xcode project, make sure it is actually being registered with your target. The current beta of Xcode occasionally forgets to add this to your target, so highlight the model and check in the file inspector to make sure it is part of your application target. If the model isn't in your target, Xcode won't auto-generate the Swift header for it.

like image 96
Brad Larson Avatar answered Jan 21 '23 14:01

Brad Larson


  1. pls run ./setup.sh
  2. select target for VGG16.mlmodel, see this screenshot
like image 44
luics Avatar answered Jan 21 '23 14:01

luics