简体   繁体   中英

error with CoreML: source file is not valid , when importing mymodel.mlmodel

I'm getting a problem when building my ios app with CoreML model in it. I've used this example code for implementing coreML in my project. I can run the example code when cloning it from github with the given model in the repo, but when I paste in my own model I get an error:

lexical preprocessor issue
    source file is not valid UTF-8
        SSD_model.mlmodel

My model is an SSD model for generating bounding boxes, (and not just object detection like the repo's model), so that could make a problem maybe. I trained it using tensorflow object detection API, and exported it to coreML using this helpful blog post . I've verified that my model works well by testing it in another script made for SSD models. Here's a snippet from the first example how I import the model now:

#import <CoreML/CoreML.h>
#import <Vision/Vision.h>
#import "SSD_model.mlmodel"

- (void)viewDidLoad {
    [super viewDidLoad];

    model = [[[SSD_model alloc] init] model]
    m = [VNCoreMLModel modelForMLModel: model error:nil];

Is there anything I need to change to this objective C code to make it work? Or any project settings that I might be forgetting? Thanks!

You are getting this error is because of this => #import "SSD_model.mlmodel"

Essentially the compiler tries to import some source code and instead finds something that is not.

You'll need to compile this model first in order to use it. You can compile it either via Xcode (it will autogenerate an interface for you) or by using APIs that compile the model in runtime (so you can update your models without needing to release a new version of the app).


Note: In the example you have linked, the author imports SomeModel.h (which I presume is the autogen header for ObjC) and not SomeModel.mlmodel . So I guess this was what you probably intended to do as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM