Mask-RCNN-CoreML icon indicating copy to clipboard operation
Mask-RCNN-CoreML copied to clipboard

Error loading model

Open joshbeal opened this issue 6 years ago • 6 comments

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.}

joshbeal avatar Jan 18 '19 05:01 joshbeal

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.}

lianyi avatar Feb 18 '19 21:02 lianyi

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.}

Miha-ha avatar Mar 06 '19 07:03 Miha-ha

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.}

moddedayja avatar Apr 01 '19 03:04 moddedayja

And does anybody have a solution?)

turmezzz avatar Apr 21 '19 21:04 turmezzz

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.}

nick-merlino avatar May 02 '19 01:05 nick-merlino

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 :(

thorikawa avatar Jun 19 '19 11:06 thorikawa