edouardlp / Mask-RCNN-CoreML

Mask-RCNN for Core ML
MIT License
127 stars 19 forks source link

Error loading model #3

Open joshbeal opened 5 years ago

joshbeal commented 5 years ago

I get the following error when running the sample app after downloading the assets:

2019-01-17 21:51:37.564980-0800 Example[4051:695886] [espresso] [Espresso::handle_ex_plan] exception=Invalid dst shape1 x 1 x 2 x 0 x -1 2019-01-17 21:51:37.565377-0800 Example[4051:695886] [coreml] Error in adding network -1. 2019-01-17 21:51:37.565508-0800 Example[4051:695886] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}

lianyi commented 5 years ago

Got the same issue with xcode Version 10.1 (10B61), and the target is ios 12.0 and 12.1

019-02-18 13:43:22.192988-0800 Example[8416:2201273] [espresso] [Espresso::handle_ex_plan] exception=Invalid dst shape1 x 1 x 2 x 0 x -1
2019-02-18 13:43:22.193386-0800 Example[8416:2201273] [coreml] Error in adding network -1.
2019-02-18 13:43:22.193534-0800 Example[8416:2201273] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
2019-02-18 13:43:22.193562-0800 Example[8416:2201273] [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}
Miha-ha commented 5 years ago

Got the same issue with xcode Version 10.1 (10B61), and the target is iOS 12.1.4:

2019-03-06 10:10:47.819631+0300 Example[1547:349765] [espresso] [Espresso::handle_ex_plan] exception=Invalid dst shape1 x 1 x 2 x 0 x -1 2019-03-06 10:10:47.820211+0300 Example[1547:349765] [coreml] Error in adding network -1. 2019-03-06 10:10:47.820472+0300 Example[1547:349765] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.} 2019-03-06 10:10:47.820518+0300 Example[1547:349765] [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}

moddedayja commented 5 years ago

Me too ,I use xcode Version 10.1 (10B61), and the target is iOS 12.1 (16b94) iPhone x . when i was crash the first time to install app after that it normal.

espresso] [Espresso::handle_ex_plan] exception=mmap error: 12 2019-03-29 14:45:08.867218+0700 TrueHR[736:42507] [coreml] Error in adding network -1. 2019-03-29 14:45:08.867297+0700 TrueHR[736:42507] [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.} 2019-03-29 14:45:08.867315+0700 TrueHR[736:42507] [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}

turmezzz commented 5 years ago

And does anybody have a solution?)

nick-merlino commented 5 years ago

Same issue here [espresso] [Espresso::handle_ex_plan] exception=Invalid dst shape1 x 1 x 2 x 0 x -1 [coreml] Error in adding network -1. [coreml] MLModelAsset: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.} [coreml] MLModelAsset: modelWithError: load failed with error Error Domain=com.apple.CoreML Code=0 "Error in declaring network." UserInfo={NSLocalizedDescription=Error in declaring network.}

thorikawa commented 5 years ago

Had the same issue and have found a work around. Instead of including MaskRCNN.mlmodel in the project, I compiled it using MLModel.compileModel Swift API on my PC beforehand and then include compiled mlmodelc file in the project.

Try the following step.

  1. Compile MaskRCNN.mlmodel using MLModel.compileModel Swift API. You can do it yourself or you can use the attached MaskRCNN.mlmodelc which was compiled by me. https://drive.google.com/file/d/1NYD4BupvIs1Pza_F7jbg8oA5HXLV8FfC/view?usp=sharing

  2. Add reference to MaskRCNN.mlmodelc folder (check Create folder references) to your project.

    スクリーンショット 2019-06-19 20 36 46
  3. Make sure that in Build Phases, MaskRCNN.mlmodelc is added in Copy Bundle Resources section.

    スクリーンショット 2019-06-19 20 45 35
  4. In Swift code, load mlmodelc file directly instead of mlmodel file.

    // instaed of this
    //            let model = try VNCoreMLModel(for: MaskRCNN().model)
    // use following
            let compiledPath = Bundle.main.path(forResource: "MaskRCNN", ofType: "mlmodelc")
            let compiledUrl = URL(fileURLWithPath: compiledPath!)
            let mlmodel = try MLModel(contentsOf: compiledUrl)
            guard let model = try? VNCoreMLModel(for: mlmodel) else {
                fatalError("can't load Core ML model")
            }

By the way, at first I tried run MLModel.compileModel on my iPhone XS, but it exceeded device's memory limit (2000mb) and crashed. So I switched to run it on my Mac Book Pro.

Finally and more strangely, after this workaround worked, the original code started to work again. I don't know what the hell is going on :(